How to use the @antv/util.each function in @antv/util

To help you get started, we’ve selected a few @antv/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 antvis / G2 / src / new_interaction / grammar-interaction.ts View on Github external
each(steps, (subSteps) => {
      each(subSteps, (step) => {
        if (isFunction(step.action)) {
          // 如果传入回调函数,则直接生成 CallbackAction
          step.actionObject = {
            action: createCallbackAction(step.action, context),
            methodName: 'execute',
          };
        } else if (isString(step.action)) {
          // 如果是字符串,则根据名称生成对应的 Action
          const arr = step.action.split(':');
          const actionName = arr[0];
          // 如果已经初始化过 action ,则直接引用之前的 action
          const action = context.getAction(actionName) || createAction(actionName, context);
          const methodName = arr[1];
          step.actionObject = {
            action,
            methodName,
github antvis / G2 / packages / g2 / src / animate / index.ts View on Github external
const axisShapes: Shape[] = getShapes(backgroundGroup, viewId);
  const cacheShapes = shapes.concat(axisShapes);
  canvas.setSilent(`${viewId}caches`, cache(cacheShapes));
  let drawn;

  if (newIsUpdate) {
    // 执行更新动画
    drawn = addAnimate(caches, cacheShapes, canvas);
  } else {
    // 初入场动画
    // drawn = addAnimate(caches, shapes, canvas, newIsUpdate);
    let animateCfg;
    let animate;
    const elements = view.get('elements');
    const coord = view.get('coord');
    _.each(elements, (element: Element) => {
      const type = element.get('type');
      const elementAnimateOption = element.get('animateOptions');
      if (elementAnimateOption !== false) {
        // 用户为关闭动画
        animateCfg = getAnimateCfg(type, 'appear', elementAnimateOption);
        if (!animateCfg) {
          return true;
        } // 用户关闭了初始动画

        animate = getAnimate(type, coord, 'appear', animateCfg.animation);
        if (_.isFunction(animate)) {
          if (animate.animationName.indexOf('group') === 0) {
            // 执行全局动画
            const yScale = element.getYScale();
            const zeroY = coord.convertPoint({
              x: 0,
github antvis / G2 / src / geometry / shape / line.ts View on Github external
function getInterpolateShapeAttrs(cfg: ShapeInfo, shapeType: string) {
  const points = getPathPoints(cfg.points, cfg.connectNulls); // 根据 connectNulls 值处理 points
  let path = [];
  each(points, (eachLinePoints) => {
    const interpolatePoints = getInterpolatePoints(eachLinePoints, shapeType);
    path = path.concat(getInterpolatePath(interpolatePoints));
  });

  return {
    ...getStyle(cfg, true, false, 'lineWidth'),
    path,
  };
}
github antvis / G2 / src / interaction / context.ts View on Github external
public destroy() {
    this.view = null;
    this.event = null;
    // 先销毁 action 再清空,一边遍历,一边删除,所以数组需要更新引用
    each(this.actions.slice(), (action) => {
      action.destroy();
    });
    this.actions = null;
    this.cacheMap = null;
  }
}
github antvis / G2Plot / src / base / controller / event.ts View on Github external
private onLayerEvent(layers: Layer[], eventObj: EventObj, eventName: string) {
    _.each(layers, (layer) => {
      const bbox = layer.getGlobalBBox();
      if (isPointInBBox({ x: eventObj.x, y: eventObj.y }, bbox)) {
        layer.emit(`${eventName}`, eventObj);
        const subLayers = layer.layers;
        if (subLayers.length > 0) {
          this.onLayerEvent(subLayers, eventObj, eventName);
        }
      }
    });
  }
}
github antvis / G2Plot / src / plots / matrix / layer.ts View on Github external
private circleToRect(shapes) {
    const gridSize = this.gridSize;
    _.each(shapes, (shape) => {
      const { x, y, size } = shape.get('origin');
      let sizeRatio = (size * 2) / Math.min(gridSize[0], gridSize[1]);
      if (!this.options.sizeField) {
        sizeRatio = 1;
      }
      const curvePath = getCircleCurve(x, y, size);
      const rectPath = getRectPath(x, y, gridSize[0], gridSize[1], sizeRatio);
      shape.stopAnimate();
      shape.attr('path', curvePath);
      shape.animate(
        {
          path: rectPath,
        },
        1000,
        'easeCubic'
      );
github antvis / G2Plot / src / plots / ring / layer.ts View on Github external
private applyResponsive(stage) {
    const methods = responsiveMethods[stage];
    _.each(methods, (r) => {
      const responsive = r as IAttrs;
      responsive.method(this);
    });
  }
github antvis / G2 / src / interaction / action / element / state.ts View on Github external
protected setElementsStateByItem(elements: Element[], field: string, item: ListItem, enable: boolean) {
    each(elements, (el) => {
      if (this.isMathItem(el, field, item)) {
        el.setState(this.stateName, enable);
      }
    });
  }
github antvis / G2Plot / src / plots / line / component / annotation / timeGroupAnnotation.ts View on Github external
private _drawLines() {
    const intervals = this.intervals;
    _.each(intervals, (i) => {
      const percent = this.scale.scale(i);
      const point = this._getPointByPercent(percent, 'x');
      this.container.addShape('line', {
        attrs: {
          x1: point,
          y1: 0,
          x2: point,
          y2: LINEHEIGHT,
          stroke: '#ccc',
          lineWidth: 1,
        },
      });
    });
  }
github antvis / G2 / src / interaction / action / element / range-state.ts View on Github external
protected setElementsState(elements: Element[], enable) {
    each(elements, (el) => {
      this.setElementState(el, enable);
    });
  }