Can I have this cluster shape in Graphviz? - 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.

Related

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:

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:

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