问题描述
我有这个Graphviz DOT图:
digraph unit_test {
label="Unit test"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start
end
node[shape="Box" style="filled" fillcolor="#ff7f0e"]
process
subgraph cluster_process {
label = "Major logic"
process
}
start -> process
process -> end
}
以上呈现为:
我有第二张图:
digraph details {
label = "Process details"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start
end
node[shape="Box" style="filled" fillcolor="#ff7f0e"]
details
subgraph cluster_details {
label = "Details"
details
}
start -> details
details -> end
}
哪个呈现给:
问题
当我将上述两个图形放在同一个名为supporting.dot
的DOT文件中并运行dot -Tpng -o supporting.png supporting.dot
命令时,终端将打印出一些粗体,并且输出图像文件将不包含两个图形包含第一个。一个DOT文件中可以使用多个图形吗?如果是这样,我想念什么?
解决方法
Dot无法将2个图形呈现到单个文件中,您看到的输出可能是其中一个图形的png内容。
为防止这种情况,您可以先通过gvpack运行图形-类似:
gvpack -u supporting.dot | dot -Tpng -o supporting.png
这会将supporting.dot
中的所有图形组合成一个图形,然后使用dot
进行渲染。
gvpack的更多选项可能会影响图形的布局。
,对于要完成的任务尚不清楚,但是以下可能是一个起点
digraph G{
subgraph unit_test {
label="Unit test"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start
end
node[shape="box" style="filled" fillcolor="#ff7f0e"]
process
subgraph cluster_process {
label = "Major logic"
process
}
start -> process
process -> end
}
subgraph details {
label = "Process details"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start1 [label="start"]
end1 [label="end"]
node[shape="box" style="filled" fillcolor="#ff7f0e"]
details
subgraph cluster_details {
label = "Details"
details
}
start1 -> details
details -> end1
}
}
请注意第二个子图中的命名/标签。
,在一个输入文件中定义多个图形是合法的。然后,您可以使用 -O 选项生成多个输出文件,如下所示:
dot -Tpng -O multi.gv
这将产生 multi.gv.png 和 multi.gv.2.png