handle lifeline edges
This commit is contained in:
parent
2fe494f678
commit
2f71d575df
2 changed files with 29 additions and 0 deletions
|
|
@ -318,6 +318,15 @@ func ExtractSubgraph(container *d2graph.Object, includeSelf bool) (nestedGraph *
|
||||||
remainingEdges := make([]*d2graph.Edge, 0, len(g.Edges))
|
remainingEdges := make([]*d2graph.Edge, 0, len(g.Edges))
|
||||||
for _, edge := range g.Edges {
|
for _, edge := range g.Edges {
|
||||||
srcIsNested := isNestedObject(edge.Src)
|
srcIsNested := isNestedObject(edge.Src)
|
||||||
|
if d2sequence.IsLifelineEnd(edge.Dst) {
|
||||||
|
// special handling for lifelines since their edge.Dst is a special Object
|
||||||
|
if srcIsNested {
|
||||||
|
nestedGraph.Edges = append(nestedGraph.Edges, edge)
|
||||||
|
} else {
|
||||||
|
remainingEdges = append(remainingEdges, edge)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
dstIsNested := isNestedObject(edge.Dst)
|
dstIsNested := isNestedObject(edge.Dst)
|
||||||
if srcIsNested && dstIsNested {
|
if srcIsNested && dstIsNested {
|
||||||
nestedGraph.Edges = append(nestedGraph.Edges, edge)
|
nestedGraph.Edges = append(nestedGraph.Edges, edge)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"oss.terrastruct.com/util-go/go2"
|
"oss.terrastruct.com/util-go/go2"
|
||||||
|
|
@ -411,6 +412,25 @@ func (sd *sequenceDiagram) addLifelineEdges() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsLifelineEnd(obj *d2graph.Object) bool {
|
||||||
|
// lifeline ends only have ID and no graph parent or box set
|
||||||
|
if obj.Graph != nil || obj.Parent != nil || obj.Box != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !strings.Contains(obj.ID, "-lifeline-end-") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
parts := strings.Split(obj.ID, "-lifeline-end-")
|
||||||
|
if len(parts) > 1 {
|
||||||
|
hash := parts[len(parts)-1]
|
||||||
|
actorID := strings.Join(parts[:len(parts)-1], "-lifeline-end-")
|
||||||
|
if strconv.Itoa(go2.StringToIntHash(actorID+"-lifeline-end")) == hash {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (sd *sequenceDiagram) placeNotes() {
|
func (sd *sequenceDiagram) placeNotes() {
|
||||||
rankToX := make(map[int]float64)
|
rankToX := make(map[int]float64)
|
||||||
for _, actor := range sd.actors {
|
for _, actor := range sd.actors {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue