如何强制对点中的节点进行排名?
我有许多 graphviz 点格式的相对简单(自动生成)的图表。 这些显示了通过状态机的路径,但 dot 有一个有点令人困惑的习惯,即当我希望图形按状态顺序排列时,它会决定两个节点必须处于同一等级。 我已经尝试了很多设置(包括下面列出的 :n
和 :s
以及 weight
),但我无法说服 dot将第三状态置于第四状态之上。
我在很多图表上都遇到这个问题:似乎有一些内部的点决定如果两个节点处于同一等级并且没有什么可以覆盖它会更好。 我什至有代码指定一个节点应该是 rank=sink
,但 dot 决定在其下面放置另一个节点。
有没有什么方法可以表明节点有序比任何其他约束更重要?
用于生成图表的代码如下所示:
digraph {
ERROR [label="Error"];
FirstSTATE [label="Initial State" URL="\ref FirstSTATE"];
FirstSTATE -> SecondSTATE;
SecondSTATE [label="Second State" URL="\ref SecondSTATE"];
SecondSTATE -> ThirdSTATE;
ThirdSTATE [label="Third State" URL="\ref ThirdSTATE"];
FourthSTATE [label="Fouth State?" shape="diamond"];
ThirdSTATE:s -> FourthSTATE:n [weight=50];
FourthSTATE -> FifthSTATE [label="Yes" ];
FourthSTATE -> ThirdSTATE [label="No"];
FifthSTATE [label="Fifth State" URL="\ref FifthSTATE"];
SixthSTATE [label="Sixth State?" shape="diamond"];
SixthSTATE -> ERROR [label="Yes" ];
SixthSTATE -> SeventhSTATE [label="No"];
FifthSTATE -> SixthSTATE;
SeventhSTATE [label="Seventh State" URL="\ref SeventhSTATE"];
SeventhSTATE -> EighthSTATE;
EighthSTATE [label="Eighth State" URL="\ref EighthSTATE"];
NinthSTATE [label="Ninth State?" shape="diamond"];
NinthSTATE -> TenthSTATE [label="Yes" ];
NinthSTATE -> EighthSTATE [label="No"];
EighthSTATE -> NinthSTATE;
TenthSTATE [label="Tenth State" URL="\ref TenthSTATE"];
EleventhSTATE [label="Eleventh State?" shape="diamond"];
EleventhSTATE -> ERROR [label="Yes" ];
EleventhSTATE -> TwelfthSTATE [label="No" ];
TenthSTATE -> EleventhSTATE;
TwelfthSTATE [label="Twelfth State" URL="\ref TwelfthSTATE"];
}
该图表当前如下所示:
I have a number of relatively simple (auto-generated) graphs in graphviz dot format. These show the path through a state machine, but dot has a slightly confusing habit of deciding that two nodes must be on the same rank when I would like the graph to be in state order. I've tried a lot of settings (including the :n
and :s
and the weight
listed below), but I cannot persuade dot to place the Third State above the Fourth State.
I have this problem with a lot of graphs: there seems to be something internal to dot that decides that it would be better if two nodes were on the same rank and there's nothing that can be done to override it. I've even had code that specifies that one node should be a rank=sink
, but dot has decided to put another node below it anyway.
Is there any way to suggest to dot that it's more important that the nodes are in order than any other constraint?
The code that was used to generate the graph looks like this:
digraph {
ERROR [label="Error"];
FirstSTATE [label="Initial State" URL="\ref FirstSTATE"];
FirstSTATE -> SecondSTATE;
SecondSTATE [label="Second State" URL="\ref SecondSTATE"];
SecondSTATE -> ThirdSTATE;
ThirdSTATE [label="Third State" URL="\ref ThirdSTATE"];
FourthSTATE [label="Fouth State?" shape="diamond"];
ThirdSTATE:s -> FourthSTATE:n [weight=50];
FourthSTATE -> FifthSTATE [label="Yes" ];
FourthSTATE -> ThirdSTATE [label="No"];
FifthSTATE [label="Fifth State" URL="\ref FifthSTATE"];
SixthSTATE [label="Sixth State?" shape="diamond"];
SixthSTATE -> ERROR [label="Yes" ];
SixthSTATE -> SeventhSTATE [label="No"];
FifthSTATE -> SixthSTATE;
SeventhSTATE [label="Seventh State" URL="\ref SeventhSTATE"];
SeventhSTATE -> EighthSTATE;
EighthSTATE [label="Eighth State" URL="\ref EighthSTATE"];
NinthSTATE [label="Ninth State?" shape="diamond"];
NinthSTATE -> TenthSTATE [label="Yes" ];
NinthSTATE -> EighthSTATE [label="No"];
EighthSTATE -> NinthSTATE;
TenthSTATE [label="Tenth State" URL="\ref TenthSTATE"];
EleventhSTATE [label="Eleventh State?" shape="diamond"];
EleventhSTATE -> ERROR [label="Yes" ];
EleventhSTATE -> TwelfthSTATE [label="No" ];
TenthSTATE -> EleventhSTATE;
TwelfthSTATE [label="Twelfth State" URL="\ref TwelfthSTATE"];
}
The graph currently looks like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用“constraint=false”。
http://www.graphviz.org/doc/info/attrs.html #d:constraint
在你的图表中:
你将得到:
Use "constraint=false".
http://www.graphviz.org/doc/info/attrs.html#d:constraint
In your graph:
You'll get:
每当您想要一个向上的箭头时,请从上到下(即向后)编写边缘,然后添加
dir=back
(https://graphviz.org/docs/attrs/dir/) 使箭头指向向上而不是向下。因此,不要
写:
现在,由于所有边都从
ThirdSTATE
到FourthSTATE
,因此排名不再含糊,Graphviz 将可靠地放置ThirdSTATE
位于FourthSTATE
之上。这通常比使用 constraint=false 更好,因为使用 constraint=false 的边有时会被赋予非常摇摆的边(就好像它们没有参与图形布局一样?)。
Whenever you want an arrow that points upward, write the edge from top to bottom (i.e. backwards), then add
dir=back
(https://graphviz.org/docs/attrs/dir/) to make the arrow point upward instead of downward.So instead of:
write:
Now since all the edges go from
ThirdSTATE
toFourthSTATE
, the rank is no longer ambiguous and Graphviz will reliably putThirdSTATE
aboveFourthSTATE
.This is often better than using
constraint=false
since edges withconstraint=false
are sometimes given very wiggly edges (as if they did not participate in graph layout?).