How to prevent the subgraph cluster alignment order from being reversed?

Viewed 464

If I have a graphviz dot script like this:

digraph g {
node [style=rounded, shape=box]

    subgraph cluster1 {
        style="invis"
        1 -> 2 -> 3 -> 4 -> 5
    }

    subgraph cluster2 {
        style="invis"
         6 -> 7

         7 -> 8 -> 11
         7 -> 9 -> 11
         7 -> 10 -> 11
    }

    edge[constraint=false];
    splines="ortho"
    5 -> 6 [weight=0]
}

I get an output that looks like this (what I want):

enter image description here

However, if the labels in some of the nodes at the end become too long, the arrangement gets reversed like this:

digraph g {
node [style=rounded, shape=box]

8 [label="very long label"]
9 [label="very long label"]
10 [label="very long label"]


    subgraph cluster1 {
        style="invis"
        1 -> 2 -> 3 -> 4 -> 5
    }

    subgraph cluster2 {
        style="invis"
         6 -> 7

         7 -> 8 -> 11
         7 -> 9 -> 11
         7 -> 10 -> 11
    }

    edge[constraint=false];
    splines="ortho"
    5 -> 6 [weight=0]
}

enter image description here

How can I prevent this and force the original ordering method to occur?

1 Answers

You will have to define your long labels after having defined the other; graphviz draws the nodes in the order the are defined.

digraph g {
node [style=rounded, shape=box]

    subgraph cluster1 {
        style="invis"
        1 -> 2 -> 3 -> 4 -> 5
    }

    subgraph cluster2 {
        style="invis"
         6 -> 7

         7 -> 8 -> 11
         7 -> 9 -> 11
         7 -> 10 -> 11
    }

    8 [label="very long label"]
    9 [label="very long label"]
    10 [label="very long label"]

    edge[constraint=false];
    splines="ortho"
    5 -> 6 [weight=0]
}

yields

enter image description here

Related