Search code examples
graphviz

How to control ordering of root nodes?


I can control ordering of other nodes using ordering="in", but root nodes have no incoming edges to define the order by that way.

Eg:

digraph {
  A -> B
  C -> D
  D -> X
  B -> X
  X [ordering="in"]
}

It generates this: actual output but I want this: desired output


Solution

  • This question may be duplicated with the question here. The following approach using additional invisible edges works perfectly for this graph:

    digraph {
      A -> B
      A -> D[style=invis];
      C -> B[style=invis];
      C -> D
      D -> X
      B -> X
      X [ordering="in"]
    }
    

    enter image description here