WojciechKo
WojciechKo

Reputation: 1531

children order in graphviz tree

I have following tree:

digraph G {
    subgraph cluster0{
        37[label="+"];
        42[label="a"];
        44[label="b"];
        47[label="*"];
        46[label="c"];
        49[label="d"];
        51[label="e"];
        53[label="f"];
        55[label="g"];
        57[label="h"];
        61[label="*"];
        60[label="i"];
        63[label="j"];
        37 -> 42[label="c"];
        37 -> 44[label="c"];
        37 -> 47[label="c"];
        37 -> 61[label="c"];
        42 -> 37[label="p"];
        44 -> 37[label="p"];
        47 -> 37[label="p"];
        47 -> 46[label="c"];
        47 -> 49[label="c"];
        47 -> 51[label="c"];
        47 -> 53[label="c"];
        47 -> 55[label="c"];
        47 -> 57[label="c"];
        46 -> 47[label="p"];
        49 -> 47[label="p"];
        51 -> 47[label="p"];
        53 -> 47[label="p"];
        55 -> 47[label="p"];
        57 -> 47[label="p"];
        61 -> 37[label="p"];
        61 -> 60[label="c"];
        61 -> 63[label="c"];
        60 -> 61[label="p"];
        63 -> 61[label="p"];
    }
}

Output is here: https://i.sstatic.net/CoUlH.png

Order of children in first * subtree is: G H C D E F, but it should be C D E F G H. I have noticed that if I delete subgraph cluster0{ the order is right, but I can't do it this way. Can you suggest any other solution?

Upvotes: 4

Views: 1561

Answers (1)

Pekka
Pekka

Reputation: 3644

Graphviz attempts to retain the lexical ordering of nodes when there is no other constraint. However, the edge labels can affect placement as they take up space and can push nodes around.

If you have a specific order that is essential, then try something like

{ rank = same; 
46 -> 49 -> 51 -> 53 -> 55 -> 57 [style = invis];
}

to introduce the additional ordering constraint into the graph.

You need to be careful with this though, as it can distort more complex graphs in ways that are very difficult to predict.

Clusters further complicate matters in larger graphs as they implicitly attempt to make the subgraph more compact and introduce a bounding box that non-cluster members cannot cross.

Upvotes: 2

Related Questions