0

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:

  • keep b and g within the border, and
  • allow g to appear of to the side and not interfere with the rest of the graph.

Any suggestions would be much appreciated!

Arpan Srivastava
  • 356
  • 5
  • 10
Dimpl
  • 935
  • 1
  • 10
  • 24

1 Answers1

1

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?)

sroush
  • 5,375
  • 2
  • 5
  • 11
  • On the real graph (the one I provided here was a minimal example), it would be better if there was more space between `b` and `g` (there is a loooot of space on that line). I would also prefer not to modify the compilation process for ease of re-creation. Currently, my best idea is to remove `g` entirely and add it by hand post-generation. – Dimpl Aug 28 '21 at 00:11