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
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>
116 changes: 116 additions & 0 deletions src/components/HedWordcloud.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
import type { HedSummary } from "../lib/qa";

interface Props {
summary: HedSummary;
maxTags?: number;
}

const { summary, maxTags = 24 } = Astro.props;
// Sort by count desc, cap at maxTags.
const tags = [...summary.tags]
.sort((a, b) => b.count - a.count)
.slice(0, maxTags);

// Font sizing: log-scaled between minFs and maxFs.
const minFs = 0.7;
const maxFs = 1.9;
const minCount = Math.min(...tags.map((t) => t.count));
const maxCount = Math.max(...tags.map((t) => t.count));
const logSpan = Math.log(maxCount + 1) - Math.log(minCount + 1);

function sizeFor(count: number): number {
if (logSpan === 0) return (minFs + maxFs) / 2;
const t = (Math.log(count + 1) - Math.log(minCount + 1)) / logSpan;
return minFs + t * (maxFs - minFs);
}

// Deterministic shuffle so the layout doesn't shift on every render but
// also doesn't sort biggest-to-smallest in one corner (which looks like a list).
// Simple hash → swap pairs.
function rotate<T>(arr: T[], step: number): T[] {
const out = [...arr];
for (let i = 0; i < out.length; i++) {
const j = (i + step) % out.length;
[out[i], out[j]] = [out[j], out[i]];
}
return out;
}
const arranged = rotate(tags, Math.max(1, Math.floor(tags.length / 3)));
---

<section class="hed">
<header class="hed__head">
<h3 class="hed__title">HED event tags</h3>
<span class="hed__hint">
{summary.totalEvents.toLocaleString()} events in {summary.eventFiles} files
</span>
</header>
<div class="hed__cloud" role="list">
{arranged.map((t) => (
<span
role="listitem"
class:list={["hed__tag", `hed__tag--${(t.category ?? "default").toLowerCase().replace(/[^a-z0-9]+/g, "-")}`]}
style={`font-size: ${sizeFor(t.count).toFixed(2)}rem`}
title={`${t.tag}: ${t.count} occurrences${t.category ? ` (${t.category})` : ""}`}
>
{t.tag}
</span>
))}
</div>
</section>

<style>
.hed {
display: flex;
flex-direction: column;
gap: var(--space-3);
}
.hed__head {
display: flex;
justify-content: space-between;
align-items: baseline;
}
.hed__title {
font-family: var(--font-display);
font-size: var(--fs-sm);
color: var(--color-fg);
margin: 0;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.hed__hint {
color: var(--color-fg-subtle);
font-family: var(--font-mono);
font-size: var(--fs-xs);
}
.hed__cloud {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
align-items: baseline;
align-content: center;
padding: var(--space-4) var(--space-5);
background: var(--color-bg-subtle);
border-radius: var(--radius-md);
min-block-size: 9rem;
}
.hed__tag {
display: inline-block;
color: var(--color-fg-muted);
line-height: 1;
font-weight: var(--fw-medium);
transition: color 0.15s ease;
}
.hed__tag:hover {
color: var(--color-fg);
}
/* Category-based hue cycling — semantic, not rainbow. */
.hed__tag--sensory-event { color: var(--modality-eeg); }
.hed__tag--agent-action { color: var(--modality-emg); }
.hed__tag--item { color: var(--color-fg); }
.hed__tag--property { color: var(--modality-meg); }
.hed__tag--spatial { color: var(--modality-ieeg); }
.hed__tag--experimental-structure { color: var(--color-fg-muted); }
.hed__tag--event { color: var(--brand-teal); }
</style>
116 changes: 116 additions & 0 deletions src/components/HistogramChart.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
import { buildHistogram } from "../lib/qa";

interface Props {
title: string;
values: number[];
/** Optional domain override e.g. [0,100] for percentages. */
domain?: [number, number];
/** Units to render after the median value (e.g., "%", "dB"). */
unit?: string;
/** Bin count, default 10. */
binCount?: number;
/** Color, defaults to brand teal. */
fill?: string;
}

const { title, values, domain, unit = "", binCount = 10, fill = "var(--brand-teal)" } = Astro.props;
const finite = values.filter((v) => Number.isFinite(v));
const bins = buildHistogram(values, binCount, domain);
const maxCount = Math.max(1, ...bins.map((b) => b.count));
const sorted = [...finite].sort((a, b) => a - b);
const median = sorted.length === 0 ? 0 : sorted[Math.floor(sorted.length / 2)];

// SVG geometry: viewBox 0 0 120 60. Bars 10 wide with 2 gap = 12 step.
const PLOT_H = 50;
const BAR_W = 10;
const GAP = 2;
const TOTAL_W = bins.length * (BAR_W + GAP);
---

<figure class="hist">
<figcaption>
<span class="hist__title">{title}</span>
<span class="hist__hint">
<span class="hist__median">median {Math.round(median * 10) / 10}{unit}</span>
<span class="hist__n">n={finite.length}</span>
</span>
</figcaption>
{finite.length === 0 ? (
<div class="hist__empty">No data</div>
) : (
<svg viewBox={`0 0 ${TOTAL_W} 60`} preserveAspectRatio="none" class="hist__svg" role="img" aria-label={title}>
{bins.map((b, i) => {
const h = (b.count / maxCount) * PLOT_H;
const y = PLOT_H - h;
const x = i * (BAR_W + GAP);
return (
<g>
<rect x={x} y={y} width={BAR_W} height={h} fill={fill} opacity={0.85}>
<title>{`${b.label}${unit}: ${b.count}`}</title>
</rect>
</g>
);
})}
{/* Baseline */}
<line x1="0" y1={PLOT_H} x2={TOTAL_W} y2={PLOT_H} stroke="var(--color-border)" stroke-width="0.5" />
</svg>
)}
<div class="hist__axis">
<span>{Math.round(bins[0]?.lo ?? 0)}{unit}</span>
<span>{Math.round(bins[bins.length - 1]?.hi ?? 0)}{unit}</span>
</div>
</figure>

<style>
.hist {
margin: 0;
display: flex;
flex-direction: column;
gap: var(--space-1);
}
.hist figcaption {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: var(--space-2);
flex-wrap: wrap;
}
.hist__title {
font-family: var(--font-display);
font-weight: var(--fw-semibold);
color: var(--color-fg);
font-size: var(--fs-sm);
}
.hist__hint {
display: inline-flex;
gap: var(--space-2);
font-family: var(--font-mono);
font-size: var(--fs-xs);
color: var(--color-fg-subtle);
}
.hist__median {
color: var(--color-fg-muted);
}
.hist__svg {
inline-size: 100%;
aspect-ratio: 2 / 1;
background: var(--color-bg-subtle);
border-radius: var(--radius-sm);
}
.hist__axis {
display: flex;
justify-content: space-between;
font-family: var(--font-mono);
font-size: 10px;
color: var(--color-fg-subtle);
}
.hist__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>
Loading