A simple integer-based implementation of IGridConstraintProvider<T>.
Examples
Enabling grid snapping
const snapContext = new GraphSnapContext()
const gridInfo = new GridInfo(50, 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.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
gridInfo,
new GridRenderer(),
)
Type Parameters
- T
- The type of the items.
Type Details
- yFiles module
- view
Constructors
Properties
Gets or sets the grid info that describes the geometry of the grid.
Property Value
The grid info.
Gets the grid origin.
Gets the grid height.
Gets the grid width.
Methods
snapToGrid
(context: IInputModeContext, item: T, location: IMutablePoint, xSnapPolicy: SnapPolicy, ySnapPolicy: SnapPolicy) : booleanPerforms the actual snapping to grid coordinates.
Parameters
options - Object
A map of options to pass to the method.
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.