我正在尝试使用 Graphviz 可视化一个简单的有限状态机图。Graphviz 创建的布局并不完全符合我的喜好。我期待一个更紧凑的结果,边缘更短。
到目前为止,我已经尝试过使用组并改变边的权重,但运气不佳。我不清楚为什么 Graphviz 以它的方式绘制图形,以及如何根据我的喜好调整它的算法。我可以设置任何参数来实现这一目标吗?或者我应该使用另一个命令而不是dot
?我试过neato
了,但结果看起来完全一团糟,我真的不明白我在做什么......
这是我迄今为止最好的结果:
尝试可视化比这更好的布局,我认为如果红色框的对齐方式不同,图形会看起来更好,更紧凑,例如如图中的箭头所示:
我用来dot
创建图表,他的源代码如下:
1 digraph JobStateDiagram
2 {
3 rankdir=LR;
4 size="8,5";
5
6 node [style="rounded,filled,bold", shape=box, fixedsize=true, width=1.3, fontname="Arial"];
7 Created [fillcolor=black, shape=circle, label="", width=0.25];
8 Destroyed [fillcolor=black, shape=doublecircle, label="", width=0.3];
9 Empty [fillcolor="#a0ffa0"];
10 Announced [fillcolor="#a0ffa0"];
11 Assigned [fillcolor="#a0ffa0"];
12 Working [fillcolor="#a0ffa0"];
13 Ready [fillcolor="#a0ffa0"];
14 TimedOut [fillcolor="#ffa0a0"];
15 Failed [fillcolor="#ffa0a0"];
16
17 {
18 rank=source; Created Destroyed;
19 }
20
21 edge [style=bold, fontname="Arial" weight=2]
22 Empty -> Announced [ label="announce" ];
23 Announced -> Assigned [ label="assign" ];
24 Assigned -> Working [ label="start" ];
25 Working -> Ready [ label="finish" ];
26 Ready -> Empty [ label="revoke" ];
27
28 edge [fontname="Arial" color="#aaaaaa" weight=1]
29 Announced -> TimedOut [ label="timeout" ];
30 Assigned -> TimedOut [ label="timeout" ];
31 Working -> TimedOut [ label="timeout" ];
32 Working -> Failed [ label="error" ];
33 TimedOut -> Announced [ label="announce" ];
34 TimedOut -> Empty [ label="revoke" ];
35 Failed -> Announced [ label="announce" ];
36 Failed -> Empty [ label="revoke" ];
37
38 edge [style=bold, fontname="Arial" weight=1]
39 Created -> Empty [ label="initialize" ];
40 Empty -> Destroyed [ label="finalize" ];
41 Announced -> Empty [ label="revoke" ];
42 Assigned -> Empty [ label="revoke" ];
43 Working -> Empty [ label="revoke" ];
44 }
另外,如果我在上面的 Graphviz 文件中做了任何奇怪的事情,任何人都请告诉我——感谢任何反馈。
更新:
更多的实验和尝试一些建议,如用户 marapet 给出的端口,增加了我的困惑......例如,在下图中,为什么dot
选择为 and 绘制这些奇怪的弯路,Working->Failed
而Failed->Announced
不是直线?