Browse Source

Network: Relax clustering condition for adding already clustered nodes to cluster (#3554)

Previous condition was too strict: if *any* node for the cluster was already clustered, the clustering would abort.

Current fix scans for already clustered nodes and proceeds with what is left.
master
wimrijnders 7 years ago
committed by Yotam Berkowitz
parent
commit
683544c51f
1 changed files with 13 additions and 8 deletions
  1. +13
    -8
      lib/network/modules/Clustering.js

+ 13
- 8
lib/network/modules/Clustering.js View File

@ -524,21 +524,26 @@ class ClusterEngine {
* @private * @private
*/ */
_cluster(childNodesObj, childEdgesObj, options, refreshData = true) { _cluster(childNodesObj, childEdgesObj, options, refreshData = true) {
// kill condition: no nodes don't bother
if (Object.keys(childNodesObj).length == 0) {return;}
// allow clusters of 1 if options allow
if (Object.keys(childNodesObj).length == 1 && options.clusterNodeProperties.allowSingleNodeCluster != true) {return;}
// check if this cluster call is not trying to cluster anything that is in another cluster.
// Remove nodes which are already clustered
var tmpNodesToRemove = []
for (let nodeId in childNodesObj) { for (let nodeId in childNodesObj) {
if (childNodesObj.hasOwnProperty(nodeId)) { if (childNodesObj.hasOwnProperty(nodeId)) {
if (this.clusteredNodes[nodeId] !== undefined) { if (this.clusteredNodes[nodeId] !== undefined) {
return;
tmpNodesToRemove.push(nodeId);
} }
} }
} }
for (var n = 0; n < tmpNodesToRemove.length; ++n) {
delete childNodesObj[tmpNodesToRemove[n]];
}
// kill condition: no nodes don't bother
if (Object.keys(childNodesObj).length == 0) {return;}
// allow clusters of 1 if options allow
if (Object.keys(childNodesObj).length == 1 && options.clusterNodeProperties.allowSingleNodeCluster != true) {return;}
let clusterNodeProperties = util.deepExtend({},options.clusterNodeProperties); let clusterNodeProperties = util.deepExtend({},options.clusterNodeProperties);
// construct the clusterNodeProperties // construct the clusterNodeProperties

Loading…
Cancel
Save