Pisnge
A Rust-based diagram rendering library compatible with mermaidjs.
Features
- Mermaid Compatibility: Parses Mermaid pie chart syntax (.mmd files)
- SVG Output: Generates clean, scalable SVG files with full text support
- PNG Output: Generates raster PNG files with full text support
- CLI Interface: Simple command-line tool for batch processing
- Fast: Much faster, smaller and more memory efficient than mermaid, does not need puppeteer
Installation
Pre-built Binaries (Ubuntu 22.04)
Download the latest binary from Releases:
# Download the binary
# Make it executable
# Use it directly
From crates.io
From source
Usage
Command Line
# Basic usage
# Specify format (defaults to png)
# Custom font and dimensions
# Verbose output
# If running from source
Required Arguments
-i, --input: Input Mermaid file (.mmd)-o, --output: Output file path
Optional Arguments
-f, --format: Output format - "png" or "svg" (defaults to "png")-w, --width: Desired maximum width-H, --height: Desired maximum height--font: Font family name (defaults to "Liberation Sans")-v, --verbose: Show detailed parsing information
Charts will be rendered up to the maximum of width/height and the unfilled dimension will be reduced in the output rather than introducing borders into the image.
Mermaid Syntax Support
Basic Pie Chart
pie title My Pie Chart
"Label 1": 42
"Label 2": 30
"Label 3": 28
With Data Display
pie showData title Story Points by Status
"Done": 262
"To Do": 129
"In Progress": 87
With Theme Configuration
%%{init: {'theme': 'base', 'themeVariables': {'pie1': '#ff6b6b', 'pie2': '#4ecdc4'}}}%%
pie showData title Custom Colors
"Category A": 60
"Category B": 40
# Render an example pie chart
# Or if running from source
Architecture
- Parser (
src/parser.rs): Uses nom to parse Mermaid pie chart syntax - Renderer (
src/renderer.rs): Generates SVG using thesvgcrate - Data Structures (
src/lib.rs): DefinesPieChart,PieChartData, andPieChartConfig
Differences to Mermaid
This project currently only supports pie charts and all mermaid options should be supported, however only the base theme is supported and the default colors are different.
The pie chart segments are rendered in the order they are specified rather than from biggest to smallest, and the overall spacing is better since font widths/heights are measured directly.
Development
Running Tests
Building
Dependencies
clap: Command-line argument parsingnom: Parser combinator used to parse mmd syntaxsvg: SVG generationresvg: SVG to PNG conversiontiny-skia: 2D graphics rasterizationfont-kit: For loading system fontsrusttype: For measuring text widths/heights
License
MIT License - see LICENSE file for details.
Contributing
Contributions welcome! This library currently focuses on pie charts but could be extended to support other Mermaid diagram types.
Roadmap
- PNG output format
- Additional Mermaid diagram types (xy chart is planned soon)
- New diagram types not supported by mermaid
- More theming options than provided by mermaid