【问题标题】:How can I create a loop in my Graphviz flowchart?如何在我的 Graphviz 流程图中创建循环?
【发布时间】:2017-09-22 13:22:43
【问题描述】:

我正在尝试创建一个带有设置位置的节点的流程图。我正在使用不可见的节点来尝试强制边缘的方向。我的图如下。 它不太正确,因为我希望从节点 d 出来的线以及从 cd 的边缘是连续的(并且是直的)。

我怎样才能让线条全部连接起来?谢谢

我要重现的代码

digraph g1 {

  graph [splines=false];

  // invisible nodes
  node[fontsize=15, shape = box, width=3, height=0] ;
  i1 [ style="invis"];
  i2 [ style="invis"];
  i3 [ style="invis"];
  i4 [ style="invis"];

  node[fontsize=15, color = black, shape = box, width=3, height=1] ;
  a[color=blue, label="a"];
  b[color=green, label="b"];
  c[color=orange, label="c"]; 
  d[color=red, label="d"] ;       

  {rank=same; a -> b -> c};

  {rankdir = TB;    c -> i1[arrowhead=none];
        i1 -> d[label="  FOR EACH\n\n"]; 
        d -> i2[arrowhead=none];
  };

  {rank=same; i3 -> i2[arrowhead=none] };

  {rankdir = TB; 
    b -> i4[style="invis"];
    i4 -> i3[arrowhead=none];
  };

  {rank=same; i4 -> i1};

}

根据 Paul 的评论,我尝试使用 node[fontsize=15, shape = box, label="", width=0, height=0, fixedsize=true] 导致

【问题讨论】:

  • 看起来不可见节点的大小导致箭头在“半空中”开始。对于不可见的节点,我会尝试类似node[shape = box, width=0, height=0 fixedsize=true] ;,但我现在无法尝试。
  • 谢谢@PaulR;我已经用你的建议编辑了这个问题。似乎通过将宽度和高度设置为零会改变节点的定位方式。
  • 啊,我明白了...也许你可以使用 ranksep 属性和“相等”来影响间距。
  • 谢谢@PaulR,我会试试看的。

标签: loops graphviz flowchart


【解决方案1】:

使用shape = pointsminlen 来拯救:

digraph g1 {

  graph [splines=false];

  // invisible nodes
  node[ shape = point, width=0, height=0] ;
  i1 [ style="invis"];
  i2 [ style="invis"];
  i3 [ style="invis"];
  i4 [ style="invis"];

  node[fontsize=15, color = black, shape = box, width=3, height=1] ;
  a[color=blue, label="a"];
  b[color=green, label="b"];
  c[color=orange, label="c"]; 
  d[color=red, label="d"] ;       

  {rank=same; a -> b -> c};

  c -> i1[arrowhead=none];
  i1 -> d[label="  FOR EACH\n\n"]; 
  d -> i2[arrowhead=none];

  {rank=same; i3 -> i2[arrowhead=none, minlen = 7 ] };

  b -> i4[style="invis"];
  i4 -> i3[arrowhead=none];

  {rank=same; i4 -> i1};

}

产量

【讨论】:

  • 谢谢 vaettchen,看起来不错。请问minlen=7是跟踪和错误吗?
  • 是的。它恰好是 3 + 3 + 1(你的盒子的宽度乘以 2,加上 1 个空格)但不确定这是否是巧合......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-23
  • 2019-04-09
  • 1970-01-01
  • 2020-09-16
  • 1970-01-01
  • 2015-10-16
相关资源
最近更新 更多