This does not mean minimizing the lengths of the edges, especially since in the example the edges are defined with the attribute constraint=false .
Although this is not a complete answer, I think it can be found somewhere in the following two points:
- Important is the order in which nodes appear in the graph.
- Changing
rankdir to LR contains unpredictable (or at least hard to predict) behavior and / or probably still a mistake or two ( rankdir search ).
I will try to explain as well as I can, and I understand graphviz, but you can go and immediately read this answer from Emden R. Gansner to the graphviz mailing list , as well as the next answer from Stephen North - they should know, so I will give some of them .. .
Why is the order in which nodes appear important? By default, in the upper column, the first mentioned nodes will appear to the left of the following nodes, if edges and restrictions do not lead to a better location.
Therefore, without clusters and rankdir=LR graphs look like this (without surprises):
ADG BEH CFI
So far so good. But what happens when rankdir=LR is applied?
ERG wrote:
Dot processes rankdir = LR using a regular TB scheme, and then rotates the layout counterclockwise 90 degrees (and then, of course, controls the node rotation, edge direction, etc.). Thus, subgraph one is located to the left of subgraph two in the TB layout, as you would expect, and then ends lower than after rotation. If you want a subgraph that should be on top, list it second in the graph.
So, if this were correct, without clusters, the nodes should look like this:
GHI DEF ABC
In fact, they look like this:
ABC DEF GHI
Why? Stephen North replied:
At some point, we decided that there should be a default value from top to bottom,
even if the graph rotates, so the code that flips the edge plane inside.
So, TB is plotted on the graph, turned counterclockwise and the flat edges are inverted:
ADGGHIABC BEH --> DEF --> DEF CFIABCGHI
Although this works well enough for simple graphs, it seems that when the clusters are involved, everything is a little different. Usually, edges are also thrown into clusters (as in clusterY ), but there are times when smoothing a flat edge does not work, as you might think. Your example is one such case.
Why is there a mistake or limitation when turning these ribs? Since the same graphs are usually displayed correctly when using rankdir=TB .
Fortunately, workarounds are often easy - for example, you can use the order in which nodes appear to influence the layout:
digraph { rankdir="LR"; node[shape=record, height="0.4", width="0.4"]; edge[dir=none]; E;