Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_getHubSizes() {
let hubSizes = {};
let nodeIds = this.body.nodeIndices;
util.forEach(nodeIds, (nodeId) => {
let node = this.body.nodes[nodeId];
let hubSize = this._getActiveEdges(node).length;
hubSizes[hubSize] = true;
});
// Make an array of the size sorted descending
let result = [];
util.forEach(hubSizes, (size) => {
result.push(Number(size));
});
TimSort.sort(result, function(a, b) {
return b - a;
});
return result;
delete clusterNode.containedNodes[deletedNodeIds[n]];
}
});
// Remove nodes from cluster list
for (let n = 0; n < deletedNodeIds.length; n++) {
delete this.clusteredNodes[deletedNodeIds[n]];
}
//
// Remove deleted edges from clustering
//
// Add the deleted clustered edges to the list
util.forEach(this.clusteredEdges, (edgeId) => {
let edge = this.body.edges[edgeId];
if (edge === undefined || !edge.endPointsValid()) {
deletedEdgeIds[edgeId] = edgeId;
}
});
// Cluster nodes can also contain edges which are not clustered,
// i.e. nodes 1-2 within cluster with an edge in between.
// So the cluster nodes also need to be scanned for invalid edges
eachClusterNode(function(clusterNode) {
util.forEach(clusterNode.containedEdges, (edge, edgeId) => {
if (!edge.endPointsValid() && !deletedEdgeIds[edgeId]) {
deletedEdgeIds[edgeId] = edgeId;
}
});
});
util.forEach(this.body.edges, (edge, edgeId) => {
// Explicitly scan the contained edges for validity
let isValid = true;
let replacedIds = edge.clusteringEdgeReplacingIds;
if (replacedIds !== undefined) {
let numValid = 0;
util.forEach(replacedIds, (containedEdgeId) => {
let containedEdge = this.body.edges[containedEdgeId];
if (containedEdge !== undefined && containedEdge.endPointsValid()) {
numValid += 1;
}
});
isValid = (numValid > 0);
}
if (!edge.endPointsValid() || !isValid) {
deletedEdgeIds[edgeId] = edgeId;
}
});
throw new Error('node with id: ' + childClusterId + ' is not a cluster');
}
// Disconnect child cluster from current cluster
delete this.containedNodes[childClusterId];
util.forEach(childCluster.edges, (edge) => {
delete this.containedEdges[edge.id];
});
// Transfer nodes and edges
util.forEach(childCluster.containedNodes, (node, nodeId) => {
this.containedNodes[nodeId] = node;
});
childCluster.containedNodes = {};
util.forEach(childCluster.containedEdges, (edge, edgeId) => {
this.containedEdges[edgeId] = edge;
});
childCluster.containedEdges = {};
// Transfer edges within cluster edges which are clustered
util.forEach(childCluster.edges, (clusterEdge) => {
util.forEach(this.edges, (parentClusterEdge) => {
// Assumption: a clustered edge can only be present in a single clustering edge
// Not tested here
let index = parentClusterEdge.clusteringEdgeReplacingIds.indexOf(clusterEdge.id);
if (index === -1) return;
util.forEach(clusterEdge.clusteringEdgeReplacingIds, (srcId) => {
parentClusterEdge.clusteringEdgeReplacingIds.push(srcId);
// Maintain correct bookkeeping for transferred edge
let childCluster = this.body.nodes[childClusterId];
if (this.containedNodes[childClusterId] === undefined) {
throw new Error('node with id: ' + childClusterId + ' not in current cluster');
}
if (!childCluster.isCluster) {
throw new Error('node with id: ' + childClusterId + ' is not a cluster');
}
// Disconnect child cluster from current cluster
delete this.containedNodes[childClusterId];
util.forEach(childCluster.edges, (edge) => {
delete this.containedEdges[edge.id];
});
// Transfer nodes and edges
util.forEach(childCluster.containedNodes, (node, nodeId) => {
this.containedNodes[nodeId] = node;
});
childCluster.containedNodes = {};
util.forEach(childCluster.containedEdges, (edge, edgeId) => {
this.containedEdges[edgeId] = edge;
});
childCluster.containedEdges = {};
// Transfer edges within cluster edges which are clustered
util.forEach(childCluster.edges, (clusterEdge) => {
util.forEach(this.edges, (parentClusterEdge) => {
// Assumption: a clustered edge can only be present in a single clustering edge
// Not tested here
let index = parentClusterEdge.clusteringEdgeReplacingIds.indexOf(clusterEdge.id);
if (index === -1) return;
initFontOptions(newFontOptions) {
// Prepare the multi-font option objects.
// These will be filled in propagateFonts(), if required
util.forEach(multiFontStyle, (style) => {
this.fontOptions[style] = {};
});
// Handle shorthand option, if present
if (Label.parseFontString(this.fontOptions, newFontOptions)) {
this.fontOptions.vadjust = 0;
return;
}
// Copy over the non-multifont options, if specified
util.forEach(newFontOptions, (prop, n) => {
if (prop !== undefined && prop !== null && typeof prop !== 'object') {
this.fontOptions[n] = prop;
}
});
}
warnedForOverflow = true;
}
// create a major label on the left when needed
if (this.options.showMajorLabels) {
var leftTime = this.body.util.toTime(0),
leftText = step.getLabelMajor(leftTime),
widthText = leftText.length * (this.props.majorCharWidth || 10) + 10; // upper bound estimation
if (xFirstMajorLabel == undefined || widthText < xFirstMajorLabel) {
this._repaintMajorText(0, leftText, orientation, className);
}
}
// Cleanup leftover DOM elements from the redundant list
util.forEach(this.dom.redundant, function (arr) {
while (arr.length) {
var elem = arr.pop();
if (elem && elem.parentNode) {
elem.parentNode.removeChild(elem);
}
}
});
};
initFontOptions(newFontOptions) {
// Prepare the multi-font option objects.
// These will be filled in propagateFonts(), if required
util.forEach(multiFontStyle, (style) => {
this.fontOptions[style] = {};
});
// Handle shorthand option, if present
if (Label.parseFontString(this.fontOptions, newFontOptions)) {
this.fontOptions.vadjust = 0;
return;
}
// Copy over the non-multifont options, if specified
util.forEach(newFontOptions, (prop, n) => {
if (prop !== undefined && prop !== null && typeof prop !== 'object') {
this.fontOptions[n] = prop;
}
});
}
_determineLevelsByHubsize() {
let levelDownstream = (nodeA, nodeB) => {
this.hierarchical.levelDownstream(nodeA, nodeB);
}
let hubSizes = this._getHubSizes();
for (let i = 0; i < hubSizes.length; ++i ) {
let hubSize = hubSizes[i];
if (hubSize === 0) break;
util.forEach(this.body.nodeIndices, (nodeId) => {
let node = this.body.nodes[nodeId];
if (hubSize === this._getActiveEdges(node).length) {
this._crawlNetwork(levelDownstream, nodeId);
}
});
}
}
this.body.emitter.on('destroy', () => {
util.forEach(this.nodesListeners, (callback, event) => {
if (this.body.data.nodes)
this.body.data.nodes.off(event, callback);
});
delete this.body.functions.createNode;
delete this.nodesListeners.add;
delete this.nodesListeners.update;
delete this.nodesListeners.remove;
delete this.nodesListeners;
});
}