0

How to make an edge with both direction in GraphViz?

I am trying to make an curved edge with both direction.

But the only plot I can make is:

enter image description here

I want to make the edge between x1 and x2 curved with both direction.

The code I used:

digraph {

rankdir=LR

node [shape=box ]
x1;x2
node [shape=oval ]
y

x1->y[dir=back label=0.77]
x2->y[dir=back label=0.42]

x1:w -> x2:w[dir=both constraint=false]

}

I would appreciate any help.

Dany
  • 4,521
  • 1
  • 15
  • 32
Keon-Woong Moon
  • 216
  • 4
  • 10
  • What version of Graphviz are you using? – tk421 Sep 05 '18 at 16:13
  • I notice that if I have `[ dir=both label="" ]` then the arrow shows in both directions, but swapping the attributes `[ label="" dir=both ]` then only one direction appears. Weird! – Ooker Jun 15 '21 at 11:43

1 Answers1

1

I think there should be a better solution but the following did work for me:

digraph {

rankdir=LR

node [shape=box ]
x1;x2
node [shape=oval ]
y

x1->y[dir=back label=0.77]
x2->y[dir=back label=0.42]

x1:w -> x2:w[dir=both constraint=false]
x2:w -> x1:w[dir=both constraint=false]
}

based on the answer from Changing edge direction in dot:

digraph g {

rankdir=LR

node [shape=box ]
{rank=same x1;x2}
node [shape=oval ]
y

x1 -> y[dir=back label=0.77]
x2 -> y[dir=back label=0.42]

x1:w -> x2:w[dir=both label=0.34]

}
albert
  • 8,285
  • 3
  • 19
  • 32
  • But it make two edges. If I add a label for this edge, your approach makes two edges. For example, x2:w->x1:w[dir=both constraint=false label=0.34] – Keon-Woong Moon Sep 05 '18 at 15:43
  • That is a new constraint compared to the original question. There should indeed be a better solution. – albert Sep 05 '18 at 15:47
  • when removing the `constraint=false` the double header arrow appears. Probably by playing around a bit with positioning etc. you might be able to get the right picture. It is a bit strange to me that it doesn't work, I couldn't directly find the right answer in the documentation either (https://graphviz.gitlab.io/_pages/doc/info/lang.html). – albert Sep 05 '18 at 16:17