2
votes

I have created a cytoscape.js graph. Users are allowed to click and zoom/drill down on any node to see all the neighboring nodes and edges. I need to add a reset button, that will restore the graph to it's original position, i.e. when the page was first loaded. I have tried using a couple of different functions such as cy.load, forcerender, cy.destroy and recreate graph. Only thing left is to clear the entire object from the dom and add another cytoscape graph object. I would like to know if there is a simple way I can do a redraw or reload the entire graph. I have all the details (original styles/node data) stored in an array.

Thanks

1
node positions are determined by layout calculations, each redraw will give you a different result. you can save the initial x and y of each node and then restore it. or you can supply it with your json data and avoid using a layout - svarog

1 Answers

0
votes

Save the positions and then restore them whenever you want with nodes.positions(): http://js.cytoscape.org/#nodes.positions

Or save the element JSONs and then later restore them: http://js.cytoscape.org/#ele.json