在 DOT
的 DOT
语言中,我试图表示一个依赖关系图 . 我需要能够在容器内部拥有节点,并且能够使节点和/或容器依赖于其他节点和/或容器 .
我正在使用 subgraph
来代表我的容器 . 节点链接工作正常,但我无法弄清楚如何连接子图 .
鉴于下面的程序,我需要能够用箭头连接 cluster_1
和 cluster_2
,但我尝试的任何东西都会创建新节点而不是连接集群:
digraph G {
graph [fontsize=10 fontname="Verdana"];
node [shape=record fontsize=10 fontname="Verdana"];
subgraph cluster_0 {
node [style=filled];
"Item 1" "Item 2";
label = "Container A";
color=blue;
}
subgraph cluster_1 {
node [style=filled];
"Item 3" "Item 4";
label = "Container B";
color=blue;
}
subgraph cluster_2 {
node [style=filled];
"Item 5" "Item 6";
label = "Container C";
color=blue;
}
// Renders fine
"Item 1" -> "Item 2";
"Item 2" -> "Item 3";
// Both of these create new nodes
cluster_1 -> cluster_2;
"Container A" -> "Container C";
}
3 回答
为便于参考,HighPerformanceMark答案中描述的解决方案直接应用于原始问题,如下所示:
graph
声明中的compound=true
至关重要 . 这产生了输出:请注意,我将边缘更改为引用群集中的节点,将ltail和lhead属性添加到每个边缘,指定群集名称,并添加图层级属性“compound = true” .
关于人们可能想要连接其中没有节点的集群的担心,我的解决方案是始终向每个集群添加一个节点,使用style = plaintext进行渲染 . 使用此节点标记集群(而不是集群的内置"label"属性,该属性应设置为空字符串(在Python中,
label='""'
) . 这意味着我不再添加直接连接集群的边,但它可以工作在我的特殊情况下 .确保您对文件使用
fdp
布局 . 我不认为neato
支持集群 .DOT用户手册给出了以下具有簇之间具有边缘的簇的图的示例
节点和集群之间的边缘 .