Fix edge padding

This commit is contained in:
Júlio César Batista 2022-12-02 16:02:34 -08:00
parent 1c3a73207f
commit 4c41794ea2
No known key found for this signature in database
GPG key ID: 10C4B861BF314878
3 changed files with 8 additions and 6 deletions

View file

@ -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

View file

@ -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")
}

View file

@ -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)