Skip to content

Add interactive dashboard with Build Canada charts library#15

Open
xrendan wants to merge 8 commits into
mainfrom
claude/integrate-graphing-library-jxAOK
Open

Add interactive dashboard with Build Canada charts library#15
xrendan wants to merge 8 commits into
mainfrom
claude/integrate-graphing-library-jxAOK

Conversation

@xrendan
Copy link
Copy Markdown
Member

@xrendan xrendan commented May 8, 2026

Summary

This PR adds a new interactive dashboard page that showcases the @buildcanada/charts library's Grapher component with life expectancy data visualization capabilities.

Key Changes

  • New Dashboard Page (src/app/dashboard/page.tsx): Server component that sets up metadata and imports the Build Canada charts stylesheet
  • Dashboard Component (src/app/dashboard/Dashboard.tsx): Interactive client component featuring:
    • Multiple chart type options (Line, Discrete Bar, Stacked Area, Slope)
    • Entity preset selection (G7, Americas, Asia regions)
    • Responsive sizing that adapts to viewport dimensions
    • Life expectancy data visualization using the LifeExpectancyGrapher
  • Dynamic Loading Wrapper (src/app/dashboard/DashboardClient.tsx): Client-side dynamic import with SSR disabled and loading skeleton for better UX
  • Dependencies: Added @buildcanada/charts, @buildcanada/colours, @buildcanada/components, mobx, mobx-react, and sass to support the charting library

Implementation Details

  • The dashboard uses React hooks (useState, useMemo, useEffect) to manage chart type, entity selection, and responsive sizing
  • Window resize listener ensures the chart dimensions scale appropriately between 420-660px height and up to 1100px width
  • Chart state is memoized based on chart type, preset index, and dimensions to optimize re-renders
  • UI includes segmented button group for chart type selection and dropdown for entity presets
  • Includes user guidance text and instructions for chart interactivity

https://claude.ai/code/session_01H5n1EL6QDosMXGTS8UndR9

claude and others added 8 commits May 7, 2026 22:47
Wires the @buildcanada/charts library (plus its @buildcanada/colours and
@buildcanada/components peers) into TradingPost as file: dependencies
pointing at the sibling bcds checkout. The dashboard renders an
interactive Grapher with the LifeExpectancyGrapher sample dataset and
exposes controls to switch chart type (Line / Discrete Bar /
Stacked Area / Slope) and entity preset.

Notes on the integration:

- The Grapher component uses MobX, mounts via observers that touch
  window/document, and is not RSC-safe. The page boundary loads it via
  next/dynamic with ssr: false from a client wrapper so Next does not
  try to prerender it (mobx decorators initialize on import, so even
  SSR of an otherwise-client component fails).
- @buildcanada/charts ships a single SCSS entry point as its
  './styles.css' export. Adding 'sass' as a dependency lets Next
  compile that .scss directly when imported from the dashboard route.
- mobx (^6.15) and mobx-react (^7.6) are required as peer deps by the
  charts package. mobx-react 7.6 still declares React 16/17/18 as its
  peer but works against React 19 for the @observer usage in Grapher.

Together with the matching fix in bcds (TC-39 stage 3 decorator emit +
automatic JSX runtime in the charts build), /dashboard now mounts the
Grapher cleanly and survives chart-type / entity-preset switching.
Now that bcds#7 is merged and @buildcanada/charts@0.3.9 is published
(with the TC-39 stage 3 decorator emit + automatic JSX runtime fix),
TradingPost no longer needs the local file:../bcds/packages/* links.
Switching to ^0.3.9 / ^0.3.5 / ^0.3.3 so the integration works on a
fresh checkout (CI, other developers) without a sibling bcds tree.

Verified end-to-end: pnpm install resolves the registry packages,
`next dev` boots, /dashboard mounts the Grapher (12 SVGs, 17
interactive buttons), chart-type and entity-preset switching both
work, no pageerrors.
These are peer dependencies that pnpm auto-installs on our behalf:
- sass is a peer of next 16 (Next ships built-in Sass support)
- mobx and mobx-react are peers of @buildcanada/charts

Since this repo is pnpm-only (packageManager: pnpm@9.5.0) and pnpm 8+
defaults auto-install-peers to true, declaring them ourselves is
redundant — pnpm pulls them in either way. Removing keeps package.json
focused on direct dependencies and avoids version-pin drift between
us and the charts peer-dep declaration.

Verified: pnpm install resolves mobx@6.15.3 and mobx-react@7.6.0 via
peer auto-install; /dashboard mounts the Grapher cleanly (12 SVGs, 17
interactive buttons, no pageerrors).
Replaces the life-expectancy demo at /dashboard with a real KPI browser:

- /dashboard — index of jurisdictions and their organizations
- /dashboard/[jurisdiction]/[org] — per-org dashboard showing every
  numeric measure with a Grapher chart (actual + target series across
  the available years), grouped by service category in a sidebar

Adds src/lib/api/kpis.ts with typed fetchers for jurisdictions,
organizations, measures, and facts (auto-paginating).

The KPI endpoints live under /api/v1/kpis on the york_factory API
(see ../york_factory/docs/api/kpis). Reads are unauthenticated and
revalidated server-side every 10 minutes.
Restructures the per-org dashboard so each KPI measure is a separately
shareable, SEO-friendly route:

  /dashboard/[jurisdiction]/[org]/[measure]

- New [org]/layout.tsx owns the org header and the sidebar of measures
  (Link-based, active state via usePathname).
- [org]/page.tsx becomes an overview: cards for each measure showing the
  latest actual value with a link to the measure's chart page.
- New [org]/[measure]/page.tsx fetches the measure (via getMeasure for
  description + lineages) and its facts, then renders a single Grapher
  chart with line/bar toggle.

Adds listFactsForMeasure and getMeasure fetchers to src/lib/api/kpis.ts.
Lists every source document the measure's citations come from (PDF
title, publication date, fiscal year, years covered, page numbers, and
value types contributed). Documents are unique per row and sorted by
publication date descending.

Adds listCitationsForMeasure to src/lib/api/kpis.ts.
Replaces the standalone Sources panel with in-chart citation rendering
on the @buildcanada/charts Grapher:

- variable metadata.origins[] — one entry per source document
  (title, producer, urlMain, datePublished, citationFull with page
  numbers). Grapher's Sources tab renders these natively.
- GrapherState.sourceDesc — compact "Data source:" footer line.
- GrapherState.originUrl — clickable footer link to the most recent
  source PDF.
Joining raw doc titles with "; " produced noisy footers like
"Transportation Services - Operating Budget; Operating Budget".
For measures backed by multiple source documents, the footer line
now reads "<organization> · N source documents · FY <range>" —
individual titles still live in the Sources tab.
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.

2 participants