2022-11-21 01:55:22PM

This commit is contained in:
Alexander Wang 2022-11-21 13:55:22 -08:00
parent 6f8017d16c
commit d974e85c72
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 7 additions and 4 deletions

View file

@ -16,6 +16,7 @@ import (
"oss.terrastruct.com/xdefer" "oss.terrastruct.com/xdefer"
"oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/geo"
"oss.terrastruct.com/d2/lib/go2" "oss.terrastruct.com/d2/lib/go2"
"oss.terrastruct.com/d2/lib/label" "oss.terrastruct.com/d2/lib/label"
@ -240,6 +241,8 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
if obj.LabelWidth != nil && obj.LabelHeight != nil { if obj.LabelWidth != nil && obj.LabelHeight != nil {
if len(obj.ChildrenArray) > 0 { if len(obj.ChildrenArray) > 0 {
obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter))
} else if obj.Attributes.Shape.Value == d2target.ShapeImage {
obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter))
} else { } else {
obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
} }

View file

@ -49,7 +49,7 @@
"underline": false, "underline": false,
"labelWidth": 13, "labelWidth": 13,
"labelHeight": 26, "labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER" "labelPosition": "OUTSIDE_TOP_CENTER"
}, },
{ {
"id": "b", "id": "b",
@ -99,7 +99,7 @@
"underline": false, "underline": false,
"labelWidth": 13, "labelWidth": 13,
"labelHeight": 26, "labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER" "labelPosition": "OUTSIDE_TOP_CENTER"
} }
], ],
"connections": [ "connections": [

View file

@ -2,7 +2,7 @@
<svg <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="556" height="328" viewBox="-88 -88 556 328"><style type="text/css"> width="556" height="359" viewBox="-88 -119 556 359"><style type="text/css">
<![CDATA[ <![CDATA[
.shape { .shape {
shape-rendering: geometricPrecision; shape-rendering: geometricPrecision;
@ -14,7 +14,7 @@ width="556" height="328" viewBox="-88 -88 556 328"><style type="text/css">
} }
]]> ]]>
</style><g class="shape" ><image href="https://icons.terrastruct.com/essentials/004-picture.svg" x="12" y="12" width="128" height="128" style="fill:#FFFFFF;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="76.000000" y="79.000000" style="text-anchor:middle;font-size:16px;fill:black">a</text><g class="shape" ><image href="https://icons.terrastruct.com/essentials/004-picture.svg" x="240" y="12" width="128" height="128" style="fill:#FFFFFF;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="304.000000" y="79.000000" style="text-anchor:middle;font-size:16px;fill:black">b</text><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 142.000000 76.000000 L 236.000000 76.000000" class="connection" style="fill:none;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" marker-end="url(#mk-3990223579)" /><style type="text/css"><![CDATA[ </style><g class="shape" ><image href="https://icons.terrastruct.com/essentials/004-picture.svg" x="12" y="12" width="128" height="128" style="fill:#FFFFFF;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="76.000000" y="-3.000000" style="text-anchor:middle;font-size:16px;fill:black">a</text><g class="shape" ><image href="https://icons.terrastruct.com/essentials/004-picture.svg" x="240" y="12" width="128" height="128" style="fill:#FFFFFF;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="304.000000" y="-3.000000" style="text-anchor:middle;font-size:16px;fill:black">b</text><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 142.000000 76.000000 L 236.000000 76.000000" class="connection" style="fill:none;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" marker-end="url(#mk-3990223579)" /><style type="text/css"><![CDATA[
.text-bold { .text-bold {
font-family: "font-bold"; font-family: "font-bold";
} }

Before

Width:  |  Height:  |  Size: 324 KiB

After

Width:  |  Height:  |  Size: 324 KiB