3lli0t
3lli0t

Reputation: 77

Graphviz subgraphs order

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!

Upvotes: 4

Views: 6065

Answers (1)

vaettchen
vaettchen

Reputation: 7659

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

Upvotes: 5

Related Questions