fix monospaced edge labels

This commit is contained in:
Alexander Wang 2023-03-16 15:02:06 -07:00
parent a1fc223521
commit 65d36215f9
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
16 changed files with 1055 additions and 476 deletions

View file

@ -1424,8 +1424,13 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
if g.Theme != nil && g.Theme.SpecialRules.CapsLock {
edge.Attributes.Label.Value = strings.ToUpper(edge.Attributes.Label.Value)
}
usedFont := fontFamily
if edge.Attributes.Style.Font != nil {
f := d2fonts.D2_FONT_TO_FAMILY[edge.Attributes.Style.Font.Value]
usedFont = &f
}
dims := GetTextDimensions(mtexts, ruler, edge.Text(), fontFamily)
dims := GetTextDimensions(mtexts, ruler, edge.Text(), usedFont)
if dims == nil {
return fmt.Errorf("dimensions for edge label %#v not found", edge.Text())
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 350 KiB

After

Width:  |  Height:  |  Size: 350 KiB

View file

@ -135,6 +135,11 @@ logs: { shape: page; style.multiple: true }
network.data processor -> api server
`,
},
{
name: "mono-edge",
script: `direction: right
x -> y: hi { style.font: mono }`,
},
{
name: "mono-font",
script: `satellites: SATELLITES {

View file

@ -10,7 +10,7 @@
"x": 0,
"y": 41
},
"width": 333,
"width": 334,
"height": 640,
"opacity": 1,
"strokeDash": 0,
@ -52,7 +52,7 @@
"x": 20,
"y": 106
},
"width": 293,
"width": 294,
"height": 545,
"opacity": 1,
"strokeDash": 0,
@ -91,7 +91,7 @@
"id": "NETWORK.CELL TOWER.satellites",
"type": "stored_data",
"pos": {
"x": 86,
"x": 87,
"y": 195
},
"width": 161,
@ -132,7 +132,7 @@
"id": "NETWORK.CELL TOWER.transmitter",
"type": "rectangle",
"pos": {
"x": 91,
"x": 92,
"y": 496
},
"width": 151,
@ -173,7 +173,7 @@
"id": "costumes",
"type": "sql_table",
"pos": {
"x": 373,
"x": 374,
"y": 100
},
"width": 311,
@ -330,7 +330,7 @@
"id": "monsters",
"type": "sql_table",
"pos": {
"x": 373,
"x": 374,
"y": 401
},
"width": 311,
@ -506,7 +506,7 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
@ -516,15 +516,15 @@
"y": 262
},
{
"x": 107.8,
"x": 108,
"y": 355.6
},
{
"x": 107.8,
"x": 108.05,
"y": 402.6
},
{
"x": 151,
"x": 151.25,
"y": 497
}
],
@ -555,25 +555,25 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 166,
"x": 167,
"y": 262
},
{
"x": 166.4,
"x": 167,
"y": 355.6
},
{
"x": 166.5,
"x": 167,
"y": 402.6
},
{
"x": 166.5,
"x": 167,
"y": 497
}
],
@ -604,25 +604,25 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 182,
"x": 183,
"y": 262
},
{
"x": 225.2,
"x": 226,
"y": 355.6
},
{
"x": 225.2,
"x": 225.95,
"y": 402.6
},
{
"x": 182,
"x": 182.75,
"y": 497
}
],
@ -659,19 +659,19 @@
"labelPercentage": 0,
"route": [
{
"x": 528.5,
"x": 529.5,
"y": 280
},
{
"x": 528.5,
"x": 529.5,
"y": 328.4
},
{
"x": 528.5,
"x": 529.5,
"y": 352.7
},
{
"x": 528.5,
"x": 529.5,
"y": 401.5
}
],

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 624 KiB

After

Width:  |  Height:  |  Size: 624 KiB

View file

@ -10,7 +10,7 @@
"x": 0,
"y": 41
},
"width": 333,
"width": 334,
"height": 412,
"opacity": 1,
"strokeDash": 0,
@ -52,7 +52,7 @@
"x": 20,
"y": 106
},
"width": 293,
"width": 294,
"height": 317,
"opacity": 1,
"strokeDash": 0,
@ -91,7 +91,7 @@
"id": "NETWORK.CELL TOWER.satellites",
"type": "stored_data",
"pos": {
"x": 86,
"x": 87,
"y": 138
},
"width": 161,
@ -132,7 +132,7 @@
"id": "NETWORK.CELL TOWER.transmitter",
"type": "rectangle",
"pos": {
"x": 91,
"x": 92,
"y": 325
},
"width": 151,
@ -192,7 +192,7 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
@ -202,15 +202,15 @@
"y": 205
},
{
"x": 106,
"x": 106.19999999999999,
"y": 253
},
{
"x": 106,
"x": 106.25,
"y": 277.2
},
{
"x": 142,
"x": 142.25,
"y": 326
}
],
@ -241,25 +241,25 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 166,
"x": 167,
"y": 205
},
{
"x": 166.4,
"x": 167,
"y": 253
},
{
"x": 166.5,
"x": 167,
"y": 277.2
},
{
"x": 166.5,
"x": 167,
"y": 326
}
],
@ -290,25 +290,25 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 191,
"x": 192,
"y": 205
},
{
"x": 227,
"x": 227.8,
"y": 253
},
{
"x": 227,
"x": 227.75,
"y": 277.2
},
{
"x": 191,
"x": 191.75,
"y": 326
}
],

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 268 KiB

After

Width:  |  Height:  |  Size: 268 KiB

180
e2etests/testdata/stable/mono-edge/dagre/board.exp.json generated vendored Normal file
View file

@ -0,0 +1,180 @@
{
"name": "",
"isFolderOnly": false,
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "rectangle",
"pos": {
"x": 0,
"y": 0
},
"width": 53,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B6",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "x",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 8,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "y",
"type": "rectangle",
"pos": {
"x": 171,
"y": 0
},
"width": 54,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B6",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "y",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 9,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": [
{
"id": "(x -> y)[0]",
"src": "x",
"srcArrow": "none",
"srcLabel": "",
"dst": "y",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "hi",
"fontSize": 16,
"fontFamily": "mono",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 18,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 53,
"y": 33
},
{
"x": 100.2,
"y": 33
},
{
"x": 123.8,
"y": 33
},
{
"x": 171,
"y": 33
}
],
"isCurve": true,
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
],
"root": {
"id": "",
"type": "",
"pos": {
"x": 0,
"y": 0
},
"width": 0,
"height": 0,
"opacity": 0,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "N7",
"stroke": "",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"zIndex": 0,
"level": 0
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 587 KiB

171
e2etests/testdata/stable/mono-edge/elk/board.exp.json generated vendored Normal file
View file

@ -0,0 +1,171 @@
{
"name": "",
"isFolderOnly": false,
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "rectangle",
"pos": {
"x": 12,
"y": 12
},
"width": 53,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B6",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "x",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 8,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "y",
"type": "rectangle",
"pos": {
"x": 223,
"y": 12
},
"width": 54,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B6",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "y",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 9,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": [
{
"id": "(x -> y)[0]",
"src": "x",
"srcArrow": "none",
"srcLabel": "",
"dst": "y",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "hi",
"fontSize": 16,
"fontFamily": "mono",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 18,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 65,
"y": 45
},
{
"x": 223,
"y": 45
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
],
"root": {
"id": "",
"type": "",
"pos": {
"x": 0,
"y": 0
},
"width": 0,
"height": 0,
"opacity": 0,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "N7",
"stroke": "",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"zIndex": 0,
"level": 0
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 587 KiB

View file

@ -108,7 +108,7 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
@ -118,11 +118,11 @@
"y": 66
},
{
"x": 30.799999999999997,
"x": 30,
"y": 114.4
},
{
"x": 30.9,
"x": 30.1,
"y": 138.7
},
{
@ -157,7 +157,7 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
@ -206,7 +206,7 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
@ -216,11 +216,11 @@
"y": 66
},
{
"x": 130.2,
"x": 131,
"y": 114.4
},
{
"x": 130.1,
"x": 130.9,
"y": 138.7
},
{

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 265 KiB

After

Width:  |  Height:  |  Size: 265 KiB

View file

@ -108,17 +108,17 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 44,
"x": 43,
"y": 78
},
{
"x": 44.5,
"x": 43.5,
"y": 259
}
],
@ -148,7 +148,7 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
@ -188,17 +188,17 @@
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 37,
"labelWidth": 38,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 140,
"x": 141,
"y": 78
},
{
"x": 140.5,
"x": 141.5,
"y": 259
}
],

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 265 KiB

After

Width:  |  Height:  |  Size: 265 KiB