- I
Remarks
This mode can be used with any context menu implementation since it does not impose any specific requirements. Typically, it is used in the following way:
When this mode is informed that the user wants to show the context menu for example because a contextmenu event was fired, it checks whether its current state allows opening a context menu, and fires the populate-menu and GraphInputMode.populateItemContextMenu events.
If the context menu was closed because of user interaction with it, for example the user selected a menu entry in a custom context menu, this mode must be informed by calling the method closeMenu.
The context menu HTML element is positioned using "position: absolute". It is therefore positioned with respect to it's offset parent, which is the closest ancestor with "position: relative". In summary, for the context menu to work properly, the element containing the graph component must be styled with "position: relative".
Examples
Typically, the ContextMenuInputMode is installed as child mode of a GraphEditorInputMode or GraphViewerInputMode and can be retrieved from the contextMenuInputMode property.
const contextMenuInputMode = mode.contextMenuInputModeIt is recommended to configure the context menu handling on the parent GraphEditorInputMode or GraphViewerInputMode instead of the ContextMenuInputMode. This involves registering for the populate-item-context-menu event instead of the populate-menu event:
// mode is either an instance of GraphEditorInputMode or GraphViewerInputMode
mode.contextMenuItems = GraphItemTypes.NODE
mode.addEventListener('populate-item-context-menu', (evt) => {
// Get the node which is handled or null if the item is not a node
const node = evt.item
// Create the context menu items
if (node !== null) {
// Create a menu item to delete the node
// Show the menu
evt.contextMenu = [
{ label: 'Delete Item', action: () => graph.remove(node) },
]
}
})See Also
Developer's Guide
Demos
- Shows how to add a context menu to the nodes of a graph and to the canvas background.
Members
Constructors
Initializes a new instance of the ContextMenuInputMode class.
Parameters
Properties
Gets or sets a custom parent element to which the context menu is added as a child in the DOM.
By default this property is null, which means that the menu is added to the document.body.
When specifying some other element as parent, it must be assured that the element is currently visible (i.e. has no style with property display: none).
Gets the installed ConcurrencyController.
Examples
mode.contextMenuInputMode.enabled = falseThe 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.
Retrieves the IInputModeContext this mode has been installed in.
null if this mode is currently not installed. Use createInputModeContext to obtain a context that has this IInputMode as the inputMode.Implements
IInputMode.prioritytrue.Gets or sets the cursor to use when the mouse is at a valid menu location.
nullGets or sets an IHitTestable that determines whether it is valid to open a context menu at the queried position.
false onMenuOpening will not be queried and the context menu will not be shown. By default, there is a hit testable instance that always yields true.See Also
Developer's Guide
Methods
Implements
IInputMode.cancelThis method must be called by custom event listeners on HTMLElements added in contextMenu to indicate that the menu has been closed.
Creates an input mode context that uses this instance as the inputMode and delegates to parentInputModeContext otherwise.
null, i.e. while this mode is installed.Return Value
- IInputModeContext
- An instance that has this IInputMode set as the inputMode
Creates an IInputModeContext for use with the populate-menu call in the upcoming query.
Installs this mode in the canvas.
Parameters
- context: IInputModeContext
- The context to install this mode into.
- controller: ConcurrencyController
- The controller for this mode.
Implements
IInputMode.installCalled after cancel has been called.
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
Can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
Called when the menu is closed and triggers the menu-closed event.
Populates the context menu for the given world coordinate.
Parameters
- location: Point
- The location in the world coordinate system for which the context menu has been invoked.
Return Value
Raises the populate-menu event.
Parameters
- evt: PopulateContextMenuEventArgs
- The PopulateContextMenuEventArgs instance containing the event data.
See Also
Developer's Guide
Called after tryStop has been called.
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
Removes the menu from the context and replaces it with the old instance.
Parameters
- context: IInputModeContext
- The context to uninstall this mode from.
Implements
IInputMode.uninstallEvents
Properties of
PopulateContextMenuEventArgs- context: IInputModeContext
- Gets the context for the current event.
- contextMenu: ContextMenuContentwritable
- Gets or sets the context menu content to use.
- handled: booleanwritable
- Gets or sets a value indicating whether this PopulateContextMenuEventArgs has been handled.
- queryLocation: Point
- Gets the queried location in world coordinates.
- showMenu: booleanwritable
- Gets or sets a value indicating whether to actually display the context menu.
Examples
ContextMenuInputMode. This involves registering for the populate-item-context-menu event instead of this event:// mode is either an instance of GraphEditorInputMode or GraphViewerInputMode
mode.contextMenuItems = GraphItemTypes.NODE
mode.addEventListener('populate-item-context-menu', (evt) => {
// Get the node which is handled or null if the item is not a node
const node = evt.item
// Create the context menu items
if (node !== null) {
// Create a menu item to delete the node
// Show the menu
evt.contextMenu = [
{ label: 'Delete Item', action: () => graph.remove(node) },
]
}
})See Also
Developer's Guide