Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undo remove nodes operation in Cytoscape JS

When you remove nodes in cytoscape JS (using cy.remove()), the edges attached to these nodes are also deleted from the graph. The description for cy.remove() says it removes elements from the graph and returns them. However, the data that is returned does not include the deleted edges.

As a consequence the following sequence of operations

removedData = cy.remove(someNodes); cy.add(removedData);

do modify the graph, as they could cause some edges to disappear.

How should you perform a reversible removal operation in Cytoscape JS?

like image 233
Waldorf Avatar asked Dec 21 '25 18:12

Waldorf


1 Answers

You could just include the edges explicitly:

removedData = cy.remove(someNodes.union(someNodes.connectedEdges()));

Then both removedData.restore() and cy.add(removedData) will restore both nodes and edges.

like image 54
Suzanne Paley Avatar answered Dec 24 '25 10:12

Suzanne Paley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!