我有以下点文件:
digraph finite_state_machine {
{
rank=same;
node [shape = doublecircle]; q_5;
node [shape = circle];
q_1 -> q_2 [ label = "." ];
q_1 -> q_2 [ label = "\epsilon" ];
q_2 -> q_1 [ label = "\epsilon" ];
q_2 -> q_3 [ label = "a" ];
q_3 -> q_4 [ label = "^\wedge a" ];
q_3 -> q_4 [ label = "\epsilon" ];
q_4 -> q_3 [ label = "\epsilon" ];
q_4 -> q_5 [ label = "b" ];
}
}
我的印象是节点会按照提到的顺序出现。但顺序对我来说似乎是随机的。我希望订单从左到右依次为下标。此外,边缘穿过标签,我该如何避免?
这是当前图片:
答案 0 :(得分:6)
Graphviz会根据彼此之间的边缘布置节点,而不是按照外观的顺序排列。如果您希望边缘不影响任何节点的位置,可以通过添加constraint=false
来完成此操作。
因此,这张图:
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" ];
}
}
会得到你:
我必须添加pad
,以便不会切断某些标签。
答案 1 :(得分:2)
这是其中一个想法。
1)使用以下命令查找放置节点时点所使用的位置。
dot filename.dot
2)注意生成的输出中每个节点的 pos 属性。然后根据您的代码中的喜好更改其值。以下是您的示例的修改点代码。
digraph finite_state_machine {
{
rank=same;
node [shape = circle];
q_1[pos="30"];
q_2[pos="130"];
q_3[pos="230"];
q_4[pos="330"];
node [shape = doublecircle];
q_5 [pos="430"];
q_1 -> q_2 [ label = "." ];
q_1 -> q_2 [ label = "\epsilon" ];
q_2 -> q_1 [ label = "\epsilon" ];
q_2 -> q_3 [ label = "a" ];
q_3 -> q_4 [ label = "^\wedge a" ];
q_3 -> q_4 [ label = "\epsilon" ];
q_4 -> q_3 [ label = "\epsilon" ];
q_4 -> q_5 [ label = "b" ];
}
}
3)再次运行点,这次生成输出文件。
结果可以在这里看到: