Graphviz布局从左到右,然后从上到下

时间:2019-03-11 19:22:00

标签: graphviz

digraph finite_state_machine {
    size="8,5"
    rankdir=LR;
      node [shape = doublecircle]; beg, end;
      node [shape = circle];

  subgraph clusterG1 {
    label="area code";
    beg -> ac1 [ label = "(" ];
    ac1 -> ac2 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
    ac2 -> ac3 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
    ac3 -> ac4 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
  }

    ac4 -> ex1 [ label = ")" ];

  subgraph clusterG2 {
    label="exchange"
    ex1 -> ex2 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
    ex2 -> ex3 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
    ex3 -> ex4 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
  }

  ex4 -> num1 [ label = "-" ];

  subgraph clusterG3 {
    label="number"
    num1 -> num2 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
    num2 -> num3 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
    num3 -> num4 [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
    num4 -> end [ label = "0,1,2,3,4,\n5,6,7,8,9,0" ];
  }

}

为此:

enter image description here

(对不起,太小了)

这是一个简单的线性图。我想从左到右有三个方框,每个方框从上到下都是内部组织的。经过大量的搜寻后,我仍然不确定该怎么做!

1 个答案:

答案 0 :(得分:1)

基本上,您只需向连接群集之间节点的边缘添加contstraint = false属性:

ac4 -> ex1 [ label = ")", constraint=false ];

ex4 -> num1 [ label = "-", constraint=false ];

此属性禁止边影响连接节点的等级位置。换句话说,它添加了连接箭头,但头和尾巴的位置保持不变,好像根本没有连接。

尽管如此,您将面临另一个问题-如果您的集群并排放置,则将一个集群的底部与另一个集群的 top 连接在一起在整个图中难看的重叠边缘。

如果您在解决问题上遇到麻烦,请告诉我您希望如何解决该问题,我们可以一起解决该问题。

enter image description here