cleanup
This commit is contained in:
parent
c32bfdda34
commit
9eaa4e98c4
3 changed files with 53 additions and 54 deletions
|
|
@ -22,31 +22,23 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
|
|||
return nil
|
||||
}
|
||||
|
||||
// Imagine the grpah has two long texts, one at top center and one at top left.
|
||||
// Imagine the graph has two long texts, one at top center and one at top left.
|
||||
// Top left should go left enough to not collide with center.
|
||||
// So place the center ones first, then the later ones will consider them for bounding box
|
||||
for _, processCenters := range []bool{true, false} {
|
||||
for _, obj := range constantNears {
|
||||
if strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
||||
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
||||
obj.TopLeft = geo.NewPoint(place(obj))
|
||||
}
|
||||
}
|
||||
for _, obj := range constantNears {
|
||||
if strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
||||
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
||||
// The z-index for constant nears does not matter, as it will not collide
|
||||
g.Objects = append(g.Objects, obj)
|
||||
obj.Parent.Children[obj.ID] = obj
|
||||
obj.Parent.ChildrenArray = append(obj.Parent.ChildrenArray, obj)
|
||||
}
|
||||
}
|
||||
|
||||
for _, obj := range constantNears {
|
||||
if !strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
||||
obj.TopLeft = geo.NewPoint(place(obj))
|
||||
}
|
||||
}
|
||||
for _, obj := range constantNears {
|
||||
if !strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
||||
// The z-index for constant nears does not matter, as it will not collide
|
||||
g.Objects = append(g.Objects, obj)
|
||||
}
|
||||
}
|
||||
|
||||
// These shapes skipped core layout, which means they also skipped label placements
|
||||
|
|
@ -106,6 +98,13 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra
|
|||
nears = append(nears, obj)
|
||||
g.Objects = append(g.Objects[:i], g.Objects[i+1:]...)
|
||||
i--
|
||||
delete(obj.Parent.Children, obj.ID)
|
||||
for i := 0; i < len(obj.Parent.ChildrenArray); i++ {
|
||||
if obj.Parent.ChildrenArray[i] == obj {
|
||||
obj.Parent.ChildrenArray = append(obj.Parent.ChildrenArray[:i], obj.Parent.ChildrenArray[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nears
|
||||
|
|
|
|||
48
e2etests/testdata/stable/constant_near/elk/board.exp.json
generated
vendored
48
e2etests/testdata/stable/constant_near/elk/board.exp.json
generated
vendored
|
|
@ -6,8 +6,8 @@
|
|||
"id": "x",
|
||||
"type": "",
|
||||
"pos": {
|
||||
"x": 1961,
|
||||
"y": 16
|
||||
"x": 12,
|
||||
"y": 12
|
||||
},
|
||||
"width": 113,
|
||||
"height": 126,
|
||||
|
|
@ -46,8 +46,8 @@
|
|||
"id": "y",
|
||||
"type": "",
|
||||
"pos": {
|
||||
"x": 1960,
|
||||
"y": 242
|
||||
"x": 12,
|
||||
"y": 238
|
||||
},
|
||||
"width": 114,
|
||||
"height": 126,
|
||||
|
|
@ -86,8 +86,8 @@
|
|||
"id": "The top of the mountain",
|
||||
"type": "text",
|
||||
"pos": {
|
||||
"x": 1936,
|
||||
"y": -28
|
||||
"x": -12,
|
||||
"y": -32
|
||||
},
|
||||
"width": 162,
|
||||
"height": 24,
|
||||
|
|
@ -126,8 +126,8 @@
|
|||
"id": "Joe",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 1809,
|
||||
"y": 129
|
||||
"x": -139,
|
||||
"y": 125
|
||||
},
|
||||
"width": 131,
|
||||
"height": 126,
|
||||
|
|
@ -166,8 +166,8 @@
|
|||
"id": "Donald",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 2094,
|
||||
"y": 129
|
||||
"x": 146,
|
||||
"y": 125
|
||||
},
|
||||
"width": 155,
|
||||
"height": 126,
|
||||
|
|
@ -206,8 +206,8 @@
|
|||
"id": "bottom",
|
||||
"type": "text",
|
||||
"pos": {
|
||||
"x": 1546,
|
||||
"y": 388
|
||||
"x": -402,
|
||||
"y": 384
|
||||
},
|
||||
"width": 943,
|
||||
"height": 130,
|
||||
|
|
@ -246,8 +246,8 @@
|
|||
"id": "i am top left",
|
||||
"type": "text",
|
||||
"pos": {
|
||||
"x": 1445,
|
||||
"y": -28
|
||||
"x": -503,
|
||||
"y": -32
|
||||
},
|
||||
"width": 81,
|
||||
"height": 24,
|
||||
|
|
@ -286,8 +286,8 @@
|
|||
"id": "i am top right",
|
||||
"type": "text",
|
||||
"pos": {
|
||||
"x": 2509,
|
||||
"y": -28
|
||||
"x": 560,
|
||||
"y": -32
|
||||
},
|
||||
"width": 91,
|
||||
"height": 24,
|
||||
|
|
@ -326,8 +326,8 @@
|
|||
"id": "i am bottom left",
|
||||
"type": "text",
|
||||
"pos": {
|
||||
"x": 1418,
|
||||
"y": 388
|
||||
"x": -530,
|
||||
"y": 384
|
||||
},
|
||||
"width": 108,
|
||||
"height": 24,
|
||||
|
|
@ -366,8 +366,8 @@
|
|||
"id": "i am bottom right",
|
||||
"type": "text",
|
||||
"pos": {
|
||||
"x": 2509,
|
||||
"y": 388
|
||||
"x": 560,
|
||||
"y": 384
|
||||
},
|
||||
"width": 118,
|
||||
"height": 24,
|
||||
|
|
@ -430,12 +430,12 @@
|
|||
"labelPercentage": 0,
|
||||
"route": [
|
||||
{
|
||||
"x": 2017.5,
|
||||
"y": 142
|
||||
"x": 69,
|
||||
"y": 138
|
||||
},
|
||||
{
|
||||
"x": 2017.5,
|
||||
"y": 242
|
||||
"x": 69,
|
||||
"y": 238
|
||||
}
|
||||
],
|
||||
"animated": false,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<svg
|
||||
style="background: white;"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
width="1409" height="746" viewBox="1318 -128 1409 746"><style type="text/css">
|
||||
width="1408" height="746" viewBox="-630 -132 1408 746"><style type="text/css">
|
||||
<![CDATA[
|
||||
.shape {
|
||||
shape-rendering: geometricPrecision;
|
||||
|
|
@ -774,16 +774,16 @@ width="1409" height="746" viewBox="1318 -128 1409 746"><style type="text/css">
|
|||
.md .contains-task-list:dir(rtl) .task-list-item-checkbox {
|
||||
margin: 0 -1.6em 0.25em 0.2em;
|
||||
}
|
||||
</style><g id="x"><g class="shape" ><rect x="1961" y="16" width="113" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="2017.500000" y="82.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">x</text></g><g id="y"><g class="shape" ><rect x="1960" y="242" width="114" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="2017.000000" y="308.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">y</text></g><g id="The top of the mountain"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="1936.000000" y="-28.000000" width="162" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>The top of the mountain</p>
|
||||
</div></foreignObject></g></g><g id="Joe"><g class="shape" ><path d="M 1940 255 H 1809 V 253.2093 C 1809 231.7209 1823.3851 212.3488 1846.0176 203.0698 C 1833.5505 195.5814 1826.0703 183.3721 1826.0703 170.0233 C 1826.0703 147.3953 1847.7438 129 1874.4041 129 C 1901.0644 129 1922.7379 147.3953 1922.7379 170.0233 C 1922.7379 183.3721 1915.4495 195.4186 1902.7906 203.2326 C 1925.4231 212.5117 1939.8082 231.8838 1939.8082 253.3721 V 255 H 1940 Z" style="fill:#E3E9FD;stroke:#0D32B2;opacity:1.000000;stroke-width:2;"/></g><text class="text-bold" x="1874.500000" y="195.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">Joe</text></g><g id="Donald"><g class="shape" ><path d="M 2249 255 H 2094 V 253.2093 C 2094 231.7209 2111.0205 212.3488 2137.7994 203.0698 C 2123.0483 195.5814 2114.1977 183.3721 2114.1977 170.0233 C 2114.1977 147.3953 2139.8419 129 2171.3865 129 C 2202.9312 129 2228.5754 147.3953 2228.5754 170.0233 C 2228.5754 183.3721 2219.9517 195.4186 2204.9736 203.2326 C 2231.7525 212.5117 2248.773 231.8838 2248.773 253.3721 V 255 H 2249 Z" style="fill:#E3E9FD;stroke:#0D32B2;opacity:1.000000;stroke-width:2;"/></g><text class="text-bold" x="2171.500000" y="195.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">Donald</text></g><g id="bottom"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="1546.000000" y="388.000000" width="943" height="130"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><h1>Cats, no less liquid than their shadows, offer no angles to the wind.</h1>
|
||||
</style><g id="x"><g class="shape" ><rect x="12" y="12" width="113" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="68.500000" y="78.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">x</text></g><g id="y"><g class="shape" ><rect x="12" y="238" width="114" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="69.000000" y="304.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">y</text></g><g id="The top of the mountain"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="-12.000000" y="-32.000000" width="162" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>The top of the mountain</p>
|
||||
</div></foreignObject></g></g><g id="Joe"><g class="shape" ><path d="M -8 251 H -139 V 249.2093 C -139 227.7209 -124.6149 208.3488 -101.9824 199.0698 C -114.4495 191.5814 -121.9297 179.3721 -121.9297 166.0233 C -121.9297 143.3953 -100.2562 125 -73.5959 125 C -46.9356 125 -25.2621 143.3953 -25.2621 166.0233 C -25.2621 179.3721 -32.5505 191.4186 -45.2094 199.2326 C -22.5769 208.5117 -8.1918 227.8838 -8.1918 249.3721 V 251 H -8 Z" style="fill:#E3E9FD;stroke:#0D32B2;opacity:1.000000;stroke-width:2;"/></g><text class="text-bold" x="-73.500000" y="191.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">Joe</text></g><g id="Donald"><g class="shape" ><path d="M 301 251 H 146 V 249.2093 C 146 227.7209 163.0205 208.3488 189.7994 199.0698 C 175.0483 191.5814 166.1977 179.3721 166.1977 166.0233 C 166.1977 143.3953 191.8419 125 223.3865 125 C 254.9312 125 280.5754 143.3953 280.5754 166.0233 C 280.5754 179.3721 271.9517 191.4186 256.9736 199.2326 C 283.7525 208.5117 300.773 227.8838 300.773 249.3721 V 251 H 301 Z" style="fill:#E3E9FD;stroke:#0D32B2;opacity:1.000000;stroke-width:2;"/></g><text class="text-bold" x="223.500000" y="191.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">Donald</text></g><g id="bottom"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="-402.000000" y="384.000000" width="943" height="130"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><h1>Cats, no less liquid than their shadows, offer no angles to the wind.</h1>
|
||||
<p>If we can't fix it, it ain't broke.</p>
|
||||
<p>Dieters live life in the fasting lane.</p>
|
||||
</div></foreignObject></g></g><g id="i am top left"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="1445.000000" y="-28.000000" width="81" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am top left</p>
|
||||
</div></foreignObject></g></g><g id="i am top right"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="2509.000000" y="-28.000000" width="91" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am top right</p>
|
||||
</div></foreignObject></g></g><g id="i am bottom left"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="1418.000000" y="388.000000" width="108" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am bottom left</p>
|
||||
</div></foreignObject></g></g><g id="i am bottom right"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="2509.000000" y="388.000000" width="118" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am bottom right</p>
|
||||
</div></foreignObject></g></g><g id="(x -> y)[0]"><marker id="mk-3990223579" markerWidth="10.000000" markerHeight="12.000000" refX="7.000000" refY="6.000000" viewBox="0.000000 0.000000 10.000000 12.000000" orient="auto" markerUnits="userSpaceOnUse"> <polygon class="connection" fill="#0D32B2" stroke-width="2" points="0.000000,0.000000 10.000000,6.000000 0.000000,12.000000" /> </marker><path d="M 2017.500000 144.000000 L 2017.500000 238.000000" class="connection" style="fill:none;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" marker-end="url(#mk-3990223579)" mask="url(#926909487)"/></g><mask id="926909487" maskUnits="userSpaceOnUse" x="-100" y="-100" width="1409" height="746">
|
||||
<rect x="-100" y="-100" width="1409" height="746" fill="white"></rect>
|
||||
</div></foreignObject></g></g><g id="i am top left"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="-503.000000" y="-32.000000" width="81" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am top left</p>
|
||||
</div></foreignObject></g></g><g id="i am top right"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="560.000000" y="-32.000000" width="91" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am top right</p>
|
||||
</div></foreignObject></g></g><g id="i am bottom left"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="-530.000000" y="384.000000" width="108" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am bottom left</p>
|
||||
</div></foreignObject></g></g><g id="i am bottom right"><g class="shape" ></g><g><foreignObject requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" x="560.000000" y="384.000000" width="118" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="md" style="background-color:transparent;color:#0A0F25;"><p>i am bottom right</p>
|
||||
</div></foreignObject></g></g><g id="(x -> y)[0]"><marker id="mk-3990223579" markerWidth="10.000000" markerHeight="12.000000" refX="7.000000" refY="6.000000" viewBox="0.000000 0.000000 10.000000 12.000000" orient="auto" markerUnits="userSpaceOnUse"> <polygon class="connection" fill="#0D32B2" stroke-width="2" points="0.000000,0.000000 10.000000,6.000000 0.000000,12.000000" /> </marker><path d="M 69.000000 140.000000 L 69.000000 234.000000" class="connection" style="fill:none;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" marker-end="url(#mk-3990223579)" mask="url(#565755562)"/></g><mask id="565755562" maskUnits="userSpaceOnUse" x="-100" y="-100" width="1408" height="746">
|
||||
<rect x="-100" y="-100" width="1408" height="746" fill="white"></rect>
|
||||
|
||||
</mask><style type="text/css"><![CDATA[
|
||||
.text {
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 663 KiB After Width: | Height: | Size: 663 KiB |
Loading…
Reference in a new issue