Graphviz - How to organize nodes in a loop in a rectangular layout?

Pre-Script

... And only when I finished the production of this example, I saw the roundtrip thread theme , which looks beautiful. Since I already said it here, I might also ask: are there any other alternatives?

Original publication

Is there a way to automatically lay out nodes in a rectangular layout when on a subgraph?

As an example, let's say I have this structure:

digraph
{
    rankdir="LR";

    node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];

    a -> b -> c -> d -> e -> f -> g -> h -> b;
}

It gives a chart test_1

My goal is for them to line up in a rectangle with rows of three nodes, forming

If I try to keep my rank and change rankdir, this is not as expected (I assume because you cannot change rankdirlike 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;
    }
}

test_2

, , :

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; }
}

test_3

Edit

, . , , ( )!

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" ];
}

enter image description here

+4
1

, , .

:

digraph
{
    rankdir="LR";

    node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];

    x -> y;
    y -> aa [ constraint="false" ];
    aa -> ab -> ac -> ba;

    { rank="same"; ba -> bb -> bc -> ca; }

    da -> cc -> cb -> ca [ dir="back" ];

    { rank="same"; aa -> dc -> db -> da [ dir="back" ]; };

}

enter image description here

:

digraph
{
    rankdir="LR";

    node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];

    x -> y;
    y -> aa [ constraint="false" ];
    aa -> ab -> ac;
    ac -> ba [ constraint="false" ];
    bc -> bb -> ba [ dir="back" ];

    bc -> ca [ constraint="false" ];
    ca -> cb -> cc;

    cc -> da [ constraint="false" ];
    dc -> db -> da [ dir="back" ];

    y -> dc [ dir="back", constraint="false" ];

    // { rank="same"; aa; bc; ca; dc; };
}

.

enter image description here

+2

Source: https://habr.com/ru/post/1523759/


All Articles