我有一个非常简单的图表:
digraph G {
"for" -> "initial assignment"
"initial assignment" -> "condition"
"condition" -> "code" [color=red]
"condition" -> "end" [color=red]
"code" -> "final assignment" [color=red]
"final assignment" -> "condition" [color=red]
}
Run Code Online (Sandbox Code Playgroud)
但是,节点必须按特定顺序从上到下绘制。(红色箭头是红色的,因为它们违反了这个特定的顺序。)
一种方法是:
digraph G {
{rank = same; "$1"; "for"}
{rank = same; "$2"; "initial assignment"}
{rank = same; "$3"; "condition"}
{rank = same; "$4"; "final assignment"}
{rank = same; "$5"; "code"}
{rank = same; "$6"; "end"}
"$1" -> "$2" -> "$3" -> "$4" -> "$5" -> "$6"
"for" -> "initial assignment"
"initial assignment" -> "condition"
"condition" -> "code" [color=red]
"condition" -> "end" [color=red]
"code" -> "final assignment" [color=red]
"final assignment" -> "condition" [color=red]
}
Run Code Online (Sandbox Code Playgroud)
但是,这会在图表上显示那些额外的节点,我宁愿没有。如何在不绘制节点和边的情况下定义它们?
(我可以将边缘定义为白色,将节点文本定义为白色等,但 graphviz 仍会为它们分配空间,这不适用于透明 png 图像。此外,图层不适用于所有输出格式比如.png,这些节点需要的空间还是分配的,这些方案暂且不考虑。)
Graphviz 的作者Stephen North建议使用[style=invis]:
digraph G {
{
node [style=invis]
edge [style=invis]
"$1" -> "$2" -> "$3" -> "$4" -> "$5" -> "$6"
}
{rank = same; "$1"; "for"}
{rank = same; "$2"; "initial assignment"}
................................................................................
Run Code Online (Sandbox Code Playgroud)
这并不能完全解决问题,因为空间仍然分配给这些零碎的东西,但我不得不猜测它已经尽力了。
| 归档时间: |
|
| 查看次数: |
7414 次 |
| 最近记录: |