Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/unstable'
Browse files Browse the repository at this point in the history
  • Loading branch information
kinimesi committed Dec 19, 2017
2 parents 5639c75 + 2777d4c commit 886699f
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 79 deletions.
105 changes: 65 additions & 40 deletions cytoscape-expand-collapse.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cueUtilities.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
101 changes: 63 additions & 38 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -50,26 +33,27 @@
}

// 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

// 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -107,15 +94,17 @@

// 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);
};

// 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);
Expand Down Expand Up @@ -202,28 +191,64 @@

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)
cueUtilities(options, cy, api, $);


options.ready();

setScratch(cy, 'options', options);
}

return api; // Expose the API to the users
return getScratch(cy, 'api'); // Expose the API to the users
});
};

Expand Down

0 comments on commit 886699f

Please sign in to comment.