Context Menu#
Plugins can add their own entries to the right-click context menu that appears when a user
clicks on a map element (e.g. a bioentity or reaction). The contextMenu object is returned
by window.minerva.plugins.registerPlugin and is scoped to the registering plugin - the id
of a menu item only needs to be unique within that plugin.
Add Menu#
To add an entry to the context menu, plugins can use the addMenu method in the contextMenu
object. This method takes the following arguments:
- name: label displayed for the menu entry
- style: CSS class name(s) applied to the menu entry
- enabled: whether the entry is enabled (clickable) or disabled
- callback: function invoked when the entry is clicked, called with:
- coordinates:
{ modelId, x, y, zoom }- the map location that was right-clicked - element: the
ModelElementor reaction the user clicked on, orundefinedif the click was not on a recognized element
- coordinates:
addMenu returns a string id identifying the created entry. Save this id if you intend to
update or remove the entry later.
Example of addMenu method usage:#
const {
element,
contextMenu: { addMenu },
} = minerva.plugins.registerPlugin({
pluginName,
pluginVersion,
pluginUrl,
});
const menuItemId = addMenu('Show details', 'my-plugin-menu-item', true, (coordinates, element) => {
console.log('Clicked at', coordinates, 'on element', element);
});Update Menu#
To change the label, style, or enabled state of an existing entry, plugins can use the
updateMenu method. This method takes the following arguments:
- id: the id returned by
addMenu - name: new label for the menu entry
- style: new CSS class name(s) for the menu entry
- enabled: new enabled state
Calling updateMenu with an id that does not exist for the plugin throws an error.
Example of updateMenu method usage:#
const {
element,
contextMenu: { addMenu, updateMenu },
} = minerva.plugins.registerPlugin({
pluginName,
pluginVersion,
pluginUrl,
});
const menuItemId = addMenu('Show details', 'my-plugin-menu-item', true, callback);
updateMenu(menuItemId, 'Show details (disabled)', 'my-plugin-menu-item', false);Remove Menu#
To remove an entry from the context menu, plugins can use the removeMenu method. This method
takes one argument:
- id: the id returned by
addMenu
Example of removeMenu method usage:#
const {
element,
contextMenu: { addMenu, removeMenu },
} = minerva.plugins.registerPlugin({
pluginName,
pluginVersion,
pluginUrl,
});
const menuItemId = addMenu('Show details', 'my-plugin-menu-item', true, callback);
removeMenu(menuItemId);