Diagram
diagramRenders 54 editorial declarative SVG diagram types with orthogonal routing, 4 importers (Mermaid/draw.io/Excalidraw/PlantUML), and Paper/Markdown integrations.
Usage
54 Editorial Diagrams Gallery & Multi-Format Importers
Browse all 54 visual types across 6 layout families, explore 9 semantic patterns, and redraw Mermaid, draw.io, Excalidraw, or PlantUML live into editorial SVG.
import { Diagram, importDiagram } from "@hulianui/ui/diagram";
export function ArchitectureCard() {
return (
<Diagram
spec={{
type: "architecture",
title: "Payment Core Topology",
skin: "editorial",
variant: "dots",
nodes: [
{ id: "gw", label: "API Gateway", tag: "EDGE", icon: "gateway" },
{ id: "ledger", label: "Ledger Core", tag: "CORE", treatment: "focal", icon: "database" },
],
edges: [{ from: "gw", to: "ledger", label: "COMMIT", tone: "accent" }],
}}
/>
);
}With Paper (Dynamic Figures & Print Adaptation)
Drive highlightNodes from prose FigRef clicks inside PaperFigure; switching to print mode adapts automatically to light paper and expands sub-figures.
in the system overview, external traffic passes through the gateway and auth guard before entering synchronous ledger persistence. Switching to print mode adapts the diagram to light paper and expands sub-figures.
import { FigRef, Paper, PaperFigure } from "@hulianui/ui";
import { ArchitectureDiagram } from "@hulianui/ui/diagram";
const states = {
overview: { focus: [] as string[] },
ingress: { focus: ["gw", "auth"] },
commit: { focus: ["auth", "ledger"] },
};
export function PaperLinkedDiagram() {
return (
<Paper defaultMode="read">
<p>
Click <FigRef to="tx-arch" state="ingress">Gateway & Auth Guard</FigRef> to highlight the active nodes.
</p>
<PaperFigure id="tx-arch" states={states} caption="Core transaction pipeline with narrative focus">
{(state) => (
<ArchitectureDiagram
title="Transaction Pipeline"
showHeader={false}
highlightNodes={state.focus}
nodes={[
{ id: "gw", label: "API Gateway", tag: "EDGE" },
{ id: "auth", label: "Policy Guard", tag: "SEC", treatment: "security" },
{ id: "ledger", label: "Ledger Store", tag: "STORE", treatment: "focal" },
]}
edges={[
{ from: "gw", to: "auth", label: "VERIFY" },
{ from: "auth", to: "ledger", label: "COMMIT", tone: "accent" },
]}
/>
)}
</PaperFigure>
</Paper>
);
}With Markdown (Automatic Fenced Diagram Rendering)
Pass createMarkdownDiagramRenderer to Markdown.renderCodeBlock to redraw mermaid, plantuml, drawio, excalidraw, and diagram fences automatically.
Embedded Diagrams in Markdown
Write fenced mermaid blocks directly in Markdown and let createMarkdownDiagramRenderer() redraw them in Hulian editorial style:
Regular language fences fall back to the default CodeBlock:
const renderCodeBlock = createMarkdownDiagramRenderer({ skin: "editorial" });import { Markdown } from "@hulianui/ui";
import { createMarkdownDiagramRenderer } from "@hulianui/ui/diagram";
const renderCodeBlock = createMarkdownDiagramRenderer({
skin: "editorial",
variant: "dots",
});
export function TechnicalDoc({ source }: { source: string }) {
return <Markdown renderCodeBlock={renderCodeBlock}>{source}</Markdown>;
}With SlideDeck / StageDraw (Stepped Walkthrough & Live Ink)
Sync controlled activeStep with slide progression and overlay StageDraw for live presentation annotations.
import { useState } from "react";
import { StageDraw } from "@hulianui/ui";
import { ArchitectureDiagram } from "@hulianui/ui/diagram";
export function PresentationDiagram() {
const [step, setStep] = useState<number | null>(1);
return (
<div className="relative">
<ArchitectureDiagram
title="Slide Step Walkthrough"
activeStep={step}
onActiveStepChange={setStep}
nodes={[
{ id: "ingest", label: "Event Ingest", step: 0 },
{ id: "router", label: "Rule Engine", treatment: "focal", step: 1 },
{ id: "sink", label: "Audit Sink", treatment: "store", step: 2 },
]}
edges={[
{ from: "ingest", to: "router", label: "STREAM", step: 1 },
{ from: "router", to: "sink", label: "ARCHIVE", tone: "accent", step: 2 },
]}
/>
<StageDraw tool="pen" toolbar />
</div>
);
}When to use
Built for technical documentation, architecture decision records (ADRs), blogs, papers, slides, and structured AI generation. Pass a typed JSON spec (or Mermaid / draw.io / Excalidraw / PlantUML source) to render publication-grade editorial SVG with 4px-grid rounded orthogonal routing, OKLCH zero-flash theme adaptation, geometry verification, and offline-safe SVG/PNG export.
How it fits into the Hulian visualization ecosystem:
- Interactive dashboards & business apps (hover tooltips, drill-down, drag-and-drop editing): use Chart, Sankey, Funnel, Treemap, Gantt, Heatmap, SequenceDiagram, or Flow.
- Editorial concept & architecture diagrams for docs, papers, slides, and AI output: use
Diagram(@hulianui/ui/diagram). - Dynamic narrative & presentation stages: place
<Diagram>inside Paper (PaperFigure+FigRef) to highlight nodes from prose and adapt cleanly to print; pair with SlideDeck / StageDraw for stepped walkthroughs with live ink annotations; or wirecreateMarkdownDiagramRenderer()into Markdown to redraw fencedmermaidblocks automatically.
Import
Like Formula, Diagram lives on its own subpath so consumers who do not render diagrams pay zero bundle cost—and no extra npm package installation is required beyond @hulianui/ui:
import {
Diagram,
ArchitectureDiagram,
DIAGRAM_CATALOG,
SEMANTIC_PATTERN_CATALOG,
createMarkdownDiagramRenderer,
importDiagram,
exportDiagramToSvgString,
verifyDiagramSvg,
} from "@hulianui/ui/diagram";Fine-grained subpaths are also available: @hulianui/ui/diagram/importers, @hulianui/ui/diagram/export, @hulianui/ui/diagram/verify, and @hulianui/ui/diagram/catalog.
54 visual types across 6 layout families
| Layout family | Count | Visual types |
|---|---|---|
Graph & Zone (graph-zone) | 17 | architecture, architecture-delta, it-current-state, deployment, high-level, data-flow, dp-integration, medallion, flowchart, state-machine, swimlane, process, procedure-chart, event-modeling, dependency-graph, schedule-network, sbgn |
Hierarchy & Schema (hierarchy) | 8 | tree, org-chart, nested, layer-stack, er, database-schema, uml-class, git-graph |
Matrix & Blueprint (matrix) | 7 | quadrant, wardley-map, user-journey, service-blueprint, story-map, dp-security-matrix, requirement-traceability |
Analytical & Geometric (analytical) | 14 | bar, line, radar, waterfall, scatter, polar, unit-grid, venn, loop, fishbone, packet-structure, heatmap, treemap, pyramid |
Flow & Time (flow-time) | 6 | sequence, gantt, sankey, kanban, timeline, steps |
Axonometric (axonometric) | 2 | exploded-axonometric, axonometric-plan |
Common props (DiagramCommonProps)
| Name | Type | Default | Description |
|---|---|---|---|
| title * | string | - | Diagram title shown in header and written into SVG <title> |
| eyebrow | string | Derived from type | Monospace eyebrow label above the title |
| description | string | Auto-generated | Written into SVG <desc> for screen readers and verification |
| skin | "editorial" | "light" | "dark" | "terminal" | "editorial" | Defaults to @hulianui/tokens OKLCH semantic tokens with zero-flash dark mode |
| variant | "clean" | "dots" | "sketchy" | "clean" | Paper surface treatment: clean paper, dot grid, or subtle hand-drawn filter |
| motion | "none" | "reveal" | "step" | "loop" | "none" | Optional step walkthrough controls, respecting prefers-reduced-motion |
| activeStep | number | null | - | Controlled 0-based step index (null shows all), for syncing with Paper or SlideDeck |
| defaultActiveStep | number | null | null | Uncontrolled initial step index |
| onActiveStepChange | (step: number | null) => void | - | Callback when the active step changes |
| highlightNodes | readonly string[] | - | Node IDs to emphasize (ideal for <FigRef> narrative focus) |
| highlightEdges | readonly string[] | - | Edge IDs or "from->to" keys to emphasize |
| dimOthers | boolean | true | Dim non-highlighted elements when focus arrays are provided |
| adaptPaperPrint | boolean | true | Automatically switches editorial to light paper and hides step controls when inside <Paper mode="print"> |
| sizePreset | DiagramSizePreset | "fit" | Canvas aspect presets (doc-inline, doc-wide, slide-16x9, print-a4-landscape, etc.) |
| showHeader | boolean | true | Set to false when nested inside a captioned container like PaperFigure |
| legend / callouts / summaryCards | arrays | - | Bottom horizontal legend, editorial italic callouts, and asymmetric summary cards |
Ecosystem integrations
1. With Paper
Place <Diagram> inside <PaperFigure> and drive highlightNodes or activeStep from prose <FigRef> clicks. When <Paper> switches to print mode, Diagram reads PaperContext automatically, adapts to light paper, and hides interactive step buttons.
2. With Markdown
Pass createMarkdownDiagramRenderer(options?) to <Markdown renderCodeBlock={...} />:
- Automatically renders
mermaid,plantuml/puml,drawio,excalidraw, anddiagram(JSONDiagramSpec) fenced blocks in Hulian editorial style. - Gracefully falls back to the default CodeBlock for all other languages or invalid input.
3. Shared offline SVG / PNG export
exportDiagramToSvgString(svg) shares the OKLCH-to-sRGB color resolver from Paper, turning var(--color-*) and oklch() / oklab() values into standalone #rrggbb + opacity attributes so exported SVGs open reliably offline in Word, Inkscape, and LaTeX.
Playground
<ArchitectureDiagram title="Payment Core Topology" skin="editorial" variant="dots" motion="step" showHeader={true} nodes={nodes} edges={edges} />