Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz subgraphs order

Tags:

graphviz

dot

I'm trying to create a graphic network with dot. and Graphiz.

So far this is my code:

  graph {
rankdir  = LR;
splines=line;       

subgraph cluster_1{            
    1; 2;
}
subgraph cluster_2{
    b; c;
}

subgraph cluster_3{
color = white       
    10;11;
}

b -- {1 2 10 11}[color = blue];
c -- {1 2 10 11}[color = yellow];   



1[label = "1", style = filled, fillcolor = grey91]
2[label = "2", style = filled, fillcolor = grey91]
b[label = "B", style = filled, fillcolor = blue]
c[label = "C", style = filled, fillcolor = yellow]
10[label = "10", style = filled, fillcolor = grey91]
11[label = "11", style = filled, fillcolor = grey91]

}

This is what I get:

enter image description here

This is what I would like to obtain: enter image description here

How to put the subgraphs in the correct order?

Thank you everyone in advance for your help! Kind regards!

like image 202
3lli0t Avatar asked Sep 03 '25 16:09

3lli0t


1 Answers

Defining the edges in the order as desired helps. Your version puts 1 2 10 11 in the same rank, hence they are set one below the other.

graph 
{
    rankdir = LR;
    splines = line;

    node[ style = filled, fillcolor = grey91 ];
    1 2 10 11;
    b[ label = "B", fillcolor = blue   ];
    c[ label = "C", fillcolor = yellow ];


    subgraph cluster_1
    {            
        1; 2;
    }
    subgraph cluster_2
    {
        b; c;
    }
    subgraph cluster_3
    {
        color = white       
        10; 11;
    }

    edge[ color = blue ]
    { 1 2 } -- b -- { 10 11 };
    edge[ color = yellow ]
    { 1 2 } -- c -- { 10 11 };
}

yields

enter image description here

like image 158
vaettchen Avatar answered Sep 05 '25 14:09

vaettchen