From 224615a0cc46d0754f1c70e2a2b2d7b28f9f291e Mon Sep 17 00:00:00 2001 From: ugurdogrusoz Date: Fri, 6 Oct 2017 15:13:03 +0300 Subject: [PATCH 1/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ee2d520..502364a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,8 @@ Get collapsed children of all collapsed nodes recursively. Returned value includ Forces the visual cue to be cleared. It is to be called in extreme cases. ## Events +Notice that following events are performed for *each* node that is collapsed/expanded. Also, notice that any post-processing layout is performed *after* the event. + `cy.nodes().on("expandcollapse.beforecollapse", function(event) { var node = this; ... })` Triggered before a node is collapsed `cy.nodes().on("expandcollapse.aftercollapse", function(event) { var node = this; ... })` Triggered after a node is collapsed From e7ead9422d7030ea21fbbcf2cfe2eec914b181eb Mon Sep 17 00:00:00 2001 From: Metin Can Siper Date: Tue, 24 Oct 2017 17:55:14 -0700 Subject: [PATCH 2/3] Fixed multiple tabs issue --- src/cueUtilities.js | 2 +- src/index.js | 101 +++++++++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/cueUtilities.js b/src/cueUtilities.js index 9603088..8976b37 100644 --- a/src/cueUtilities.js +++ b/src/cueUtilities.js @@ -1,7 +1,7 @@ var debounce = require('./debounce'); -var elementUtilities; module.exports = function (params, cy, api, $) { + var elementUtilities; var fn = params; var eMouseOver, eMouseOut, ePosition, eRemove, eTap, eZoom, eAdd, eFree; diff --git a/src/index.js b/src/index.js index 59e4c61..3ff3146 100644 --- a/src/index.js +++ b/src/index.js @@ -9,34 +9,17 @@ return; } // can't register if cytoscape unspecified - var expandCollapseUtilities; var undoRedoUtilities = require('./undoRedoUtilities'); var cueUtilities = require("./cueUtilities"); - var options = { - 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 - ready: function () { }, // callback when expand/collapse initialized - undoable: true, // and if undoRedoExtension exists, - - cueEnabled: true, // Whether cues are enabled - expandCollapseCuePosition: 'top-left', // default cue position is top left you can specify a function per node too - expandCollapseCueSize: 12, // size of expand-collapse cue - expandCollapseCueLineSize: 8, // size of lines used for drawing plus-minus icons - expandCueImage: undefined, // image of expand icon if undefined draw regular expand cue - collapseCueImage: undefined, // image of collapse icon if undefined draw regular collapse cue - expandCollapseCueSensitivity: 1 // sensitivity of expand-collapse cues - }; - - function setOptions(from) { + function extendOptions(options, extendBy) { var tempOpts = {}; for (var key in options) tempOpts[key] = options[key]; - for (var key in from) + for (var key in extendBy) if (tempOpts.hasOwnProperty(key)) - tempOpts[key] = from[key]; + tempOpts[key] = extendBy[key]; return tempOpts; } @@ -50,18 +33,18 @@ } // creates and returns the API instance for the extension - function createExtensionAPI(cy) { + function createExtensionAPI(cy, expandCollapseUtilities) { var api = {}; // API to be returned // set functions // set all options at once api.setOptions = function(opts) { - options = opts; + setScratch(cy, 'options', options); }; // set the option whose name is given api.setOption = function (name, value) { - options[name] = value; + getScratch(cy, 'options')[name] = value; }; // Collection functions @@ -69,7 +52,8 @@ // collapse given eles extend options with given param api.collapse = function (_eles, opts) { var eles = this.collapsibleNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return expandCollapseUtilities.collapseGivenNodes(eles, tempOptions); @@ -78,7 +62,8 @@ // collapse given eles recursively extend options with given param api.collapseRecursively = function (_eles, opts) { var eles = this.collapsibleNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return this.collapse(eles.union(eles.descendants()), tempOptions); @@ -87,7 +72,8 @@ // expand given eles extend options with given param api.expand = function (_eles, opts) { var eles = this.expandableNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return expandCollapseUtilities.expandGivenNodes(eles, tempOptions); @@ -96,7 +82,8 @@ // expand given eles recusively extend options with given param api.expandRecursively = function (_eles, opts) { var eles = this.expandableNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return expandCollapseUtilities.expandAllNodes(eles, tempOptions); @@ -107,7 +94,8 @@ // collapse all collapsible nodes api.collapseAll = function (opts) { - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return this.collapseRecursively(this.collapsibleNodes(), tempOptions); @@ -115,7 +103,8 @@ // expand all expandable nodes api.expandAll = function (opts) { - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return this.expandRecursively(this.expandableNodes(), tempOptions); @@ -202,18 +191,52 @@ return api; // Return the API instance } - - var api; // Define the api instance - + + // Get the whole scratchpad reserved for this extension (on an element or core) or get a single property of it + function getScratch (cyOrEle, name) { + if (cyOrEle.scratch('_cyExpandCollapse') === undefined) { + cyOrEle.scratch('_cyExpandCollapse', {}); + } + + var scratch = cyOrEle.scratch('_cyExpandCollapse'); + var retVal = ( name === undefined ) ? scratch : scratch[name]; + return retVal; + } + + // Set a single property on scratchpad of an element or the core + function setScratch (cyOrEle, name, val) { + getScratch(cyOrEle)[name] = val; + } + // register the extension cy.expandCollapse() cytoscape("core", "expandCollapse", function (opts) { + var cy = this; + + var options = getScratch(cy, 'options') || { + 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 + ready: function () { }, // callback when expand/collapse initialized + undoable: true, // and if undoRedoExtension exists, + + cueEnabled: true, // Whether cues are enabled + expandCollapseCuePosition: 'top-left', // default cue position is top left you can specify a function per node too + expandCollapseCueSize: 12, // size of expand-collapse cue + expandCollapseCueLineSize: 8, // size of lines used for drawing plus-minus icons + expandCueImage: undefined, // image of expand icon if undefined draw regular expand cue + collapseCueImage: undefined, // image of collapse icon if undefined draw regular collapse cue + expandCollapseCueSensitivity: 1 // sensitivity of expand-collapse cues + }; + // If opts is not 'get' that is it is a real options object then initilize the extension if (opts !== 'get') { - var cy = this; - options = setOptions(opts); - - expandCollapseUtilities = require('./expandCollapseUtilities')(cy); - api = createExtensionAPI(cy); // creates and returns the API instance for the extension + options = extendOptions(options, opts); + + var expandCollapseUtilities = require('./expandCollapseUtilities')(cy); + var api = createExtensionAPI(cy, expandCollapseUtilities); // creates and returns the API instance for the extension + + setScratch(cy, 'api', api); + undoRedoUtilities(cy, api); if(options.cueEnabled) @@ -221,9 +244,11 @@ options.ready(); + + setScratch(cy, 'options', options); } - return api; // Expose the API to the users + return getScratch(cy, 'api'); // Expose the API to the users }); }; From 2777d4c427a40d4cd4c22d8ddd13b8438cb1eb58 Mon Sep 17 00:00:00 2001 From: kinimesi Date: Tue, 5 Dec 2017 13:31:35 +0300 Subject: [PATCH 3/3] Rebuild... --- cytoscape-expand-collapse.js | 105 ++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 40 deletions(-) diff --git a/cytoscape-expand-collapse.js b/cytoscape-expand-collapse.js index d5f27e4..d0609d1 100644 --- a/cytoscape-expand-collapse.js +++ b/cytoscape-expand-collapse.js @@ -21,9 +21,9 @@ var boundingBoxUtilities = { module.exports = boundingBoxUtilities; },{}],2:[function(_dereq_,module,exports){ var debounce = _dereq_('./debounce'); -var elementUtilities; module.exports = function (params, cy, api, $) { + var elementUtilities; var fn = params; var eMouseOver, eMouseOut, ePosition, eRemove, eTap, eZoom, eAdd, eFree; @@ -1361,34 +1361,17 @@ module.exports = expandCollapseUtilities; return; } // can't register if cytoscape unspecified - var expandCollapseUtilities; var undoRedoUtilities = _dereq_('./undoRedoUtilities'); var cueUtilities = _dereq_("./cueUtilities"); - var options = { - 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 - ready: function () { }, // callback when expand/collapse initialized - undoable: true, // and if undoRedoExtension exists, - - cueEnabled: true, // Whether cues are enabled - expandCollapseCuePosition: 'top-left', // default cue position is top left you can specify a function per node too - expandCollapseCueSize: 12, // size of expand-collapse cue - expandCollapseCueLineSize: 8, // size of lines used for drawing plus-minus icons - expandCueImage: undefined, // image of expand icon if undefined draw regular expand cue - collapseCueImage: undefined, // image of collapse icon if undefined draw regular collapse cue - expandCollapseCueSensitivity: 1 // sensitivity of expand-collapse cues - }; - - function setOptions(from) { + function extendOptions(options, extendBy) { var tempOpts = {}; for (var key in options) tempOpts[key] = options[key]; - for (var key in from) + for (var key in extendBy) if (tempOpts.hasOwnProperty(key)) - tempOpts[key] = from[key]; + tempOpts[key] = extendBy[key]; return tempOpts; } @@ -1402,18 +1385,18 @@ module.exports = expandCollapseUtilities; } // creates and returns the API instance for the extension - function createExtensionAPI(cy) { + function createExtensionAPI(cy, expandCollapseUtilities) { var api = {}; // API to be returned // set functions // set all options at once api.setOptions = function(opts) { - options = opts; + setScratch(cy, 'options', options); }; // set the option whose name is given api.setOption = function (name, value) { - options[name] = value; + getScratch(cy, 'options')[name] = value; }; // Collection functions @@ -1421,7 +1404,8 @@ module.exports = expandCollapseUtilities; // collapse given eles extend options with given param api.collapse = function (_eles, opts) { var eles = this.collapsibleNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return expandCollapseUtilities.collapseGivenNodes(eles, tempOptions); @@ -1430,7 +1414,8 @@ module.exports = expandCollapseUtilities; // collapse given eles recursively extend options with given param api.collapseRecursively = function (_eles, opts) { var eles = this.collapsibleNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return this.collapse(eles.union(eles.descendants()), tempOptions); @@ -1439,7 +1424,8 @@ module.exports = expandCollapseUtilities; // expand given eles extend options with given param api.expand = function (_eles, opts) { var eles = this.expandableNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return expandCollapseUtilities.expandGivenNodes(eles, tempOptions); @@ -1448,7 +1434,8 @@ module.exports = expandCollapseUtilities; // expand given eles recusively extend options with given param api.expandRecursively = function (_eles, opts) { var eles = this.expandableNodes(_eles); - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return expandCollapseUtilities.expandAllNodes(eles, tempOptions); @@ -1459,7 +1446,8 @@ module.exports = expandCollapseUtilities; // collapse all collapsible nodes api.collapseAll = function (opts) { - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return this.collapseRecursively(this.collapsibleNodes(), tempOptions); @@ -1467,7 +1455,8 @@ module.exports = expandCollapseUtilities; // expand all expandable nodes api.expandAll = function (opts) { - var tempOptions = setOptions(opts); + var options = getScratch(cy, 'options'); + var tempOptions = extendOptions(options, opts); evalOptions(tempOptions); return this.expandRecursively(this.expandableNodes(), tempOptions); @@ -1554,18 +1543,52 @@ module.exports = expandCollapseUtilities; return api; // Return the API instance } - - var api; // Define the api instance - + + // Get the whole scratchpad reserved for this extension (on an element or core) or get a single property of it + function getScratch (cyOrEle, name) { + if (cyOrEle.scratch('_cyExpandCollapse') === undefined) { + cyOrEle.scratch('_cyExpandCollapse', {}); + } + + var scratch = cyOrEle.scratch('_cyExpandCollapse'); + var retVal = ( name === undefined ) ? scratch : scratch[name]; + return retVal; + } + + // Set a single property on scratchpad of an element or the core + function setScratch (cyOrEle, name, val) { + getScratch(cyOrEle)[name] = val; + } + // register the extension cy.expandCollapse() cytoscape("core", "expandCollapse", function (opts) { + var cy = this; + + var options = getScratch(cy, 'options') || { + 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 + ready: function () { }, // callback when expand/collapse initialized + undoable: true, // and if undoRedoExtension exists, + + cueEnabled: true, // Whether cues are enabled + expandCollapseCuePosition: 'top-left', // default cue position is top left you can specify a function per node too + expandCollapseCueSize: 12, // size of expand-collapse cue + expandCollapseCueLineSize: 8, // size of lines used for drawing plus-minus icons + expandCueImage: undefined, // image of expand icon if undefined draw regular expand cue + collapseCueImage: undefined, // image of collapse icon if undefined draw regular collapse cue + expandCollapseCueSensitivity: 1 // sensitivity of expand-collapse cues + }; + // If opts is not 'get' that is it is a real options object then initilize the extension if (opts !== 'get') { - var cy = this; - options = setOptions(opts); - - expandCollapseUtilities = _dereq_('./expandCollapseUtilities')(cy); - api = createExtensionAPI(cy); // creates and returns the API instance for the extension + options = extendOptions(options, opts); + + var expandCollapseUtilities = _dereq_('./expandCollapseUtilities')(cy); + var api = createExtensionAPI(cy, expandCollapseUtilities); // creates and returns the API instance for the extension + + setScratch(cy, 'api', api); + undoRedoUtilities(cy, api); if(options.cueEnabled) @@ -1573,9 +1596,11 @@ module.exports = expandCollapseUtilities; options.ready(); + + setScratch(cy, 'options', options); } - return api; // Expose the API to the users + return getScratch(cy, 'api'); // Expose the API to the users }); }; @@ -1675,4 +1700,4 @@ module.exports = function (cy, api) { },{}]},{},[6])(6) }); -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvYm91bmRpbmdCb3hVdGlsaXRpZXMuanMiLCJzcmMvY3VlVXRpbGl0aWVzLmpzIiwic3JjL2RlYm91bmNlLmpzIiwic3JjL2VsZW1lbnRVdGlsaXRpZXMuanMiLCJzcmMvZXhwYW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nZhc1xuICAgICAgICAgIC5hdHRyKCdoZWlnaHQnLCAkY29udGFpbmVyLmhlaWdodCgpKVxuICAgICAgICAgIC5hdHRyKCd3aWR0aCcsICRjb250YWluZXIud2lkdGgoKSlcbiAgICAgICAgICAuY3NzKHtcbiAgICAgICAgICAgICdwb3NpdGlvbic6ICdhYnNvbHV0ZScsXG4gICAgICAgICAgICAndG9wJzogMCxcbiAgICAgICAgICAgICdsZWZ0JzogMCxcbiAgICAgICAgICAgICd6LWluZGV4JzogJzk5OSdcbiAgICAgICAgICB9KVxuICAgICAgICA7XG5cbiAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgdmFyIGNhbnZhc0JiID0gJGNhbnZhcy5vZmZzZXQoKTtcbiAgICAgICAgICB2YXIgY29udGFpbmVyQmIgPSAkY29udGFpbmVyLm9mZnNldCgpO1xuXG4gICAgICAgICAgJGNhbnZhc1xuICAgICAgICAgICAgLmNzcyh7XG4gICAgICAgICAgICAgICd0b3AnOiAtKGNhbnZhc0JiLnRvcCAtIGNvbnRhaW5lckJiLnRvcCksXG4gICAgICAgICAgICAgICdsZWZ0JzogLShjYW52YXNCYi5sZWZ0IC0gY29udGFpbmVyQmIubGVmdClcbiAgICAgICAgICAgIH0pXG4gICAgICAgICAgO1xuXG4gICAgICAgICAgLy8gcmVmcmVzaCB0aGUgY3VlcyBvbiBjYW52YXMgcmVzaXplXG4gICAgICAgICAgaWYoY3kpe1xuICAgICAgICAgICAgY2xlYXJEcmF3cyh0cnVlKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0sIDApO1xuXG4gICAgICB9LCAyNTApO1xuXG4gICAgICBmdW5jdGlvbiBzaXplQ2FudmFzKCkge1xuICAgICAgICBfc2l6ZUNhbnZhcygpO1xuICAgICAgfVxuXG4gICAgICBzaXplQ2FudmFzKCk7XG5cbiAgICAgICQod2luZG93KS5iaW5kKCdyZXNpemUnLCBmdW5jdGlvbiAoKSB7XG4gICAgICAgIHNpem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YgKHRpbWVvdXRJZCB8fCAhbGVhZGluZyk7XG5cbiAgICAgIGlmIChtYXhXYWl0ID09PSBmYWxzZSkge1xuICAgICAgICB2YXIgbGVhZGluZ0NhbGwgPSBsZWFkaW5nICYmICF0aW1lb3V0SWQ7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAoIW1heFRpbWVvdXRJZCAmJiAhbGVhZGluZykge1xuICAgICAgICAgIGxhc3RDYWxsZWQgPSBzdGFtcDtcbiAgICAgICAgfVxuICAgICAgICB2YXIgcmVtYWluaW5nID0gbWF4V2FpdCAtIChzdGFtcCAtIGxhc3RDYWxsZWQpLFxuICAgICAgICAgICAgICAgIGlzQ2FsbGVkID0gcmVtYWluaW5nIDw9IDAgfHwgcmVtYWluaW5nID4gbWF4V2FpdDtcblxuICAgICAgICBpZiAoaXNDYWxsZWQpIHtcbiAgICAgICAgICBpZiAobWF4VGltZW91dElkKSB7XG4gICAgICAgICAgICBtYXhUaW1lb3V0SWQgPSBjbGVhclRpbWVvdXQobWF4VGltZW91dElkKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgbGFzdENhbGxlZCA9IHN0YW1wO1xuICAgICAgICAgIHJlc3VsdCA9IGZ1bmMuYXBwbHkodGhpc0FyZywgYXJncyk7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAoIW1heFRpbWVvdXRJZCkge1xuICAgICAgICAgIG1heFRpbWVvdXRJZCA9IHNldFRpbWVvdXQobWF4RGVsYXllZCwgcmVtYWluaW5nKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgaWYgKGlzQ2FsbGVkICYmIHRpbWVvdXRJZCkge1xuICAgICAgICB0aW1lb3V0SWQgPSBjbGVhclRpbWVvdXQodGltZW91dElkKTtcbiAgICAgIH1cbiAgICAgIGVsc2UgaWYgKCF0aW1lb3V0SWQgJiYgd2FpdCAhPT0gbWF4V2FpdCkge1xuICAgICAgICB0aW1lb3V0SWQgPSBzZXRUaW1lb3V0KGRlbGF5Z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