C

SnapContext

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.

Parameters

Properties

Gets the current input mode context.
protectedreadonlyfinal

Property Value

The current input mode context if this instance isInitialized or isInitializing, otherwise null.
Gets or sets a value indicating whether this SnapContext is enabled.
final

Property Value

true if enabled; false otherwise.

See Also

Developer's Guide
Gets or sets the GridSnapDistance.
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.
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 = snapContext

Note that the grid visualization has to be enabled separately

graphComponent.renderTree.createElement(
  graphComponent.renderTree.backgroundGroup,
  gridInfo,
  new GridRenderer(),
)

See Also

API
nodeGridConstraintProvider, bendGridConstraintProvider, portGridConstraintProvider
Gets a value indicating whether the context is initialized.
The context is initialized between the calls to dragInitialized and dragFinished or cancelDrag.
readonlyfinal
Gets a value indicating whether this instance is currently initializing.
readonlyfinal

Property Value

true if this instance is initializing; false otherwise.

See Also

API
initialized, initializing, isInitialized
Gets the original location of the mouse at the time the gesture was initialized.
readonlyfinal

Property Value

The original location.

See Also

API
initializeDrag
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.

The distance is interpreted in view coordinates.

The default is 5.0d

final

See Also

API
snapDistance
Gets the collection of SnapResults.
This collection is automatically updated during moving the mouse.
readonlyfinal
Gets or sets a value indicating whether to visualize the snap results.
final

Property Value

true if the results should be visualized, false otherwise.

See Also

API
createSnapResultsModelManager

Methods

Called when a drag has been canceled.
Clears all temporary lists and sets isInitialized back to false, as well as performs cleanUp and finally triggers the cleaned-up event.
Performs cleanup procedures.
This is called in response to cancelDrag and dragFinished as well as initially during initializeDrag.
protected
Helper method used by createSnapResultsModelManager to create the IObjectRenderer<SnapResult> for the SnapResult type.
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.
Called when a drag has been successfully finished.
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 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 snappingDisabled to true.
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

mouseLocation: Point
The actual mouse location.
finalLocation: Point
The final snap location that has been used by the client code for the move.
Collects a list of snap references.

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.
This 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 snappingDisabled to true.
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.
Raises the cleanUp event.
protected

Parameters

evt: InputModeEventArgs
The InputModeEventArgs instance containing the event data.
Raises the collect-snap-results event.
protected

Parameters

evt: CollectSnapResultsEventArgs
The CollectSnapResultsEventArgs instance containing the event data.
Raises the initialized event.
protected

Parameters

evt: InputModeEventArgs
The InputModeEventArgs instance containing the event data.
Raises the initializing event.
protected

Parameters

evt: InputModeEventArgs
The InputModeEventArgs instance containing the event data.
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.

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.

Events

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.

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.

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.

Properties of

InputModeEventArgs
context: IInputModeContext
Gets the context for the current event.

See Also

API
initializeDrag
Occurs when this instance is about to be initialized.

Properties of

InputModeEventArgs
context: IInputModeContext
Gets the context for the current event.

See Also

API
initializeDrag