Dimpl
Dimpl

Reputation: 942

Graphviz enforce ordering between nodes of different levels

I have the following graph:

digraph {
  stylesheet = "..."
  subgraph cluster {
    b; c; g;
    {rank=same; b; g;}
  }
  a -> b;
  b -> c;
  c -> d;
  c -> e;
  f -> c;
  {rank=same; a; f;}
}

enter image description here

Is there any way to force/encourage the edge f -> c to pass between nodes b and g? I've tried a number of different strategies and graphviz refuses to both:

Any suggestions would be much appreciated!

Upvotes: 0

Views: 250

Answers (1)

sroush
sroush

Reputation: 6763

Indeed, the dot algorithm does not want to route the f->c edge as you want. However, the neato edge routing algorithm produces a closer result. So we use dot to position the nodes and neato -n to route the edges. Like so:

dot -Tdot myfile.gv >out.dot
neato -n -Tpng out.dot >myfile.png

Using this input:

 digraph {
  stylesheet = "https://g3doc.corp.google.com/frameworks/g3doc/includes/graphviz-style.css"
  nodesep=.5  // optional
  subgraph cluster {
    b 
    c; g 
    {rank=same; b; g;}
  }

  f -> g [style=invis]
  f:se -> c:nw [constraint=false]

  a -> b;
  b -> c;
  c -> d;
  c -> e;
}

Giving:
enter image description here

See https://graphviz.org/faq/#FaqDotWithNodeCoords
And https://graphviz.org/docs/outputs/canon/

(Close enough?)

Upvotes: 1

Related Questions