43

I'm trying to display edges going from right to left (i.e. backwards) using dot:

C <- A -> B

The best I could do was:

digraph {
  a -> b;
  c -> a [dir="back"];
  {rank=same;c a b}
}

..which is fine, except I don't like using c -> a when the edge is directed the other way.

So I wanted to share this solution (which didn't seem to be mentioned on SO) and check if I'm missing something obvious.

See: http://www.graphviz.org/doc/info/attrs.html#k:dirType

STF
  • 1,485
  • 3
  • 19
  • 36
Nickolay
  • 31,095
  • 13
  • 107
  • 185
  • This doesn’t solve the problem that the rank of the nodes for the a-c edge still isn’t reversed relative to the graph, unless you write it `c -> a`. I wish one could just write `a <- c`. :/ – Evi1M4chine Nov 27 '13 at 04:28

2 Answers2

59

I have no alternative to your usage of dir, but i can make it slightly shorter, if you want horizontal alignment, use the rankdir property of graph, to force direction from left to right.

digraph {
  rankdir=LR;
  a->b;
  c->a [dir="back"];
}
Martin
  • 10,738
  • 14
  • 59
  • 67
10

To make edges point backwards by default:

digraph {
  edge [dir="back"];
  a -> b;
  c -> a;
}

Then, override the default to point forwards:

c -> d [dir="forward"];
Roger Dahl
  • 15,132
  • 8
  • 62
  • 82