在DOT
的{{1}}语言中,我试图表示一个依赖关系图。我需要能够在容器内部拥有节点,并且能够使节点和/或容器依赖于其他节点和/或容器。
我正在使用GraphViz
来表示我的容器。节点链接工作正常,但我无法弄清楚如何连接子图。
鉴于以下程序,我需要能够使用箭头连接subgraph
和cluster_1
,但我尝试的任何内容都会创建新节点而不是连接群集:
cluster_2
答案 0 :(得分:155)
DOT用户手册给出了以下带有簇之间具有边缘的簇的图形示例
digraph G {
compound=true;
subgraph cluster0 {
a -> b;
a -> c;
b -> d;
c -> d;
}
subgraph cluster1 {
e -> g;
e -> f;
}
b -> f [lhead=cluster1];
d -> e;
c -> g [ltail=cluster0,lhead=cluster1];
c -> e [ltail=cluster0];
d -> h;
}
和节点与集群之间的边缘。
答案 1 :(得分:79)
为了便于参考,HighPerformanceMark答案中描述的解决方案直接应用于原始问题,如下所示:
digraph G {
graph [fontsize=10 fontname="Verdana" compound=true];
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;
}
// Edges between nodes render fine
"Item 1" -> "Item 2";
"Item 2" -> "Item 3";
// Edges that directly connect one cluster to another
"Item 1" -> "Item 3" [ltail=cluster_0 lhead=cluster_1];
"Item 1" -> "Item 5" [ltail=cluster_0 lhead=cluster_2];
}
compound=true
声明中的graph
至关重要。这产生了输出:
请注意,我将边缘更改为引用群集中的节点,将ltail和lhead属性添加到每个边缘,指定群集名称,并添加图层级属性“compound = true”。
担心人们可能想要连接其中没有节点的集群,我的解决方案是始终向每个集群添加一个节点,使用style = plaintext进行渲染。使用此节点标记集群(而不是集群的内置“label”属性,该属性应设置为空字符串(在Python中,label='""'
)。这意味着我不再添加连接的边缘直接集群,但它适用于我的特定情况。
答案 2 :(得分:10)
确保您对文件使用fdp
布局。我认为neato
不支持群集。