Skip to content

preserve WSI viewport zoom level on resize and fullscreen - #2843

Open
katyayni1999000 wants to merge 1 commit into
cornerstonejs:mainfrom
katyayni1999000:fix/wsi-zoom-preserve-resize
Open

preserve WSI viewport zoom level on resize and fullscreen#2843
katyayni1999000 wants to merge 1 commit into
cornerstonejs:mainfrom
katyayni1999000:fix/wsi-zoom-preserve-resize

Conversation

@katyayni1999000

@katyayni1999000 katyayni1999000 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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

  • [] My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • [] My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • [] The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • [] "OS:
  • [] "Node version:
  • [] "Browser:

Summary by CodeRabbit

  • Bug Fixes
    • Preserved zoom levels when resizing the viewport or switching to fullscreen.
    • Prevented unintended zoom drift when the viewport dimensions change.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

WSI zoom preservation

Layer / File(s) Summary
Resize zoom state and recalculation
packages/core/src/RenderingEngine/WSIViewport.ts
WSIViewport stores fit-relative zoom and resolution-clamping state. resize() recalculates the target, updates the map size, reapplies the resolution, and records clamping.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Possibly related PRs

Suggested reviewers: wayfarer3130

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers context, changes, and testing, but all checklist items are unchecked and the tested environment is missing. Mark applicable checklist items as complete and provide the OS, Node version, and browser used for testing.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes preserving WSI viewport zoom during resize and fullscreen changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between ab8a356 and 14bb5ff.

📒 Files selected for processing (1)
  • packages/core/src/RenderingEngine/WSIViewport.ts

Comment on lines +73 to +77
// 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant