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:
Related
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.
I've the following output currently I want to place a label below the edge between p and z in the figure.Is it possible to do in graphviz I've tried using xlabels but it doesn't work.
Current Code:
digraph GPG{
node [shape=box];
subgraph cluster0{
node[shape=circle];
0[label=0,style=invis];
}
subgraph cluster1{
node[shape=circle];
1[label=1,style=invis];
p->z [label="2 | 1",minlen=1];
{
rank = same;
p;z;
}
}
subgraph cluster2{
node[shape=circle];
2[label=2,style=invis];
}
0->1
1->2
}
I want a label below edge p->z as well above the edge.Is it possible in graphviz?
Kind of ugly, but:
digraph overunder{
splines=false
{ rank=same
a -> b [label=" over " ]
a -> b [label="under" penwidth=0.0 dir=none]
}
}
Produces:
You may have to add the non-breaking space characters (see above) because Graphviz seems to position labels based on the length of the text - longer labels are placed above shorter labels.
My ultimate aim is to write a python script that will automatically generate graphviz graphs based on some input data. However, I'm first focusing just on the graphviz.
This is currently what I have:
digraph G {
compound=true;
node [shape=box];
edge [dir=none];
subgraph cluster_overall{
subgraph cluster_top{
apple;
banana;
}
subgraph clustermsc{
basket1;
basket2;
label="Baskets";
}
subgraph cluster_bottom{
orange;
kiwi;
}
label="Test";
}
apple -> basket1;
banana -> basket2;
orange -> basket1;
kiwi -> basket2;
}
Current: https://i.imgur.com/76GCx0f.png
This is what I want my final graph to look like. With the number of fruits evenly distributed between the top and bottom section (based on the input date):
Final: https://i.imgur.com/OHFsAdd.png
How do I structure the page to have 3 static, separate sections. Currently the fruit's placement constantly changes based on node they point to.
Please let me know if I wasn't clear in my explanation, I'll try better explaining it. Thanks.
Don't have enough repuation to directly post images.
In graphviz, it is important to produce the hierarchy as the tool sees it, not reproducing the logic that is on your mind. simply reversing the edges from your baskets to the "lower" fruits does the job:
digraph G {
compound=true;
node [shape=box];
edge [dir=none];
subgraph cluster_overall{
subgraph cluster_top{
apple;
banana;
}
subgraph clustermsc{
basket1;
basket2;
label="Baskets";
}
subgraph cluster_bottom{
orange;
kiwi;
}
label="Test";
}
apple -> basket1;
banana -> basket2;
basket1 -> orange; // !!!
basket2-> kiwi; // !!!
}
gives you
If you want to force a certain order of items (such as apple being to the left of banana), you can do so by replacing your definition with
subgraph cluster_top{
{ rank = same; apple -> banana[ style = invis ] }
}
If I correctly understood you, you need to connect clusters with invisible edges to force their position.
Here I've added a dummy node into each cluster (because to connect clusters you have to connect nodes in these clusters and then add lhead and ltail attributes).
Then I've connected these clusters in the correct order with invisible edges. Also I've added an extremely big weight to these edges to give them priority over other edges.
Is that what you need?
digraph G {
compound=true;
node [shape=box];
edge [dir=none];
subgraph cluster_overall{
subgraph cluster_top{
dummy_top [shape=point width=0 style=invis]
apple;
banana;
}
subgraph clustermsc{
dummy_msc [shape=point width=0 style=invis]
basket1;
basket2;
label="Baskets";
}
subgraph cluster_bottom{
dummy_bottom [shape=point width=0 style=invis]
orange;
kiwi;
}
label="Test";
}
dummy_top -> dummy_msc [
style=invis
weight=100
lhead="clustermsc"
ltail="cluster_top"
]
dummy_msc -> dummy_bottom [
style=invis
weight=100
lhead="cluster_bottom"
ltail="clustermsc"
]
apple -> basket1;
banana -> basket2;
orange -> basket1;
kiwi -> basket2;
}
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:
I'm able to create a graph in the same row using dot graphviz. I want to create graphs one below the other i.e. after plotting one subgraph it should go to next line and then start plotting the next graph..
Here is a minimalist code for dot. The subgraph "plot2" is below "plot1" because rankdir=LR.
digraph G {
rankdir=LR
subgraph cluster_2 {
a2
label="plot2"
}
subgraph cluster_1 {
a1
label="plot1";
}
}
You can test it directly here: GraphvizFiddle