From 641c809464e49b44c860a4de8817c050e9a7948d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20C=C3=A9sar=20Batista?= Date: Wed, 30 Nov 2022 13:41:20 -0800 Subject: [PATCH] Fix span rendering order --- d2layouts/d2sequence/layout.go | 1 + d2layouts/d2sequence/layout_test.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/d2layouts/d2sequence/layout.go b/d2layouts/d2sequence/layout.go index b77037d60..359463892 100644 --- a/d2layouts/d2sequence/layout.go +++ b/d2layouts/d2sequence/layout.go @@ -218,6 +218,7 @@ func (sd *sequenceDiagram) placeSpans() { width := SPAN_WIDTH + (float64(span.Level()-2) * SPAN_DEPTH_GROW_FACTOR) x := rankToX[sd.objectRank[span]] - (width / 2.) span.Box = geo.NewBox(geo.NewPoint(x, minY), width, height) + span.ZIndex = 1 } } diff --git a/d2layouts/d2sequence/layout_test.go b/d2layouts/d2sequence/layout_test.go index 26d88f9fe..7935b71da 100644 --- a/d2layouts/d2sequence/layout_test.go +++ b/d2layouts/d2sequence/layout_test.go @@ -208,6 +208,12 @@ func TestSpansSequenceDiagram(t *testing.T) { t.Fatalf("expected a.t1 and b.t1 to have the same height, got %.5f and %.5f", a_t1.Height, b_t1.Height) } + for _, span := range []*d2graph.Object{a_t1, a_t2, b_t1} { + if span.ZIndex != 1 { + t.Fatalf("expected span ZIndex=1, got %d", span.ZIndex) + } + } + // Y diff of the 2 first edges expectedHeight := g.Edges[1].Route[0].Y - g.Edges[0].Route[0].Y + (2 * SPAN_EDGE_PAD) if a_t1.Height != expectedHeight {