feat: add shape type to pie, support similar patterns to other Recharts components#6482
feat: add shape type to pie, support similar patterns to other Recharts components#6482
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6482 +/- ##
=======================================
Coverage 94.17% 94.17%
=======================================
Files 494 494
Lines 41644 41656 +12
Branches 4819 4817 -2
=======================================
+ Hits 39218 39230 +12
Misses 2421 2421
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 103 bytes (0.0%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
|
668d50b to
0427746
Compare
WalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Pie as Pie Component
participant Sector as PieSectors
participant Shape as Shape Renderer
User->>Pie: Render with shape prop
Pie->>Sector: Pass shape + data + isActive
Sector->>Shape: shape ?? sectorOptions
alt shape provided
Shape->>Shape: Call shape(props) with isActive
else fallback
Shape->>Shape: Use default sectorOptions
end
Shape-->>User: Render sector (active/inactive)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
0af1889 to
158f2a9
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
storybook/stories/API/chart/PieChart.stories.tsx (1)
2-25: Shape callback correctly demonstrates new PieshapeAPIImporting
Sectorand using ashape={({ isActive, ...props }) => <Sector {...props} fill={isActive ? activeShape.fill : props.fill} />}is consistent with the new Pie shape contract and keepsisActiveout of the renderedSectorprops. This story is a good example of the intended usage.If you want to avoid confusion between the deprecated
activeShapeprop and the newshapeAPI, you might consider renaming theactiveShapearg here to something likeactiveShapeConfigto signal it’s only used for styling in the story controls.test/cartesian/Bar.spec.tsx (1)
841-849: Background callback expectation updated forisActiveflagAdding
isActive: falseto the expected background props keeps this test aligned with the new Shape/activation contract. No functional change beyond exposing the flag to custom backgrounds.You may later want a complementary test that covers
isActive: truefor backgrounds in anactiveBarscenario, to fully lock in the contract.src/util/ActiveShapeUtils.tsx (1)
27-107:Shapenow drives activation viaprops.isActive, enabling callbacks to see active stateRouting
isActivethroughpropsand checkingprops.isActivebefore wrapping in the active<Layer>lets all option variants (element, function, object, default) observe the active state, while keeping prior behavior for non‑active cases. The function and clone branches still behave as before aside from receiving the extraisActiveflag.If there are other call sites of
Shapethat conceptually support an active state but do not yet supplyisActive, consider adding small tests similar to the Bar background and Pie tests to ensure they also get the flag consistently.www/src/docs/api/Pie.ts (1)
172-205: Pie API docs correctly introduceshapeand deprecateactiveShape/inactiveShapeThe new
shapeprop description and thedeprecated: trueflags onactiveShapeandinactiveShapeare consistent with the implementation and give users a clear migration path toward theshape+isActivepattern.If there is a central doc section describing the generic
Shapehelper (object/function/ReactElement semantics), linking to it from theshapeprop description here would make the behavior even clearer.src/polar/Pie.tsx (2)
160-200: Newshapetyping and deprecation annotations for active/inactive shapes look soundDefining
PieShapeand threadingshape?: PieShapethroughInternalPiePropsandPieProps, while markingactiveShape/inactiveShapeas deprecated, matches the intended new API. The separation between internal (InternalPieProps) and external (PieProps) types is preserved and keeps legacy props functional.If you expect consumers to type their
shapecallbacks explicitly, consider exporting a public helper type likePieSectorShapeProps = PieSectorDataItem & { isActive: boolean }so users don’t need to re‑declare the intersection themselves.
268-280:PieSectorscorrectly prioritizesshapeover legacy active/inactive shapes and wiresisActiveThe logic
- derives
isActivefromselectActiveTooltipIndex,- computes
sectorOptionsfromactiveShape/inactiveShapeonly when applicable, and- passes
option={shape ?? sectorOptions}along withisActiveintoShape,so that:
shapefully controls rendering when provided, usingisActivefor styling,- existing
activeShape/inactiveShapebehavior is preserved whenshapeis absent, and- default sectors still work when none of these props are set.
This is a clean, backwards‑compatible layering of the new API.
Down the line, you might add a small unit test that exercises
shapeandactiveShapetogether (e.g.shapedefined,activeShapealso set) to codify thatshapeintentionally wins in such scenarios.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/polar/Pie.tsx(8 hunks)src/util/ActiveShapeUtils.tsx(1 hunks)storybook/stories/API/chart/PieChart.stories.tsx(2 hunks)test/cartesian/Bar.spec.tsx(1 hunks)test/chart/PieChart.spec.tsx(2 hunks)test/polar/Pie.spec.tsx(1 hunks)www/src/docs/api/Pie.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
storybook/stories/API/chart/PieChart.stories.tsx (2)
src/polar/Pie.tsx (1)
Pie(833-873)src/index.ts (2)
Pie(54-54)Sector(32-32)
src/polar/Pie.tsx (2)
src/util/types.ts (1)
ActiveShape(1038-1043)src/util/ActiveShapeUtils.tsx (1)
Shape(80-107)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build, Test, Pack
🔇 Additional comments (4)
test/polar/Pie.spec.tsx (1)
333-406: Active shape mock now correctly assertsisActive: trueExtending the expected
activeShapecall payload withisActive: truematches the updatedShapebehavior and gives good coverage of the new activation signal on Pie sectors.test/chart/PieChart.spec.tsx (2)
505-539: Update click test to target the active shape layerThe revised sequence (null‑check sector, hover to activate, then click the
.recharts-active-shapelayer) matches the new rendering model where the active sector is wrapped in its own<Layer>. This keeps the test robust against the extra wrapper without changing the public click contract.
570-582: Mouse leave test accounts for active shape wrapperAdding the pre‑hover on the active shape before unhovering the sector accurately models how focus/hover transitions work with the new extra
<Layer class="recharts-active-shape">. It prevents false negatives caused by the additional DOM layer in tests.src/polar/Pie.tsx (1)
667-759: Animation path now correctly forwardsshapeto animated sectorsPassing
shape={props.shape}fromSectorsWithAnimationintoPieSectorsensures that custom shapes are honored during animation as well as in the static case. The rest of the animation step logic is unchanged, so existing behavior should remain intact.
| defaultVal: 'null', | ||
| isOptional: false, | ||
| isOptional: true, | ||
| deprecated: true, |
There was a problem hiding this comment.
Would be great to have an alternative in the description for everything that we deprecate. Same as in code.
Description
In 3.0 we removed
activeIndexwhich has proved to cause some pain for consumers.Instead of adding it back, we're moving to a different API for "active" and "inactive" Pie shapes. This will follow similar patterns to custom
LabelandTooltips.Related Issue
A few directly or indirectly related
#6251
#6259
#6052
#5999
Motivation and Context
allow people to do what they want
How Has This Been Tested?
current unit tests pass, need to add more
Screenshots (if appropriate):
Types of changes
Checklist:
need to update docs
Summary by CodeRabbit
New Features
shapeprop for Pie components enabling flexible sector customization. The prop accepts a React element or function receiving active state information for dynamic rendering.Deprecated
activeShapeandinactiveShapeprops are deprecated; use the newshapeprop instead. Existing implementations remain supported for backward compatibility.