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 obj.LabelWidth != nil && obj.LabelHeight != nil {
if len(obj.ChildrenArray) > 0 { if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) 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)) obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
} else { } else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) 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 obj.LabelWidth != nil && obj.LabelHeight != nil {
if len(obj.ChildrenArray) > 0 { if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) 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)) obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
} else { } else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))

View file

@ -1222,7 +1222,7 @@ foo baz -> hello
script: `shape: sequence_diagram script: `shape: sequence_diagram
a: "a label" { a: "a label" {
shape: callout shape: callout
} }
b: "b\nlabels" { b: "b\nlabels" {
shape: circle shape: circle
@ -1233,7 +1233,7 @@ c: "a class" {
-private() int -private() int
} }
d: "cloudyyyy" { d: "cloudyyyy" {
shape: cloud shape: cloud
} }
e: |go e: |go
a := 5 a := 5
@ -1241,47 +1241,47 @@ e: |go
fmt.Printf("%d", b) fmt.Printf("%d", b)
| |
f: "cyl" { f: "cyl" {
shape: cylinder shape: cylinder
} }
g: "dia" { g: "dia" {
shape: diamond shape: diamond
} }
h: "docs" { h: "docs" {
shape: document shape: document
} }
i: "six corners" { i: "six corners" {
shape: hexagon shape: hexagon
} }
j: "a random icon" { j: "a random icon" {
shape: image shape: image
icon: https://icons.terrastruct.com/essentials/004-picture.svg icon: https://icons.terrastruct.com/essentials/004-picture.svg
} }
k: "over" { k: "over" {
shape: oval shape: oval
} }
l: "pack" { l: "pack" {
shape: package shape: package
} }
m: "docs page" { m: "docs page" {
shape: page shape: page
} }
n: "too\nhard\to say" { n: "too\nhard\to say" {
shape: parallelogram shape: parallelogram
} }
o: "single\nperson" { o: "single\nperson" {
shape: person shape: person
} }
p: "a queue" { p: "a queue" {
shape: queue shape: queue
} }
q: "a square" { q: "a square" {
shape: square shape: square
} }
r: "a step at a time" { r: "a step at a time" {
shape: step shape: step
} }
s: "data" { s: "data" {
shape: stored_data shape: stored_data
} }
t: "users" { t: "users" {
@ -1324,6 +1324,14 @@ s -> t`,
script: `x -> x -> x -> y script: `x -> x -> x -> y
z -> y z -> y
z -> z: hello 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, "underline": false,
"labelWidth": 31, "labelWidth": 31,
"labelHeight": 26, "labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER", "labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0, "zIndex": 0,
"level": 1 "level": 1
}, },
@ -565,7 +565,7 @@
"underline": false, "underline": false,
"labelWidth": 20, "labelWidth": 20,
"labelHeight": 26, "labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER", "labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0, "zIndex": 0,
"level": 2 "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, "underline": false,
"labelWidth": 31, "labelWidth": 31,
"labelHeight": 26, "labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER", "labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0, "zIndex": 0,
"level": 1 "level": 1
}, },
@ -565,7 +565,7 @@
"underline": false, "underline": false,
"labelWidth": 20, "labelWidth": 20,
"labelHeight": 26, "labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER", "labelPosition": "OUTSIDE_TOP_CENTER",
"zIndex": 0, "zIndex": 0,
"level": 2 "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