use more accurate icon bounding
This commit is contained in:
parent
cea18eaf21
commit
e1b407ea52
3 changed files with 16 additions and 10 deletions
|
|
@ -91,10 +91,16 @@ func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point) {
|
|||
contentBox := geo.NewBox(geo.NewPoint(0, 0), float64(targetShape.Width), float64(targetShape.Height))
|
||||
s := shape.NewShape(targetShape.Type, contentBox)
|
||||
size := GetIconSize(s.GetInnerBox(), targetShape.IconPosition)
|
||||
y1 = go2.Min(y1, targetShape.Pos.Y-label.PADDING-size)
|
||||
x1 = go2.Min(x1, targetShape.Pos.X-label.PADDING-size)
|
||||
y2 = go2.Max(y2, targetShape.Pos.Y+label.PADDING+size)
|
||||
x2 = go2.Max(x2, targetShape.Pos.X+label.PADDING+size)
|
||||
|
||||
if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_TOP") {
|
||||
y1 = go2.Min(y1, targetShape.Pos.Y-label.PADDING-size)
|
||||
} else if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_BOTTOM") {
|
||||
y2 = go2.Max(y2, targetShape.Pos.Y+label.PADDING+size)
|
||||
} else if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_LEFT") {
|
||||
x1 = go2.Min(x1, targetShape.Pos.X-label.PADDING-size)
|
||||
} else if strings.HasPrefix(targetShape.IconPosition, "OUTSIDE_RIGHT") {
|
||||
x2 = go2.Max(x2, targetShape.Pos.X+label.PADDING+size)
|
||||
}
|
||||
}
|
||||
|
||||
if targetShape.Label != "" {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><svg id="d2-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="391" height="514" viewBox="-69 -28 391 514"><rect x="-69.000000" y="-28.000000" width="391.000000" height="514.000000" class=" fill-N7" /><style type="text/css"><![CDATA[
|
||||
<?xml version="1.0" encoding="utf-8"?><svg id="d2-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="324" height="514" viewBox="-2 -28 324 514"><rect x="-2.000000" y="-28.000000" width="324.000000" height="514.000000" class=" fill-N7" /><style type="text/css"><![CDATA[
|
||||
.text {
|
||||
font-family: "font-regular";
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
svgEl.setAttribute("height", height * ratio - 16);
|
||||
}
|
||||
});
|
||||
]]></script><g id="vpc"><g class="shape" ><rect x="0.000000" y="41.000000" width="320.000000" height="443.000000" stroke="green" fill="white" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/aws%2F_Group%20Icons%2FVirtual-private-cloud-VPC_light-bg.svg" x="-5.000000" y="-28.000000" width="64" height="64" /><text x="212.000000" y="28.000000" fill="green" class="text" style="text-anchor:middle;font-size:28px">VPC 1 10.1.0.0./16</text></g><g id="vpc.az"><g class="shape" ><rect x="20.000000" y="117.000000" width="280.000000" height="326.000000" stroke="blue" fill="white" style="stroke-width:2;stroke-dasharray:6.000000,5.919384;" /></g><text x="160.000000" y="105.000000" fill="blue" class="text" style="text-anchor:middle;font-size:24px">Availability Zone A</text></g><g id="vpc.az.firewall"><g class="shape" ><rect x="40.000000" y="191.000000" width="240.000000" height="209.000000" stroke="purple" fill="#e1d5e7" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/aws%2FNetworking%20&%20Content%20Delivery%2FAmazon-Route-53_Hosted-Zone_light-bg.svg" x="35.000000" y="122.000000" width="64" height="64" /><text x="202.500000" y="180.000000" fill="purple" class="text" style="text-anchor:middle;font-size:20px">Firewall Subnet A</text></g><g id="vpc.az.firewall.ec2"><g class="shape" ><rect x="80.000000" y="237.000000" width="160.000000" height="118.000000" class=" stroke-B1 fill-N7" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/aws%2FCompute%2F_Instance%2FAmazon-EC2_C4-Instance_light-bg.svg" x="130.500000" y="266.500000" width="59" height="59" /><text x="160.000000" y="258.000000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">EC2 Instance</text></g><mask id="2222372815" maskUnits="userSpaceOnUse" x="-69" y="-28" width="391" height="514">
|
||||
<rect x="-69" y="-28" width="391" height="514" fill="white"></rect>
|
||||
]]></script><g id="vpc"><g class="shape" ><rect x="0.000000" y="41.000000" width="320.000000" height="443.000000" stroke="green" fill="white" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/aws%2F_Group%20Icons%2FVirtual-private-cloud-VPC_light-bg.svg" x="-5.000000" y="-28.000000" width="64" height="64" /><text x="212.000000" y="28.000000" fill="green" class="text" style="text-anchor:middle;font-size:28px">VPC 1 10.1.0.0./16</text></g><g id="vpc.az"><g class="shape" ><rect x="20.000000" y="117.000000" width="280.000000" height="326.000000" stroke="blue" fill="white" style="stroke-width:2;stroke-dasharray:6.000000,5.919384;" /></g><text x="160.000000" y="105.000000" fill="blue" class="text" style="text-anchor:middle;font-size:24px">Availability Zone A</text></g><g id="vpc.az.firewall"><g class="shape" ><rect x="40.000000" y="191.000000" width="240.000000" height="209.000000" stroke="purple" fill="#e1d5e7" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/aws%2FNetworking%20&%20Content%20Delivery%2FAmazon-Route-53_Hosted-Zone_light-bg.svg" x="35.000000" y="122.000000" width="64" height="64" /><text x="202.500000" y="180.000000" fill="purple" class="text" style="text-anchor:middle;font-size:20px">Firewall Subnet A</text></g><g id="vpc.az.firewall.ec2"><g class="shape" ><rect x="80.000000" y="237.000000" width="160.000000" height="118.000000" class=" stroke-B1 fill-N7" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/aws%2FCompute%2F_Instance%2FAmazon-EC2_C4-Instance_light-bg.svg" x="130.500000" y="266.500000" width="59" height="59" /><text x="160.000000" y="258.000000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">EC2 Instance</text></g><mask id="2222372815" maskUnits="userSpaceOnUse" x="-2" y="-28" width="324" height="514">
|
||||
<rect x="-2" y="-28" width="324" height="514" fill="white"></rect>
|
||||
|
||||
</mask></svg>
|
||||
|
Before Width: | Height: | Size: 653 KiB After Width: | Height: | Size: 653 KiB |
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><svg id="d2-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="244" height="626" viewBox="-69 -26 244 626"><rect x="-69.000000" y="-26.000000" width="244.000000" height="626.000000" class=" fill-N7" /><style type="text/css"><![CDATA[
|
||||
<?xml version="1.0" encoding="utf-8"?><svg id="d2-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="177" height="626" viewBox="-2 -26 177 626"><rect x="-2.000000" y="-26.000000" width="177.000000" height="626.000000" class=" fill-N7" /><style type="text/css"><![CDATA[
|
||||
.text {
|
||||
font-family: "font-regular";
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
svgEl.setAttribute("height", height * ratio - 16);
|
||||
}
|
||||
});
|
||||
]]></script><g id="a"><g class="shape" ><rect x="0.000000" y="43.000000" width="173.000000" height="555.000000" class=" stroke-B1 fill-B4" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/essentials/004-picture.svg" x="-5.000000" y="-26.000000" width="64" height="64" /><text x="120.000000" y="30.000000" class="text fill-N1" style="text-anchor:middle;font-size:30px">Big font</text></g><g id="a.a"><g class="shape" ><rect x="20.000000" y="107.000000" width="133.000000" height="130.000000" class=" stroke-B1 fill-B5" style="stroke-width:2;" /></g><text x="86.500000" y="95.000000" class="text fill-N1" style="text-anchor:middle;font-size:24px">a</text></g><g id="a.b"><g class="shape" ><rect x="60.000000" y="337.000000" width="53.000000" height="66.000000" class=" stroke-B1 fill-B5" style="stroke-width:2;" /></g><text x="86.500000" y="375.500000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">b</text></g><g id="a.c"><g class="shape" ><rect x="60.000000" y="503.000000" width="53.000000" height="66.000000" class=" stroke-B1 fill-B5" style="stroke-width:2;" /></g><text x="86.500000" y="541.500000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">c</text></g><g id="a.a.a"><g class="shape" ><rect x="60.000000" y="139.000000" width="53.000000" height="66.000000" class=" stroke-B1 fill-B6" style="stroke-width:2;" /></g><text x="86.500000" y="177.500000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">a</text></g><g id="a.(a -> b)[0]"><marker id="mk-3488378134" 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 points="0.000000,0.000000 10.000000,6.000000 0.000000,12.000000" class="connection fill-B1" stroke-width="2" /> </marker><path d="M 86.500000 239.500000 C 86.500000 277.500000 86.500000 297.500000 86.500000 333.500000" fill="none" class="connection stroke-B1" style="stroke-width:2;" marker-end="url(#mk-3488378134)" mask="url(#3160218901)" /></g><g id="a.(b -> c)[0]"><path d="M 86.500000 405.500000 C 86.500000 443.500000 86.500000 463.500000 86.500000 499.500000" fill="none" class="connection stroke-B1" style="stroke-width:2;" marker-end="url(#mk-3488378134)" mask="url(#3160218901)" /></g><mask id="3160218901" maskUnits="userSpaceOnUse" x="-69" y="-26" width="244" height="626">
|
||||
<rect x="-69" y="-26" width="244" height="626" fill="white"></rect>
|
||||
]]></script><g id="a"><g class="shape" ><rect x="0.000000" y="43.000000" width="173.000000" height="555.000000" class=" stroke-B1 fill-B4" style="stroke-width:2;" /></g><image href="https://icons.terrastruct.com/essentials/004-picture.svg" x="-5.000000" y="-26.000000" width="64" height="64" /><text x="120.000000" y="30.000000" class="text fill-N1" style="text-anchor:middle;font-size:30px">Big font</text></g><g id="a.a"><g class="shape" ><rect x="20.000000" y="107.000000" width="133.000000" height="130.000000" class=" stroke-B1 fill-B5" style="stroke-width:2;" /></g><text x="86.500000" y="95.000000" class="text fill-N1" style="text-anchor:middle;font-size:24px">a</text></g><g id="a.b"><g class="shape" ><rect x="60.000000" y="337.000000" width="53.000000" height="66.000000" class=" stroke-B1 fill-B5" style="stroke-width:2;" /></g><text x="86.500000" y="375.500000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">b</text></g><g id="a.c"><g class="shape" ><rect x="60.000000" y="503.000000" width="53.000000" height="66.000000" class=" stroke-B1 fill-B5" style="stroke-width:2;" /></g><text x="86.500000" y="541.500000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">c</text></g><g id="a.a.a"><g class="shape" ><rect x="60.000000" y="139.000000" width="53.000000" height="66.000000" class=" stroke-B1 fill-B6" style="stroke-width:2;" /></g><text x="86.500000" y="177.500000" class="text-bold fill-N1" style="text-anchor:middle;font-size:16px">a</text></g><g id="a.(a -> b)[0]"><marker id="mk-3488378134" 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 points="0.000000,0.000000 10.000000,6.000000 0.000000,12.000000" class="connection fill-B1" stroke-width="2" /> </marker><path d="M 86.500000 239.500000 C 86.500000 277.500000 86.500000 297.500000 86.500000 333.500000" fill="none" class="connection stroke-B1" style="stroke-width:2;" marker-end="url(#mk-3488378134)" mask="url(#3160218901)" /></g><g id="a.(b -> c)[0]"><path d="M 86.500000 405.500000 C 86.500000 443.500000 86.500000 463.500000 86.500000 499.500000" fill="none" class="connection stroke-B1" style="stroke-width:2;" marker-end="url(#mk-3488378134)" mask="url(#3160218901)" /></g><mask id="3160218901" maskUnits="userSpaceOnUse" x="-2" y="-26" width="177" height="626">
|
||||
<rect x="-2" y="-26" width="177" height="626" fill="white"></rect>
|
||||
|
||||
</mask></svg>
|
||||
|
Before Width: | Height: | Size: 654 KiB After Width: | Height: | Size: 654 KiB |
Loading…
Reference in a new issue