Can I define sub-clusters in dot language (Graphviz)? - graphviz

In dot you can define clusters, which are basically boxes around a group of nodes. (1)
Is it possible to define a cluster, such that it is rendered within another cluster (a box within a box)?
(1) See also Subgraphs and Clusters in http://www.graphviz.org/content/dot-language

That works just fine:
graph {
subgraph cluster1
{
label="outside 1"
subgraph cluster11
{
label="inside 1"
a--b
};
subgraph cluster12
{
label="inside 2"
c--d
};
};
subgraph cluster2
{
label="outside 2"
e--f
}
}
Output:

Related

Can I have this cluster shape in Graphviz?

Layered two rectangles like Cluster1 or Cluster2 in the following image:
The closest you can get without hassle is nested clusters, like so:
digraph N {
rankdir=LR
labelloc=b
subgraph clusterA1 { // outer cluster
subgraph clusterA { // inner cluster
graph [bgcolor=white]
label=Cluster1
Node1
}
}
subgraph clusterB1 {
subgraph clusterB {
label=Cluster2
Node2
}
}
Node1 -> Node2 [minlen=2]
}
Giving:
It may be possible to get the look you are after by post-processing (with Python, gvpr, or the like) a similar input and creating or repositioning a cluster or node to give the look you want. Not sure.

Is it possible to specify a cluster inside a subgraph

I would like to create several clusters inside a subgraph like the following :
subgraph sub {
rank=same;
subgraph cluster_test {
p4;
p5;
p6;
}
subgraph cluster_t {
p1;
p2;
p3;
}
}
My aim is to have several clusters (which group the nodes together) at the same rank. However it seems clusters do not work inside subgraphs. Is there a way around that ?
rank=same can't apply across clusters. (yes, it would be nice). Clusters are laid out independently, rank=same would require dependent layout.
Also rank=same really applies to nodes within a subgraph, not a cluster, that can consist of nodes in multiple ranks.
Clusters are positioned based on the ranks of the enclosed nodes, but to try to get multiple clusters horizontally aligned, try embedding then within a parental cluster, like so (or using invisible edges to adjust ranking):
digraph D {
subgraph cluster_outer{
subgraph cluster_test {
p4;
p5;
p6;
}
subgraph cluster_t {
p1;
p2;
p3;
}
graph [peripheries=0] // if you don't want the extra box
}
}
Giving:
[

Graphviz nodes on a timeline

What do I do to ensure April and May fall between Jan and Aug?
Is there a solution without the use of hidden nodes/edges?
digraph G {
rankdir=LR;
"09/30/2021"->"12/03/2021"->"01/05/2022"->"08/19/2022";
"12/03/2021"->"04/27/2022"->"05/25/2022";
}
https://dreampuf.github.io/GraphvizOnline/
Here's how to get your timeline linear using a cluster. Then to get the other arcs not to be inside the cluster, give them nodes outside the cluster. You can always hide these (and fix the one out of Sep) - yes there may be a way to not use hidden nodes, not sure why you'd want to avoid this.
digraph G {
rankdir=LR;
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
Jan->Feb->Mar -> Apr->May->Jun->Jul->Aug->Sep->Oct->Nov->Dec;
label = "timeline";
}
Sep->op1->Mar->op2->May->op3->Aug;
Mar->op4->Apr->op5->May;
}
Produces this:

Arranging graphviz clusters

I'm trying to generate the following construct:
I have four graphs. Three of them are supposed to be in the first "row", all vertically aligned by their vertical center. The fourth graph is supposed to be below the other three, in the second "row". It should be horizontally aligned with either the horizontal center of the upper row's middle graph or the horizontal center of the entire upper row. Additionally there will be edges between some members of separate clusters/graphs.
Here there are only edges between members of cluster_a and cluster_d, but there may be edges between members of any combination of clusters.
Ususal you can do this by adding some additional invisible scarfolding nodes and edges e.g.:
digraph G {
rankdir=LR
edge[minlen=2]//enable finer control over node location when scarfolding
subgraph cluster_d { label=cluster_d
d_0->d_2
d_1->d_0
//d_1->d_3
//extra node to simulate edge between edges
d_13[shape=point]
d_1->d_13[dir=none minlen=1]
d_13->d_3[minlen=1]
d_3->d_2
d_3->d_3
}
subgraph cluster_abc { // better align cluster
subgraph cluster_a { label=cluster_a
a_0->a_2
a_0->a_3
a_1->a_0
a_1->a_1
a_1->a_2
a_1->a_3
//a_2->a_3
//extra node to simulate edge between edges
a_23[shape=point]
a_2->a_23[dir=none minlen=1]
a_23->a_3[minlen=1]
a_3->a_2
a_3->a_3
}
subgraph cluster_c { label=cluster_c
c_0->c_0
c_0->c_1
c_0->c_2
c_0->c_3
c_1->c_3
c_3->c_3
c_2->c_0
c_2->c_1
c_2->c_2
c_2->c_3
}
subgraph cluster_b { label=cluster_b
b_0->b_0
b_0->b_2
b_0->b_3
b_1->b_1
b_1->b_2
b_1->b_3
b_2->b_0
b_3->b_2
}
color=invis
}
{//scarfolding
edge[style=invis]node[style=invis] //hide scarfolding
{
rank=same
node[shape=point] //minimize impact on edge routing around the scarfolding nodes
x_0
x_1
}
a_3->c_0
c_3->b_0
// we can not use same rank across cluster boundary so instead of a_3->d_1 we do a_2->x_0 + x_1->d_1
a_2->x_0
x_1->d_1[minlen=3]
}
{
edge[headclip=false tailclip=false]
a_2->d_1[dir=none constraint=false]
a_3->d_3[dir=none]
}
a_23->d_13[dir=none constraint=false]
}

Graphviz: Intersecting but non-recursive clusters

I was wondering if it's possible to do something like this in Graphviz:
As you can see, node "two" is inside two clusters while the clusters aren't recursive.
Note: Image made with Dia.
No, this is currently not possible
Just rewriting Jens' comment as an answer.
While Graphviz won't produce overlapping clusters directly, it will allow you to create overlapping clusters with a bit of editing. (For more info see: https://www.graphviz.org/faq/#FaqDotWithCoords)
Start with:
digraph o {
graph [newrank=true nodesep=.5]
subgraph cluster1 {
graph [margin=50 label="Subgraph 1"]
{rank=same
one-> two [style=invis]
}
}
subgraph cluster2 {
graph [label="Subgraph 2"]
three
}
{rank=same
one two three
}
}
run this command: dot -Tdot myfile.gv >myfile.dot
Then edit myfile.dot to change the boundary box of cluster2. Like so:
digraph o {
graph [bb="0,0,398,175",
newrank=true,
nodesep=.5
];
node [label="\N"];
{
graph [rank=same];
one [height=0.5,
pos="85,76",
width=0.75827];
two [height=0.5,
pos="176,76",
width=0.77632];
three [height=0.5,
pos="340,76",
width=0.99297];
}
subgraph cluster1 {
graph [bb="8,8,254,167",
label="Subgraph 1",
lheight=0.21,
lp="131,155.5",
lwidth=1.17,
margin=50
];
{
graph [rank=same];
one;
two;
one -> two [pos="e,147.67,76 112.37,76 120.74,76 129.1,76 137.46,76",
style=invis];
}
}
subgraph cluster2 {
graph [bb="135,50,390,125", // X1 edited
label="Subgraph 2",
lheight=0.21,
lp="340,113.5",
lwidth=1.17
];
three;
}
}
run this command on the edited file: neato -n2 -Tpng myfile.dot >myfile.png
Giving:

Resources