避免graphviz中的边相交
假设我们有以下简单图:避免graphviz中的边相交,graphviz,Graphviz,假设我们有以下简单图: digraph Test { Start[shape = doublecircle]; Foo[shape = square]; Bar[shape = diamond]; Baz[shape = square]; Xyz[shape = square]; Start -> Foo; Foo:s -> Bar:n; Bar:w -> Baz:n; Bar:e -> Xyz:
digraph Test {
Start[shape = doublecircle];
Foo[shape = square];
Bar[shape = diamond];
Baz[shape = square];
Xyz[shape = square];
Start -> Foo;
Foo:s -> Bar:n;
Bar:w -> Baz:n;
Bar:e -> Xyz:n;
Baz:s -> Foo:n;
}
其呈现方式如下:
有没有一种方法可以告诉graphviz绘制边
Baz->Foo
,而不与Foo->Bar
或Bar->Baz
相交?在graphviz布局中,您所能做的就是尽量避免干扰:)
从文件中取出指南针\u pt:
digraph Test {
Start[shape = doublecircle];
Foo[shape = square];
Bar[shape = diamond];
Baz[shape = square];
Xyz[shape = square];
Start -> Foo;
Foo -> Bar;
Bar -> Baz;
Bar -> Xyz;
Baz -> Foo;
}
你会得到:
添加一个不可见节点应该可以做到:
digraph Test {
Start[shape = doublecircle];
Foo[shape = square];
Bar[shape = diamond];
Baz[shape = square];
Xyz[shape = square];
// "invisible" node to connect baz to foo
BazToFoo [shape=none, label="", height=0, width=0]
Start -> Foo;
Foo:s -> Bar:n;
Bar:w -> Baz:n;
Bar:e -> Xyz:n;
Baz:s -> BazToFoo [dir=none] // remove the arrowhead
BazToFoo -> Foo:n;
}
虽然我同意保持简单,但这里有一种替代方法,可以进行一些更改以消除边缘交叉
digraph Test {
Start[shape = doublecircle, group=a];
Foo[shape = square, group=a];
Bar[shape = diamond, group=a];
Xyz[shape = square];
Baz[shape = square];
Start -> Foo;
Foo:s -> Bar:n;
Bar:e -> Baz:n;
Bar:w -> Xyz:n;
Baz:s -> Foo:n[constraint=false];
}
我发现graphviz的布局不容易沿图形的左外侧将边重新布线。可能是布局算法的工作方式,只允许图形向右和向下展开
这就是为什么我切换了底部节点的位置,使具有返回边的节点位于右侧