cytoscape-edge-editing
Description
A Cytoscape.js extension enabling interactive editing of edge bend and control points for segment and unbundled bezier edges, respectively. It also allows for reconnection of edges to other source/target nodes. The extension is distributed under The MIT License.
- The term 'anchor' will be used here and in the code to refer to bend and control points collectively.
- To highlight anchor positions of an edge you should select the edge and unselect any other edges. Note that in determining the edge to highlight the anchor positions we assume that the unvisible edges are not selected.
- To add an anchor select the edge and unselect any other edge, right click where you want to add the anchor and click 'Add Bend Point' or 'Add Control Point' on the context menu (requires 'cytoscape.js-context-menus' extension). The context menu will distiguish between the edges and it will not be possible to a bend point on an unbundled bezier edge and vice versa.
- Bend points or control points can be added to edges which are not of type segments or unbundled bezier. The edge will then become segemetns or unbundled bezier accordingly.
- To remove an anchor select the edge and unselect any other edge, right click on the anchor and click 'Remove Bend Point' or 'Remove Control Point' on the context menu (requires 'cytoscape.js-context-menus' extension).
- To move an anchor drag and drop it when the edge is the only selected edge.
- Alternatively,
- You can click anywhere on the edge (if it is the only selected edge) to introduce and relocate an anchor by dragging.
- A bend point is removed if it is dropped near the line segment between its two neighbours.
- Drag and drop can also be used to quickly create and drag an anchor on a highlighted edge. The anchor type will be decided based on the edge type. This will not work with edges which are not segments or unbundled bezier.
- To reconnect an edge, select the handle (source or target), drag and drop on the new (source or target) node.
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 is a demo:
Dependencies
- Cytoscape.js ^3.3.0
- Konva ^7.0.3
- cytoscape-undo-redo.js(optional) ^1.0.1
- cytoscape-context-menus.js(optional) ^2.0.0
Usage instructions
Download the library:
- via npm:
npm install cytoscape-edge-editing
,
- via bower:
bower install cytoscape-edge-editing
, or
- via direct download in the repository (probably from a tag).
require()
the library as appropriate for your project:
CommonJS:
var cytoscape = require('cytoscape');
var konva = require('konva');
var edgeEditing = require('cytoscape-edge-editing');
edgeEditing( cytoscape, konva );
AMD:
require(['cytoscape', 'cytoscape-edge-editing', 'konva'], function( cytoscape, edge-editing, konva ){
edge-editing( cytoscape, konva );
});
Plain HTML/JS has the extension registered for you automatically, because no require()
is needed.
API
var instance = cy.edgeEditing( options );
An instance has a number of functions available:
instance.getAnchorsAsArray(ele);
instance.initAnchorPoints(eles);
instance.deleteSelectedAnchor(ele, index);
instance.getEdgeType(ele);
You can also get an existing instance:
cy.edgeEditing('get');
Or you can check if the extension is initilized before
cy.edgeEditing('initialized');
Default Options
var options = {
bendPositionsFunction: function(ele) {
return ele.data('bendPointPositions');
},
bendCornersIsRoundFunction: function(ele) {
return false;
},
controlPositionsFunction: function(ele) {
return ele.data('controlPointPositions');
},
bendPointPositionsSetterFunction: function(ele, bendPointPositions) {
ele.data('bendPointPositions', bendPointPositions);
},
controlPointPositionsSetterFunction: function(ele, controlPointPositions) {
ele.data('controlPointPositions', controlPointPositions);
},
initAnchorsAutomatically: true,
ignoredClasses: [],
undoable: false,
anchorShapeSizeFactor: 3,
zIndex: 999,
bendRemovalSensitivity : 8,
addBendMenuItemTitle: "Add Bend Point",
removeBendMenuItemTitle: "Remove Bend Point",
removeAllBendMenuItemTitle: "Remove All Bend Points",
addControlMenuItemTitle: "Add Control Point",
removeControlMenuItemTitle: "Remove Control Point",
removeAllControlMenuItemTitle: "Remove All Control Points",
moveSelectedAnchorsOnKeyEvents: function () {
return true;
},
handleReconnectEdge: true,
handleAnchors: true,
validateEdge: function (edge, newSource, newTarget) {
return 'valid';
},
actOnUnsuccessfulReconnection: undefined,
useTrailingDividersAfterContextMenuOptions: false,
enableCreateAnchorOnDrag: true,
enableFixedAnchorSize: false,
enableRemoveAnchorMidOfNearLine: true,
isShowHandleOnHover: false,
anchorColor: '#000000',
endPointColor: '#000000'
};
Build targets
npm run build
: Build ./src/**
into cytoscape-edge-editing.js
in production environment and minimize the file.
npm run build:dev
: Build ./src/**
into cytoscape-edge-editing.js
in development environment without minimizing the file.
Publishing instructions
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-edge-editing https://github.com/iVis-at-Bilkent/cytoscape.js-edge-editing.git
Team
Alumni