Is there a function that resets the graph to it's freshly loaded state? I've tried cy.reset() but that just resets zoom and pan, not restoring to the virgin graph.
Also is there a way to restore all removed elements?
Thanks!
Is there a function that resets the graph to it's freshly loaded state? I've tried cy.reset() but that just resets zoom and pan, not restoring to the virgin graph.
Also is there a way to restore all removed elements?
Thanks!
Call cy.elements().remove()
and cy.add()
with the same graph data.
cy.elements().remove()
and cy.add()
, but some styling on the nodes is missing. I tried to call cy.style()
and cy.resize()
, but it didn't fix the styling. How do I fix it? –
Orthochromatic Save in a variable the elements you removed, e.g.:
const elsRemoved = cy.elements().remove();
Then, for restoring them simply call:
elsRemoved.restore();
Refer to https://js.cytoscape.org/#eles.restore for more info
With data (here, a .cyjs
file exported from Cytoscape), loaded via a function into Cytoscape.js, and redrawn at the click of a button.
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
</head>
<body>
<div id='cy'></div>
<script>
$.getJSON("ontology2.cyjs", function (data) {
var cy = cytoscape({
container: document.getElementById('cy'),
elements: data.elements,
// ...
});
// Reset graph:
$('button.reset')
.on("click", function() {
cy.remove('node["*"]');
cy.add(data.elements);
});
});
</script>
<button class="reset">Reset</button>
<body>
© 2022 - 2024 — McMap. All rights reserved.