preserve WSI viewport zoom level on resize and fullscreen - #2843
preserve WSI viewport zoom level on resize and fullscreen#2843katyayni1999000 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe WSI viewport now preserves fit-relative zoom during canvas resizing and fullscreen changes. It tracks prior dimensions, reapplies the target resolution after map resizing, and records when OpenLayers clamps the requested resolution. ChangesWSI zoom preservation
Estimated code review effort: 3 (Moderate) | ~15–30 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/RenderingEngine/WSIViewport.ts`:
- Around line 73-77: Update the manual zoom and camera-resolution paths,
including setZoom and setCamera, so any resolution change outside resize()
synchronizes _wsiZoomTarget with the new zoom and clears _wsiZoomClamped.
Preserve resize()’s clamped-target behavior while ensuring subsequent resizes
retain the latest manual zoom selection.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 680ef500-4ac8-487c-8cb9-7dff1728d4d5
📒 Files selected for processing (1)
packages/core/src/RenderingEngine/WSIViewport.ts
| // Fit-relative zoom preserved across resize / full screen (see | ||
| // resize()). 1 = fit-to-container. _wsiZoomClamped tracks whether the | ||
| // view clamped the resolution, so the next resize keeps the target. | ||
| private _wsiZoomTarget = 1; | ||
| private _wsiZoomClamped = false; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Synchronize the clamped zoom state after manual zoom changes.
After a clamp, Line 502 sets _wsiZoomClamped to true. A later call to setZoom or setCamera can change the view resolution. Line 471 then skips target derivation on every later resize. The next resize reapplies the stale target and discards the later zoom selection.
Update _wsiZoomTarget and clear _wsiZoomClamped when resolution changes outside resize().
Also applies to: 471-483
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/src/RenderingEngine/WSIViewport.ts` around lines 73 - 77,
Update the manual zoom and camera-resolution paths, including setZoom and
setCamera, so any resolution change outside resize() synchronizes _wsiZoomTarget
with the new zoom and clears _wsiZoomClamped. Preserve resize()’s clamped-target
behavior while ensuring subsequent resizes retain the latest manual zoom
selection.
Context
Problem
When a WSI (Whole Slide Imaging) viewport container is resized — e.g. toggling full screen, dragging a panel divider, or a responsive layout change — the zoom level resets to fit-to-slide. Users lose their current zoom position and have to re-navigate.
Changes & Results
Track the user's zoom as a ratio relative to the fit-to-container resolution (_wsiZoomTarget). On resize():
Derive the current fit-relative zoom from the old container size before updating.
Call map.updateSize() to let OpenLayers know about the new dimensions.
Compute the new fit resolution for the updated container and apply the preserved zoom target.
Detect if OpenLayers clamped the resolution to its min/max range (_wsiZoomClamped) so subsequent resizes don't ratchet the target.
Testing
Resize the browser window while zoomed into a WSI slide — zoom level is preserved.
Toggle full screen — same zoom level maintained.
Zoom to maximum resolution, then resize — clamped state is respected without drift.
Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Tested Environment
Summary by CodeRabbit