Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/components/BidsTree.astro
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,81 @@ const dataHost = new URL(dataBase).host;
overflow: auto;
}
.tree__preview[hidden] { display: none; }
/* The signal viewer is the one preview that needs vertical room. Its scope
height is derived from its width, so at any usable width the plot is
taller than the 480px cap above and would sit behind a scrollbar inside
an already-scrolling page. Let the panel grow to the viewer instead; the
Enlarge control below is the escape hatch when it still isn't enough. */
.tree__preview--signal {
max-block-size: none;
overflow: visible;
padding: 0;
}
/* Inline signal-viewer chrome (website#217): file name on the left, the
promote-to-dialog control on the right, viewer host underneath. */
.eegv-inline__bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--space-3);
padding: var(--space-2) var(--space-5);
border-block-end: 1px solid var(--color-border);
}
.eegv-inline__name {
font-family: var(--font-mono);
font-size: var(--fs-xs);
color: var(--color-fg-muted);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.eegv-inline__btn {
display: inline-flex;
align-items: center;
gap: var(--space-1);
flex: none;
padding: var(--space-1) var(--space-3);
border: 1px solid var(--color-border);
border-radius: var(--radius-sm);
background: var(--color-bg);
color: var(--color-fg-muted);
font: inherit;
font-size: var(--fs-xs);
cursor: pointer;
}
.eegv-inline__btn:hover {
color: var(--color-fg);
border-color: var(--color-link);
}
.eegv-inline__btn:focus-visible {
outline: 2px solid var(--color-focus);
outline-offset: 2px;
}
.eegv-inline__btn svg {
inline-size: 12px;
block-size: 12px;
}
/* Stand-in left in the inline panel while the viewer is in the dialog, so
the panel doesn't read as an empty box and the return has an exact
position to restore the host into. */
.eegv-inline__moved {
margin: 0;
padding: var(--space-5);
color: var(--color-fg-muted);
font-size: var(--fs-sm);
}
/* The signal panel has no padding of its own (the viewer is full-bleed
inside it), so the transient messages the page writes need their own.
Descendant, not child, selectors: the "unavailable" and error messages
are written straight into the panel, but the loading one goes inside
`[data-eegv-host]` — it is the placeholder the mount replaces. The
mounted viewer's own markup is `.eegv` / `.eegv__*` throughout, so
nothing here collides. */
.tree__preview--signal .preview__empty,
.tree__preview--signal .preview__error,
.tree__preview--signal .preview__loading {
padding: var(--space-4) var(--space-5);
}
/* Markdown preview prose. Distinct from .readme__ so the dataset-header
README component's styles don't bleed in. */
.preview__md {
Expand Down
74 changes: 42 additions & 32 deletions src/components/EegViewerDialog.astro
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
---
/**
* Full-screen modal host for the EEG/MEG/iEEG/EMG signal viewer
* (website#199). Previously `mountEegViewer` mounted inline into a slot
* inside the BIDS file tree row — cramped for a multi-channel scope with a
* short time axis. This is a single, page-level dialog (one per dataset
* page, sized ~70% of the viewport) that every "eeg" preview button opens;
* the mount/teardown orchestration lives in dataset/[id].astro's script,
* next to the click handler that already owns the rest of the file-preview
* state machine.
* Enlarged host for the EEG/MEG/iEEG/EMG signal viewer.
*
* The viewer opens *inline*, in the clicked BIDS tree row's own preview
* panel; this dialog is where it goes when the user asks for more room via
* the panel's "Enlarge" control (website#217). Between #199 and #217 this
* was the entry point — every signal file opened straight into it — which
* turned a glance at a recording into a page takeover.
*
* It receives the *already-mounted* viewer host, moved here from the inline
* panel and moved back on close; it never hosts a mount of its own. See
* `enlargeEegViewer` in dataset/[id].astro, where the rest of the
* file-preview state machine already lives.
*
* Deliberately outside `BidsTree.astro`'s `<section data-tree-defer>` — that
* section's innerHTML is fully replaced during hydration and again on every
* "show more" / subdirectory expand, which would destroy a dialog nested
* inside it.
* section's innerHTML is replaced wholesale during hydration, which would
* destroy a dialog nested inside it.
*
* No bottom "Close" button here (unlike ActionBar's dialogs): the viewer's
* own toolbar already fills the available height, so a text button below it
* would sit below the fold — exactly the discoverability problem the corner
* X exists to fix. The corner X + Esc are the only exits, which is enough
* for a full-viewport visualization surface.
* No bottom "Close" button here (unlike ActionBar's dialogs): the viewer
* fills the available height, so a text button below it would sit below the
* fold — exactly the discoverability problem the corner X exists to fix. The
* corner X and Esc are the only exits, and both return the viewer inline.
*/
import DialogCloseButton from "./DialogCloseButton.astro";
---
Expand All @@ -27,30 +29,38 @@ import DialogCloseButton from "./DialogCloseButton.astro";
<DialogCloseButton />
<div class="eegv-dialog__scroll">
<h2 class="eegv-dialog__title" data-eegv-title>Signal viewer</h2>
<div class="eegv-dialog__body" data-eegv-slot aria-live="polite"></div>
{/* No `aria-live` (dropped in website#217): what lands here is a live
viewer, whose cursor readout and legend update continuously and would
otherwise be announced on every pointer move. The "unavailable" and
mount-failure messages never reach this slot at all — neither path
renders an Enlarge control — though a mount still in flight when the
user enlarges does briefly carry its "Loading viewer…" placeholder in
with it. */}
<div class="eegv-dialog__body" data-eegv-slot></div>
</div>
</dialog>

<style>
.eegv-dialog {
inset: 0;
margin: auto;
/* "Roughly 70% of the viewport" (website#199), clamped so it never
overflows a small screen and never balloons past a useful size on a
huge one. Height is a cap, not a fixed size — a short "unavailable"
message shouldn't leave a mostly-empty modal. */
inline-size: min(70vw, 1400px);
/* Wider and taller than the ~70% of #199, because this is no longer the
default surface: the user got here by explicitly asking for more room
than the inline panel gives, so the jump should be worth the click.
Still clamped, so it never overflows a small screen and never balloons
past a useful size on a huge one. */
inline-size: min(92vw, 1800px);
max-inline-size: calc(100vw - 2rem);
min-inline-size: min(320px, calc(100vw - 2rem));
/* `block-size: fit-content` is load-bearing, not decorative: a native
<dialog> centered via `inset: 0` + `margin: auto` with `height: auto`
(the default) stretches to fill all the way to max-block-size instead
of shrinking to its content — confirmed by testing the "unavailable"
fallback, which is short and otherwise left a big empty box under a
two-line message. `fit-content` makes the box size to its content,
still capped by max-block-size once the viewer is tall enough to hit it. */
(the default) stretches all the way to max-block-size instead of
shrinking to its content. The viewer derives its height from its width,
so without this a wide-but-short scope would sit at the top of a mostly
empty box. `fit-content` sizes to the viewer, still capped by
max-block-size once it is tall enough to hit it. */
block-size: fit-content;
max-block-size: min(70vh, 900px);
max-block-size: min(90vh, 1100px);
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
background: var(--color-bg-elevated);
Expand Down Expand Up @@ -84,10 +94,10 @@ import DialogCloseButton from "./DialogCloseButton.astro";
margin: 0 0 var(--space-4);
padding-inline-end: var(--dialog-x-clearance);
}
/* A small floor, not a target: enough that a one-line message doesn't
read as a rendering glitch, small enough that the "unavailable"
fallback (a couple of lines of text) doesn't leave a large dead area
now that .eegv-dialog sizes to fit-content (see the comment above). */
/* A floor, not a target: if the host arrives before its first paint (or a
move races a repaint) the box shouldn't collapse to nothing and read as
a rendering glitch. Small enough not to leave dead space now that
.eegv-dialog sizes to fit-content (see the comment above). */
.eegv-dialog__body {
min-block-size: 48px;
}
Expand Down
18 changes: 12 additions & 6 deletions src/lib/eeg-viewer/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { zarrStoreUrl } from "../zarr-base";
* and drives the render loop: pick the pyramid level for the window, dequantize
* only the visible channel rows, optional DC removal, overlay events, draw.
*
* The slot is a full-screen modal's body (EegViewerDialog.astro, website#199)
* rather than an inline row in the BIDS tree — the caller owns showing/hiding
* the dialog; this module only measures and fills whatever slot it's given.
* The slot is normally a per-row host inside the BIDS file tree, and the
* caller may reparent it into the page-level dialog when the user asks to
* enlarge (website#217). Neither is this module's concern: it measures and
* fills whatever slot it is given, and keeps working across a move because it
* holds the element itself rather than re-querying for it. Between #199 and
* #217 the slot was the dialog's body and nothing else.
*
* Design intent:
* - The scope has a FIXED height. Channels share it, so "show all" squeezes the
Expand Down Expand Up @@ -136,9 +139,12 @@ function windowChannelMagnitudes(channels: ChannelWindow[]): Float32Array[] {
* previously mounted there first (so re-opening on a new file, or on a
* failed re-open, never leaves the prior instance's ResizeObserver /
* MutationObserver / WebGL context running under replaced DOM). Returns a
* disposer the caller should invoke when the host UI (e.g. a modal) closes,
* so the instance doesn't keep rendering — and its listeners/GL context
* don't keep living — once nothing is visible. Returns `undefined` when
* disposer the caller should invoke once the instance is genuinely finished
* with — its preview collapsed, or another recording opened — so it stops
* rendering and releases its listeners and GL context. Note that merely
* moving the slot (inline panel to dialog and back, website#217) is not
* that: the instance survives a move and must not be disposed on one.
* Returns `undefined` when
* nothing was actually mounted (the store failed to open, has no channel
* groups, or the canvas context is unavailable) — those paths already
* degrade to a static "unavailable" message with no listeners to tear down.
Expand Down
30 changes: 21 additions & 9 deletions src/lib/render-dir-listing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,34 @@ describe("renderTopLevel", () => {
expect(html).toContain(`data-preview-type="json"`);
expect(html).toContain(`data-preview-type="eeg"`);
expect(html).toContain(`data-preview-type="md"`);
// md/json/tsv each get exactly one inline preview slot; eeg opens the
// shared signal-viewer modal instead (website#199) and gets no per-row
// slot of its own.
// Every previewable type gets exactly one inline slot, eeg included
// (website#217 — between #199 and #217 eeg opened straight into a modal
// and had no per-row slot).
const slots = html.match(/data-preview-slot/g) ?? [];
expect(slots.length).toBe(3);
expect(slots.length).toBe(4);
});

it("marks the eeg preview button aria-haspopup=dialog, not aria-expanded", () => {
it("gives the eeg row an inline preview slot marked for signal sizing", () => {
const html = renderTopLevel(
listing({ children: [{ kind: "file", name: "sub-01_task-rest_eeg.set", size: 100000 }] }),
);
expect(html).toContain(`data-preview-type="eeg"`);
expect(html).toContain(`aria-haspopup="dialog"`);
// The eeg button doesn't toggle adjacent content, so it must not claim
// aria-expanded the way the md/json/tsv inline-preview buttons do.
expect(html).not.toMatch(/data-preview-type="eeg"[^>]*aria-expanded/);
expect(html).toContain(`class="tree__preview tree__preview--signal"`);
// The signal panel hosts a live viewer whose readouts update continuously;
// announcing each one is why it opts out of the aria-live the text
// previews use.
expect(html).not.toMatch(/tree__preview--signal[^>]*aria-live/);
});

it("marks the eeg preview button aria-expanded, not aria-haspopup=dialog", () => {
const html = renderTopLevel(
listing({ children: [{ kind: "file", name: "sub-01_task-rest_eeg.set", size: 100000 }] }),
);
// The button toggles its adjacent panel like every other preview type;
// the dialog is a second step behind the panel's Enlarge control, so
// claiming aria-haspopup="dialog" here would misdescribe the button.
expect(html).toMatch(/data-preview-type="eeg"[^>]*aria-expanded="false"/);
expect(html).not.toContain(`aria-haspopup="dialog"`);
});

it("omits the preview button + slot for unknown formats (CHANGES, .gitattributes)", () => {
Expand Down
44 changes: 28 additions & 16 deletions src/lib/render-dir-listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,23 @@ function renderFileRow(
if (isRoot) {
row.push(`<span class="tree__icon" aria-hidden="true">▪</span>`);
}
if (previewType === "eeg") {
// Clicking the name opens the full-screen signal-viewer modal
// (website#199) rather than expanding an inline region, so this is
// `aria-haspopup="dialog"` — not `aria-expanded`, which would claim the
// button toggles adjacent content the way the md/json/tsv buttons do.
row.push(
`<button class="tree__preview-btn" type="button" data-preview-path="${esc(fullPath)}" data-preview-type="${previewType}" data-file-size="${entry.size}" data-file-name="${esc(entry.name)}" aria-haspopup="dialog" title="Open signal viewer for ${esc(entry.name)}"><span class="tree__name">${displayName}</span></button>`,
);
} else if (previewType) {
if (previewType) {
// Clicking the name opens the inline preview; the document-level
// click delegate fetches lazily on the first open. data-file-size
// gates the 512 KB cap before the fetch runs.
//
// Signal files take this same branch, and specifically the same
// `aria-expanded` semantics (website#217). Between #199 and #217 they
// were `aria-haspopup="dialog"`, because the button opened the viewer
// straight into a modal; now it expands the adjacent panel like every
// other preview type, and the modal sits behind a separate "Enlarge"
// control inside that panel. Only the tooltip still distinguishes them.
const title =
previewType === "eeg"
? `Open signal viewer for ${esc(entry.name)}`
: `Preview ${esc(entry.name)}`;
row.push(
`<button class="tree__preview-btn" type="button" data-preview-path="${esc(fullPath)}" data-preview-type="${previewType}" data-file-size="${entry.size}" data-file-name="${esc(entry.name)}" aria-expanded="false" title="Preview ${esc(entry.name)}"><span class="tree__name">${displayName}</span></button>`,
`<button class="tree__preview-btn" type="button" data-preview-path="${esc(fullPath)}" data-preview-type="${previewType}" data-file-size="${entry.size}" data-file-name="${esc(entry.name)}" aria-expanded="false" title="${title}"><span class="tree__name">${displayName}</span></button>`,
);
} else {
// No preview affordance for unknown formats — the name is a plain
Expand All @@ -123,15 +126,24 @@ function renderFileRow(

// Wrap the row in an <li> that also carries the lazy preview slot for
// the on-click expansion. The slot stays hidden until the user opens
// the preview; once filled, data-loaded prevents re-fetches. EEG rows
// skip the slot entirely — they mount into the shared modal's slot
// (EegViewerDialog.astro), not a per-row one.
// the preview; once filled, data-loaded prevents re-fetches.
//
// Signal rows get a slot too (website#217) — the viewer mounts into it and
// is only moved into the dialog when the user asks for it. Two differences
// from a text preview, both marked by `tree__preview--signal`: the panel
// drops the fixed height cap (the scope's height tracks its width, so a
// 480px scroller would bury the plot), and it carries no `aria-live`. A
// live region around a mounted viewer would announce every cursor-readout
// and legend update; the transient messages that genuinely need announcing
// carry their own `role="status"` / `role="alert"` instead.
return [
`<li class="tree__file-wrap" data-preview-wrap>`,
row.join(""),
previewType && previewType !== "eeg"
? `<div class="tree__preview" data-preview-slot hidden aria-live="polite"></div>`
: "",
previewType === "eeg"
? `<div class="tree__preview tree__preview--signal" data-preview-slot hidden></div>`
: previewType
? `<div class="tree__preview" data-preview-slot hidden aria-live="polite"></div>`
: "",
"</li>",
].join("");
}
Expand Down
Loading
Loading