G6 icon indicating copy to clipboard operation
G6 copied to clipboard

节点内shape的旋转动画如何指定旋转中心?

Open SilenceChen opened this issue 6 years ago • 5 comments

  • G6 Version:
  • Platform:
  • Mini Showcase(like screenshots):
  • CodePen Link:
shapes[11].animate(
  (ratio: any) => {
    const matrix = G6.Util.mat3.create();
    const toMatrix = G6.Util.transform(matrix, [['r', ratio * Math.PI * 2]]);
    return {
      matrix: toMatrix
    };
  },
  {
    repeat: true,
    duration: 1000
  }
);

用这种方式旋转图形,图形的旋转中心是节点的(0,0)坐标,在图形不在(0,0)坐标时如何自旋呀~

SilenceChen avatar Aug 27 '20 10:08 SilenceChen

如果是官网上这个例子,https://g6.antv.vision/zh/examples/scatter/node,这样就是沿着左上角旋转:

const toMatrix = Util.transform(matrix,
            [['t', width / 2, height / 2],
            ['r', ratio * Math.PI * 2],
            ['t', -width / 2, -height / 2]]);

总体思想就是先把需要旋转的物体的旋转中心移动到 (0, 0) 然后旋转,再移回去

Yanyan-Wang avatar Aug 27 '20 11:08 Yanyan-Wang

谢谢谢谢~

SilenceChen avatar Aug 27 '20 11:08 SilenceChen

帮了大忙,感谢!

Kole6 avatar Nov 02 '22 06:11 Kole6

[['t', width / 2, height / 2], ['r', ratio * Math.PI * 2], ['t', -width / 2, -height / 2]]

感谢大佬,折腾了半天。

snowsunset avatar Feb 17 '23 02:02 snowsunset

感谢,管用,不过我是

[['t', -width / 2, -height / 2], ['r', ratio * Math.PI * 2], ['t', width / 2, height / 2]]

haibolian avatar Oct 12 '24 03:10 haibolian