Skip to content

Commit 9c1f252

Browse files
julianrschmidtJulian Schmidt
andauthored
fix: visualizer did not return stable graphs when having 2 transitions from the same source (#57)
Co-authored-by: Julian Schmidt <[email protected]>
1 parent 86c5e2b commit 9c1f252

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

mermaid_visualizer_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func TestMermaidFlowChartOutput(t *testing.T) {
4242
"closed",
4343
Events{
4444
{Name: "open", Src: []string{"closed"}, Dst: "open"},
45+
{Name: "part-open", Src: []string{"closed"}, Dst: "intermediate"},
46+
{Name: "part-open", Src: []string{"intermediate"}, Dst: "open"},
4547
{Name: "close", Src: []string{"open"}, Dst: "closed"},
4648
{Name: "part-close", Src: []string{"intermediate"}, Dst: "closed"},
4749
},
@@ -59,7 +61,9 @@ graph LR
5961
id2[open]
6062
6163
id0 --> |open| id2
64+
id0 --> |part-open| id1
6265
id1 --> |part-close| id0
66+
id1 --> |part-open| id2
6367
id2 --> |close| id0
6468
6569
style id0 fill:#00AA00

visualizer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func getSortedTransitionKeys(transitions map[eKey]string) []eKey {
4444
sortedTransitionKeys = append(sortedTransitionKeys, transition)
4545
}
4646
sort.Slice(sortedTransitionKeys, func(i, j int) bool {
47+
if sortedTransitionKeys[i].src == sortedTransitionKeys[j].src {
48+
return sortedTransitionKeys[i].event < sortedTransitionKeys[j].event
49+
}
4750
return sortedTransitionKeys[i].src < sortedTransitionKeys[j].src
4851
})
4952

0 commit comments

Comments
 (0)