nidi3 / graphviz-java

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

Graphviz Does Not Load Custom Attributes? #170

Closed rride closed 4 years ago

rride commented 4 years ago

Hi,

I am using DOT graph format to organize entities and annotate properties of connections between them (see the graph below for details). My idea was using graphviz-java to render entities and their connection structure and to do that I was going to use the code below. However, it looks like Graphviz does not load custom properties into Link::attrs(). Is that expected to happen? Is there a way to work this around? Am I doing anything wrong?

   MutableGraph g = new Parser().read(dot);

    g.edges().forEach({link ->
      link.add(Label.lines(link.attrs().get("relationship").toString()));
    });

Graph:

graph graphWithLoop { entity1 [type = Urn]; entity2 [type = Urn]; entity3 [type = Urn]; entity1 -- entity2 [relationship = "1:"]; entity2 -- entity3 [relationship = "1:"]; entity3 -- entity1 [relationship = "1:*"]; }

nidi3 commented 4 years ago

I get

graph "graphWithLoop" {
"entity1" ["type"="Urn"]
"entity2" ["type"="Urn"]
"entity3" ["type"="Urn"]
"entity1" -- "entity2" ["relationship"="1:","label"="1:\n"]
"entity2" -- "entity3" ["relationship"="1:","label"="1:\n"]
"entity3" -- "entity1" ["relationship"="1:*","label"="1:*\n"]
}

What would yo expect?

rride commented 4 years ago

I apologize for a false alarm. The behavior I encountered was a result of https://issues.apache.org/jira/browse/GROOVY-4239, which is about Groovy preferring static methods of a class over instance methods if they have the same signature. In this case, attrs() is defined as an instance method in Link class and as a static method in Attributes interface, which causes the problem. I believe this is a result of the language's design problem and not exactly Graphviz's.