Graphviz-如何隔开自参考边以避免造成视觉混乱?
我有一个图形,对象的实例有时会调用它们自己。这是使用点布局引擎Graphviz-如何隔开自参考边以避免造成视觉混乱?,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 我可能在考
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条的解决方案将是一个良好的开端
这是对隐藏节点方法的尝试。也不太好。移除不可见节点上的标签
属性仍会在箭头之间留下间隙
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”
:
给予:
编辑:查找与点相关的答案,因为我有时会将点传递给专门的渲染库,例如,我知道它适用于点,但不确定其他布局引擎。尝试使用点或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"];
}
}
您可以通过在两端为每个边指定一个不同的显式端口方向来强制在自身边之间进行一些分离:foo:n->foo:n
,foo:ne->foo:ne
,等等。恐怕结果还是不太好。@jasonharper谢谢你的建议,但是,是的,它们仍然有点混乱,与其说是边缘箭头,它确实有间隔,不如说是边缘标签,它的间隔并不一致。我喜欢它,不过我会看看我是否能在我的实际代码中使用它。
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"];
}
}