Expand description
flowmaid — a Mermaid-like diagram engine.
Supported diagram types: flowcharts (flowchart / graph),
Entity-Relationship diagrams (erDiagram), UML class diagrams
(classDiagram), sequence diagrams (sequenceDiagram), pie
charts (pie), state diagrams (stateDiagram-v2), mindmaps
(mindmap), and user-journey diagrams (journey).
Library usage:
let svg = flowmaid::render_svg("flowchart TD\nA[Start] --> B[Done]").unwrap();
assert!(svg.starts_with("<svg"));
let er = flowmaid::render_svg("erDiagram\nusers ||--o{ posts : writes").unwrap();
assert!(er.contains("users"));
let uml = flowmaid::render_svg("classDiagram\nAnimal <|-- Dog").unwrap();
assert!(uml.contains("Animal"));Re-exports§
pub use emit::to_mermaid;pub use model::Document;pub use parser::ParseError;
Modules§
- class
- UML class diagram rendering: classes drawn as three-compartment boxes (name / fields / methods), relationships drawn with UML end glyphs (triangles, diamonds, open arrows).
- emit
- Graph → mermaid text — the inverse of
crate::parser::parse(issue #18). - er
- Entity-Relationship rendering: entities drawn as attribute tables, relationships drawn with crow’s foot notation.
- fold
- Serpentine / compact layout for long linear chains (issue #15).
- journey
- User-journey rendering: a fixed horizontal band — no graph layout. Tasks flow left to right in source order; each is a smiley face whose color and mouth curve track its 1–5 satisfaction score (red frown → green smile). Sections are colored bands spanning their tasks, a thin path links the faces, and each participant gets a stable accent shown in a legend and as per-task dots.
- layout
- Sugiyama layout engine, following dagre (the algorithm mermaid.js uses):
- mindmap
- Mindmap rendering, in the Mermaid style: the root sits at the centre
and branches radiate outward. Nodes at depth
kland on a ring of radiusk · RING; each subtree owns an angular wedge sized by its leaf count, so busy branches get more room. Every top-level branch gets a stable accent that its whole subtree fills, and the six node shapes (rounded / square / circle / hexagon / bang / cloud) are drawn for real. - model
- Core data model: graph, nodes, edges.
- parser
- Hand-written parser for Mermaid-like diagram syntax.
- pie
- Pie chart rendering: proportional slices drawn clockwise from
12 o’clock, percentage labels inside the slices, and a color
legend on the right (with raw values when
showDatais set). - render
- SVG wrapper:
render(graph)= automatic scene -> SVG serialisation. All geometry & serialisation logic lives in thescenemodule, so the output of render() and the interactive flow (scene/route/to_svg) are guaranteed identical. - scene
- Ready-to-draw geometry for interactive apps (drag & drop
editors, hit-testing, export). Every coordinate in this module
is FINAL (screen pixels, already following the diagram
direction) — unlike the abstract coordinates inside
layout. - seq
- Sequence diagram rendering: participant boxes across the top, dashed lifelines below, and one row per statement top-down.
- style
- Shared color theme, exposed so hosts (GUI painters) can match the SVG writers exactly.
Functions§
- render_
svg - Shortcut: Mermaid-syntax text -> SVG string. Dispatches on the diagram type header (flowchart/graph, erDiagram, classDiagram, sequenceDiagram, pie, or stateDiagram-v2).