Skip to content

Commit

Permalink
Merge pull request #30 from iVis-at-Bilkent/unstable
Browse files Browse the repository at this point in the history
Merge unstable to master
  • Loading branch information
hasanbalci authored Mar 29, 2020
2 parents a75d8d3 + a76fad5 commit 43a7f84
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 29 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ A Cytoscape.js extension enabling interactive editing of edge bend points and re

<img src="edge-editing-animated-demo.gif" width="340">

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](https://doi.org/10.1371/journal.pone.0197238)", PLoS ONE, 13(5): e0197238, 2018.

## Demo

Click [here](https://ivis-at-bilkent.github.io/cytoscape.js-edge-editing/demo.html) for demo
Expand All @@ -40,7 +44,7 @@ CommonJS:
```js
var cytoscape = require('cytoscape');
var jquery = require('jquery');
var edgeBendEditing = require('cytoscape-edge-editing');
var edgeEditing = require('cytoscape-edge-editing');

edgeEditing( cytoscape, jquery ); // register extension
```
Expand Down
40 changes: 26 additions & 14 deletions cytoscape-edge-editing.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->

<script src="https://cdn.rawgit.com/ivis-at-bilkent/cytoscape.js-context-menus/master/cytoscape-context-menus.js"></script>
<script src="https://cdn.rawgit.com/ivis-at-bilkent/cytoscape.js-undo-redo/master/cytoscape-undo-redo.js"></script>
<script src="https://cdn.rawgit.com/ivis-at-bilkent/cytoscape.js-undo-redo/unstable/cytoscape-undo-redo.js"></script>
<script src="cytoscape-edge-editing.js"></script>

<style>
Expand Down
37 changes: 24 additions & 13 deletions src/UIUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (params, cy) {

var addBendPointCxtMenuId = 'cy-edge-bend-editing-cxt-add-bend-point';
var removeBendPointCxtMenuId = 'cy-edge-bend-editing-cxt-remove-bend-point';
var ePosition, eStyle, eRemove, eAdd, eZoom, eSelect, eUnselect, eTapStart, eTapDrag, eTapEnd, eCxtTap;
var eStyle, eRemove, eAdd, eZoom, eSelect, eUnselect, eTapStart, eTapDrag, eTapEnd, eCxtTap, eDrag;
// last status of gestures
var lastPanningEnabled, lastZoomingEnabled, lastBoxSelectionEnabled;
// status of edge to highlight bends and selected edges
Expand Down Expand Up @@ -44,6 +44,7 @@ module.exports = function (params, cy) {
}

refreshDraws();
edge.select();
};

var cxtRemoveBendPointFcn = function (event) {
Expand All @@ -61,7 +62,8 @@ module.exports = function (params, cy) {
cy.undoRedo().do('changeBendPoints', param);
}

setTimeout(function(){refreshDraws()}, 50) ;
setTimeout(function(){refreshDraws();edge.select();}, 50) ;

};

// function to reconnect edge
Expand Down Expand Up @@ -531,7 +533,7 @@ module.exports = function (params, cy) {
refreshDraws();
});

cy.on('position', 'node', ePosition = function () {
/* cy.on('position', 'node', ePosition = function () {
var node = this;
if(cy.edges(":selected").length == 1){
cy.edges().unselect()
Expand All @@ -543,7 +545,7 @@ module.exports = function (params, cy) {
}
refreshDraws();
});
}); */
/* cy.on("afterUndo", function (event, actionName, args, res) {
if(actionName == "drag") {
Expand Down Expand Up @@ -688,7 +690,7 @@ module.exports = function (params, cy) {
}

movedBendEdge = edge;

edge.unselect();
moveBendParam = {
edge: edge,
weights: edge.data('cyedgebendeditingWeights') ? [].concat(edge.data('cyedgebendeditingWeights')) : [],
Expand Down Expand Up @@ -726,6 +728,13 @@ module.exports = function (params, cy) {
}
});

cy.on('drag', 'node', eDrag = function (event) {
var node = this;
cy.edges().unselect();
if(!node.selected()){
cy.nodes().unselect();
}
});
cy.on('tapdrag', eTapDrag = function (event) {
var edge = movedBendEdge;
if(movedBendEdge !== undefined && bendPointUtilities.isIgnoredEdge(edge) ) {
Expand Down Expand Up @@ -892,6 +901,7 @@ module.exports = function (params, cy) {
};
var result = cy.undoRedo().do('reconnectEdge', param);
edge = result.edge;
//edge.select();
}
}
}
Expand All @@ -900,7 +910,7 @@ module.exports = function (params, cy) {
if(isValid !== 'valid' && typeof actOnUnsuccessfulReconnection === 'function'){
actOnUnsuccessfulReconnection();
}
edge.unselect();
edge.select();
cy.remove(dummyNode);
}
}
Expand Down Expand Up @@ -1009,11 +1019,12 @@ module.exports = function (params, cy) {
cy.on('cyedgebendediting.changeBendPoints', 'edge', function() {
var edge = this;
cy.startBatch();
cy.edges().unselect();
cy.trigger('bendPointMovement');
cy.endBatch();
cy.edges().unselect();
//edge.select();
cy.trigger('bendPointMovement');
cy.endBatch();
refreshDraws();
edge.select();


});
}
Expand Down Expand Up @@ -1135,16 +1146,16 @@ module.exports = function (params, cy) {
$container.data('cyedgebendediting', data);
},
unbind: function () {
cy.off('position', 'node', ePosition)
.off('remove', 'node', eRemove)
cy.off('remove', 'node', eRemove)
.off('add', 'node', eAdd)
.off('style', 'edge.edgebendediting-hasbendpoints:selected', eStyle)
.off('select', 'edge', eSelect)
.off('unselect', 'edge', eUnselect)
.off('tapstart', 'edge', eTapStart)
.off('tapdrag', eTapDrag)
.off('tapend', eTapEnd)
.off('cxttap', eCxtTap);
.off('cxttap', eCxtTap)
.off('drag', 'node',eDrag);

cy.unbind("zoom pan", eZoom);
}
Expand Down
1 change: 1 addition & 0 deletions src/registerUndoRedoFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module.exports = function (cy, bendPointUtilities, params) {
location: oldLoc,
oldLoc: location
}
edge.unselect();
return result;
}

Expand Down

0 comments on commit 43a7f84

Please sign in to comment.