|
|
@ -258,7 +258,6 @@ class ClusterEngine { |
|
|
|
*/ |
|
|
|
_createClusterEdges (childNodesObj, childEdgesObj, clusterNodeProperties, clusterEdgeProperties) { |
|
|
|
let edge, childNodeId, childNode, toId, fromId, otherNodeId; |
|
|
|
let nodeIdField = this.body.data.nodes._fieldId; |
|
|
|
|
|
|
|
// loop over all child nodes and their edges to find edges going out of the cluster
|
|
|
|
// these edges will be replaced by clusterEdges.
|
|
|
@ -280,20 +279,20 @@ 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[nodeIdField]; |
|
|
|
toId = clusterNodeProperties.id; |
|
|
|
fromId = edge.fromId; |
|
|
|
otherNodeId = fromId; |
|
|
|
} |
|
|
|
else { |
|
|
|
toId = edge.toId; |
|
|
|
fromId = clusterNodeProperties[nodeIdField]; |
|
|
|
fromId = clusterNodeProperties.id; |
|
|
|
otherNodeId = toId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Only edges from the cluster outwards are being replaced.
|
|
|
|
if (childNodesObj[otherNodeId] === undefined) { |
|
|
|
createEdges.push({edge, fromId, toId}); |
|
|
|
createEdges.push({edge: edge, fromId: fromId, toId: toId}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -311,12 +310,12 @@ class ClusterEngine { |
|
|
|
// set up the edge
|
|
|
|
clonedOptions.from = createEdges[j].fromId; |
|
|
|
clonedOptions.to = createEdges[j].toId; |
|
|
|
clonedOptions.id = '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.
|
|
|
|
let edgeId = 'clusterEdge:' + util.randomUUID(); |
|
|
|
let newEdge = this.body.functions.createEdge(edgeId, clonedOptions); |
|
|
|
newEdge.clusteringEdgeReplacingId = edgeId; |
|
|
|
let newEdge = this.body.functions.createEdge(clonedOptions); |
|
|
|
newEdge.clusteringEdgeReplacingId = edge.id; |
|
|
|
|
|
|
|
// connect the edge.
|
|
|
|
this.body.edges[newEdge.id] = newEdge; |
|
|
@ -352,8 +351,6 @@ 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;} |
|
|
|
|
|
|
@ -398,8 +395,8 @@ class ClusterEngine { |
|
|
|
} |
|
|
|
|
|
|
|
// check if we have an unique id;
|
|
|
|
if (clusterNodeProperties[nodeIdField] === undefined) {clusterNodeProperties[nodeIdField] = 'cluster:' + util.randomUUID();} |
|
|
|
let clusterId = clusterNodeProperties[nodeIdField]; |
|
|
|
if (clusterNodeProperties.id === undefined) {clusterNodeProperties.id = 'cluster:' + util.randomUUID();} |
|
|
|
let clusterId = clusterNodeProperties.id; |
|
|
|
|
|
|
|
if (clusterNodeProperties.label === undefined) { |
|
|
|
clusterNodeProperties.label = 'cluster'; |
|
|
@ -417,9 +414,11 @@ class ClusterEngine { |
|
|
|
clusterNodeProperties.y = pos.y; |
|
|
|
} |
|
|
|
|
|
|
|
// create the clusterNode
|
|
|
|
// force the ID to remain the same
|
|
|
|
let clusterNode = this.body.functions.createNode(clusterId, clusterNodeProperties, Cluster); |
|
|
|
clusterNodeProperties.id = clusterId; |
|
|
|
|
|
|
|
// create the clusterNode
|
|
|
|
let clusterNode = this.body.functions.createNode(clusterNodeProperties, Cluster); |
|
|
|
clusterNode.isCluster = true; |
|
|
|
clusterNode.containedNodes = childNodesObj; |
|
|
|
clusterNode.containedEdges = childEdgesObj; |
|
|
@ -427,7 +426,7 @@ class ClusterEngine { |
|
|
|
clusterNode.clusterEdgeProperties = options.clusterEdgeProperties; |
|
|
|
|
|
|
|
// finally put the cluster node into global
|
|
|
|
this.body.nodes[clusterNodeProperties[nodeIdField]] = clusterNode; |
|
|
|
this.body.nodes[clusterNodeProperties.id] = 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); |
|
|
@ -448,13 +447,13 @@ class ClusterEngine { |
|
|
|
// disable the childNodes
|
|
|
|
for (let nodeId in childNodesObj) { |
|
|
|
if (childNodesObj.hasOwnProperty(nodeId)) { |
|
|
|
this.clusteredNodes[nodeId] = {clusterId:clusterNodeProperties[nodeIdField], node: this.body.nodes[nodeId]}; |
|
|
|
this.clusteredNodes[nodeId] = {clusterId:clusterNodeProperties.id, node: this.body.nodes[nodeId]}; |
|
|
|
this.body.nodes[nodeId].setOptions({hidden:true, physics:false}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// set ID to undefined so no duplicates arise
|
|
|
|
clusterNodeProperties[nodeIdField] = undefined; |
|
|
|
clusterNodeProperties.id = undefined; |
|
|
|
|
|
|
|
// wrap up
|
|
|
|
if (refreshData === true) { |
|
|
@ -533,7 +532,6 @@ class ClusterEngine { |
|
|
|
return |
|
|
|
} |
|
|
|
let clusterNode = this.body.nodes[clusterNodeId]; |
|
|
|
let edgeIdField = this.body.data.edges._fieldId; |
|
|
|
let containedNodes = clusterNode.containedNodes; |
|
|
|
let containedEdges = clusterNode.containedEdges; |
|
|
|
|
|
|
@ -627,11 +625,10 @@ class ClusterEngine { |
|
|
|
|
|
|
|
// apply the edge specific options to it.
|
|
|
|
let id = 'clusterEdge:' + util.randomUUID(); |
|
|
|
util.deepExtend(clonedOptions, {from: fromId, to: toId, hidden: false, physics: true}); |
|
|
|
clonedOptions[edgeIdField] = id; |
|
|
|
util.deepExtend(clonedOptions, {from: fromId, to: toId, hidden: false, physics: true, id: id}); |
|
|
|
|
|
|
|
// create it
|
|
|
|
let newEdge = this.body.functions.createEdge(transferEdge.id, clonedOptions); |
|
|
|
let newEdge = this.body.functions.createEdge(clonedOptions); |
|
|
|
newEdge.clusteringEdgeReplacingId = transferEdge.id; |
|
|
|
this.body.edges[id] = newEdge; |
|
|
|
this.body.edges[id].connect(); |
|
|
|