Skip to content

Commit 9b83a0f

Browse files
authored
Merge pull request #2041 from alixander/seq-bounding-box-improve
d2sequence: fix bounding box of sequence diagrams
2 parents 3d3bf05 + 95136ea commit 9b83a0f

File tree

6 files changed

+741
-1
lines changed

6 files changed

+741
-1
lines changed

d2layouts/d2sequence/sequence_diagram.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,19 @@ func (sd *sequenceDiagram) isActor(obj *d2graph.Object) bool {
646646
func (sd *sequenceDiagram) getWidth() float64 {
647647
// the layout is always placed starting at 0, so the width is just the last actor
648648
lastActor := sd.actors[len(sd.actors)-1]
649-
return lastActor.TopLeft.X + lastActor.Width
649+
rightmost := lastActor.TopLeft.X + lastActor.Width
650+
651+
for _, m := range sd.messages {
652+
for _, p := range m.Route {
653+
rightmost = math.Max(rightmost, p.X)
654+
}
655+
// Self referential messages may have labels that extend further
656+
if m.Src == m.Dst {
657+
rightmost = math.Max(rightmost, m.Route[1].X+float64(m.LabelDimensions.Width)/2.)
658+
}
659+
}
660+
661+
return rightmost
650662
}
651663

652664
func (sd *sequenceDiagram) getHeight() float64 {

e2etests/testdata/txtar/sequence-bounding-box/dagre/board.exp.json

Lines changed: 256 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)