Skip to content
Closed
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
15 changes: 14 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@ import cloudflare from "@astrojs/cloudflare";
export default defineConfig({
output: "server",
adapter: cloudflare({
imageService: "compile",
// 'passthrough' keeps sharp out of the worker entirely. We don't use
// Astro's <Image> component — all hero/logo assets are static SVG/JPG in
// /public served as-is. 'compile' still pulled sharp into the SSR bundle
// (deploy failure: `process.report.getReport is not implemented` in the
// Workers runtime).
imageService: "passthrough",
}),
// We don't use <Image> / astro:assets anywhere — all images are plain <img>
// referencing /public/*.{svg,jpg,png}. The default image service still ships
// sharp into the SSR bundle, which the Cloudflare Workers runtime can't
// execute (sharp needs native bindings + node:process internals). The noop
// service is a Workers-safe replacement.
image: {
service: { entrypoint: "astro/assets/services/noop" },
},
site: "https://nemar.org",
trailingSlash: "ignore",
experimental: {
Expand Down
121 changes: 121 additions & 0 deletions src/components/AgeGenderChart.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
import { bucketAgesBySex } from "../lib/qa";

interface Props {
ages: number[];
sexes: Array<"M" | "F" | "O" | null>;
}

const { ages, sexes } = Astro.props;
const buckets = bucketAgesBySex(ages, sexes, 10);
const maxCount = Math.max(1, ...buckets.flatMap((b) => [b.M, b.F, b.O]));

// SVG geometry: each bucket has 3 paired bars (M/F/O), 6px wide each, 1px gap.
// Bucket cell = 3*6 + 2*1 = 20. Plus a 4px right-margin per bucket = 24 step.
const BAR_W = 6;
const BAR_GAP = 1;
const BUCKET_PAD = 4;
const CELL_W = 3 * BAR_W + 2 * BAR_GAP + BUCKET_PAD;
const TOTAL_W = buckets.length * CELL_W;
const PLOT_H = 50;
---

<figure class="agender">
<figcaption>
<span class="agender__title">Age and gender</span>
<span class="agender__hint">{ages.length} participants</span>
</figcaption>
{buckets.length === 0 ? (
<div class="agender__empty">No demographics available</div>
) : (
<svg viewBox={`0 0 ${TOTAL_W} 64`} preserveAspectRatio="none" class="agender__svg" role="img" aria-label="Age and gender distribution">
{buckets.map((b, i) => {
const x0 = i * CELL_W;
const mH = (b.M / maxCount) * PLOT_H;
const fH = (b.F / maxCount) * PLOT_H;
const oH = (b.O / maxCount) * PLOT_H;
return (
<g>
<rect x={x0} y={PLOT_H - mH} width={BAR_W} height={mH} fill="var(--modality-eeg)">
<title>{`${b.label}: ${b.M} M`}</title>
</rect>
<rect x={x0 + BAR_W + BAR_GAP} y={PLOT_H - fH} width={BAR_W} height={fH} fill="var(--modality-ieeg)">
<title>{`${b.label}: ${b.F} F`}</title>
</rect>
<rect x={x0 + 2 * (BAR_W + BAR_GAP)} y={PLOT_H - oH} width={BAR_W} height={oH} fill="var(--modality-emg)" opacity="0.8">
<title>{`${b.label}: ${b.O} O`}</title>
</rect>
<text x={x0 + (3 * BAR_W + 2 * BAR_GAP) / 2} y="60" text-anchor="middle" font-size="6" fill="var(--color-fg-subtle)" font-family="var(--font-mono)">
{b.label}
</text>
</g>
);
})}
<line x1="0" y1={PLOT_H} x2={TOTAL_W} y2={PLOT_H} stroke="var(--color-border)" stroke-width="0.5" />
</svg>
)}
<ul class="agender__legend" role="list">
<li><span class="agender__swatch" style="background: var(--modality-eeg)"></span> Male</li>
<li><span class="agender__swatch" style="background: var(--modality-ieeg)"></span> Female</li>
<li><span class="agender__swatch" style="background: var(--modality-emg); opacity:0.8"></span> Other / unknown</li>
</ul>
</figure>

<style>
.agender {
margin: 0;
display: flex;
flex-direction: column;
gap: var(--space-1);
}
.agender figcaption {
display: flex;
justify-content: space-between;
align-items: baseline;
}
.agender__title {
font-family: var(--font-display);
font-weight: var(--fw-semibold);
color: var(--color-fg);
font-size: var(--fs-sm);
}
.agender__hint {
color: var(--color-fg-subtle);
font-family: var(--font-mono);
font-size: var(--fs-xs);
}
.agender__svg {
inline-size: 100%;
aspect-ratio: 5 / 2;
background: var(--color-bg-subtle);
border-radius: var(--radius-sm);
}
.agender__legend {
display: flex;
flex-wrap: wrap;
gap: var(--space-3);
list-style: none;
padding: 0;
margin: 0;
font-size: var(--fs-xs);
color: var(--color-fg-muted);
}
.agender__legend li {
display: inline-flex;
align-items: center;
gap: 4px;
}
.agender__swatch {
inline-size: 10px;
block-size: 10px;
border-radius: 2px;
}
.agender__empty {
padding: var(--space-4);
background: var(--color-bg-subtle);
border-radius: var(--radius-sm);
color: var(--color-fg-subtle);
font-size: var(--fs-sm);
text-align: center;
}
</style>
61 changes: 57 additions & 4 deletions src/components/BidsDirChildren.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ interface Props {
node: TreeNode;
basePath: string;
depth: number;
datasetId: string;
version: string;
}

const { node, basePath, depth } = Astro.props;
const { node, basePath, depth, datasetId, version } = Astro.props;
// Strip the trailing /id/version off basePath to get the data.nemar.org root
// for the QA endpoints (which sit alongside the version routes, not inside).
const dataBase = basePath.replace(/\/[^/]+\/[^/]+$/, "");
const indentVar = `--depth: ${depth}`;
// Auto-open is conservative: only the first level when the subject count is
// small. Large BIDS datasets (e.g. nm000104 with 1000+ subjects) stay
Expand Down Expand Up @@ -38,7 +43,7 @@ function countFilesDeep(n: TreeNode): number {
</span>
<span class="tree__size">{formatBytes(child.totalSize)}</span>
</summary>
<Astro.self node={child} basePath={basePath} depth={depth + 1} />
<Astro.self node={child} basePath={basePath} depth={depth + 1} datasetId={datasetId} version={version} />
</details>
</li>
))}
Expand All @@ -53,8 +58,34 @@ function countFilesDeep(n: TreeNode): number {
{f.path.split("/").pop()}
</a>
<span class="tree__size">{formatBytes(f.size)}</span>
{cls.isEEG && <span class="tree__tag tree__tag--soon" title="Visualizer ships in Phase 5">Vis · soon</span>}
{cls.isTSV && <span class="tree__tag tree__tag--soon" title="TSV viewer ships in Phase 5">View · soon</span>}
{cls.isEEG && (
<button
type="button"
class="tree__action tree__action--vis"
data-open-vis
data-dataset-id={datasetId}
data-bids-path={f.path}
data-version={version}
data-base={dataBase}
title="Open QA plots for this file"
>
Vis
</button>
)}
{cls.isTSV && (
<button
type="button"
class="tree__action tree__action--view"
data-open-view
data-dataset-id={datasetId}
data-bids-path={f.path}
data-version={version}
data-base={dataBase}
title="Preview this TSV file"
>
View
</button>
)}
{cls.isJSON && <span class="tree__tag">JSON</span>}
</li>
);
Expand Down Expand Up @@ -148,4 +179,26 @@ function countFilesDeep(n: TreeNode): number {
background: var(--color-bg-subtle);
cursor: help;
}
.tree__action {
font-size: var(--fs-xs);
padding: 4px 10px;
border-radius: var(--radius-pill);
background: var(--color-bg);
border: 1px solid var(--color-border-strong);
color: var(--color-fg-muted);
font-family: var(--font-mono);
cursor: pointer;
flex-shrink: 0;
transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tree__action:hover {
background: var(--color-fg);
color: var(--color-bg);
border-color: var(--color-fg);
}
.tree__action--vis:hover {
background: var(--brand-teal);
border-color: var(--brand-teal);
color: var(--brand-navy);
}
</style>
11 changes: 9 additions & 2 deletions src/components/BidsTree.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import type { TreeNode } from "../lib/bids-tree";
import { classifyFile } from "../lib/bids-tree";
import { formatBytes } from "../lib/format";
import BidsDirChildren from "./BidsDirChildren.astro";
import FileVisModal from "./FileVisModal.astro";
import FileViewModal from "./FileViewModal.astro";

interface Props {
root: TreeNode;
basePath: string;
datasetId: string;
version: string;
}

const { root, basePath } = Astro.props;
const { root, basePath, datasetId, version } = Astro.props;
const topLevel = root.children;
const rootFiles = root.files;

Expand Down Expand Up @@ -62,13 +66,16 @@ function countFilesDeep(n: TreeNode): number {
</span>
<span class="tree__size">{formatBytes(node.totalSize)}</span>
</summary>
<BidsDirChildren node={node} basePath={basePath} depth={1} />
<BidsDirChildren node={node} basePath={basePath} depth={1} datasetId={datasetId} version={version} />
</details>
</li>
))}
</ul>
</section>

<FileVisModal />
<FileViewModal />

<style>
.tree {
border: 1px solid var(--color-border);
Expand Down
Loading