diff --git a/README.md b/README.md index d1fcfa8..df6feaf 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Notice that following events are performed for *each* node that is collapsed/exp // recommended usage: use cose-bilkent layout with randomize: false to preserve mental map upon expand/collapse fisheye: true, // whether to perform fisheye view after expand/collapse you can specify a function too animate: true, // whether to animate on drawing changes you can specify a function too + animationDuration: 1000, // when animate is true, the duration in milliseconds of the animation ready: function () { }, // callback when expand/collapse initialized undoable: true, // and if undoRedoExtension exists, diff --git a/cytoscape-expand-collapse.js b/cytoscape-expand-collapse.js index 1b649f4..925ed65 100644 --- a/cytoscape-expand-collapse.js +++ b/cytoscape-expand-collapse.js @@ -812,7 +812,7 @@ return { var node = nodes[0]; if (node._private.data.collapsedChildren != null) { // Expand the given node the third parameter indicates that the node is simple which ensures that fisheye parameter will be considered - this.expandNode(node, options.fisheye, true, options.animate, options.layoutBy); + this.expandNode(node, options.fisheye, true, options.animate, options.layoutBy, options.animationDuration); } } else { @@ -833,7 +833,7 @@ return { * in a batch. */ cy.startBatch(); - this.simpleCollapseGivenNodes(nodes, options); + this.simpleCollapseGivenNodes(nodes/*, options*/); cy.endBatch(); nodes.trigger("position"); // position not triggered by default when collapseNode is called @@ -893,10 +893,10 @@ return { * applyFishEyeView parameter then the state of view port is to be changed to have extra space on the screen (if needed) before appliying the * fisheye view. */ - expandNode: function (node, applyFishEyeView, single, animate, layoutBy) { + expandNode: function (node, applyFishEyeView, single, animate, layoutBy, animationDuration) { var self = this; - var commonExpandOperation = function (node, applyFishEyeView, single, animate, layoutBy) { + var commonExpandOperation = function (node, applyFishEyeView, single, animate, layoutBy, animationDuration) { if (applyFishEyeView) { node._private.data['width-before-fisheye'] = node._private.data['size-before-collapse'].w; @@ -905,7 +905,7 @@ return { // Fisheye view expand the node. // The first paramter indicates the node to apply fisheye view, the third parameter indicates the node // to be expanded after fisheye view is applied. - self.fishEyeViewExpandGivenNode(node, single, node, animate, layoutBy); + self.fishEyeViewExpandGivenNode(node, single, node, animate, layoutBy, animationDuration); } // If one of these parameters is truthy it means that expandNodeBaseFunction is already to be called. @@ -952,10 +952,10 @@ return { pan: viewPort.pan, zoom: viewPort.zoom, complete: function () { - commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy); + commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy, animationDuration); } }, { - duration: 1000 + duration: animationDuration || 1000 }); } else { @@ -967,7 +967,7 @@ return { // If animating is not true we need to call commonExpandOperation here if (!animating) { - commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy); + commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy, animationDuration); } //return the node to undo the operation @@ -1023,7 +1023,7 @@ return { * Apply fisheye view to the given node. nodeToExpand will be expanded after the operation. * The other parameter are to be passed by parameters directly in internal function calls. */ - fishEyeViewExpandGivenNode: function (node, single, nodeToExpand, animate, layoutBy) { + fishEyeViewExpandGivenNode: function (node, single, nodeToExpand, animate, layoutBy, animationDuration) { var siblings = this.getSiblings(node); var x_a = this.xPositionInParent(node); @@ -1114,7 +1114,7 @@ return { } // Move the sibling in the special way - this.fishEyeViewMoveNode(sibling, T_x, T_y, nodeToExpand, single, animate, layoutBy); + this.fishEyeViewMoveNode(sibling, T_x, T_y, nodeToExpand, single, animate, layoutBy, animationDuration); } // If there is no sibling call expand node base function here else it is to be called one of fishEyeViewMoveNode() calls @@ -1124,7 +1124,7 @@ return { if (node.parent()[0] != null) { // Apply fisheye view to the parent node as well ( If exists ) - this.fishEyeViewExpandGivenNode(node.parent()[0], single, nodeToExpand, animate, layoutBy); + this.fishEyeViewExpandGivenNode(node.parent()[0], single, nodeToExpand, animate, layoutBy, animationDuration); } return node; @@ -1145,7 +1145,7 @@ return { * Move node operation specialized for fish eye view expand operation * Moves the node by moving its descandents. Movement is animated if both single and animate flags are truthy. */ - fishEyeViewMoveNode: function (node, T_x, T_y, nodeToExpand, single, animate, layoutBy) { + fishEyeViewMoveNode: function (node, T_x, T_y, nodeToExpand, single, animate, layoutBy, animationDuration) { var childrenList = cy.collection(); if(node.isParent()){ childrenList = node.children(":visible"); @@ -1177,13 +1177,13 @@ return { } }, { - duration: 1000 + duration: animationDuration || 1000 }); } } else { for (var i = 0; i < childrenList.length; i++) { - this.fishEyeViewMoveNode(childrenList[i], T_x, T_y, nodeToExpand, single, animate, layoutBy); + this.fishEyeViewMoveNode(childrenList[i], T_x, T_y, nodeToExpand, single, animate, layoutBy, animationDuration); } } }, @@ -1396,7 +1396,7 @@ module.exports = expandCollapseUtilities; // set all options at once api.setOptions = function(opts) { - setScratch(cy, 'options', options); + setScratch(cy, 'options', opts); }; // set the option whose name is given @@ -1583,6 +1583,7 @@ module.exports = expandCollapseUtilities; layoutBy: null, // for rearrange after expand/collapse. It's just layout options or whole layout function. Choose your side! fisheye: true, // whether to perform fisheye view after expand/collapse you can specify a function too animate: true, // whether to animate on drawing changes you can specify a function too + animationDuration: 1000, // when animate is true, the duration in milliseconds of the animation ready: function () { }, // callback when expand/collapse initialized undoable: true, // and if undoRedoExtension exists, @@ -1718,4 +1719,4 @@ module.exports = function (cy, api) { },{}]},{},[6])(6) }); -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvYm91bmRpbmdCb3hVdGlsaXRpZXMuanMiLCJzcmMvY3VlVXRpbGl0aWVzLmpzIiwic3JjL2RlYm91bmNlLmpzIiwic3JjL2VsZW1lbnRVdGlsaXRpZXMuanMiLCJzcmMvZXhwYW5kQ29sbGFwc2VVdGlsaXRpZXMuanMiLCJzcmMvaW5kZXguanMiLCJzcmMvdW5kb1JlZG9VdGlsaXRpZXMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNB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IGN5LmdldEZpdFZpZXdwb3J0KHVuaW9uQkIsIDEwKTtcbiAgICAgICAgICB2YXIgc2VsZiA9IHRoaXM7XG4gICAgICAgICAgYW5pbWF0aW5nID0gYW5pbWF0ZTsgLy8gU2lnbmFsIHRoYXQgdGhlcmUgaXMgYW4gYW5pbWF0aW9uIG5vdyBhbmQgY29tbW9uRXhwYW5kT3BlcmF0aW9uIHdpbGwgYmUgY2FsbGVkIGFmdGVyIGFuaW1hdGlvblxuICAgICAgICAgIC8vIENoZWNrIGlmIHdlIG5lZWQgdG8gYW5pbWF0ZSBkdXJpbmcgcGFuIGFuZCB6b29tXG4gICAgICAgICAgaWYgKGFuaW1hdGUpIHtcbiAgICAgICAgICAgIGN5LmFuaW1hdGUoe1xuICAgICAgICAgICAgICBwYW46IHZpZXdQb3J0LnBhbixcbiAgICAgICAgICAgICAgem9vbTogdmlld1BvcnQuem9vbSxcbiAgICAgICAgICAgICAgY29tcGxldGU6IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICBjb21tb25FeHBhbmRPcGVyYXRpb24obm9kZSwgYXBwbHlGaXNoRXllVmlldywgc2luZ2xlLCBhbmltYXRlLCBsYXlvdXRCeSwgYW5pbWF0aW9uRHVyYXRpb24pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgIGR1cmF0aW9uOiBhbmltYXRpb25EdXJhdGlvbiB8fCAxMDAwXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICBjeS56b29tKHZpZXdQb3J0Lnpvb20pO1xuICAgICAgICAgICAgY3kucGFuKHZpZXdQb3J0LnBhbik7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBcbiAgICAgIC8vIElmIGFuaW1hdGluZyBpcyBub3QgdHJ1ZSB3ZSBuZWVkIHRvIGNhbGwgY29tbW9uRXhwYW5kT3BlcmF0aW9uIGh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ICAgICAgIHJlc3VsdC5vbGREYXRhID0gZ2V0Tm9kZVBvc2l0aW9ucygpO1xuICAgICAgICByZXN1bHQubm9kZXMgPSBmdW5jLmluZGV4T2YoXCJBbGxcIikgPiAwID8gYXBpW2Z1bmNdKHNlY29uZFRpbWVPcHRzKSA6IGFwaVtmdW5jXShjeS5jb2xsZWN0aW9uKG5vZGVzKSwgc2Vjb25kVGltZU9wdHMpO1xuICAgICAgICByZXR1cm5Ub1Bvc2l0aW9ucyhhcmdzLm9sZERhdGEpO1xuICAgICAgfVxuXG4gICAgICByZXR1cm4gcmVzdWx0O1xuICAgIH07XG4gIH1cblxuICB2YXIgYWN0aW9ucyA9IFtcImNvbGxhcHNlXCIsIFwiY29sbGFwc2VSZWN1cnNpdmVseVwiLCBcImNvbGxhcHNlQWxsXCIsIFwiZXhwYW5kXCIsIFwiZXhwYW5kUmVjdXJzaXZlbHlcIiwgXCJleHBhbmRBbGxcIl07XG5cbiAgZm9yICh2YXIgaSA9IDA7IGkgPCBhY3Rpb25zLmxlbmd0aDsgaSsrKSB7XG4gICAgdXIuYWN0aW9uKGFjdGlvbnNbaV0sIGRvSXQoYWN0aW9uc1tpXSksIGRvSXQoYWN0aW9uc1soaSArIDMpICUgNl0pKTtcbiAgfVxuXG59O1xuIl19 diff --git a/src/expandCollapseUtilities.js b/src/expandCollapseUtilities.js index b868132..9f58e50 100644 --- a/src/expandCollapseUtilities.js +++ b/src/expandCollapseUtilities.js @@ -139,7 +139,7 @@ return { var node = nodes[0]; if (node._private.data.collapsedChildren != null) { // Expand the given node the third parameter indicates that the node is simple which ensures that fisheye parameter will be considered - this.expandNode(node, options.fisheye, true, options.animate, options.layoutBy); + this.expandNode(node, options.fisheye, true, options.animate, options.layoutBy, options.animationDuration); } } else { @@ -160,7 +160,7 @@ return { * in a batch. */ cy.startBatch(); - this.simpleCollapseGivenNodes(nodes, options); + this.simpleCollapseGivenNodes(nodes/*, options*/); cy.endBatch(); nodes.trigger("position"); // position not triggered by default when collapseNode is called @@ -220,10 +220,10 @@ return { * applyFishEyeView parameter then the state of view port is to be changed to have extra space on the screen (if needed) before appliying the * fisheye view. */ - expandNode: function (node, applyFishEyeView, single, animate, layoutBy) { + expandNode: function (node, applyFishEyeView, single, animate, layoutBy, animationDuration) { var self = this; - var commonExpandOperation = function (node, applyFishEyeView, single, animate, layoutBy) { + var commonExpandOperation = function (node, applyFishEyeView, single, animate, layoutBy, animationDuration) { if (applyFishEyeView) { node._private.data['width-before-fisheye'] = node._private.data['size-before-collapse'].w; @@ -232,7 +232,7 @@ return { // Fisheye view expand the node. // The first paramter indicates the node to apply fisheye view, the third parameter indicates the node // to be expanded after fisheye view is applied. - self.fishEyeViewExpandGivenNode(node, single, node, animate, layoutBy); + self.fishEyeViewExpandGivenNode(node, single, node, animate, layoutBy, animationDuration); } // If one of these parameters is truthy it means that expandNodeBaseFunction is already to be called. @@ -279,10 +279,10 @@ return { pan: viewPort.pan, zoom: viewPort.zoom, complete: function () { - commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy); + commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy, animationDuration); } }, { - duration: 1000 + duration: animationDuration || 1000 }); } else { @@ -294,7 +294,7 @@ return { // If animating is not true we need to call commonExpandOperation here if (!animating) { - commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy); + commonExpandOperation(node, applyFishEyeView, single, animate, layoutBy, animationDuration); } //return the node to undo the operation @@ -350,7 +350,7 @@ return { * Apply fisheye view to the given node. nodeToExpand will be expanded after the operation. * The other parameter are to be passed by parameters directly in internal function calls. */ - fishEyeViewExpandGivenNode: function (node, single, nodeToExpand, animate, layoutBy) { + fishEyeViewExpandGivenNode: function (node, single, nodeToExpand, animate, layoutBy, animationDuration) { var siblings = this.getSiblings(node); var x_a = this.xPositionInParent(node); @@ -441,7 +441,7 @@ return { } // Move the sibling in the special way - this.fishEyeViewMoveNode(sibling, T_x, T_y, nodeToExpand, single, animate, layoutBy); + this.fishEyeViewMoveNode(sibling, T_x, T_y, nodeToExpand, single, animate, layoutBy, animationDuration); } // If there is no sibling call expand node base function here else it is to be called one of fishEyeViewMoveNode() calls @@ -451,7 +451,7 @@ return { if (node.parent()[0] != null) { // Apply fisheye view to the parent node as well ( If exists ) - this.fishEyeViewExpandGivenNode(node.parent()[0], single, nodeToExpand, animate, layoutBy); + this.fishEyeViewExpandGivenNode(node.parent()[0], single, nodeToExpand, animate, layoutBy, animationDuration); } return node; @@ -472,7 +472,7 @@ return { * Move node operation specialized for fish eye view expand operation * Moves the node by moving its descandents. Movement is animated if both single and animate flags are truthy. */ - fishEyeViewMoveNode: function (node, T_x, T_y, nodeToExpand, single, animate, layoutBy) { + fishEyeViewMoveNode: function (node, T_x, T_y, nodeToExpand, single, animate, layoutBy, animationDuration) { var childrenList = cy.collection(); if(node.isParent()){ childrenList = node.children(":visible"); @@ -504,13 +504,13 @@ return { } }, { - duration: 1000 + duration: animationDuration || 1000 }); } } else { for (var i = 0; i < childrenList.length; i++) { - this.fishEyeViewMoveNode(childrenList[i], T_x, T_y, nodeToExpand, single, animate, layoutBy); + this.fishEyeViewMoveNode(childrenList[i], T_x, T_y, nodeToExpand, single, animate, layoutBy, animationDuration); } } }, diff --git a/src/index.js b/src/index.js index 81a8e11..b0968a3 100644 --- a/src/index.js +++ b/src/index.js @@ -39,7 +39,7 @@ // set all options at once api.setOptions = function(opts) { - setScratch(cy, 'options', options); + setScratch(cy, 'options', opts); }; // set the option whose name is given @@ -226,6 +226,7 @@ layoutBy: null, // for rearrange after expand/collapse. It's just layout options or whole layout function. Choose your side! fisheye: true, // whether to perform fisheye view after expand/collapse you can specify a function too animate: true, // whether to animate on drawing changes you can specify a function too + animationDuration: 1000, // when animate is true, the duration in milliseconds of the animation ready: function () { }, // callback when expand/collapse initialized undoable: true, // and if undoRedoExtension exists,