diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-14 15:30:49 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-14 15:30:49 +0200 |
| commit | 2fdfa26388f4e738d1a4f89a29fbe93dfdbce41a (patch) | |
| tree | f254bd12c372bcad61704b2a6c36bf015114dd64 | |
| parent | 48bbbdc23c9db6653de59be7271535eb3c96dfe6 (diff) | |
FSM graph generation: Add generation using mermaid as default
Dot from graphviz kept re-ordering (e.g. flipping edges) which is annoying when showing the
graph live
| -rw-r--r-- | src/fsm.go | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -103,11 +103,12 @@ func (eduvpn *VPNState) GoTransition(newState FSMStateID, data string) bool { return ok } -func (eduvpn *VPNState) GenerateGraph() string { +func (eduvpn *VPNState) generateDotGraph() string { graph := `digraph eduvpn_fsm { nodesep = 2; -rankdir = LR;` - graph += "\nnode[color=blue]; " + eduvpn.FSM.Current.String() + ";\n" +remincross = false; +` + graph += "node[color=blue]; " + eduvpn.FSM.Current.String() + ";\n" graph += "node [color=black];\n" for state, transitions := range eduvpn.FSM.States { for _, transition := range transitions { @@ -118,6 +119,21 @@ rankdir = LR;` return graph } +func (eduvpn *VPNState) generateMermaidGraph() string { + graph := "graph TD\n" + graph += "style " + eduvpn.FSM.Current.String() + " fill:cyan\n" + for state, transitions := range eduvpn.FSM.States { + for _, transition := range transitions { + graph += state.String() + "(" + state.String() + ") " + "-->|" + transition.Description + "| " + transition.To.String() + "\n" + } + } + return graph +} + +func (eduvpn *VPNState) GenerateGraph() string { + return eduvpn.generateMermaidGraph() +} + func (eduvpn *VPNState) InitializeFSM() { eduvpn.FSM = &FSM{ States: FSMStates { |
