Diagram
Introduction
Section titled “Introduction”Shows and edits flowcharts and other node-and-connector diagrams. Diagram renders a JSON model in SVG: nodes (rectangle, rounded, ellipse, diamond, parallelogram, cylinder, document, or a custom SVG shape) with labels, positions, sizes, and ports; edges with straight, orthogonal, or curved routing, arrowheads, dashes, and labels; optional groups.
Auto-layout is layered (Sugiyama style, for flowcharts) or tree, in four directions (TB, BT, LR, RL), and can keep pinned or hand-moved nodes. In edit mode people add shapes from a palette, drag nodes (grid snap, alignment guides), drag from a port to connect, drag edge ends to reconnect, edit labels inline, select several items (Shift-click, marquee), copy, paste, delete, and undo. Every edit also has a keyboard path (M move mode, C connect, Enter label, Delete) and a single-pointer path (toolbar Connect and Move selection). Nodes are a listbox with spatial arrow navigation; a text alternative table lists every node and its connections. diagramToSvg, diagramToPng, and downloadDiagram export the drawing; layoutDiagram is the pure layout function.
- JSON modelNodes with seven shapes or custom SVG, ports, edges with three routings, arrowheads, labels, and groups.
- Auto-layoutLayered flowcharts and trees in four directions, keeping hand-moved steps when you ask.
- Full editingPalette, drag to move with snap and guides, connect from ports, reconnect, inline labels, copy, paste, undo.
- Keyboard firstSpatial arrow navigation, move mode, a connect flow, and a text alternative listing every connection.
- ExportTheme-matched SVG and PNG files without style attributes, ready to share.
Use it for
- Showing or designing a process, workflow, or decision flow (approval routes, onboarding steps, state machines).
- Letting users build a small graph visually, with a keyboard path for every edit.
- Laying out a graph automatically from data (layoutDiagram) and letting people adjust it.
Use something else for
- Reporting hierarchies with one manager per person: use Organization Chart.
- Schedules and dependencies over time: use Gantt.
- Thousands of nodes or force-directed networks: the diagram renders every node and is sized for hundreds.
Anatomy
<div class="aui-diagram [--editing] [--hand] [--placing] [--connecting]"> (consumer host) <div class="aui-diagram__toolbar" role="group" aria-label="{label} controls"> <button class="aui-diagram__tool" data-aui-action="zoomOut|zoomIn|fit|pan|connect|place|undo|redo|delete" aria-label="…" [aria-disabled] [aria-pressed]> <div class="aui-diagram__palette" role="group" aria-label="Add shapes"> (edit mode) <button class="aui-diagram__palette-item"><svg class="__palette-shape" aria-hidden="true"/><span>Decision</span> <div class="aui-diagram__viewport" role="group" aria-roledescription="canvas" aria-label="{label}" tabindex="0"> <svg class="aui-diagram__svg"> <g class="aui-diagram__scene" transform="translate(…) scale(…)"> <rect class="aui-diagram__grid" aria-hidden="true"/> (edit mode) <g class="aui-diagram__groups" aria-hidden="true">…</g> <g class="aui-diagram__edges" aria-hidden="true"><g class="aui-diagram__edge"><path class="__line"/><path class="__arrow"/>… <g class="aui-diagram__nodes" role="listbox" aria-multiselectable="true" aria-label="{label}: nodes"> <g class="aui-diagram__node" role="option" aria-roledescription="node" aria-selected="false" tabindex="0" aria-label="Manager approval, decision, leads to HR check (Yes), comes from Request" transform="translate(x y)"> <rect class="aui-diagram__focus"/><g class="__body"><path class="aui-diagram__shape"/></g> <text class="aui-diagram__label" aria-hidden="true"><tspan>…</tspan></text> <g class="aui-diagram__ports"><g class="__port" data-aui-port="right">…</g></g> (edit mode) <g class="aui-diagram__links" role="listbox" aria-label="{label}: connections"> <g class="aui-diagram__link" role="option" aria-roledescription="connection" aria-label="Request to Manager approval"> <path class="__link-ring"/><path class="__link-core"/><path class="__link-hit"/> <g class="__edge-label" aria-hidden="true"><rect/><text/></g><g class="__handles">…</g> <g class="aui-diagram__overlay" aria-hidden="true"/> (guides, marquee, preview) <input class="aui-diagram__editor" type="text" hidden> (inline label editor) <div class="aui-diagram__text"> <button class="aui-diagram__text-toggle" aria-expanded="false" aria-controls="…">Show text description</button> <div class="aui-diagram__table-scroll" role="region" hidden><table class="aui-diagram__table">…Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Showcase: Process designer
Section titled “Showcase: Process designer”A fully featured live example. Change its options, use it with the keyboard, and watch the event log. The bar above the frame switches theme, density, direction, and locale.
Showcase source
// Process designer showcase: a leave approval workflow (request, manager// approval, HR check, approved or rejected) laid out automatically, with a direction and// algorithm switch, edit mode (palette, ports, keyboard connect and move, inline labels),// undo and redo, SVG and PNG export, and the model JSON updated live.import { Diagram, downloadDiagram, type DiagramChangeDetail, type DiagramLayoutAlgorithm, type DiagramLayoutDirection, type DiagramModel, type DiagramRouting } from '@absoluteui/components/diagram';import { action, choice, createShowcase, hostIn, section, status, toggle } from './kit.js';
const sc = createShowcase({ title: 'Process designer', description: 'A leave approval route. Switch the layout, turn on edit mode to add steps from the palette, drag from a port (or press C on two nodes) to connect, press M to move a node with the arrow keys, Enter to rename, and Delete to remove. Every edit can be undone; the model below is what you would save.',});
const model: DiagramModel = { groups: [{ id: 'approvals', label: 'Approvals' }], nodes: [ { id: 'request', label: 'Leave request submitted', shape: 'ellipse', width: 176, height: 64 }, { id: 'manager', label: 'Manager approval', shape: 'diamond', width: 176, height: 104, group: 'approvals' }, { id: 'hr', label: 'HR check: balance and blackout dates', shape: 'diamond', width: 192, height: 112, group: 'approvals' }, { id: 'approved', label: 'Approved: calendar updated', shape: 'rounded' }, { id: 'rejected', label: 'Rejected: employee notified', shape: 'rounded' }, { id: 'records', label: 'Leave records', shape: 'cylinder', width: 136, height: 80 }, ], edges: [ { id: 'submit', from: 'request', to: 'manager' }, { id: 'm-yes', from: 'manager', to: 'hr', label: 'Approve' }, { id: 'm-no', from: 'manager', to: 'rejected', label: 'Decline' }, { id: 'hr-yes', from: 'hr', to: 'approved', label: 'OK' }, { id: 'hr-no', from: 'hr', to: 'rejected', label: 'Over balance', dashed: true }, { id: 'store', from: 'approved', to: 'records', routing: 'curved', arrowEnd: 'triangle' }, ],};
let algorithm: DiagramLayoutAlgorithm = 'layered';let direction: DiagramLayoutDirection = 'TB';
const host = hostIn(sc.stage);const diagram = Diagram.create(host, { label: 'Leave approval', model, layout: { algorithm, direction }, palette: [ { shape: 'rounded', label: 'Step' }, { shape: 'diamond', label: 'Decision', width: 176, height: 104 }, { shape: 'ellipse', label: 'Start or end', width: 160, height: 60 }, { shape: 'document', label: 'Form' }, { shape: 'cylinder', label: 'Records', width: 136, height: 80 }, ], // A finished request never goes back to the start. canConnect: (_from, to) => to.id !== 'request',});const live = status(sc.stage);
const jsonSection = section(sc, 'Model (JSON)');const pre = document.createElement('pre');pre.className = 'sc-json';pre.tabIndex = 0;pre.setAttribute('aria-label', 'Diagram model');jsonSection.append(pre);const show = (): void => { pre.textContent = JSON.stringify(diagram.model, null, 2);};show();
host.addEventListener('aui-change', (e) => { const d = (e as CustomEvent<DiagramChangeDetail>).detail; show(); live.textContent = `${d.reason}: ${String(d.model.nodes.length)} steps, ${String(d.model.edges.length)} connections`; sc.log('diagram aui-change', { reason: d.reason, ids: d.ids });});sc.listen(host, ['aui-select', 'aui-node-activate', 'aui-zoom'], 'diagram');
const relayout = (): void => { diagram.layout({ algorithm, direction });};choice( sc, 'Layout direction', [ { value: 'TB', label: 'Top to bottom' }, { value: 'LR', label: 'Left to right' }, { value: 'BT', label: 'Bottom to top' }, { value: 'RL', label: 'Right to left' }, ], direction, (value) => { direction = value; relayout(); },);choice( sc, 'Layout algorithm', [ { value: 'layered', label: 'Layered (flowchart)' }, { value: 'tree', label: 'Tree' }, ], algorithm, (value) => { algorithm = value; relayout(); },);choice<DiagramRouting>( sc, 'Connectors', [ { value: 'orthogonal', label: 'Orthogonal' }, { value: 'curved', label: 'Curved' }, { value: 'straight', label: 'Straight' }, ], 'orthogonal', (routing) => { diagram.update({ routing }); },);toggle(sc, 'Edit mode', false, (editable) => { diagram.update({ editable });});toggle(sc, 'Snap to grid', true, (snapToGrid) => { diagram.update({ snapToGrid });});action(sc, 'Undo', () => { diagram.undo();});action(sc, 'Redo', () => { diagram.redo();});action(sc, 'Tidy up (keep moved steps)', () => { diagram.layout({ algorithm, direction, keepPositions: true });});action(sc, 'Fit', () => { diagram.fit();});action(sc, 'Export SVG', () => { void downloadDiagram(diagram, { format: 'svg', fileName: 'leave-approval' });});action(sc, 'Export PNG', () => { void downloadDiagram(diagram, { format: 'png', fileName: 'leave-approval' });});A flowchart laid out automatically
Section titled “A flowchart laid out automatically”import { Diagram, type DiagramModel, type DiagramNodeActivateDetail } from '@absoluteui/components/diagram';
const model: DiagramModel = { nodes: [ { id: 'start', label: 'Request submitted', shape: 'ellipse' }, { id: 'manager', label: 'Manager approval', shape: 'diamond', height: 96 }, { id: 'done', label: 'Approved', shape: 'rounded' }, { id: 'rejected', label: 'Rejected', shape: 'rounded' }, ], edges: [ { id: 'e1', from: 'start', to: 'manager' }, { id: 'e2', from: 'manager', to: 'done', label: 'Yes' }, { id: 'e3', from: 'manager', to: 'rejected', label: 'No', dashed: true }, ],};
const host = document.createElement('div');document.body.append(host);Diagram.create(host, { label: 'Leave approval', model, layout: { algorithm: 'layered', direction: 'TB' } });host.addEventListener('aui-node-activate', (event) => { host.dataset.opened = (event as CustomEvent<DiagramNodeActivateDetail>).detail.node.label;});Edit mode with undo and saving
Section titled “Edit mode with undo and saving”import { Diagram, type DiagramChangeDetail, type DiagramModel } from '@absoluteui/components/diagram';import { Button } from '@absoluteui/components/button';
let saved: DiagramModel = { nodes: [ { id: 'a', label: 'Draft', x: 0, y: 0 }, { id: 'b', label: 'Review', x: 240, y: 0, locked: true }, ], edges: [{ id: 'ab', from: 'a', to: 'b' }],};
const host = document.createElement('div');document.body.append(host);const diagram = Diagram.create(host, { label: 'Document workflow', model: saved, editable: true, routing: 'curved', // Nothing may lead back to the draft. canConnect: (_from, to) => to.id !== 'a',});host.addEventListener('aui-change', (event) => { saved = (event as CustomEvent<DiagramChangeDetail>).detail.model;});const undo = document.createElement('button');undo.type = 'button';undo.textContent = 'Undo';Button.enhance(undo);undo.addEventListener('click', () => { diagram.undo();});host.after(undo);Ports, routing, and arrowheads
Section titled “Ports, routing, and arrowheads”import { Diagram } from '@absoluteui/components/diagram';
const host = document.createElement('div');document.body.append(host);Diagram.create(host, { label: 'Data flow', model: { nodes: [ { id: 'app', label: 'Web app', shape: 'rectangle', x: 0, y: 80, ports: [{ id: 'out', side: 'right' }] }, { id: 'api', label: 'API', shape: 'rounded', x: 260, y: 80, ports: [{ id: 'in', side: 'left' }, { id: 'db', side: 'bottom' }] }, { id: 'db', label: 'Orders', shape: 'cylinder', x: 276, y: 240, width: 128, height: 80 }, ], edges: [ { id: 'call', from: 'app', fromPort: 'out', to: 'api', toPort: 'in', label: 'HTTPS', arrowStart: 'circle', arrowEnd: 'triangle' }, { id: 'query', from: 'api', fromPort: 'db', to: 'db', routing: 'straight', arrowEnd: 'arrow' }, ], },});A custom shape and export
Section titled “A custom shape and export”import { Diagram, downloadDiagram } from '@absoluteui/components/diagram';import { Button } from '@absoluteui/components/button';
const SVG = 'http://www.w3.org/2000/svg';const host = document.createElement('div');document.body.append(host);const diagram = Diagram.create(host, { label: 'Escalation', model: { nodes: [ { id: 'alert', label: 'Alert', shape: 'custom', x: 0, y: 0, width: 120, height: 72 }, { id: 'oncall', label: 'On-call engineer', x: 220, y: 4 }, ], edges: [{ id: 'page', from: 'alert', to: 'oncall', label: 'Page' }], }, // Non-interactive SVG in local coordinates; the label is drawn on top. renderShape: (_node, { width, height, doc }) => { const hexagon = doc.createElementNS(SVG, 'path'); hexagon.setAttribute('d', `M20 0H${String(width - 20)}L${String(width)} ${String(height / 2)}L${String(width - 20)} ${String(height)}H20L0 ${String(height / 2)}Z`); hexagon.setAttribute('class', 'escalation-shape'); return hexagon; },});const save = document.createElement('button');save.type = 'button';save.textContent = 'Download SVG';Button.enhance(save);save.addEventListener('click', () => { void downloadDiagram(diagram, { format: 'svg', fileName: 'escalation' });});host.after(save);Pure layout (no DOM)
Section titled “Pure layout (no DOM)”import { layoutDiagram } from '@absoluteui/components/diagram';
const result = layoutDiagram( [ { id: 'a', width: 120, height: 48 }, { id: 'b', width: 120, height: 48 }, { id: 'c', width: 120, height: 48 }, ], [{ from: 'a', to: 'b' }, { from: 'a', to: 'c' }], { algorithm: 'tree', direction: 'LR', nodeGap: 24, rankGap: 48 },);const b = result.positions.get('b');document.body.dataset.size = `${String(result.width)}x${String(result.height)}, b at ${String(b?.x ?? 0)}`;Straight connectors and a coarser grid everywhere
Section titled “Straight connectors and a coarser grid everywhere”import { configureAbsoluteUI } from '@absoluteui/core';
configureAbsoluteUI({ components: { diagram: { routing: 'straight', gridSize: 24, textAlternative: 'visible' } } });Install and start
Section titled “Install and start”npm install @absoluteui/components @absoluteui/core @absoluteui/themeRegistry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.
import { Diagram, type DiagramModel } from '@absoluteui/components/diagram';import '@absoluteui/components/diagram/style.css';First use
Section titled “First use”import { Diagram, downloadDiagram, type DiagramChangeDetail, type DiagramModel } from '@absoluteui/components/diagram';import '@absoluteui/components/diagram/style.css';
const model: DiagramModel = { nodes: [ { id: 'request', label: 'Leave request', shape: 'ellipse' }, { id: 'manager', label: 'Manager approval', shape: 'diamond', height: 96 }, { id: 'approved', label: 'Approved' }, { id: 'rejected', label: 'Rejected' }, ], edges: [ { id: 'e1', from: 'request', to: 'manager' }, { id: 'e2', from: 'manager', to: 'approved', label: 'Yes' }, { id: 'e3', from: 'manager', to: 'rejected', label: 'No' }, ],};
const host = document.querySelector<HTMLElement>('#workflow');if (host) { const diagram = Diagram.create(host, { label: 'Leave approval', model, editable: true, layout: { direction: 'LR' } }); host.addEventListener('aui-change', (event) => { sessionStorage.setItem('workflow', JSON.stringify((event as CustomEvent<DiagramChangeDetail>).detail.model)); }); document.querySelector('#export')?.addEventListener('click', () => { void downloadDiagram(diagram, { format: 'png', fileName: 'leave-approval' }); });}More usage
See section 33 (vanilla), the metadata examples (basic, editing, ports-routing, custom-shape, layout-function, global-config), and the Process designer showcase on the docs site.
Using Angular? See Diagram for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”Diagram.create(host: HTMLElement, options: DiagramOptions): Diagram; layoutDiagram(nodes: readonly DiagramLayoutNode[], edges: readonly DiagramLayoutEdge[], options?: DiagramLayoutOptions): DiagramLayoutResult; diagramToSvg(diagram: Diagram, options?: DiagramExportOptions): string; diagramToPng(diagram, options?): Promise<Blob>; downloadDiagram(diagram, options: DiagramDownloadOptions): Promise<void>Global configuration key: diagram (see Configuration).
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
label |
string |
Accessible name of the diagram (canvas); the node list is named ‘{label}: nodes’, the connection list ‘{label}: connections’, and the toolbar ‘{label} controls’. Non-empty. Required. | |
model |
DiagramModel |
JSON model { nodes, edges, groups? }. Node: { id, label, shape? (‘rectangle’ | ‘rounded’ (default) | ‘ellipse’ | ‘diamond’ | ‘parallelogram’ | ‘cylinder’ | ‘document’ | ‘custom’), x?, y?, width?, height? (16..2000), ports? ({ id, side, offset? }; default one per side: top, right, bottom, left), group?, pinned?, locked?, data? }. Edge: { id, from, to, fromPort?, toPort?, label?, routing?, arrowStart? (default ‘none’), arrowEnd? (default ‘arrow’; ‘none’ | ‘arrow’ | ‘triangle’ | ‘diamond’ | ‘circle’), dashed?, data? }. Group: { id, label }. Validated (DIAGRAM_OPTIONS). Nodes without x/y are placed by auto-layout. Replacing it with update() clears the undo history. Required. | |
editable |
boolean |
false |
Edit mode: palette, ports, moving, connecting, reconnecting, inline labels, copy and paste, delete, marquee selection, undo and redo. |
layout |
DiagramAutoLayout | null |
Auto-layout settings { algorithm?: ‘layered’ | ‘tree’, direction?: ‘TB’ | ‘BT’ | ‘LR’ | ‘RL’, nodeGap?, rankGap?, sweeps?, keepPositions? }. Given on create, the layout runs once (keepPositions keeps nodes that have positions). Also the defaults of layout() and of placing nodes without positions. | |
palette |
readonly DiagramPaletteItem[] |
Shapes offered in edit mode: { shape, label, width?, height? }. Default: Step (rounded), Decision (diamond), Start or end (ellipse), Process, Input or output, Document, Database. | |
renderShape |
(node: Readonly<DiagramNode>, context: DiagramShapeContext) => SVGElement |
Draws nodes with shape ‘custom’ ({ width, height, selected, doc } context): return SVG content in local coordinates. The label is drawn on top; return non-interactive content. | |
canConnect |
(from: Readonly<DiagramNode>, to: Readonly<DiagramNode>) => boolean |
Veto new and changed connections (pointer, keyboard, addEdge). Self connections and exact duplicates are always refused (announced). | |
historyLimit |
number |
100 |
Undo depth, integer 0..500 (0 disables history). |
showGrid |
boolean |
true |
Dotted grid on the canvas in edit mode. |
nodeWidth |
number |
160 |
Default node width, integer 40..800 diagram px. Globally configurable. |
nodeHeight |
number |
64 |
Default node height, integer 24..600 diagram px. Globally configurable. |
gridSize |
number |
16 |
Grid spacing (snap, keyboard move step, grid dots), integer 4..200. Globally configurable. |
snapToGrid |
boolean |
true |
Snap moved and added nodes to the grid (keyboard moves step by gridSize; off: 1 px). Globally configurable. |
routing |
'straight' | 'orthogonal' | 'curved' |
"orthogonal" |
Default edge routing (an edge’s own routing wins). Globally configurable. |
nodeGap |
number |
40 |
Auto-layout space between neighbors of one rank, integer 8..400. Globally configurable. |
rankGap |
number |
64 |
Auto-layout space between ranks, integer 16..600. Globally configurable. |
minZoom |
number |
0.2 |
Smallest zoom factor, 0.05..1. Globally configurable. |
maxZoom |
number |
3 |
Largest zoom factor, 1..8. Globally configurable. |
textAlternative |
'toggle' | 'visible' | 'hidden' | 'none' |
"toggle" |
Nodes and connections table below the canvas: behind a Show text description button (toggle), always shown, visually hidden but available to screen readers, or none. Globally configurable. |
locale |
string |
"en-US" |
Locale of messages, counts, and zoom percentages. Globally configurable. Inherited from common configuration. |
direction |
'ltr' | 'rtl' |
"ltr" |
rtl mirrors auto-layout and the reading order of nodes; arrow keys stay spatial. Globally configurable. Inherited from common configuration. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
host |
HTMLElement |
The host (class aui-diagram). |
element |
SVGGElement |
The nodes listbox (role=listbox). |
model |
DiagramModel |
The current model, in model order, with every node’s position and size (copies, for saving). |
selection |
DiagramSelectDetail |
Selected node and edge ids. |
editable |
boolean |
Edit mode. |
scale |
number |
Current zoom factor. |
canUndo | canRedo |
boolean |
History is available. |
geometry |
DiagramGeometry |
Drawn geometry (node boxes, wrapped label lines, edge routes, group boxes, bounds) and sample elements for computed colors (used by the export functions). |
Methods
Section titled “Methods”| Method | Description |
|---|---|
update(options: Partial<DiagramOptions>): void |
Merge and apply options (validated first). model replaces the data (undo history cleared; nodes without positions are laid out). No event. |
select(ids: readonly string[]): void |
Replace the selection with these node and edge ids (no event). |
focusNode(id: string): void |
Focus a node and pan it into view. |
addNode(node: Partial<DiagramNode> & { label: string }): string |
Add a node; id, size, and position are filled in (position: a free spot at the view center). Undoable; emits aui-change (‘add’); returns the id. |
addEdge(edge: Partial<DiagramEdge> & { from: string; to: string }): string | null |
Connect two nodes; null when refused (self, duplicate, canConnect). Undoable; emits aui-change (‘connect’). |
updateNode(id: string, patch: Partial<Omit<DiagramNode, 'id'>>): void; updateEdge(id: string, patch: Partial<Omit<DiagramEdge, 'id'>>): void |
Change one node or edge (validated). Undoable; emits aui-change (‘update’). |
moveNode(id: string, x: number, y: number): void |
Move a node (snapped when snapToGrid). Undoable; emits aui-change (‘move’). |
remove(ids: readonly string[]): void |
Remove nodes (with their edges) and edges. Undoable; emits aui-change (‘delete’). |
layout(options?: DiagramAutoLayout): void |
Run auto-layout (defaults from the layout option), then fit. keepPositions keeps pinned and hand-moved nodes. Undoable; announces; emits aui-change (‘layout’). |
undo(): boolean; redo(): boolean |
Undo / redo the last edit (whole-model snapshots). Announce and emit aui-change (‘undo’ / ‘redo’); false when there is nothing to undo/redo. |
copy(): number; paste(): string[] |
Copy the selected nodes and the edges between them into the instance clipboard; paste them offset by two grid steps (new ids), select them, emit aui-change (‘paste’). |
editLabel(id: string): void |
Open the inline label editor of a node or edge (edit mode). Enter or blur commits, Escape cancels. |
fit(): void |
Scale (at most 100 %) and center the drawing; announces the zoom. |
zoomTo(scale: number): void |
Zoom around the viewport center, clamped to minZoom..maxZoom; announces and emits aui-zoom. |
centerOn(id: string): void |
Center the view on a node. |
describe(): string |
Plain-text description: one line per node with its shape and connections. |
destroy(): void |
Remove the toolbar, palette, viewport, text alternative, listeners, and host classes. |
Events
Section titled “Events”| Event | Detail | Bubbles | Cancelable | Description |
|---|---|---|---|---|
aui-change |
DiagramChangeDetail { reason: 'add' | 'move' | 'connect' | 'reconnect' | 'label' | 'delete' | 'paste' | 'layout' | 'update' | 'undo' | 'redo'; model: DiagramModel; ids: string[] } |
Yes | No | The model changed through the UI or an API method. Save detail.model. |
aui-select |
DiagramSelectDetail { nodes: string[]; edges: string[] } |
Yes | No | The selection changed through the UI (click, Shift-click, marquee, Space, Ctrl/Cmd+A, Escape, paste, delete). select() does not emit. |
aui-node-activate |
DiagramNodeActivateDetail { id: string; node: DiagramNode } |
Yes | No | A node was activated: Enter or double-click in view mode, or double-click on a locked node in edit mode. |
aui-zoom |
DiagramZoomDetail { scale: number } |
Yes | No | The zoom changed through the toolbar, keys, Ctrl/Cmd + wheel, or zoomTo (fit does not emit). |
Content areas
Section titled “Content areas”| Area | Description |
|---|---|
renderShape |
SVG content of ‘custom’ nodes, re-rendered when the node’s label, size, ports, or selection changes. |
CSS classes
Section titled “CSS classes”All rules live in the aui.components cascade layer, so application styles override them without specificity battles.
| Class | Purpose |
|---|---|
aui-diagram |
Host; –editing in edit mode, –hand with the Pan tool, –placing while Move selection waits for a point, –connecting while a connection is being made. |
aui-diagram__toolbar | __tool |
Toolbar group and its buttons (aria-disabled when unavailable; Pan, Connect, and Move selection are toggles with aria-pressed). |
aui-diagram__palette | __palette-item | __palette-shape |
Edit-mode palette: buttons that add a shape (click) or are dragged onto the canvas. |
aui-diagram__viewport | --panning |
Focusable canvas (block-size 30rem by default); arrow keys pan. |
aui-diagram__svg | __scene | __grid | __grid-dot |
The SVG, the transformed scene, and the edit-mode grid. |
aui-diagram__groups | __group | __group-box | __group-label |
Group boxes around their member nodes. |
aui-diagram__edges | __edge | --dashed | --selected | __line | __arrow | --open |
Connector drawing (aria-hidden). |
aui-diagram__nodes | __node | --locked | --source | --moving | --target |
Node listbox and options (transform attribute); states for locked nodes, the connect source, move mode, and the drop target. |
aui-diagram__body | __shape | --custom | __shape-detail | __label | __focus |
Node outline, cylinder rim, label text, and focus ring. |
aui-diagram__ports | __port | __port-hit | __port-dot |
Edit-mode ports (drag to connect). |
aui-diagram__links | __link | __link-hit | __link-ring | __link-core | __edge-label | __edge-label-bg | __edge-label-text | __handles | __handle |
Connection listbox options: hit area, focus ring, label, and reconnect handles of a selected edge. |
aui-diagram__overlay | __guide | __marquee | __preview | __ghost |
Alignment guides, marquee, connection preview, palette drop ghost. |
aui-diagram__editor |
Inline label input (positioned through the CSSOM). |
aui-diagram__text | --hidden | __text-toggle | __table-scroll | __table |
Text alternative: toggle button and the nodes and connections table. |
Icon slots
Section titled “Icon slots”| Slot | Default icon |
|---|---|
toolbar |
zoom-out, zoom-in, maximize (fit), grip (Pan tool), link (Connect), locate (Move selection), undo, redo, trash (delete) |
Design tokens
Section titled “Design tokens”Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.
--aui-border-width | --aui-border-width-strong | --aui-color-border | --aui-color-border-strong | --aui-color-focus-ring | --aui-color-hover | --aui-color-selected | --aui-color-selected-text | --aui-color-surface | --aui-color-surface-sunken | --aui-color-text | --aui-color-text-disabled | --aui-color-text-muted | --aui-focus-ring-offset | --aui-focus-ring-width | --aui-font-family-sans | --aui-font-size-sm | --aui-font-size-xs | --aui-font-weight-semibold | --aui-icon-size-sm | --aui-line-height-tight | --aui-radius-md | --aui-radius-sm | --aui-shadow-sm | --aui-space-1 | --aui-space-2 | --aui-touch-target-min
TypeScript definitions
type DiagramShape = 'rectangle' | 'rounded' | 'ellipse' | 'diamond' | 'parallelogram' | 'cylinder' | 'document' | 'custom';type DiagramRouting = 'straight' | 'orthogonal' | 'curved';type DiagramArrow = 'none' | 'arrow' | 'triangle' | 'diamond' | 'circle';interface DiagramPort { id: string; side: 'top' | 'right' | 'bottom' | 'left'; offset?: number }interface DiagramNode { id: string; label: string; shape?: DiagramShape; x?: number; y?: number; width?: number; height?: number; ports?: DiagramPort[]; group?: string; pinned?: boolean; locked?: boolean; data?: DiagramData }interface DiagramEdge { id: string; from: string; to: string; fromPort?: string; toPort?: string; label?: string; routing?: DiagramRouting; arrowStart?: DiagramArrow; arrowEnd?: DiagramArrow; dashed?: boolean; data?: DiagramData }interface DiagramGroup { id: string; label: string }interface DiagramModel { nodes: DiagramNode[]; edges: DiagramEdge[]; groups?: DiagramGroup[] }interface DiagramAutoLayout { algorithm?: 'layered' | 'tree'; direction?: 'TB' | 'BT' | 'LR' | 'RL'; nodeGap?: number; rankGap?: number; sweeps?: number; keepPositions?: boolean }interface DiagramChangeDetail { reason: DiagramChangeReason; model: DiagramModel; ids: string[] }interface DiagramSelectDetail { nodes: string[]; edges: string[] }interface DiagramNodeActivateDetail { id: string; node: DiagramNode }interface DiagramZoomDetail { scale: number }Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: A focusable canvas (group, roledescription ‘canvas’) containing two multi-select listboxes, one for nodes and one for connections, each with one roving tab stop (WAI-ARIA APG listbox, with spatial arrow navigation for nodes). Each node’s accessible name states its label, shape, and connections; a text alternative table lists every node with what it leads to and comes from. Edits have keyboard and single-pointer paths (no deprecated ARIA drag-and-drop attributes) and are announced through live regions.
Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.
Keyboard
Section titled “Keyboard”| Key | Context | Action |
|---|---|---|
| Tab / Shift+Tab | Diagram | Toolbar buttons, palette (edit mode), canvas, the focused node, the focused connection, then the text alternative. |
| Arrow keys | Canvas focused | Pan the view (Shift: four times farther). |
| Arrow keys | Node focused | Move focus to the nearest node in that direction (spatial, not mirrored in RTL); Shift adds it to the selection. |
| Home / End | Node focused | First / last node in reading order. |
| Space / Shift+Space or Ctrl/Cmd+Space | Node or connection focused | Select only this item / toggle it in the selection. |
| Enter | Node focused, view mode | Activates the node (aui-node-activate). |
| Enter or F2 | Node or connection focused, edit mode | Edit the label inline (Enter or leaving the field commits, Escape cancels). |
| C | Node focused, edit mode | First press: this node is the source (‘Connecting from …’); move to the target and press C or Enter to connect. C on the source again cancels. |
| M | Node focused, edit mode | Move mode for the node (or the selection): arrows move by one grid step (Shift: five), Enter or M finishes (one undo step), Escape restores. |
| Delete / Backspace | Node or connection focused, edit mode | Delete the selection (or the focused item); deleting nodes deletes their connections. Locked nodes stay. |
| Ctrl/Cmd+C / Ctrl/Cmd+X / Ctrl/Cmd+V | Edit mode | Copy / cut the selected nodes (with the connections between them) / paste them offset. |
| Ctrl/Cmd+A | Diagram focused | Select every node. |
| Ctrl/Cmd+Z / Ctrl/Cmd+Shift+Z or Ctrl/Cmd+Y | Edit mode | Undo / redo. |
| + or = / - / 0 | Diagram focused | Zoom in / out around the center; fit to screen. |
| Escape | Diagram focused | Cancels connecting or Move selection, else clears the selection. |
| ArrowDown/ArrowRight / ArrowUp/ArrowLeft, Home / End | Connection focused | Next / previous connection; first / last. |
| Element | Role |
|---|---|
| toolbar <div> | group, named ‘{label} controls’ |
| toolbar and palette <button>s | button (native); Pan tool, Connect, and Move selection are toggles (aria-pressed) |
| palette <div> | group, named ‘Add shapes’ |
| viewport <div> | group with aria-roledescription ‘canvas’, named by label; focusable (arrow keys pan) |
| nodes <g> | listbox (aria-multiselectable), named ‘{label}: nodes’ |
| node <g> | option with aria-roledescription ‘node’, named ‘{label}, {shape}, leads to …, comes from …’ |
| connections <g> | listbox (aria-multiselectable), named ‘{label}: connections’; hidden when there are none |
| connection <g> | option with aria-roledescription ‘connection’, named ‘{from} to {to}[, {label}]’ |
| connector drawing, groups, grid, overlay, label text | none (aria-hidden=true) |
| label editor <input type=text> | textbox, named ‘Label of {name}’ |
| text alternative | button (aria-expanded, aria-controls) and a region with a table (caption, column and row headers) |
ARIA attributes
Section titled “ARIA attributes”| Attribute | Element | Value |
|---|---|---|
aria-label |
canvas / listboxes / options / toolbar / editor | label; ‘{label}: nodes’; ‘{label}: connections’; computed node and connection names; ‘{label} controls’; ‘Label of {name}’ |
aria-roledescription |
canvas / node / connection | canvas / node / connection (localized) |
aria-selected |
options | true for selected nodes and connections |
aria-multiselectable |
listboxes | true |
tabindex |
options | 0 on the focused node and the focused connection, -1 on the others |
aria-disabled |
toolbar buttons | true at the zoom limits and when undo, redo, delete, Move selection, or Connect is not possible |
aria-pressed |
Pan tool, Connect, Move selection | true while active |
aria-expanded / aria-controls |
text alternative toggle | Whether the table is shown / the table region id |
live region |
shared live regions | Polite: zoom, added, deleted, moved, connected, reconnected, label changed, copied, pasted, undone, redone, layout applied, cancellations. Assertive: move mode, connecting from, Move selection prompt, refused connection, locked node. |
One node and one connection are in the Tab order (roving tabindex): the last focused, else the first in reading order. Focusing a node pans the view so it is fully visible. Re-rendering keeps focus on the same element; after deleting, focus moves to the first remaining node (or the canvas); after adding from the palette or pasting, focus moves to the new node; the label editor returns focus to its item. Nodes show a focus-ring rectangle; connections a ring along their path.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”Automated test results: Accessibility and compliance.
Notes and known caveats
Section titled “Notes and known caveats”- Every dragging action has an alternative (2.5.7): moving by M plus arrows or by the toolbar Move selection button then a single click on the canvas; connecting by C on source and target or the Connect button then a click on the target; adding shapes by clicking palette buttons; panning with arrow keys on the canvas; reconnecting by deleting and connecting again.
- Node names include their connections, and the text alternative table lists the whole graph, so the structure is available without seeing the drawing (1.1.1, 1.3.1).
- Selected nodes differ by fill and a three px outline, connectors by width, not color alone (1.4.1).
- Ports are small pointer targets (2.5.8); the keyboard and toolbar connect paths are the equivalent controls.
- Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
- Screen readers in browse mode may intercept arrow keys and letters; users need focus mode inside the diagram.
- Pointer drags (move, connect, marquee, pan) are not announced while they happen; the result is.
- Spatial arrow navigation can skip nodes hidden behind others in the same direction; Home/End and the text alternative reach every node.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/diagram |
108.4 kB | 36.1 kB | 31.8 kB | 1.6 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| Diagram.create with 300 nodes and 400 edges (layered layout included) | < 250 ms in headless Chromium, first layout and paint included (e2e performance test; 184 ms measured in a desktop Chromium pane) |
| layoutDiagram (layered) for a 500-node flowchart (499 edges) | < 50 ms in headless Chromium (e2e performance test; 12 ms measured in Node 24) |
| layoutDiagram (layered) for 500 nodes and 700 edges, 200 of them long cross edges | < 250 ms (worst case measured: 110 to 160 ms in Node 24) |
| One drag frame moving a node with 300 nodes rendered | < 8 ms (only the moved nodes and their edges are updated) |
Tested scale: 300 nodes and 400 edges for the create and drag budgets, 500 nodes for the layout budgets; 4 to 12 nodes in the behavior unit tests. Every node and edge is an SVG element (no virtualization): keep diagrams to a few hundred nodes.
Diagram.createwith 300 nodes and 400 edges, layout and first paint included: budget < 250 ms in headless Chromium (184 ms measured).layoutDiagram(layered): a 500-node flowchart < 50 ms (12 ms measured); 500 nodes with 200 long cross edges < 250 ms (110 to 160 ms measured).- Drags update only the moved nodes and their edges (budget < 8 ms per frame at 300 nodes); a full re-render runs once at the end.
- Label wrapping is measured with a canvas 2D context and cached per label.
Measured run times: Performance.
Details
Section titled “Details”States
View mode and edit mode; selected nodes and edges; focused node and connection; move mode; connecting (keyboard, toolbar, or port drag); placing (Move selection); Pan tool on; dragging (move, connect, reconnect, marquee, pan); editing a label; locked node; zoomed and panned; text alternative shown or hidden.
State transitions
| From | Trigger | To |
|---|---|---|
| Idle | Node M (edit) |
Move mode; arrows move; Enter/M commits one undo step; Escape restores. |
| Idle | Node C (edit) or toolbar Connect |
Connecting from the node; C/Enter on another node or a click connects; Escape or C on the source cancels. |
| Idle | Port drag (edit) | Connection preview; release on a node connects (on a port: to that port). |
| Selected edge | Handle drag (edit) | Reconnect preview; release on a node changes that end. |
| Idle | Toolbar Move selection | Placing; a click on the canvas centers the selection there; Escape cancels. |
| Idle | Enter/F2 or double-click (edit) | Label editor; Enter or blur commits, Escape cancels; focus returns to the item. |
| Any edit | Undo / Redo | Previous / next snapshot. |
| Any | update({ model }) |
New data; history and modes cleared. |
Accessibility notes
- Every drag has an alternative (WCAG 2.5.7): move with
Mand arrows or toolbar Move selection then one click; connect withCon source and target or Connect then one click; add shapes by clicking palette buttons; pan with arrow keys; reconnect by deleting and connecting again. - Node names carry their connections and the text alternative lists the whole graph, so the structure does not depend on seeing the drawing (1.1.1, 1.3.1).
- Selection is shown by fill plus a three px outline (nodes) or width (edges), not color alone (1.4.1).
- Ports are small pointer targets; keyboard and toolbar connect are the equivalent controls (2.5.8).
- Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Responsive behavior
The viewport has a fixed block size (30rem by default; set block-size on .aui-diagram__viewport) and clips the drawing. The view pans and zooms instead of scrolling, so the page reflows at 320 px. Toolbar and palette wrap and use touch-target-min buttons. fit() scales the drawing into any viewport; before the user pans or zooms, a resize refits.
Right-to-left
direction: 'rtl' mirrors auto-layout (LR runs right to left; top-down layouts are mirrored horizontally) and the reading order of nodes. Arrow keys are spatial and not swapped: ArrowLeft always goes to the node on the left. Toolbar and palette follow the inline direction.
Theming
Nodes use --aui-diagram-node-bg and --aui-diagram-node-border, connectors --aui-diagram-edge-color, the canvas --aui-diagram-canvas-bg with --aui-diagram-grid-color dots. Selected nodes use color-selected with a color-selected-text outline; focus uses color-focus-ring. Works in the light, dark, and high-contrast themes and with density (toolbar sizes follow touch-target-min). Forced-colors mode uses CanvasText lines and outlines, Canvas fills, and Highlight for selection and focus. Nothing animates, so reduced motion needs no change.
Global configuration
import { configureAbsoluteUI } from '@absoluteui/core';
configureAbsoluteUI({ components: { diagram: { routing: 'curved', gridSize: 20, textAlternative: 'visible' } } });Globally configurable: nodeWidth, nodeHeight, gridSize, snapToGrid, routing, nodeGap, rankGap, minZoom, maxZoom, textAlternative, plus the common locale and direction.
Component configuration
Every globally configurable option can also be set per instance in Diagram.create() and changed with update(); instance values win. label, model, editable, layout, palette, renderShape, canConnect, historyLimit, and showGrid are per instance only.
Timezones
Not applicable: the diagram shows no dates or times.
Icons
Toolbar icons are built-in names resolved through the icon registry: zoom-out, zoom-in, maximize (fit), grip (Pan tool), link (Connect), locate (Move selection), undo, redo, trash (delete). Register replacements for these names to change them everywhere. Palette buttons draw their shape outline.
Security
Labels render through textContent in SVG <text>; the label editor is a plain text input (no HTML anywhere). renderShape returns SVG elements the application builds (strings are not accepted; the result is checked to be an SVGElement). The model is validated before use: unique ids, known nodes, ports, and groups, finite numbers in range, and JSON-primitive data. Positions are SVG attributes and the editor position goes through the CSSOM, so the component works under a strict CSP with Trusted Types. Export writes presentation attributes only; PNG export needs img-src blob:.
Data handling
No persistence, network access, or telemetry. Every change emits aui-change with the whole model (copies); the model getter returns copies for saving. Copy and paste use an instance clipboard (the system clipboard is not read or written). Export creates files through temporary object URLs; nothing is uploaded.
Supported data scale
Sized for a few hundred nodes and edges (tested at 300 nodes and 400 edges; layout at 500 nodes). Every node and edge is an SVG element (no virtualization). For thousands of nodes use a data view (Data Grid, Organization Chart with lazy loading) instead.
Edge cases
- Nodes without positions are placed by layout; with
keepPositions, new nodes go next to a placed neighbor and never overlap. - Cycles are allowed (back edges are reversed for layering only); self connections are refused.
- Exact duplicate connections are refused; parallel edges between different ports are allowed.
- An empty model shows an empty canvas; the connection list is hidden while there are none.
- Long labels wrap to the node’s label area and end with an ellipsis; the full label stays in the accessible name and the text alternative.
- Locked nodes cannot be moved, relabelled, or deleted through the UI (the API can still change them).
- An empty node label is not accepted from the editor (the old label stays); an empty edge label removes it.
update({ model })during a drag or move mode cancels the interaction first.
Errors
Invalid options or models throw AbsoluteUIError (DIAGRAM_OPTIONS) with the property path (for example diagram.model.edges[2].toPort) and the expected value, before anything renders or changes. API methods with unknown ids throw the same error. canConnect refusals are announced, not thrown. Export throws DIAGRAM_EXPORT_OPTIONS for bad options and DIAGRAM_EXPORT_FAILED / DIAGRAM_EXPORT_UNAVAILABLE when rasterizing is not possible.
Known limitations
- Edges are routed between their end points only and do not avoid other nodes.
- Every node and edge is rendered (no virtualization).
- Groups are boxes around their members; swimlanes and nested groups are not provided.
- Nodes are resized through the model, not by dragging handles.
- A plain mouse wheel scrolls the page; zoom needs Ctrl/Cmd + wheel, the toolbar, or keys. No pinch zoom.
- Keyboard reconnect means delete and connect again.
- Export draws custom shapes as rounded rectangles.
- Manual screen-reader verification is pending.
Unsupported scenarios
- Freehand drawing, user-placed edge waypoints.
- Rich text or HTML labels.
- Collaborative editing (merging is the application’s job).
- Printing across pages.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.