Graphviz - how do I change rankdir in a subgraph within a subgraph?

78 Views Asked by At

I've got the following graph. I'm content with it, except for the nodes within the red rectangle:

(Here's the Graphviz Visual Editor Link)

I'd rather have the nodes "hollow" and "hohl" be atop each other, like so: (Here's the Graphviz Visual Editor Link])

Every attempt at adding a nested subgraph was unsuccessful, despite using

  • newrank=true,
  • compound=true,
  • rank=same and
  • rankdir="TB"

Can anyone offer any advice?

Bonus question: I'd also prefer the "rabbit hole" node to be horizontically centered, but I haven't found out how to do that either.

1

There are 1 best solutions below

1
sroush On BEST ANSWER
  • Rearranged all the code to better understand it (made it easier for my eyes).
  • Re-did ranking (rank=same)
  • Used minlen to push bottom 3 nodes back to the bottom
  • Used group attribute to encourage vertical alignment

p.s. rankdir applies to the entire (root) graph

digraph {
  fontname="Helvetica,Arial,sans-serif"
  fontsize=18
  rankdir="TB"
  
  node [fontname="Helvetica,Arial,sans-serif"]
  edge [fontname="Helvetica,Arial,sans-serif"]
  layout=dot
  
  rabbithole [group=R label=<<FONT POINT-SIZE="30">"rabbit hole"</FONT>> shape=rectangle]
  rabbit     [label="\"rabbit\"\n(origin unknown)"]
  rabbithole -> rabbit
  rabbithole -> hole
  
  {rank=sink  // keep on same rank
    hulahoop [label="\"Hula Hoop\""]
    holy     [label="\"holy\""]
    hell     [label="\"hell\""]
  }
  
  hulaz -> hulahoop [minlen=2 dir=none label="unrelated"]  // push to bottom
  hulaz -> holy [dir=none label="unrelated"]
  hulaz -> hell [dir=none label="unrelated"]
   
  subgraph cluster_hulaz{
    hole [group=R label="\"hole\""]
  
    hulaz  [group=R label=<<I><FONT POINT-SIZE="20">"hulaz"</FONT></I><BR/>(PGmc root,<BR/>"hollow")>, shape=doublecircle]
    hollow [group=2 label="\"hollow\""]
    hohl   [group=2 label="\"hohl\"\n(de, \"hollow\")"]
    Höhle  [label="\"Höhle\"\n(de, \"cave\")"]
  
      { rank=same
      hole hollow
      }
      { rank=same
      hulaz  hohl Höhle
      }
      hole -> hulaz [dir=none]
      hulaz -> hollow [dir=none]
      hulaz -> hohl [dir=none]
      hollow -> hohl [dir=none]
      hohl -> Höhle [dir=none]
  }
}

Giving:
enter image description here