'How to remove clustering from vis.js

I have clustering set on a vis.js network diagram. Adding nodes to cluster works. But I cannot remove a node from cluster. I believe the problem is that the first time the code below runs it creates a cluster, after I do some modification to the nodes (e.g. remove node from group) and I run it the second time it keeps the previous cluster and just adds the nodes (if any was added) but doesn't remove them (if any was removed).

So I think that removing all the cluster options and the applying it again should do the trick, but I cant find the way to achieve that.

  const clusterOption = {
    joinCondition: function (childOptions) {
      return childOptions.cid === group.groupId;
    },
    clusterNodeProperties: { 
      id: group.groupId, 
      label: group.label, 
      shape: 'database', 
      allowSingleNodeCluster: true 
    }
  };
  this.network.cluster(clusterOption);

So my idea would be to do something along the following lines (in pseudocode) before calling the above code.

this.network.clearClusters();



Solution 1:[1]

Running this.network.cluster(clusterOption); again seems to work in my experiments (see http://jsfiddle.net/thomaash/t8q37Lsc/, though I adapted one of the examples since you didn't provide MWE). But this may be a bug. It seems to me that the cluster should be updated when the underlying nodes are updated. Do you plan to open an issue (https://github.com/visjs/vis-network/issues/new)?

PS: What version are you using? People sometimes miss an update and then try to solve issues that are resolved in newer versions.

Solution 2:[2]

function decluster() {
    for (index of network.body.nodeIndices) {
        if (network.isCluster(index) == true) {
            network.openCluster(index);
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tomáš Vy?ítal
Solution 2 richardec