Force node will be under another node

I have a chart that is laid out from left to right. However, there are some elements of this graph that I want to set relative to another node. For example, if I have this graph:

digraph "Test" { rankdir = "LR" A -> B B -> C D -> B note -> B note [ shape="house" ] }; 

It looks like this:

Normal dot layout

However, I would like the β€œnote” of the node to always be located directly below the node that it points to, for example, this (manually created) graph:

Desired DOT layout

I tried experimenting with a subgraph with a different rankdir and messing around with the rank and constraint attributes, but failed to achieve this, as I only played with DOT for a couple of days.

+4
source share
2 answers

Here's what you could do: list the nodes before defining the edges and limit node A to the same rank as node note by putting them in a subgraph:

 digraph "Test" { rankdir = "LR" A;D; {rank=same; note; B;} C; A -> B B -> C D -> B B -> note [dir=back] note [ shape="house" ] }; 

Note that for node note node A I had to change the direction of the edge and add dir=back to draw the arrow correctly.

graphviz output

+5
source

A common technique for moving nodes around is to create invisible edges. In your case, you can create an edge from A to note , mark it invisible, and then mark the edge from note to B as non-limiting:

 A -> note [style="invis"]; note -> B [constraint=false]; 
+3
source

All Articles