Skip to content

Commit

Permalink
d2sequence: fix multiline labels
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Aug 6, 2024
1 parent b28af6c commit 9a4125a
Show file tree
Hide file tree
Showing 72 changed files with 5,602 additions and 4,750 deletions.
4 changes: 3 additions & 1 deletion ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Sequence diagram edge groups account for edge label heights [#2038](https://github.com/terrastruct/d2/pull/2038)
- Sequence diagram self-referential edges account for edge label heights [#2040](https://github.com/terrastruct/d2/pull/2040)
- Sequence diagram: The spacing between self-referential edges and regular edges is uniform [#2043](https://github.com/terrastruct/d2/pull/2043)
- Sequence diagram: The spacing between self-referential edges and regular edges is uniform [#2043](https://github.com/terrastruct/d2/pull/2043)

#### Bugfixes ⛑️

- Sequence diagram multi-line edge labels no longer can collide with other elements [#2049](https://github.com/terrastruct/d2/pull/2049)
17 changes: 5 additions & 12 deletions d2layouts/d2sequence/sequence_diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (sd *sequenceDiagram) placeNotes() {

for _, msg := range sd.messages {
if sd.verticalIndices[msg.AbsID()] < verticalIndex {
y += sd.yStep
y += sd.yStep + float64(msg.LabelDimensions.Height)
}
}
for _, otherNote := range sd.notes {
Expand Down Expand Up @@ -535,7 +535,6 @@ func (sd *sequenceDiagram) placeSpans() {
// routeMessages routes horizontal edges (messages) from Src to Dst lifeline (actor/span center)
// in another step, routes are adjusted to spans borders when necessary
func (sd *sequenceDiagram) routeMessages() error {
var prevIsLoop bool
messageOffset := sd.maxActorHeight + sd.yStep
for _, message := range sd.messages {
message.ZIndex = MESSAGE_Z_INDEX
Expand All @@ -546,13 +545,6 @@ func (sd *sequenceDiagram) routeMessages() error {
}
}

// we need extra space if the previous message is a loop
if prevIsLoop {
messageOffset += MIN_MESSAGE_DISTANCE * 1.5
}

startY := messageOffset + noteOffset

var startX, endX float64
if startCenter := getCenter(message.Src); startCenter != nil {
startX = startCenter.X
Expand Down Expand Up @@ -580,22 +572,23 @@ func (sd *sequenceDiagram) routeMessages() error {

if isSelfMessage || isToDescendant || isFromDescendant || isToSibling {
midX := startX + SELF_MESSAGE_HORIZONTAL_TRAVEL
startY := messageOffset + noteOffset
endY := startY + math.Max(float64(message.LabelDimensions.Height), MIN_MESSAGE_DISTANCE)*1.5
message.Route = []*geo.Point{
geo.NewPoint(startX, startY),
geo.NewPoint(midX, startY),
geo.NewPoint(midX, endY),
geo.NewPoint(endX, endY),
}
prevIsLoop = true
messageOffset = endY + sd.yStep - noteOffset
} else {
startY := messageOffset + noteOffset + float64(message.LabelDimensions.Height/2.)
message.Route = []*geo.Point{
geo.NewPoint(startX, startY),
geo.NewPoint(endX, startY),
}
prevIsLoop = false
messageOffset = startY + float64(message.LabelDimensions.Height/2.) + sd.yStep - noteOffset
}
messageOffset += math.Max(sd.yStep, float64(message.LabelDimensions.Height)+MIN_MESSAGE_DISTANCE*1.5)

if message.Label.Value != "" {
message.LabelPosition = go2.Pointer(label.InsideMiddleCenter.String())
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9a4125a

Please sign in to comment.