如何对齐节点列和包边?

时间:2017-10-03 21:10:16

标签: graphviz dot

我可以使用此代码生成图表:

档案test.dot

digraph g {
    {rank=same;  1 -> 2 -> 3 -> 4}
    {rank=same;  5 -> 6 -> 7 -> 8}
    {rank=same;  9 -> 10 -> 11 -> 12}

    4 -> 5
    8 -> 9
}

dot test.dot -Tpng -o test.png

输出:

enter image description here

但是,我希望节点的排列更像这样:

enter image description here

是否可以在graphviz dot中制作这样的图形?

1 个答案:

答案 0 :(得分:5)

使用具有较强重量的隐形边缘:

digraph g 
{
    splines="ortho"

    // connect the left most nodes and keep them one below the other
    1 -> 5 -> 9[ style = invis, weight = 10 ];

    // do your stuff
    { rank = same;  1 -> 2 -> 3 -> 4 }
    { rank = same;  5 -> 6 -> 7 -> 8 }
    { rank = same;  9 -> 10 -> 11 -> 12 }

    4 -> 5;
    8 -> 9;
}

yields

enter image description here