lodash#times JavaScript Examples

The following examples show how to use lodash#times. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: debug-toolbar.js    From ThreatMapper with Apache License 2.0 6 votes vote down vote up
function addAllVariants(dispatch) {
  const newNodes = flattenDeep(STACK_VARIANTS.map(stack => (SHAPES.map((s) => {
    if (!stack) return [deltaAdd(label(s, stack), [], s, stack)];
    return times(3).map(() => deltaAdd(label(s, stack), [], s, stack));
  }))));

  dispatch(receiveNodesDelta({
    add: newNodes
  }));
}
Example #2
Source File: edge-container.js    From ThreatMapper with Apache License 2.0 5 votes vote down vote up
waypointsMapToArray = (waypointsMap) => {
  const waypointsArray = times(EDGE_WAYPOINTS_CAP, () => ({}));
  waypointsMap.forEach((value, key) => {
    const [axis, index] = [key[0], key.slice(1)];
    waypointsArray[index][axis] = value;
  });
  return waypointsArray;
}
Example #3
Source File: layout.js    From ThreatMapper with Apache License 2.0 5 votes vote down vote up
decoratedNodesByTopologySelector = createSelector(
  [
    layersTopologyIdsSelector,
    state => state.get('pinnedMetricType'),
    // Generate the dependencies for this selector programmatically (because we want their
    // number to be customizable directly by changing the constant). The dependency functions
    // here depend on another selector, but this seems to work quite fine. For example, if
    // layersTopologyIdsSelector = ['hosts', 'containers'] and RESOURCE_VIEW_MAX_LAYERS = 3,
    // this code will generate:
    //   [
    //     state => state.getIn(['nodesByTopology', 'hosts'])
    //     state => state.getIn(['nodesByTopology', 'containers'])
    //     state => state.getIn(['nodesByTopology', undefined])
    //   ]
    // which will all be captured by `topologiesNodes` and processed correctly (even for undefined).
    ...times(RESOURCE_VIEW_MAX_LAYERS, index => (
      state => state.getIn(['nodesByTopology', layersTopologyIdsSelector(state).get(index)])
    ))
  ],
  (layersTopologyIds, pinnedMetricType, ...topologiesNodes) => {
    let nodesByTopology = makeMap();
    let parentLayerTopologyId = null;

    topologiesNodes.forEach((topologyNodes, index) => {
      const layerTopologyId = layersTopologyIds.get(index);
      const parentTopologyNodes = nodesByTopology.get(parentLayerTopologyId, makeMap());
      const showCapacity = TOPOLOGIES_WITH_CAPACITY.includes(layerTopologyId);
      const isBaseLayer = (index === 0);

      const nodeParentDecorator = nodeParentDecoratorByTopologyId(parentLayerTopologyId);
      const nodeMetricSummaryDecorator = nodeMetricSummaryDecoratorByType(
        pinnedMetricType,
        showCapacity
      );

      // Color the node, deduce its anchor point, dimensions and info about its pinned metric.
      const decoratedTopologyNodes = (topologyNodes || makeMap())
        .map(nodeResourceViewColorDecorator)
        .map(nodeMetricSummaryDecorator)
        .map(nodeResourceBoxDecorator)
        .map(nodeParentDecorator);

      const filteredTopologyNodes = decoratedTopologyNodes
        // Filter out the nodes with no parent in the topology of the previous layer, as their
        // positions in the layout could not be determined. The exception is the base layer.
        // TODO: Also make an exception for uncontained nodes (e.g. processes).
        .filter(node => parentTopologyNodes.has(node.get('parentNodeId')) || isBaseLayer)
        // Filter out the nodes with no metric summary data, which is needed to render the node.
        .filter(node => node.get('metricSummary'))
        // Filter out nodes with zero-width, as they will never be shown, no matter how much we
        // zoom in. The example is every node consuming less than 0.005% CPU, as the 2-digit
        // precision will round it down to zero.
        .filter(node => node.get('width') > 0);

      nodesByTopology = nodesByTopology.set(layerTopologyId, filteredTopologyNodes);
      parentLayerTopologyId = layerTopologyId;
    });

    return nodesByTopology;
  }
)