fix notes identifying as spans

This commit is contained in:
Alexander Wang 2022-12-04 13:40:46 -08:00
parent a4e66f658a
commit c2825e401f
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
2 changed files with 19 additions and 3 deletions

View file

@ -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: ""}

View file

@ -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"
}
]
}