1

I have this code

graph G {
node [shape=circle]
rankdir=LR;
1 -- 10;
2 -- 9;
3 -- 8;
4 -- 7;
5 -- 6;
}

but I want to have the vertices 1 ... 10 in a flat, horizontal row, then with the connecting edges as arcs (alternating above, below) connecting 1 to 10, 2 to 9, etc. My code only produces a stack of vertices and their edges.

147pm
  • 2,137
  • 18
  • 28

2 Answers2

2

You need to tell graphviz first that you want to have the nodes in a row. Only then you can introduce a second set of edges the way you like. There is very limited control as to how graphviz places the edges; Trial and error brought me to the solution below which is the best I could find.

See comments in the code:

graph so 
{
    node [shape=circle]
    rankdir=LR;

    // We put all nodes in one row
    // We need the weight to keep them straight
    // Edge style is invisible, so that they are not in the way of your edges
    1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7 -- 8 -- 9 -- 10[ weight = 10, style = invis ];

    1:ne -- 10:nw;          // added ports to force node above
    2 -- 9;                 // the rest is graphviz' decision
    3 -- 8;
    4 -- 7;
    5 -- 6;
}

gives you

enter image description here

vaettchen
  • 7,299
  • 22
  • 41
1

Try this. Invisible edges are to enforce order within rank. Double 5 -- 6 edge is to enforce arc, otherwise the edge would be straight. I tried it on viz-js.com. The alternation of above and below arcs heavily depends on order of edges. Since it's very sensitive, undocumented and probably prone to minor version change, I don't recommend it as production solution, the DOT engine is IMHO not suitable for such tasks. For one-shot documentation purposes it's sufficient and fulfills your specification.

graph G {
splines=splines;
node [shape=circle];
edge [constraint=false];
rankdir=LR;
1 -- 10;
3 -- 8;
2 -- 9;
1 -- 2 [style=invis, constraint=true];
2 -- 3 [style=invis, constraint=true];
3 -- 4 [style=invis, constraint=true];
4 -- 5 [style=invis, constraint=true];
5 -- 6 [style=invis];
4 -- 7;
5 -- 6 [constraint=true];
6 -- 7 [style=invis, constraint=true];
7 -- 8 [style=invis, constraint=true];
8 -- 9 [style=invis, constraint=true];
9 -- 10 [style=invis, constraint=true];
}

viz-js.com screenshot

Tomáš Záluský
  • 10,735
  • 2
  • 36
  • 64