Skip to content

fix(editor): optimize ResetViewBox positioning and remove zoom UI from site LiveEditor - #201

Merged
Aarebecca merged 4 commits into
antvis:mainfrom
xxMudCloudxx:fix/reset-viewbox-bottom-layout
Feb 10, 2026
Merged

Aarebecca merged 4 commits into
antvis:mainfrom
xxMudCloudxx:fix/reset-viewbox-bottom-layout

Conversation

@xxMudCloudxx

Copy link
Copy Markdown
Contributor

本次修改旨在修复 ResetViewBox 按钮在父容器存在 CSS transform(如缩放)时的定位偏移问题。同时,清理了 PreviewPanel 中不再需要的缩放控制代码。

改动详情

1. 修复按钮定位逻辑

文件: src/editor/plugins/reset-viewbox.ts

  • 相对坐标计算:更新 placeButton 方法,采用相对于 offsetParent 的坐标计算方式,使其能够自适应父容器的 transform 变换。
  • Transform 缩放补偿:引入了对当前 transform scale 的动态计算,确保布局布局参数包含 CSS 缩放的影响。

2. 增强鲁棒性 (Robustness)

为了应对复杂的集成环境,对插件底层逻辑进行了加固:

  • 边界限制 (Boundary Clamping):新增 findStableContainer 逻辑,识别最近的滚动或 overflow 容器。当 SVG 内容超出容器时,强制将按钮位置限制在容器可视区域内,防止按钮“溢出”不可见。
  • 安全计算:
    • 在计算缩放比例 (getTransformScale) 时增加了对 offsetWidth/Height 为 0 的检查,防止除以零导致的 NaN 错误。
    • 在执行定位更新前增加 svg.isConnected 检查,避免对未挂载的 DOM 元素进行无效计算。
  • 空值兜底:为 offsetParent 和容器检测提供了完善的兜底逻辑,确保在极端的 DOM 树结构下依然保持程序稳定。

3. 代码清理

文件: site/src/components/LiveEditor/PreviewPanel.tsx

  • 简化组件结构:移除了约 100 行与旧版 transform/缩放控制相关的代码。

前后对比

修改前:

transform会影响到按钮的定位
image

修改后:

移除PreviewPanel 缩放控制逻辑前, 按钮不会溢出:
image

移除PreviewPanel 缩放控制逻辑后的UI布局:
image

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @xxMudCloudxx, 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!

本次拉取请求主要致力于提升编辑器中 ResetViewBox 按钮的用户体验和代码质量。通过精确调整按钮的定位逻辑,使其能够适应复杂的 CSS 变换环境,并确保在内容溢出时仍能正确显示。同时,移除了冗余的缩放功能代码,使 PreviewPanel 组件更加精简高效。

Highlights

  • 修复 ResetViewBox 按钮定位: 解决了 ResetViewBox 按钮在父容器有 CSS transform(如缩放)时定位不准确的问题,通过采用相对于 offsetParent 的坐标计算和动态缩放补偿,确保按钮始终位于正确位置。
  • 增强插件鲁棒性: 引入了边界限制逻辑,识别最近的滚动或 overflow 容器,确保按钮在 SVG 内容溢出容器时仍能被限制在可视区域内。同时,增加了对除零错误的检查和未挂载 DOM 元素的处理,提升了程序的稳定性。
  • 移除不必要的缩放控制: 从 PreviewPanel 组件中删除了旧的、不再需要的缩放状态、处理函数和相关的 UI 元素(如缩放按钮和滚轮缩放逻辑),简化了组件结构和代码。
Changelog
  • site/src/components/LiveEditor/PreviewPanel.tsx
    • 移除了 zoom 状态及其相关的 handleZoomIn, handleZoomOut, handleResetZoom 函数。
    • 删除了 containerRef 引用。
    • 移除了处理滚轮缩放的 useEffect 钩子。
    • 从 JSX 中移除了缩放控制条及其按钮。
    • 移除了 Infographic 组件上的 transform 样式属性。
  • src/editor/plugins/reset-viewbox.ts
    • 新增了 stableContainer 私有属性,用于缓存最近的稳定容器。
    • 新增 getTransformScale 方法,用于获取元素的 CSS transform 缩放比例,并增加了对 offsetWidth/Height 为 0 的安全检查。
    • 新增 findStableContainer 和 _findStableContainer 方法,用于查找最近的滚动或 overflow 容器,以实现边界限制。
    • 修改 placeButton 方法,使其使用相对于 offsetParent 的坐标计算,并考虑父元素的 transform 缩放。
    • 在 placeButton 中引入了 effectiveRect 逻辑,根据 stableContainer 对按钮位置进行边界限制,防止溢出。
    • 在 placeButton 中增加了 svg.isConnected 检查,避免对未挂载的 DOM 元素进行操作。
    • 在 destroy 方法中重置 stableContainer。
Activity
  • 目前没有与此拉取请求相关的评论、审查或进展活动。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 主要优化了 ResetViewBox 插件的定位逻辑,并清理了网站 LiveEditor 中不再需要的缩放 UI,目标明确,改动清晰。

核心的定位修复逻辑考虑了父元素的 transform: scale 影响,并增加了对容器边界的判断,增强了插件的鲁棒性,值得肯定。

我提出了两点可以进一步提升代码鲁棒性的建议,主要集中在 reset-viewbox.ts 文件中:

  1. 建议移除对 stableContainer 的缓存,以更好地应对动态 DOM 变化。
  2. 建议调整 _findStableContainer 中的循环逻辑,以确保能正确检查 <body> 和 <html> 元素作为潜在的溢出容器。

整体来看,这是一次高质量的修复和重构。采纳建议后,代码的健壮性将得到进一步提升。

Comment thread src/editor/plugins/reset-viewbox.ts Resolved
Comment thread src/editor/plugins/reset-viewbox.ts Resolved
@codecov-commenter

codecov-commenter commented Feb 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 48.83721% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.93%. Comparing base (11bfa9a) to head (dbded3d).

Files with missing lines Patch % Lines
src/editor/plugins/reset-viewbox.ts 48.83% 21 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #201      +/-   ##
==========================================
+ Coverage   45.92%   45.93%   +0.01%     
==========================================
  Files         338      338              
  Lines       27000    27038      +38     
  Branches     2189     2200      +11     
==========================================
+ Hits        12400    12421      +21     
- Misses      14590    14606      +16     
- Partials       10       11       +1     
Flag Coverage Δ
infographic 45.93% <48.83%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/editor/plugins/reset-viewbox.ts 76.43% <48.83%> (-5.92%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@Aarebecca
Aarebecca merged commit c4e7e8b into antvis:main Feb 10, 2026
1 check passed
@xxMudCloudxx
xxMudCloudxx deleted the fix/reset-viewbox-bottom-layout branch February 10, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants