Skip to main content

Home > @jsplumbtoolkit/browser-ui > snapToGrid

snapToGrid() function

Snap the given x,y to a point on the grid defined by gridX and gridY, using the given thresholds to calculate proximity to the grid.

Signature:

export declare function snapToGrid(pos: PointXY, grid: Grid, thresholdX?: number, thresholdY?: number): PointXY;

Parameters

ParameterTypeDescription
posPointXYPosition to transform
gridGridDefinition of the grid
thresholdXnumberDefines how close to a grid line in the x axis a value must be in order to be snapped to it.
thresholdYnumberDefines how close to a grid line in the y axis a value must be in order to be snapped to it.

Returns:

PointXY

The point to which the position was snapped, given the constraints of the grid.