Geometry helpers for computing node port positions and converting between
screen and canvas coordinate spaces (accounting for zoom and pan).
- Source:
Methods
(static) canvasToScreen(canvasX, canvasY, canvasRect, zoom, pan) → {Object}
Convert a canvas point into screen (viewport) coordinates.
Parameters:
| Name | Type | Description |
|---|---|---|
canvasX |
number | Horizontal canvas coordinate. |
canvasY |
number | Vertical canvas coordinate. |
canvasRect |
Object | Canvas bounding rectangle with `left` and `top` offsets. |
zoom |
number | Current zoom factor. |
pan |
Object | Current pan offset with `x` and `y` in canvas units. |
- Source:
Returns:
Point `{ x, y }` in screen coordinates.
- Type
- Object
(static) computeFitToScreen(nodes, viewport, paddingopt) → {Object|null}
Compute the zoom and pan that fit every node within the viewport, centered and
with a margin. Zoom is clamped to [ZOOM_MIN, ZOOM_MAX]; pan is derived from the
canvas mapping `screen = (canvas + pan) * zoom` so the node bounding box's
center lands at the viewport center.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
nodes |
Array.<Object> | Workflow nodes with numeric `x`, `y` and a `type`. | ||
viewport |
Object | Visible canvas size in screen pixels. | ||
padding |
number |
<optional> |
60 | Screen-pixel margin to leave on every side. |
- Source:
Returns:
The fit transform, or null when there are no nodes.
- Type
- Object | null
(static) getNodeSize(node) → {Object}
Return the rendered pixel size of a node, which depends on its type: filter
diamonds and start/end control nodes are smaller than regular components.
Parameters:
| Name | Type | Description |
|---|---|---|
node |
Object | A workflow node with a `type` field. |
- Source:
Returns:
The node's width and height in canvas pixels.
- Type
- Object
(static) getPortPosition(node, portType, nodeWidthopt, nodeHeightopt) → {Object}
Compute the canvas coordinates of a node's input or output port.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
node |
Object | Node with numeric `x` and `y` top-left canvas coordinates. | ||
portType |
string | Which port to locate; `'output'` for the right edge, otherwise the left edge. | ||
nodeWidth |
number |
<optional> |
160 | Node width in canvas units. |
nodeHeight |
number |
<optional> |
80 | Node height in canvas units. |
- Source:
Returns:
Point `{ x, y }` in canvas coordinates at the vertical center of the node's edge.
- Type
- Object
(static) screenToCanvas(screenX, screenY, canvasRect, zoom, pan) → {Object}
Convert a screen (viewport) point into canvas coordinates.
Parameters:
| Name | Type | Description |
|---|---|---|
screenX |
number | Horizontal screen coordinate (e.g. from a mouse event). |
screenY |
number | Vertical screen coordinate. |
canvasRect |
Object | Canvas bounding rectangle with `left` and `top` offsets. |
zoom |
number | Current zoom factor. |
pan |
Object | Current pan offset with `x` and `y` in canvas units. |
- Source:
Returns:
Point `{ x, y }` in canvas coordinates.
- Type
- Object