我正在尝试创建一个带有两个子图的图形。代码如下:
digraph G {
subgraph step1 {
style=filled;
node [label="Compiler"] step1_Compiler;
node [label="Maschine"] step1_Maschine;
color=lightgrey;
}
subgraph step2 {
style=filled;
color=lightgrey;
node [label="Interpretierer"] step2_Interpretierer;
node [label="Maschine"] step2_Maschine;
label="Virtuelle Maschine";
}
"Programm (Java)" -> step1_Compiler;
step1_Compiler -> step1_Maschine;
step1_Maschine -> "Bytecode";
"Bytecode" -> step2_Interpretierer;
step2_Interpretierer -> step2_Maschine;
step2_Maschine -> "Ergebnis";
}
我得到的结果如下:
我希望两个子图周围都能看到一个方框。我在这里缺少什么?
答案 0 :(得分:111)
您必须使用 cluster 为子图的名称添加前缀:
subgraph clusterstep1 {
和
subgraph clusterstep2 {
以获得样式和标签。
来自graphiz documentation, section "Subgraphs and Clusters":
子图的第三个角色直接涉及图形的方式 由某些布局引擎布局。 如果子图的名称开始 对于集群,Graphviz将子图注释为特殊集群 子图即可。如果支持,布局引擎将执行布局 属于集群的节点与整个节点一起绘制 绘制包含在边界矩形内的簇。注意 无论好坏,集群子图都不是DOT的一部分 语言,但仅仅是某些人遵守的句法惯例 布局引擎。