Anh Trung
Anh Trung

Reputation: 21

How to set head and tail position in nodes graphviz

I can not control an edge's head and tail position between 2 nodes.

I'm setting up a node like a graph below

questionGraph

digraph G{
  node [shape = "box"]
  a -> b
  b -> a
}

Upvotes: 2

Views: 2834

Answers (2)

vaettchen
vaettchen

Reputation: 7659

This first part is basically the same answer that @marapet has given already:

digraph G
{
   node[ shape = "box" ];
   a:w -> b:w;
   a:e -> b:e[ dir = back ];
}

It produces a graph with round edges:

enter image description here

If that's OK, then marapet's answer should be accepted.

If you insist on the shape that you provided in your post, a bit more complicated procedure needs to be applied:

digraph G
{
    // we create the two nodes to be displayed
    node[ shape = "box" ];
    a b;
    //we also create four empty nodes for routing the edges
    node[ shape = point, height = 0 ];
    x1 x2 x3 x4;
    // we make sure that the nodes are arranged on the right levels
    { rank = same; x1 a x2 }
    { rank = same; x3 b x4 }

    // we draw the edges one by one as the heads are varying
    x1 -> a[ dir = none ];
    a -> x2[ dir = back ];
    x1 -> x3[ dir = none ];
    x2 -> x4[ dir = none ];
    b -> x4[ dir = none ];
    x3 -> b;
}

This gives you

enter image description here

Upvotes: 3

marapet
marapet

Reputation: 56516

The head and tail position of an edge can be defined by using compass points as specified in The dot language, or by using the headport or tailport attributes:

digraph G{
  node [shape = "box"]
  a:w -> b:w
  b -> a [headport=e, tailport=e]
}

Upvotes: 1

Related Questions