点图 - 边连接重叠,不会空出

时间:2015-11-27 23:24:13

标签: graph graphviz dot edge

我也在试着看看我是否可以使用Dot编程语言将它应用到我的旧项目中。 任务很简单:轻松创建高质量的图形。 不幸的是,虽然实现我的图表的细节相当容易,但我不得不花费大量时间来调整布局。 此外,我很不清楚我的指令顺序如何影响我的图形,但它实际上看起来像我的代码的最后一条指令在开头产生一个完全不同的输出!

以下是代码:

digraph {
TOP [shape=doublecircle]
TOP->TOP->{rank=same a->b->c->b->a}
a:s->c:s
a:nw->a:sw
c:ne->c:se
b:s->b:s
}

如此。首先,我通过排名......终于掌握了“让节点在相同的水平/垂直线上”......

我还解决了边缘做愚蠢互连的问题(连接图形下方的所有自由空间,边缘以笨拙的方式绕过整个图形并且重叠一切?)使用方向指示器“ :e“和这样的(我相信它们被称为路线......),但看起来graphviz并没有以聪明的方式使用它们,因为结果对我来说很有趣。

以下是输出,如何避免边缘重叠并为将来()标签留出足够的空间?

My graph

(用 dot -Tpng test.dot -o test.png 制作)

(另外,我还需要在底部添加一个c->边缘,但添加一个“正常”方式会破坏一切......)

谢谢:)

1 个答案:

答案 0 :(得分:0)

您可以使用不可见的节点来重新路由"你想要的边缘(根据下面的评论编辑):

digraph
{
    /* layout */
    // node width to create space for longer labels
    node [ width = 1.75 ];
    { rank=same; a; b; c }

    /* nodes */
    t [ label = "TOP", shape = doublecircle, width = 1];
    a [ label = "short" ];
    b [ label = "medium" ];
    c [ label = "rather  l o n g"]
    // invisible nodes to 're-route' the edges
    x [ style = invis, shape = point, width = 0 ];
    y [ style = invis, shape = point, width = 0 ];

    /* edges */
    t -> t;
    t -> { a b c }
    t -> { a b c } [dir = back ];      // added for reverse arrows
    a -> b -> c -> b -> a;
    a:nw -> a:sw;
    c:ne -> c:se;
    b:s -> b:s;
    // put the invisible nodes at the desired places with invisible edges
    b -> x -> y [ style = invis ];
    // edges to invisible nodes must not have heads
    c:sw -> x [ arrowhead = "none" ];
    x -> a:se;
    a:s ->  y [ arrowhead = "none" ];
    y -> c:s;
}

产量

enter image description here