diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 47dee829f..6cace9281 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -374,11 +374,18 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err if hasTop || hasBottom { padding := parsePadding(elkNodes[obj].LayoutOptions.Padding) if hasTop { - // TODO I think this fails to account for a potential inner label of container - padding.top = go2.Max(padding.top, d2target.MAX_ICON_SIZE+2*label.PADDING) + ownLabelHeight := 0 + if obj.LabelPosition != nil && strings.HasPrefix(*obj.LabelPosition, "INSIDE_TOP") { + ownLabelHeight = obj.LabelDimensions.Height + label.PADDING + } + padding.top = go2.Max(padding.top, d2target.MAX_ICON_SIZE+2*label.PADDING+ownLabelHeight) } if hasBottom { - padding.bottom = go2.Max(padding.bottom, d2target.MAX_ICON_SIZE+2*label.PADDING) + ownLabelHeight := 0 + if obj.LabelPosition != nil && strings.HasPrefix(*obj.LabelPosition, "INSIDE_BOTTOM") { + ownLabelHeight = obj.LabelDimensions.Height + label.PADDING + } + padding.bottom = go2.Max(padding.bottom, d2target.MAX_ICON_SIZE+2*label.PADDING+ownLabelHeight) } elkNodes[obj].LayoutOptions.Padding = padding.String() } diff --git a/e2etests/testdata/txtar/sql-icon/elk/board.exp.json b/e2etests/testdata/txtar/sql-icon/elk/board.exp.json index 140aded18..1e79b6318 100644 --- a/e2etests/testdata/txtar/sql-icon/elk/board.exp.json +++ b/e2etests/testdata/txtar/sql-icon/elk/board.exp.json @@ -253,7 +253,7 @@ "y": 330 }, "width": 972, - "height": 262, + "height": 303, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -291,7 +291,7 @@ "type": "sql_table", "pos": { "x": 62, - "y": 404 + "y": 445 }, "width": 106, "height": 72, @@ -375,7 +375,7 @@ "type": "class", "pos": { "x": 188, - "y": 404 + "y": 445 }, "width": 204, "height": 138, @@ -436,7 +436,7 @@ "type": "code", "pos": { "x": 412, - "y": 404 + "y": 445 }, "width": 74, "height": 37, @@ -488,7 +488,7 @@ "type": "text", "pos": { "x": 506, - "y": 404 + "y": 445 }, "width": 428, "height": 91, @@ -567,7 +567,7 @@ }, { "x": 115, - "y": 404 + "y": 445 } ], "animated": false, @@ -605,7 +605,7 @@ }, { "x": 290, - "y": 404 + "y": 445 } ], "animated": false, @@ -643,7 +643,7 @@ }, { "x": 449, - "y": 404 + "y": 445 } ], "animated": false, @@ -681,7 +681,7 @@ }, { "x": 720, - "y": 404 + "y": 445 } ], "animated": false, diff --git a/e2etests/testdata/txtar/sql-icon/elk/sketch.exp.svg b/e2etests/testdata/txtar/sql-icon/elk/sketch.exp.svg index 8a6a3288d..cd36ca0c5 100644 --- a/e2etests/testdata/txtar/sql-icon/elk/sketch.exp.svg +++ b/e2etests/testdata/txtar/sql-icon/elk/sketch.exp.svg @@ -1,27 +1,27 @@ -withoutwithtableExabclassEx+ab:= 1a := 1

This is for all ill-treated fellows

+withoutwithtableExabclassEx+ab:= 1a := 1

This is for all ill-treated fellows

You will live a long, healthy, happy life and make bags of money.

-
tableExabclassEx+ab:= 1a := 1

This is for all ill-treated fellows

+
tableExabclassEx+ab:= 1a := 1

This is for all ill-treated fellows

You will live a long, healthy, happy life and make bags of money.

-
- +
+ - - + +
\ No newline at end of file