家族树的Graphviz点边缘端口 [英] Graphviz Dot Edge Ports for Family Tree

查看:106
本文介绍了家族树的Graphviz点边缘端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常能够生成看起来并不可怕的家谱,但是我遇到了以下问题.

I am very close to being able to generate a family tree that doesn't look terrible, but I'm running into the following problem.

//file: tree.dot
digraph {
    edge [dir=none];
    node [
        fillcolor="black",fixedsize=true,shape=box,
        style="rounded,filled",width=2.0
    ];
    splines=ortho;
    // GEN -01
    {
        rank=same; rankdir=LR;
        "Grandfather" [regular=0];
        m0002 [
            label="",shape=diamond,regular=0,height=0.25,
            width=0.25,style="filled",
        ];
        "Grandmother" [regular=0];
        {
            rank=same; rankdir=LR;
            "Grandfather" -> m0002 -> "Grandmother";
        }
    }
    m0002 -> c0001;
    // GEN  00
    {
        rank=same; rankdir=LR;
        c0000 [
            label="",shape=circle, regular=0, height=0.05,
            width=0.05,style="filled"
        ];
        c0001 [
            label="",shape=circle, regular=0, height=0.05,
            width=0.05,style="filled"
        ];
        c0002 [
            label="",shape=circle, regular=0, height=0.05,
            width=0.05, style="filled"
        ];
        {
            rank=same; rankdir=LR;
            c0000 -> c0001 -> c0002;
        }
    }
    {
        rank=same; rankdir=LR;
        "Son 1" [regular=0];
        "Daughter 1" [regular=0];
        "Son 2" [regular=0];
        m0000 [
            label="",shape=diamond,regular=0,height=0.25,
            width=0.25,style="filled"
        ];
        "Other Daughter 1" [regular=0];
        "Other Son 1" [regular=0];
        "Other Other Son 1" [regular=0];
        m0001 [
            label="",shape=diamond,regular=0,height=0.25,
            width=0.25, style="filled"
        ];
        "Other Daughter 2" [regular=0];
        {
            rank=same; rankdir=LR;
            "Son 2" -> m0000 -> "Other Daughter 1";
            "Other Other Son 1" -> m0001 -> "Other Daughter 2";
        }
    }
    c0000 -> "Son 1";
    c0001 -> "Daughter 1";
    c0002 -> "Son 2";
}

上面的代码生成此图像,该边缘具有 Son 1 Son 2 看起来很奇怪.我用dot -Tpng tree.dot运行了它.当我在此处运行相同的代码时,我得到了

The above code produces this image, which has edges to Son 1 and Son 2 that look weird. I ran it with dot -Tpng tree.dot. When I run the same code here, I get the expected output.

我做错什么了吗?如何在不使用Web界面的情况下获得预期的输出(我可能有数百个节点)?换句话说,如何使 c0000 c0002 儿子1 儿子2 ,以便它们的边缘附着到节点的中心顶部?

Am I doing something wrong? How can I get the expected output without using the web interface (I will have potentially hundreds of nodes)? In other words, how can I get c0000 and c0002 to line up with the center of Son 1 and Son 2, respectively, so that their edges attach to the center top of the nodes?

提前感谢您的帮助!

推荐答案

您可以使用端口指定边缘连接的位置,该端口使用罗盘方向,n,s,e,w,nw,ne, sw,se.

You can specify where the edge connects using ports which use compass directions, n, s, e, w, nw, ne, sw, se.

在点文件的末尾更改以下几行以包含端口.

Changing the following lines at the end of your dot file to include ports.

    c0000 -> "Son 1" [headport=ne];
    c0002 -> "Son 2":nw; // Shorthand for [headport=nw]

产生此图片

这不会使边缘居中,并且将端口位置更改为n不起作用.但是它不再像原始图像一样具有指向空角的边缘. GraphViz实用程序的一部分是自动布局,但是有时它似乎会覆盖用户的决定(或者是一个错误).

This doesn't put the edges dead center, and changing the port locations to n doesn't work. But it no longer has edges pointing to an empty corner like your original. Part of GraphViz's utility is the autolayout but sometimes it seems to override user decisions (or is a bug).

这篇关于家族树的Graphviz点边缘端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆