Browser (JavaScript)¶
predictygraph-js (npm package predictygraph) renders .pdg diagrams to SVG in the browser, with the same layout, routing and themes as pdg. It has no runtime dependencies (27 kB gzipped).
Script tag¶
<script src="https://cdn.jsdelivr.net/npm/predictygraph"></script>
<pre class="pdg">
graph dir=LR
pod "Pod" -> sched "Scheduler" -> gpu "GPU"
</pre>
On page load every pre.pdg, div.pdg and code.language-pdg element is replaced with its SVG, so fenced ```pdg blocks from Markdown renderers work as-is. A diagram with an error is replaced with the error message.
ES module¶
npm install predictygraph
import { render } from "predictygraph";
element.innerHTML = render(source, { theme: "nord" });
API¶
render(source, opts?)returns the SVG as a string. ThrowsPdgSyntaxError(with.line) on invalid input.run(opts?)renders matching elements in the page.opts.selectoroverrides the default selector;opts.nodestakes elements directly.initialize(opts)sets defaults for later calls.startOnLoad: falseturns off the automatic run on page load.listThemes()returns the built-in theme names.
Options for render and initialize:
theme: a built-in theme; overridestheme=in the diagram.css: extra stylesheet text (string or array), applied after the theme.resolve(path, kind): mapsstylesheetand image paths in the diagram to CSS text or an image URL. Onlydata:andhttp(s):image URLs are used.measurer: custom text measurement ({ width(text, family, size, bold) }). The default measures with a canvas, so labels fit the page's fonts.t: animation time in seconds for diagrams withanimate.
Differences from the command line¶
Local font files, --target presets and PNG/APNG output are only in pdg.