fix label and icon being placed over each other in dagre/elk

This commit is contained in:
Alexander Wang 2022-12-03 16:30:44 -08:00
parent e77aee2303
commit d1bc498b0f
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
11 changed files with 191 additions and 23 deletions

View file

@ -150,7 +150,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
if obj.LabelWidth != nil && obj.LabelHeight != nil {
if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
} else if obj.Attributes.Shape.Value == d2target.ShapeImage {
} else if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
} else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))

View file

@ -247,7 +247,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
if obj.LabelWidth != nil && obj.LabelHeight != nil {
if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
} else if obj.Attributes.Shape.Value == d2target.ShapeImage {
} else if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
} else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))

View file

@ -1324,6 +1324,14 @@ s -> t`,
script: `x -> x -> x -> y
z -> y
z -> z: hello
`,
},
{
name: "icon-label",
script: `ww: {
label: hello
icon: https://icons.terrastruct.com/essentials/time.svg
}
`,
},
}

View file

@ -0,0 +1,56 @@
{
"name": "",
"shapes": [
{
"id": "ww",
"type": "",
"pos": {
"x": 0,
"y": 0
},
"width": 140,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#F7F8FE",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": {
"Scheme": "https",
"Opaque": "",
"User": null,
"Host": "icons.terrastruct.com",
"Path": "/essentials/time.svg",
"RawPath": "",
"ForceQuery": false,
"RawQuery": "",
"Fragment": "",
"RawFragment": ""
},
"iconPosition": "INSIDE_MIDDLE_CENTER",
"fields": null,
"methods": null,
"columns": null,
"label": "hello",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 40,
"labelHeight": 26,
"labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": []
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 324 KiB

56
e2etests/testdata/stable/icon-label/elk/board.exp.json generated vendored Normal file
View file

@ -0,0 +1,56 @@
{
"name": "",
"shapes": [
{
"id": "ww",
"type": "",
"pos": {
"x": 12,
"y": 12
},
"width": 140,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#F7F8FE",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": {
"Scheme": "https",
"Opaque": "",
"User": null,
"Host": "icons.terrastruct.com",
"Path": "/essentials/time.svg",
"RawPath": "",
"ForceQuery": false,
"RawQuery": "",
"Fragment": "",
"RawFragment": ""
},
"iconPosition": "INSIDE_MIDDLE_CENTER",
"fields": null,
"methods": null,
"columns": null,
"label": "hello",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 40,
"labelHeight": 26,
"labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": []
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 324 KiB

View file

@ -476,7 +476,7 @@
"underline": false,
"labelWidth": 31,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0,
"level": 1
},
@ -565,7 +565,7 @@
"underline": false,
"labelWidth": 20,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0,
"level": 2
},

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 490 KiB

After

Width:  |  Height:  |  Size: 490 KiB

View file

@ -476,7 +476,7 @@
"underline": false,
"labelWidth": 31,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0,
"level": 1
},
@ -565,7 +565,7 @@
"underline": false,
"labelWidth": 20,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0,
"level": 2
},

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 486 KiB

After

Width:  |  Height:  |  Size: 486 KiB