Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用rotate旋转后,zoom-canvas失效,图谱不能放大或缩小 #2277

Closed
1 task done
52jaden opened this issue Nov 11, 2020 · 9 comments
Closed
1 task done
Labels
bug 🐛 Something isn't working

Comments

@52jaden
Copy link

52jaden commented Nov 11, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

项目中之前用的是3.6.0的版本,升级到最新的3.8.3,这个问题依然存在
在官方示例上,最下面添加了两行代码
graph.get('group').rotate(Math.PI / 2)
graph.moveTo(0,0)
实现rotate后,图谱不能放大或缩小了

Environment Info
g6 3.8.3
System mac
Browser chrome、edge均存在
@Yanyan-Wang
Copy link
Contributor

谢谢,是个 bug,接下来会跟进一下

@Yanyan-Wang Yanyan-Wang added the bug 🐛 Something isn't working label Nov 13, 2020
@52jaden
Copy link
Author

52jaden commented Nov 16, 2020

谢谢,是个 bug,接下来会跟进一下

大概什么时间会修复呢,我们这边项目需求要做调整

@52jaden
Copy link
Author

52jaden commented Nov 24, 2020

谢谢,是个 bug,接下来会跟进一下

大佬,这个还没有修复吗

@Yanyan-Wang
Copy link
Contributor

Yanyan-Wang commented Dec 1, 2020

经排查,是由于旋转后矩阵的取值方式应该与旋转前不同,但目前由于没有考虑到用户会旋转画布,所以取缩放系数都是取的 matrix[0].

目前可以这样进行旋转和缩放:

引用两个矩阵相关的 util 包

import { transform } from '@antv/matrix-util';
import { mat3 } from '@antv/matrix-util';

旋转:

        const center = [250, 250]; // 图的中心
        let matrix = graph.getGroup().getMatrix() || [1, 0, 0, 0, 1, 0, 0, 0, 1];
// 以图中心为旋转中心
        matrix = transform(matrix, [
          ['t', -center, -center],  // 先平移到中心
          ['r', Math.PI / 2], // 旋转
          ['t', center, center], // 再平移回去
        ]);
        graph.getGroup().setMatrix(matrix)

缩放:

// 可监听滚轮 graph.on('onWheel', e => {...}); 进行缩放
// 同样以图中心为缩放中心,也可以改为 e.x, e.y 作为缩放中心
        const center = [250, 250]; // 图的中心
        let matrix = graph.getGroup().getMatrix() || [1, 0, 0, 0, 1, 0, 0, 0, 1];
        mat3.translate(matrix, matrix, [-center.x, -center.y]);  // 平移到中心
        mat3.scale(matrix, matrix, [2, 2]); // 缩放 2 倍
        mat3.translate(matrix, matrix, [center.x, center.y]); // 平移回去
        graph.getGroup().setMatrix(matrix)

由于旋转画布这个操作比较少见,可能短期内还没有安排在内部解决旋转画布后的缩放问题

@WGL878420
Copy link

WGL878420 commented Aug 23, 2021

image
为啥transform报错啊
image
image

@Yanyan-Wang
Copy link
Contributor

graph.get('group').rotate(Math.PI / 2)
graph.moveTo(0,0)

请另开 issue 并提供一下在线复现 demo 哈

@Yanyan-Wang
Copy link
Contributor

由于旋转画布这个操作比较少见,没有计划支持该需求

@LeaveZzz
Copy link

自己使用graph.getGroup().setMatrix设置旋转矩阵之后,与矩阵相关的API全乱套了,focus、zoomTo等等。而且缩放操作时缩放中心并不是设置的center的位置。后续会支持内置的旋转画布操作吗?

@haibolian
Copy link

haibolian commented Dec 6, 2024

同旋转后zoom行为失效问题,可以旋转根 group 中的子group

const group = graph.getGroup();
group.cfg.children.forEach((child) => {
  child.rotate(Math.PI / 2);
});

https://codesandbox.io/p/sandbox/antv-g6-rotate-zoom-n2z7hx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants