如何使GraphViz梯形图直线流动
How to make GraphViz ladder diagram flows straight
下面的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.
样条曲线属性稍微改变了结果。只改了第一行代码,像这样:
digraph ladder { ranksep=".1"; nodesep=".1"; splines=false;
禁用样条曲线时的结果如下:
好的,问题似乎是边缘 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"] }
}
变化是:
- 添加了
spline=line
指令
- 从边缘移除了 "Flow3" 标签(该修改将边缘变回直线)
- 向
c3
节点添加了 "Flow3" 标签
这就是最终结果:
这是另一种可能的解决方案。也是黑客。它涉及将弯曲的流分成多个较小的直线流。
改变这个:
{ rank=same; b3 -> d3 [dir=forward label="Flow3"] }
为此:
{
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"] }
}
生成的梯形图是这样的:
下面的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.
样条曲线属性稍微改变了结果。只改了第一行代码,像这样:
digraph ladder { ranksep=".1"; nodesep=".1"; splines=false;
禁用样条曲线时的结果如下:
好的,问题似乎是边缘 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"] }
}
变化是:
- 添加了
spline=line
指令 - 从边缘移除了 "Flow3" 标签(该修改将边缘变回直线)
- 向
c3
节点添加了 "Flow3" 标签
这就是最终结果:
这是另一种可能的解决方案。也是黑客。它涉及将弯曲的流分成多个较小的直线流。
改变这个:
{ rank=same; b3 -> d3 [dir=forward label="Flow3"] }
为此:
{
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"] }
}
生成的梯形图是这样的: