GraphViz的 - 如何连接子图?
-
19-09-2019 - |
题
在对于DOT
的GraphViz
语言,我试图表示依赖关系图。我需要能够有一个容器内的节点,并能够使节点和/或容器依赖于其它节点和/或容器中。
我使用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";
}
解决方案
在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;
}
和节点和集群之间的边缘。
其他提示
为了便于参考在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属性每个边缘,指定群集名称,并添加了图形级属性“化合物=真”。
关于一个可能要与它里面没有节点连接群集,我的解决办法是的总是的节点添加到每个群集与风格呈现=明文后顾之忧。使用此节点标记集群(而不是集群内置的“标签”属性,它应该被设置为空字符串(Python中,label='""'
)。这意味着我不再补充说,直接连接集群的边缘,但它在我的特殊情况。
请确保您使用的fdp
布局文件。我不认为neato
支持集群。
不隶属于 StackOverflow