How to control node placement in graphviz (i.e. avoid edge crossings)
Solution 1:
You could create an invisible constraint, to cause the red node to appear to the left of all other nodes.
redNode -> leftmostNode [style=invis];
Before:
After:
Solution 2:
I like @smokris' [style=invis]
trick for persuading graphviz to put things where you want them, by adding edges which affect layout but aren't visible.
Another trick is the constraint
attribute, which lets you add edges which are visible but don't affect layout.
If adding a new edge messes up your graph, set [constraint=false]
on that edge: now graphviz will ignore it when placing nodes. 🙂
If
false
, the edge is not used in ranking the nodes. For example, in the graphdigraph G { a -> c; a -> b; b -> c [constraint=false]; }
the edge
b -> c
does not add a constraint during rank assignment, so the only constraints are that a be above b and c, yielding the graph:
Solution 3:
@Jannis, in case you're still interested in an answer to this, there is actually a way to control individual node placement - you use the "pos" attribute:
http://www.graphviz.org/doc/info/attrs.html#d:pos
As an example of this, you could write:
n [pos="3,5!"];
That would force node n
to be at precisely (3,5)
.
However, this only works with layout engines "fdp" and "neato".