家谱树的Graphviz Dot Edge端口

时间:2018-02-05 21:35:15

标签: tree graphviz dot graph-visualization

非常接近能够生成看起来不太可怕的家谱,但我遇到了以下问题。

//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";
}

以上代码生成this image,其边缘为 Son 1 Son 2 ,看起来很奇怪。我用dot -Tpng tree.dot运行它。当我运行相同的代码here时,我会得到expected output

我做错了吗?如何在不使用Web界面的情况下获得预期的输出(我可能有数百个节点)?换句话说,如何让 c0000 c0002 Son 1 Son 2 ,分别使它们的边缘连接到节点的中心顶部?

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

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

更改点文件末尾的以下行以包含端口。

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

产生此图像

Edge links are more toward center

这不会使边缘处于死点,并且将端口位置更改为n不起作用。但它不再像你原来那样指向空角。 GraphViz实用程序的一部分是自动布局,但有时它似乎会覆盖用户决策(或者是一个错误)。