diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go
index 6dd37f828..ada0ca0e7 100644
--- a/d2layouts/d2elklayout/layout.go
+++ b/d2layouts/d2elklayout/layout.go
@@ -147,8 +147,10 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
walk(g.Root, nil, func(obj, parent *d2graph.Object) {
height := obj.Height
- if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
- height += float64(*obj.LabelHeight) + label.PADDING
+ if obj.LabelWidth != nil && obj.LabelHeight != nil {
+ if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
+ height += float64(*obj.LabelHeight) + label.PADDING
+ }
}
n := &ELKNode{
diff --git a/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/board.exp.json b/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/board.exp.json
index 3d188b1cf..f1b566716 100644
--- a/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/board.exp.json
+++ b/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/board.exp.json
@@ -51,6 +51,56 @@
"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": []
diff --git a/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/sketch.exp.svg b/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/sketch.exp.svg
index eff9f32b3..3726c5c2d 100644
--- a/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/sketch.exp.svg
+++ b/e2etests/testdata/regression/elk_img_empty_label_panic/dagre/sketch.exp.svg
@@ -2,7 +2,7 @@
\ No newline at end of file
diff --git a/e2etests/testdata/regression/elk_img_empty_label_panic/elk/board.exp.json b/e2etests/testdata/regression/elk_img_empty_label_panic/elk/board.exp.json
new file mode 100644
index 000000000..e37d0a2b3
--- /dev/null
+++ b/e2etests/testdata/regression/elk_img_empty_label_panic/elk/board.exp.json
@@ -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": []
+}
diff --git a/e2etests/testdata/regression/elk_img_empty_label_panic/elk/sketch.exp.svg b/e2etests/testdata/regression/elk_img_empty_label_panic/elk/sketch.exp.svg
new file mode 100644
index 000000000..81e2051b4
--- /dev/null
+++ b/e2etests/testdata/regression/elk_img_empty_label_panic/elk/sketch.exp.svg
@@ -0,0 +1,24 @@
+
+
\ No newline at end of file