【发布时间】:2020-01-13 18:34:54
【问题描述】:
我有这个代码
graph G {
node [shape=circle]
rankdir=LR;
1 -- 10;
2 -- 9;
3 -- 8;
4 -- 7;
5 -- 6;
}
但我想将顶点 1 ... 10 放在一个平坦的水平行中,然后将连接边作为弧(上、下交替)连接 1 到 10、2 到 9 等。我的代码只产生一堆顶点及其边。
【问题讨论】:
标签: graphviz
我有这个代码
graph G {
node [shape=circle]
rankdir=LR;
1 -- 10;
2 -- 9;
3 -- 8;
4 -- 7;
5 -- 6;
}
但我想将顶点 1 ... 10 放在一个平坦的水平行中,然后将连接边作为弧(上、下交替)连接 1 到 10、2 到 9 等。我的代码只产生一堆顶点及其边。
【问题讨论】:
标签: graphviz
您需要先告诉graphviz,您希望将节点排成一行。只有这样,您才能以您喜欢的方式引入第二组边缘。对于graphviz 如何放置边缘的控制非常有限;反复试验使我找到了下面的解决方案,这是我能找到的最好的解决方案。
见代码中的cmets:
graph so
{
node [shape=circle]
rankdir=LR;
// We put all nodes in one row
// We need the weight to keep them straight
// Edge style is invisible, so that they are not in the way of your edges
1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7 -- 8 -- 9 -- 10[ weight = 10, style = invis ];
1:ne -- 10:nw; // added ports to force node above
2 -- 9; // the rest is graphviz' decision
3 -- 8;
4 -- 7;
5 -- 6;
}
给你
【讨论】:
试试这个。不可见的边缘将强制执行等级内的顺序。双5——6边是强制弧线,否则边是直的。我在 viz-js.com 上试过。上弧和下弧的交替很大程度上取决于边缘的顺序。由于它非常敏感,没有文档并且可能容易发生较小的版本更改,因此我不建议将其作为生产解决方案,恕我直言,DOT 引擎不适合此类任务。对于一次性文档的目的,它就足够了并且满足您的规范。
graph G {
splines=splines;
node [shape=circle];
edge [constraint=false];
rankdir=LR;
1 -- 10;
3 -- 8;
2 -- 9;
1 -- 2 [style=invis, constraint=true];
2 -- 3 [style=invis, constraint=true];
3 -- 4 [style=invis, constraint=true];
4 -- 5 [style=invis, constraint=true];
5 -- 6 [style=invis];
4 -- 7;
5 -- 6 [constraint=true];
6 -- 7 [style=invis, constraint=true];
7 -- 8 [style=invis, constraint=true];
8 -- 9 [style=invis, constraint=true];
9 -- 10 [style=invis, constraint=true];
}
【讨论】: