Skip to content

IS-V3: 2D three-view fallback and figure exports with the credit - #555

Merged
neuromechanist merged 8 commits into
feature/issue-537-epic-spatialfrom
feat/is-v3-exports
Nov 18, 2026
Merged

neuromechanist merged 8 commits into
feature/issue-537-epic-spatialfrom
feat/is-v3-exports

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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

What changed

Without WebGL2, or when the reader asks, the panel draws the contacts in three orthographic views (left, top, front) as accessible SVG; "Save PNG" and "Save SVG" produce figure files that carry the credit inside them.

  • src/lib/ieeg-spatial/views2d.ts (new, pure): layoutViews (one scale for all three views, orientation pinned to camera.ts's presets by a test, far-to-near drawing order, selected contact last, radius by the 3D view's rule only when units are millimeters), viewsMarkup (a <g> per view, one <circle> with a <title> per located contact), parseViewOutlines (reads the vendored views.json, refuses anything else). A contact without a finite position is never drawn.
  • src/lib/ieeg-spatial/export.ts (new): exportSvg and exportPng, the only entry points. One Figure (title, 3D frame or the three views, colorbar, labels wrapped to lines, a reserved footer) is read by two serializers: buildDrawList (the raster operations, the last one is always the credit, run by rasterize with the export canvas's own ratio, 2 canvas pixels per figure pixel) and buildSvg (views, labels, colorbar, a <metadata> block with dataset id, version, recording path, frame, every label, the credit and its address and the paper DOI, and last the credit's <a href> around its <text> from creditSvg). File names are <recording stem>_contacts_<frame>.png|svg, from the path and a closed vocabulary.
  • src/lib/ieeg-spatial/panel.ts: PanelState.view2d, event view_changed, stage kind views2d, PanelModel.view; the DOM half adds the "2D views" switch (disabled and pressed without WebGL2, with that sentence as its title), the two save buttons, the inline SVG views (click a dot to select; the contact list stays the keyboard path), and a download helper that says in words when the browser refuses. templatePlacementFor(state) is the named seam for IS-V2.
  • src/styles/eeg-viewer.css: the 2D stage, the actions row, and .eegv__spatial-inner > * { flex-shrink: 0 } (with the extra row the panel's content can exceed the scope's height, and a shrinking flex child squashed the contact list to nothing; the panel scrolls instead).
  • e2e/ieeg-spatial-panel.spec.ts: 4 more tests (below).

The files say what the screen says: every label is read from the panel's own PanelModel (status line, frame choice, template sentences, notes, activity message, summary and no-data line, colorbar ends, the selection), in the same words. The SVG is always the three views; the PNG is the live 3D frame (BrainRenderer.snapshot(), no API change was needed) when the view is 3D, and the three views otherwise.

Seam for IS-V2 (documented in export.ts and panel.ts)

templatePlacementFor(state): TemplatePlacement | null in panel.ts returns null for every state today, so no outline is drawn and no template sentence is said. IS-V2 replaces its body. TemplatePlacement (in export.ts) carries outlines (from views.json, via parseViewOutlines), optional positions (one per placed contact, in the template's millimeters after IS-V2's transform; absent means as declared) and labels (the template and "approximate" sentences). The 2D views and both exports read this and nothing else. No transform and no mesh loading is implemented here. Live 3D template sentences are IS-V2's to paint from the same value.

Deviations and interpretation

  1. The card's one exportPng(state) takes an ExportInput (state, its viewModel, the contactColors, the theme tokens, the seam value, the frame name) plus the optional 3D frame, so the pure builders need no import of panel.ts values (no import cycle).
  2. "Every label visible on screen" is read as the panel's text around the picture. The contact list is not restated; each row's text is in its circle's <title>.
  3. The 3D frame is never drawn larger than its own pixel size (the renderer's frame is the panel's size; enlarging it only blurs it), so a 3D PNG from a small panel has the picture centered in the 960-pixel figure.
  4. Circles are not tab stops (hundreds of them); the "keyboard focus follows the contact list" is the selection highlighting both. The live SVG is role="group" so each circle's <title> stays reachable.
  5. Leak check allowlist wording: the third command prints only the two XML namespace identifiers (http://www.w3.org/2000/svg, http://purl.org/dc/elements/1.1/) and addresses built from RAVE_CREDIT; nothing else.
  6. The tests were written alongside the modules; each is proved by mutation instead (below).

Gates (round 1 head 03ba9aa, epic tip 221321e, nothing newer to merge)

  • bun install --frozen-lockfile: Checked 416 installs across 568 packages (no changes)
  • bun run typecheck: Result (509 files): 0 errors, 0 warnings, 19 hints (the base's 19 hints)
  • bun run lint: Checked 439 files in 201ms. No fixes applied.
  • bun run test src/lib/ieeg-spatial/export.test.ts src/lib/ieeg-spatial/views2d.test.ts: Test Files 2 passed (2), Tests 55 passed (55)
  • bun run test: Test Files 186 passed | 3 skipped (189), Tests 5318 passed | 14 skipped (5332)
  • PUBLIC_DATA_BASE_URL=https://data.nemar.org bun run test:e2e e2e/ieeg-spatial-panel.spec.ts (headless, dev server): 14 passed (1.4m)
  • Bundle, bunx astro build and gzip -9c <chunk> | wc -c. Base (epic tip): panel chunk 58,830 raw, 21,645 gzipped; viewer chunk 166,137 raw, 58,277 gzipped. Now: panel chunk 76,690 raw, 28,362 gzipped (+6,717 gzipped); viewer chunk 166,137 raw, 58,279 gzipped (+2, a hash). The panel chunk is under the plan's 30 KB panel budget; IS-V2's addition to the same chunk is not counted here. The three generate:* Open Graph steps of bun run build were skipped (they render cards from the live catalog and touch no chunk).
  • Leak check on export.ts, views2d.ts, both tests, the e2e spec and the stylesheet: see deviation 5.

Real-browser evidence (headless Chromium, on005522)

  • Downloaded PNG (3D, frame MNI152NLin6ASym): sub-R1001P_ses-0_task-YC1_acq-bipolar_ieeg_contacts_mni152nlin6asym.png, 1920x880, signature PNG; decoded in the page, the bottom-right 440x60 region holds 173 distinct colors and 1,518 dark pixels, the bottom-left region of the same size holds 1 color and 0 dark pixels (the plain background), so the difference is the credit.
  • Downloaded SVG: parsed with DOMParser (image/svg+xml), no parser error; three g[data-view] (left, top, front); 264 circles for 88 contacts, each with a non-empty <title>; the last child of the root is g.eegv-credit, whose <a href> is the address credit.ts declares around the sentence it declares; the metadata holds the dataset id, the status line, the address and the DOI.
  • 2D switch: canvas removed, 3 x contacts circles in the stage, a click on a dot selects the contact in the list, the saved SVG and PNG carry the activity summary, the colorbar ends and the "Selected:" line. Without WebGL2: the same, with the switch disabled and titled "3D view needs WebGL2". A refusal state shows no switch or save button and keeps the credit.

Mutation checks

Each test below fails under the one-line mutation named, reverted afterwards (git status --porcelain clean after each run).

  • Card 1 (SVG has the credit link, address, text and the template's "approximate" sentence): skip creditSvg (2 fail).
  • Card 2 (credit painter last in the draw list): append a label operation after the credit (3 fail).
  • Card 3 (a native frame has no outline): draw outlines whenever the template argument is not undefined, so a null one is read (20 fail, including the native and described frame tests).
  • Card 4 (one circle with a title per located contact): remove the position filter (4 fail).
  • Beyond the card: left view not flipped (orientation vs camera.ts); top draw order reversed; wrapped lines losing their trailing space; credit painted at ratio 1; a frame label built from free text; notes, the selection line, the colorbar ends or the WebGL sentence dropped from the files; & not escaped in a title; the selected circle not larger; view_changed ignored; the switch enabled without WebGL2; the 3D frame enlarged past its size; the recording dropped from the metadata; the seam's positions ignored; the value dropped from a title (21 mutations, 21 caught).
  • e2e: skip the raster credit (the corner is uniform, Expected: > 8, Received: 1); skip the SVG credit (Expected: "eegv-credit", Received: null).

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), and a 2x pixel-ratio screen for the 3D PNG (headless runs at ratio 1).
  • The merge with IS-V2's panel.ts: the second PR to merge takes the base in; this branch's panel.ts additions are the view2d state and event, the views2d stage kind, PanelModel.view, templatePlacementFor, and the DOM half's views and actions.

Card IS-V3.

Review round 1 (head 03ba9aa)

Fixed: I1 the activity measure and band ("Band power, relative (dB): High gamma, 70 to 150 Hz", from the selectors' own words, one measureSentence) are in the model, the live 2D notes, the SVG, the PNG draw list and the 3D PNG; I2 escapeXml strips XML-forbidden control characters (unit test, a full-figure test with U+0001 and U+000B in a contact name, and an e2e that parses the markup with the browser's XML parser); S1 chose to correct the comment and the test name: the 3D frame is capped at its pixel count in figure pixels and is drawn at exactly 2x (smoothed); S2 orientation letters on every view (R/L and A/P and S/I from the view definitions, a test pins them to the 3D camera's projection; in live view, SVG and PNG); S4 downloadFile takes a schedule seam and tests use the real URL registry (resolveObjectURL) to prove the revoke, also when the click throws; S5 doiUrl() exported from credit.ts, used by creditSvg and export.ts (a scan test keeps doi.org out of export.ts).

S3: the "Selected:" line is a deliberate addition to the exports (not in the live status): it restates the selected contacts with the same sentence as their circle titles.

Owner addition (transparency): every circle title, the "Selected:" line and each contact-list row now say the contact name as recorded first, the channel(s) beside it in parentheses, and where the dataset recorded it: LAF2 (channels LAF1-LAF2, LAF2-LAF3); recorded (-48.8321, 53.1194, 1.08525940626615) mm, frame: MNI152NLin6ASym; 1.50 µV². One function, contactTitle (with recordedLocation and templateLocation), builds it for all of them, so the wording is declared once. The recorded line is numerically equal to the file's value to 15 significant digits, not the file's own characters: trailing zeros and exponent notation are normalized, because IS-C1's parser keeps numbers, not text. In the file's own unit the number prints as parsed; for a converted unit (a file in meters) IS-C1's millimeters are divided back and read to 15 significant digits, so the line says meters as the file did (the committed fixtures reproduce character for character). Carrying the raw coordinate strings through IS-C1's parser, so the line is verbatim, is assigned to the next card, IS-J1. TemplatePlacement gained approximate: boolean; a template position is added as template (x, y, z) mm, approximate only when the seam supplies one, and says "approximate" only when the seam says so. A native frame has only the recorded line.

Round 1 gates (head 03ba9aa): bun run typecheck Result (509 files): 0 errors, 0 warnings, 19 hints; bun run lint Checked 439 files in 283ms. No fixes applied.; bun run test src/lib/ieeg-spatial Test Files 9 passed (9), Tests 308 passed (308); bun run test Test Files 186 passed | 3 skipped (189), Tests 5334 passed | 14 skipped (5348); e2e 15 passed (1.1m). Chunks: panel 78,547 raw, 29,021 gzipped (base 21,645, +7,376); viewer 166,137 raw, 58,277 gzipped (same as base). Revert checks (each fails its named tests, then reverted, tree clean): drop the recorded line from the title (6 fail), round the recorded position (4), band left out of the measure (2), control characters not stripped (2), front letters not swapped (3), download address never revoked (2), DOI address built in export.ts (1), letters left out of the PNG draw list (1), template line drops "approximate" (2), list rows lose the recorded line (5), title drops the channel (6), measure label left out of the files (2).

S6 (wiring IS-V2's seam) is pending until V2 has merged; templatePlacementFor still returns null.

Round 2: IS-V2 merged in, template seam wired (head 61c3df6)

The epic tip (IS-V2, bbe44a8) is merged into the branch (merge, no rebase). Conflicts in panel.ts, eeg-viewer.css (one copy of the shared .eegv__spatial-inner > * rule, V2's comment kept) and the e2e spec resolved keeping both sides' behavior. One existing assertion changed: without WebGL2 the template box now reports the outlines' loading state (the 2D views wait on views.json, never on the mesh); panel.test.ts says so and still pins that the surface is never asked for. V2's e2e mesh watcher now counts only the two .mesh.bin files (the outlines file is watched apart).

  • templatePlacementFor(state, outlines) now returns, for a frame with a registry row (V2's templateRuleOf) and outlines in hand: the outlines parsed from views.json (parseViewOutlines), the positions through V2's placeOnTemplate, approximate from the rule, the labels templateLabel(rule) and templateNotice() (the notice's words are the live box's: TEMPLATE_NOTICE_PREFIX, TEMPLATE_REFERENCE.text, TEMPLATE_LICENSE_TEXT, with TEMPLATE_REFERENCE.href and TEMPLATE_LICENSE_HREF in the SVG's metadata). Native, described, pending, unsupported-units frames, and outlines still loading or failed, give null: no outline, no template line, no label (the "No template placement ..." note still comes from the panel's own notes).
  • PanelState.outlines (idle, loading, ready, failed) with events outlines_loaded/outlines_failed and effect load_outlines, mirroring V2's template: the fetch is wanted only with the panel open on a registered frame and contacts drawn (3D, 2D or without WebGL2, because the SVG is always the 2D views); never for EEG, ACPC or a closed panel; a module-level promise caches it, so a reopen does not refetch; a failure is retried on a reopen, frame or recording change.
  • templateModel covers the 2D stages from the outlines' status, so the live box shows the same label, notice and two links in 3D and 2D. The 3D PNG says what the model said (loading, failed or ready, in V2's words); the SVG and 2D PNG say what the seam says.
  • Contact titles, the "Selected:" line and each live list row show the recorded line, and a smaller template (x, y, z) mm, approximate line once a template is drawn (ContactRow.template, placedRule), by the same templateLocation.

Gates (head 61c3df6): typecheck Result (512 files): 0 errors, 0 warnings, 19 hints; lint Checked 442 files in 183ms. No fixes applied.; bun run test src/lib/ieeg-spatial Test Files 10 passed (10), Tests 364 passed (364); bun run test Test Files 187 passed | 3 skipped (190), Tests 5390 passed | 14 skipped (5404); e2e 26 passed (1.9m) (the run before a format-only change). Chunks: panel 89,506 raw, 32,877 gzipped (the owner's budget is 64 KB); viewer 166,137 raw, 58,278 gzipped.

Real fixtures: nm000454 (own frame, not approximate), nm000376 (IXI549Space), on005522 monopolar (Talairach, positions checked against applyAffine(TALAIRACH_TO_MNI, ...)), nm000485 and nm000355 in e2e; ACPC (on004473), Other (nm000485), a pending identifier (a real state with its frame replaced by NIHPD) and an undeclared-units frame (nm000373) for the negative cases. e2e: nm000485 downloads the SVG (three outlines, both sentences equal to the live box's, the title of every circle with both lines, the credit last) and a PNG whose corner holds the credit, and counts one views.json request across a close and reopen; nm000376 does it from the 3D view; nm000355 has no outline, template line, label or request; an EEG dataset never asks.

Revert checks (each fails its named tests, reverted, tree clean): outlines without a registered rule (5), template line for a frame with no template (10), template sentences left out of the files (6), recorded line left out (10), list rows without the template line (4), outlines wanted for every frame (1), outlines refetched on every reopen (1), notice left out of the seam (3), addresses left out of the metadata (3), contacts not moved by the transform (1), approximate never said (3), 2D stage ignoring the outlines status (4), 3D frame labels taken from the seam (1).

Round 3 (head d890bfc)

  • Orientation letters are inset 8 px inside each view's own box, and each view has a thin frame (inset 3 px) round it, in the live view, SVG (data-view-frame) and PNG (a frame draw operation). A geometric test on the layout (row and 2x2 grid) asserts every letter lies inside its own frame and keeps at least 8 px from every letter of every other view (the glyph footprint is 0.6 em by 1 em); the drawing area's padding grew to 18 px so letters stay clear of dots.
  • The once-per-page outlines cache has a seam (templateOutlines(read), forgetTemplateOutlines() for tests): two panels opened in sequence share one read, a failed read is not kept, a wrong format is refused and not kept. The reader is given the real committed views.json.
  • Honest wording of the recorded line (docblock of recordedLocation, test comments, and above).

Gates (head d890bfc): typecheck Result (512 files): 0 errors, 0 warnings, 19 hints; lint Checked 442 files in 182ms. No fixes applied.; ieeg-spatial Tests 368 passed (368); full Test Files 187 passed | 3 skipped (190), Tests 5394 passed | 14 skipped (5408); e2e 26 passed (2.0m); panel chunk 90,024 raw, 33,013 gzipped; viewer 166,137 raw, 58,277 gzipped. Leak check: only the two XML namespace identifiers. Revert checks (each fails its named test, reverted): left letters back at the cell edge (1), right letters back at the cell edge (1), frames not written in the markup (1), frames missing from the draw list (1), cache ??= changed to = (1), a failed read kept in the cache (2).

@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: d890bfc
Status: ✅  Deploy successful!
Preview URL: https://4aed6952.nemar-website.pages.dev
Branch Preview URL: https://feat-is-v3-exports.nemar-website.pages.dev

View logs

@neuromechanist
neuromechanist merged commit d162257 into feature/issue-537-epic-spatial Nov 18, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feat/is-v3-exports branch November 18, 2026 06:13
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