Flowchart

VdFlowchart edits a flat diagram of nodes and edges, with layouts, inline labels, and undo/redo. This page runs package 1.6.1. The live editor opts into camera scales 0.05–20 and resizable node sides 6–4800. Defaults stay 0.35–3 and 56–420 when you omit both ends of a pair.

Editor
Scale 1.0000

Overview sets the camera to 0.05, so the whole workspace is visible at once. The editor toolbar still zooms, fits, and undoes. Every step is a flat node rather than a nested container. Hover a node to show a handle outside each side: drag a handle to connect, or click it to add a connected node.

A node resized smaller than its default size scales its text, wrapping, radius, stroke, markers, curve arms, orthogonal routes, labels, and inline editor with it. Default-size steps keep their standard chrome, and larger nodes do not grow that chrome. Junctions stay 28×28. With these wider camera bounds the background grid covers 240,000 units and keeps a readable screen spacing. The default 0.35–3 camera keeps the 12,000-unit grid.

Saved JSON uses document format 1.3.0, which is separate from package 1.6.1. Format 1.3.0 writes optional collapsed: true, color, fill, stroke, textColor, and locked: true on nodes and color, strokeStyle on edges only when non-default, and does not add a parent id. viewport.scale is stored to four decimal places; positions and sizes stay at two. Every older 1.x document still loads. Malformed JSON and unsupported future versions throw before the current diagram changes. Catch errors when calling load() directly. Use exportSvg() to export a cropped standalone SVG string.

API Reference

Install

Usage

<script setup lang="ts">
import { ref } from 'vue';
import { VdFlowchart, type VdFlowchartDocument, type VdFlowchartExposed } from '@vanduo-oss/vd3-flowchart';
import '@vanduo-oss/vd3-flowchart/css';
const editor = ref<VdFlowchartExposed | null>(null);
const readonly = ref(false);
const document = ref<VdFlowchartDocument>({
  nodes: [
    { id: 'start', text: 'Start', x: 40, y: 100 },
    { id: 'note', text: 'Note', x: 280, y: 120, width: 16, height: 16 },
  ],
  edges: [{ id: 'next', from: { nodeId: 'start', port: 'right' }, to: { nodeId: 'note', port: 'left' } }],
});
</script>
<template>
  <button type="button" @click="readonly = !readonly">Toggle read-only</button>
  <button type="button" :disabled="!editor?.canUndo()" @click="editor?.undo()">Undo</button>
  <button type="button" @click="editor?.fitNode('note')">Fit note</button>
  <VdFlowchart ref="editor" :data="document" :readonly="readonly"
    :min-scale="0.05" :max-scale="20" :min-node-size="6" :max-node-size="4800"
    auto-fit style="height: 560px" @change="document = $event.document" />
</template>

Component API

Prop / eventDescription
:dataExternal document replacement. Echoing @change back into :data is safe and does not emit again.
:readonlyDisable editing; preserve the document, view, selection, and history.
:gridSizeBackground grid size in px.
:preserveSelectionKeep the current selection across data-driven reloads when possible.
:autoFitFit the view to content once the editor reports a measurable size.
:history / :historyLimitLimit retained snapshots. Disabling history clears it; reenabling starts from the current document.
:keyboardShortcuts'mindmap' (default): Tab adds a child, Enter adds a sibling, F2/Space/typing edits. 'basic': Enter edits and Tab moves focus.
:snapGuidesSnap dragged nodes to other nodes' edges and centres; hold Alt to bypass (default true).
:minimapShow the overview minimap in the canvas corner. It is pointer-only, aria-hidden, and hides below 480px wide (default true).
:autoLayoutRe-run the current tree or radial layout after keyboard or handle insertions, in the same undo step (default false).
:minScale / :maxScaleCamera bounds. Defaults are 0.35 and 3. Pass both ends. This demo uses 0.05 and 20. Omitting one end on a later update keeps that end's current value. An invalid pair (missing, non-finite, non-positive, or min not below max) falls back to the whole default pair.
:minNodeSize / :maxNodeSizeResizable-node sides. Defaults are 56 and 420. Pass both ends. This demo uses 6 and 4800. Junctions stay 28. The same omit-one-end and invalid-pair rules apply. Changing the bounds later does not resize nodes already on the canvas.
@changeDocument mutations and camera changes. Pan and zoom fire change as well as viewport. Pan and zoom are not undoable.
@select / @viewport / @connectSelection, camera, and edge-added events. viewport is the camera event. connect fires for every added edge, not only edges created with the pointer.
@readyEmitted once with the underlying VdFlowchart core instance.

Ports

Edges attach on the four cardinal ports only: top, right, bottom, and left. Any other port name is dropped. When a port is omitted, from falls back to right and to falls back to left, unless autoPort aims each end at the other node.

Keyboard shortcuts

With the canvas focused and the default keyboard-shortcuts="mindmap". Home, End, and Cmd/Ctrl+C/X/V work in basic as well. Copy, cut, and paste are ignored while a field is being edited.

KeysAction
Arrow keysSelect the nearest node in that direction
Home / EndSelect the first or last visible node in document order
Shift+ArrowSelect a connection on that side (repeat to cycle)
Enter, F2, or typing on a connectionEdit the connection label (or double-click it)
Shift+click, Shift+dragAdd nodes to the selection, or select with a box
Cmd/Ctrl+ASelect all nodes
Cmd/Ctrl+C / X / VCopy, cut, or paste the selection
Cmd/Ctrl+/Collapse or expand the branch (or click its badge)
Cmd/Ctrl + ] / [Bring forward / send backward (add Shift for front / back)
Cmd/Ctrl+LLock or unlock the selected node(s)
TabAdd a child node and edit it
Enter / Shift+EnterAdd a sibling below / above and edit it
F2, Space, or start typingEdit the label
Enter while editingSave the label (Shift+Enter adds a new line)
Tab while editingSave and add a child
Alt+ArrowNudge the selection one grid step (add Shift for 1 px)
Alt while draggingTurn off alignment snapping for that drag
Delete / BackspaceDelete the selection (a single node selects its parent)
Cmd/Ctrl+DDuplicate the selection
Cmd/Ctrl+Z, Shift+Cmd/Ctrl+ZUndo, redo
Cmd/Ctrl + = / - / 0Zoom in, out, to 100%
Shift+1Fit the diagram to the view
EscCancel editing, then the active tool, then deselect
Shift+Tab, or Esc then TabLeave the canvas
?Show every shortcut in the editor

A node and its connection undo as one step, and naming a node you just added joins that step. Use keyboard-shortcuts="basic" when Tab must always move focus: Enter or F2 then edits a label and Ctrl/Cmd+Enter saves it.

Accessibility

The canvas is a keyboard surface (tabindex="0"). Arrow keys, Home, and End move the selection when the canvas itself is focused. Graph outline lists nodes and connections behind labelled Edit and Connect controls. Press ? for the shortcut dialog. The minimap is pointer-only (click and drag) and aria-hidden, so it is not a keyboard or screen-reader control; use the canvas keys and Graph outline instead. These notes describe the controls that ship. They are not a WCAG conformance claim.

Node Types

TypeUse
rounded-rectPrimary flow step
rectSharp process block
diamondDecision
circleStart or end state
textboxNotes or descriptive payload
labelFree text annotation
junctionBranch or merge point. Stays 28×28. Node-size bounds do not resize it.

Events

EventDescription
changeA document mutation or a camera change. The payload includes reason and document. Resize completion uses reason node:resize. Pan and zoom also emit change; they are not history entries.
selectSelection changed. The payload carries the primary selection snapshot and nodeIds for every selected node.
viewportThe camera event. The payload includes reason, viewport (x, y, and scale to four decimal places), and document. fitNode uses reason viewport:fit-node.
connectAn edge was added. Pointer drags, handle clicks, keyboard insertion, Graph outline, and addEdge all emit it. It is not limited to pointer-created edges.
historyCore only: editor.on('history', …) with reason, canUndo, and canRedo. The Vue component does not emit history. Read canUndo() and canRedo() from the template ref.

Exposed methods (template ref)

MethodDescription
undo() / redo()Step through the whole-document history.
canUndo() / canRedo()Whether the template ref can step backward or forward. False when history is empty or disabled.
fitNode(nodeId, padding?)Frame one visible node. Padding is screen pixels and defaults to 48. Unknown or hidden nodes do nothing. Also available as getInstance().fitNode().
layout(mode?)Auto-arrange nodes — exactly three modes: 'tree', 'radial', or 'grid' (default 'tree'). The toolbar select mirrors the active mode.
setNodeColor(id, color) / setEdgeColor(id, color)Apply one of the 12 theme-adaptive color presets (FLOWCHART_COLOR_PRESETS) or a custom CSS color override ({ fill, stroke, textColor } on nodes; CSS color string on edges). Pass 'default' or null to reset.
setSelectionColor(color) / clearSelectionColor()Color or reset the active selection (single node, multi-node selection, or edge) in a single undoable step.
bringToFront() / bringForward() / sendBackward() / sendToBack()Reorder the active selection (or an explicit node/edge id) in the SVG stacking layer and serialized document order.
alignNodes(alignment) / distributeNodes(axis)Align multi-selected nodes ('left' | 'center' | 'right' | 'top' | 'middle' | 'bottom') or distribute 3+ nodes ('horizontal' | 'vertical').
setNodeLocked(id?, locked?) / toggleNodeLocked(id?)Lock or unlock nodes against dragging, resizing, nudging, inline editing, and deletion.
exportSvg(options?)Serialize the visible diagram to a cropped, standalone <svg> string with inlined colors.
getInstance()The underlying core: fitView(), zoomTo(), fitNode(), toJSON(), load(), canUndo(), canRedo(), addNode(), addEdge(), insertBranchNode(), and the rest of the core API.