Skip to content

Charts: Download CSV on every chart card - #86

Merged
Luen merged 1 commit into
mainfrom
chart-csv-download
Nov 2, 2026
Merged

Luen merged 1 commit into
mainfrom
chart-csv-download

Conversation

@Luen

@Luen Luen commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Closes #31.

What

  • src/lib/components/charts/csv.ts provides collectCsv() (called by ChartCard) and registerCsv() (called by each chart component). Both work through Svelte context, so all ~134 chart cards get the button without touching any call site.

  • Every chart type exports a sensible table:

    Chart CSV
    Bar category × series, plus ci_low/ci_high when the chart has error bars
    Line long format: series, x (ISO date for date axes, plus x_label when the chart formats x), y
    Scatter x, y, group, label
    Histogram bin_start, bin_end, one count column per series
    Box plot n, low, q1, median, q3, high, mean
    Heatmap wide table, one row per row label
    Polar one row per sector
    Timeline ISO start/end with the detail text
  • If a card passes an explicit table, that table becomes the CSV instead.

  • The button appears after hydration (it needs JS) and builds the file client-side from data already on the page. There's no server endpoint, so no extra queries and no new CSP rules. File names look like physioshark-<chart-title>.csv.

Checks

  • pnpm lint, pnpm check pass. pnpm test passes (41 tests, including the new csv.test.ts for quoting, blanks, rounding and multiple tables).
  • pnpm build and pnpm test:e2e pass (29, axe light/dark).
  • Clicked through the cards on /tides in the browser and checked the CSV contents.

🤖 Generated with Claude Code

Each chart component registers a table builder with its ChartCard through
Svelte context (charts/csv.ts); the card shows a Download CSV button after
hydration and builds the file on click. Explicit ChartCard tables take
precedence.

Closes #31

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Luen
Luen merged commit 1bf470a into main Nov 2, 2026
5 checks passed
@Luen
Luen deleted the chart-csv-download branch November 2, 2026 23:17
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.

Charts: download data as CSV for every chart

1 participant