diff --git a/d2layouts/d2sequence/constants.go b/d2layouts/d2sequence/constants.go index 7dcf72d35..e39f8e2dd 100644 --- a/d2layouts/d2sequence/constants.go +++ b/d2layouts/d2sequence/constants.go @@ -8,6 +8,8 @@ const VERTICAL_PAD = 50. const MIN_ACTOR_DISTANCE = 250. +const MIN_ACTOR_WIDTH = 150. + // min vertical distance between messages const MIN_MESSAGE_DISTANCE = 80. @@ -25,3 +27,6 @@ const SPAN_MESSAGE_PAD = 16. const LIFELINE_STROKE_WIDTH int = 2 const LIFELINE_STROKE_DASH int = 8 + +// pad when the actor has the label placed OutsideMiddleBottom so that the lifeline is not so close to the text +const LIFELINE_LABEL_PAD = 5. diff --git a/d2layouts/d2sequence/layout_test.go b/d2layouts/d2sequence/layout_test.go index c54028a07..83892aada 100644 --- a/d2layouts/d2sequence/layout_test.go +++ b/d2layouts/d2sequence/layout_test.go @@ -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-SPAN_MESSAGE_PAD != 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 9e5206e58..10aa7259d 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -52,6 +52,12 @@ func newSequenceDiagram(actors []*d2graph.Object, messages []*d2graph.Edge) *seq for rank, actor := range actors { sd.root = actor.Parent sd.objectRank[actor] = rank + + if actor.Width < MIN_ACTOR_WIDTH { + aspectRatio := actor.Height / actor.Width + actor.Width = MIN_ACTOR_WIDTH + actor.Height = math.Round(aspectRatio * actor.Width) + } sd.maxActorHeight = math.Max(sd.maxActorHeight, actor.Height) queue := make([]*d2graph.Object, len(actor.ChildrenArray)) @@ -138,7 +144,7 @@ func (sd *sequenceDiagram) addLifelineEdges() { actorBottom := actor.Center() actorBottom.Y = actor.TopLeft.Y + actor.Height if *actor.LabelPosition == string(label.OutsideBottomCenter) { - actorBottom.Y += float64(*actor.LabelHeight) + actorBottom.Y += float64(*actor.LabelHeight) + LIFELINE_LABEL_PAD } actorLifelineEnd := actor.Center() actorLifelineEnd.Y = endY @@ -180,7 +186,7 @@ func (sd *sequenceDiagram) placeSpans() { } // places spans from most to least nested - // the order is important because the only way a child span exists is if there'e an message to it + // the order is important because the only way a child span exists is if there's a message to it // however, the parent span might not have a message to it and then its position is based on the child position // or, there can be a message to it, but it comes after the child one meaning the top left position is still based on the child // and not on its own message