Is it possible to specify a cluster inside a subgraph - graphviz

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:
[

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.

Graph in Graph Extraction

I want to draw a graph with "dot" format. The graph I want is a (sub)graph in a graph style. The subgraph (a child) has internal graph, and the (parent) graphs are connected among the parents, and does not connect to children that are connected only in the subgraph.
Could you please guide how writing such style with the dot-format, with an example?
Good news:
creating your "parent nodes" is pretty easy. Graphviz, (dot) calls them "cluster subgraphs" (or clusters). (well documented on p. 19 of https://www.graphviz.org/pdf/dotguide.pdf) see below for an example.
Bad news:
explicitly sizing clusters is very difficult. Dot sizes a cluster to be just big enough to contain its nodes.
explicitly positioning clusters is also quite difficult. Dot positions clusters based on the "best" positioning of the component nodes, specifically the edges that connect nodes within the various clusters.
drawing edges from one cluster to another is a kludge. You define an edge from a node contained within one cluster to another node contained within a different cluster and instruct dot to clip that edge so it appears to be from cluster to cluster. This uses the attribute compound=true. (again, read the documentation listed above)
Finally: the fdp engine allows cluster-to-cluster edges, but you lose the directionality of the edges
Drawn with dot:
digraph C {
graph [compound=true] // allows edges to/from clusters
// create an extra cluster to try to keep clusterA above clusterB
subgraph clusterWrapper {
graph [peripheries=0] // no box around
subgraph clusterA {
graph [peripheries=1] // box around
a -> c
b->c
c->d
}
subgraph clusterB {
graph [peripheries=1] // box around
f->g
e->g
}
} // end of wrapper
subgraph clusterC {
edge [dir=none ] // no arrowheads
h->k
i->k
i->l
j->l
{rank=same h->i->j [style=invis]}
}
b->f [ltail=clusterA, lhead=clusterB];
l:s->b:n [ltail=clusterC, lhead=clusterA];
l->f [style=invis weight=50]
}
Giving:

Graphviz: How to place nodes only in lower semi-circle using circo layout?

In the attached figure, the nodes are arranged in a circle around the node. Is there a (possibly generic) way to arrange the nodes only in the lower semi-circle, without having to provide fixed coordinates for the nodes?
Edit: Would like to achieve something like shown in the image attached below. As one can see - all the nodes are arranged in the lower semi-circular region (this figure was made using CMap Tools).
The code is trivial, but pasting it anyway.
digraph semicircle {
rankdir="TD"
graph [nodesep="0.1", ranksep="0.3", center=true]
mindist="0.4"
S [label="Root", style="filled", fillcolor="greenyellow", shape="box"]
subgraph cluster1 {
rank="same"
A; B; C; D;
S -> {A, B, C, D};
} }
using dot/circo : graphviz version 2.40.1
I noted that circo placed nodes counter-clockwise, starting at 3 o'clock.
I added enough invisible nodes to fill the 2 through 10 o'clock positions.
To make the inter-nodal distances even more uniform I added:
node [shape=square style=rounded]
The result I got is this:
Try this:
digraph semicircle {
rankdir="TD"
graph [nodesep="0.1", ranksep="0.3", center=true, root=S]
mindist="0.4"
S [label="Root", style="filled", fillcolor="greenyellow", shape="box"]
subgraph cluster1 {
rank="same"
A
z1[style=invis label=""]
z2[style=invis label=""]
B; C; D;
S -> A
S -> z1,z2 [style=invis]
S -> { B, C, D};
}
}

Can I define sub-clusters in dot language (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:

Graphviz subgraph doesn't get visualized

I'm trying to create a graph with two subgraphs in dot. The code is as follows:
digraph G {
subgraph step1 {
style=filled;
node [label="Compiler"] step1_Compiler;
node [label="Maschine"] step1_Maschine;
color=lightgrey;
}
subgraph step2 {
style=filled;
color=lightgrey;
node [label="Interpretierer"] step2_Interpretierer;
node [label="Maschine"] step2_Maschine;
label="Virtuelle Maschine";
}
"Programm (Java)" -> step1_Compiler;
step1_Compiler -> step1_Maschine;
step1_Maschine -> "Bytecode";
"Bytecode" -> step2_Interpretierer;
step2_Interpretierer -> step2_Maschine;
step2_Maschine -> "Ergebnis";
}
The result I am getting looks like the following:
I expected to see a box around both subgraphs. What am I missing here?
You'll have to prefix the name of your subgraphs with cluster:
subgraph clusterstep1 {
and
subgraph clusterstep2 {
in order to get the style and label.
From the graphiz documentation, section "Subgraphs and Clusters":
The third role for subgraphs directly involves how the graph will be
laid out by certain layout engines. If the name of the subgraph begins
with cluster, Graphviz notes the subgraph as a special cluster
subgraph. If supported, the layout engine will do the layout so that
the nodes belonging to the cluster are drawn together, with the entire
drawing of the cluster contained within a bounding rectangle. Note
that, for good and bad, cluster subgraphs are not part of the DOT
language, but solely a syntactic convention adhered to by certain of
the layout engines.

Resources