Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order boxes left to right in dot graphviz

Tags:

dot

I have this gv code,

I want to have the horizontal order : 12 13 14 15 23 24

but I get:

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

the solution : Force the left to right order of nodes in graphviz? did not work for this case (ordering nodes not edges).

enter image description here

If I add :

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

We get the same unordered nodes:

png file made with:

dot -T png test.gv > test.png
like image 888
user3313834 Avatar asked Sep 13 '25 20:09

user3313834


1 Answers

Or more simply:

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

like image 50
nachocab Avatar answered Sep 17 '25 21:09

nachocab