When switching from "normal" subgraphs to clusters, rank=same
doesn't apprear to work anymore.
To show my problem, please have a look at the following example graph.
digraph INV_X1 {
rankdir = "LR";
edge [penwidth="2"];
/* Component styles */
M_i_0 [shape=none;image="res/nmos.jpg"];
M_i_1 [shape=none;image="res/pmos.jpg"];
/* Node styles */
A [style=filled;color=green];
ZN [style=filled;color=green];
/* Connections */
M_i_0:n -> ZN;
A -> M_i_0:w;
/* Put M_i_0 and _VSS_0 on the same rank. */
subgraph g_VSS_0 {
rank=same;
label="_VSS_0";
_VSS_0 [shape=none;image="res/gnd.jpg";label=""];
M_i_0 -> _VSS_0 [arrowhead=none];
}
M_i_1:s -> ZN;
A -> M_i_1:w;
/* Put M_i_1 and _VDD_1 on the same rank. */
subgraph g_VDD_1 {
rank=same;
label="_VDD_1";
_VDD_1 [shape=none;image="res/pwr.jpg";label=""];
_VDD_1 -> M_i_1 [arrowhead=none];
}
}
The output is shown in the following picture. I hope it's not too confusing as I used some images for nodes. I created two subgraphs to group two nodes each and put them on the same rank. One subgraph is at the center top, the other on the center bottom.
Now I want to switch from subgraphs to clusters to make sure that the grouped nodes are always placed close to one another, and I want to have borders and labels to make the clusters visible. But when I just change the subgraph names to "cluster_..." it looks like this.
What is the problem here? Why is rank=same
no longer working as expected? Also the given port position is no longer working as expected (edge is no longer connected on the south/north of the node).
I tried to pull rank=same
out of the cluster into an own statement but that seems to completely overwrite the previous cluster statement as border and labels disappear. Also, I tried to use constraint=false
on the node connections but that messes up the node order so I wasn't really satisfied with that approach.
Any help is appreciated. You can find the used images here if you want to recreate the graph.
You are right, as documentation states, "rank" attribute works only with subgraphs (cluster is not a subgraph anymore). But what's the problem, put another subgraph inside your cluster!
digraph INV_X1 {
rankdir = "LR";
edge [penwidth="2"];
/* Component styles */
M_i_0 [shape=none;image="res/nmos.jpg"];
M_i_1 [shape=none;image="res/pmos.jpg"];
/* Node styles */
A [style=filled;color=green];
ZN [style=filled;color=green];
/* Connections */
M_i_0:n -> ZN;
A -> M_i_0:w;
subgraph cluster_a{
/* Put M_i_0 and _VSS_0 on the same rank. */
label="_VSS_0";
subgraph g_VSS_0 {
rank=same;
_VSS_0 [shape=none;image="res/gnd.jpg";label=""];
_VSS_0 -> M_i_0 [arrowhead=none];
}
}
M_i_1:s -> ZN;
A -> M_i_1:w;
/* Put M_i_1 and _VDD_1 on the same rank. */
subgraph cluster_b {
label="_VDD_1";
subgraph g_VDD_1 {
rank=same;
_VDD_1 [shape=none;image="res/pwr.jpg";label=""];
M_i_1 -> _VDD_1 [arrowhead=none];
}
}
}
Also note that I've changed the order of your edges M_i_1 -> _VDD_1
and _VSS_0 -> M_i_0
, for some reason they were inversed.
Result: