Renders a diagram into container and returns a DiagramApi. Throws a TypeError when container is not an element or options is not an object.
diagramDefinition
The widget definition (name BirchDiagram, tag birchui-diagram, factory and the 11 events) for the adapters' generic factories. See Use it in your framework.
DIAGRAM_EVENT_NAMES
The list of event names.
diagramStyles
The stylesheet as a string.
BUILT_IN_TYPES, BUILT_IN_SHAPES, FOUR_PORTS
Built-in type names, their default sizes and shapes, and the default port set.
Pass options to createDiagram, or change them later with update(partial). All options are optional. An invalid value logs one console warning and the default is used.
Subscribe with on(event, listener). A listener that throws is caught and reported with console.error, so it never breaks the diagram. In framework adapters the same events are on… props (React, Solid), kebab-case listeners (Vue), outputs (Angular), on handlers of the Svelte action, or kebab-case CustomEvents on a custom element.
Event
Payload
When
ready
{ api }
Once, in a microtask after createDiagram returns.
nodeClick
{ node, point, domEvent }
A node is clicked.
nodeDoubleClick
{ node, point, domEvent }
A node is double-clicked (the label editor also opens unless read-only).
edgeClick
{ edge, point, domEvent }
An edge is clicked.
selectionChange
{ nodes, edges }
The selection changed.
nodesChange
{ changes, source }
Nodes were added, removed, moved, resized or updated.
edgesChange
{ changes, source }
Edges were added, removed or updated.
connect
{ edge, source, target, isReconnect }
The user created or reconnected an edge.
viewportChange
{ viewport }
The view was panned or zoomed.
contextMenu
{ target, node?, edge?, point, domEvent }
Right-click on a node, an edge or the canvas. Listening suppresses the browser menu.
historyChange
{ canUndo, canRedo, undoLabel?, redoLabel? }
The undo history changed, including when it is cleared.
changes entries are { type, id, before?, after? } with type'add', 'remove', 'move', 'resize' or 'update' (edges: 'add', 'remove' or 'update'). source is 'user', 'api', 'history' (undo and redo) or 'layout'. point is in diagram units. Loading a document with setNodes, setEdges, fromJSON or update({ nodes, edges }) emits historyChange only.
The root element has the class lq-diagram, plus lq-theme-light, lq-theme-dark or lq-theme-auto when theme is set, lq-diagram--readonly, lq-diagram--list, lq-diagram--overview and lq-diagram--connecting while those states apply. Nodes have lq-diagram-node and lq-diagram-node--<type>, plus --selected, --container, --collapsed, --valid-target and --invalid-target; HTML template wrappers are lq-diagram-html-node. Theme with the shared --lq-* tokens and diagram tokens such as --lq-diagram-accent, --lq-diagram-node-bg, --lq-diagram-node-border, --lq-diagram-edge, --lq-diagram-grid-color, --lq-diagram-guide and --lq-diagram-selection. See the shared theming guide.