1

Using dot, the basic layout puts nodes into layers. If you create subgraphs, it groups related nodes inside of rectangles, but the nodes are still in layers, and those layers are influenced by the nodes outside of the subgraph.

Sometimes, this is great. But sometimes, when a subgraph is an independent visual entity, it might be nice to be able to lay out its content without respect to the layers of the other parts of the graph. Take for example the following:

digraph x {
  subgraph one {
    a [ label="a\nvery\nlong\nlabel" ]
    b [ label="another\nvery\nlong\nlabel" ]
    c [ label="still\nmore\nlong\nlabels" ]
    a -> b - > c
  }
  subgraph two {
    w -> x -> y -> z
  }
}

Because of the long labels, the nodes in subgraph one will take up a lot of space. But because of the layer-based layout, the nodes in subgraph two will be vertically aligned with the corresponding nodes from subgraph one.

Is there a way to make it layout subgraph two as if subgraph one did not exist?

John Arrowwood
  • 2,370
  • 2
  • 21
  • 32
  • Have you play with the clusterrank graph attribute? Per [documentation](https://www.graphviz.org/doc/info/attrs.html#a:clusterrank): "Mode used for handling clusters. If clusterrank is "local", a subgraph whose name begins with "cluster" is given special treatment. The subgraph is laid out separately, and then integrated as a unit into its parent graph..." – Eok Aug 16 '19 at 17:31

1 Answers1

0

Not directly with dot. Dot does rank alignment across the entire graph. However here are two ways to get close to what you want:

  • use neato -Goverlap=false -Gmode=hier to approximate a dot layout: enter image description here

  • or split the various parts into separate graphs, use dot -Tdot to layout each, then use gvpack (https://graphviz.org/pdf/gvpack.1.pdf) to combine the parts into a single output. Like so:

    dot -Tdot ComboGraph1a.gv >ComboGraph1a.dot
    dot -Tdot ComboGraph1b.gv >ComboGraph1b.dot gvpack -array_ib2 ComboGraph1?.dot |neato -Tpng -n2 >oooo.png
    Giving:
    enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11