Skip to content

Commit

Permalink
fix bounding boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Dec 31, 2022
1 parent 642df43 commit 510c102
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ This release also gives more power to configure layouts. `width` and `height` ar

#### Features 🚀

- Tooltips can be set on shapes. See [https://d2lang.com/tour/tooltips](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548)
- Links can be set on shapes. See [https://d2lang.com/tour/tooltips](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548)
- Tooltips can be set on shapes. See [https://d2lang.com/tour/interactive](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548)
- Links can be set on shapes. See [https://d2lang.com/tour/interactive](https://d2lang.com/tour/interactive). [#548](https://github.com/terrastruct/d2/pull/548)
- The `width` and `height` attributes are no longer restricted to images and can be applied to non-container shapes. [#498](https://github.com/terrastruct/d2/pull/498)
- Layout engine options are exposed and configurable. See individual layout pages on [https://d2lang.com/tour/layouts](https://d2lang.com/tour/layouts) for list of configurations. [#563](https://github.com/terrastruct/d2/pull/563)

Expand Down
3 changes: 2 additions & 1 deletion d2renderers/d2svg/appendix/appendix.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func generateAppendix(diagram *d2target.Diagram, ruler *textmeasure.Ruler, svg s
}
}
}
totalHeight += SPACER

return fmt.Sprintf(`<g x="%d" y="%d" width="%d" height="100%%">%s</g>
`, tl.X, br.Y, (br.X - tl.X), strings.Join(lines, "\n")), maxWidth, totalHeight
Expand Down Expand Up @@ -182,5 +183,5 @@ func generateLine(i, y int, text string, ruler *textmeasure.Ruler) (string, int,
line += fmt.Sprintf(`<text class="text" x="%d" y="%d" style="font-size: %dpx;">%s</text>`,
ICON_RADIUS*3, y, FONT_SIZE, d2svg.RenderText(text, ICON_RADIUS*3, float64(dims.Height)))

return line, dims.Width + ICON_RADIUS*3, dims.Height
return line, dims.Width + ICON_RADIUS*3, go2.IntMax(dims.Height, ICON_RADIUS*2)
}
14 changes: 10 additions & 4 deletions d2target/d2target.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point) {
y2 := int(math.MinInt32)

for _, targetShape := range diagram.Shapes {
x1 = go2.Min(x1, targetShape.Pos.X)
y1 = go2.Min(y1, targetShape.Pos.Y)
x2 = go2.Max(x2, targetShape.Pos.X+targetShape.Width)
y2 = go2.Max(y2, targetShape.Pos.Y+targetShape.Height)
x1 = go2.Min(x1, targetShape.Pos.X-targetShape.StrokeWidth)
y1 = go2.Min(y1, targetShape.Pos.Y-targetShape.StrokeWidth)
x2 = go2.Max(x2, targetShape.Pos.X+targetShape.Width+targetShape.StrokeWidth)
y2 = go2.Max(y2, targetShape.Pos.Y+targetShape.Height+targetShape.StrokeWidth)

if targetShape.Tooltip != "" || targetShape.Link != "" {
// 16 is the icon radius
y1 = go2.Min(y1, targetShape.Pos.Y-targetShape.StrokeWidth-16)
x2 = go2.Max(x2, targetShape.Pos.X+targetShape.StrokeWidth+targetShape.Width+16)
}

if targetShape.Label != "" {
labelPosition := label.Position(targetShape.LabelPosition)
Expand Down

0 comments on commit 510c102

Please sign in to comment.