GraphViz, grouping multiple edges between the same nodes but with different labels
Asked Answered
C

2

22
digraph G {
  a -> b [ label = "foo" ];
  a -> b [ label = "bar" ];
}

This will create two edges between the 'a' and 'b' nodes. Is there a way to have only one edge (group them)?

Crosspiece answered 24/2, 2010 at 8:9 Comment(2)
Do you want one edge with two labels? In other words, what do you want that would be different than just having one statement which specifies one edge between a and b?Hi
I wonder if there's a way to make the edge thicker if there are more duplicates of it.Yuk
P
7

I think it really depends on what your desired output would be. One possibility is:

digraph G {
   graph [ splines = false ]
   a -> b [ label = "foo" ];
   a -> b [ label = "bar" ];
 }

Where not using splines draws edges with straight line segments and so duplicate edges will not be distinguished visually.

In your ideal output, what would the single edge look like since there are to be two different labels for it?

Partnership answered 24/2, 2010 at 8:25 Comment(2)
Thx for the answer. It really visually is not distinguished. With labels I would like to concatenate them. I will probably have to write again the file with modifications.Crosspiece
You're correct. Your objective goes beyond the node/edge processing capabilities of graphviz and does require some sort of pre-processing to merge duplicates into the form you're looking for. Of course, with smaller graphs like the example, you can sort of fake it with the splines option.Partnership
T
46

The "strict" keyword may help you.

strict digraph G {
  a -> b [ label = "foo" ];
  a -> b [ label = "bar" ];
}

This will combine the edges. But I believe it will only apply the first label.

Tibiotarsus answered 21/7, 2010 at 14:53 Comment(1)
Work, but will apply the last label.Carom
P
7

I think it really depends on what your desired output would be. One possibility is:

digraph G {
   graph [ splines = false ]
   a -> b [ label = "foo" ];
   a -> b [ label = "bar" ];
 }

Where not using splines draws edges with straight line segments and so duplicate edges will not be distinguished visually.

In your ideal output, what would the single edge look like since there are to be two different labels for it?

Partnership answered 24/2, 2010 at 8:25 Comment(2)
Thx for the answer. It really visually is not distinguished. With labels I would like to concatenate them. I will probably have to write again the file with modifications.Crosspiece
You're correct. Your objective goes beyond the node/edge processing capabilities of graphviz and does require some sort of pre-processing to merge duplicates into the form you're looking for. Of course, with smaller graphs like the example, you can sort of fake it with the splines option.Partnership

© 2022 - 2024 — McMap. All rights reserved.