Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing clusters on the same rank in Graphviz

Tags:

graphviz

I would like these two nodes to appear on the same level:

enter image description here

digraph G {
    subgraph cluster1 {
        label="Local Datacenter";
        router1;
        host1;
    }
    subgraph cluster2 {
        label="Remote Datacenter";
        router2;
        host2;
    }
    router1 -> router2;
    router2 -> host2;
    router1 -> host1;
}

I have tried using rank=same and rank=min, but they aren't giving me what I need.

Interestingly, if I set rankdir=LR and comment out the two router-to-host edges, it gives me exactly the look I want - but I would like to leave the edges intact.

like image 694
tinypigdotcom Avatar asked Jul 26 '11 01:07

tinypigdotcom


2 Answers

You may use the newrank graph attribute (added in GraphViz 2.30) to activate the new ranking algorithm which allows defining rank=same for nodes which belong to clusters.

Add the following line at the top:

newrank=true;

Add the following line after the cluster definitions:

{ rank=same; router1; router2; }

Here's the resulting graph:

routers with same rank

like image 112
dubek Avatar answered Sep 23 '22 16:09

dubek


You may simply modify the edge between the routers:

router1 -> router2[constraint=false];

constraint indicates whether the edge should be used in the ranking of the nodes.

like image 30
marapet Avatar answered Sep 22 '22 16:09

marapet