Skip to content

Commit

Permalink
Merge pull request #2041 from alixander/seq-bounding-box-improve
Browse files Browse the repository at this point in the history
d2sequence: fix bounding box of sequence diagrams
  • Loading branch information
alixander authored Aug 3, 2024
2 parents 3d3bf05 + 95136ea commit 9b83a0f
Show file tree
Hide file tree
Showing 6 changed files with 741 additions and 1 deletion.
14 changes: 13 additions & 1 deletion d2layouts/d2sequence/sequence_diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,19 @@ func (sd *sequenceDiagram) isActor(obj *d2graph.Object) bool {
func (sd *sequenceDiagram) getWidth() float64 {
// the layout is always placed starting at 0, so the width is just the last actor
lastActor := sd.actors[len(sd.actors)-1]
return lastActor.TopLeft.X + lastActor.Width
rightmost := lastActor.TopLeft.X + lastActor.Width

for _, m := range sd.messages {
for _, p := range m.Route {
rightmost = math.Max(rightmost, p.X)
}
// Self referential messages may have labels that extend further
if m.Src == m.Dst {
rightmost = math.Max(rightmost, m.Route[1].X+float64(m.LabelDimensions.Width)/2.)
}
}

return rightmost
}

func (sd *sequenceDiagram) getHeight() float64 {
Expand Down
256 changes: 256 additions & 0 deletions e2etests/testdata/txtar/sequence-bounding-box/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9b83a0f

Please sign in to comment.