Merge pull request #555 from gavin-ts/fix-elk-panic
elk: fix panic with empty label on image/icon
This commit is contained in:
commit
1c958ead3b
7 changed files with 281 additions and 2 deletions
|
|
@ -9,4 +9,5 @@
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
- Restricts where `near` key constant values can be used, with good error messages, instead of erroring (e.g. setting `near: top-center` on a container would cause bad layouts or error). [#538](https://github.com/terrastruct/d2/pull/538)
|
- Restricts where `near` key constant values can be used, with good error messages, instead of erroring (e.g. setting `near: top-center` on a container would cause bad layouts or error). [#538](https://github.com/terrastruct/d2/pull/538)
|
||||||
|
- Fixes an error during ELK layout when images had empty labels. [#555](https://github.com/terrastruct/d2/pull/555)
|
||||||
- Fixes rendering classes and tables with empty headers. [#498](https://github.com/terrastruct/d2/pull/498)
|
- Fixes rendering classes and tables with empty headers. [#498](https://github.com/terrastruct/d2/pull/498)
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,10 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
||||||
|
|
||||||
walk(g.Root, nil, func(obj, parent *d2graph.Object) {
|
walk(g.Root, nil, func(obj, parent *d2graph.Object) {
|
||||||
height := obj.Height
|
height := obj.Height
|
||||||
if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
|
if obj.LabelWidth != nil && obj.LabelHeight != nil {
|
||||||
height += float64(*obj.LabelHeight) + label.PADDING
|
if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
|
||||||
|
height += float64(*obj.LabelHeight) + label.PADDING
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n := &ELKNode{
|
n := &ELKNode{
|
||||||
|
|
|
||||||
|
|
@ -248,6 +248,20 @@ code: |go
|
||||||
b := a + 7
|
b := a + 7
|
||||||
fmt.Printf("%d", b)
|
fmt.Printf("%d", b)
|
||||||
|
|
|
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "elk_img_empty_label_panic",
|
||||||
|
script: `
|
||||||
|
img: {
|
||||||
|
label: ""
|
||||||
|
shape: image
|
||||||
|
icon: https://icons.terrastruct.com/infra/019-network.svg
|
||||||
|
}
|
||||||
|
ico: {
|
||||||
|
label: ""
|
||||||
|
icon: https://icons.terrastruct.com/infra/019-network.svg
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
107
e2etests/testdata/regression/elk_img_empty_label_panic/dagre/board.exp.json
generated
vendored
Normal file
107
e2etests/testdata/regression/elk_img_empty_label_panic/dagre/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"fontFamily": "SourceSansPro",
|
||||||
|
"shapes": [
|
||||||
|
{
|
||||||
|
"id": "img",
|
||||||
|
"type": "image",
|
||||||
|
"pos": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"width": 128,
|
||||||
|
"height": 128,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#FFFFFF",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": {
|
||||||
|
"Scheme": "https",
|
||||||
|
"Opaque": "",
|
||||||
|
"User": null,
|
||||||
|
"Host": "icons.terrastruct.com",
|
||||||
|
"Path": "/infra/019-network.svg",
|
||||||
|
"RawPath": "",
|
||||||
|
"ForceQuery": false,
|
||||||
|
"RawQuery": "",
|
||||||
|
"Fragment": "",
|
||||||
|
"RawFragment": ""
|
||||||
|
},
|
||||||
|
"iconPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 0,
|
||||||
|
"labelHeight": 0,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ico",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": 188,
|
||||||
|
"y": 14
|
||||||
|
},
|
||||||
|
"width": 100,
|
||||||
|
"height": 100,
|
||||||
|
"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": "/infra/019-network.svg",
|
||||||
|
"RawPath": "",
|
||||||
|
"ForceQuery": false,
|
||||||
|
"RawQuery": "",
|
||||||
|
"Fragment": "",
|
||||||
|
"RawFragment": ""
|
||||||
|
},
|
||||||
|
"iconPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 0,
|
||||||
|
"labelHeight": 0,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": []
|
||||||
|
}
|
||||||
24
e2etests/testdata/regression/elk_img_empty_label_panic/dagre/sketch.exp.svg
vendored
Normal file
24
e2etests/testdata/regression/elk_img_empty_label_panic/dagre/sketch.exp.svg
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<svg
|
||||||
|
style="background: white;"
|
||||||
|
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
width="488" height="328" viewBox="-100 -100 488 328"><style type="text/css">
|
||||||
|
<![CDATA[
|
||||||
|
.shape {
|
||||||
|
shape-rendering: geometricPrecision;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
.connection {
|
||||||
|
stroke-linecap: round;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
.blend {
|
||||||
|
mix-blend-mode: multiply;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
]]>
|
||||||
|
</style><g id="img"><g class="shape" ><image href="https://icons.terrastruct.com/infra/019-network.svg" x="0" y="0" width="128" height="128" style="fill:#FFFFFF;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g></g><g id="ico"><g class="shape" ><rect x="188" y="14" width="100" height="100" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><image href="https://icons.terrastruct.com/infra/019-network.svg" x="213.000000" y="39.000000" width="50" height="50" /></g><mask id="1654899612" maskUnits="userSpaceOnUse" x="-100" y="-100" width="488" height="328">
|
||||||
|
<rect x="-100" y="-100" width="488" height="328" fill="white"></rect>
|
||||||
|
|
||||||
|
</mask><style type="text/css"><![CDATA[]]></style></svg>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
107
e2etests/testdata/regression/elk_img_empty_label_panic/elk/board.exp.json
generated
vendored
Normal file
107
e2etests/testdata/regression/elk_img_empty_label_panic/elk/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"fontFamily": "SourceSansPro",
|
||||||
|
"shapes": [
|
||||||
|
{
|
||||||
|
"id": "img",
|
||||||
|
"type": "image",
|
||||||
|
"pos": {
|
||||||
|
"x": 12,
|
||||||
|
"y": 12
|
||||||
|
},
|
||||||
|
"width": 128,
|
||||||
|
"height": 128,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#FFFFFF",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": {
|
||||||
|
"Scheme": "https",
|
||||||
|
"Opaque": "",
|
||||||
|
"User": null,
|
||||||
|
"Host": "icons.terrastruct.com",
|
||||||
|
"Path": "/infra/019-network.svg",
|
||||||
|
"RawPath": "",
|
||||||
|
"ForceQuery": false,
|
||||||
|
"RawQuery": "",
|
||||||
|
"Fragment": "",
|
||||||
|
"RawFragment": ""
|
||||||
|
},
|
||||||
|
"iconPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 0,
|
||||||
|
"labelHeight": 0,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ico",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": 160,
|
||||||
|
"y": 26
|
||||||
|
},
|
||||||
|
"width": 100,
|
||||||
|
"height": 100,
|
||||||
|
"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": "/infra/019-network.svg",
|
||||||
|
"RawPath": "",
|
||||||
|
"ForceQuery": false,
|
||||||
|
"RawQuery": "",
|
||||||
|
"Fragment": "",
|
||||||
|
"RawFragment": ""
|
||||||
|
},
|
||||||
|
"iconPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 0,
|
||||||
|
"labelHeight": 0,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": []
|
||||||
|
}
|
||||||
24
e2etests/testdata/regression/elk_img_empty_label_panic/elk/sketch.exp.svg
vendored
Normal file
24
e2etests/testdata/regression/elk_img_empty_label_panic/elk/sketch.exp.svg
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<svg
|
||||||
|
style="background: white;"
|
||||||
|
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
width="448" height="328" viewBox="-88 -88 448 328"><style type="text/css">
|
||||||
|
<![CDATA[
|
||||||
|
.shape {
|
||||||
|
shape-rendering: geometricPrecision;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
.connection {
|
||||||
|
stroke-linecap: round;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
.blend {
|
||||||
|
mix-blend-mode: multiply;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
]]>
|
||||||
|
</style><g id="img"><g class="shape" ><image href="https://icons.terrastruct.com/infra/019-network.svg" x="12" y="12" width="128" height="128" style="fill:#FFFFFF;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g></g><g id="ico"><g class="shape" ><rect x="160" y="26" width="100" height="100" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><image href="https://icons.terrastruct.com/infra/019-network.svg" x="185.000000" y="51.000000" width="50" height="50" /></g><mask id="124328945" maskUnits="userSpaceOnUse" x="-100" y="-100" width="448" height="328">
|
||||||
|
<rect x="-100" y="-100" width="448" height="328" fill="white"></rect>
|
||||||
|
|
||||||
|
</mask><style type="text/css"><![CDATA[]]></style></svg>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
Loading…
Reference in a new issue