John
John

Reputation: 83

Layout that handles adding nodes dynamically (cytoscape.js)

Here is an example of what I'm doing:

function showNeighbors(ele) {
  cy.add(this.cyData.getElementById(ele.id()).neighborhood());
  cy.elements().layout(layoutOpts);
}

This is the only why I can find to add the new nodes to the layout. I would like to add nodes similar to how D3 does by having a .enter() function or some way to add nodes to the current layout. Is this possible in Cytoscape.js?

Upvotes: 6

Views: 4753

Answers (1)

maxkfranz
maxkfranz

Reputation: 12250

If the layout supports smooth transitioning (like Cola), just stop the layout on the old elements and start a new layout on the entire graph (including the new element): layout.stop(); layout = cy.elements().makeLayout(...); layout.run();

http://js.cytoscape.org/#layouts/layout-manipulation

If the layout doesn't support smooth transitioning, then it will still work but the animation won't necessary be smooth (e.g. a node may initially jump).

Upvotes: 6

Related Questions