This commit is contained in:
Alexander Wang 2023-02-10 14:02:57 -08:00
parent 9fad105822
commit af11b4ddb5
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 15 additions and 13 deletions

View file

@ -345,8 +345,10 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
continue continue
} }
subtract := go2.Min(rootAttrs.ranksep/2, *obj.LabelHeight+label.PADDING)
// This was artifically added to make dagre consider label height // 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{}) movedEdges := make(map[*d2graph.Edge]struct{})
for _, e := range g.Edges { for _, e := range g.Edges {
@ -371,7 +373,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
currDst = currDst.Parent currDst = currDst.Parent
} }
if isSrcDesc && isDstDesc { if isSrcDesc && isDstDesc {
stepSize := float64(*obj.LabelHeight) + label.PADDING stepSize := float64(subtract)
if e.Src != obj || e.Dst != obj { if e.Src != obj || e.Dst != obj {
stepSize /= 2. stepSize /= 2.
} }
@ -388,7 +390,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
curr := q[0] curr := q[0]
q = q[1:] q = q[1:]
stepSize := float64(*obj.LabelHeight) + label.PADDING stepSize := float64(subtract)
if curr != obj { if curr != obj {
stepSize /= 2. stepSize /= 2.
} }

View file

@ -7,10 +7,10 @@
"type": "rectangle", "type": "rectangle",
"pos": { "pos": {
"x": 0, "x": 0,
"y": 130 "y": 65
}, },
"width": 404, "width": 404,
"height": 446, "height": 511,
"opacity": 1, "opacity": 1,
"strokeDash": 0, "strokeDash": 0,
"strokeWidth": 2, "strokeWidth": 2,
@ -48,10 +48,10 @@
"type": "rectangle", "type": "rectangle",
"pos": { "pos": {
"x": 40, "x": 40,
"y": 216 "y": 162
}, },
"width": 324, "width": 324,
"height": 360, "height": 381,
"opacity": 1, "opacity": 1,
"strokeDash": 0, "strokeDash": 0,
"strokeWidth": 2, "strokeWidth": 2,
@ -89,7 +89,7 @@
"type": "rectangle", "type": "rectangle",
"pos": { "pos": {
"x": 80, "x": 80,
"y": 284 "y": 241
}, },
"width": 244, "width": 244,
"height": 270, "height": 270,
@ -130,7 +130,7 @@
"type": "rectangle", "type": "rectangle",
"pos": { "pos": {
"x": 120, "x": 120,
"y": 352 "y": 309
}, },
"width": 164, "width": 164,
"height": 160, "height": 160,
@ -171,7 +171,7 @@
"type": "rectangle", "type": "rectangle",
"pos": { "pos": {
"x": 170, "x": 170,
"y": 404 "y": 361
}, },
"width": 64, "width": 64,
"height": 56, "height": 56,

View file

@ -3,7 +3,7 @@
id="d2-svg" id="d2-svg"
style="background: white;" style="background: white;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="652" height="778" viewBox="-124 -100 652 778"><style type="text/css"> width="652" height="843" viewBox="-124 -165 652 843"><style type="text/css">
<![CDATA[ <![CDATA[
.shape { .shape {
shape-rendering: geometricPrecision; shape-rendering: geometricPrecision;
@ -39,8 +39,8 @@ width="652" height="778" viewBox="-124 -100 652 778"><style type="text/css">
svgEl.setAttribute("height", height * ratio - 16); svgEl.setAttribute("height", height * ratio - 16);
} }
}); });
]]></script><g id="ninety nine"><g class="shape" ><rect x="0" y="130" width="404" height="446" style="fill:#E3E9FD;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="99.000000" style="text-anchor:middle;font-size:99px;fill:#0A0F25">ninety nine</text></g><g id="ninety nine.sixty four"><g class="shape" ><rect x="40" y="216" width="324" height="360" style="fill:#EDF0FD;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="194.000000" style="text-anchor:middle;font-size:64px;fill:#0A0F25">sixty four</text></g><g id="ninety nine.sixty four.thirty two"><g class="shape" ><rect x="80" y="284" width="244" height="270" style="fill:#F7F8FE;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="270.000000" style="text-anchor:middle;font-size:32px;fill:#0A0F25">thirty two</text></g><g id="ninety nine.sixty four.thirty two.sixteen"><g class="shape" ><rect x="120" y="352" width="164" height="160" style="fill:#FFFFFF;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="342.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">sixteen</text></g><g id="ninety nine.sixty four.thirty two.sixteen.eight"><g class="shape" ><rect x="170" y="404" width="64" height="56" style="fill:#FFFFFF;stroke:#0D32B2;stroke-width:2;" /></g><text class="text-bold" x="202.000000" y="434.500000" style="text-anchor:middle;font-size:8px;fill:#0A0F25">eight</text></g><mask id="3442700494" maskUnits="userSpaceOnUse" x="-100" y="-100" width="652" height="778"> ]]></script><g id="ninety nine"><g class="shape" ><rect x="0" y="65" width="404" height="511" style="fill:#E3E9FD;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="34.000000" style="text-anchor:middle;font-size:99px;fill:#0A0F25">ninety nine</text></g><g id="ninety nine.sixty four"><g class="shape" ><rect x="40" y="162" width="324" height="381" style="fill:#EDF0FD;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="140.000000" style="text-anchor:middle;font-size:64px;fill:#0A0F25">sixty four</text></g><g id="ninety nine.sixty four.thirty two"><g class="shape" ><rect x="80" y="241" width="244" height="270" style="fill:#F7F8FE;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="227.000000" style="text-anchor:middle;font-size:32px;fill:#0A0F25">thirty two</text></g><g id="ninety nine.sixty four.thirty two.sixteen"><g class="shape" ><rect x="120" y="309" width="164" height="160" style="fill:#FFFFFF;stroke:#0D32B2;stroke-width:2;" /></g><text class="text" x="202.000000" y="299.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">sixteen</text></g><g id="ninety nine.sixty four.thirty two.sixteen.eight"><g class="shape" ><rect x="170" y="361" width="64" height="56" style="fill:#FFFFFF;stroke:#0D32B2;stroke-width:2;" /></g><text class="text-bold" x="202.000000" y="391.500000" style="text-anchor:middle;font-size:8px;fill:#0A0F25">eight</text></g><mask id="674103652" maskUnits="userSpaceOnUse" x="-100" y="-100" width="652" height="843">
<rect x="-100" y="-100" width="652" height="778" fill="white"></rect> <rect x="-100" y="-100" width="652" height="843" fill="white"></rect>
</mask><style type="text/css"><![CDATA[ </mask><style type="text/css"><![CDATA[
.text { .text {

Before

Width:  |  Height:  |  Size: 649 KiB

After

Width:  |  Height:  |  Size: 649 KiB