diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 1272105fe..8233dce79 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -345,8 +345,10 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err continue } + subtract := go2.Min(rootAttrs.ranksep/2, *obj.LabelHeight+label.PADDING) + // This was artifically added to make dagre consider label height - obj.Height -= (float64(*obj.LabelHeight) + label.PADDING) + obj.Height -= float64(subtract) movedEdges := make(map[*d2graph.Edge]struct{}) for _, e := range g.Edges { @@ -371,7 +373,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err currDst = currDst.Parent } if isSrcDesc && isDstDesc { - stepSize := float64(*obj.LabelHeight) + label.PADDING + stepSize := float64(subtract) if e.Src != obj || e.Dst != obj { stepSize /= 2. } @@ -388,7 +390,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err curr := q[0] q = q[1:] - stepSize := float64(*obj.LabelHeight) + label.PADDING + stepSize := float64(subtract) if curr != obj { stepSize /= 2. } diff --git a/e2etests/testdata/stable/font_sizes_containers_large/dagre/board.exp.json b/e2etests/testdata/stable/font_sizes_containers_large/dagre/board.exp.json index 1d131a92a..c1b6f4cd0 100644 --- a/e2etests/testdata/stable/font_sizes_containers_large/dagre/board.exp.json +++ b/e2etests/testdata/stable/font_sizes_containers_large/dagre/board.exp.json @@ -7,10 +7,10 @@ "type": "rectangle", "pos": { "x": 0, - "y": 130 + "y": 65 }, "width": 404, - "height": 446, + "height": 511, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -48,10 +48,10 @@ "type": "rectangle", "pos": { "x": 40, - "y": 216 + "y": 162 }, "width": 324, - "height": 360, + "height": 381, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -89,7 +89,7 @@ "type": "rectangle", "pos": { "x": 80, - "y": 284 + "y": 241 }, "width": 244, "height": 270, @@ -130,7 +130,7 @@ "type": "rectangle", "pos": { "x": 120, - "y": 352 + "y": 309 }, "width": 164, "height": 160, @@ -171,7 +171,7 @@ "type": "rectangle", "pos": { "x": 170, - "y": 404 + "y": 361 }, "width": 64, "height": 56, diff --git a/e2etests/testdata/stable/font_sizes_containers_large/dagre/sketch.exp.svg b/e2etests/testdata/stable/font_sizes_containers_large/dagre/sketch.exp.svg index 5d4f49655..533dd9d80 100644 --- a/e2etests/testdata/stable/font_sizes_containers_large/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/font_sizes_containers_large/dagre/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="652" height="778" viewBox="-124 -100 652 778">