An input mode for use in a GraphComponent that fires events when the pointer enters or leaves the visualization of a graph item.
Remarks
This mode can be used to determine when the pointer is being moved from one item to the next.
This mode is exclusive by default.
Examples
Typically, the ItemHoverInputMode
is installed as child mode of a GraphEditorInputMode or GraphViewerInputMode and can be retrieved from the itemHoverInputMode property.
const itemHoverInputMode = mode.itemHoverInputMode
The ItemHoverInputMode
raises the hovered-item-changed event each time the cursor hovers over a different item or the canvas, in which case the hovered item is null
. One can also configure the item types which are reported:
// mode is either an instance of GraphEditorInputMode or GraphViewerInputMode
// enable the ItemHoverInputMode and let it handle edges and nodes
mode.itemHoverInputMode.enabled = true
mode.itemHoverInputMode.hoverItems =
GraphItemTypes.EDGE | GraphItemTypes.NODE
// handle changes on the hovered items
mode.itemHoverInputMode.addEventListener(
'hovered-item-changed',
(evt) => {
const oldItem = evt.oldItem
// e.g. remove the highlight from oldItem here
const newItem = evt.item
// e.g. add a highlight to newItem here
},
)
Related Programming Samples
- Graph Viewer
- Displays sample graphs from various application domains.
Type Details
- yFiles module
- view
Constructors
Initializes a new instance of the ItemHoverInputMode class.
Parameters
A map of options to pass to the method.
- priority - number
- exclusive - boolean
- A value indicating whether this mode will be the only one running when it has the mutex. This option sets the exclusive property on the created object.
- enabled - boolean
- The enabled state of this input mode. This option sets the enabled property on the created object.
- hoverItems - GraphItemTypes
- Which graph items are considered by this input mode. This option sets the hoverItems property on the created object.
- hoverCursor - Cursor
- The cursor to use when the pointer is hovering over a isValidHoverItem valid hover item. This option sets the hoverCursor property on the created object.
- ignoreInvalidItems - boolean
- A value indicating whether items that have been hit at the current location that are not valid items should be ignored (and an underlying valid item be considered instead) or reported as
null
. This option sets the ignoreInvalidItems property on the created object.
Properties
Gets the installed controller.
Gets the current item the pointer is hovering over.
Property Value
null
if the pointer is not hovering over a valid item.Gets or sets the enabled state of this input mode.
Remarks
Examples
mode.itemHoverInputMode.enabled = false
Gets or sets a value indicating whether this mode will be the only one running when it has the mutex.
Remarks
The value of this property will be delegated to the exclusive property of the controller.
If this mode is marked as exclusive and has the mutex, all other modes added to the same MultiplexingInputMode will be deactivated. Otherwise, it will always run concurrently with all other modes.
Gets or sets the cursor to use when the pointer is hovering over a isValidHoverItem valid hover item.
Property Value
null
(the default).Gets or sets which graph items are considered by this input mode.
Remarks
The default is ALL.
Note that the default is set to a different value if this mode is a child mode of the GraphEditorInputMode or GraphViewerInputMode. and documented there.
Examples
// mode is either an instance of GraphEditorInputMode or GraphViewerInputMode
// enable the ItemHoverInputMode and let it handle edges and nodes
mode.itemHoverInputMode.enabled = true
mode.itemHoverInputMode.hoverItems =
GraphItemTypes.EDGE | GraphItemTypes.NODE
// handle changes on the hovered items
mode.itemHoverInputMode.addEventListener(
'hovered-item-changed',
(evt) => {
const oldItem = evt.oldItem
// e.g. remove the highlight from oldItem here
const newItem = evt.item
// e.g. add a highlight to newItem here
},
)
Gets or sets a value indicating whether items that have been hit at the current location that are not valid items should be ignored (and an underlying valid item be considered instead) or reported as null
.
Remarks
This setting also has an influence, if the items you want to hover over are covered by "invalid" items in front of them. By default, these "invalid" items will stop the hover picking process and null
will be reported, even if there is a valid item underneath the hovered item.
Set this to true
to let hit test enumeration continue to find the next valid item. Set this to false
if invalid items should be reported as null
.
The default is true
.
See Also
Retrieves the IInputModeContext this mode has been installed in.
Remarks
null
if this mode is currently not installed. Use createInputModeContext to get a context that has this IInputMode as the inputMode.Gets the priority of this input mode.
Remarks
Implements
Methods
Will be called to unconditionally cancel all ongoing edits.
Remarks
This will be called prior to the uninstalling of this instance and when other input modes temporarily acquire the mutex.
In order to stop an active input mode manually, client code should use the following idiom:
if (!mode.tryStop()) {
mode.cancel()
}
Implements
Creates an implementation of IInputModeContext that is specific to this mode.
Remarks
This is needed for events that are triggered by this InputMode to signal where the event is coming from. A common usage for this is, for example, in isHit calls.
The result can be given to isHit or enumerateHits to let implementations of IHitTestable get access to the current IInputModeContext. This can be done by looking up IInputModeContext from the ICanvasContext's lookup method or simply down-casting.
Returns
- ↪IInputModeContext
- A readily configured IInputModeContext.
See Also
Gets the items that have been hit at the given location.
Remarks
Parameters
A map of options to pass to the method.
- location - Point
- The location in world coordinates to query.
Returns
- ↪IEnumerable<IModelItem>
- An enumerable over the items that have been hit at the given location.
Installs this mode into the given context that is provided by the canvas.
Remarks
In general a mode can only be installed into a single canvas at all times.
This method is called to initialize this instance. Subclasses should override this method to register the corresponding event handler delegates for the various input events they need to register with.
Overriding implementations should call the base implementation, first.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The context that this instance shall be installed into. The same instance will be passed to this instance during uninstall. A reference to the context may be kept and queried during the time the mode is installed.
- controller - ConcurrencyController
- The controller for this mode.
See Also
Implements
Determines whether the given item is a valid item to be considered for hovering.
Remarks
Parameters
A map of options to pass to the method.
- item - IModelItem
- The item to check.
Returns
- ↪boolean
true
if it is valid to report a hover over the specified item;false
otherwise.
See Also
Called after cancel has been called.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
Called after the active property of the installed ConcurrencyController has been set to true
.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
Called after the active property of the installed ConcurrencyController has been set to false
.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
Raises the hovered-item-changed event.
Parameters
A map of options to pass to the method.
- evt - HoveredItemChangedEventArgs
- The HoveredItemChangedEventArgs instance containing the event data.
Called after tryStop has been called.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
Overridden to only return true
if this instance does not currently have the input mutex.
Uninstalls this mode from the given context.
Remarks
This code should clean up all changes made to the canvas in the install method. After a mode has been uninstalled it can be installed again into the same or another canvas.
Overriding implementations should call the base implementation after their own code.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The context to deregister from. This is the same instance that had been passed to install during installation.
Implements
Forces a reevaluation of the item that the pointer is currently hovering over or at a specific location.
Remarks
Parameters
A map of options to pass to the method.
- location - Point
- The query location. If omitted, the last location is queried again.
Events
Occurs when the item that is being hovered over with the pointer changes.
Remarks
Examples
null
. One can also configure the item types which are reported:// mode is either an instance of GraphEditorInputMode or GraphViewerInputMode
// enable the ItemHoverInputMode and let it handle edges and nodes
mode.itemHoverInputMode.enabled = true
mode.itemHoverInputMode.hoverItems =
GraphItemTypes.EDGE | GraphItemTypes.NODE
// handle changes on the hovered items
mode.itemHoverInputMode.addEventListener(
'hovered-item-changed',
(evt) => {
const oldItem = evt.oldItem
// e.g. remove the highlight from oldItem here
const newItem = evt.item
// e.g. add a highlight to newItem here
},
)