I'd like to point to a sub graph where the line stops on the edge.
From what I understand I can select any of the nodes in the sub graph.
Is there a way to create an invisible node that you can point to?
digraph G {
compound=true;
subgraph cluster_a{
label="node1";
node1;
}
node2->node1 [lhead=cluster_a];
}
Ideally node1 should not be visible
You may simply use style=invis:
node1 [style=invis];
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 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:
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:
In this graph the bottom edge is not drawn symmetrical to the top edge:
digraph G {
A:ne -> A:nw;
A:sw -> A:se;
}
I want it to look more like a "fat snowman" with the edge A:sw -> A:se; looping below the node. Is there a way?
Short answer no - or not easily.
Loops seem to be placed from the rankdir direction. If rankdir is TB (down), loops seem to be placed "up".
It you're willing to work at it, you can run your graph twice, once with rankdir=TB, once with rankdir=BT - both times with -Tdot. Then you'd have to replace the offending edge with the equivalent edge from the other graph. [I hope this makes some sense]
Here is a tweaked version of your graph run with different values of rankdir:
digraph G {
A:ne -> A:nw;
A:sw -> A:se;
dummy [style=invis]
dummy -> A [style=invis]
}
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.