fix: add missing sector index to Pie shape#6683
Conversation
WalkthroughThis PR changes Pie shape APIs to pass an index to shape/active-shape functions, introduces a new Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Pie as Pie Component
participant ShapeFn as shape function
participant Sector as Sector Component
Note over App,Pie: Render Pie with shape={renderFn}
App->>Pie: render pie (data, shape=renderFn)
loop for each sector (i)
Pie->>ShapeFn: renderFn(props, i)
Note right of ShapeFn: props includes isActive, payload, index, percent, angles
alt isActive
ShapeFn->>Sector: return custom active Sector/group
else not active
ShapeFn->>Sector: return plain Sector
end
Sector-->>Pie: rendered SVG element
end
Pie-->>App: assembled SVG pie
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-11-23T13:30:10.388ZApplied to files:
🧬 Code graph analysis (2)src/polar/Pie.tsx (2)
test/polar/Pie.spec.tsx (2)
⏰ 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)
🔇 Additional comments (4)
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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/polar/Pie.tsx (1)
537-538: Remove leftover debugconsole.logThe commented
// console.log(onClickFromContext);appears to be debugging residue and can be removed to keep the render path clean.test/polar/Pie.spec.tsx (1)
138-160: Test description now mismatches the prop under testThis test now exercises
shape={...}rather thanactiveShape, but the description still says “when activeShape is set to be an element”; consider renaming to mentionshapeso it’s clear which API the test is covering.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/polar/Pie.tsx(3 hunks)src/util/ActiveShapeUtils.tsx(2 hunks)storybook/stories/Examples/Pie/CustomActiveShapePieChart.stories.tsx(3 hunks)storybook/stories/Examples/Pie/PieWithCells.stories.tsx(2 hunks)test/polar/Pie.spec.tsx(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-23T13:30:10.388Z
Learnt from: PavelVanecek
Repo: recharts/recharts PR: 6669
File: www/src/docs/exampleComponents/ScatterChart/ScatterChartWithLabels.tsx:2-2
Timestamp: 2025-11-23T13:30:10.388Z
Learning: The `TooltipIndex` type from recharts is defined in `src/state/tooltipSlice.ts` but is not currently exported from the public API entry points. It should not be imported from `recharts/types/state/tooltipSlice` as this is an internal implementation path. An ESLint rule is needed to prevent regressions.
Applied to files:
src/polar/Pie.tsxstorybook/stories/Examples/Pie/PieWithCells.stories.tsx
🧬 Code graph analysis (3)
src/polar/Pie.tsx (2)
src/index.ts (1)
PieSectorDataItem(56-56)src/util/ActiveShapeUtils.tsx (1)
Shape(81-108)
storybook/stories/Examples/Pie/PieWithCells.stories.tsx (1)
src/polar/Pie.tsx (1)
Pie(873-913)
test/polar/Pie.spec.tsx (3)
src/shape/Sector.tsx (1)
Sector(213-254)src/index.ts (1)
Sector(32-32)src/util/Constants.ts (2)
DATA_ITEM_INDEX_ATTRIBUTE_NAME(33-33)DATA_ITEM_DATAKEY_ATTRIBUTE_NAME(56-56)
⏰ 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). (2)
- GitHub Check: Build, Test, Pack
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
src/util/ActiveShapeUtils.tsx (2)
27-34: Index added toShapePropslooks consistent and safeAdding
index?: string | numbertoShapePropsmatches howShapeis now used inPieand other charts and stays backward‑compatible since it’s optional and intersected withExtraProps. No issues here.
90-95: Passingprops.indexinto function shape is the right extensionCalling function options as
option(props, props.index)correctly exposes the index to shape/activeShape callbacks while remaining non‑breaking for existing single‑argument handlers that will simply ignore the second parameter.src/polar/Pie.tsx (2)
159-160:PieSectorShapeProps/PieShapedefinitions align withShapeusageDefining
PieSectorShapePropsasPieSectorDataItem & { isActive: boolean; index: number }andPieShapeas a two‑argument function matches whatPieSectorspasses intoShapeand whatShapeforwards to user callbacks; this gives bothprops.indexand the numericindexparameter reliably.
545-573: Index forwarding intoShapeis correct and matches the new APIPassing
index={i}into<Shape option={shape ?? sectorOptions} ...>ensures bothshapeandactiveShape/inactiveShapefunctions can receive a numeric index via the second argument and viaprops.index, which matches the updated tests and story usage.storybook/stories/Examples/Pie/CustomActiveShapePieChart.stories.tsx (1)
22-80: Story correctly demonstrates newPie.shapebehaviorUsing
renderActiveShapeas(props: PieSectorDataItem & { isActive: boolean }) => ReactElementand wiring it viashape={renderActiveShape}matches the new Pie shape API; theisActive-based branch plus the plain<Sector {...props} />fallback is a good, minimal example.Also applies to: 85-85
storybook/stories/Examples/Pie/PieWithCells.stories.tsx (1)
3-3: Interactive highlighting viashapeand click index looks solidTracking
activeIndicesdriven byonClick={(_, index) => { ... }}and usingshape={(props, index) => ...}to conditionally render<Sector>with a different fill is a clean demonstration of the new numeric index being passed through; the toggle logic onactiveIndicesis straightforward and correct.Also applies to: 21-42
test/polar/Pie.spec.tsx (1)
335-412: Expectation onactiveShapecall correctly asserts index propagationUpdating
expect(activeShape).toHaveBeenCalledWith(...)to include theindex: 0field in the props object and the explicit second argument0matches the new behavior whereShapeforwards bothprops.indexand the numeric index parameter toactiveShape. This provides good coverage that the bug fix (missing index) is actually wired through.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6683 +/- ##
=======================================
Coverage 94.02% 94.02%
=======================================
Files 499 499
Lines 42547 42547
Branches 4873 4873
=======================================
Hits 40004 40004
Misses 2538 2538
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 74 bytes (0.0%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
|
Description
I forgot to pass
indexto the newPie.shapeprop. It makes theshapeprop a million times more usefulI'm using a numeric index for now... I think its easier than strings and we're already passing
numberinBar.rectangleand in all of the click handler functionsRelated Issue
Fixes #6052 and #5999
Motivation and Context
How Has This Been Tested?
Adjusted storybook, adjusted tests
Screenshots (if appropriate):
recharts-multi-select.mov
Types of changes
Ehh, feature that was intended to be released in previous minor version
Checklist:
Summary by CodeRabbit
New Features
shapeprop for conditional rendering based on active/inactive state.Sectorcomponent for direct use.Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.