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 속성을 추가하고 클러스터 이름을 지정하고 그래프 수준 속성 'Compound = True'를 추가했습니다.
내부에 노드가없는 클러스터를 연결하고 싶을 걱정과 관련하여 내 솔루션은 다음과 같습니다. 언제나 스타일 = 일반 텍스트로 렌더링 된 모든 클러스터에 노드를 추가하십시오. 이 노드를 사용하여 클러스터의 내장 "레이블"속성 대신 클러스터에 레이블을 지정합니다. 이는 빈 문자열로 설정해야합니다 (Python, Python. label='""'
). 이것은 더 이상 클러스터를 직접 연결하는 가장자리를 추가하지 않지만 특정 상황에서 작동합니다.
사용 중인지 확인하십시오 fdp
파일의 레이아웃. 나는 생각하지 않는다 neato
클러스터를 지원합니다.