Manages interactive snapping of ILabels to their owner during drag operations like movements.
Remarks
Snapping is enabled for IGraph items by setting an instance of this on the GraphEditorInputMode as labelSnapContext.
This class provides a set of properties to customize the snapping behavior.
IPositionHandler implementations and similar classes can retrieve instances of this class from the IInputModeContext.
Examples
Related Programming Samples
- Snapping
- Shows how to enable snapping (guide lines) for interactive changes.
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.input.LabelSnapContext
See Also
Constructors
Initializes a new instance of the LabelSnapContext class.
Parameters
A map of options to pass to the method.
- collectInitialLocationSnapLines - boolean
Whether this instance should collect snap lines for the initial position of a label. This option sets the collectInitialLocationSnapLines property on the created object.
- collectNodeShapeSnapLines - boolean
Whether this instance should collect six snap lines, two through the center and four through the border sides of the label owner. This option sets the collectNodeShapeSnapLines property on the created object.
- collectOwnNodeDistanceSnapLines - boolean
Whether this instance should collect four snap lines in parallel to the owner's borders at the initial label distance. This option sets the collectOwnNodeDistanceSnapLines property on the created object.
- collectSameOwnerNodeDistanceSnapLines - boolean
Whether this instance should collect snap lines in parallel to the border of the label owner at the distance of other node labels of that owner. This option sets the collectSameOwnerNodeDistanceSnapLines property on the created object.
- collectAllNodeDistanceSnapLines - boolean
Whether this instance should collect snap lines in parallel to the border of the label owner at the distance of other node labels in the graph. This option sets the collectAllNodeDistanceSnapLines property on the created object.
- collectEdgePathSnapLines - boolean
Whether this instance should collect snap lines on the edge path. This option sets the collectEdgePathSnapLines property on the created object.
- collectOwnEdgeDistanceSnapLines - boolean
Whether this instance should collect two snap lines in parallel to the edge path of the label owner at the initial distance of the edge label. This option sets the collectOwnEdgeDistanceSnapLines property on the created object.
- collectSameOwnerEdgeDistanceSnapLines - boolean
Whether this instance should collect snap lines in parallel to the edge path of the label owner at the distances of all edge labels of that owner. This option sets the collectSameOwnerEdgeDistanceSnapLines property on the created object.
- collectAllEdgeDistanceSnapLines - boolean
Whether this instance should collect snap lines in parallel to the edge path of the label owner at the distance of other edge labels in the graph. This option sets the collectAllEdgeDistanceSnapLines property on the created object.
- snapNodeLabels - boolean
Whether this context will automatically snap the node labels to snap lines. This option sets the snapNodeLabels property on the created object.
- snapEdgeLabels - boolean
Whether this context will automatically snap the edge labels to snap lines. This option sets the snapEdgeLabels property on the created object.
- snapPortLabels - boolean
Whether this context will automatically snap the port labels to snap lines. This option sets the snapPortLabels property on the created object.
- snapLineExtension - number
The amount by which snap lines that are induced by existing edge segments are being extended. This option sets the snapLineExtension property on the created object.
- collectPortSnapLines - boolean
Whether this instance should collect snap lines to the center of the owner port. This option sets the collectPortSnapLines property on the created object.
- 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 or sets whether this instance should collect snap lines in parallel to the border of the label owner at the distance of other node labels in the graph.
Remarks
Note that the label snaps to these snap lines with the side that is closer to the node's border. That way, snapping to such a snap line preserves the perceived distance from the node border for both labels inside and outside the node bounds.
The default is false
.
Gets or sets whether this instance should collect four snap lines in parallel to the owner's borders at the initial label distance.
Remarks
Note that the label snaps to these snap lines with the side that is closer to the node's border. That way, snapping to such a snap line preserves the perceived distance from the node border for both labels inside and outside the node bounds.
The default is true
.
Gets or sets whether this instance should collect snap lines in parallel to the border of the label owner at the distance of other node labels of that owner.
Remarks
Note that the label snaps to these snap lines with the side that is closer to the node's border. That way, snapping to such a snap line preserves the perceived distance from the node border for both labels inside and outside the node bounds.
The default is true
.
Gets the current input mode context.
Defined in
Gets or sets a value indicating whether this SnapContext is enabled.
Defined in
Gets or sets the GridSnapDistance.
Remarks
Defined in
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
Defined in
Gets whether the context is initialized.
Remarks
Defined in
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.
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
Defined in
Gets the collection of the snap lines that have been added to this context.
Gets the collection of SnapResults.
Gets or sets a value indicating whether to visualize the snap results.
Methods
Called when a drag has been canceled.
Remarks
Defined in
Performs clean up procedures.
Remarks
Overrides
Helper method used by createSnapResultsModelManager to create the ICanvasObjectDescriptor for the SnapResult type.
Returns
- ↪ICanvasObjectDescriptor
- An instance that can install SnapResults in a CanvasComponent.
Defined in
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.
Defined in
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
- ↪SnapState
- A SnapState that specifies the adjusted coordinates and how they have been adjusted. The unchanged coordinates if snapping has been temporarily disabled by setting
snappingDisabled
totrue
.
Overrides
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.
- mouseLocation - Point
- The actual mouse location.
- finalSnapState - SnapState
- The final snap state that contains the location that has been used by the client code for the move and how it has been snapped.
Defined in
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.
Overrides
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
.
Overrides
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.
Overrides
Raises the cleanUp event.
Parameters
A map of options to pass to the method.
- evt - InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Defined in
Raises the CollectSnapLines event.
Parameters
A map of options to pass to the method.
- evt - CollectLabelSnapLineEventArgs
- The CollectLabelSnapLineEventArgs 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.
Defined in
Raises the Initialized event.
Parameters
A map of options to pass to the method.
- evt - InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Defined in
Raises the Initializing event.
Parameters
A map of options to pass to the method.
- evt - InputModeEventArgs
- The InputModeEventArgs instance containing the event data.
Defined in
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.
Defined in
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.
Overrides
Events
Occurs when this instance has been cleaned up.
See Also
Defined in
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 every time this instance has been initialized to collect SnapLines.
Remarks
See Also
Event Registration
addCollectSnapLinesListener(function(this, CollectLabelSnapLineEventArgs):void)
Event Deregistration
removeCollectSnapLinesListener(function(this, CollectLabelSnapLineEventArgs):void)
Signature Details
function(sender: this, evt: CollectLabelSnapLineEventArgs)
Parameters
- sender - this
- The source of the event.
- evt - CollectLabelSnapLineEventArgs
- 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.
Defined in
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
Defined in
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
Defined in
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.