Is there any way to create a graph with clusters using jgrapht? Example graph with two clusters "process #1" and "process #2":
Expected dot file content :
digraph G {
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
subgraph cluster_1 {
node [style=filled];
b0 -> b1 -> b2 -> b3;
label = "process #2";
color=blue
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
Your graph design is a bit peculiar. When I visually look at your graph, I see a base graph, and 2 clustered groups of nodes. When I look at your DOT file, I see 2 subgraphs, and an 'outer' graph that refers to specific nodes in your subgraph. Note that a subgraph is not a cluster.
Your question seems to have 2 parts: (1) can you create a graph with clusters using jgrapht and (2) can you create the DOT file in your example. The answers are: (1) yes, (2) no, at least not out of the box, since DOTExporter
does not support 'subgraphs'.
There are a few different ways you can create clustered graphs.
List<Set<V>>
to store your clusters. You could visualize the subgraph induced by a particular cluster using the AsSubgraph
class.BlockCutpointGraph
implementation.If you want to export your graph in a similar fashion as your example DOT file, you'll have to do some work. You could implement your own custom DOTExporter, or modify the existing one. Perhaps an easy alternative (not the cleanest) is to do something along the following lines:
AsSubgraph
classMaskSubgraph
class.DOTExporter
class. subgraph
keywork.Using your example:
digraph G {
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
digraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
Here you have to substitute digraph
by subgraph
and insert this graph into the base graph to obtain:
digraph G {
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
Obviously you must repeat this for the remaining clusters.