Skip to content

feat(core): add WSI right-drag zoom - #2870

Open
benjaminforras wants to merge 1 commit into
cornerstonejs:mainfrom
benjaminforras:wsi-drag-zoom
Open

feat(core): add WSI right-drag zoom#2870
benjaminforras wants to merge 1 commit into
cornerstonejs:mainfrom
benjaminforras:wsi-drag-zoom

Conversation

@benjaminforras

@benjaminforras benjaminforras commented Aug 18, 2026

Copy link
Copy Markdown

Context

Whole-slide microscopy viewports do not currently expose the existing DICOM Microscopy Viewer drag-zoom interaction. Applications that need region zoom therefore have to patch the built Cornerstone package.

This change enables region zoom in the source WSI render path while keeping the selection inside the slide extent.

Changes & Results

  • Activate drag zoom for the right mouse button after the microscopy viewer renders.
  • Clamp the drag interaction's coordinates and pixels to the slide projection extent, then restore the shared map event for other interactions.
  • Disable drag zoom if the peer viewer no longer adds one identifiable interaction with the expected handlers.
  • Keep the new peer-library capabilities optional in the public WSI compatibility types.
  • Add a regression test covering activation, extent clamping, pixel recalculation, and event restoration.

Before: right-dragging did not zoom a selected WSI region.

After: right-dragging shows the existing OpenLayers selection box and fits the selected in-slide region.

No dependency or user-facing configuration changes are included.

Testing

Automated checks:

  • pnpm exec jest --selectProjects core packages/core/test/dicomMicroscopyRenderPath.jest.js --runInBand - 34 suites passed, 552 tests passed, 2 skipped.
  • pnpm run build - passed for the workspace.
  • pnpm run test:ci - passed in Chrome Headless.
  • The repository pre-commit lint and formatting hook passed.

Manual verification steps:

  1. Load a WSI dataset in a generic whole-slide viewport.
  2. Right-drag across an area of the slide and confirm the selection box appears and the viewport fits that area.
  3. Right-drag beyond a slide edge and confirm the selected region stays within the slide extent.
  4. Confirm left-drag panning and wheel zoom retain their existing behavior.

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. No public documentation change is needed because this
    configures existing viewer behavior and adds no user-facing API.

Tested Environment

  • "OS: Microsoft Windows 11 Enterprise"
  • "Node version: 24.15.0"
  • "Browser: Chrome Headless 101.0.4950.0"

Summary by CodeRabbit

  • New Features

    • Added right-button drag zoom for whole-slide image viewing.
    • Drag interactions are constrained to the image boundaries for more predictable navigation.
    • Improved compatibility with viewers that provide optional map and interaction capabilities.
  • Bug Fixes

    • Prevented drag handling from modifying the original event coordinates.
    • Safely disables drag zoom when the viewer setup is incomplete or ambiguous.
  • Tests

    • Added coverage for drag-zoom activation, boundary clamping, and event preservation.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d8dd1fd-01f7-4eab-8dfc-e5998b048544

📥 Commits

Reviewing files that changed from the base of the PR and between 7034957 and bb534c1.

📒 Files selected for processing (3)
  • packages/core/src/RenderingEngine/GenericViewport/WSI/DicomMicroscopyRenderPath.ts
  • packages/core/src/utilities/WSIUtilities.ts
  • packages/core/test/dicomMicroscopyRenderPath.jest.js

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The render path now configures right-button drag zoom for WSI maps. It validates the required viewer and map APIs, clamps drag coordinates to the image extent, restores original events, and adds focused Jest coverage.

Changes

WSI drag zoom

Layer / File(s) Summary
WSI interaction contracts and activation
packages/core/src/utilities/WSIUtilities.ts, packages/core/src/RenderingEngine/GenericViewport/WSI/DicomMicroscopyRenderPath.ts
The WSI contracts define map events, interactions, coordinate conversion, and optional drag-zoom controls. The render path activates right-button drag zoom after data setup.
Constrained drag handlers and validation
packages/core/src/RenderingEngine/GenericViewport/WSI/DicomMicroscopyRenderPath.ts, packages/core/test/dicomMicroscopyRenderPath.jest.js
The render path validates the drag-zoom setup, clamps down, drag, and up event coordinates, restores original event values, and tests out-of-bounds events.
Estimated code review effort: 3 (Moderate) ~20 minutes

Merge Risk: ⚪ Minimal · up to bb534

This change adds right-drag zoom for WSI viewports with extent clamping and regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant DicomMicroscopyRenderPath
  participant WSIViewer
  participant WSIMap
  participant DragZoomInteraction
  DicomMicroscopyRenderPath->>WSIViewer: Activate right-button drag zoom
  DicomMicroscopyRenderPath->>WSIMap: Get interactions
  DicomMicroscopyRenderPath->>DragZoomInteraction: Wrap down, drag, and up handlers
  DragZoomInteraction->>WSIMap: Convert clamped coordinates to pixels
  DragZoomInteraction-->>DicomMicroscopyRenderPath: Restore original event values
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change and follows the semantic-release format.
Description check ✅ Passed The description includes context, changes, testing results, manual verification steps, and completed checklist items.
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
🧪 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.

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