Skip to content

Commit

Permalink
Fix #69
Browse files Browse the repository at this point in the history
Instead of keeping parent info of all children at initialization, we keep info of only removed ones.
This fixes the error on the newly added nodes.
  • Loading branch information
hasanbalci committed Jul 26, 2019
1 parent cdde6f6 commit 5385d84
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
27 changes: 18 additions & 9 deletions cytoscape-expand-collapse.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/expandCollapseUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ return {
node.removeClass('cy-expand-collapse-collapsed-node');

node.trigger("expandcollapse.beforeexpand");
node._private.data.collapsedChildren.restore();
var restoredNodes = node._private.data.collapsedChildren;
restoredNodes.restore();
var parentData = cy.scratch('_cyExpandCollapse').parentData;
for(var i = 0; i < restoredNodes.length; i++){
delete parentData[restoredNodes[i].id()];
}
cy.scratch('_cyExpandCollapse').parentData = parentData;
this.repairEdges(node);
node._private.data.collapsedChildren = null;

Expand Down Expand Up @@ -554,6 +560,9 @@ return {
for (var i = 0; i < children.length; i++) {
var child = children[i];
this.removeChildren(child, root);
var parentData = cy.scratch('_cyExpandCollapse').parentData;
parentData[child.id()] = child.parent();
cy.scratch('_cyExpandCollapse').parentData = parentData;
var removedChild = child.remove();
if (root._private.data.collapsedChildren == null) {
root._private.data.collapsedChildren = removedChild;
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@
};

api.getParent = function(nodeId) {
var parentData = getScratch(cy, 'parentData');
return parentData[nodeId];
if(cy.getElementById(nodeId)[0] === undefined){
var parentData = getScratch(cy, 'parentData');
return parentData[nodeId];
}
else{
return cy.getElementById(nodeId).parent();
}
};

// This method works problematic TODO fix related bugs and expose it
Expand Down Expand Up @@ -252,11 +257,6 @@
setScratch(cy, 'options', options);

var parentData = {};
var children = cy.nodes(':child');
for(var i = 0; i < children.length; i++){
var node = children[i];
parentData[node.id()] = node.parent();
}
setScratch(cy, 'parentData', parentData);
}

Expand Down

0 comments on commit 5385d84

Please sign in to comment.