【问题标题】:Order boxes left to right in dot graphviz在 dot graphviz 中从左到右排序框
【发布时间】:2016-03-17 15:34:10
【问题描述】:

我有这个 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? 不适用于这种情况(排序节点而不是边)。

如果我添加:

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

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

png 文件使用:

dot -T png test.gv > test.png

【问题讨论】:

    标签: dot


    【解决方案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;}
    }
    

    【讨论】:

    • 谢谢你的作品,顺便说一句,他们还有其他方法吗?
    • 您可以明确指定节点位置(分配 (x,y) 值),但我不希望这样做。多余的边缘有点烦人,但往往更容易维护并且整体看起来更好。
    【解决方案2】:

    或者更简单地说:

    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]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-29
      • 2015-05-08
      • 2010-12-02
      • 2015-07-04
      • 2010-12-03
      • 2021-11-05
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多