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

标签 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;
    } 
} 

带有相应的输出(使用 dot -Tpng file.dot > file.png 编译)
dot tree result

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

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

最佳答案

即使它对我没有直接作用,我还是通过了 Tom Ron 的建议去查看 this answer关于二叉树;提供的脚本对我不起作用,但 faq entry链接那里帮助我解决了问题;由于间距原因,我不想添加不可见节点,而是指定了正确的 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;
    } 
} 

与相应的输出 dot tree output

关于layout - 如何使表示二叉树的点图更对称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23429600/

相关文章:

android - 自定义 Android 评分栏拉伸(stretch)图像

Graphviz节点样式: thicker contours?

graphviz - 仅在 graphviz 中显示唯一的边

graphviz - 如何避免 Graphviz 点布局浪费空间,不同大小的节点处于同一等级?

jquery - 如何在 jQueryMobile 中跨页面保持相同的页眉/页脚?

android - 后台下载的自定义状态栏通知

magento - 如何删除产品页面 magento 上的附加选项卡

layout - Graphviz DOT 将节点排列成圆圈,布局也是如此 "compact"

python - 决策树可视化期间位置参数遵循关键字参数错误

适用于手机的 Android 条件布局 :tablets