diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-07 14:18:12 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-07 14:18:12 +0200 |
| commit | e4f667e2e9da96e707f5923ea38fa58977bac01f (patch) | |
| tree | 5f1049e70fa22c0c5e37631434ad3cbd4157c1cf /src | |
| parent | d58b704289a02b1b444f5bdf79f7ca2ee8ddceb8 (diff) | |
FSM: Different color for non-activated current states and a legend
Diffstat (limited to 'src')
| -rw-r--r-- | src/fsm.go | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -192,7 +192,7 @@ func (eduvpn *VPNState) GoTransition(newState FSMStateID, data string) bool { return ok } -func getGraphviz(fsm *FSM, graph string) string { +func getGraphviz(fsm *FSM, graph string, current bool) string { if fsm == nil { return graph } @@ -209,24 +209,36 @@ func getGraphviz(fsm *FSM, graph string) string { graph += "style=\"\"\n" } if fsm.Current == name { - graph += "color=\"blue\"\n" - graph += "fontcolor=\"blue\"\n" + color := "orange" + if current { + color = "blue" + } + graph += fmt.Sprintf("color=\"%s\"\n", color) + graph += fmt.Sprintf("fontcolor=\"%s\"\n", color) } else { graph += "color=\"\"\n" graph += "fontcolor=\"\"\n" } graph += "label=" + name.String() - graph = getGraphviz(state.Sub, graph) + graph = getGraphviz(state.Sub, graph, current && fsm.Current == name) graph += "\n}" } return graph } func (eduvpn *VPNState) GenerateGraph() string { - graph := "digraph fsm {\n" - graph += "nodesep=2" - graph = getGraphviz(eduvpn.FSM, graph) + graph := `digraph fsm_with_legend { +nodesep=2 +subgraph fsm { +nodesep=2` + graph = getGraphviz(eduvpn.FSM, graph, true) graph += "\n}" + graph += `graph [labelloc="b" labeljust="r" label=< +<TABLE BORDER="2" CELLBORDER="1" CELLSPACING="0"> +<TR><TD BGCOLOR="BLUE"><font color="white">The current state</font></TD></TR> +<TR><TD BGCOLOR="ORANGE">A state that is not the current state but will be once the parent state becomes the current</TD></TR> +</TABLE>>]; +}` return graph } |
