Search code examples
graphgraphvizfsm

How can I make a circular graph in Graphviz?


I have this following graph in graphviz:

enter image description here

That is generated from this code:

digraph finite_state_machine {
    rankdir=TB;
    node [shape = none]; Start;
    node [shape = circle];
    nodesep=.5;
    Start -> A;
    
    A->B
    B->C
    C->D
    D->E
    E->F
    F->G
    G->H
    H->I
    I->A

    {rank = same; A B C D}
    {rank = same; E}
    {rank = same; F G H I}
}

How can I change the direction of those bottom lines in order to make it look like that? enter image description here


Solution

  • An example with 8 nodes (as from your drawing it was not clear where to put the 9-th):

    digraph finite_state_machine {
        rankdir=TB;
        node [shape = none]; Start;
        node [shape = circle];
        nodesep=.5;
        Start -> A;
        
        A->B
        B->C
        C->D
        D->E
        F->E [dir=back]
        G->F [dir=back]
        H->G [dir=back]
        A->H [dir=back]
       
    
        {rank = same; A B C }
        {rank = same;  E F G }
    }
    

    enter image description here