diff --git a/d2layouts/d2sequence/constants.go b/d2layouts/d2sequence/constants.go index ff34e3db3..7dcf72d35 100644 --- a/d2layouts/d2sequence/constants.go +++ b/d2layouts/d2sequence/constants.go @@ -20,6 +20,8 @@ const SPAN_DEPTH_GROWTH_FACTOR = 8. // when a span has a single messages const MIN_SPAN_HEIGHT = 80. +const SPAN_MESSAGE_PAD = 16. + const LIFELINE_STROKE_WIDTH int = 2 const LIFELINE_STROKE_DASH int = 8 diff --git a/d2layouts/d2sequence/layout_test.go b/d2layouts/d2sequence/layout_test.go index 49d6a5a52..c54028a07 100644 --- a/d2layouts/d2sequence/layout_test.go +++ b/d2layouts/d2sequence/layout_test.go @@ -246,7 +246,7 @@ func TestSpansSequenceDiagram(t *testing.T) { } // Y diff of the 2 first edges - expectedHeight := g.Edges[1].Route[0].Y - g.Edges[0].Route[0].Y + expectedHeight := g.Edges[1].Route[0].Y - g.Edges[0].Route[0].Y + (2 * SPAN_MESSAGE_PAD) if a_t1.Height != expectedHeight { t.Fatalf("expected a.t1 height to be %.5f, got %.5f", expectedHeight, a_t1.Height) } @@ -268,7 +268,7 @@ func TestSpansSequenceDiagram(t *testing.T) { if a_t1.TopLeft.Y != b_t1.TopLeft.Y { t.Fatal("expected a.t1 and b.t1 to be placed at the same Y") } - if a_t1.TopLeft.Y != g.Edges[0].Route[0].Y { + if a_t1.TopLeft.Y-SPAN_MESSAGE_PAD != g.Edges[0].Route[0].Y { t.Fatal("expected a.t1 to be placed at the same Y of the first message") } diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index 719a57f6e..9e5206e58 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -210,12 +210,12 @@ func (sd *sequenceDiagram) placeSpans() { // if it is the same as the child top left, add some padding minY := math.Min(minMessageY, minChildY) - if minY == minChildY { - minY -= SPAN_DEPTH_GROWTH_FACTOR + if minY == minChildY || minY == minMessageY { + minY -= SPAN_MESSAGE_PAD } maxY := math.Max(maxMessageY, maxChildY) - if maxY == maxChildY { - maxY += SPAN_DEPTH_GROWTH_FACTOR + if maxY == maxChildY || maxY == maxMessageY { + maxY += SPAN_MESSAGE_PAD } height := math.Max(maxY-minY, MIN_SPAN_HEIGHT)