问题
There is a cool sample at Hide nodes with animation by maxfranz.
I am having trouble reverting the state though.
Even if i keep the nodes + edges and then run restore on them. The nodes / edges do not reappear. Add doesnt work. Restore doesnt work. I must be missing something.
On clicking the node i hide (collapse) the linked nodes and I keep the removedElements in an array, and then store in a sratch with node specific namespace. When the node is clicked again, i want to restore (expand) the state on graph.
So i would expect something like this to work:
var tapped = e.cyTarget;
if (cy.scratch(tapped.id() + "_removed")) {
var removedElements = cy.scratch(tapped.id() + "_removed");
for (var i = removedElements.length - 1; i >= 0; i--) {
removedElements[i].restore();
}
}
Note that the order of restoring the edges and nodes to be correct, first adding nodes then edges for them in the reverse order of removal.
回答1:
If you've restored hidden elements, they'll be hidden when you restore them. Make sure their style is set appropriately.
来源:https://stackoverflow.com/questions/33508140/cytoscape-js-hiding-and-restoring-nodes-with-edges-afterwards