Pan and zoom any SVG or element, inline or full screen. A toolbar with zoom, fit, 100%, full screen and Copy SVG, wheel, pinch and keyboard, a readable floor for inline diagrams, and a renderer prop so Mermaid or any engine can draw into it without being bundled.
On this page
- Mermaid in docs
- Architecture diagrams
- Flow charts
- Large charts
- Screenshots
Examples
With a renderer
Pass the source and a function that turns it into SVG. The viewer runs it after mount and again when the source changes, aborts the older call, shows a drawing state, and shows a failure with its message and the source. Mermaid stays your dependency: the code tab shows the wiring. The demo below uses a small stand-in that reads lines of A -> B; edit it, or type a line without an arrow to see the error.
Any element, filling a panel
Installation
Installation is part of Pro
Pro components install from a licensed registry. The live preview stays open to everyone.
Props
- children
ReactNode- Any SVG or element. An SVG's size comes from its viewBox; an element is measured.
- svg
string- SVG markup, put in as nodes. Scripts, on* handlers and javascript: links are removed; sanitize untrusted markup first.
- source / renderer
string / (source, signal) => Promise<string | SVGElement>- Draws source into SVG on the client. The older call's signal aborts when the source changes; a throw shows the error with the source and Try again.
- label
string- Default
"Diagram" - The accessible name and the full-screen title.
- mode
"inline"|"fill"- Default
"inline" - Inline: column wide, as tall as needed up to maxHeight. Fill: fills the parent, fitted with padding, a plain wheel pans.
- maxHeight
number- Default
480 - The tallest an inline view grows before it pans.
- minZoom
number- Default
0.7 - Inline, a diagram is never fitted below this scale; the rest pans.
- fullScreen
boolean- Default
true - The full screen button and the hint's link.
- copy
boolean|(svg) => void- Default
true - Copy SVG. A function gets the markup instead of the clipboard.
- defaultView / onViewChange
{ view: { x, y, k }, fitted }- Start from a remembered view; hear every zoom and pan to remember it.
- toolbarStart / toolbar
ReactNode / boolean- Default
- / true - Something at the start of the toolbar row (Diagram | Code tabs), or no toolbar at all.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Any SVG or element. An SVG's size comes from its viewBox; an element is measured. |
| svg | string | - | SVG markup, put in as nodes. Scripts, on* handlers and javascript: links are removed; sanitize untrusted markup first. |
| source / renderer | string / (source, signal) => Promise<string | SVGElement> | - | Draws source into SVG on the client. The older call's signal aborts when the source changes; a throw shows the error with the source and Try again. |
| label | string | "Diagram" | The accessible name and the full-screen title. |
| mode | "inline" | "fill" | "inline" | Inline: column wide, as tall as needed up to maxHeight. Fill: fills the parent, fitted with padding, a plain wheel pans. |
| maxHeight | number | 480 | The tallest an inline view grows before it pans. |
| minZoom | number | 0.7 | Inline, a diagram is never fitted below this scale; the rest pans. |
| fullScreen | boolean | true | The full screen button and the hint's link. |
| copy | boolean | (svg) => void | true | Copy SVG. A function gets the markup instead of the clipboard. |
| defaultView / onViewChange | { view: { x, y, k }, fitted } | - | Start from a remembered view; hear every zoom and pan to remember it. |
| toolbarStart / toolbar | ReactNode / boolean | - / true | Something at the start of the toolbar row (Diagram | Code tabs), or no toolbar at all. |
Accessibility
- The diagram is a focusable image with your label; + and - zoom, 0 fits, 1 goes to 100% and the arrows pan while it has focus.
- The toolbar is a labelled toolbar; every button has a name and its key in a tooltip, and the zoom level is announced politely as it changes.
- Full screen is a modal dialog named by its title; Escape closes it and focus goes back to the full screen button.
- A failed render is an alert with the message and the source, so the content is never lost.
- Give a diagram a text alternative near it when its content matters (the source, or a short summary): an SVG drawing is not read out.
What it handles
- 01Shows a diagram as wide as its column and as tall as it needs; one that does not fit is scaled down, never below 70%, and the rest pans.
- 02Zooms with the toolbar, Cmd or Ctrl + wheel, a trackpad pinch or two fingers, around the pointer; drags to pan; + - 0 1 and the arrows from the keyboard.
- 03Keeps the page scrolling under a plain wheel inline; a sideways wheel or Shift + wheel pans a wide diagram in place.
- 04Opens full screen fitted to the window, and gives focus back to the button on close.
- 05Copies the SVG, and draws from any renderer you pass (Mermaid, Graphviz, your server) with an AbortSignal, a drawing state and the error with its source.
- 06Takes any SVG markup or element; scripts, event handlers and javascript: links in markup are removed.
States
- First render
- Fitted, nothing moves
- none
- Zoom or fit from the toolbar or keys
- The diagram eases to the new view
- 180ms, ease in out
- Wheel, pinch or drag
- Follows the hand at once
- none
- Full screen
- The surface fades in
- 120ms, ease out
- Drawing
- A spinner and Drawing the diagram, until the renderer answers
- none
- Reduced motion
- Every view change is instant
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Fitted, nothing moves | none |
| Zoom or fit from the toolbar or keys | The diagram eases to the new view | 180ms, ease in out |
| Wheel, pinch or drag | Follows the hand at once | none |
| Full screen | The surface fades in | 120ms, ease out |
| Drawing | A spinner and Drawing the diagram, until the renderer answers | none |
| Reduced motion | Every view change is instant | 0ms |
Works with
When to use
When to use
- Mermaid, Graphviz or any SVG diagram in docs and notes: readable inline, pan and zoom, full screen and Copy SVG.
- Large charts, maps or screenshots that need zoom without leaving the page.
When not to use
- An editable graph of nodes and edges: use Node Graph Editor.
- A whiteboard people draw on: use AI Whiteboard.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Diagram Viewer to my app and wire it to my own data.
- I need mermaid, Graphviz or any SVG diagram in docs and notes: readable inline, pan and zoom, full screen and Copy SVG. Set that up with the Knowns UI Diagram Viewer.
- Which Diagram Viewer props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "diagram-viewer" }) and search_docs({ query: "diagram viewer" }). Pro props, full examples and source come back once your license key is in the MCP config.