diff --git a/README.md b/README.md index 2785ac9..d0f6c1b 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,12 @@ Collapse all edges in the graph. `api.expandAllEdges()` Expand all edges in the graph. +`api.loadJson(jsonStr)` +Load elements from JSON string. + +`api.saveJson(elems, filename)` +Saves elements in JSON format to a file. Default value for `elems` is all the elements. Default value for `filename` is 'expand-collapse-output.json' + ## 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. diff --git a/cytoscape-expand-collapse.js b/cytoscape-expand-collapse.js index d65f5dd..582e7d4 100644 --- a/cytoscape-expand-collapse.js +++ b/cytoscape-expand-collapse.js @@ -2017,6 +2017,13 @@ module.exports = expandCollapseUtilities; },{"./cueUtilities":2,"./expandCollapseUtilities":6,"./saveLoadUtilities":8,"./undoRedoUtilities":9}],8:[function(_dereq_,module,exports){ function saveLoadUtilities(cy, api) { + /** converts array of JSON to a cytoscape.js collection (bottom-up recursive) + * keeps information about parents, all nodes added to cytoscape, and nodes to be collapsed + * @param {} jsonArr an array of objects (a JSON array) + * @param {} allNodes a cytoscape.js collection + * @param {} nodes2collapse a cytoscape.js collection + * @param {} node2parent a JS object (simply key-value pairs) + */ function json2cyCollection(jsonArr, allNodes, nodes2collapse, node2parent) { // process edges last since they depend on nodes jsonArr.sort((a) => { @@ -2067,6 +2074,9 @@ function saveLoadUtilities(cy, api) { return coll; } + /** clears all the data related to collapsed node + * @param {} e a cytoscape element + */ function clearCollapseMetaData(e) { e.data('collapsedChildren', null); e.removeClass('cy-expand-collapse-collapsed-node'); @@ -2077,6 +2087,9 @@ function saveLoadUtilities(cy, api) { e.data('expandcollapseRenderedCueSize', null); } + /** converts cytoscape collection to JSON array.(bottom-up recursive) + * @param {} elems + */ function cyCollection2Json(elems) { let r = []; for (let i = 0; i < elems.length; i++) { @@ -2102,7 +2115,10 @@ function saveLoadUtilities(cy, api) { return r; } - // { cy: any, collapsedEdges: any, collapsedChildren: any, originalEnds: any }[] + /** returns { cy: any, collapsedEdges: any, collapsedChildren: any, originalEnds: any }[] + * from cytoscape collection + * @param {} col + */ function halfDeepCopyCollection(col) { let arr = []; for (let i = 0; i < col.length; i++) { @@ -2127,6 +2143,13 @@ function saveLoadUtilities(cy, api) { } return { + + /** Load elements from JSON formatted string representation. + * For collapsed compounds, first add all collapsed nodes as normal nodes then collapse them. Then reposition them. + * For collapsed edges, first add all of the edges then remove collapsed edges from cytoscape. + * For original ends, restore their reference to cytoscape elements + * @param {} txt string + */ loadJson: function (txt) { const fileJSON = JSON.parse(txt); // original endpoints won't exist in cy. So keep a reference. @@ -2179,6 +2202,12 @@ function saveLoadUtilities(cy, api) { cy.fit(); }, + + /** saves cytoscape elements (collection) as JSON + * calls elements' json method (https://js.cytoscape.org/#ele.json) when we keep a cytoscape element in the data. + * @param {} elems cytoscape collection + * @param {} filename string + */ saveJson: function (elems, filename) { if (!elems) { elems = cy.$(); @@ -2456,4 +2485,4 @@ module.exports = function (cy, api) { },{}]},{},[7])(7) }); -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvYm91bmRpbmdCb3hVdGlsaXRpZXMuanMiLCJzcmMvY3VlVXRpbGl0aWVzLmpzIiwic3JjL2RlYm91bmNlLmpzIiwic3JjL2RlYm91bmNlMi5qcyIsInNyYy9lbGVtZW50VXRpbGl0aWVzLmpzIiwic3JjL2V4cGFuZENvbGxhcHNlVXRpbGl0aWVzLmpzIiwic3JjL2luZGV4LmpzIiwic3JjL3NhdmVMb2FkVXRpbGl0aWVzLmpzIiwic3JjL3VuZG9SZWRvVXRpbGl0aWVzLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0FDQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FB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aXplICogZmFjdG9yXG4gICAgICAgICAgJiYgY3lSZW5kZXJlZFBvc1kgPj0gZXhwYW5kY29sbGFwc2VSZW5kZXJlZFN0YXJ0WSAtIGV4cGFuZGNvbGxhcHNlUmVuZGVyZWRSZWN0U2l6ZSAqIGZhY3RvclxuICAgICAgICAgICYmIGN5UmVuZGVyZWRQb3NZIDw9IGV4cGFuZGNvbGxhcHNlUmVuZGVyZWRFbmRZICsgZXhwYW5kY29sbGFwc2VSZW5kZXJlZFJlY3RTaXplICogZmFjdG9yKSB7XG4gICAgICAgICAgaWYgKG9wdHMudW5kb2FibGUgJiYgIXVyKSB7XG4gICAgICAgICAgICB1ciA9IGN5LnVuZG9SZWRvKHsgZGVmYXVsdEFjdGlvbnM6IGZhbHNlIH0pO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmIChhcGkuaXNDb2xsYXBzaWJsZShub2RlKSkge1xuICAgICAgICAgICAgY2xlYXJEcmF3cygpO1xuICAgICAgICAgICAgaWYgKG9wdHMudW5kb2FibGUpIHtcbiAgICAgICAgICAgICAgdXIuZG8oXCJjb2xsYXBzZVwiLCB7XG4gICAgICAgICAgICAgICAgbm9kZXM6IG5vZGUsXG4gICAgICAgICAgICAgICAgb3B0aW9uczogb3B0c1xuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICBhcGkuY29sbGFwc2Uobm9kZSwgb3B0cyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGVsc2UgaWYgKGFwaS5pc0V4cGFuZGFibGUobm9kZSkpIHtcbiAgICAgICAgICAgIGNsZWFyRHJhd3MoKTtcbiAgICAgICAgICAgIGlmIChvcHRzLnVuZG9hYmxlKSB7XG4gICAgICAgICAgICAgIHVyLmRvKFwiZXhwYW5kXCIsIHsgbm9kZXM6IG5vZGUsIG9wdGlvbnM6IG9wdHMgfSk7XG4gICAgICAgICAgICB9XG4gICA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tIHBhcnNlRmxvYXQobm9kZS5jc3MoJ3BhZGRpbmctdG9wJykpXHJcbiAgICAgICAgICAgICsgbm9kZUJvcmRlcldpZCArIHNpemUgKyBvZmZzZXQ7XHJcblxyXG4gICAgICAgICAgY3VlQ2VudGVyID0geyB4OiB4LCB5OiB5IH07XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgIHZhciBvcHRpb24gPSBvcHRpb25zKCkuZXhwYW5kQ29sbGFwc2VDdWVQb3NpdGlvbjtcclxuICAgICAgICAgIGN1ZUNlbnRlciA9IHR5cGVvZiBvcHRpb24gPT09ICdmdW5jdGlvbicgPyBvcHRpb24uY2FsbCh0aGlzLCBub2RlKSA6IG9wdGlvbjtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHZhciBleHBhbmRjb2xsYXBzZUNlbnRlciA9IGVsZW1lbnRVdGlsaXRpZXMuY29udmVydFRvUmVuZGVyZWRQb3NpdGlvbihjdWVDZW50ZXIpO1xyXG5cclxuICAgICAgICAvLyBjb252ZXJ0IHRvIHJlbmRlcmVkIHNpemVzXHJcbiAgICAgICAgcmVjdFNpemUgPSBNYXRoLm1heChyZWN0U2l6ZSwgcmVjdFNpemUgKiBjeS56b29tKCkpO1xyXG4gICAgICAgIGxpbmVTaXplID0gTWF0aC5tYXgobGluZVNpemUsIGxpbmVTaXplICogY3kuem9vbSgpKTtcclxuICAgICAgICB2YXIgZGlmZiA9IChyZWN0U2l6ZSAtIGxpbmVTaXplKSAvIDI7XHJcblxyXG4gICAgICAgIHZhciBleHBhbmRjb2xsYXBzZUNlbnRlclggPSBleHBhbmRjb2xsYXBzZUNlbnRlci54O1xyXG4gICAgICAgIHZhciBleHBhbmRjb2xsYXBzZUNlbnRlclkgPSBleHBhbmRjb2xsYXBzZUNlbnRlci55O1xyXG5cclxuICAgICAgICB2YXIgZXhwYW5kY29sbGFwc2VTdGFydFggPSBleHBhbmRjb2xsYXBzZUNlbnRlclggLSByZWN0U2l6ZSAvIDI7XH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C0gZXhwYW5kY29sbGFwc2VSZW5kZXJlZFJlY3RTaXplICogZmFjdG9yXHJcbiAgICAgICAgICAmJiBjeVJlbmRlcmVkUG9zWSA8PSBleHBhbmRjb2xsYXBzZVJlbmRlcmVkRW5kWSArIGV4cGFuZGNvbGxhcHNlUmVuZGVyZWRSZWN0U2l6ZSAqIGZhY3Rvcikge1xyXG4gICAgICAgICAgaWYgKG9wdHMudW5kb2FibGUgJiYgIXVyKSB7XHJcbiAgICAgICAgICAgIHVyID0gY3kudW5kb1JlZG8oeyBkZWZhdWx0QWN0aW9uczogZmFsc2UgfSk7XHJcbiAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgaWYgKGFwaS5pc0NvbGxhcHNpYmxlKG5vZGUpKSB7XHJcbiAgICAgICAgICAgIGNsZWFyRHJhd3MoKTtcclxuICAgICAgICAgICAgaWYgKG9wdHMudW5kb2FibGUpIHtcclxuICAgICAgICAgICAgICB1ci5kbyhcImNvbGxhcHNlXCIsIHtcclxuICAgICAgICAgICAgICAgIG5vZGVzOiBub2RlLFxyXG4gICAgICAgICAgICAgICAgb3B0aW9uczogb3B0c1xyXG4gICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIGVsc2Uge1xyXG4gICAgICAgICAgICAgIGFwaS5jb2xsYXBzZShub2RlLCBvcHRzKTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG4gICAgICAgICAgZWxzZSBpZiAoYXBpLmlzRXhwYW5kYWJsZShub2RlKSkge1xyXG4gICAgICAgICAgICBjbGVhckRyYXdzKCk7XHJcbiAgICAgICAgICAgIGlmIChvcHRzLnVuZG9hYmxlKSB7XHJcbiAgICAgICAgICAgICAgdXIuZG8oXCJleHBhbmRcIiwgeyBub2Rlczogbm9kZSwgb3B0aW9uczogb3B0cyB9KTtcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBlbHNlIHtcclxuICAgICAgICAgICAgICBhcGkuZXhw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pb25zLnRyYWlsaW5nIDogdHJhaWxpbmc7XHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gY2FuY2VsKCkge1xyXG4gICAgICBpZiAodGltZW91dElkKSB7XHJcbiAgICAgICAgY2xlYXJUaW1lb3V0KHRpbWVvdXRJZCk7XHJcbiAgICAgIH1cclxuICAgICAgaWYgKG1heFRpbWVvdXRJZCkge1xyXG4gICAgICAgIGNsZWFyVGltZW91dChtYXhUaW1lb3V0SWQpO1xyXG4gICAgICB9XHJcbiAgICAgIGxhc3RDYWxsZWQgPSAwO1xyXG4gICAgICBtYXhUaW1lb3V0SWQgPSB0aW1lb3V0SWQgPSB0cmFpbGluZ0NhbGwgPSB1bmRlZmluZWQ7XHJcbiAgICB9XHJcblxyXG4gICAgZnVuY3Rpb24gY29tcGxldGUoaXNDYWxsZWQsIGlkKSB7XHJcbiAgICAgIGlmIChpZCkge1xyXG4gICAgICAgIGNsZWFyVGltZW91dChpZCk7XHJcbiAgICAgIH1cclxuICAgICAgbWF4VGltZW91dElkID0gdGltZW91dElkID0gdHJhaWxpbmdDYWxsID0gdW5kZWZpbmVkO1xyXG4gICAgICBpZiAoaXNDYWxsZWQpIHtcclxuICAgICAgICBsYXN0Q2FsbGVkID0gbm93KCk7XHJcbiAgICAgICAgcmVzdWx0ID0gZnVuYy5hcHBseSh0aGlzQXJnLCBhcmdzKTtcclxuICAgICAgICBpZiAoIXRpbWVvdXRJZCAmJiAhbWF4VGltZW91dElkKSB7XHJcbiAgICAgICAgICBhcmdzID0gdGhpc0FyZyA9IHVuZGVmaW5lZDtcclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuICAgIH1cclxuXHJcbiAgICBmdW5jdGlvbiBkZWxheWVkKCkge1xyXG4gICAgICB2YXIgcmVtYWluaW5nID0gd2FpdCAtIChub3coKSAtIHN0YW1wKTtcclxuICAgICAgaWYgKHJlbWFpbmluZyA8PSAwIHx8IHJlbWFpbmluZyA+IHdhaXQpIHtcclxuICAgICAgICB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JCLCAxMCk7XHJcbiAgICAgICAgICB2YXIgc2VsZiA9IHRoaXM7XHJcbiAgICAgICAgICBhbmltYXRpbmcgPSBhbmltYXRlOyAvLyBTaWduYWwgdGhhdCB0aGVyZSBpcyBhbiBhbmltYXRpb24gbm93IGFuZCBjb21tb25FeHBhbmRPcGVyYXRpb24gd2lsbCBiZSBjYWxsZWQgYWZ0ZXIgYW5pbWF0aW9uXHJcbiAgICAgICAgICAvLyBDaGVjayBpZiB3ZSBuZWVkIHRvIGFuaW1hdGUgZHVyaW5nIHBhbiBhbmQgem9vbVxyXG4gICAgICAgICAgaWYgKGFuaW1hdGUpIHtcclxuICAgICAgICAgICAgY3kuYW5pbWF0ZSh7XHJcbiAgICAgICAgICAgICAgcGFuOiB2aWV3UG9ydC5wYW4sXHJcbiAgICAgICAgICAgICAgem9vbTogdmlld1BvcnQuem9vbSxcclxuICAgICAgICAgICAgICBjb21wbGV0ZTogZnVuY3Rpb24gKCkge1xyXG4gICAgICAgICAgICAgICAgY29tbW9uRXhwYW5kT3BlcmF0aW9uKG5vZGUsIGFwcGx5RmlzaEV5ZVZpZXcsIHNpbmdsZSwgYW5pbWF0ZSwgbGF5b3V0QnksIGFuaW1hdGlvbkR1cmF0aW9uKTtcclxuICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0sIHtcclxuICAgICAgICAgICAgICBkdXJhdGlvbjogYW5pbWF0aW9uRHVyYXRpb24gfHwgMTAwMFxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICAgIH1cclxuICAgICAgICAgIGVsc2Uge1xyXG4gICAgICAgICAgICBjeS56b29tKHZpZXdQb3J0Lnpvb20pO1xyXG4gICAgICAgICAgICBjeS5wYW4odmlld1BvcnQucGFuKTtcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuICAgICAgXHJcbiAgICAgIC8vIElmIGFuaW1hdGluZyBpcyBub3QgdHJ1ZSB3ZSBuZWVkIHRvIGNhbGwgY29tbW9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RpZmZfb25feTtcclxuICAgICAgZF95X2xvd2VyID0gZF95X2xvd2VyIC0gYWJzX2RpZmZfb25feTtcclxuICAgIH1cclxuICAgIC8vIENlbnRlciB3ZW50IHRvIERPV05cclxuICAgIGVsc2Uge1xyXG4gICAgICBkX3lfdXBwZXIgPSBkX3lfdXBwZXIgLSBhYnNfZGlmZl9vbl95O1xyXG4gICAgICBkX3lfbG93ZXIgPSBkX3lfbG93ZXIgKyBhYnNfZGlmZl9vbl95O1xyXG4gICAgfVxyXG5cclxuICAgIHZhciB4UG9zSW5QYXJlbnRTaWJsaW5nID0gW107XHJcbiAgICB2YXIgeVBvc0luUGFyZW50U2libGluZyA9IFtdO1xyXG5cclxuICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc2libGluZ3MubGVuZ3RoOyBpKyspIHtcclxuICAgICAgeFBvc0luUGFyZW50U2libGluZy5wdXNoKHRoaXMueFBvc2l0aW9uSW5QYXJlbnQoc2libGluZ3NbaV0pKTtcclxuICAgICAgeVBvc0luUGFyZW50U2libGluZy5wdXNoKHRoaXMueVBvc2l0aW9uSW5QYXJlbnQoc2libGluZ3NbaV0pKTtcclxuICAgIH1cclxuXHJcbiAgICBmb3IgKHZhciBpID0gMDsgaSA8IHNpYmxpbmdzLmxlbmd0aDsgaSsrKSB7XHJcbiAgICAgIHZhciBzaWJsaW5nID0gc2libGluZ3NbaV07XHJcblxyXG4gICAgICB2YXIgeF9iID0geFBvc0luUGFyZW50U2libGluZ1tpXTtcclxuICAgICAgdmFyIHlfYiA9IHlQb3NJblBhcmVudFNpYmxpbmdbaV07XHJcblxyXG4gICAgICB2YXIgc2xvcGUgPSAoeV9iIC0geV9hKSAvICh4X2IgLSB4X2EpO1xyXG5cclxuICAgICAgdmFyIGRfeCA9IDA7XHJcbiAgICAgIHZhciBkX3kgPSAwO1xyXG4gICAgICB2YXIgVF94ID0gMDtcclxuICAgICAgdmFyIFRfeSA9IDA7XHJcblxyXG4gICAgICAvLyBDdXJyZW50IHNpYmxpbmcgaXMgb24gdGhlIExFRlRcclxuICAgICAgaWYgKHhfYSA+IHhfYikge1xyXG4gICAgICAgIGRfeCA9IGRfeF9sZWZ0O1xyXG4gICAgICB9XHJcbiAgICAgIC8vIEN1cnJlbnQgc2libGluZyBpcyBvbiB0aGUgUklHSFRcclxuICAgICAgZWxzZSB7XHJcbiAgICAgICAgZF94ID0gZF94X3JpZ2h0O1xyXG4gICAgICB9XHJcbiAgICAgIC8vIEN1cnJlbnQgc2libGluZyBpcyBvbiB0aGUgVVBQRVIgc2lkZVxyXG4gICAgICBpZiAoeV9hID4geV9iKSB7XHJcbiAgICAgICAgZF95ID0gZF95X3VwcGVyO1xyXG4gICAgICB9XHJcbiAgICAgIC8vIEN1cnJlbnQgc2libGluZyBpcyBvbiB0aGUgTE9XRVIgc2lkZVxyXG4gICAgICBlbHNlIHtcclxuICAgICAgICBkX3kgPSBkX3lfbG93ZXI7XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIGlmIChpc0Zpbml0ZShzbG9wZSkpIHtcclxuICAgICAgICBUX3ggPSBNYXRoLm1pbihkX3gsIChkX3kgLyBNYXRoLmFicyhzbG9wZSkpKTtcclxuICAgICAgfVxyXG5cclxuICAgICAgaWYgKHNsb3BlICE9PSAwKSB7XHJcbiAgICAgICAgVF95ID0gTWF0aC5taW4oZF95LCAoZF94ICogTWF0aC5hYnMoc2xvcGUpKSk7XHJcbiAgICAgIH1cclxuXHJcbiAgICAgIGlmICh4X2EgPiB4X2IpIHtcclxuICAgICAgICBUX3ggPSAtMSAqIFRfeDtcclxuICAgICAgfVxyXG5cclxuICAgICAgaWYgKHlfYSA+IHlfYikge1xyXG4gICAgICAgIFRfeSA9IC0xICogVF95O1xyXG4gICAgICB9XHJcbiAgICAgIFxyXG4gICAgICAvLyBNb3ZlIHRoZSBzaWJsaW5nIGluIHRoZSBzcGVjaWFsIHdheVxyXG4gICAgICB0aGlzLmZpc2hFeWVWaWV3TW92ZU5vZGUoc2libGluZywgVF94LCB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XHJcbiAgICAgIGFwaS5leHBhbmRFZGdlc0JldHdlZW5Ob2RlcyA9IGZ1bmN0aW9uIChub2Rlcykge1xyXG4gICAgICAgIHZhciBlZGdlc1RvRXhwYW5kID0gY3kuY29sbGVjdGlvbigpO1xyXG4gICAgICAgIGZ1bmN0aW9uIHBhaXJ3aXNlKGxpc3QpIHtcclxuICAgICAgICAgIHZhciBwYWlycyA9IFtdO1xyXG4gICAgICAgICAgbGlzdFxyXG4gICAgICAgICAgICAuc2xpY2UoMCwgbGlzdC5sZW5ndGggLSAxKVxyXG4gICAgICAgICAgICAuZm9yRWFjaChmdW5jdGlvbiAoZmlyc3QsIG4pIHtcclxuICAgICAgICAgICAgICB2YXIgdGFpbCA9IGxpc3Quc2xpY2UobiArIDEsIGxpc3QubGVuZ3RoKTtcclxuICAgICAgICAgICAgICB0YWlsLmZvckVhY2goZnVuY3Rpb24gKGl0ZW0pIHtcclxuICAgICAgICAgICAgICAgIHBhaXJzLnB1c2goW2ZpcnN0LCBpdGVtXSlcclxuICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSlcclxuICAgICAgICAgIHJldHVybiBwYWlycztcclxuICAgICAgICB9XHJcbiAgICAgICAgdmFyIG5vZGVzUGFpcnMgPSBwYWlyd2lzZShub2Rlcyk7XHJcbiAgICAgICAgLy8gZm9yIHNlbGYtbG9vcHNcclxuICAgICAgICBub2Rlc1BhaXJzLnB1c2goLi4ubm9kZXMubWFwKHggPT4gW3gsIHhdKSk7XHJcbiAgICAgICAgbm9kZXNQYWlycy5mb3JFYWNoKGZ1bmN0aW9uIChub2RlUGFpcikge1xyXG4gICAgICAgICAgY29uc3QgaWQxID0gbm9kZVBhaXJbMV0uaWQoKTtcclxuICAgICAgICAgIHZhciBlZGdlcyA9IG5vZGVQYWlyWzBdLmNvbm5lY3RlZEVkZ2VzKCcuY3ktZXhwYW5kLWNvbGxhcHNlLWNvbGxhcHNlZC1lZGdlW3NvdXJjZSA9IFwiJyArIGlkMSArICd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FZGdlcywgY29sbGFwc2VBbGxFZGdlcyk7XHJcblxyXG4gXHJcblxyXG5cclxuICBcclxuXHJcblxyXG59O1xyXG4iXX0= diff --git a/package.json b/package.json index b7f0cfb..217edea 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "main": "cytoscape-expand-collapse.js" }, "scripts": { + "build": "echo 'node version must be 10!' && gulp build", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { diff --git a/src/saveLoadUtilities.js b/src/saveLoadUtilities.js index 74625b7..e0fcc80 100644 --- a/src/saveLoadUtilities.js +++ b/src/saveLoadUtilities.js @@ -1,4 +1,11 @@ function saveLoadUtilities(cy, api) { + /** converts array of JSON to a cytoscape.js collection (bottom-up recursive) + * keeps information about parents, all nodes added to cytoscape, and nodes to be collapsed + * @param {} jsonArr an array of objects (a JSON array) + * @param {} allNodes a cytoscape.js collection + * @param {} nodes2collapse a cytoscape.js collection + * @param {} node2parent a JS object (simply key-value pairs) + */ function json2cyCollection(jsonArr, allNodes, nodes2collapse, node2parent) { // process edges last since they depend on nodes jsonArr.sort((a) => { @@ -49,6 +56,9 @@ function saveLoadUtilities(cy, api) { return coll; } + /** clears all the data related to collapsed node + * @param {} e a cytoscape element + */ function clearCollapseMetaData(e) { e.data('collapsedChildren', null); e.removeClass('cy-expand-collapse-collapsed-node'); @@ -59,6 +69,9 @@ function saveLoadUtilities(cy, api) { e.data('expandcollapseRenderedCueSize', null); } + /** converts cytoscape collection to JSON array.(bottom-up recursive) + * @param {} elems + */ function cyCollection2Json(elems) { let r = []; for (let i = 0; i < elems.length; i++) { @@ -84,7 +97,10 @@ function saveLoadUtilities(cy, api) { return r; } - // { cy: any, collapsedEdges: any, collapsedChildren: any, originalEnds: any }[] + /** returns { cy: any, collapsedEdges: any, collapsedChildren: any, originalEnds: any }[] + * from cytoscape collection + * @param {} col + */ function halfDeepCopyCollection(col) { let arr = []; for (let i = 0; i < col.length; i++) { @@ -109,6 +125,13 @@ function saveLoadUtilities(cy, api) { } return { + + /** Load elements from JSON formatted string representation. + * For collapsed compounds, first add all collapsed nodes as normal nodes then collapse them. Then reposition them. + * For collapsed edges, first add all of the edges then remove collapsed edges from cytoscape. + * For original ends, restore their reference to cytoscape elements + * @param {} txt string + */ loadJson: function (txt) { const fileJSON = JSON.parse(txt); // original endpoints won't exist in cy. So keep a reference. @@ -161,6 +184,12 @@ function saveLoadUtilities(cy, api) { cy.fit(); }, + + /** saves cytoscape elements (collection) as JSON + * calls elements' json method (https://js.cytoscape.org/#ele.json) when we keep a cytoscape element in the data. + * @param {} elems cytoscape collection + * @param {} filename string + */ saveJson: function (elems, filename) { if (!elems) { elems = cy.$();