下面的graphviz代码生成梯形图,但flow3是弯曲的。这仅在边缘穿过垂直线时发生。如何使flow3笔直且水平?我试着尝试使用splines属性但没有成功。如何更改代码以强制通过其他对象的直线?
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;
禁用样条曲线时显示此结果:
答案 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 :(得分: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"] }
}
得到的梯形图是这样的: