Skip to content

Add demographics Sankey diagram with cross-filtering#9

Open
amc-corey-cox wants to merge 1 commit into
mainfrom
demographics-sankey
Open

Add demographics Sankey diagram with cross-filtering#9
amc-corey-cox wants to merge 1 commit into
mainfrom
demographics-sankey

Conversation

@amc-corey-cox
Copy link
Copy Markdown
Member

Summary

  • Add Sankey diagram (via @nivo/sankey) showing Sex → Race → Ethnicity → Smoking Status
  • Demographic data generated per-participant with condition-correlated distributions (e.g., cardiovascular skews male with higher smoking rates)
  • Node labels show counts that update with filtering
  • Clicking Sankey nodes adds demographic filters
  • Demographic filters integrated into FilterPanel with green chips
  • Demo data distributions made more distinct across condition categories for visible filtering impact

Test plan

  • Verify Sankey renders below the donut charts with labeled columns
  • Filter by a condition category — Sankey node counts should shift visibly
  • Click a Sankey node bar — demographic filter chip should appear
  • Clear filters and verify counts return to baseline
  • Check responsive layout on narrow screens

Copilot AI review requested due to automatic review settings March 11, 2026 14:27
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 11, 2026

Deploy Preview for study-palette ready!

Name Link
🔨 Latest commit 5128fba
🔍 Latest deploy log https://app.netlify.com/projects/study-palette/deploys/69b17bb90100980008aaa0a5
😎 Deploy Preview https://deploy-preview-9--study-palette.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a demographics Sankey visualization to the demo UI and wires it into the existing cross-filtering model (condition/procedure filters) by introducing new participant demographic fields and filter chips.

Changes:

  • Extend demo participant generation and filtering to include sex, race, ethnicity, and smoking status; add Sankey data builder utilities.
  • Add a new DemographicsSankey component (Nivo Sankey) and render it in demo mode; enable click-to-filter behavior.
  • Update FilterPanel and styling to display demographic filter chips; add test polyfill for ResizeObserver.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
ui/src/test-setup.ts Adds ResizeObserver stub for Vitest/jsdom.
ui/src/index.css Adds demographic chip styling and Sankey-specific layout styles.
ui/src/demoData.ts Adds demographic fields, weighted generation, demographic filtering, and Sankey data builder.
ui/src/FilterPanel.tsx Renders removable demographic filter chips and includes demographics in “has filters” logic.
ui/src/DemographicsSankey.tsx New Nivo Sankey component with node labels and click-to-add-filter behavior.
ui/src/App.tsx Computes Sankey data from filtered participants and renders the Sankey in demo mode.
ui/package.json Adds @nivo/sankey dependency.
ui/bun.lockb Adds a Bun binary lockfile artifact as part of dependency update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ui/package.json
Comment on lines 14 to 18
"dependencies": {
"@nivo/sankey": "^0.99.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"recharts": "^3.7.0"
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency was added, but the repository’s existing Bun text lockfile (ui/bun.lock) was not updated (the new dependency only appears in bun.lockb). Please ensure the lockfile format the repo standardizes on is updated so installs are reproducible in CI and for other developers.

Copilot uses AI. Check for mistakes.
Comment thread ui/src/App.tsx
Comment on lines +114 to +117
<DemographicsSankey
data={sankeyData}
onFilterAdd={handleFilterAdd}
/>
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New Sankey UI/behavior is introduced here (rendering + click-to-filter), but App.test.tsx doesn’t currently assert that the Demographics section renders in demo mode or that clicking a Sankey node updates the FilterPanel chips. Adding a couple of tests around rendering and filter interaction would help prevent regressions.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +15
const FILTER_KEY_MAP: Record<string, keyof ActiveFilters> = {
sex: "sex",
race: "race",
ethnicity: "ethnicity",
smokingStatus: "smokingStatus",
};
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FILTER_KEY_MAP is typed as Record<string, keyof ActiveFilters>, which implies every string key is valid. That defeats the runtime check and can hide mistakes when parsing dimKey. Use a narrower type (e.g., const FILTER_KEY_MAP = {...} as const and derive keyof typeof FILTER_KEY_MAP, or Partial<Record<string, keyof ActiveFilters>>) so unknown keys are correctly typed as undefined and handled explicitly.

Copilot uses AI. Check for mistakes.
Comment thread ui/src/demoData.ts
Comment on lines +266 to +268
const nodes: SankeyNode[] = [];
const nodeIds = new Set<string>();

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodeIds is populated but never used. This adds dead code and suggests a missing validation step. Either remove nodeIds entirely, or use it to validate that source/target IDs built for links exist in nodes (and drop/guard invalid ones).

Copilot uses AI. Check for mistakes.
Comment thread ui/src/index.css
Comment on lines +168 to +171
.sankey-container {
overflow: hidden;
}

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.sankey-container is defined here but not used by any component (no matching className). Either wrap the Sankey in an element using this class (if overflow: hidden is needed), or remove the unused rule to avoid stale CSS.

Suggested change
.sankey-container {
overflow: hidden;
}

Copilot uses AI. Check for mistakes.
Comment thread ui/src/index.css
display: flex;
justify-content: space-between;
padding: 0 10px 0 10px;
margin-right: 140px;
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.sankey-labels uses a hard-coded margin-right: 140px, but the Sankey chart uses margin.right = 160 in DemographicsSankey.tsx, so the column labels are likely to drift out of alignment. Consider deriving both from the same value (or using a CSS layout that doesn’t depend on magic numbers) so responsive behavior is consistent.

Suggested change
margin-right: 140px;
margin-right: 160px;

Copilot uses AI. Check for mistakes.
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