feat(Bar): support data prop directly on Bar, like Line/Area/Scatter - #7599
Conversation
Bar registered its per-item settings with data hardcoded to undefined,
even though the store selectors (selectBarRectangles) already knew how
to fall back to item-level data when present. This meant <Bar data={...}>
silently did nothing, and Bar would fail to render at all when the parent
chart had no top-level data prop (recharts#3985).
Line, Area, and Scatter already support this via the DataProvider
interface; Bar now does too.
Walkthrough
ChangesBar data propagation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle ReportChanges will decrease total bundle size by 243 bytes (-0.0%) ⬇️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
|
Bar now supports a data prop (previous commit), so the omnidoc readProject snapshots need to include it in their prop lists.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7599 +/- ##
=======================================
Coverage 88.19% 88.20%
=======================================
Files 620 620
Lines 14520 14520
Branches 3718 3717 -1
=======================================
+ Hits 12806 12807 +1
+ Misses 1519 1518 -1
Partials 195 195 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I'm going to handle this as a new feature |
Summary
<Bar>silently ignored adataprop set directly on it, and would fail to render entirely when the parent chart had no top-leveldata— even thoughLine,Area, andScatterall support per-itemdatavia theDataProviderinterface. Fixes #3985 (and the closely related #1699, #3504).Root cause:
Bar.tsxregisters its settings with the store viaSetCartesianGraphicalItem, but hardcodeddata={undefined}regardless of what was actually passed to<Bar data={...}>— with a comment literally questioning why ("Bar does not allow setting data directly on the graphical item (why?)"). The selector layer (selectBarRectanglesinbarSelectors.ts) already had full support for falling back to item-level data when present; it just never received any because of this one line.Changes
BarPropsnow extendsDataProvider<DataPointType>(matchingLine/Area/Scatter), sodatais a properly typed prop.SetCartesianGraphicalItemnow reportsprops.datainstead of a hardcodedundefined.Test plan
Bar's owndataprop is reported to the Redux store.<Bar data={...}>renders correctly even when the parent chart has no top-leveldata.test/cartesian/Barsuite passes (123/123).test/cartesian,test/chart,test/statesuites pass with no regressions (2394+ tests).tsc --noEmitclean.eslintclean.Summary by CodeRabbit
datafor consistent state integration and rendering.data.dataprop for Bar.