qmuntal / stateless

Go library for creating finite state machines
BSD 2-Clause "Simplified" License
898 stars 47 forks source link

Export to DOT graph doesn't produce correct string representation of the state machine #56

Closed zaporozhets closed 1 year ago

zaporozhets commented 1 year ago

Unfortunately, ToGraph doesn't generate correct output for phoneCall state machine from statemachine_test.go example.

Online visualizer(http://www.webgraphviz.com/) reports the following error

Warning: :7: string ran past end of line Error: :8: syntax error near line 8 context: exit >>> / <<< func2"; Warning: :8: string ran past end of line Warning: OnHold -> OnHold: head is inside tail cluster cluster_Connected Warning: OnHold -> OnHold: tail is inside head cluster cluster_Connected

image

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

    subgraph cluster_Connected {
        label="Connected\n----------\nentry / startCallTimer
exit / func2";
        OnHold [label="OnHold"];
    }
    OffHook [label="OffHook"];
    Ringing [label="Ringing"];
    OnHold -> OffHook [label="LeftMessage", ltail="cluster_Connected"];
    Connected -> Connected [label="MuteMicrophone"];
    OnHold -> OnHold [label="PlacedOnHold", ltail="cluster_Connected"];
    Connected -> Connected [label="SetVolume"];
    Connected -> Connected [label="UnmuteMicrophone"];
    OffHook -> Ringing [label="CallDialed / func1"];
    OnHold -> PhoneDestroyed [label="PhoneHurledAgainstWall"];
    OnHold -> OnHold [label="TakenOffHold", lhead="cluster_Connected"];
    Ringing -> OnHold [label="CallConnected", lhead="cluster_Connected"];
    init [label="", shape=point];
    init -> OffHook
}

Can you, please, take a look?

Cheers, Taras.

qmuntal commented 1 year ago

Thanks for reporting this issue. I've fixed it in #57.

zaporozhets commented 1 year ago

That's awesome. Thanks