Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only show unique edges in graphviz

Tags:

graphviz

I have an input file with about ~5000 lines and 1 to 9 nodes per line.

Many edges are not unique and I would like to only show the unique ones.

A more simple example.

graph {
    a -- b
    a -- b
    a -- b
}

Yields

enter image description here

Is there a way to make the above graph yield something like

enter image description here

I know I could change the sample input to

graph {
    a -- b
}

But it would not be easy to do that for my real input.

like image 714
humanbeing Avatar asked Mar 15 '23 17:03

humanbeing


2 Answers

There actually is a way: Use the strict keyword:

strict graph G {
    a -- b [label="First"];
    a -- b [label="Second"];
    a -- b [label="Third"];
}

Result:

GraphViz output showing combined edges.

Without strict, all three edges would be shown. Note that it only takes the first edge's attributes, contrary to what the documentation suggests.

like image 129
Alex Reinking Avatar answered Mar 21 '23 01:03

Alex Reinking


Try strict:

strict graph {
    a -- b
    a -- b
    a -- b
}

This yields

enter image description here

and should work for any size of graph.

like image 29
vaettchen Avatar answered Mar 21 '23 03:03

vaettchen