- Notifications
You must be signed in to change notification settings - Fork43
A Cytoscape.js extension to provide context menu around elements and core instance
License
iVis-at-Bilkent/cytoscape.js-context-menus
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Cytoscape.js extension to provide context menu around elements and core instance distributed underThe MIT License.
Please cite the following paper when using this extension:
U. Dogrusoz , A. Karacelik, I. Safarli, H. Balci, L. Dervishi, and M.C. Siper, "Efficient methods and readily customizable libraries for managing complexity of large networks", PLoS ONE, 13(5): e0197238, 2018.
Here are demos:simple andcustomized, respectively:
- Cytoscape.js ^2.7.0 || ^3.0.0
Download the library:
- via npm:
npm install cytoscape-context-menus, - via bower:
bower install cytoscape-context-menus, or - via direct download in the repository (probably from a tag).
Import the library as appropriate for your project:
ES import:
Note: es import doesn't work for plain javascript applications because webpack doesn't support es module output at the moment.
importcytoscapefrom'cytoscape';importcontextMenusfrom'cytoscape-context-menus';// register extensioncytoscape.use(contextMenus);// import CSS as wellimport'cytoscape-context-menus/cytoscape-context-menus.css';
CommonJS:
varcytoscape=require('cytoscape');varcontextMenus=require('cytoscape-context-menus');contextMenus(cytoscape);// register extension
AMD:
require(['cytoscape','cytoscape-context-menus'],function(cytoscape,contextMenus){contextMenus(cytoscape);// register extension});
Plain HTML/JS has the extension registered for you automatically, because norequire() is needed.
varoptions={// Customize event to bring up the context menu// Possible options https://js.cytoscape.org/#events/user-input-device-eventsevtType:'cxttap',// List of initial menu items// A menu item must have either onClickFunction or submenu or bothmenuItems:[/* { id: 'remove', // ID of menu item content: 'remove', // Display content of menu item tooltipText: 'remove', // Tooltip text for menu item image: {src : "remove.svg", width : 12, height : 12, x : 6, y : 4}, // menu icon // Filters the elements to have this menu item on cxttap // If the selector is not truthy no elements will have this menu item on cxttap selector: 'node, edge', onClickFunction: function () { // The function to be executed on click console.log('remove element'); }, disabled: false, // Whether the item will be created as disabled show: false, // Whether the item will be shown or not hasTrailingDivider: true, // Whether the item will have a trailing divider coreAsWell: false // Whether core instance have this item on cxttap submenu: [] // Shows the listed menuItems as a submenu for this item. An item must have either submenu or onClickFunction or both. }, { id: 'hide', content: 'hide', tooltipText: 'hide', selector: 'node, edge', onClickFunction: function () { console.log('hide element'); }, disabled: true }, { id: 'add-node', content: 'add node', tooltipText: 'add node', image: {src : "add.svg", width : 12, height : 12, x : 6, y : 4}, selector: 'node', coreAsWell: true, onClickFunction: function () { console.log('add node'); } }*/],// css classes that menu items will havemenuItemClasses:[// add class names to this list],// css classes that context menu will havecontextMenuClasses:[// add class names to this list],// Indicates that the menu item has a submenu. If not provided default one will be usedsubmenuIndicator:{src:'assets/submenu-indicator-default.svg',width:12,height:12}};
Note:selector andcoreAsWell options are ignored for the items that are inside a submenu. Their visiblity depends on their root parent's visibility.
varinstance=cy.contextMenus(options);
- Returns whether the extension is active.
- Appends given menu item to the menu items list.
- If parentID is specified, the item is inserted to the submenu of the item with parentID.
- If the parent has no submenu then it will automatically be created.
- If not specified item will be inserted to the root of the contextmenu
- Same with above but takes an array of items
- Removes the menu item with given ID and its submenu along with
- Sets whether the menuItem with given ID will have a following divider
- Inserts given item before the existingitem
- Moves the item with given ID to the submenu of the parent with the given ID or to root with the specified options
- If
optionsis astring, then it is the id of the parent - If
optionsis a{ selector?: string, coreAsWell?: boolean }, then old properties are overwritten by them and the menu item is moved to the root. If it doesn't have either properties item isnot moved. - If
optionsis null or not provided, then it is just moved to the root
- Inserts the
itembefore theexistingItemand moves it to the submenu that contains theexistingItem
- Disables the menu item with given ID.
- Enables the menu item with given ID.
- Shows the menu item with given ID.
- Hides the menu item with given ID.
- Destroys the extension instance
- Changes the order of items.
xandyare id of context menu items to be swapped
- Returns the used options
- Returns the existing instance to the extension
npm run build: Build./src/**intocytoscape-edge-editing.jsin production environment and minimize the file.npm run build:dev: Build./src/**intocytoscape-edge-editing.jsin development environment without minimizing the file.
This project is set up to automatically be published to npm and bower. To publish:
- Build the extension :
npm run build - Commit the build :
git commit -am "Build for release" - Bump the version number and tag:
npm version major|minor|patch - Push to origin:
git push && git push --tags - Publish to npm:
npm publish . - If publishing to bower for the first time, you'll need to run
bower register cytoscape-context-menus https://github.com/iVis-at-Bilkent/cytoscape.js-context-menus.git
About
A Cytoscape.js extension to provide context menu around elements and core instance
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors15
Uh oh!
There was an error while loading.Please reload this page.


