Skip to content

feat: viewer P1 - filters, full-res lines, butterfly, minimap, cursor, keyboard (website#99) - #103

Merged
neuromechanist merged 5 commits into
mainfrom
feat/viewer-p1
Jun 3, 2026
Merged

neuromechanist merged 5 commits into
mainfrom
feat/viewer-p1

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

P1 feature set for the Zarr signal viewer (follows the merged P0 #101), website#99.

Highlights

  • Crisp full-resolution lines by default. useSuffixRequest: true on the FetchStore makes the sharded level-0 read a native suffix index + the window's inner chunks (~127 KB for a 10 s window) instead of a redundant ~3 MB full-shard GET. The default window now renders actual level-0 samples (clean EEG lines), with the view pyramid reserved for wide overviews.
  • Client HP/LP/notch filters (filters.ts, zero-phase filtfilt biquad cascade, RBJ design). Display-only: reads level-0 for a padded window, applies the cascade, crops the transient pad, renders. Essential for line-noise-heavy recordings (50/60 Hz notch). Status shows filtered; greys when the window is too wide for level-0.
  • Overview minimap: whole-recording activity envelope (one coarse view-level read) + event ticks + the current-window box; click to jump.
  • Cursor readout: Chan / Time / Value on hover.
  • Butterfly (b): overlay all channels in one slot to spot outliers.
  • Bad-channel marking: click a label to dim it.
  • Time-format toggle (t): seconds <-> HH:MM:SS.
  • Extended keyboard: Home/End window size, b/t, ? help overlay (plus the P0 nav/scale/DC keys).

Tests / checks

  • New no-mock unit tests: filters.test.ts (HP removes DC, LP attenuates, notch suppresses 60 Hz, zero-phase), overview aggregate. 543 tests pass, 0 type errors, lint clean, build succeeds.
  • Verified live against nm000132 + a backfilled on007139 (heavy 50 Hz line noise) on the dev server.

Follow-ups: per-segment level-0 sharding for sample-zoom at very wide windows; P2 (montage reorder, annotations, two-cursor, WebGL, multi-store, electrode layout).

Butterfly mode (b key + checkbox) overlays all visible channels in one
full-height slot for outlier detection. Bad-channel marking (click label
in gutter) dims traces and labels to 30% alpha. Both paths share the
refactored renderStacked/renderButterfly helpers.

FrameChannel gains optional `dim?: boolean`; renderFrame accepts
`butterfly?: boolean` in RenderOptions. No existing tests broken.
Mousemove over the plot shows "Chan · time · value" (using formatSi).
Clock toggle (t key + checkbox) switches axis ticks to HH:MM:SS.
Home/End step through WINDOW_CHOICES. ? toggles a key-listing help
overlay. Butterfly and Clock checkboxes added to Display group.
New eegv__cursor / eegv__help / eegv__minimap CSS in BidsTree.astro.
readOverview reads the coarsest view-pyramid level and aggregates to a
per-column max-range Float32Array (aggregateOverview, pure + tested).
The minimap draws the activity bars, event tick marks colored by type,
and a translucent blue box for the current window; clicking jumps to
the clicked time. Minimap hidden when no view levels exist.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: ab7abb7
Status: ✅  Deploy successful!
Preview URL: https://a28409c9.nemar-website.pages.dev
Branch Preview URL: https://feat-viewer-p1.nemar-website.pages.dev

View logs

- readFrame: when a filtered window is too wide for level-0 and falls back
  to the pyramid band, re-read the visible (unpadded) window so nCols/time
  align with the axis (was shifting traces left by padS).
- readFrame: report filtered=false when designFilters yields no biquads
  (all cutoffs >= Nyquist) so the status note does not over-claim.
- loadOverview: sequence-guard the fire-and-forget load + catch errors so a
  group switch can't flash stale minimap data and a rejection can't escape.
- render(): wrap renderImpl so event-handler/observer calls can't raise an
  unhandled rejection on a synchronous paint throw.
- readOverview: validate [2,nCh,nTime] shape before indexing dims.
- render butterfly legend: drop double-dim (0.3 fill x 0.3 alpha) on bad chans.
- drawOverview: single durationS axis (zero-guarded) for ticks + window box.
- cache trace-slot layout per frame; reuse in click/move hit-tests.
- renderUnavailable: warn (not debug) so structural failures are visible.
- tests: HP+LP band-pass cascade; aggregateOverview siFactor + offset.
- comments: clarify level-0 cap + view-fallback wording.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review response (6 pr-review-toolkit agents, Sonnet)

Ran code-reviewer, silent-failure-hunter, type-design, test-analyzer, simplifier, and comment-analyzer against main...feat/viewer-p1. Addressed in ab7abb7.

Addressed

  • Time-shift bug (HIGH): filtered window too wide for level-0 fell back to the pyramid band but returned the padded span's nCols, shifting every trace ~padS left of the axis. Now re-reads the visible (unpadded) window on fallback.
  • Overview load race + unhandled rejection (CRITICAL/HIGH): loadOverview was a fire-and-forget, unguarded promise. Added a sequence guard (group switch can't flash stale minimap data) + error catch, and wrapped render() so handler/observer calls can't raise an unhandled rejection on a synchronous paint throw.
  • filtered over-claim (MED): designFilters returning empty (all cutoffs >= Nyquist) now reports filtered:false instead of "filtered".
  • readOverview shape (MED): validates [2,nCh,nTime] before indexing dims.
  • Butterfly legend double-dim (MED): dim legend was 0.3 fill x 0.3 alpha = 0.09; now uses globalAlpha alone.
  • Logging: renderUnavailable warns instead of console.debug (hidden by default).
  • Cleanup: single zero-guarded durationS in drawOverview; trace-slot layout cached per frame and reused by the click/move hit-tests.
  • Tests (+3): HP+LP band-pass cascade; aggregateOverview non-unity siFactor + non-zero offset.
  • Comments: clarified the level-0 cap + view-level fallback wording.

Deliberately skipped (false positive / by design)

  • retryingFetch retries thrown errors: intended. The wrapper only wraps fetch(); zarrita decode happens after it returns, so decode errors never enter this loop. Retrying a network throw is the resilience goal.
  • discoverViewLevels continue-on-non-404: the proposed "continue" would punch a hole in the contiguous viewLevels array (indexed by position), breaking level selection. Break-at-gap is correct; transient metadata 429/5xx are already retried by the store fetch.
  • No-pyramid level-0 cap: a store lacks a pyramid only when the recording is short (biosigIO builds it above a small threshold), so the fallback can't over-fetch in practice. Comment clarified instead.
  • FilterSpec drop null: the undefined/null/0 "off" encodings are all funneled through ?? 0 > 0 guards and unit-tested; Number(x) || null is the idiom. Cosmetic; not worth churn across the typed handlers/tests.
  • GroupHandle hardening (rowIndex uniqueness, drop redundant nChannels, rate upper-bound): stores are produced solely by biosigIO with valid contiguous rowIndex and correct n_channels; the existing mismatch warn + rate=250 fallback suffice. Defends against inputs this pipeline can't emit.
  • WindowData level/kind union refactor + computePxPerPhys merge: structural polish with no behavior change; readFrame already uses kind as ground truth. Deferred.

546 tests pass, 0 type errors, lint clean, build green.

@neuromechanist
neuromechanist merged commit 9355a40 into main Jun 3, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feat/viewer-p1 branch June 3, 2026 14:48
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