Dot graph language - how to make bidirectional edges automatically?
Asked Answered
P

2

100

Here is a very simplified example of my Dot graph:

strict digraph graphName {
A->B
B->A
}

This creates alt text

Instead I want a single edge shown between A and B but with a double arrow head. I know how to get the double arrowhead as a global option:

strict digraph graphName {
  edge [dir="both"]
A->B
B->A
}

But that looks very ugly, and not all of my edges should be dual headed.

alt text

If I do more processing of the graph and detect the double reference myself and replace the two edges with a single edge, it looks OK. But I'd rather not have to do this extra step

strict digraph graphName {
A->B [dir="both"]
}

alt text

Any better solutions?

Posthaste answered 11/8, 2010 at 20:16 Comment(0)
O
89

How about 'concentrate=true'?:

strict digraph graphName {
concentrate=true
A->B
B->A
}

with concentrate=true

From the documentation:

If true, use edge concentrators. This merges multiedges into a single edge and causes partially parallel edges to share part of their paths. The latter feature is not yet available outside of dot.

Optimal answered 11/8, 2010 at 22:24 Comment(4)
Works with a label for me, and I'm running an older version.Hydrodynamics
If it helps... this didn't work for me, in so much as it coalesced the edges, but only put a single arrow on the end. Then I tried to "strict digraph"... and it works perfectly then.Ague
This is silly but it's what the OP wanted, so big up!Gottschalk
@Ague It does not work for me either, I get edges with a single arrowhead only. I am using pygraphviz, and I tried pgv.AGraph(directed=True, strict=True), but it does not work either, i get two edges again... Any suggestions?Garygarza
J
130

You should just use:

A -> B [dir=both]
Jolie answered 19/7, 2013 at 9:7 Comment(3)
This saved me some redundant lines, and I'm using it as well as the top answer where appropriate.Hydrodynamics
You don't need quotes around "both"Dyslogistic
@NoahSussman It can't be the accepted answer because it doesn't actually answer the question ;)Gottschalk
O
89

How about 'concentrate=true'?:

strict digraph graphName {
concentrate=true
A->B
B->A
}

with concentrate=true

From the documentation:

If true, use edge concentrators. This merges multiedges into a single edge and causes partially parallel edges to share part of their paths. The latter feature is not yet available outside of dot.

Optimal answered 11/8, 2010 at 22:24 Comment(4)
Works with a label for me, and I'm running an older version.Hydrodynamics
If it helps... this didn't work for me, in so much as it coalesced the edges, but only put a single arrow on the end. Then I tried to "strict digraph"... and it works perfectly then.Ague
This is silly but it's what the OP wanted, so big up!Gottschalk
@Ague It does not work for me either, I get edges with a single arrowhead only. I am using pygraphviz, and I tried pgv.AGraph(directed=True, strict=True), but it does not work either, i get two edges again... Any suggestions?Garygarza

© 2022 - 2024 — McMap. All rights reserved.