Interface: DiagramCanvasHandle
Imperative methods of a DiagramCanvas, reached through its ref.
Methods
clientToDiagram()
clientToDiagram(clientX, clientY): object;
Client px → diagram coordinates.
Parameters
clientX
number
clientY
number
Returns
object
x
x: number;
y
y: number;
exportPng()
exportPng(options?): Promise<Blob | null>;
scale default 2; null without a model.
Parameters
options?
CanvasExportOptions & object
Returns
Promise<Blob | null>
exportSvg()
exportSvg(options?): string | null;
null without a model.
Parameters
options?
Returns
string | null
fitView()
fitView(options?): void;
Fits the whole active view into the canvas.
Parameters
options?
duration?
number
Returns
void
focusNode()
focusNode(id, options?): void;
Pans (keeps zoom) so the node is centred. onlyIfHidden: no-op when ≥ 60% of it is visible.
Parameters
id
string
options?
duration?
number
onlyIfHidden?
boolean
Returns
void
focusNodes()
focusNodes(ids, options?): void;
Fits the given nodes (all when empty), optionally capping the zoom; padding in px.
Parameters
ids
string[]
options?
duration?
number
maxZoom?
number
padding?
| number
| {
bottom?: number;
left?: number;
right?: number;
top?: number;
}
Space to keep free around the nodes, screen px: one number for every side, or the sides an overlay covers (each at least the canvas's own padding on that side).
Returns
void
getGeometry()
getGeometry(): DiagramGeometry | null;
Geometry as drawn now (after drags), active view.
Returns
DiagramGeometry | null
getNodeClientRect()
getNodeClientRect(id): DOMRect | null;
Screen rectangle (client px) of a node as drawn now, or null. For overlays (note editor).
Parameters
id
string
Returns
DOMRect | null
getSelection()
getSelection(): string[];
Ids of the nodes selected in the canvas (editable mode).
Returns
string[]
getViewport()
getViewport(): Viewport;
The current pan and zoom.
Returns
placeNodes()
placeNodes(positions): void;
Writes node positions (e.g. a new note placed where the user clicked) and reports one 'move' (editable); read-only canvases move the nodes locally.
Parameters
positions
Record<string, {
x: number;
y: number;
}>
Returns
void
print()
print(options?): void;
Prints the active view (a hidden iframe with the standalone SVG).
Parameters
options?
Returns
void
runAutoLayout()
runAutoLayout(scope?): Promise<Layout | null>;
Runs ELK for the active view and reports one 'auto-layout' change. Resolves to the new layout.
Parameters
scope?
Returns
Promise<Layout | null>
setNodeSettings()
setNodeSettings(ids, settings): void;
Pin / collapse through the layout (reports a 'settings' change).
Parameters
ids
string[]
settings
Returns
void
setSelection()
setSelection(ids): void;
Replaces the canvas selection ([] clears it), e.g. when the editor's cursor moves on.
Parameters
ids
string[]
Returns
void
setViewport()
setViewport(viewport, options?): void;
Pans and zooms to viewport, animated over duration ms when given.
Parameters
viewport
options?
duration?
number
Returns
void
zoomIn()
zoomIn(): void;
Zooms in one step around the centre.
Returns
void
zoomOut()
zoomOut(): void;
Zooms out one step around the centre.
Returns
void