Manages interactive snapping of elements to other elements during drag operations like movements.
Inheritance Hierarchy
Remarks
This class should be used by IInputMode implementations and similar code as follows:
- To initialize the operation initializeDrag needs to be called.
- Method dragInitialized needs to be called after the mode has performed all of its own initialization.
- Then a series of zero or more invocations handleMove needs to be called for each incremental movement of the user's input device.
- After handleMove has been called, the mode should perform the move and report back to the instance by calling the dragged method.
- If the operation is canceled by the user cancelDrag should be called.
- If the operation is finalized the dragFinished method should be called.
See Also
Developer's Guide
API
- snapContext, snapContext, createSnapResultsModelManager
Members
Show:
Constructors
Initializes a new instance of the SnapContext class.
Initializes a new instance of the SnapContext class.
Parameters
Properties
Gets the current input mode context.
Gets the current input mode context.
protectedreadonlyfinal
Property Value
Gets or sets a value indicating whether this SnapContext is enabled.
Gets or sets a value indicating whether this SnapContext is enabled.
final
Property Value
true if enabled; false otherwise.See Also
Developer's Guide
The maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap. The distance is interpreted in view coordinates.
final
Gets or sets the type of the grid snapping that should be performed.
Gets or sets the type of the grid snapping that should be performed.
Determines which grid elements an object should snap to.
conversionfinal
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 = snapContextNote that the grid visualization has to be enabled separately
graphComponent.renderTree.createElement(
graphComponent.renderTree.backgroundGroup,
gridInfo,
new GridRenderer(),
)See Also
readonlyfinal
readonlyfinal
Property Value
true if this instance is initializing; false otherwise.See Also
Gets the original location of the mouse at the time the gesture was initialized.
Gets the original location of the mouse at the time the gesture was initialized.
Gets the collection of SnapResults.
Gets the collection of SnapResults.
This collection is automatically updated during moving the mouse.
readonlyfinal
final
Property Value
true if the results should be visualized, false otherwise.See Also
Methods
Clears all temporary lists and sets isInitialized back to false, as well as performs cleanUp and finally triggers the cleaned-up event.
This is called in response to cancelDrag and dragFinished as well as initially during initializeDrag.
protected
Overridden in
GraphSnapContext.cleanUpHelper method used by createSnapResultsModelManager to create the IObjectRenderer<SnapResult> for the SnapResult type.
Helper method used by createSnapResultsModelManager to create the IObjectRenderer<SnapResult> for the SnapResult type.
createSnapResultsModelManager
(canvasComponent: CanvasComponent): CollectionModelManager<SnapResult>Helper method that creates a CollectionModelManager<T> that can be used to present the current SnapResults in the provided CanvasComponent.
createSnapResultsModelManager
(canvasComponent: CanvasComponent): CollectionModelManager<SnapResult>Helper method that creates a CollectionModelManager<T> that can be used to present the current SnapResults in the provided CanvasComponent.
Parameters
- canvasComponent: CanvasComponent
- The control to initialize the CollectionModelManager<T> with.
Return Value
- CollectionModelManager<SnapResult>
- The model manager that manages the visual representation of the SnapResults.
Clears all temporary lists and sets isInitialized back to false. Also the cleanUp method is invoked and the cleaned-up event is triggered.
Parameters
- newLocation: Point
- The current mouse location.
- snappingDisabled: boolean
- If set to
truesnapping is temporarily disabled. This will remove the snap reference visualizations and return the unchanged coordinates.
Return Value
- Point
- The adjusted coordinates or the unchanged coordinates if snapping has been temporarily disabled by setting
snappingDisabledtotrue.
This method needs to be called by the client IInputMode that initialized this instance after it has performed the actual move operation with the adjusted coordinates after a call to handleMove.
This method needs to be called by the client IInputMode that initialized this instance after it has performed the actual move operation with the adjusted coordinates after a call to handleMove.
Most of the client code implementations will just call this method with the exact location returned by handleMove. This method does not need to be called if snapping has been temporarily disabled by calling handleMove with its
snappingDisabled parameter set to true.Parameters
Snap references represent possible lines, circles, or other references to which a moved item can "snap".
This method is called at the start of MoveInputMode's or HandleInputMode's gesture after all items to be moved or reshaped have been added.
Overridden in
GraphSnapContext.dragInitializedThis method returns the adjusted (mouse) coordinates. It also manages the collection of SnapResults. If snapping should be temporarily (for a mouse move) disabled,
snappingDisabled has to be set to true.Parameters
- newLocation: Point
- The current mouse location.
- snappingDisabled: boolean
- If set to
true, snapping is temporarily disabled. This will remove the snap reference visualizations and return the unchanged coordinates.
Return Value
- Point
- The adjusted coordinates or the unchanged coordinates if snapping has been temporarily disabled by setting
snappingDisabledtotrue.
Called by IInputMode implementations when an interactive drag is started.
Called by IInputMode implementations when an interactive drag is started.
Updates isInitializing, originalLocation, and currentInputModeContext and then triggers the initializing event.
Parameters
- context: IInputModeContext
- The context in which the interactive drag is started.
- originalLocation: Point
- The original location of the mouse.
Throws
- Exception ({ name: 'InvalidOperationError' })
- If this context is already initialized.
Overridden in
GraphSnapContext.initializeDragRaises the cleanUp event.
Raises the cleanUp event.
protected
Parameters
- evt: InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Raises the collect-snap-results event.
Raises the collect-snap-results event.
protected
Parameters
- evt: CollectSnapResultsEventArgs
- The CollectSnapResultsEventArgs instance containing the event data.
Raises the initialized event.
Raises the initialized event.
protected
Parameters
- evt: InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Raises the initializing event.
Raises the initializing event.
protected
Parameters
- evt: InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Chooses the current SnapResults from a temporary list.
Chooses the current SnapResults from a temporary list.
Chooses from a list of possible results the most important ones. Also maintains the collection of snap results.
protected
Parameters
- snapResults: List<SnapResult>
- A temporary list of suggested SnapResults.
- originalLocation: Point
- The point in world coordinates where the mouse move started.
- newLocation: Point
- The current mouse location.
Return Value
- Point
- The adjusted coordinates.
Helper method that wraps the given context so that a lookup query on the wrapped context for the SnapContext type yields this instance.
Helper method that wraps the given
context so that a lookup query on the wrapped context for the SnapContext type yields this instance.Parameters
- context: IInputModeContext
- The context to wrap and delegate all calls to.
Return Value
- IInputModeContext
- A modified instance that yields this instance if it is queried for the SnapContext type.
Overridden in
GraphSnapContext.wrapContextEvents
Occurs when this instance has been cleaned up.
Occurs when this instance has been cleaned up.
Properties of
InputModeEventArgs- context: IInputModeContext
- Gets the context for the current event.
See Also
API
- cleanUp
Occurs while moving items and handles.
Occurs while moving items and handles.
The moving model items must register for this event, preferably in the initializeDrag method of the IDragHandler.
The event handler has to add SnapResults for the moving object to the list. The IDragHandlers of the moved items have to take care themselves whether to add a handler to the list depending on their settings.
Properties of
CollectSnapResultsEventArgs- context: IInputModeContext
- Gets the context for the current event.
- delta: Point
- Gets the vector by which the mouse has been moved since initialization of the snapping process.
- gridSnapDistance: number
- Gets the zoom invariant grid snap distance.
- newLocation: Point
- Gets the new (current) location of the mouse that is going to be manipulated by the snapping process.
- originalLocation: Point
- Gets the original location of the mouse at the beginning of the gesture.
- snapDistance: number
- Gets the zoom invariant snap distance.
Occurs when this instance has been initialized.
Occurs when this instance has been initialized.
Properties of
InputModeEventArgs- context: IInputModeContext
- Gets the context for the current event.
See Also
Occurs when this instance is about to be initialized.
Occurs when this instance is about to be initialized.
Properties of
InputModeEventArgs- context: IInputModeContext
- Gets the context for the current event.