Pre-Script
... And just when I finished producing these example, I saw the 'roundtrip' flow topic, which looks nice. Since I've already put this on here, might as well ask: are there another alternatives?
Original Post
Is there a way to automatically lay out nodes in a rectangular layout when in a subgraph?
As an example, say I have the given structure:
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e -> f -> g -> h -> b;
}
This yields the diagram
My goal is to have them line up in a rectangle with rows of three nodes, forming
If I try to constrain the rank and change the rankdir
, it is not as expected (I'm assuming because you can't change rankdir
like this):
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e -> f -> g -> h -> b;
subgraph
{
rankdir="TB";
rank="same";
c; d; e;
}
subgraph
{
rankdir="TB";
rank="same";
f; g; h;
}
}
If I go through and manually and assign rank to line up as I desired, it works:
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e -> f -> g -> h -> b;
{ rank="same"; c; h; }
{ rank="same"; d; g; }
{ rank="same"; e; f; }
}
Edit
Just tried out the method, worked well. I did have to unconstrain the right-most edge to prevent it from making an asymetric shape, but overall worked like a charm (and much more intuitive)!
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e;
e -> f [ constraint="false" ];
b -> h -> g -> f [ dir="back" ];
}