Skip to content

Migrate charts from Plotly to Recharts + vanilla-extract foundation#663

Merged
MaxGhenis merged 11 commits intomainfrom
recharts-vanilla-extract-migration
Feb 14, 2026
Merged

Migrate charts from Plotly to Recharts + vanilla-extract foundation#663
MaxGhenis merged 11 commits intomainfrom
recharts-vanilla-extract-migration

Conversation

@MaxGhenis
Copy link
Copy Markdown
Contributor

Summary

  • Migrate 16 chart components from react-plotly.js to recharts (React-native SVG charts)
  • Add @vanilla-extract/css + Vite plugin with theme contract and global Recharts styles
  • Fix pre-existing issues: TypeScript errors (design-system dist, Vercel types), timezone bug in formatPostDate, stylelint config for third-party CSS

Closes #609, #662

Changes

Foundation

  • Install recharts, @vanilla-extract/css, @vanilla-extract/vite-plugin
  • Configure vanillaExtractPlugin() in vite.config.mjs
  • Create VE theme contract (theme.css.ts) and global Recharts styles (global.css.ts)
  • Add Recharts utilities: margins, font style, watermark config, tick formatters

Migrated charts (16 files)

  • 5 poverty impact bar charts (by age, gender, race, deep poverty variants)
  • 1 inequality impact bar chart
  • 4 distributional impact bar charts (income/wealth × average/relative)
  • 2 winners/losers stacked horizontal bar charts
  • 1 historical parameter step-line chart
  • 2 earnings variation line/area charts (baseline-only + baseline-and-reform)
  • 1 marginal tax rates line/area chart

Stays on Plotly (6 files — future PRs)

  • Choropleth map, hexagonal map (no Recharts geo support)
  • 2 waterfall charts (no native Recharts waterfall)
  • Blog markdown/notebook Plotly JSON embeds

Pre-existing fixes

  • Rebuild design-system dist to include text.warning color type
  • Fix formatPostDate timezone bug (date-only strings parsed as UTC)
  • Add stylelint ignore for third-party blog post CSS assets

Test plan

  • npm run lint — 0 errors (ESLint + Stylelint)
  • npx tsc --noEmit — 0 errors
  • npm test — 2848 passed, 0 failed
  • npm run build — both website + calculator build
  • Visual check: all 16 migrated charts render with correct colors, labels, tooltips
  • Visual check: remaining 6 Plotly charts (maps, waterfall, blog) unaffected

🤖 Generated with Claude Code

MaxGhenis and others added 3 commits February 13, 2026 15:24
Install recharts and @vanilla-extract/css + vite-plugin. Add VE theme
contract and global Recharts styles. Add Recharts utility constants
(margins, font, watermark) and tick formatter functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace react-plotly.js with recharts for all non-map, non-waterfall,
non-blog chart components. This includes:

- 5 poverty impact bar charts (by age, gender, race, deep poverty)
- 1 inequality impact bar chart
- 4 distributional impact bar charts (income/wealth, average/relative)
- 2 winners/losers stacked horizontal bar charts
- 1 historical parameter step-line chart
- 2 earnings variation line/area charts
- 1 marginal tax rates line/area chart

Also fixes pre-existing issues:
- Fix timezone bug in formatPostDate (date-only strings)
- Add stylelint ignore for third-party blog post CSS assets

Closes #609, #662

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
policyengine-app-v2 Ready Ready Preview, Comment Feb 14, 2026 6:06pm
policyengine-calculator Ready Ready Preview, Comment Feb 14, 2026 6:06pm

Request Review

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove explicit type annotation and use `as const` instead, letting TypeScript
infer a narrow literal type that is structurally compatible with both Recharts'
SVG tick props and CSS style properties.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MaxGhenis and others added 2 commits February 13, 2026 16:29
wordWrap() was converting newlines to <br> HTML tags, which Plotly
renders as HTML but Recharts renders as literal text. Changed wordWrap
to return \n instead, and added .replaceAll('\n', '<br>') at the Plotly
consumption sites (budgetary impact charts).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Create ChartWatermark, ImpactTooltip, ImpactBarLabel, and TOOLTIP_STYLE
as shared components/constants, replacing ~650 lines of duplicated code
across 16 Recharts chart files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rewrite chart-standards.md to document Recharts as the default chart
library, with shared components (ChartWatermark, ImpactTooltip,
ImpactBarLabel, TOOLTIP_STYLE) and Plotly exceptions list. Update
CLAUDE.md reference.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Historical values: anchor y-axis at 0 with nice round tick intervals,
  add solid zero reference line via ReferenceLine
- Winners/losers: allow tooltip to escape chart viewbox so it renders
  above stacked bars instead of overlapping them

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The vanillaExtractPlugin in Vite was interfering with Plotly.js module
loading, causing congressional district choropleth maps to render blank.
Since VE is wrong for Recharts charts (SVG prop-based styling), remove
all VE traces: plugin config, CSS-in-JS imports, .css.ts files, and
packages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MaxGhenis MaxGhenis merged commit 6f37026 into main Feb 14, 2026
8 checks passed
@MaxGhenis MaxGhenis deleted the recharts-vanilla-extract-migration branch February 14, 2026 18:13
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 0.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@policyengine
Copy link
Copy Markdown

policyengine Bot commented Feb 17, 2026

Sorry @github-actions[bot], only members of the PolicyEngine/core-developers team can invoke Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch from plotly to recharts

1 participant