feat(#2246): 给多选框增加整体rotate 和 resize#5042
feat(#2246): 给多选框增加整体rotate 和 resize#5042zhangxilong-43 wants to merge 2 commits intoantvis:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求为图编辑器的 Selection 插件带来了重要的功能升级,允许用户对多个选中的节点进行整体的缩放和旋转操作。这一改进极大地提升了用户在处理复杂图表时的效率和体验,使其能够像在 Figma 等设计工具中一样,对一组元素进行统一的变换。通过引入新的交互手柄和精密的算法,确保了变换的准确性和流畅性,同时保持了对现有代码库的低影响性。 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
本次 PR 为多选框增加了整体旋转和缩放的功能,这是一个很棒的新特性。核心逻辑主要在 src/plugin/selection/selection.ts 中,代码实现质量很高,特别是旋转部分采用了快照和绝对定位来避免累积误差。
我发现了一个关键问题和一些可以改进的地方:
- 在计算选中节点组的边界框时,没有考虑节点的旋转角度,这会导致选择框大小不正确,从而影响旋转中心和缩放基准。
- 在缩放逻辑中,存在一个可以简化的表达式和一个魔法数字,建议提取为常量以提高代码可读性。
具体的修改建议请看我的评论。
Note: Security Review did not run due to the size of the PR.
Title: feat(selection): support group Resize & Rotate for multi-selected nodes
📝 Description
为 Selection 插件新增框选后统一 Resize 和 Rotate 的能力。选中 2 个及以上节点时,选框上出现 8 个缩放手柄和 1 个旋转手柄,拖拽手柄可对所有选中节点进行等比缩放或绕选框中心旋转。
核心改动:
src/plugin/selection/selection.ts(+430 行):手柄渲染、resize/rotate 事件处理和算法逻辑src/plugin/selection/style/raw.ts(+67 行):手柄 CSS 样式src/model/model.ts(+2 行):BatchName联合类型新增'group-rotate' | 'group-resize'设计要点:
model.ts的 2 行类型扩展;所有功能逻辑封装在 Selection 插件内部,新增方法均为protected,不改变任何已有公共 APIresizable/rotatable时行为与原来 100% 一致delegateEvents/delegateDocumentEvents,批操作复用model.startBatch/stopBatch(History 天然兼容),变换过程复用refreshSelectionBoxes同步更新🖼️ Screenshot
以下是改动后的效果

💡 Motivation and Context
当前 X6 的 Transform 插件仅支持对单个节点进行 Resize/Rotate,Selection 插件支持多选后整体拖拽移动,但不支持统一缩放和旋转。在图编辑器场景中,框选后统一变换是一个常见需求(类似 Figma 的多选变换行为)。
API 使用示例:
新增配置项:
resizableboolean | { minWidth?, minHeight?, preserveAspectRatio? }undefined(关闭)rotatableboolean | { grid? }undefined(关闭)grid为角度吸附步长新增事件:
selection:rotate{ cells: Node[], angle: number }selection:rotating{ cells: Node[], angle: number }selection:rotated{ cells: Node[], angle: number }selection:resize{ cells: Node[] }selection:resizing{ cells: Node[] }selection:resized{ cells: Node[] }🧩 Types of changes
🔍 Self Check before Merge