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
See Also
Constructors
Initializes a new instance of the SnapContext class.
Parameters
A map of options to pass to the method.
- visualizeSnapResults - boolean
- A value indicating whether to visualize the snap results. This option sets the visualizeSnapResults property on the created object.
- snapDistance - number
- The global snap distance, which is the maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap. This option sets the snapDistance property on the created object.
- gridSnapType - GridSnapTypes
- The type of the grid snapping that should be performed. This option sets the gridSnapType property on the created object.
- gridSnapDistance - number
- The GridSnapDistance. This option sets the gridSnapDistance property on the created object.
- enabled - boolean
- A value indicating whether this SnapContext is enabled. This option sets the enabled property on the created object.
Properties
Gets the current input mode context.
Property Value
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, 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(),
)
See Also
Gets whether the context is initialized.
Remarks
Gets or sets a value indicating whether this instance is currently initializing.
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 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.
Property Value
true
if the results should be visualized, false
otherwise.See Also
Methods
Called when a drag has been canceled.
Remarks
Performs cleanup procedures.
Remarks
Helper method used by createSnapResultsModelManager to create the IObjectRenderer<SnapResult> for the SnapResult type.
Returns
- ↪IObjectRenderer<SnapResult>
- An instance that can install SnapResults in a 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
A map of options to pass to the method.
- canvasComponent - 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 reference visualizations and return the unchanged coordinates.
Returns
- ↪Point
- The adjusted coordinates or the unchanged coordinates if snapping has been temporarily disabled by setting
snappingDisabled
totrue
.
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 references.
Remarks
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.
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 reference visualizations and return the unchanged coordinates.
Returns
- ↪Point
- The adjusted coordinates or 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 collect-snap-results 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) : PointChooses 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
- ↪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.
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
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.
Occurs when this instance has been initialized.
See Also
Occurs when this instance is about to be initialized.