Graphviz Dot Edge Ports for Family Tree

两盒软妹~` 提交于 2020-01-15 03:40:07

问题


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

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.

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?

Thanks in advance for your help!


回答1:


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]

results in this image

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).



来源:https://stackoverflow.com/questions/48631866/graphviz-dot-edge-ports-for-family-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!