graphviz - Graphviz - 如何分隔自引用边缘以避免造成视觉混乱?
问题描述
我有一个图表,其中对象的实例有时会调用自己。这是使用点布局引擎。
digraph G {
foo;
foo -> foo [label="msg1"];
foo -> foo [label="msg2"];
foo -> foo [label="msg3"];
}
这在渲染的图表中造成了一些混乱,因为它们最终都在同一个位置。
将它们分开一点最简单/最好的方法是什么?我想一种蛮力方法是添加隐藏节点n1, n2, n3
,然后foo -> n1; n1->foo; foo -> n2;...
我可能正在查看每个节点最多 7-8 条自引用消息的顺序,但 3-4 条的解决方案将是一个好的开始。
这是对隐藏节点方法的尝试。也不是很好。删除label
不可见节点上的属性仍然会在箭头之间留下空隙。
digraph G {
foo;
foo -> n1 [label="msg1" dir="none"];
n1 -> foo;
foo -> n2 [label="msg2" dir="none"];
n2 -> foo;
foo -> n3 [label="msg3" dir="none"];
n3 -> foo;
n1 [ label = "", style = invis ];
n2 [ label = "", style = invis ];
n3 [ label = "", style = invis ];
}
到目前为止我管理的最好的(实际的边缘标签很长,所以我添加了它来查看结果)是通过使用 n1、n2、n3 中间节点,不是隐藏的,而是使用shape="plaintext"
:
digraph G {
foo;
foo -> n1 [dir="none"];
n1 -> foo;
foo -> n2 [dir="none"];
n2 -> foo;
foo -> n3 [dir="none"];
n3 -> foo;
n1 [ shape="plaintext" label="msg111111111111111111111111111"];
n2 [ shape="plaintext" label="msg222222222222222222222222222" ];
n3 [ shape="plaintext" label="msg333333333333333333333333333" ];
}
给予:
编辑: 寻找与dot相关的答案,因为我有时将 DOT 传递给专门的渲染库,如d3-graphviz,我知道它适用于dot,不确定其他布局引擎。
解决方案
用点或neato试试这个
digraph G {
graph [center=true pad=.5]
subgraph clustera {
// neato seems to ignore margin!
graph [margin=70 style=dotted] // change dotted to invis for finished graph
graph [nodesep=.3] // neato, not dot
// edge[labelangle=0 labeldistance=4] // minlen=.7]
foo [height=.8 width=1.4 shape=circle];
foo -> foo [tailport=n headport=n taillabel="msg1"];
foo -> foo [tailport=ne headport=ne taillabel="msg1a"];
foo -> foo [tailport=e headport=e taillabel="msg2"];
foo -> foo [tailport=se headport=se taillabel="msg2a"];
foo -> foo [tailport=s headport=s taillabel="msg3"];
foo -> foo [tailport=sw headport=sw taillabel="msg3a"];
foo -> foo [tailport=w headport=w taillabel="msg4"];
foo -> foo [tailport=nw headport=nw taillabel="msg4a"];
}
}