nidi3 / graphviz-java

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

I cannot set size for SVG output.. #129

Closed GYiyouth closed 4 years ago

GYiyouth commented 5 years ago

cannot set width or height for svg

            Graphviz.useEngine(new GraphvizCmdLineEngine(), new GraphvizV8Engine()); // Rasterizer.builtIn() works only with CmdLineEngine
            Graph g = graph("example5").directed()
                    .with(node("abc").link(node("xyz")))
                    ;

            Graphviz viz = Graphviz.fromGraph(g);
            viz.height(180).render(Format.SVG).toFile(new File("example/ex5.svg"));
            viz.width(200).rasterize(Rasterizer.BATIK).toFile(new File("example/ex5b.png"));
            viz.width(200).rasterize(Rasterizer.SALAMANDER).toFile(new File("example/ex5s.png"));
            viz.width(200).rasterize(Rasterizer.builtIn("png")).toFile(new File("example/ex5p"));
            String dot = viz.render(Format.DOT).toString();
            String json = viz.engine(Engine.NEATO).render(Format.JSON).toString();
            BufferedImage image = viz.render(Format.PNG).toImage();

it will error image

and size of svg not changed

image

GYiyouth commented 5 years ago

My Java version is

java version "1.8.0_191" Java(TM) SE Runtime Environment (build 1.8.0_191-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

I run program on Mac

nidi3 commented 4 years ago

The first error is because you don't have native graphviz installed on your computer. In this case, GraphvizV8Engine is used as fallback which does not work together with Rasterizer.builtIn(). The unchanged size is indeed a bug.

nidi3 commented 4 years ago

Should be fixed in version 0.11.1.