qmuntal / stateless

Go library for creating finite state machines
https://wikipedia.org/wiki/Finite-state_machine
BSD 2-Clause "Simplified" License
975 stars 53 forks source link

ToGraph work incorrectly with embed substate #21

Closed okhowang closed 2 years ago

okhowang commented 3 years ago

exmaple code

package main

import (
    "fmt"

    "github.com/qmuntal/stateless"
)

func main() {
    sm := stateless.NewStateMachine("a")
    sm.Configure("a").Permit("toB", "b")
    sm.Configure("b").InitialTransition("b-1")
    sm.Configure("b-1").SubstateOf("b").InitialTransition("b-1-1").Permit("toB2", "b-2")
    sm.Configure("b-2").SubstateOf("b")
    sm.Configure("b-1-1").SubstateOf("b-1")
    fmt.Println(sm.ToGraph())
}

which output

digraph {
    compound=true;
    node [shape=Mrecord];
    rankdir="LR";

    b-2 [label="b-2"];
    b-1-1 [label="b-1-1"];
    a [label="a"];

subgraph cluster_b {
    label="b";
    b-1 [label="b-1"];
    b-2 [label="b-2"];
}
    b-1 [label="b-1"];

a -> b [style="solid", label="toB"];
b-1 -> b-2 [style="solid", label="toB2"];
 init [label="", shape=point];
 init -> {a}[style = "solid"]
}
qmuntal commented 2 years ago

Fixed in https://github.com/qmuntal/stateless/releases/tag/v1.5.3