janalis / viz
Mermaid, Graphviz and PlantUML for PHP: native rendering with a CLI fallback, SVG/PNG/PDF export and conversion between the three
Requires
- php: >=8.5
- ext-mbstring: *
- symfony/filesystem: ^8.0
- symfony/polyfill-intl-grapheme: ^1.33
- symfony/process: ^8.0
- symfony/string: ^8.0
- symfony/yaml: ^8.1
Requires (Dev)
- carthage-software/mago: 1.59.*
- infection/infection: ^0.35.4
- phpunit/phpunit: ^13.2
Suggests
- ext-gd: Native PNG export of Mermaid diagrams (needs FreeType)
- ext-zlib: Compressed native PDF export
Provides
None
Conflicts
None
Replaces
None
README
Viz
Mermaid, Graphviz and PlantUML for PHP.
Native rendering · SVG, PNG and PDF · conversion between the three
Documentation · Getting started · Rendering · Conversion · Compatibility
Viz renders Mermaid, Graphviz and PlantUML diagrams from PHP 8.5 to SVG, PNG or PDF, and converts between the three languages. Each language is drawn natively, in PHP, with no Node, browser, Graphviz or Java needed; the language's own command-line tool is the fallback for whatever the native renderer leaves.
- Mermaid: 30+ diagram families, themes and the hand-drawn look, pinned to Mermaid 12.1
(compatibility). Fallback:
mmdc. - Graphviz: the DOT language and every layout, written clean-room from the published
papers and
dot's observed output (compatibility). Fallback:dot. - PlantUML: every diagram family, ported from PlantUML's MIT distribution and sized as the
jar sizes it (compatibility).
Fallback:
plantumlor its.jar.
Install
composer require janalis/viz
PHP 8.5 with ext-mbstring; ext-gd with FreeType for PNG, ext-zlib for compressed PDF. See
Installation for the optional tools.
Quick start
use Janalis\Viz\Viz; use Janalis\Viz\Render\Format; use Janalis\Viz\Source\SourceFormat; $viz = new Viz(); $svg = $viz->render("flowchart LR\n a --> b", SourceFormat::Mermaid, Format::Svg)->bytes; $viz->export('digraph { a -> b }', SourceFormat::Dot, 'graph.pdf'); // format from the extension $dot = $viz->convert($mermaidFlowchart, SourceFormat::Mermaid, SourceFormat::Dot);
More in the guide: rendering and export, native or command line, conversion and the shared models and upgrading from 0.1.
Contributing
Bug reports with the diagram that misbehaves are welcome, as are fixes. Please note the
clean-room rule: the native Graphviz is written from published papers and dot's observed
output only, never from Graphviz's source. See the
development guide.
make install
make verify # validate, format, lint, analyze, 100% line coverage, audit
Changes go under ## Unreleased in CHANGELOG.md; the Release workflow cuts a
version from it (releasing).
License
MIT. The bundled IBM Plex Mono fonts are under the SIL Open Font License
(resources/fonts/OFL.txt). The ported parts of Mermaid, PlantUML (its MIT distribution), its
Open Iconic icons, HSLuv, khroma, roughjs, d3-shape and d3-format keep their notices in
resources/licenses/, as do the Twemoji pictures PlantUML bundles, under CC-BY 4.0.
