process-flowchart-js: Process Flowchart (a diagram editor)
The diagram demo: no backend, no network calls beyond its own files. A
<vn-diagram> with a <vn-diagram-palette> beside it and a
<vn-diagram-toolbar> above it, over the flowchart of
an order-handling process (20 shapes in two lanes, Sales and Warehouse, and
20 connectors) loaded from plan.json through
VanillaDiagramStaticDataManager, or a generated plan of 1,000 to 100,000
shapes. See
docs/vanilla-diagram/00-index.md and
docs/vanilla-diagram-toolbar/00-index.md.
What it shows
- The palette, linked by id.
<vn-diagram-palette diagram="flow" sets="basic flowchart">shows the eight basic shapes (group, a container, among them), theflowchartsetapp.jsregisters, then the three connector kinds. Drag a tile onto the canvas, or click it (or focus it and press Enter) to add the shape in the middle of the view. The connector buttons set the kind the next connector is drawn with. Itsswatchesattribute gives each shape its own colour slot (rectangle:col1...database:col9), so every tile shows and adds in that colour, which the theme picks. - A custom symbol set.
app.jsregistersflowchartwithVanillaDiagramElement.registerSymbolSet():document(a page with a wavy bottom) anddata(a parallelogram) are declarative, an SVG path of the node's size;database(a cylinder) is drawn by arendercallback that paints with the theme's tokens. The data symbols move their left and right ports onto the slanted sides.laneis a container (container: true): a frame with its label in a band along the top, 7% of its height up to 40 px. - Lanes.
plan.jsongathers the process into two lanes, Sales and Warehouse: each step names its lane as itsparent. The lanes draw under the connectors; a click on a step selects the step, a click on a lane's label or border selects the lane, and a drag inside a lane draws a rubber band. Moving a lane moves its steps; a step dropped in the other lane joins it, dropped outside both leaves them; a shape dropped from the palette into a lane joins it. Resizing a lane stops at its steps; deleting it deletes them. Undo takes each back in one step. - Elbows around shapes. The elbow connectors route around the other
shapes (
avoid-shapesis on by default): drag a shape across a connector and, at the release, the connector goes around it; drag it away and the connector straightens. The lanes aren't in the way. - Editing. Select by click, Ctrl-click, Shift-click or a rubber band;
drag to move, the eight handles to resize, both snapping to the 16px grid
(
grid-size="16") and to guides along the other shapes (Alt turns it off); hover a shape and drag from a port to another shape to connect them, or click one port and then another; drag a selected connector's end to reconnect it, and a selected elbow's segment handles to reshape it; turn a selected shape by its rotation handle above it (Shift: 15 degree steps) or withRand Shift +R; double-click a shape or a connector (or press Enter or F2) to edit its text or label; Ctrl+C, Ctrl+X, Ctrl+V and Ctrl+D copy, cut, paste and duplicate; Delete removes. Zoom with the wheel or a pinch, pan with a right- or middle-button drag. With the canvas focused, the keys select, nudge, resize and connect (the component README lists them). - The toolbar, written in markup.
<vn-diagram-toolbar diagram="flow">(thevanilla-diagram-toolbarcomponent, its own script) spans the page, as the grid's and the Gantt's toolbars do.index.htmllists its items: the status line at the left, which shows each change's label fromvn-diagram-changed(setStatusMessage()); then the standard commands, which undo and redo, zoom, delete, bring to front and send to back, colour the selection from the colour menu (a colour box and a label per slot), change the selected connectors' type and arrows from the connector type and arrows menus, and download the drawing asdiagram.svganddiagram.png, each following the diagram's state; last, a command of the app's own, Reset, asecondarybutton with a label and an iconapp.jsregisters (registerIcon()), whichregisterCommand('reset', ...)runs: it builds the plan the page started with again (plan.json, or the generated plan of?shapes=), gives the diagram a new data manager of the selected server's kind holding it (setDataManager()) and loads it (loadDiagramAsync()), so every edit is gone and the undo history is cleared (the diagram's busy overlay says it is loading; the status line says how it ended). Reset's tooltip is a label of the app's own (setMessages()), anddisabled-when="busy"turns it off while the diagram is busy (a load, its own included, Tidy up or an export). Tidy up, after the status line, is the standardlayoutcommand with a label: it arranges the diagram as layers flowing down, the lanes inside out (one undo step), then zooms to fit. Each moved connector gets the ports that face each other, and the note, Inventory, Purchase order, Invoice and Orders stay beside the step they hang off; a second Tidy up moves nothing. While it runs the diagram is busy: the canvas takes no input (no edit, selection, pan or zoom), Tidy up and the zoom buttons are off, and on a large plan a spinner says "Arranging shapes..." until the fitted drawing is final. - Large diagrams. The Size selector (or
?shapes=1000,10000,100000) swaps the order process for a generated plan: lanes of 100 shapes (the lane and 99 steps and decisions in 9 rows of 11), each row joined by elbows, a decision's Yes along the row and its No down to the step below, the last of a row down to the next. Up to 10,000 shapes the zoom goes down to 0.02 (initializeDiagram({ minZoom })), so the load fits the whole plan in view and draws all of it; at 100,000 the default limit, 0.1, keeps the view to a part of the plan. Only what is in view is drawn; below zoom 0.4 text and labels hide; the load builds the model in slices behind the busy overlay; the elbows out of view route in the background. Ctrl+A, the toolbar, the slow server and the failed save work at every size. - Screen readers. The status line isn't the only one listening: the
diagram's own live region says each keyboard selection and each change,
NandPwalk a shape's connectors andJfollows one, and a hidden outline lists the shapes lane by lane with their connections (up to 10,000). - A slow server and a failed save. The Server selector swaps in a
sample-defined
SlowDataManager, which extends the static manager with a 1.2s delay per save; the status line says Saving... while saves are pending (hasPendingSaves()). Fail the next save, beside the selector, makes its nextsaveChanges()reject: the diagram reverts that change and every one made after it, restores the undo history, and firesvn-diagram-save-failed, which the status line reports. Switching servers starts the new manager fromtoJSON(), so the drawing carries over. - Fifteen themes. The Theme selector sets a theme on the diagram and
the palette (the toolbar, with no
themeof its own, follows the diagram's) and swaps the page chrome's app theme. Under Built in are the diagram's fourteen themes, the grid's Default, Material, Fiori, Carbon, Glow, Fluent and Apple, light and dark, each with its own colours for the ten slots; with them the page takes the shared app theme (../_common/themes/app-<theme>.css). - A theme of the app's own. Ledger, under This app's own, is the
grid's Ledger look, which the diagram doesn't ship:
app.jsregistersthemes/vn-diagram-ledger.csswithVanillaDiagramElement.registerTheme('ledger', ...), so the diagram, the palette and the toolbar all resolve the name to it, and loads the page chrome fromthemes/app-ledger.cssin place of a shared app theme. Warm paper and dark ink, the ruling blue as the grid's dots, the red margin line as the snap guides, oxblood for the selection, serif type, a double rule under the header.
Files
| File | |
|---|---|
index.html |
The header with the theme, size and server selectors and the "Fail the next save" button, the toolbar and its items (Tidy up, the standard commands, Reset), the palette and the diagram |
app.js |
The flowchart symbols (the lane container among them), the generated plans, ?shapes= and the zoom limit up to 10,000 shapes, the slow manager, the status line, the Reset command, the Ledger theme's registration, the theme switch, the load |
themes/vn-diagram-ledger.css |
The app's own diagram theme, Ledger: every --vn-diagram-* token, for the diagram, the palette and the toolbar |
themes/app-ledger.css |
The page chrome under Ledger, in place of a shared app theme |
plan.json |
The order-handling flowchart in its two lanes: a version 1 diagram document, as toJSON() returns |
styles.css |
Layout; colours come from the app theme (shared, or themes/app-ledger.css), the toolbar's from the diagram's theme |
Running it
Serve the repository root (npx http-server . -p 4173) and open
/samples/process-flowchart-js/. In the build, dist/samples/process-flowchart-js/
loads vanilla-diagram.bundle.js and vanilla-diagram-toolbar.bundle.js from
dist/vanilla-components/latest/.