Skip to content

ENH: Zoom the demo app's viewers with the mouse wheel - #423

Merged
thewtex merged 2 commits into
mainfrom
demo-zoom
Oct 12, 2026
Merged

thewtex merged 2 commits into
mainfrom
demo-zoom

Conversation

@thewtex

@thewtex thewtex commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

The demo app's niivue viewers now zoom with the mouse wheel. This PR also moves the demo to niivue 1.0.0-rc.21.

Mouse-wheel zoom

Before this change the wheel did nothing on 2D images. niivue zooms a 2D view on the wheel only when one of the drag modes is "pan". The demo used niivue's defaults: left button moves the crosshair, right button adjusts contrast. With those, the wheel steps through slices, and a 2D image has only one slice.

createViewerPanel (src/viewer/panel.ts) now passes two options to the NiiVue constructor:

  • secondaryDragMode: DRAG_MODE.pan: the right button pans, which turns on wheel zoom.
  • wheelZoomAnchor: 'pointer': zoom centres on the mouse rather than the crosshair, because 2D images are drawn without a crosshair.

The existing panel link already sends pan and zoom to the other panels, so all four panels zoom and pan together. "Reset view" already restores them.

Behavior changes:

  • Right-drag no longer adjusts contrast (window/level).
  • On 3D volumes in the slice layouts, the wheel zooms instead of stepping slices. Clicking still moves the crosshair to another slice.
  • The 3D render view zoomed on the wheel before and is unchanged.

niivue 1.0.0-rc.16 → 1.0.0-rc.21

This moves to the newest 1.0 pre-release, published under npm's next tag. npm's latest tag still points to the 0.x line, whose API the demo doesn't use.

The only breaking change between the two versions is the removal of LUT.centroids, which the demo doesn't use. niivue's own dependencies resolve to the same versions as before. @niivue/cbor-loader is already at its latest, 1.2.1.

Tests

  • test/viewer.spec.ts gains two steps:
    • Scrolling over the inputs comparison raises the 2D zoom.
    • Right-dragging over it pans.
      Both check that all four panels still agree. Both steps fail with the old drag modes.
  • On rc.21: typecheck passes, all 317 unit tests pass, and all 38 Playwright tests pass (Chromium).

🤖 Generated with Claude Code

thewtex and others added 2 commits October 12, 2026 13:08
niivue zooms a 2D view on the wheel only when a drag mode pans; with the
default modes (crosshair, contrast) the wheel steps slices, which does
nothing on a 2D image. Make the right button pan, which turns on wheel
zoom, and anchor the zoom at the pointer, since 2D images are drawn
without a crosshair. The panel link already broadcasts pan and zoom, so
all four panels follow, and "Reset view" restores them.

Right-drag no longer adjusts contrast, and on 3D volumes the wheel now
zooms the slice views instead of stepping slices.

The viewer spec scrolls and right-drags over the inputs comparison and
checks that every panel zooms and pans together.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Move from 1.0.0-rc.16 to the newest 1.0 pre-release (npm's next tag;
latest still points at the 0.x line, whose API the demo does not use).
The only breaking change in between, the removal of LUT.centroids, does
not touch the demo. @niivue/cbor-loader is already at its latest, 1.2.1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@thewtex thewtex changed the title demo zoom ENH: Zoom the demo app's viewers with the mouse wheel Oct 12, 2026
@thewtex
thewtex merged commit 9de4d21 into main Oct 12, 2026
18 checks passed
@thewtex
thewtex deleted the demo-zoom branch October 12, 2026 17:24
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