Browse Source

added comments

flowchartTest
Alex de Mulder 9 years ago
parent
commit
2689fd3b54
2 changed files with 77 additions and 9 deletions
  1. +3
    -3
      examples/network/39_newClustering.html
  2. +74
    -6
      lib/network/mixins/ClusterMixin.js

+ 3
- 3
examples/network/39_newClustering.html View File

@ -63,7 +63,7 @@
processClusterProperties: function (properties, childNodes, childEdges) {
return properties;
},
// clusterNodeProperties: {id:'bla', borderWidth:8},
clusterNodeProperties: {id:'bla', borderWidth:8},
}
var clusterOptionsByData = {
@ -73,7 +73,7 @@
processClusterProperties: function (properties, childNodes, childEdges) {
return properties;
},
// clusterNodeProperties: {id:'bla', borderWidth:8}
clusterNodeProperties: {id:'bla', borderWidth:8}
}
// network.clusterByNodeData(clusterOptionsByData)
@ -89,7 +89,7 @@
// });
network.on("select", function(params) {
if (params.nodes.length == 1) {
if (params.nodes[0].indexOf("cluster") != -1) {
if (network.isCluster(params.nodes[0]) == true) {
network.openCluster(params.nodes[0])
}
}

+ 74
- 6
lib/network/mixins/ClusterMixin.js View File

@ -94,7 +94,9 @@ exports.clusterOutliers = function(options, doNotUpdateCalculationNodes) {
this._cluster(clusters[i].nodes, clusters[i].edges, options, true)
}
this._wrapUp();
if (doNotUpdateCalculationNodes !== true) {
this._wrapUp();
}
}
/**
@ -114,17 +116,15 @@ exports.clusterByConnection = function(nodeId, options, doNotUpdateCalculationNo
if (options.clusterNodeProperties.y === undefined) {options.clusterNodeProperties.y = node.y; options.clusterNodeProperties.allowedToMoveY = !node.yFixed;}
var childNodesObj = {};
var edge;
var childEdgesObj = {}
var childNodeId;
var parentNodeId = node.id;
var parentClonedOptions = this._cloneOptions(parentNodeId);
childNodesObj[parentNodeId] = node;
// collect the nodes that will be in the cluster
for (var i = 0; i < node.edges.length; i++) {
edge = node.edges[i];
childNodeId = this._getConnectedId(edge, parentNodeId);
var edge = node.edges[i];
var childNodeId = this._getConnectedId(edge, parentNodeId);
if (childNodeId !== parentNodeId) {
if (options.joinCondition === undefined) {
@ -148,6 +148,14 @@ exports.clusterByConnection = function(nodeId, options, doNotUpdateCalculationNo
this._cluster(childNodesObj, childEdgesObj, options, doNotUpdateCalculationNodes);
}
/**
* This returns a clone of the options or properties of the edge or node to be used for construction of new edges or check functions for new nodes.
* @param objId
* @param type
* @returns {{}}
* @private
*/
exports._cloneOptions = function(objId, type) {
var clonedOptions = {};
if (type === undefined || type == 'node') {
@ -161,6 +169,16 @@ exports._cloneOptions = function(objId, type) {
return clonedOptions;
}
/**
* This function creates the edges that will be attached to the cluster.
*
* @param childNodesObj
* @param childEdgesObj
* @param newEdges
* @param options
* @private
*/
exports._createClusterEdges = function (childNodesObj, childEdgesObj, newEdges, options) {
var edge, childNodeId, childNode;
@ -209,12 +227,18 @@ exports._createClusterEdges = function (childNodesObj, childEdgesObj, newEdges,
}
/**
* This function checks the options that can be supplied to the different cluster functions
* for certain fields and inserts defaults if needed
* @param options
* @returns {*}
* @private
*/
exports._checkOptions = function(options) {
if (options === undefined) {options = {};}
if (options.clusterEdgeProperties === undefined) {options.clusterEdgeProperties = {};}
if (options.clusterNodeProperties === undefined) {options.clusterNodeProperties = {};}
return options;
}
@ -287,6 +311,7 @@ exports._cluster = function(childNodesObj, childEdgesObj, options, doNotUpdateCa
// create the clusterNode
var clusterNode = new Node(clusterNodeProperties, this.images, this.groups, this.constants);
clusterNode.isCluster = true;
clusterNode.containedNodes = childNodesObj;
clusterNode.containedEdges = childEdgesObj;
@ -344,6 +369,22 @@ exports._cluster = function(childNodesObj, childEdgesObj, options, doNotUpdateCa
}
/**
* Check if a node is a cluster.
* @param nodeId
* @returns {*}
*/
exports.isCluster = function(nodeId) {
if (this.nodes[nodeId] !== undefined) {
return this.nodes[nodeId].isCluster;
}
else {
console.log("Node does not exist.")
return false;
}
}
/**
* get the position of the cluster node based on what's inside
* @param {object} childNodesObj | object with node objects, id as keys
@ -459,6 +500,11 @@ exports.openCluster = function(clusterNodeId, doNotUpdateCalculationNodes) {
}
}
/**
* Recalculate navigation nodes, color edges dirty, update nodes list etc.
* @private
*/
exports._wrapUp = function() {
this._updateNodeIndexList();
this._updateCalculationNodes();
@ -469,6 +515,15 @@ exports._wrapUp = function() {
}
}
/**
* Connect an edge that was previously contained from cluster A to cluster B if the node that it was originally connected to
* is currently residing in cluster B
* @param edge
* @param nodeId
* @param from
* @private
*/
exports._connectEdge = function(edge, nodeId, from) {
var clusterStack = this._getClusterStack(nodeId);
if (from == true) {
@ -486,6 +541,12 @@ exports._connectEdge = function(edge, nodeId, from) {
edge.connect();
}
/**
* Get the stack clusterId's that a certain node resides in. cluster A -> cluster B -> cluster C -> node
* @param nodeId
* @returns {Array}
* @private
*/
exports._getClusterStack = function(nodeId) {
var stack = [];
var max = 100;
@ -501,6 +562,13 @@ exports._getClusterStack = function(nodeId) {
}
/**
* Get the Id the node is connected to
* @param edge
* @param nodeId
* @returns {*}
* @private
*/
exports._getConnectedId = function(edge, nodeId) {
if (edge.toId != nodeId) {
return edge.toId;

Loading…
Cancel
Save