Repository navigation
Live At cursor measure for the iEEG Brain panel - #563
Merged
Merged
Conversation
Deploying nemar-website with
|
| Latest commit: |
7750f00
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8403e10e.nemar-website.pages.dev |
| Branch Preview URL: | https://feat-ieeg-live-activity.nemar-website.pages.dev |
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
The iEEG Brain panel's Activity overlay is now live. A new measure, "At cursor" (RMS, or line length as a second choice), is the default when Activity is switched on. The contact colors follow the pointer over the scope and change at mouse speed, with no new network request.
MAX_ACTIVITY_SAMPLES). It is released by everyabort_activityeffect: a window or option change, Activity off, a group or recording change, closing the panel, dispose.SpatialPanel.setCursor(timeS | null): the viewer calls it from the scope's mousemove, with null on mouseleave and when the pointer is off the traces or over the overlay, and again after each frame (so a window that scrolls under a resting pointer moves the cursor time with it). The panel coalesces calls to one recolor per animation frame.cursor_too_short). Band power and relative band power stay whole-window measures.requestAnimationFrame, recolors only (no layout, no geometry, no read), and the fast path allocates no per-contact data: preallocated arrays, a 256-entry viridis table, cached fill strings for the 2D fallback, and the renderer now rewrites its own color buffer in place (setColorsreuses it). The one string made per frame is the legend sentence.fillis rewritten in place, only for contacts whose color changed.withLive), so a figure saved at the cursor states the measure, window and cursor time. The contact list and files catch up once the pointer has rested 150 ms (LIST_IDLE_MS); they are too heavy for every frame.live-activity.ts(allocation-free engine),cursor-activity.test.ts. The pure short-window metric andcursorScalelive inactivity.ts.Deviations from the design, and why
cursor_changed,activity.cursorS) so it is testable, but the DOM half handles that event without a fullsync()(which would rebuild the model for every contact on each move). A full paint happens only when the live state turns on or off, and when the pointer rests.<title>s do not follow every frame (150 ms rest), see above.Measured cost (headless Chromium 148, software GL, nm000485, 136 located channels, 10 s window, data.nemar.org)
cursorFramecallback; the budget is 16 ms.Tests
bunx vitest run src/lib/eeg-viewer src/lib/ieeg-spatial test/brain-template-vendor.test.ts: 1090 passed. New:cursor-activity.test.ts(19: window edges and clipping, NaN refusal, units, rate too low, the committed on006136 slice against the external reference, a sine formula, scale fixed and percentile-bounded, engine bipolar mean and no-value index, 5000 updates with a flat heap), reducer tests inpanel.test.ts(default, width option, refusal sentence, cursor event, legend text, list and colors, other measures untouched), and a real-reader test inactivity-reads.test.ts(matrix retained, same values as the plain plan, no extra chunk fetch).bun run lint,bun run typecheck: clean.PUBLIC_DATA_BASE_URL=https://data.nemar.org bun run test:e2e e2e/ieeg-spatial-validation.spec.ts -g "cursor": 2 passed. Also ran the existing Activity budget test and the three panel specs touched here: passed.requestAnimationFrameand keys on the callback namecursorFrame, so it needs the dev server (unminified names).Not run
web/ieeg-spatial-view.md) are not edited; see the hand-off notes.Review round 1: what changed
createLiveCursor(panel.ts) with an injected clock, frame queue and timers (test infrastructure only; the state, reducer, matrix and engine are real). Tests inpanel.test.ts, "the live cursor's lifecycle": manysetCursorcalls queue one frame and recolor once; entering and leaving live are full paints; a cursor outside the read keeps whole-window values; the list catches up only afterLIST_IDLE_MSof rest; dispose with a frame queued (no throw, no recolor, timers cleared); matrix release on every abort path, one test each for window change, width change, measure change, Activity off, group change, recording change, panel close and dispose, each also checking a stale matrix is never measured (even against the old ready state); a new read replaces the old samples (values double when the samples double); position kept, not painted, while closed or off. The e2e stays the integration check.cursor-source.ts(tests incursor-source.test.ts) ends the cursor on pointerleave, pointercancel, touch pointerdown/up/cancel,touchstart/touchend/touchcancel, and ignores the compatibility mouse events after a tap; mouse behavior is unchanged. Keyboard: no cursor source, by design. The arrow keys already scroll the window and Shift-arrows page it, so spending them on a second meaning would break existing keyboard behavior; keyboard and touch users get the whole-window value, which the legend says in words (the legend paragraph is plain text in reading order, not a live region, and the measure select is labeled "At cursor: RMS").createCursorSource.windowMovedmaps the resting pixel against the current plot and clears the cursor when the plot narrowed past it or has zero width (cursor-source.test.ts: narrowing, zero width, no pointer).ispans[i, i + 1) / rateaftert0S(the left edge of sample 0, asfloor(start * rate)gives it), so the read covers[t0S, t0S + nSamples / rate]and both ends are valid; code is nowcenter < 0 || center > nSamplesand the docblock says so. Test "keeps a cursor exactly at either end of the read, and refuses one a hair past it".cursorScaletakes the contacts' channel rows and pools the same per-contact means the colors use. Tests: bipolar limits follow the pair mean, not raw channels (a one-contact scale collapses to the mean); the engine colors a pair with its mean on that scale.non_finite) from overflowed results (undefined_value) and takes the first channel's reason for a pair, ascontactValuesOfdoes;band_above_nyquistcannot occur for RMS and line length. Test "why a contact has no value...".live-activity.ts(no casts); docblock moved to its function;changedis now relative to an explicitcommit(), soviewState/synccalls never consume it, andmeasure()skips re-measuring the same center (test "changed is relative to the last commit"); the animation frame is cancelled on dispose.Also: the e2e timing probe now keys on the controller's
onFramecallback. Re-measured: 59 recolor frames for 60 moves, median 0.10 ms, worst 0.4 ms, entering frame 5.7 ms, 0 requests.Not run this round: the whole e2e suite, other browsers, GPU Chromium, real touch hardware (the touch handling is tested as logic only), CI.
Review round 2
createActivityRunner(panel.ts), which the shell'srun()anddispose()delegate to; the abort tests feed the reducer's own effects to it instead of callingrelease()by hand. New and changed tests inpanel.test.ts: each abort path (window change, width change, measure change, Activity off, group change, recording change, panel close, dispose) goes throughrunner.run; "a new read releases the old samples by itself, aborts the read before it, and starts after the debounce" runs only theread_activityeffect; "dispose reaches the live cursor" checks the queued frame survives the abort effect and onlyrunner.dispose()cancels it. Mutation check done: deleting the release onabort_activityfails 5 tests, deleting the release onread_activityfails 1, deletinglive.dispose()from the runner's dispose fails 1; all restored (119 passing). What stays outside unit tests: the one-line delegations in the shell (run()to the runner,dispose()torunner.dispose()), which need a DOM; the e2e recording-change and Activity specs exercise them.navigatein viewer-session.ts callsmountEegViewer, whose first act tears the old instance down), which builds a new cursor source and a new panel;recording_changedis dispatched only fromstart(), once per panel. Solastnever outlives the panel state it mirrors. No code change, one comment incursor-source.ts.viewsHtml. Accepted as not worth a change, and no test: showing it cannot happen needs a DOM. Reasoning: every full paint after live motion regenerates the SVG from the current exact colors, and the DOM's last recolor is for the latest cursor, so the two can only differ by the one-step table rounding, never by a wrong value.Re-run: targeted unit tests 1122 passed, lint and typecheck clean, the two
cursore2e tests pass (59 recolor frames for 60 moves, median 0.10 ms, worst 0.4 ms, entering frame 8.3 ms, 0 requests). Not run: whole e2e suite, other browsers, GPU Chromium, touch hardware, CI.Agentic AI tools were used. Workflows follow the Research Skills (doi:10.5281/zenodo.20696515). The author assumes full responsibility for this content and associated changes.