min object width
This commit is contained in:
parent
4c41794ea2
commit
94895ab693
3 changed files with 14 additions and 3 deletions
|
|
@ -8,6 +8,8 @@ const VERTICAL_PAD = 50.
|
||||||
|
|
||||||
const MIN_ACTOR_DISTANCE = 250.
|
const MIN_ACTOR_DISTANCE = 250.
|
||||||
|
|
||||||
|
const MIN_ACTOR_WIDTH = 150.
|
||||||
|
|
||||||
// min vertical distance between messages
|
// min vertical distance between messages
|
||||||
const MIN_MESSAGE_DISTANCE = 80.
|
const MIN_MESSAGE_DISTANCE = 80.
|
||||||
|
|
||||||
|
|
@ -25,3 +27,6 @@ const SPAN_MESSAGE_PAD = 16.
|
||||||
const LIFELINE_STROKE_WIDTH int = 2
|
const LIFELINE_STROKE_WIDTH int = 2
|
||||||
|
|
||||||
const LIFELINE_STROKE_DASH int = 8
|
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.
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ func TestSpansSequenceDiagram(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-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")
|
t.Fatal("expected a.t1 to be placed at the same Y of the first message")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,12 @@ func newSequenceDiagram(actors []*d2graph.Object, messages []*d2graph.Edge) *seq
|
||||||
for rank, actor := range actors {
|
for rank, actor := range actors {
|
||||||
sd.root = actor.Parent
|
sd.root = actor.Parent
|
||||||
sd.objectRank[actor] = rank
|
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)
|
sd.maxActorHeight = math.Max(sd.maxActorHeight, actor.Height)
|
||||||
|
|
||||||
queue := make([]*d2graph.Object, len(actor.ChildrenArray))
|
queue := make([]*d2graph.Object, len(actor.ChildrenArray))
|
||||||
|
|
@ -138,7 +144,7 @@ func (sd *sequenceDiagram) addLifelineEdges() {
|
||||||
actorBottom := actor.Center()
|
actorBottom := actor.Center()
|
||||||
actorBottom.Y = actor.TopLeft.Y + actor.Height
|
actorBottom.Y = actor.TopLeft.Y + actor.Height
|
||||||
if *actor.LabelPosition == string(label.OutsideBottomCenter) {
|
if *actor.LabelPosition == string(label.OutsideBottomCenter) {
|
||||||
actorBottom.Y += float64(*actor.LabelHeight)
|
actorBottom.Y += float64(*actor.LabelHeight) + LIFELINE_LABEL_PAD
|
||||||
}
|
}
|
||||||
actorLifelineEnd := actor.Center()
|
actorLifelineEnd := actor.Center()
|
||||||
actorLifelineEnd.Y = endY
|
actorLifelineEnd.Y = endY
|
||||||
|
|
@ -180,7 +186,7 @@ func (sd *sequenceDiagram) placeSpans() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// places spans from most to least nested
|
// 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
|
// 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
|
// 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
|
// and not on its own message
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue