How to use the @antv/util.isNumberEqual 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 / packages / component / src / axis / line.ts View on Github external
const title = this.get('title');
    let angle;
    if (labelRenderer) {
      const labels: Shape[] = labelRenderer.getLabels();
      const offset = this.get('label').offset;
      const append = 12;
      const titleOffset = title && title.offset ? title.offset : 20;
      if (titleOffset < 0) {
        // 如果是负的的话就不旋转
        return;
      }
      const vector = this.getAxisVector(); // 坐标轴的向量,仅处理水平或者垂直的场景

      let maxWidth;
      let maxHeight;
      if (Util.isNumberEqual(vector[0], 0) && title && title.text) {
        // 坐标轴垂直,由于不知道边距,只能防止跟title重合,如果title不存在,则不自动旋转
        maxWidth = this.getMaxLabelWidthOrHeight(labelRenderer, 'width');
        if (maxWidth > titleOffset - offset - append) {
          angle = Math.acos((titleOffset - offset - append) / maxWidth) * -1;
        }
      } else if (Util.isNumberEqual(vector[1], 0) && labels.length > 1) {
        // 坐标轴水平,不考虑边距,根据最长的和平均值进行翻转
        maxWidth = this.getMaxLabelWidthOrHeight(labelRenderer, 'width');
        maxHeight = this.getMaxLabelWidthOrHeight(labelRenderer, 'height');
        if (maxWidth > avgWidth) {
          const degrees = Util.isArray(autoRotate) ? autoRotate : AUTO_ROTATE_DEGREES;
          for (const degree of degrees) {
            angle = (degree * Math.PI) / 180;
            if (avgWidth * Math.abs(Math.sin(angle)) > maxHeight + 4) {
              break;
            }
github antvis / G2 / packages / component / src / axis / line.ts View on Github external
if (labelRenderer) {
      const ticks = this.get('tickItems');
      const labels = labelRenderer.getLabels();
      const vector = this.getAxisVector(); // 坐标轴的向量,仅处理水平或者垂直的场景
      if (labels.length < 2) {
        return;
      }
      if (Util.isNumberEqual(vector[0], 0)) {
        // 坐标轴垂直
        const maxHeight = this.getMaxLabelWidthOrHeight(labelRenderer, 'height') + append;
        const avgHeight = Math.abs(this._getAvgLabelHeightSpace(labelRenderer));
        if (maxHeight > avgHeight) {
          labelSpace = maxHeight;
          tickStep = avgHeight;
        }
      } else if (Util.isNumberEqual(vector[1], 0) && labels.length > 1) {
        // 坐标轴水平
        const maxWidth = this.getMaxLabelWidthOrHeight(labelRenderer, 'width') + append;
        const avgWidth = Math.abs(this._getAvgLabelLength(labelRenderer));
        if (maxWidth > avgWidth) {
          labelSpace = maxWidth;
          tickStep = avgWidth;
        }
      }

      if (labelSpace && tickStep) {
        const ratio = Math.ceil(labelSpace / tickStep);
        Util.each(labels, (label: Shape, i: number) => {
          if (i % ratio !== 0) {
            label.set('visible', false);
            label.attr('text', '');
          }
github antvis / G2 / src / animate / animation / sector-path-update.ts View on Github external
function getAngle(startPoint: number[], arcPath: PathCommand) {
  let { startAngle, endAngle } = getArcParams(startPoint, arcPath);

  if (!isNumberEqual(startAngle, -Math.PI * 0.5) && startAngle < -Math.PI * 0.5) {
    startAngle += Math.PI * 2;
  }
  if (!isNumberEqual(endAngle, -Math.PI * 0.5) && endAngle < -Math.PI * 0.5) {
    endAngle += Math.PI * 2;
  }

  if (arcPath[5] === 0) {
    // 逆时针,需要将 startAngle 和 endAngle 转置,因为 G2 极坐标系为顺时针方向
    [startAngle, endAngle] = [endAngle, startAngle];
  }

  if (isNumberEqual(startAngle, Math.PI * 1.5)) {
    startAngle = Math.PI * -0.5;
  }

  if (isNumberEqual(endAngle, Math.PI * -0.5)) {
github antvis / G2 / packages / component / src / axis / line.ts View on Github external
const titleOffset = title && title.offset ? title.offset : 20;
      if (titleOffset < 0) {
        // 如果是负的的话就不旋转
        return;
      }
      const vector = this.getAxisVector(); // 坐标轴的向量,仅处理水平或者垂直的场景

      let maxWidth;
      let maxHeight;
      if (Util.isNumberEqual(vector[0], 0) && title && title.text) {
        // 坐标轴垂直,由于不知道边距,只能防止跟title重合,如果title不存在,则不自动旋转
        maxWidth = this.getMaxLabelWidthOrHeight(labelRenderer, 'width');
        if (maxWidth > titleOffset - offset - append) {
          angle = Math.acos((titleOffset - offset - append) / maxWidth) * -1;
        }
      } else if (Util.isNumberEqual(vector[1], 0) && labels.length > 1) {
        // 坐标轴水平,不考虑边距,根据最长的和平均值进行翻转
        maxWidth = this.getMaxLabelWidthOrHeight(labelRenderer, 'width');
        maxHeight = this.getMaxLabelWidthOrHeight(labelRenderer, 'height');
        if (maxWidth > avgWidth) {
          const degrees = Util.isArray(autoRotate) ? autoRotate : AUTO_ROTATE_DEGREES;
          for (const degree of degrees) {
            angle = (degree * Math.PI) / 180;
            if (avgWidth * Math.abs(Math.sin(angle)) > maxHeight + 4) {
              break;
            }
          }
        }
      }
    }

    return angle;
github antvis / util / packages / matrix-util / __tests__ / unit / matrix-spec.js View on Github external
it('vec2.angleTo(v1, v2)', () => {
    const v1 = vec2.fromValues(0, -1);
    const v2 = vec2.fromValues(1, 0);
    expect(isNumberEqual(vec2.angleTo(v1, v2), Math.PI / 2)).to.be.true;
  });
  it('vec2.angleTo(v1, v2, true)', () => {
github antvis / G2 / packages / g2 / __tests__ / unit / element / interval-spec.js View on Github external
shapes.forEach((shape) => {
        expect(shape.attr('path').length).to.equal(6);
        expect(isNumberEqual(shape.attr('path')[2][1] - shape.attr('path')[1][1], 180 / 3 / 6)).to.be.true;
      });
    });
github antvis / G2 / packages / g2 / __tests__ / unit / element / interval-spec.js View on Github external
interval.getShapes().forEach((shape) => {
        const origin = shape.get('origin');
        const path = shape.attr('path');
        expect(isNumberEqual(interval.getSize(origin), path[2][1] - path[1][1])).to.be.true;
      });
github antvis / G2 / src / animate / animation / sector-path-update.ts View on Github external
const arcPaths = path.filter((command) => {
    return command[0] === 'A' || command[0] === 'a';
  });

  const firstArcPathCommand = arcPaths[0];
  const lastArcPathCommand = arcPaths.length > 1 ? arcPaths[1] : arcPaths[0];
  const firstIndex = path.indexOf(firstArcPathCommand);
  const lastIndex = path.indexOf(lastArcPathCommand);
  const firstStartPoint = getArcStartPoint(path[firstIndex - 1]);
  const lastStartPoint = getArcStartPoint(path[lastIndex - 1]);

  const { startAngle: firstStartAngle, endAngle: firstEndAngle } = getAngle(firstStartPoint, firstArcPathCommand);
  const { startAngle: lastStartAngle, endAngle: lastEndAngle } = getAngle(lastStartPoint, lastArcPathCommand);

  if (isNumberEqual(firstStartAngle, lastStartAngle) && isNumberEqual(firstEndAngle, lastEndAngle)) {
    startAngle = firstStartAngle;
    endAngle = firstEndAngle;
  } else {
    startAngle = Math.min(firstStartAngle, lastStartAngle);
    endAngle = Math.max(firstEndAngle, lastEndAngle);
  }

  let radius = firstArcPathCommand[1];
  let innerRadius = arcPaths[arcPaths.length - 1][1];

  if (radius < innerRadius) {
    [radius, innerRadius] = [innerRadius, radius];
  } else if (radius === innerRadius) {
    innerRadius = 0;
  }
github antvis / G2 / src / util / graphics.ts View on Github external
export function getArcPath(
  centerX: number,
  centerY: number,
  radius: number,
  startAngleInRadian: number,
  endAngleInRadian: number
) {
  const start = polarToCartesian(centerX, centerY, radius, startAngleInRadian);
  const end = polarToCartesian(centerX, centerY, radius, endAngleInRadian);

  if (isNumberEqual(endAngleInRadian - startAngleInRadian, Math.PI * 2)) {
    const middlePoint = polarToCartesian(centerX, centerY, radius, startAngleInRadian + Math.PI);
    return [
      ['M', start.x, start.y],
      ['A', radius, radius, 0, 1, 1, middlePoint.x, middlePoint.y],
      ['A', radius, radius, 0, 1, 1, start.x, start.y],
      ['A', radius, radius, 0, 1, 0, middlePoint.x, middlePoint.y],
      ['A', radius, radius, 0, 1, 0, start.x, start.y],
      ['Z'],
    ];
  }
  const arcSweep = endAngleInRadian - startAngleInRadian <= Math.PI ? 0 : 1;
  return [
    ['M', start.x, start.y],
    ['A', radius, radius, 0, arcSweep, 1, end.x, end.y],
  ];
}