Manages interactive snapping of elements to other elements during drag operations like movements.
Remarks
- 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.
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.input.SnapContext
See Also
Constructors
Initializes a new instance of the SnapContext class.
Properties
Gets the current input mode context.
Gets or sets a value indicating whether this SnapContext is enabled.
Gets or sets the type of the grid snapping that should be performed.
Remarks
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))
See Also
Gets whether the context is initialized.
Remarks
Gets or sets a value indicating whether this instance is currently initializing.
Gets the original location of the mouse at the time the gesture was initialized.
See Also
Gets or sets the global snap distance, which is the maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap.
Remarks
The distance is interpreted in view coordinates.
The default is 5.0d
See Also
Gets the collection of SnapResults.
Remarks
Gets or sets a value indicating whether to visualize the snap results.
Methods
Called when a drag has been canceled.
Remarks
Performs clean up procedures.
Remarks
Helper method used by createSnapResultsModelManager to create the ICanvasObjectDescriptor for the SnapResult type.
Returns
- ↪ICanvasObjectDescriptor
- An instance that can install SnapResults in a CanvasComponent.
Helper method that creates the a CollectionModelManager<T> that can be used to present the current SnapResults in the provided CanvasComponent.
Parameters
A map of options to pass to the method.
- canvas - CanvasComponent
- The control to initialize the CollectionModelManager<T> with.
Returns
- ↪CollectionModelManager<SnapResult>
- The model manager that manages the visual representation of the SnapResults.
Called when a drag has been successfully finished.
Remarks
Parameters
A map of options to pass to the method.
- newLocation - Point
- The current mouse location.
- snappingDisabled - boolean
- If set to
true
snapping is temporarily disabled. This will remove the snap line visualizations and return a SnapState with the unchanged coordinates and the NOT_SNAPPED snapType.
Returns
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.
Remarks
snappingDisabled
parameter set to true
.Parameters
A map of options to pass to the method.
Collects a list of snap lines.
Remarks
Snap lines represent possible horizontal or vertical lines 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.
Handles a move.
Remarks
snappingDisabled
has to be set to true
.Parameters
A map of options to pass to the method.
- newLocation - Point
- The current mouse location.
- snappingDisabled - boolean
- If set to
true
snapping is temporarily disabled. This will remove the snap line visualizations and return a SnapState with the unchanged coordinates and the snapType NOT_SNAPPED.
Returns
- ↪SnapState
- The adjusted coordinates and how they have been adjusted. The unchanged coordinates if snapping has been temporarily disabled by setting
snappingDisabled
totrue
.
Called by IInputMode implementations when an interactive drag is started.
Remarks
Parameters
A map of options to pass to the method.
- 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.
Raises the cleanUp event.
Parameters
A map of options to pass to the method.
- evt - InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Raises the CollectSnapResults event.
Parameters
A map of options to pass to the method.
- evt - CollectSnapResultsEventArgs
- The CollectSnapResultsEventArgs instance containing the event data.
Raises the Initialized event.
Parameters
A map of options to pass to the method.
- evt - InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Raises the Initializing event.
Parameters
A map of options to pass to the method.
- evt - InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
processSnapResults
(snapResults: List<SnapResult>, originalLocation: Point, newLocation: Point) : SnapStateChooses the current SnapResults from a temporary list.
Remarks
Parameters
A map of options to pass to the method.
- 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.
Returns
- ↪SnapState
- The adjusted coordinates and how they have been adjusted.
Helper method that wraps the given context
so that a lookup query on the wrapped context for the SnapContext type yields this instance.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The context to wrap and delegate all calls to.
Returns
- ↪IInputModeContext
- A modified instance that yields this instance if it is queried for the SnapContext type.
Events
Occurs when this instance has been cleaned up.
See Also
Event Registration
addCleanedUpListener(function(this, InputModeEventArgs):void)
Event Deregistration
removeCleanedUpListener(function(this, InputModeEventArgs):void)
Signature Details
function(sender: this, evt: InputModeEventArgs)
Parameters
- sender - this
- The source of the event.
- evt - InputModeEventArgs
- An object that contains the event data.
Occurs while moving items and handles.
Remarks
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.
Event Registration
addCollectSnapResultsListener(function(this, CollectSnapResultsEventArgs):void)
Event Deregistration
removeCollectSnapResultsListener(function(this, CollectSnapResultsEventArgs):void)
Signature Details
function(sender: this, evt: CollectSnapResultsEventArgs)
Parameters
- sender - this
- The source of the event.
- evt - CollectSnapResultsEventArgs
- An object that contains the event data.
Occurs when this instance has been initialized.
See Also
Event Registration
addInitializedListener(function(this, InputModeEventArgs):void)
Event Deregistration
removeInitializedListener(function(this, InputModeEventArgs):void)
Signature Details
function(sender: this, evt: InputModeEventArgs)
Parameters
- sender - this
- The source of the event.
- evt - InputModeEventArgs
- An object that contains the event data.
Occurs when this instance is about to be initialized.
See Also
Event Registration
addInitializingListener(function(this, InputModeEventArgs):void)
Event Deregistration
removeInitializingListener(function(this, InputModeEventArgs):void)
Signature Details
function(sender: this, evt: InputModeEventArgs)
Parameters
- sender - this
- The source of the event.
- evt - InputModeEventArgs
- An object that contains the event data.