While trying to use Graphviz to create graphs for binary trees I've encountered many times a problem; apparently, with a high enough tree and a large enough nodesep
the resulting graph tends not to be symmetric. As an example, here's a dot source
digraph G {
nodesep=0.8;
ranksep=0.5;
{node[style=invis,label=""]; cx_30;
}
{rank=same; 20; 45; cx_30}
{rank=same; 10; 25;}
{rank=same; 40; 50}
30 -> 20;
30 -> 45;
20 -> 10;
20 -> 25;
45 -> 40;
45 -> 50;
{edge[style=invis];
//Distantiate nodes
30 -> cx_30;
20 -> cx_30 -> 45;
//Force ordering between childs
10:e -> 25:w;
40:e -> 50:w;
}
}
with the corresponding output (compiled with dot -Tpng file.dot > file.png
)
As you can see, 45
isn't placed in the middle between 40
and 50
. I could use invisible nodes between 40
and 50
to correct the situation, but the resulting spacing would be too wide.
Am I doing something wrong? Is there a way to correct the situation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…