nidi3 / graphviz-java

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

Graphviz and Options are final classes #163

Closed NKame closed 4 years ago

NKame commented 4 years ago

Not really a bug per se, but I need to extend those classes to manipulate "images: []". So far I do this by overriding both classes to add the necessary accessors. Would it be possible to make them non-final, or should I submit a patch for adding my images[] handling (which is pretty rough)?

nidi3 commented 4 years ago

yes, submit a (raw) PR so I can see the intention and I can think about it

NKame commented 4 years ago

Just to give a bit a context, I create a graph like this one with HTML labels as a SVG, and I put the SVG and the images in one directory, thus my image paths are all relative. If I don't put in the options images:[{path....}], a "GraphvizException: Error: in label of node " is thrown. Patch incoming, but you know what it's going to look like now I think :-) (note: I tried with .basedir() but it doesn't prevent the exception from being thrown). image

NKame commented 4 years ago

Ok, I see in master that the "image" support is present. Simplifies the patch https://github.com/nidi3/graphviz-java/pull/164

NKame commented 4 years ago

Except it doesn't work... relative paths are not preserved, and there is a mismatch between IMG SRC which is relative and image: [{path which is absolute.

NKame commented 4 years ago

Fixed in the PR, but breaks the tests who expect absolute paths. Not sure it should apply to all cases.

nidi3 commented 4 years ago

Can you give a concrete example where a relative path don't work? I could not reproduce it in https://github.com/nidi3/graphviz-java/blob/master/graphviz-java/src/test/java/guru/nidi/graphviz/engine/ImageTest.java

NKame commented 4 years ago

The problem is that one: say I do this

 void relativeWithBase() throws IOException {
        final Graphviz g = Graphviz.fromGraph(graph().with(node(" ").with(Image.of("graphviz.png"))));
        final File out = new File("target/img-base-relative.svg");
        g.basedir(new File("target")).render(SVG).toFile(out);
        assertTrue(out.length() > 15000);
    }

My goal here is to produce a SVG in a folder I can zip and send along with the images. But that doesn't work, because the SVG is written like this:

<image xlink:href="/J:/projects/TestGVJ/target/graphviz.png" width="96px" height="96px" preserveAspectRatio="xMinYMin meet" x="4.3259" y="-100.326"/>

Thus, if I move the folder, I break the SVG.

nidi3 commented 4 years ago

Finally, I understand. Makes perfectly sense. I think the default should be relative path, absolute paths should only be used when they are explicitly provided.

jeremydouglass commented 4 years ago

This would be extremely useful for me as well.

nidi3 commented 4 years ago

fixed in 0.16.1