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

自定义矩形形状的节点,聚焦节点focusItem的时候没有定位到中心(上下左右间距不一样) #5734

Open
wuzengduo opened this issue May 13, 2024 · 4 comments

Comments

@wuzengduo
Copy link

wuzengduo commented May 13, 2024

Describe the bug

自定义矩形形状的节点,聚焦节点focusItem的时候没有定位到中心(左右间距不一样)

Your Example Website or App

https://g6.antv.antgroup.com/examples/item/customNode/#card

https://g6.antv.antgroup.com/examples/item/customNode/#card这里添加聚焦的逻辑:
function handleNodeClick(event) {
const item = event.item;
// animately move the graph to focus on the item.
// the second parameter controlls whether move with animation, the third parameter is the animate configuration
graph.focusItem(item, true, {
easing: 'easeCubic',
duration: 500,
});
}

// listen to the node click event
graph.on('node:click', handleNodeClick);

image

Steps to Reproduce the Bug or Issue

  1. 点击一个节点
  2. 聚焦到该节点,上下左右间距不一样
image

Expected behavior

期望该节点在中心,即上下左右间距一样,实际上左右间距不一样

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

@wuzengduo wuzengduo changed the title 自定义矩形形状的节点,聚焦节点focusItem的时候没有定位到中心(左右间距不一样) 自定义矩形形状的节点,聚焦节点focusItem的时候没有定位到中心(上下左右间距不一样) May 13, 2024
@Aarebecca
Copy link
Contributor

目测是自定义节点的锚点位置导致的,一般节点是以中心位置定位的,矩形节点使用了左上角来进行定位,导致 focus 看起来不在画布中心

@wuzengduo
Copy link
Author

目测是自定义节点的锚点位置导致的,一般节点是以中心位置定位的,矩形节点使用了左上角来进行定位,导致 focus 看起来不在画布中心

请问怎么修改自定义节点的这个锚点呢?

@LeaveZzz
Copy link

目测是自定义节点的锚点位置导致的,一般节点是以中心位置定位的,矩形节点使用了左上角来进行定位,导致 focus 看起来不在画布中心

请问怎么修改自定义节点的这个锚点呢?

给每一个shape的x、y增加一个-w / 2、-h / 2的偏移量

@wuzengduo
Copy link
Author

目测是自定义节点的锚点位置导致的,一般节点是以中心位置定位的,矩形节点使用了左上角来进行定位,导致 focus 看起来不在画布中心

请问怎么修改自定义节点的这个锚点呢?

给每一个shape的x、y增加一个-w / 2、-h / 2的偏移量

已解决,感谢大佬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants