如何使表示二叉树的点图更对称?

gca*_*ali 6 layout graphviz

在尝试使用 Graphviz 为二叉树创建图形时,我遇到了很多次问题;显然,如果树足够高且足够大nodesep,结果图往往不对称。例如,这是一个点源

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;
    } 
} 
Run Code Online (Sandbox Code Playgroud)

与相应的输出(编译dot -Tpng file.dot > file.png点树结果

如您所见,45不是放在40和之间的中间50。我可以在40和之间使用不可见的节点50来纠正这种情况,但由此产生的间距会太宽。

难道我做错了什么?有没有办法纠正这种情况?

gca*_*ali 6

尽管它对我没有直接作用,但我正在通过 Tom Ron 的建议来查看有关二叉树的答案;提供的脚本对我不起作用,但链接到那里的常见问题解答帮助我解决了问题;由于间距原因,我不想添加不可见节点,但是width为不可见节点指定正确的属性并进行缩放,nodesep因此效果很好。

这是一个更正的来源:

digraph G {
    nodesep=0.4; //was 0.8
    ranksep=0.5;

    {node[style=invis,label=""]; cx_30;
    }
    {node[style=invis, label="", width=.1]; ocx_45; ocx_20;
    }

    {rank=same; 20; 45; cx_30}
    {rank=same; 10; 25; ocx_20}
    {rank=same; 40; 50; ocx_45}

    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 children
                        45 -> ocx_45;
                            40 -> ocx_45 -> 50;
                        20 -> ocx_20;
                            10 -> ocx_20 -> 25;
    } 
} 
Run Code Online (Sandbox Code Playgroud)

与相应的输出 点树输出