Multiple edges between nodes only generates one edge in output
If there are two edges between two nodes, the generated output only captures one of the edges.
Code Sample:
GraphVizGraph graph = new GraphVizGraph(); graph.node(this, "nodea").label("node_a_label"); graph.node(this, "nodeb").label("node_b_label"); graph.edge(this, "nodea","nodeb").label("edge #1"); graph.edge(this, "nodea","nodeb").label("edge #2");
graph.comment("graph comment"); graph.label("graph label");
graph.writeTo(new File("c:/test.dot"));
Code Sample Output:
// graph comment digraph G { node [shape=box]; compound=true; label="graph label"; n1 [label="node_b_label"]; n0 [label="node_a_label"]; n0 -> n1 [label="edge #2"]; }
Code Sample Expected Output:
// graph comment digraph G { node [shape=box]; compound=true; label="graph label"; n1 [label="node_b_label"]; n0 [label="node_a_label"]; n0 -> n1 [label="edge #1"]; n0 -> n1 [label="edge #2"]; }
Additional details:
- using graphviz-builder-1.0.4
Thank you.
That's actually by design, the purpose of the library is to generate graphs with only one edge between any pair of nodes. Hadn't really thought about multigraphs... We tend to solve this by using a single edge with weights and/or multiple labels, which scales better as a visualization.
I just hit this too, rendering a network topology. Usually nodes have one link between them, albeit those links may be bundles / LAGs, but apparently sometimes there are entirely separated links between the same routers! Erg :)
One can of course do something funky with the labels as you say, but it doesn't entirely work for all use cases, as if one wants to colour edges according to link status for example, where one is down and one is up, there's no easy way to manage that.
This is addressed by the extra edgeId parameter https://github.com/shevek/graphviz4j/blob/master/graphviz-builder/src/main/java/org/anarres/graphviz/builder/GraphVizGraph.java#L194 which allows for multigraphs. Pass a distinct edgeId value for each separate edge you want.
The design philosophy of the library is that you can throw relative garbage at the graph API, repeat yourself, etc, and the internal hash tables will take care of you. If you want distinct objects, you have to say so explicitly.
GraphVizGraph graph = new GraphVizGraph();
graph.node(this, "nodea").label("node_a_label");
graph.node(this, "nodeb").label("node_b_label");
graph.edge(this, "nodea","nodeb", "MyFirstEdge").label("edge #1");
graph.edge(this, "nodea","nodeb", "MySecondEdge").label("edge #2");
There is no contract for edgeId save for Object/hashCode/equals and null is allowed.