Browse Source

Some more fixes regarding custom id fields

codeClimate
jos 8 years ago
parent
commit
a95aa84b18
2 changed files with 15 additions and 11 deletions
  1. +13
    -9
      lib/network/modules/Clustering.js
  2. +2
    -2
      lib/network/modules/components/nodes/Cluster.js

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

@ -258,6 +258,8 @@ class ClusterEngine {
*/
_createClusterEdges (childNodesObj, childEdgesObj, clusterNodeProperties, clusterEdgeProperties) {
let edge, childNodeId, childNode, toId, fromId, otherNodeId;
let nodeIdField = this.body.data.nodes._fieldId;
let edgeIdField = this.body.data.edges._fieldId;
// loop over all child nodes and their edges to find edges going out of the cluster
// these edges will be replaced by clusterEdges.
@ -279,13 +281,13 @@ class ClusterEngine {
else {
// set up the from and to.
if (edge.toId == childNodeId) { // this is a double equals because ints and strings can be interchanged here.
toId = clusterNodeProperties.id;
toId = clusterNodeProperties[nodeIdField];
fromId = edge.fromId;
otherNodeId = fromId;
}
else {
toId = edge.toId;
fromId = clusterNodeProperties.id;
fromId = clusterNodeProperties[nodeIdField];
otherNodeId = toId;
}
}
@ -310,7 +312,7 @@ class ClusterEngine {
// set up the edge
clonedOptions.from = createEdges[j].fromId;
clonedOptions.to = createEdges[j].toId;
clonedOptions.id = 'clusterEdge:' + util.randomUUID();
clonedOptions[edgeIdField] = 'clusterEdge:' + util.randomUUID();
//clonedOptions.id = '(cf: ' + createEdges[j].fromId + " to: " + createEdges[j].toId + ")" + Math.random();
// create the edge and give a reference to the one it replaced.
@ -351,6 +353,8 @@ class ClusterEngine {
* @private
*/
_cluster(childNodesObj, childEdgesObj, options, refreshData = true) {
let nodeIdField = this.body.data.nodes._fieldId;
// kill condition: no children so can't cluster or only one node in the cluster, don't bother
if (Object.keys(childNodesObj).length < 2) {return;}
@ -395,8 +399,8 @@ class ClusterEngine {
}
// check if we have an unique id;
if (clusterNodeProperties.id === undefined) {clusterNodeProperties.id = 'cluster:' + util.randomUUID();}
let clusterId = clusterNodeProperties.id;
if (clusterNodeProperties[nodeIdField] === undefined) {clusterNodeProperties[nodeIdField] = 'cluster:' + util.randomUUID();}
let clusterId = clusterNodeProperties[nodeIdField];
if (clusterNodeProperties.label === undefined) {
clusterNodeProperties.label = 'cluster';
@ -415,7 +419,7 @@ class ClusterEngine {
}
// force the ID to remain the same
clusterNodeProperties.id = clusterId;
clusterNodeProperties[nodeIdField] = clusterId;
// create the clusterNode
let clusterNode = this.body.functions.createNode(clusterNodeProperties, Cluster);
@ -426,7 +430,7 @@ class ClusterEngine {
clusterNode.clusterEdgeProperties = options.clusterEdgeProperties;
// finally put the cluster node into global
this.body.nodes[clusterNodeProperties.id] = clusterNode;
this.body.nodes[clusterNodeProperties[nodeIdField]] = clusterNode;
// create the new edges that will connect to the cluster, all self-referencing edges will be added to childEdgesObject here.
this._createClusterEdges(childNodesObj, childEdgesObj, clusterNodeProperties, options.clusterEdgeProperties);
@ -447,13 +451,13 @@ class ClusterEngine {
// disable the childNodes
for (let nodeId in childNodesObj) {
if (childNodesObj.hasOwnProperty(nodeId)) {
this.clusteredNodes[nodeId] = {clusterId:clusterNodeProperties.id, node: this.body.nodes[nodeId]};
this.clusteredNodes[nodeId] = {clusterId:clusterNodeProperties[nodeIdField], node: this.body.nodes[nodeId]};
this.body.nodes[nodeId].setOptions({hidden:true, physics:false});
}
}
// set ID to undefined so no duplicates arise
clusterNodeProperties.id = undefined;
clusterNodeProperties[nodeIdField] = undefined;
// wrap up
if (refreshData === true) {

+ 2
- 2
lib/network/modules/components/nodes/Cluster.js View File

@ -4,8 +4,8 @@ import Node from '../Node'
*
*/
class Cluster extends Node {
constructor(options, body, imagelist, grouplist, globalOptions) {
super(options, body, imagelist, grouplist, globalOptions);
constructor(id, options, body, imagelist, grouplist, globalOptions) {
super(id, options, body, imagelist, grouplist, globalOptions);
this.isCluster = true;
this.containedNodes = {};

Loading…
Cancel
Save