Add vertical pad to activation boxes

This commit is contained in:
Júlio César Batista 2022-11-29 12:57:07 -08:00
parent a0c0546059
commit d002531768
No known key found for this signature in database
GPG key ID: 10C4B861BF314878
3 changed files with 7 additions and 3 deletions

View file

@ -15,7 +15,7 @@ const MIN_EDGE_DISTANCE = 100.
const ACTIVATION_BOX_WIDTH = 20. const ACTIVATION_BOX_WIDTH = 20.
// small pad so that edges don't touch lifelines and activation boxes // small pad so that edges don't touch lifelines and activation boxes
const ACTIVATION_BOX_EDGE_PAD = 2. const ACTIVATION_BOX_EDGE_PAD = 5.
// as the activation boxes start getting nested, their size grows // as the activation boxes start getting nested, their size grows
const ACTIVATION_BOX_DEPTH_GROW_FACTOR = 10. const ACTIVATION_BOX_DEPTH_GROW_FACTOR = 10.

View file

@ -203,10 +203,14 @@ func (sd *sequenceDiagram) placeActivationBoxes() {
minY := math.Min(minEdgeY, minChildY) minY := math.Min(minEdgeY, minChildY)
if minY == minChildY { if minY == minChildY {
minY -= ACTIVATION_BOX_DEPTH_GROW_FACTOR minY -= ACTIVATION_BOX_DEPTH_GROW_FACTOR
} else {
minY -= ACTIVATION_BOX_EDGE_PAD
} }
maxY := math.Max(maxEdgeY, maxChildY) maxY := math.Max(maxEdgeY, maxChildY)
if maxY == maxChildY { if maxY == maxChildY {
maxY += ACTIVATION_BOX_DEPTH_GROW_FACTOR maxY += ACTIVATION_BOX_DEPTH_GROW_FACTOR
} else {
maxY += ACTIVATION_BOX_EDGE_PAD
} }
height := math.Max(maxY-minY, DEFAULT_ACTIVATION_BOX_HEIGHT) height := math.Max(maxY-minY, DEFAULT_ACTIVATION_BOX_HEIGHT)

View file

@ -209,7 +209,7 @@ func TestActivationBoxesSequenceDiagram(t *testing.T) {
} }
// Y diff of the 2 first edges // 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 * ACTIVATION_BOX_EDGE_PAD)
if a_t1.Height != expectedHeight { if a_t1.Height != expectedHeight {
t.Fatalf("expected a.t1 height to be %.5f, got %.5f", expectedHeight, a_t1.Height) t.Fatalf("expected a.t1 height to be %.5f, got %.5f", expectedHeight, a_t1.Height)
} }
@ -231,7 +231,7 @@ func TestActivationBoxesSequenceDiagram(t *testing.T) {
if a_t1.TopLeft.Y != b_t1.TopLeft.Y { if a_t1.TopLeft.Y != b_t1.TopLeft.Y {
t.Fatal("expected a.t1 and b.t1 to be placed at the same 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 != g.Edges[0].Route[0].Y-ACTIVATION_BOX_EDGE_PAD {
t.Fatal("expected a.t1 to be placed at the same Y of the first edge") t.Fatal("expected a.t1 to be placed at the same Y of the first edge")
} }