如何使GraphViz梯形图直接流动

时间:2016-11-12 00:32:48

标签: graphviz dot

下面的graphviz代码生成梯形图,但flow3是弯曲的。这仅在边缘穿过垂直线时发生。如何使flow3笔直且水平?我试着尝试使用splines属性但没有成功。如何更改代码以强制通过其他对象的直线?

enter image description here

digraph ladder { ranksep=".1"; nodesep=".1";

# Define the defaults
  node [shape=point fontsize=10]
  edge [dir=none fontsize=10]

# Column labels
  a [shape=none]
  b [shape=none]
  c [shape=none]
  d [shape=none]

# Draw the 4 column headings, no line
  { rank=same; edge[style=invis] a -> b -> c -> d   }

# Draw the columns
  a -> a1 [style=invis]
  b -> b1 [style=invis]
  c -> c1 [style=invis]
  d -> d1 [style=invis]
  a1 -> a2 -> a3 -> a4 [weight=1000 label="   "]
  b1 -> b2 -> b3 -> b4 [weight=1000 label="   "]
  c1 -> c2 -> c3 -> c4 [weight=1000 label="   "]
  d1 -> d2 -> d3 -> d4 [weight=1000 label="   "]

# Now each step in the ladder
  { rank=same; a1 -> b1 [dir=forward label="Flow1"]  }
  { rank=same; b2 -> c2 [dir=forward label="Flow2"]  }
  { rank=same; b3 -> d3 [dir=forward label="Flow3"]  }
  { rank=same; c4 -> d4 [dir=back label="Flow4"]  }
}

编辑每条评论的更新。

运行GraphViz版本2.38.0。

splines属性会稍微改变结果。只更改了第一行代码,如下所示:

digraph ladder { ranksep=".1"; nodesep=".1"; splines=false;

禁用样条曲线时显示此结果:

enter image description here

2 个答案:

答案 0 :(得分:1)

好的,问题似乎是边缘b3 -> d3试图避开自己的标签(可能与此issue有关)。

所以这是一个可怕的黑客来解决这个问题:

 digraph ladder { ranksep=".1"; nodesep=".1"; splines="line";

 # Define the defaults
   node [shape=point fontsize=10]
   edge [dir=none fontsize=10]

 # Column labels
   a [shape=none]
   b [shape=none]
   c [shape=none]
   d [shape=none]

 # Draw the 4 column headings, no line
   { rank=same; edge[style=invis] a -> b -> c -> d   }

 # Draw the columns
   a -> a1 [style=invis]
   b -> b1 [style=invis]
   c -> c1 [style=invis]
   d -> d1 [style=invis]

   a1 -> a2 -> a3 -> a4 [weight=1000 label="   "]
   b1 -> b2 -> b3 -> b4 [weight=1000 label="   "]
   c1 -> c2 -> c3 -> c4 [weight=1000 label="   "]
   d1 -> d2 -> d3 -> d4 [weight=1000 label="   "]

  # inserted a label for the node that "pretends" to be the edge label
   c3 [xlabel="Flow3"]

 # Now each step in the ladder
   { rank=same; a1 -> b1 [dir=forward label="Flow1"]  }
   { rank=same; b2 -> c2 [dir=forward label="Flow2"]  }
   { rank=same; b3 -> d3 [dir=forward ]  } #removed the label
   { rank=same; c4 -> d4 [dir=back label="Flow4"]  }
 }

变化是:

  1. 添加了spline=line指令
  2. 从边缘移除“Flow3”标签(该修改将边缘转回直线)
  3. c3节点
  4. 中添加了“Flow3”标签

    这是最后的结果:

    enter image description here

答案 1 :(得分:1)

这是另一种可能的解决方案。也是一个黑客。它涉及将弯曲流分成多个较小的直流。

改变这个:

  { rank=same; b3 -> d3 [dir=forward label="Flow3"]  }

To This:

  {
    rank=same;
    b3 -> c3 [dir=none]
    c3 -> d3 [dir=forward label="Flow3"]
  }

还进行了一些其他无关的改进,使节点不可见,垂直边缘点缀。所以完整的代码是:

digraph ladder { ranksep=".1"; nodesep=".1";

# Define the defaults
  node [shape=point fontsize=10]
  edge [dir=none fontsize=10]

# Column labels
  a [shape=none]
  b [shape=none]
  c [shape=none]
  d [shape=none]

# Draw the 4 column headings, no line
  { rank=same; edge[style=invis] a -> b -> c -> d   }

# Draw the columns
  node [style=invis]
  a -> a1 [style=invis]
  b -> b1 [style=invis]
  c -> c1 [style=invis]
  d -> d1 [style=invis]
  a1 -> a2 -> a3 -> a4 [style=dotted weight=1000 label="   "]
  b1 -> b2 -> b3 -> b4 [style=dotted weight=1000 label="   "]
  c1 -> c2 -> c3 -> c4 [style=dotted weight=1000 label="   "]
  d1 -> d2 -> d3 -> d4 [style=dotted weight=1000 label="   "]

# Now each step in the ladder
  { rank=same; a1 -> b1 [dir=forward label="Flow1"]  }
  { rank=same; b2 -> c2 [dir=forward label="Flow2"]  }
  {
    rank=same;
    b3 -> c3 [dir=none]
    c3 -> d3 [dir=forward label="Flow3"]
  }
  { rank=same; c4 -> d4 [dir=back label="Flow4"]  }
}

得到的梯形图是这样的:

enter image description here