Graphviz---random node order and edges going through labels

前端 未结 2 996
醉话见心
醉话见心 2021-01-06 15:49

I have the following dot file:

digraph finite_state_machine {
    {
        rank=same;
        node [shape = doublecircle]; q_5;
        node [shape = circle         


        
2条回答
  •  天涯浪人
    2021-01-06 16:41

    Graphviz does lay out the nodes depending on the edge between each other, and not in order of appearance. If you want an edge not to influence the position of any node, you can do this by adding constraint=false.

    Therefore, this graph:

    digraph finite_state_machine {
      pad=0.2;
        {
            rank=same;
            node [shape = doublecircle]; q_5;
            node [shape = circle];
            q_1 -> q_2 [ label = "." ];
            q_1 -> q_2 [ label = "\epsilon", constraint=false ];
            q_2 -> q_1 [ label = "\epsilon", constraint=false ];
            q_2 -> q_3 [ label = "a" ];
            q_3 -> q_4 [ label = "^\wedge a" ];
            q_3 -> q_4 [ label = "\epsilon", constraint=false ];
            q_4 -> q_3 [ label = "\epsilon", constraint=false ];
            q_4 -> q_5 [ label = "b" ];
        }
    }
    

    Will get you:

    graphviz output finite state machine

    I had to add pad in order to not have some of the labels cut off.

提交回复
热议问题