Skip to content

feat(gui): framework-neutral viewport with native pan/zoom (#218, fixes #147) - #226

Merged
CameronBrooks11 merged 1 commit into
mainfrom
feat/svelte-viewport
Jun 26, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
feat/svelte-viewport

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Closes #218. Closes #147. Replaces the react-zoom-pan-pinch PNG-preview viewport with a framework-neutral native pan/zoom, and fixes the long-standing zoom-clamp bug. Part of epic #214 (strangler-on-main: React still ships; Svelte stays behind the dev-only entry and out of vite build — unchanged at 595.75 kB).

What changed

  • src/lib/panzoom.ts — a small pure pan/zoom controller (zoomAt / pan / centered / clampScale). Applied as transform: translate(x,y) scale(s) with transform-origin: 0 0.
  • src/state/preview-session.svelte.ts — runes module porting usePreviewGeneration: validate inputs → schema-validate → plotDefinition (API) → PNG, with loading/error/warnings and a monotonic request-id stale guard (a superseded response never overwrites a newer one).
  • src/components/canvas/Viewport.svelte — the viewport: empty / generating / error / placeholder / image states, the layer scrubber, the zoom+refresh+export toolbar, and native wheel + pointer-drag pan/zoom. Wired into the Prepare workspace center region.

react-zoom-pan-pinch

Still in package.json because the live React VisualizationCanvas still uses it; zero .svelte files import it. Removed at the #221 cutover.

Verification

  • Local gate green: tsc, svelte-check (0/0), 714 vitest tests (+22: pan/zoom math incl. the GUI bug: plot viewer zoom is clamped to image bounds #147 small-zoom-up & large-pan-free cases, preview-session incl. stale guard, viewport states + wheel/toolbar wiring), coverage 82.8/72.2/81.0/81.9 (> 60/65/50/60), stylelint, lint:css:vars, vite build, bundle budget.
  • Production bundle unchanged at 595.75 kB (Viewport/panzoom/preview-session out of the rollup input).
  • Verified in-browser: empty state, scrubber + "Generate preview", and the error path all render (real image generation needs the Tauri sidecar; the pan/zoom math — the GUI bug: plot viewer zoom is clamped to image bounds #147 fix — is the unit-tested core). The error path also confirmed the toast renders as a styled fixed overlay.
  • Adversarially reviewed before commit.

Notes for reviewers

  • No change to the Python backend, OpenAPI contract, Rust shell, or the shipped React app.
  • Image rendering + interactive pan/zoom need tauri dev; the browser preview shows the non-image states.

Closes #218. Closes #147. Part of #214.

Replaces react-zoom-pan-pinch with a native CSS-transform pan/zoom and fixes the
zoom-clamp bug. Part of epic #214, strangler-on-main: React still ships; Svelte
stays behind the dev-only entry and out of the bundle (unchanged at 595.75 kB).

- lib/panzoom.ts: pure pan/zoom math (zoomAt/pan/centered/clampScale). Fixes #147
  — scale clamped to [0.1, 8] but translate is NEVER bounded, so a plot larger
  than the viewport pans freely to its overflow and a smaller one zooms up to 8x.
- state/preview-session.svelte.ts: runes port of usePreviewGeneration (validate →
  schema-validate → plotDefinition → PNG) with a monotonic request-id stale guard.
- components/canvas/Viewport.svelte: empty/generating/error/placeholder/image
  states, layer scrubber, zoom+refresh+export toolbar, native wheel + pointer-drag
  pan/zoom. Wired into the Prepare workspace.

react-zoom-pan-pinch stays in package.json for the live React path until #221.

715 tests (pan/zoom math incl. the #147 small-zoom-up & large-pan-free cases,
preview-session incl. a stale-response race, viewport states + wheel/toolbar).
Adversarially reviewed (#147 algebra verified; stale-guard race test added).

Closes #218. Closes #147. Refs #214
@CameronBrooks11 CameronBrooks11 added the gui Pull requests that update GUI components label Jun 26, 2026
@CameronBrooks11
CameronBrooks11 merged commit 8727e8c into main Jun 26, 2026
18 checks passed
@CameronBrooks11
CameronBrooks11 deleted the feat/svelte-viewport branch June 26, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gui Pull requests that update GUI components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace react-zoom-pan-pinch with a framework-neutral viewport (fixes #147) GUI bug: plot viewer zoom is clamped to image bounds

1 participant