@ -5,8 +5,8 @@ var Cluster = require('./components/nodes/Cluster').default;
class ClusterEngine {
constructor ( body ) {
this . body = body ;
this . clusteredNodes = { } ;
this . clusteredEdges = { } ;
this . clusteredNodes = { } ; // Set of all nodes which are in a cluster
this . clusteredEdges = { } ; // Set of all edges replaced by a clustering edge
this . options = { } ;
this . defaultOptions = { } ;
@ -60,14 +60,15 @@ class ClusterEngine {
let childEdgesObj = { } ;
// collect the nodes that will be in the cluster
for ( let i = 0 ; i < this . body . nodeIndices . length ; i ++ ) {
let nodeId = this . body . nodeIndices [ i ] ;
for ( let nodeId in this . body . nodes ) {
if ( ! this . body . nodes . hasOwnProperty ( nodeId ) ) continue ;
let node = this . body . nodes [ nodeId ] ;
let clonedOptions = NetworkUtil . cloneOptions ( node ) ;
if ( options . joinCondition ( clonedOptions ) === true ) {
childNodesObj [ nodeId ] = this . body . nodes [ nodeId ] ;
// collect the nod es that will be in the cluster
// collect the edg es that will be in the cluster
for ( let i = 0 ; i < node . edges . length ; i ++ ) {
let edge = node . edges [ i ] ;
if ( this . clusteredEdges [ edge . id ] === undefined ) {
@ -332,7 +333,7 @@ class ClusterEngine {
// hide the replaced edge
this . _backupEdgeOptions ( edge ) ;
edge . setOptions ( { physics : false , hidden : true } ) ;
edge . setOptions ( { physics : false } ) ;
}
}
@ -451,7 +452,7 @@ class ClusterEngine {
// cache the options before changing
this . _backupEdgeOptions ( edge ) ;
// disable physics and hide the edge
edge . setOptions ( { physics : false , hidden : true } ) ;
edge . setOptions ( { physics : false } ) ;
}
}
}
@ -460,7 +461,7 @@ class ClusterEngine {
for ( let nodeId in childNodesObj ) {
if ( childNodesObj . hasOwnProperty ( nodeId ) ) {
this . clusteredNodes [ nodeId ] = { clusterId : clusterNodeProperties . id , node : this . body . nodes [ nodeId ] } ;
this . body . nodes [ nodeId ] . setOptions ( { hidden : true , physics : false } ) ;
this . body . nodes [ nodeId ] . setOptions ( { physics : false } ) ;
}
}
@ -475,14 +476,14 @@ class ClusterEngine {
_backupEdgeOptions ( edge ) {
if ( this . clusteredEdges [ edge . id ] === undefined ) {
this . clusteredEdges [ edge . id ] = { physics : edge . options . physics , hidden : edge . options . hidden } ;
this . clusteredEdges [ edge . id ] = { physics : edge . options . physics } ;
}
}
_restoreEdge ( edge ) {
let originalOptions = this . clusteredEdges [ edge . id ] ;
if ( originalOptions !== undefined ) {
edge . setOptions ( { physics : originalOptions . physics , hidden : originalOptions . hidden } ) ;
edge . setOptions ( { physics : originalOptions . physics } ) ;
delete this . clusteredEdges [ edge . id ] ;
}
}
@ -591,8 +592,7 @@ class ClusterEngine {
containedNode . vx = clusterNode . vx ;
containedNode . vy = clusterNode . vy ;
// we use these methods to avoid re-instantiating the shape, which happens with setOptions.
containedNode . setOptions ( { hidden : false , physics : true } ) ;
containedNode . setOptions ( { physics : true } ) ;
delete this . clusteredNodes [ nodeId ] ;
}
@ -845,6 +845,29 @@ class ClusterEngine {
return hubThreshold ;
} ;
/ * *
* Determine if node with given id is part of a cluster .
*
* @ return { boolean } true if part of a cluster .
* /
_isClusteredNode ( nodeId ) {
return this . clusteredNodes [ nodeId ] !== undefined ;
}
/ * *
* Determine if edge with given id is not visible due to clustering .
*
* An edge is considered clustered if :
* - it is directly replaced by a clustering edge
* - any of its connecting nodes is in a cluster
*
* @ return { boolean } true if part of a cluster .
* /
_isClusteredEdge ( edgeId ) {
return this . clusteredEdges [ edgeId ] !== undefined ;
}
}