点图表中从左到右的订单框

时间:2015-12-11 16:37:49

标签: dot

我有这个gv代码,

我想要水平顺序: 12 13 14 15 23 24

但我明白了:

23 13 12 24 14 15

graph "tree" {
node [shape=plaintext];

1  [label = "1"]
2  [label = "2"]
3  [label = "3"]
4  [label = "4"]
5  [label = "5"]
12 [label = "12"]
13 [label = "13"]
14 [label = "14"]
15 [label = "15"]
23 [label = "23"]
24 [label = "24"]

1 -- 12;
2 -- 12;
1 -- 13;
3 -- 13;
1 -- 14;
4 -- 14;
1 -- 15;
5 -- 15;
2 -- 23;
3 -- 23;
2 -- 24;
4 -- 24;}  

解决方案:Force the left to right order of nodes in graphviz?对于这种情况不起作用(排序节点不是边缘)。

enter image description here

如果我添加:

{rank = same; 12 13 14 15 23 24; rankdir=LR;}

我们得到相同的无序节点:

png文件:

dot -T png test.gv > test.png

2 个答案:

答案 0 :(得分:1)

最简单的方法是添加'隐形'(白色,无箭头)边缘。

这将鼓励点按顺序对齐节点。

graph "tree" {
node [shape=plaintext];

1  [label = "1"]
2  [label = "2"]
3  [label = "3"]
4  [label = "4"]
5  [label = "5"]
12 [label = "12"]
13 [label = "13"]
14 [label = "14"]
15 [label = "15"]
23 [label = "23"]
24 [label = "24"]

1 -- 12;
2 -- 12;
1 -- 13;
3 -- 13;
1 -- 14;
4 -- 14;
1 -- 15;
5 -- 15;
2 -- 23;
3 -- 23;
2 -- 24;
4 -- 24;
// 'white' (invisible on white background) edges, weight to encourage order
// results in tidiest graph with horizontal nodes in desired order.
edge [color=white,weight=4,arrowhead=none,arrowtail=none];
12 -- 13 -- 14 -- 15 -- 23 -- 24 -- 25 -- 34 -- 35 -- 45;
{rank = same; 12 13 14 15 23 24 25 34 35 45; rankdir=LR;}
}

答案 1 :(得分:1)

或更简单地说:

graph "tree" {
    node[shape=plaintext]

    1 -- {12 13 14 15}
    2 -- {12 23 24}
    3 -- {13 23}
    4 -- {14 24}
    5 -- 15;

    {
        rank = same; 
        12 -- 13 -- 14 -- 15 -- 23 -- 24 [color=invis]
    }
}

enter image description here