How to use the vis-util.forEach function in vis-util

To help you get started, we’ve selected a few vis-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github visjs / vis-network / lib / network / modules / LayoutEngine.js View on Github external
_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;
github visjs / vis-network / lib / network / modules / Clustering.js View on Github external
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;
        }
      });
    });
github visjs / vis-network / lib / network / modules / Clustering.js View on Github external
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;
      }
    });
github visjs / vis-network / lib / network / modules / components / nodes / Cluster.js View on Github external
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
github visjs / vis-network / lib / network / modules / components / nodes / Cluster.js View on Github external
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;
github visjs / vis-network / lib / network / modules / components / shared / Label.js View on Github external
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;
      }
    });
  }
github visjs / vis-charts / lib / timeline / component / TimeAxis.js View on Github external
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);
      }
    }
  });
};
github visjs / vis-network / lib / network / modules / components / shared / Label.js View on Github external
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;
      }
    });
  }
github visjs / vis-network / lib / network / modules / LayoutEngine.js View on Github external
_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);
        }
      });
    }
  }
github visjs / vis-network / lib / network / modules / NodesHandler.js View on Github external
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;
    });
  }