0

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.

melborp
  • 1
  • 2
  • This solution deletes a node and it's children (nodes plus edges), and can restore them: https://stackoverflow.com/questions/30490567/collapsing-expanding-compound-node-in-cytoscape/67829648#67829648 – Victoria Stuart Jun 03 '21 at 23:23

1 Answers1

0

If you've restored hidden elements, they'll be hidden when you restore them. Make sure their style is set appropriately.

maxkfranz
  • 11,896
  • 1
  • 27
  • 36