How to use the @antv/util/lib/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 / G6 / src / graph / graph.ts View on Github external
public render(): void {
    const self = this;
    const data: GraphData = this.get('data');

    if (!data) {
      throw new Error('data must be defined first');
    }

    this.clear();

    this.emit('beforerender');
    const autoPaint = this.get('autoPaint');
    this.setAutoPaint(false);

    each(data.nodes, (node: NodeConfig) => {
      self.add(ITEM_TYPE.NODE, node);
    });

    each(data.edges, (edge: EdgeConfig) => {
      self.add(ITEM_TYPE.EDGE, edge);
    });

    if (!this.get('groupByTypes')) {
      // 为提升性能,选择数量少的进行操作
      if (data.nodes.length < data.edges.length) {
        const nodes = this.getNodes();

        // 遍历节点实例,将所有节点提前。
        nodes.forEach(node => {
          node.toFront();
        });
github antvis / G6 / src / graph / graph.ts View on Github external
if (!data) {
      throw new Error('data must be defined first');
    }

    this.clear();

    this.emit('beforerender');
    const autoPaint = this.get('autoPaint');
    this.setAutoPaint(false);

    each(data.nodes, (node: NodeConfig) => {
      self.add(ITEM_TYPE.NODE, node);
    });

    each(data.edges, (edge: EdgeConfig) => {
      self.add(ITEM_TYPE.EDGE, edge);
    });

    if (!this.get('groupByTypes')) {
      // 为提升性能,选择数量少的进行操作
      if (data.nodes.length < data.edges.length) {
        const nodes = this.getNodes();

        // 遍历节点实例,将所有节点提前。
        nodes.forEach(node => {
          node.toFront();
        });
      } else {
        const edges = this.getEdges();

        // 遍历节点实例,将所有节点提前。
github antvis / G6 / src / graph / graph.ts View on Github external
public destroy() {
    this.clear();

    each(this.get('plugins'), plugin => {
      plugin.destroyPlugin();
    });

    this.get('eventController').destroy();
    this.get('itemController').destroy();
    this.get('modeController').destroy();
    this.get('viewController').destroy();
    this.get('stateController').destroy();
    // this.get('layoutController').destroy();
    this.get('customGroupControll').destroy();
    this.get('canvas').destroy();
    this._cfg = null;
    this.destroyed = true;
  }
}
github antvis / G6 / src / graph / graph.ts View on Github external
const autoPaint: boolean = self.get('autoPaint');
    self.setAutoPaint(false);

    self.emit('beforegraphrefresh');

    if (self.get('animate')) {
      self.positionsAnimate();
    } else {
      const nodes: INode[] = self.get('nodes');
      const edges: IEdge[] = self.get('edges');

      each(nodes, (node: INode) => {
        node.refresh();
      });

      each(edges, (edge: IEdge) => {
        edge.refresh();
      });
    }

    self.setAutoPaint(autoPaint);

    self.emit('aftergraphrefresh');
    self.autoPaint();
  }
github antvis / G6 / src / graph / controller / mode.ts View on Github external
public setMode(mode: string): ModeController {
    const modes = this.modes;
    const graph = this.graph;
    const current = mode
    
    const behaviors = modes[current];
    if (!behaviors) {
      return;
    }
    graph.emit('beforemodechange', { mode });

    each(this.currentBehaves, behave => {
      behave.unbind(graph);
    });

    this.setBehaviors(current);

    graph.emit('aftermodechange', { mode });
    this.mode = mode;

    return this;
  }
github antvis / G6 / src / graph / controller / mode.ts View on Github external
private setBehaviors(mode: string) {
    const graph = this.graph;
    const behaviors = this.modes[mode];
    const behaves: IBehavior[] = [];
    let behave: IBehavior;
    each(behaviors, behavior => {
      const BehaviorInstance = Behavior.getBehavior(behavior.type)
      if (!BehaviorInstance) {
        return;
      }
      
      behave = new BehaviorInstance(behavior);
      if(behave) {
        behave.bind(graph)
        behaves.push(behave);
      }
    });
    this.currentBehaves = behaves;
  }
github antvis / G2Plot / src / plots / line / component / label / line-label.ts View on Github external
public _adjustColor(shapeId, shapes) {
    let color;
    _each(shapes, (shape) => {
      const id = shape.id;
      if (id === shapeId) {
        color = shape.attr('stroke');
      }
    });
    return color;
  }
}
github antvis / G6 / src / graph / controller / mode.ts View on Github external
private mergeBehaviors(modeBehaviors: IModeType[], behaviors): IModeType[] {
    each(behaviors, behavior => {
      if (modeBehaviors.indexOf(behavior) < 0) {
        if (isString(behavior)) {
          behavior = { type: behavior };
        }
        modeBehaviors.push(behavior);
      }
    });
    return modeBehaviors;
  }
github antvis / G6 / src / graph / controller / state.ts View on Github external
public updateGraphStates() {
    const states = this.graph.get('states')

    const cachedStates = this.cachedStates;
    
    each(cachedStates.disabled, (val, key) => {
      if (states[key]) {
        states[key] = states[key].filter(item => {
          return val.indexOf(item) < 0 && !val.destroyed;
        });
      }
    });

    each(cachedStates.enabled, (val, key) => {
      if (!states[key]) {
        states[key] = val;
      } else {
        const map = {};
        states[key].forEach(item => {
          if (!item.destroyed) {
            map[item.get('id')] = true;
          }