From 641850cf5ea1475ccdf7dc8a941320f20ef37cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20C=C3=A9sar=20Batista?= Date: Fri, 2 Dec 2022 13:54:40 -0800 Subject: [PATCH] change spans base size and growth factor --- d2layouts/d2sequence/constants.go | 6 +++--- d2layouts/d2sequence/layout_test.go | 4 ++-- d2layouts/d2sequence/sequence_diagram.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/d2layouts/d2sequence/constants.go b/d2layouts/d2sequence/constants.go index efd2d52db..62a8132ec 100644 --- a/d2layouts/d2sequence/constants.go +++ b/d2layouts/d2sequence/constants.go @@ -12,10 +12,10 @@ const MIN_ACTOR_DISTANCE = 200. const MIN_MESSAGE_DISTANCE = 100. // default size -const SPAN_WIDTH = 20. +const SPAN_BASE_WIDTH = 12. // as the spans start getting nested, their size grows -const SPAN_DEPTH_GROW_FACTOR = 10. +const SPAN_DEPTH_GROWTH_FACTOR = 8. // when a span has a single messages -const MIN_SPAN_HEIGHT = MIN_MESSAGE_DISTANCE / 2. +const MIN_SPAN_HEIGHT = 80. diff --git a/d2layouts/d2sequence/layout_test.go b/d2layouts/d2sequence/layout_test.go index 226584a45..49d6a5a52 100644 --- a/d2layouts/d2sequence/layout_test.go +++ b/d2layouts/d2sequence/layout_test.go @@ -251,8 +251,8 @@ func TestSpansSequenceDiagram(t *testing.T) { t.Fatalf("expected a.t1 height to be %.5f, got %.5f", expectedHeight, a_t1.Height) } - if a_t1.Width != SPAN_WIDTH { - t.Fatalf("expected span width to be %.5f, got %.5f", SPAN_WIDTH, a_t1.Width) + if a_t1.Width != SPAN_BASE_WIDTH { + t.Fatalf("expected span width to be %.5f, got %.5f", SPAN_BASE_WIDTH, a_t1.Width) } // check positions diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index 5664cb1db..9a20692e0 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -201,16 +201,16 @@ 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_GROW_FACTOR + minY -= SPAN_DEPTH_GROWTH_FACTOR } maxY := math.Max(maxMessageY, maxChildY) if maxY == maxChildY { - maxY += SPAN_DEPTH_GROW_FACTOR + maxY += SPAN_DEPTH_GROWTH_FACTOR } height := math.Max(maxY-minY, MIN_SPAN_HEIGHT) // -2 because the actors count as level 1 making the first level span getting 2*SPAN_DEPTH_GROW_FACTOR - width := SPAN_WIDTH + (float64(span.Level()-2) * SPAN_DEPTH_GROW_FACTOR) + width := SPAN_BASE_WIDTH + (float64(span.Level()-2) * SPAN_DEPTH_GROWTH_FACTOR) x := rankToX[sd.objectRank[span]] - (width / 2.) span.Box = geo.NewBox(geo.NewPoint(x, minY), width, height) span.ZIndex = 1