cosmograph-org / cosmos

GPU-accelerated force graph layout and rendering

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to add/remove nodes and links during simulation?

cyremur opened this issue · comments

I am trying to create a simulation where new nodes and links are added / removed as the simulation time progresses (kind of like the time filter option on cosmograph.app, but with manipulating the graph structure instead of just highlighting).

As a test, I tried the following onClick to remove a clicked node:

  events: {
    onClick: (node, i, pos, event) => {
      if (node && i !== undefined) {
        graphNodes = graphNodes.filter(n => n.id !== node.id);
        graphLinks = graphLinks.filter(l => l.source !== node.id && l.target !== node.id);
        graph.setData(graphNodes, graphLinks);
      }
      console.log("Clicked node: ", node);
    },
  },

This works, but it re-renders the whole graph with new random positioning and starts the simulation over, losing temporal cohesion in the graph visualization.

Is this behaviour supported by the library in principle? Is there a way to make sure nodes are removed / added in place without manipulating the position of other nodes in the visualization?

Note: I'm pretty sure stuff like this is possible in d3.js ;)