GraphvizRenderer

Wraps the guru.nidi:graphviz-java library (which in turn shells out to a native Graphviz dot installation, or falls back to a bundled JS implementation) to turn Graphviz DOT source -- typically produced by it.unibo.tuprolog.bdd.toDotString from a it.unibo.tuprolog.bdd.BinaryDecisionDiagram -- into a PNG image. Since actually rendering an image the first time can be slow and may fail (e.g. if no usable Graphviz engine can be found on the host), availability is probed once asynchronously via initialize and cached in isAvailable/isReady, instead of being checked synchronously on every call.

Properties

Link copied to clipboard

Whether the initialize probe has completed and determined that Graphviz can render PNGs on this host. false both while the probe is still running (see isReady) and once it has failed.

Link copied to clipboard

Whether the initialize probe has completed, regardless of its outcome (see isAvailable).

Functions

Link copied to clipboard

Kicks off, on a background thread, a one-shot probe that renders a trivial diagram (the terminal node BinaryDecisionDiagram.terminalOf true) to determine whether this Graphviz installation can actually produce PNGs; the outcome becomes visible through isReady (once the probe completes) and isAvailable (its result). Call this once at application startup, before any renderAsPNG/ it.unibo.tuprolog.ui.gui.GraphRenderView is expected to work; until the probe completes, isAvailable reports false and isReady reports false. Calling it again restarts the probe.

Link copied to clipboard
fun renderAsPNG(graph: String, imageOutputStream: OutputStream)

Renders graph (Graphviz DOT source) to a PNG image, written to imageOutputStream.