Interface for classes that can snap coordinates of items of a specific type to a grid.
Examples
Enabling grid snapping
const snapContext = new GraphSnapContext()
const gridInfo = new GridInfo(50)
snapContext.nodeGridConstraintProvider = new GridConstraintProvider(gridInfo)
snapContext.bendGridConstraintProvider = new GridConstraintProvider(gridInfo)
snapContext.portGridConstraintProvider = new GridConstraintProvider(gridInfo)
snapContext.gridSnapType = GridSnapTypes.GRID_POINTS
graphEditorInputMode.snapContext = snapContext
Note that the grid visualization has to be enabled separately
graphComponent.backgroundGroup.addChild(new GridVisualCreator(gridInfo))
Type Parameters
- T
- The type of the items this class can snap
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.input.IGridConstraintProvider
See Also
Properties
Gets the canonical origin of the grid.
Methods
snapToGrid
(context: IInputModeContext, item: T, location: IMutablePoint, xSnapPolicy: SnapPolicy, ySnapPolicy: SnapPolicy) : booleanPerforms the actual snapping to grid coordinates.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The context in which the snapping should occur.
- item - T
- The item of which the coordinates should be snapped.
- location - IMutablePoint
- The coordinates to snap.
- xSnapPolicy - SnapPolicy
- The policy for the x coordinate.
- ySnapPolicy - SnapPolicy
- The policy for the y coordinate.
Returns
- ↪boolean
- Whether the point has been snapped.
Static Methods
Creates an implementation of the interface IGridConstraintProvider<T> from the given definition.
Remarks
Parameters
A map of options to pass to the method.
- snapToGrid - function(IInputModeContext, T, IMutablePoint, SnapPolicy, SnapPolicy):boolean
Performs the actual snapping to grid coordinates.
This property holds the implementation for snapToGrid.
- horizontalGridWidth - number
Gets the canonical grid width in horizontal direction.
This property holds the implementation for horizontalGridWidth.
- verticalGridWidth - number
Gets the canonical grid width in vertical direction.
This property holds the implementation for verticalGridWidth.
- gridOrigin - Point
Gets the canonical origin of the grid.
This property holds the implementation for gridOrigin.
Returns
- ↪IGridConstraintProvider<T>
- An instance of the IGridConstraintProvider<T> interface based on the given definition.