How to use the @antv/util.filter 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 / facet / rect.ts View on Github external
rowValues.forEach((yVal, yIndex) => {
        const conditions = [
          { field: columnField, value: xVal, values: columnValues },
          { field: rowField, value: yVal, values: rowValues },
        ];

        const facetData = filter(data, (datum: Datum) => {
          // 过滤出全部满足条件的数据
          return every(conditions, (condition) => {
            const { field, value } = condition;
            return datum[field] === value;
          });
        });

        const facet: RectData = {
          type: this.cfg.type,
          data: facetData,
          region: this.getRegion(rowValuesLength, columnValuesLength, xIndex, yIndex),

          columnValue: xVal,
          rowValue: yVal,
          columnField,
          rowField,
github antvis / G2 / src / geometry / shape / util / get-path-points.ts View on Github external
export function getPathPoints(points: ShapeVertices, connectNulls?: boolean) {
  if (!points.length) {
    return [];
  }

  if (connectNulls) {
    // 即 y 值为空的场景
    const filtered = filter(points, (point: RangePoint | Point[]) => {
      return !isYNil(point);
    });
    return [filtered];
  }

  const result = [];
  let tmp = [];
  points.forEach((point: RangePoint | Point[]) => {
    if (isYNil(point)) {
      if (tmp.length) {
        result.push(tmp);
        tmp = [];
      }
    } else {
      tmp.push(point);
    }
github antvis / G2 / packages / g2 / src / plot / controller / tooltip.ts View on Github external
private _getDefaultTooltipOptions() {
    const view = this.view;
    const options = this.options;
    const theme = this.theme;
    const defaultCfg = _.mix({}, theme.tooltip);
    const elements = _.filter(view.getElements(), (element: Element): boolean => element.get('visible'));
    const shapes = _.uniq(_.map(elements, (element: Element) => element.get('type')));

    const isTransposed = view.get('coord') ? view.get('coord').isTransposed : false;

    let crosshairsCfg;
    if (view.get('coord') && view.get('coord').type === 'cartesian') {
      if (shapes[0] === 'interval') {
        if (options.shape !== false) {
          const crosshairs = _.mix({}, theme.tooltipCrosshairsRect);
          crosshairs.isTransposed = isTransposed;
          crosshairsCfg = {
            zIndex: 0, // 矩形背景框不可覆盖 geom
            crosshairs,
          };
        }
      } else if (_.indexOf(TYPE_SHOW_CROSSHAIRS, shapes[0]) > -1) {
github antvis / G2Plot / __tests__ / unit / pie-label-spec.ts View on Github external
function calcVisibleRate(labelShapes: Shape[], div: HTMLElement) {
    const visibleLabels: Shape[] = _.filter(labelShapes, (l) => l.get('visible'));

    const visibleRate = visibleLabels.length / labelShapes.length;
    div.innerHTML = `label 可见率: ${visibleRate * 100}%`;
    return visibleRate;
  }
github antvis / G2 / packages / component / src / label / base.ts View on Github external
public getLabels() {
    const container = this.get('container');
    if (container) {
      return Util.toArray(container.childNodes);
    }
    const children = this.get('group').get('children');
    return Util.filter(children, (child: any) => child.isShape);
  }
github antvis / G2 / src / util / tooltip.ts View on Github external
function getAttributesForLegend(geometry: Geometry) {
  const attributes = values(geometry.attributes);
  return filter(attributes, (attribute: Attribute) => contains(GROUP_ATTRS, attribute.type));
}