Use Pre-processors and Post-processors
masterProcessors allow you to intercept and modify the graph data or the resulting output:
- Pre-processors: Modify the DOT source string before it is sent to the Graphviz engine. This is useful for string replacements or automated graph transformations.
- Post-processors: Modify the engine's output (e.g., an SVG string) after rendering. This allows for programmatic manipulation of the resulting graphic elements (like changing CSS classes or attributes via an SVG finder).
Graph graph = graph().with(node("bad word").link("good word"));
Graphviz g = Graphviz.fromGraph(graph)
.preProcessor((source, options, processOptions) -> source.replace("bad word", "unicorn"))
.postProcessor((result, options, processOptions) ->
result.mapString(svg ->
SvgElementFinder.use(svg, finder -> {
finder.findNode("unicorn").setAttribute("class", "pink");
})));
g.render(Format.PNG).toFile(new File("example/ex9.png"));