Repository navigation
refactor(editor): refactor zoom logic to use ViewBox - #188
Conversation
- Refactor ZoomWheel to use direct viewBox manipulation instead of padding - Eliminate logical issues with padding-based zoom (inverse scaling, 0-value traps) - Update StateManager to prioritize viewBox updates over padding - decouple zoom interaction from content BBox for consistent behavior
… checks - **Interaction**: - Implement **Mouse-Point Zoom** (Ctrl/Meta + Wheel) using client-to-viewport projection. - Implement **Zoom Reset** (Ctrl + Shift + Wheel) to restore default view. - Fix **Center Zoom** (Shift + Wheel) to strictly adhere to viewBox center stability. - **Tests**: - Add comprehensive unit tests (100% coverage) covering all zoom modes and edge cases. - Polyfill `DOMMatrix/DOMPoint` for JSDOM environment.
Summary of ChangesHello @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! This pull request significantly overhauls the SVG editor's zoom functionality. By transitioning from a problematic padding-based system to direct Highlights
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
This pull request is an excellent refactor of the zoom functionality, moving from a problematic padding-based approach to a much more stable and correct implementation using the SVG viewBox. The code is well-organized, introducing pure functions for zoom calculations and comprehensive unit tests for the new logic.
I've identified a few areas for improvement:
- There is a high-severity logic flaw in
state.tsthat prevents the new zoom reset functionality from working as intended. - The unit test for mouse-centered zoom could be strengthened to fully validate the behavior.
- A confusing comment in
zoom-wheel.tsshould be removed to improve code clarity.
Overall, this is a high-quality contribution that significantly improves the editor's stability and user experience. Addressing the points above will make it even better.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #188 +/- ##
==========================================
+ Coverage 44.81% 44.89% +0.07%
==========================================
Files 332 332
Lines 26438 26473 +35
Branches 2072 2081 +9
==========================================
+ Hits 11849 11884 +35
Misses 14579 14579
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
I’ll address this in the next commit. |
- **Logic Fixes** - `fix(state)`: Improve `updateOptions` to handle falsy `viewBox` values (enabling proper attribute removal). - **Test Coverage** - `test(viewbox)`: Unit tests for `calculateZoomedViewBox` (zoom, pivot, identity). - `test(zoom-wheel)`: Verified precise coordinates for mouse-centered zooming. - `test(state-manager)`: Added tests for `viewBox` lifecycle (update/removal).
|
/gemini review |
There was a problem hiding this comment.
Code Review
This is an excellent refactoring that replaces the previous padding-based zoom mechanism with a much more robust and mathematically sound viewBox manipulation approach. The code is clean, well-organized, and the accompanying tests are very comprehensive, covering numerous scenarios and edge cases. I've identified one high-severity bug related to boundary checks and have a couple of medium-severity suggestions to further improve maintainability and code organization. Overall, this is a high-quality contribution that significantly improves the stability and user experience of the zoom feature.
…SDOM. - Created __tests__/setup/dom-polyfills.ts to house shared SVG-related polyfills. - Replaced redundant inline implementations in coordinate.test.ts and zoom-wheel.test.ts. - Improved consistency and maintainability of the test suite.
|
@xxMudCloudxx Thanks for your contribution 🎉 |
Summary
Refactors the zoom interaction mechanism to directly manipulate the SVG
viewBoxinstead of adjustingpadding. This resolves critical stability issues where excessive negative padding caused SVG height collapse and provides a smoother, more mathematically correct zooming experience.The Problems (Motivation)
The previous implementation used padding modifications to simulate zooming. This approach had several fundamental flaws:
The Solution (Changes)
1. Direct ViewBox Manipulation (
src/editor/interactions/zoom-wheel.ts)viewBox-based zoom.viewBox.viewBoxusing a standard zoom factor (options.viewBoxdirectly viaUpdateOptionsCommand.shiftto zoom in/out from the center.Ctrl/Cmdto zoom towards the mouse pointer.Ctrl+Shift+Scrollto reset.viewBoxfrom becoming too small (min 20px) or too large (max 2000px).2. ViewBox Utilities (
src/utils/viewbox.ts)calculateZoomedViewBoxhelper function.3. Cleanup (
src/utils/padding.ts)setSVGPaddingis now only used for legitimate padding settings, not for simulating zoom.Future Plan