feat: add Recharts adapter for accessible chart integration#555
feat: add Recharts adapter for accessible chart integration#555jooyoungseo wants to merge 4 commits intomainfrom
Conversation
Add a Recharts adapter that converts Recharts chart data and SVG structure into MAIDR's accessible format. This enables audio sonification, text descriptions, braille output, and keyboard navigation for Recharts charts. The adapter provides: - MaidrRecharts wrapper component for convenience - useRechartsAdapter hook for flexible integration with <Maidr> - convertRechartsToMaidr utility for non-React usage - CSS selectors targeting Recharts SVG elements for highlighting - Support for bar, line, area, scatter, and pie chart types - Simple mode (single chart type) and composed mode (mixed types) Exported as maidr/recharts with full TypeScript type definitions. Closes #542 https://claude.ai/code/session_01KDu3WPhNGkhRFYhY57xEKQ
PR Review: Recharts AdapterGood direction overall — this fills a real gap for Recharts users who want MAIDR accessibility. The API surface (simple mode vs composed mode, Critical1.
|
| Severity | Issue |
|---|---|
| Critical | MaidrRecharts constructs a new config object every render, breaking useMemo |
| Critical | :nth-of-type targets element tag not class — multi-series highlighting will be incorrect |
| Major | Pie chart uses BAR semantics without documentation or deferral |
| Major | No tests for 817 lines of new code |
| Major | recharts missing from peerDependencies |
| Minor | Unnecessary \! non-null assertion in buildComposedLayers |
| Minor | toNumber silently zeroes bad data without any warning |
| Minor | area to LINE mapping not surfaced in user-facing documentation |
Fixes from PR review: - Fix memoization in MaidrRecharts: memoize on individual primitive props instead of recreating config object every render - Fix CSS selector: replace :nth-of-type with :nth-child to avoid wrong series targeting when axes/grids share same <g> tag - Remove non-null assertion in buildComposedLayers with proper guard - Add recharts as optional peer dependency (^2.0.0 || ^3.0.0) New chart type support: - stacked_bar → TraceType.STACKED (SegmentedPoint[][] data) - dodged_bar → TraceType.DODGED (SegmentedPoint[][] data) - normalized_bar → TraceType.NORMALIZED (SegmentedPoint[][] data) - histogram → TraceType.HISTOGRAM (HistogramPoint[] with bin ranges) - radar → TraceType.LINE (radar dots as line points) - funnel → TraceType.BAR (funnel trapezoids as bar categories) New configuration options: - fillKeys: display names for series in segmented bar charts - binConfig: histogram bin range keys (xMinKey, xMaxKey, etc.) Tests: - 40 unit tests for converters and selectors (87% stmt coverage) - Add @adapters path alias to tsconfig.json https://claude.ai/code/session_01KDu3WPhNGkhRFYhY57xEKQ
PR Review: Recharts Adapter (updated review based on current code)The adapter is well-structured and addresses a real need. Many issues flagged in the earlier review have already been addressed (memoization in Critical1.
|
| Severity | Issue |
|---|---|
| Critical | :nth-child multi-series selectors won't match in real Recharts SVG due to sibling element ordering |
| Major | useRechartsAdapter hook memos on object reference — memoization is effectively no-op for inline configs |
| Major | Line chart x-values coerced to numbers; string category labels become 0 |
| Major | Stacked/dodged/normalized with single yKey creates TraceType.STACKED + BarPoint[] mismatch |
| Minor | Pie/funnel mapped to BAR without surfacing this in per-type JSDoc |
| Minor | toNumber returning 0 silently for invalid values |
| Minor | Unnecessary non-null assertion in buildSegmentedBarLayer |
- Drop CSS positional selectors for multi-series charts (unreliable with Recharts' sibling-based SVG structure); return undefined to gracefully disable highlighting; add selectorOverride escape hatch - Fix useRechartsAdapter memoization: destructure config and track individual fields in useMemo dependency array - Preserve string x-axis values in line/area/radar charts via toLineX() instead of coercing category labels like 'Jan' to 0 - Fall back to TraceType.BAR when segmented bar types have single yKey - Remove non-null assertions in buildSegmentedBarLayer/buildHistogramLayer by refactoring to accept individual params - Document pie/funnel BAR mapping for screen reader awareness in JSDoc - Update tests: 55 tests pass covering all chart types, selectorOverride, single-yKey fallback, string x-axis preservation https://claude.ai/code/session_01KDu3WPhNGkhRFYhY57xEKQ
PR Review: feat: add Recharts adapter for accessible chart integrationOverall this is a well-structured, thoroughly-documented addition that follows the project's patterns cleanly. The separation of the adapter outside the core MVVC layers is the right call, and the test coverage is excellent. Below are observations ranging from bugs to suggestions. Bug: Composed Mode Always Disables CSS HighlightingIn Inside if (seriesIndex \!= null) { // 0 \!= null → true
return undefined;
}Because A minimal fix: only disable highlighting when if (seriesIndex \!= null && seriesIndex > 0) {
return undefined;
}Or, alternatively, don't pass Concern: Unreachable Cases in
|
Add a Recharts adapter that converts Recharts chart data and SVG
structure into MAIDR's accessible format. This enables audio
sonification, text descriptions, braille output, and keyboard
navigation for Recharts charts.
The adapter provides:
Exported as maidr/recharts with full TypeScript type definitions.
Closes #542
https://claude.ai/code/session_01KDu3WPhNGkhRFYhY57xEKQ