Right to left edges in dot (Graphviz)

2019-03-14 07:25发布

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

2条回答
手持菜刀,她持情操
2楼-- · 2019-03-14 08:09

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"];
查看更多
狗以群分
3楼-- · 2019-03-14 08:15

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"];
}
查看更多
登录 后发表回答