[英]Setting arbitrary nodes positions in a Graphviz state machine diagram
Grapviz normally formats diagrams according to fixed styles. Grapviz通常根据固定样式设置图表格式。
I would like to set nodes positions of this graph: 我想设置此图的节点位置:
generated with this code: 使用以下代码生成:
digraph finite_state_machine {
# rankdir=LR;
size="8,5"
node [shape = doublecircle]; S E;
node [shape = circle];
S -> S0 [ label = "0/-" ];
S -> S1 [ label = "1/-" ];
S0 -> S1 [ label = "1/-" ];
S1 -> S0 [ label = "0/-" ];
S0 -> S00 [ label = "0/0" ];
S1 -> S11 [ label = "1/1" ];
S0 -> E [ label = "$/-" ];
S1 -> E [ label = "$/-" ];
S00 -> S00 [ label = "0/0" ];
S11 -> S11 [ label = "1/1" ];
S00 -> S1 [ label = "1/0" ];
S11 -> S0 [ label = "0/1" ];
S00 -> E [ label = "$/0" ];
S11 -> E [ label = "$/1" ];
}
// http://www.graphviz.org/Gallery/directed/fsm.html
// dot -Tpng example_fsm.dot > example_fsm.png
rank = same
is your friend. rank = same
是您的朋友。 I also have added some weight for greater symmetry. 我还增加了一些权重以实现更大的对称性。
digraph finite_state_machine
{
size="8,5"
{ rank = same; S0 S1 }
{ rank = same; S00 S11 }
node [shape = doublecircle];
S; E;
node [shape = circle];
S0; S1; S00; S11;
S -> S0 [ label = "0/-" ];
S -> S1 [ label = "1/-" ];
S0 -> S1 [ label = "1/-" ];
S1 -> S0 [ label = "0/-" ];
S0 -> S00 [ label = "0/0", weight = 8 ];
S1 -> S11 [ label = "1/1", weight = 8 ];
S0 -> E [ label = "$/-" ];
S1 -> E [ label = "$/-" ];
S00 -> S00 [ label = "0/0" ];
S11 -> S11 [ label = "1/1" ];
S00 -> S1 [ label = "1/0" ];
S11 -> S0 [ label = "0/1" ];
S00 -> E [ label = "$/0" ];
S11 -> E [ label = "$/1" ];
}
yields 产量
As an alternative solution, this one is using the constraint
and dir
attributes instead of weight
: 作为一种替代解决方案,这是使用constraint
和dir
属性而不是weight
:
digraph finite_state_machine {
size="8,5"
node [shape = doublecircle]; S E;
node [shape = circle];
S -> S0 [ label = "0/-" ];
S -> S1 [ label = "1/-" ];
S0 -> S00 [ label = "0/0" ];
S1 -> S11 [ label = "1/1" ];
S00 -> E [ label = "$/0" ];
S11 -> E [ label = "$/1" ];
S0 -> E [ label = "$/-" ];
S1 -> E [ label = "$/-" ];
S1 -> S00 [ label = "1/0", dir=back ];
S0 -> S11 [ label = "0/1", dir=back ];
edge[constraint=false];
S0 -> S1 [ label = "1/-" ];
S1 -> S0 [ label = "0/-" ];
S00 -> S00 [ label = "0/0" ];
S11 -> S11 [ label = "1/1" ];
}
Result as visualized with GraphvizFiddle 使用GraphvizFiddle可视化的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.