nidi3 / graphviz-java

Use graphviz with pure java
Apache License 2.0
937 stars 107 forks source link

Remove/Replacing Edges when adding new ones #128

Closed AmanGotchu closed 4 years ago

AmanGotchu commented 5 years ago

In my scenario I need to ensure that the end result DOT string has

  1. Complete separate list of nodes independent of its edges
  2. Complete separate list of edges independent of the node
    digraph "test" {
    graph ["label"="test","labelloc"="t","dpi"="96","rankdir"="LR"]
    subgraph "cluster_" {
    graph ["rankdir"="LR"]
    "A"
    "B"
    "C"
    }
    "A" -> "B"
    "B" -> "C"
    }

    I'm trying to accomplish this by doing adding the link independent of the mutable node object I added earlier. Because it isn't linked this will create a unique entry for the edge not connected to the node.

      for (Link link : links) {
        overallGraph.add(mutNode(phaseId).addLink(link));
      }

The only problem is that adding multiple edges to a node doesn't work using the previously shown method.

For some reason edges are being replaced/not being placed at all and I wonder if there's a way around this.

I already have a quick fix, but I'd like to understand the internals of why this doesn't work.

Is there a way to make a Graphviz graph not have duplicate edges? Is there a way to use the current Graphviz-Java syntax to accomplish what I'm trying to do without duplicate edges?

nidi3 commented 4 years ago

I don't completely unserstand the issue.

MutableNode a = mutNode("a");
MutableNode b = mutNode("b");
MutableNode c = mutNode("c");
a.addLink(Link.to(b));
a.addLink(Link.to(c));

works and gives a links from a->b and one a->c However, a.addLink(Link.between(b,c)); adds a link between a and b, not b and c. Could this be your problem?

nidi3 commented 4 years ago

Any news here?