开发者

Why does a top to bottom graphviz dot graph get layed out counter clockwise?

I updated the question with graphics and more details. Thanks to marapet, without the hack I couldn´t have generated the desired results as images.

why does this code produce this graph?

digraph {
 rankdir = TB;
 1 -> 2 -> 3 -> 1;
}

Why does a top to bottom graphviz dot graph get layed out counter clockwise?

How can I get graphviz/dot to produce a clockwise direction like this?

Why does a top to bottom graphviz dot graph get layed out counter clockwise?

Update

This is the final graph I want to generate (afaik logically correct this way)

digraph {
  rankdir = TB
  start -> 1
  1 -> 2 -> 3 -> 1
  3 -> end
  3 -> increment
  end -> product
  {rank = same; 2; 3; increment}
  {rank = same; end; product}
}

Which produc开发者_JS百科es this result

Why does a top to bottom graphviz dot graph get layed out counter clockwise?

While I want this

Why does a top to bottom graphviz dot graph get layed out counter clockwise?

Thanks


Why does this code produce this graph?

A directed graph puts its nodes on different ranks depending on their relations. Since 1 points to 2, it must be above 2, and since 2 points to 3 it gets to be above 3. But since 3 also points to 1, the circle is completed - any of the 3 nodes could be on top. Graphviz simply puts the first mentioned node on top. Therefore, if you write instead:

2 -> 3 -> 1 -> 2;

node 2 will be on top, and when using

3 -> 1 -> 2 -> 3;

node 3 will be the top node.

Probably the layout engine neato would be more appropriate for this graph, producing a graph with a clockwise direction:

Why does a top to bottom graphviz dot graph get layed out counter clockwise?

If you absolutely must use the dot layout engine, the following dot code

digraph {
  rankdir = TB;
  1 -> 2;
  3 -> 2 [dir=back];
  3 -> 1;
  {rank=same; 2; 3;}
}

produces the desired output by changing the edge 2->3 into 3->2 and at the same time inverting the direction of the arrow.

Or, an other variant of the same technique, easier to explain: We reverse the order of all arrows (1->3->2->1), but display them backwards (dir=back), and force node 2 and 3 to be on the same rank:

rankdir = TB;
edge[dir=back];
1 -> 3 -> 2 -> 1;
{rank=same; 2;3;}

This hack yields the following result:

Why does a top to bottom graphviz dot graph get layed out counter clockwise?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜