Graphviz:水平对齐无法使用向后箭头

时间:2016-10-26 20:00:27

标签: graphviz dot

我制作了以下图片:

enter image description here

我想添加一个额外的箭头,指向"远程回购"一直到"工作副本" (标有" git pull")我希望理想情况下首先略微向下,然后向左,然后向上。

当我只是在代码中添加一个箭头时,图形最终看起来像这样:

enter image description here

这是代码:

digraph G {
    /* set direction of graph to be left-->right */
    rankdir="LR";

    /* make boxes instead of ellipses */
    node [shape=box];

    /* should enforce nodes to be horizontally aligned */
    /* is not working, though... */
    rank=same;

    /* assign labels to nodes */
    wc [label="working copy"];
    id [label="index"];
    lr [label="local repo"];
    rr [label="remote repo"];

    wc -> id [label="git add"];
    id -> lr [label="git commit"];
    lr -> rr [label="git push"];

    rr -> wc [label="git pull"];
}

问题:为什么水平对齐方式被破坏以及如何解决这个问题?

后续问题:如何使箭头朝下,然后向左,然后向上? (或者是使用某种不可见/假节点的唯一方法吗?)

1 个答案:

答案 0 :(得分:1)

您可以使用constraint=false属性修改有问题的边缘。然后你会收到下面的图表。

enter image description here

如果你更喜欢角度边缘,你也可以splines=ortho获得图表。

enter image description here

请使用实例查看http://graphviz.it/#/mqNwRgzu。我已经粘贴了源代码。

digraph G {
    /* set direction of graph to be left-->right */
    rankdir="LR";
    splines=ortho;

    /* make boxes instead of ellipses */
    node [shape=box];

    /* should enforce nodes to be horizontally aligned */
    /* is not working, though... */
    rank=same;

    /* assign labels to nodes */
    wc [label="working copy"];
    id [label="index"];
    lr [label="local repo"];
    rr [label="remote repo"];

    wc -> id [label="git add"];
    id -> lr [label="git commit"];
    lr -> rr [label="git push"];

    rr -> wc [label="git pull", constraint=false];
}