Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Align nodes of subgraph with another subgraph nodes

How do I align nodes with each other between subgraphs?
In the example, I would like all the 0 nodes aligned vertically as well as the 1, 2, 3 and 4 nodes. It would be good if all the right edges of subgraphs were extended as necessary to align too.

![From this

To this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

digraph AlignWhenMissing {
rankdir=LR;
node [shape=box]

subgraph clusterA {label = "A Shift a4 along (no a3)";
    a0 -> a1;
    a1 -> a2;
    a2 -> a4;
}

subgraph clusterB {label = "B Shift b2 above a2";
    b0 -> b2;
    b2 -> b3;
}

subgraph clusterC {label = "C Shift c3 above b3";
    c0 -> c3;
}

A -> a0[lhead=clusterA];
B -> b0[lhead=clusterB];
C -> c0[lhead=clusterC];

a0 -> b0[constraint=false];
b3 -> c3[constraint=false];
a2 -> b2[constraint=false];
}

>Solution :

The minlen attribute (https://graphviz.org/docs/attrs/minlen/) applies to edges to lengthen them (i.e. to push them "out" by N ranks).
Then added invisible nodes and edges to increase cluster dimension.

digraph AlignWhenMissing {
rankdir=LR;
node [shape=box]

subgraph clusterA {label = "A Shift a4 along (no a3)";
    a0 -> a1;
    a1 -> a2;
    a2 -> a4 [minlen=2];
}

subgraph clusterB {label = "B Shift b2 above a2";
    b0 -> b2 [minlen=2]
    b2 -> b3;
    b4 [style=invis]
    b3 -> b4 [style=invis]
}

subgraph clusterC {label = "C Shift c3 above b3";
    c0 -> c3 [minlen=3];
    c4 [style=invis]
    c3 -> c4 [style=invis]
}

A -> a0[lhead=clusterA];
B -> b0[lhead=clusterB];
C -> c0[lhead=clusterC];

a0 -> b0[constraint=false];
b3 -> c3[constraint=false];
a2 -> b2[constraint=false];
}

Giving:
enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading