From 9fad10582274e6929170bfb8ad8969ee5b7a0264 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 10 Feb 2023 13:47:22 -0800 Subject: [PATCH] fix padding --- d2layouts/d2dagrelayout/layout.go | 10 +- .../d2sketch/testdata/animated/sketch.exp.svg | 6 +- .../testdata/child_to_child/sketch.exp.svg | 6 +- .../dagre/board.exp.json | 40 +-- .../dagre/sketch.exp.svg | 8 +- .../dagre/board.exp.json | 46 ++-- .../dagre/sketch.exp.svg | 14 +- .../elk_alignment/dagre/board.exp.json | 98 +++---- .../elk_alignment/dagre/sketch.exp.svg | 22 +- .../elk_loop_panic/dagre/board.exp.json | 34 +-- .../elk_loop_panic/dagre/sketch.exp.svg | 6 +- .../dagre/board.exp.json | 24 +- .../dagre/sketch.exp.svg | 6 +- .../child_to_child/dagre/board.exp.json | 16 +- .../child_to_child/dagre/sketch.exp.svg | 6 +- .../stable/chaos1/dagre/board.exp.json | 18 +- .../stable/chaos1/dagre/sketch.exp.svg | 10 +- .../stable/chaos2/dagre/board.exp.json | 180 ++++++------- .../stable/chaos2/dagre/sketch.exp.svg | 22 +- .../complex-layers/dagre/board.exp.json | 8 +- .../connected_container/dagre/board.exp.json | 30 +-- .../connected_container/dagre/sketch.exp.svg | 6 +- .../container_edges/dagre/board.exp.json | 30 +-- .../container_edges/dagre/sketch.exp.svg | 2 +- .../different_subgraphs/dagre/board.exp.json | 46 ++-- .../different_subgraphs/dagre/sketch.exp.svg | 6 +- .../stable/direction/dagre/board.exp.json | 86 +++--- .../stable/direction/dagre/sketch.exp.svg | 2 +- .../dagre/board.exp.json | 16 +- .../dagre/sketch.exp.svg | 6 +- .../stable/investigate/dagre/board.exp.json | 130 +++++----- .../stable/investigate/dagre/sketch.exp.svg | 14 +- .../stable/large_arch/dagre/board.exp.json | 244 +++++++++--------- .../stable/large_arch/dagre/sketch.exp.svg | 6 +- .../markdown_stroke_fill/dagre/board.exp.json | 6 +- .../markdown_stroke_fill/dagre/sketch.exp.svg | 10 +- .../md_2space_newline/dagre/board.exp.json | 6 +- .../md_2space_newline/dagre/sketch.exp.svg | 8 +- .../md_backslash_newline/dagre/board.exp.json | 6 +- .../md_backslash_newline/dagre/sketch.exp.svg | 8 +- .../one_container_loop/dagre/board.exp.json | 12 +- .../one_container_loop/dagre/sketch.exp.svg | 6 +- .../dagre/board.exp.json | 24 +- .../dagre/sketch.exp.svg | 6 +- .../dagre/board.exp.json | 84 +++--- .../dagre/sketch.exp.svg | 14 +- .../sequence_diagrams/dagre/board.exp.json | 230 ++++++++--------- .../sequence_diagrams/dagre/sketch.exp.svg | 26 +- .../dagre/board.exp.json | 106 ++++---- .../dagre/sketch.exp.svg | 2 +- .../child_parent_edges/dagre/board.exp.json | 70 ++--- .../child_parent_edges/dagre/sketch.exp.svg | 6 +- .../container_child_edge/dagre/board.exp.json | 24 +- .../container_child_edge/dagre/sketch.exp.svg | 10 +- .../container_label_loop/dagre/board.exp.json | 42 +-- .../container_label_loop/dagre/sketch.exp.svg | 6 +- .../dagre/board.exp.json | 28 +- .../dagre/sketch.exp.svg | 8 +- 58 files changed, 976 insertions(+), 976 deletions(-) diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index bb5bbe506..1272105fe 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -110,7 +110,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err continue } if obj.LabelHeight != nil { - maxContainerLabelHeight = go2.Max(maxContainerLabelHeight, *obj.LabelHeight) + maxContainerLabelHeight = go2.Max(maxContainerLabelHeight, *obj.LabelHeight+label.PADDING) } } @@ -141,7 +141,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err height += float64(*obj.LabelHeight) + label.PADDING } if len(obj.ChildrenArray) > 0 { - obj.Height += float64(*obj.LabelHeight) + height += float64(*obj.LabelHeight) + label.PADDING } } loadScript += generateAddNodeLine(id, int(obj.Width), int(height)) @@ -346,7 +346,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } // This was artifically added to make dagre consider label height - obj.Height -= float64(*obj.LabelHeight) + obj.Height -= (float64(*obj.LabelHeight) + label.PADDING) movedEdges := make(map[*d2graph.Edge]struct{}) for _, e := range g.Edges { @@ -371,7 +371,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err currDst = currDst.Parent } if isSrcDesc && isDstDesc { - stepSize := float64(*obj.LabelHeight) + stepSize := float64(*obj.LabelHeight) + label.PADDING if e.Src != obj || e.Dst != obj { stepSize /= 2. } @@ -388,7 +388,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err curr := q[0] q = q[1:] - stepSize := float64(*obj.LabelHeight) + stepSize := float64(*obj.LabelHeight) + label.PADDING if curr != obj { stepSize /= 2. } diff --git a/d2renderers/d2sketch/testdata/animated/sketch.exp.svg b/d2renderers/d2sketch/testdata/animated/sketch.exp.svg index 4ea57e1cb..847193776 100644 --- a/d2renderers/d2sketch/testdata/animated/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/animated/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="486" height="805" viewBox="-102 -105 486 805">aabbllmmnnoocciikkddgghhjjeeff1122 334455667788 - - - - - - - - - +aabbllmmnnoocciikkddgghhjjeeff1122 334455667788 + + + + + + + + + container

they did it in style

-

a header

+container

they did it in style

+

a header

a line of text and an

{
 	indented: "block",
@@ -805,8 +805,8 @@ width="516" height="689" viewBox="-102 -105 516 689">markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
+markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
- +
+ markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
+markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
- +
+ containerscloudtall cylinderclass- +containerscloudtall cylinderclass- num int- timeout @@ -823,8 +823,8 @@ width="2482" height="2675" viewBox="-102 -105 2482 2675">