How to use the @antv/matrix-util.transform function in @antv/matrix-util

To help you get started, we’ve selected a few @antv/matrix-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 / geometry / animate / action.ts View on Github external
export function scaleInY(
  shape: IShape | IGroup,
  animateCfg: AnimateCfg,
  coordinate: Coordinate,
  shapeModel: ShapeDrawCFG
) {
  const box = shape.getBBox();
  const x = (box.minX + box.maxX) / 2;
  const points = shapeModel.points as Point[];
  // 数值如果为负值,那么应该从上往下生长,通过 shape 的关键点进行判断
  const y = points[0].y - points[1].y <= 0 ? box.maxY : box.minY;

  shape.applyToMatrix([x, y, 1]);
  const matrix = transform(shape.getMatrix(), [
    ['t', -x, -y],
    ['s', 1, 0.01],
    ['t', x, y],
  ]);
  shape.setMatrix(matrix);

  shape.animate(
    {
      matrix: transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 1, 100],
        ['t', x, y],
      ]),
    },
    animateCfg
  );
github antvis / G2 / src / geometry / animate / action.ts View on Github external
// x 数值如果为负值,那么应该从右往左生长
  const x = points[0].y - points[1].y > 0 ? box.maxX : box.minX;
  const y = (box.minY + box.maxY) / 2;

  shape.applyToMatrix([x, y, 1]);

  const matrix = transform(shape.getMatrix(), [
    ['t', -x, -y],
    ['s', 0.01, 1],
    ['t', x, y],
  ]);
  shape.setMatrix(matrix);

  shape.animate(
    {
      matrix: transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 100, 1],
        ['t', x, y],
      ]),
    },
    animateCfg
  );
}
github antvis / G2 / src / geometry / animate / action.ts View on Github external
const x = (box.minX + box.maxX) / 2;
  const points = shapeModel.points as Point[];
  // 数值如果为负值,那么应该从上往下生长,通过 shape 的关键点进行判断
  const y = points[0].y - points[1].y <= 0 ? box.maxY : box.minY;

  shape.applyToMatrix([x, y, 1]);
  const matrix = transform(shape.getMatrix(), [
    ['t', -x, -y],
    ['s', 1, 0.01],
    ['t', x, y],
  ]);
  shape.setMatrix(matrix);

  shape.animate(
    {
      matrix: transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 1, 100],
        ['t', x, y],
      ]),
    },
    animateCfg
  );
}
github antvis / G2 / src / util / transform.ts View on Github external
export function rotate(element: IGroup | IShape, rotateRadian: number) {
  const { x, y } = element.attr();
  const matrix = transform(element.getMatrix(), [
    ['t', -x, -y],
    ['r', rotateRadian],
    ['t', x, y],
  ]);
  element.setMatrix(matrix);
}
github antvis / G2 / src / geometry / animate / action.ts View on Github external
animateCfg: AnimateCfg,
  coordinate: Coordinate,
  shapeModel: ShapeDrawCFG
) {
  const { x, y } = coordinate.getCenter();
  shape.applyToMatrix([x, y, 1]);
  const matrix = transform(shape.getMatrix(), [
    ['t', -x, -y],
    ['s', 0.01, 0.01],
    ['t', x, y],
  ]);
  shape.setMatrix(matrix);

  shape.animate(
    {
      matrix: transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 100, 100],
        ['t', x, y],
      ]),
    },
    animateCfg
  );
}
github antvis / G2 / src / animate / animation / util.ts View on Github external
export function transformShape(shape: IShape | IGroup, vector: [number, number], direct: string): number[] {
  let scaledMatrix;

  const [x, y] = vector;
  shape.applyToMatrix([x, y, 1]);
  if (direct === 'x') {
    shape.setMatrix(
      transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 0.01, 1],
        ['t', x, y],
      ])
    );
    scaledMatrix = transform(shape.getMatrix(), [
      ['t', -x, -y],
      ['s', 100, 1],
      ['t', x, y],
    ]);
  } else if (direct === 'y') {
    shape.setMatrix(
      transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 1, 0.01],
        ['t', x, y],
      ])
    );
    scaledMatrix = transform(shape.getMatrix(), [
      ['t', -x, -y],
      ['s', 1, 100],
      ['t', x, y],
github antvis / G2 / src / geometry / animate / action.ts View on Github external
export function grow(shape: IShape | IGroup, animateCfg: AnimateCfg, coordinate: Coordinate, shapeModel: ShapeDrawCFG) {
  const bbox = shape.getBBox();
  const x = (bbox.minX + bbox.maxX) / 2;
  const y = (bbox.minY + bbox.maxY) / 2;
  shape.applyToMatrix([x, y, 1]);
  const matrix = transform(shape.getMatrix(), [
    ['t', -x, -y],
    ['s', 0.01, 0.01],
    ['t', x, y],
  ]);
  shape.setMatrix(matrix);

  shape.animate(
    {
      matrix: transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 100, 100],
        ['t', x, y],
      ]),
    },
    animateCfg
  );
github antvis / G2 / packages / component / src / tooltip / canvas.ts View on Github external
containerHeight,
        panelClip ? panelClip.getBBox() : panelRange,
        this.get('enterable')
      );
      x = position[0];
      y = position[1];
    }

    const markerItems = this.get('markerItems');
    if (!Util.isEmpty(markerItems)) {
      endx = markerItems[0].x;
      endy = markerItems[0].y;
    }

    const ulMatrix = [1, 0, 0, 0, 1, 0, 0, 0, 1];
    const mat = transform(ulMatrix, [['t', x, y]]);
    container.stopAnimate();
    container.animate(
      {
        matrix: mat,
      },
      this.get('animationDuration')
    );

    const crosshairGroup = this.get('crosshairGroup');
    if (crosshairGroup) {
      const items = this.get('items');
      crosshairGroup.setPosition(endx, endy, items);
    }
    super.setPosition(x, y);
  }
github antvis / G2 / src / geometry / animate / action.ts View on Github external
export function zoomIn(
  shape: IShape | IGroup,
  animateCfg: AnimateCfg,
  coordinate: Coordinate,
  shapeModel: ShapeDrawCFG
) {
  const { x, y } = coordinate.getCenter();
  shape.applyToMatrix([x, y, 1]);
  const matrix = transform(shape.getMatrix(), [
    ['t', -x, -y],
    ['s', 0.01, 0.01],
    ['t', x, y],
  ]);
  shape.setMatrix(matrix);

  shape.animate(
    {
      matrix: transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 100, 100],
        ['t', x, y],
      ]),
    },
    animateCfg
  );
github antvis / G2 / src / geometry / animate / action.ts View on Github external
export function shrink(
  shape: IShape | IGroup,
  animateCfg: AnimateCfg,
  coordinate: Coordinate,
  shapeModel: ShapeDrawCFG
) {
  const bbox = shape.getBBox();
  const x = (bbox.minX + bbox.maxX) / 2;
  const y = (bbox.minY + bbox.maxY) / 2;
  shape.applyToMatrix([x, y, 1]);

  const { easing, duration, delay } = animateCfg;
  shape.animate(
    {
      matrix: transform(shape.getMatrix(), [
        ['t', -x, -y],
        ['s', 0.01, 0.01],
        ['t', x, y],
      ]),
    },
    duration,
    easing,
    () => {
      shape.remove(true);
    },
    delay
  );
}