From c2825e401f851ec53e8ade92c7ea41a1c3ac9074 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 4 Dec 2022 13:40:46 -0800 Subject: [PATCH] fix notes identifying as spans --- d2layouts/d2sequence/sequence_diagram.go | 20 +++++++++++++++++-- .../TestCompile/leaky_sequence.exp.json | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index bf7622a33..b22727aee 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -70,6 +70,22 @@ func hasEdge(o *d2graph.Object) bool { return false } +func (sd *sequenceDiagram) containsMessage(o *d2graph.Object) bool { + for _, m := range sd.messages { + for _, ref := range m.References { + curr := ref.ScopeObj + for curr != nil { + if curr == o { + return true + } + curr = curr.Parent + } + } + } + + return false +} + func newSequenceDiagram(actors []*d2graph.Object, messages []*d2graph.Edge) *sequenceDiagram { sd := &sequenceDiagram{ messages: messages, @@ -104,8 +120,8 @@ func newSequenceDiagram(actors []*d2graph.Object, messages []*d2graph.Edge) *seq queue = queue[1:] // spans are children of actors that have edges - // notes are children of actors with no edges - if hasEdge(child) { + // notes are children of actors with no edges and contains no messages + if hasEdge(child) && !sd.containsMessage(child) { // spans have no labels // TODO why not? Spans should be able to child.Attributes.Label = d2graph.Scalar{Value: ""} diff --git a/testdata/d2compiler/TestCompile/leaky_sequence.exp.json b/testdata/d2compiler/TestCompile/leaky_sequence.exp.json index 182b3c4e3..8e993226b 100644 --- a/testdata/d2compiler/TestCompile/leaky_sequence.exp.json +++ b/testdata/d2compiler/TestCompile/leaky_sequence.exp.json @@ -5,7 +5,7 @@ "errs": [ { "range": "d2/testdata/d2compiler/TestCompile/leaky_sequence.d2,4:0:36-4:8:44", - "errmsg": "d2/testdata/d2compiler/TestCompile/leaky_sequence.d2:5:1: connections within sequence diagrams can only connect to other objects within the same sequence diagram" + "errmsg": "d2/testdata/d2compiler/TestCompile/leaky_sequence.d2:5:1: connections within sequence diagrams can connect only to other objects within the same sequence diagram" } ] }