question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rerunning layout with compound nodes resets positions

See original GitHub issue

Some context: I am rendering a graph which receives updates via a websocket connection. My goal is to add nodes at runtime and add them to the existing rendering of cytoscape. This should happen without a fully restarted layout which would update all positions, which would be very confusing for users.

This example from webcola is pretty spot-on, since it adds nodes/edges at runtime (by clicking), but mostly keeps the already positioned nodes at their old position.

I am trying to add nodes to the the cytoscape instance at runtime, but layout.run() will only change the existing nodes.

I tried to work around that fact by doing:

var layout = cytoscapeInstance.makeLayout({name: 'cola', .... options... });

// receive updated elements from websocket
// ... later:

layout.options.eles = cytoscapeInstance.elements();
layout.run()

This kind of works, but it will restart the rendering from the beginning and will ignore the existing state of the layout. This it is the same as when I completely reinitialize cytoscape with the new data. Users have no way to follow the update animations, so they will not be able to keep track of what position the node has they just looked at.

The problem seems to be that webcola gets its own set of objects which are only calculated by using .run(). Since the transformation methods (from cytoscapes data structure to colas) are not public there is no way to work around this. Otherwise I could probably do the transformations on the new data myself and then call layout.adaptor.resume().

Any ideas on how to solve this properly?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
felixfbeckercommented, May 15, 2017

I am (if I didn’t, the all new elements would just sit in the top left corner):


let layout: Cy.LayoutInstance;
getElements().subscribe(el => {
    console.log('add', el);
    if (layout) {
        layout.stop();
    }
    layout = graph.elements().makeLayout(layoutOptions);
    graph.add(el);
    layout.run();
});
1reaction
EyMaddiscommented, Sep 7, 2016

But the problem is that the layout starts of by spreading out the nodes, as it should, but another call to makeLayout(sameOptions) and then run() it will ditch the previously calculated positions of nodes completely and restart from scratch. I tried to set the positions of the nodes, but it does not matter since (I think) this line will override all positions each time run is called. Since it is beginning again and I now have new nodes added, the layout changes completely. In your example it does not matter as the same nodes are layouted, which results in the same layout everytime (with slight variations due to the sliders).

Read more comments on GitHub >

github_iconTop Results From Across the Web

cytoscape.js compound nodes ignoring layout? - Stack Overflow
I've tried running the layout on just the parents by assigning classes and passing layout() the sub-Graph and then just running grid on...
Read more >
Using layouts - Cytoscape.js
A discrete layout sets node positions all at once. The nodes go immediately from their previous positions to their resultant layout ...
Read more >
Add and remove nodes in your cluster | Elasticsearch Guide [8.5]
As nodes join or leave a cluster, the cluster automatically reorganizes itself to evenly distribute the data across the available nodes. If you...
Read more >
An algorithm for automated layout of process description maps ...
Cellular locations of processes are not shown in the map. ... CoSE is a force-directed layout algorithm that supports compound nodes (Dogrusoz et...
Read more >
Forcing Functions: Inside D3.v4 forces and layout transitions
v3. Set alphaTarget to a relatively low number when updating a layout, and node positions will update smoothly instead of suddenly jumping to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found