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

[Feature]: 分组组件的 自动扩展 如X6中的这个效果如何实现? #1750

Closed
wfxs2012 opened this issue Aug 9, 2024 · 1 comment · Fixed by #1892
Closed

[Feature]: 分组组件的 自动扩展 如X6中的这个效果如何实现? #1750

wfxs2012 opened this issue Aug 9, 2024 · 1 comment · Fixed by #1892

Comments

@wfxs2012
Copy link

wfxs2012 commented Aug 9, 2024

背景&目的

https://x6.antv.vision/zh/examples/node/group#expand-shrink
请教大佬,自己研究了一下没做出来呀

@DymoneLewis
Copy link
Collaborator

🤔看起来大概思路就是:

  • 监听node:drag事件,触发时取出data.id,调用getNodeModelById获取到对应的nodeModel
  • 遍历graphModel.nodes找出是分组节点且children.includes(data.id)的数据(groupModel)做以下操作:
    1. 从nodeModel和groupModel中取出x,y,height,width(groupModel的重命名成:gx,gy,gHeight,gWidth),然后设置一个阈值range
    2. 判断是否满足(x - width/2) <= (gx - gWidth/2 + 10) || (x + width/2) <= (gx + gWidth/2 - 10) || (y - height/2) <= (gy - gHeight/2 + 10) || (y + height/2) <= (gy + gHeight/2 - 10)
    3. 如果满足,分组节点对应的宽/高(x方向满足就做宽度处理,y方向满足条件就做高度处理,如果都满足就宽高都处理)+ range,分组节点的x/y也要相应做加减(如果子节点是在左/上方向移动,x/y要减去range;如果是右/下方向就加range)
    4. 不满足条件就不做处理

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