Compress an unranked subgraph in graphviz

I am trying to write a subgraph in graphviz, but while I'd like the main graph to preserve the ranking of its own nodes, I'd want the subgraph one to get a compressed form, i.e. to have its layout constrained into a square.

This is the actual graph that I obtain:

and this is the code that generated it (I am actually using a python lib to produce the output image):

subgraph cluster_15_ {
graph [aspect=1 concentrate=true ordering=out ratio=compress size="1.0,1.0!"]
node [fixedsize=true shape=circle width=0.4]
edge [dirType=forward len=0.5]
cluster_15_0 [label=0]
cluster_15_2 [label=2]
cluster_15_3 [label=3]
cluster_15_4 [label=4]
cluster_15_5 [label=5]
cluster_15_7 [label=7]
cluster_15_8 [label=8]
cluster_15_11 [label=11]
cluster_15_12 [label=12]
cluster_15_13 [label=13]
cluster_15_15 [label=15]
cluster_15_0 -> cluster_15_2
cluster_15_5 -> cluster_15_3
cluster_15_3 -> cluster_15_4
cluster_15_2 -> cluster_15_5
cluster_15_5 -> cluster_15_7
cluster_15_7 -> cluster_15_8
cluster_15_12 -> cluster_15_11
cluster_15_15 -> cluster_15_12
cluster_15_15 -> cluster_15_13
cluster_15_4 -> cluster_15_15

I'd like to have the nodes into a 4x4 box for instance (the arcs can go upside, down, it is not a problem), or in a way to fit the graph in a more squareish shape.

You'd really like to use

You'd really like to use osage to lay out the subgraph, but Graphviz doesn't directly support heterogeneous layouts with one pass. It can be done with multiple passes, but takes some work.

For your case, the simplest thing to do is to remove the directionality contstraint from a few edges, say

cluster_15_3 -> cluster_15_4 [constraint=false]
cluster_15_5 -> cluster_15_7 [constraint=false]

This is obviously a one-off solution. If you want to automate this, your back to using multiple passes: do an initial layout of the cluster, then add constraint=false to any edge causing a path longer than sqrt(N) where N is the number of nodes in the cluster.

is there a way to use osage only on the subgraphs in one pass?

From your answer seems it is not possibile, moreover I doubt that the lib I am using atm would let me do it.

I will try to come up with a procedure to add that edge property and let you know. ty.

No, it is not possible to use

No, it is not possible to use different layouts in different subgraphs using a single pass.

Recent comments