Skip to content

IS-V1: iEEG Brain panel in the signal viewer - #552

Merged
neuromechanist merged 11 commits into
feature/issue-537-epic-spatialfrom
feat/is-v1-panel
Nov 18, 2026
Merged

neuromechanist merged 11 commits into
feature/issue-537-epic-spatialfrom
feat/is-v1-panel

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Card IS-V1 of the iEEG spatial view plan (the intracranial track of epic #537, ADR 0033).

What changed

On an intracranial EEG (iEEG) recording the signal viewer shows a "Brain" toggle. It opens a side panel that draws the recording's contacts in the frame the dataset declares (no anatomy yet: the template surface is IS-V2), colors them by the window's activity only while an "Activity" switch is on, links contacts and traces both ways, says plainly what it cannot show and why, and always carries the credit link.

  • src/lib/ieeg-spatial/panel.ts (new): a pure state machine (reduce, viewModel) that makes every decision, and createSpatialPanel, the DOM half that runs its effects (resolve the dataset's sidecars with geometry.ts, read level-0 samples in slices of 16 channels and compute them with activity.ts, drive brain-gl.ts) and paints its model. The credit is a field of the model in every state, so no state can leave it out; the DOM half mounts creditLink on every mount and no option omits it.
  • src/lib/ieeg-spatial/panel.test.ts (new): 69 tests, no DOM and no mocks. Geometry comes from the real files committed for IS-C1 and is read by the module's own resolveRecordingGeometry.
  • src/lib/eeg-viewer/viewer.ts: one optional ViewerOptions.spatial (dataset id, version, recording path); the Brain toggle (built only when the caller names the recording and some group is iEEG, shown only for an iEEG group); the panel's box in the plot row; a highlight band over the selected trace; clicks on a trace or its label select the channel's contact(s) while the panel is open; the panel is disposed with the viewer.
  • src/lib/eeg-viewer/viewer-session.ts: passes spatial for both mounts, so the dialog and the embed route get the panel. It is a view, not an action, and its credit is a plain link (ADR 0023).
  • src/styles/eeg-viewer.css: panel styles, all design tokens.
  • src/lib/ieeg-spatial/layout.ts (new, small): the rules the viewer needs before the panel's code loads (iEEG modality, beside or below, the scope floor).
  • e2e/ieeg-spatial-panel.spec.ts (new): the headless check, 10 tests.

Behavior the card fixes, as built:

  • The toggle is enabled once at least one channel resolves to a located contact; otherwise it is disabled and its title is the plain sentence for IS-C1's reason (nm000537: the no_coordinates sentence).
  • Panel, top to bottom: frame selector (only with more than one frame), canvas, the status line N of M channels located; frame: IDENTIFIER; positions as declared by the dataset, the Activity switch (off by default) with measure and band selectors and the colorbar, the contact list (a listbox: arrows, Home, End, Enter), and the credit link in the canvas corner.
  • Activity reads nothing while the switch is off or the panel is closed. A window over 4,000,000 samples (located channels times window samples) says "Zoom in to compute activity" and the contacts revert to the neutral color. Reads are sliced and yield between slices; a recording, group or frame change, closing the panel, or turning the switch off aborts any read in flight.
  • Without WebGL2 the panel shows the contact list, "3D view needs WebGL2" and the credit.

Deviations from the card

  1. Quiet retries (addition). The data plane answers 500 to about one directory listing in five (6 passes of 4 listings, measured: 5 of 24 failed), and one failed listing fails a whole resolution, so about half of first loads would otherwise show a refusal. The panel tries a failed read again after 300, 800 and 1600 ms before it shows one (resolveWithRetries, tested). Refusals that are properties of the data are never retried.
  2. A toggle that stays enabled for a failure that may pass. The card says disabled otherwise; for unreadable and listing_failed (IS-C1: possibly transient) the toggle stays enabled, titled "open to retry", so the panel can show the refusal, the credit and Retry. Every permanent reason is disabled with its sentence.
  3. Narrow layout, provisional. The card's stop condition asks the lead for the narrow layout if the panel cannot sit beside the scope at 360 px without hiding traces. Beside, the scope would be clipped (the viewer already draws at least 320 px). Below 720 CSS px of viewer width the panel goes below the scope at full width (spatialLayout, .eegv__plot--stack); the e2e measures it at 360 px (scope and panel both span the viewer, no sideways scroll). In the embed, whose scope fits the host, the panel counts as chrome there and the document may scroll. This is the part to confirm.
  4. Default frame. The card says "first template frame, else the first offered"; IS-C1's notes say never auto-pick the first space. Built as: the first space that can be shown and is a template, else the first that can be shown; the selector is always there with more than one frame, a refused frame is listed as "(unavailable)" and worded separately when chosen, and the status line always names the frame in use.
  5. Only contacts the recording's channels use are drawn (a contact with no trace has no activity and nothing to link to). N of M channels located counts channels.
  6. Label click. With the panel open, a click on a trace label selects its contact(s) instead of marking the channel bad; Shift+click on the label still marks it bad, and the help overlay says so. Clicks on the trace body select too, except while the annotation pencil is armed. With the panel closed nothing changes.
  7. No export canvas exists in this card (exports are IS-V3), so "every export canvas passes its own dpr to paintCredit" has no call site to check yet. A test scans src and fails any paintCredit call with fewer than five arguments (proved with a four-argument probe file).
  8. Added: a group change to a group that is not iEEG closes the panel (its toggle is then hidden); unlocated channels are listed with IS-C1's cause; test hooks as data attributes (data-spatial-*, data-stage, data-activity-state, data-activity-reads).
  9. The tests were written alongside the module, not before; each is proved by mutation instead (below).

Gates (head 55a1ef8)

  • bun install --frozen-lockfile: Checked 416 installs across 568 packages (no changes)
  • bun run typecheck: Result (503 files): 0 errors, 0 warnings, 19 hints (the base's 19 hints)
  • bun run lint: Checked 435 files in 190ms. No fixes applied.
  • bun run test src/lib/ieeg-spatial src/lib/eeg-viewer: Test Files 23 passed (23), Tests 772 passed (772)
  • bun run test: Test Files 183 passed | 3 skipped (186), Tests 5228 passed | 14 skipped (5242) (8.6 s)
  • bun run test:e2e e2e/ieeg-spatial-panel.spec.ts against bun run dev, PUBLIC_DATA_BASE_URL=https://data.nemar.org, headless: 10 passed (1.0m), twice in a row. It covers on005522 (toggle, contacts drawn, switch off by default with zero reads, switch on colors them, window moves re-read only while on, credit link href, target=_blank, rel with noopener, aria-label, Tab focus, aria-controls, Escape closing the panel and returning focus, selection both ways with a bipolar channel marking two contacts, recording change leaves nothing behind), that an EEG dataset (on009081) never requests the panel's code or an electrodes file, the no-WebGL2 state, a failed electrodes read (refusal, credit, Retry recovers), nm000537 (disabled, no_coordinates sentence) and 360 px (panel below, scope at least 280 px and drawn at its own height, stable, nothing scrolls sideways, closed panel changes nothing).
  • Bundle, measured with bunx astro build and gzip -9c <chunk> | wc -c. Base: viewer chunk 161,956 raw, 56,848 gzipped. Now the panel is its own chunk, fetched only for an iEEG recording: viewer chunk 166,137 raw, 58,277 gzipped (+1,429, the toggle, highlight band and loader); panel chunk 58,830 raw, 21,645 gzipped (renderer, activity, geometry, credit, panel). An EEG or MEG viewer pays the +1,429 only. Before this round, with the panel inside the viewer chunk, the viewer chunk was 222,880 raw and 78,070 gzipped for everyone. With brain-gl stubbed out the renderer measured +6,460 gzipped against its 14 KB budget (14,336), and the rest of the panel code +14,762 against the 30 KB budget (30,720); the split adds about 1.8 KB for the second chunk. The three generate:* Open Graph steps of bun run build were skipped (they render cards from the live catalog and touch no chunk), as in IS-R1.
  • Leak check on panel.ts, layout.ts, panel.test.ts, the e2e spec, the stylesheet and the added lines of the viewer files: all three commands print nothing.

Review round 1

The independent review found no critical issue and accepted the deviations; the driver accepted the stacked narrow layout with a floor. Fixed in this push (head 55a1ef8; the epic tip 4392b32 was already in the branch):

  • Stacked layout: the scope keeps at least 280 px while the panel is below it (.eegv__plot--stack .eegv__scope and stackedScopeHeight in the embed's fit, so the canvas is drawn at that height and the fit does not loop); the stack class is set only while the panel is open, so a closed panel changes nothing. The embed's document scrolls instead.
  • The paintCredit scan counts arguments without a trailing comma, and a test feeds it synthetic calls of 4 and 5 arguments with and without one.
  • A report for another token arriving while the read computes leaves the state unchanged (test).
  • Toggle: aria-controls names the panel box; Escape inside the panel closes it and returns focus to the toggle (e2e).
  • resolveWithRetries races its pause against the abort signal (abortableSleep), so an abort cancels the timer; tested with a 60 s pause that ends within 2 s.
  • computeActivityPlan (the slicing loop, now exported) refuses with mixed_units when a later slice's unit differs from the first slice's (voltage in one, field in another); tested on the real on006136 window, together with slicing not changing the values, not_level0, and abort.
  • The panel's code is a dynamic import() gated on an iEEG recording with a spatial input, after the first frame; EEG and MEG viewers fetch neither it nor any electrodes file (e2e). Because the viewer must not import panel.ts statically, the rules it needs moved to the small layout.ts. This departs from ADR 0033's "loaded with the viewer's lazy chunk": the driver amends that line.

Revert checks, each proved by a one-line mutation that fails the named test and reverted with a clean tree: stale token guard, mixed-units check, abort listener, slice size, abort before the first read, the floor in stackedScopeHeight and in the stylesheet, the counter's trailing-comma handling; for e2e, Escape's focus return, EEG loading the panel, the floor in the viewer's fit, aria-controls.

Mutation checks

Each test was shown to fail under a one-line mutation of panel.ts, reverted afterwards (git status --porcelain clean). The card's five: skipping the reset on a recording change (1: selection kept; the in-flight read not aborted; activity state kept), starting reads with the switch off (2), removing the 4,000,000 bound (3), selecting only the first contact of a bipolar channel (4), omitting the credit in the refusal state (5). Fifty more for the other tests (stale tokens, group and frame change, closing the panel, the Nyquist and short-window refusals, selection toggles, bounds on position warnings, millimeters only when scaled, the default frame, the toggle's reasons, retry counts and pauses); none survived. Four e2e mutations were also caught (reads while off, credit omitted, a permanent refusal left enabled, layout always beside).

Not run, would check

  • Every CI job green on the final head, because the manager reads gh pr checks.
  • Safari and Firefox: only Chromium was available.
  • Dark and light screenshots were looked at locally, not committed; IS-QA1 owns the real-data validation of colors and budgets.

Card: IS-V1. Part of #537

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 55a1ef8
Status: ✅  Deploy successful!
Preview URL: https://50ecc10c.nemar-website.pages.dev
Branch Preview URL: https://feat-is-v1-panel.nemar-website.pages.dev

View logs

@neuromechanist
neuromechanist merged commit 6419138 into feature/issue-537-epic-spatial Nov 18, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feat/is-v1-panel branch November 18, 2026 01:41
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