Interface: CanvasApi
Defined in: diagram/canvasApi.ts:17
Describes an API to interact with a scrollable graph canvas.
Properties
Property | Modifier | Type | Description |
---|---|---|---|
| Events for the scrollable graph canvas. | ||
| Live state for the current viewport size and transformation. Allows to convert between different canvas coordinate types. This state can be captured to provide freezed state via CanvasMetrics.snapshot. | ||
| Default action on moving pointer with pressed main button. Initial mode is | ||
| Canvas-specific state for rendering graph content (elements, links, etc). | ||
|
| Options for the scale-affecting operations on the canvas. |
Methods
animateGraph()
animateGraph(
setupChanges
,duration?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:149
Starts animation for graph elements and links.
Parameters
Parameter | Type | Description |
---|---|---|
| () => | immediately called function to perform animatable changes on graph |
|
| duration animation duration in milliseconds (default is |
Returns
Promise
<void
>
promise which resolves when this animation ends
Example:
// Animate element movement by 200px (in paper coordinates) on the x-axis
const target = model.getElement(...);
canvas.animateGraph(() => {
const {x, y} = target.position;
target.setPosition(x + 200, y);
});
centerContent()
centerContent(
options?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:67
Changes the viewport such that center of the bounding box for the graph content is aligned to the viewport center.
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<void
>
centerTo()
centerTo(
paperPosition?
,options?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:59
Changes the viewport such that its center is aligned to specified point in paper coordinates.
If no point is specified, aligns the viewport center with the canvas center instead.
Parameters
Parameter | Type |
---|---|
| |
|
Returns
Promise
<void
>
exportRaster()
exportRaster(
options?
):Promise
<string
>
Defined in: diagram/canvasApi.ts:124
Exports the diagram as a rendered raster image (e.g. PNG, JPEG, etc) serialized into base64-encoded data URL.
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<string
>
exportSvg()
exportSvg(
options?
):Promise
<string
>
Defined in: diagram/canvasApi.ts:119
Exports the diagram as a serialized into text SVG document
with <foreignObject>
HTML layers inside.
Exported SVG document would include all diagram content as well as every CSS rule which applies to any DOM element from the diagram content.
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<string
>
focus()
focus():
void
Defined in: diagram/canvasApi.ts:52
Sets the focus on the graph canvas itself to be able to handle keyboard interaction within its layers.
Returns
void
getScale()
getScale():
number
Defined in: diagram/canvasApi.ts:71
Returns the current scale of the graph content in relation to the viewport.
Returns
number
isAnimatingGraph()
isAnimatingGraph():
boolean
Defined in: diagram/canvasApi.ts:131
Returns true
if there is an active animation for graph or links on the canvas;
otherwise false
.
Returns
boolean
See
setPointerMode()
setPointerMode(
value
):void
Defined in: diagram/canvasApi.ts:47
Sets default action on moving pointer with pressed main button.
Parameters
Parameter | Type |
---|---|
|
Returns
void
setScale()
setScale(
value
,options?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:79
Changes the viewport to set specific scale of the graph content.
If pivot
is specified, the viewport is changed as if the canvas was
zoomed-in or zoomed-out at that point of the canvas
(e.g. by mouse wheel or pinch-zoom at the pivot).
Parameters
Parameter | Type |
---|---|
|
|
|
Returns
Promise
<void
>
zoomBy()
zoomBy(
value
,options?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:85
Same as setScale() but relative to the current scale value.
Parameters
Parameter | Type |
---|---|
|
|
|
Returns
Promise
<void
>
See
zoomIn()
zoomIn(
scaleOptions?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:91
Same as zoomBy() with a positive zoom step value.
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<void
>
See
zoomOut()
zoomOut(
scaleOptions?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:97
Same as zoomBy() with a negative zoom step value.
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<void
>
See
zoomToFit()
zoomToFit(
options?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:105
Changes the viewport to fit the whole graph content if possible.
If the diagram is empty, centers the viewport at the middle of the canvas.
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<void
>
See
zoomToFitRect()
zoomToFitRect(
paperRect
,options?
):Promise
<void
>
Defined in: diagram/canvasApi.ts:111
Changes the viewport to fit specified rectangle area in paper coordinates if possible.
Parameters
Parameter | Type |
---|---|
| |
|
Returns
Promise
<void
>