diff --git a/d2target/d2target.go b/d2target/d2target.go index f4884008c..942cef08a 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -87,6 +87,16 @@ func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point) { x2 = go2.Max(x2, targetShape.Pos.X+MULTIPLE_OFFSET+targetShape.Width+targetShape.StrokeWidth) } + if targetShape.Icon != nil && label.Position(targetShape.IconPosition).IsOutside() { + 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 targetShape.Label != "" { labelPosition := label.Position(targetShape.LabelPosition) if !labelPosition.IsOutside() {