Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify in DOT file that edges go upwards

I want to render a directed graph like:

    A
   ^ ^
  /   \
 /     \
B       C

But no matter what order I put the statements in, dot insists on generating an image that looks like:

B       C
 \     /
  \   /
   v v
    A

I've tried specifying the port, but then the edges just wrap around. It doesn't change the position of the nodes.

like image 776
dspyz Avatar asked Dec 11 '22 07:12

dspyz


2 Answers

The solution is rankdir

digraph G {
 rankdir="BT"
 B->A
 C->A
}
like image 160
CodeFreezr Avatar answered Jan 10 '23 01:01

CodeFreezr


rankdir is the solution if you want to build your whole graph from bottom to top. A more flexible approach is to just tell the edges to point backward:

digraph G
{
    A -> B[ dir = back ];
    A -> C[ dir = back ];
}

yields

enter image description here

You could also write

A -> { B C }[ dir = back ];

Or you could give the general instructions for all edges defined after this instruction to point backward:

edge[ dir = back ];

This can be undone by

edge[ dir = forw ];

Hence,

digraph G
{
    edge[ dir = back ];
    A -> B;
    A -> C;
    edge[ dir = forw ];
    { B C } -> D;
}

yields

enter image description here

like image 21
vaettchen Avatar answered Jan 10 '23 01:01

vaettchen