fix(Area): connectNulls connects across stacked points where every series is null#7566
Conversation
…ries is null A null value in one series of a stack still renders as zero contribution so the offsets of the series above are preserved. When every series in the stack is null at a data point there is no offset to preserve, so the point becomes a break point that connectNulls can connect across. Fixes recharts#6985
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
WalkthroughChangesStacked area null-gap handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AreaChart
participant selectArea
participant computeArea
AreaChart->>selectArea: request stacked area points
selectArea->>computeArea: pass stackDataKeys
computeArea->>computeArea: detect all-null stack breakpoint
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cartesian/Area.tsx`:
- Line 983: Replace DataKey<any> with DataKey<unknown> in the stackDataKeys type
in src/cartesian/Area.tsx at lines 983-983 and in the return type of the area
selector in src/state/selectors/areaSelectors.ts at lines 141-145; preserve the
existing APIs and behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 08c36f9e-7c12-4c1d-a0df-31d324b428f5
⛔ Files ignored due to path filters (3)
test-vr/__snapshots__/tests/www/AreaChartApiExamples.spec-vr.tsx-snapshots/AreaChartConnectNulls-1-chromium-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/www/AreaChartApiExamples.spec-vr.tsx-snapshots/AreaChartConnectNulls-1-firefox-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/www/AreaChartApiExamples.spec-vr.tsx-snapshots/AreaChartConnectNulls-1-webkit-linux.pngis excluded by!**/*.png
📒 Files selected for processing (4)
src/cartesian/Area.tsxsrc/state/selectors/areaSelectors.tstest/chart/AreaChart.spec.tsxwww/src/docs/exampleComponents/AreaChart/AreaChartConnectNulls.tsx
Bundle ReportChanges will decrease total bundle size by 506 bytes (-0.01%) ⬇️. This is within the configured threshold ✅ Detailed changes
ℹ️ *Bundle size includes cached data from a previous commit Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-treeshaking-sankeyAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-sunburstAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-treemapAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7566 +/- ##
==========================================
+ Coverage 88.20% 88.23% +0.03%
==========================================
Files 615 619 +4
Lines 14276 14390 +114
Branches 3591 3645 +54
==========================================
+ Hits 12592 12697 +105
- Misses 1494 1499 +5
- Partials 190 194 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Why did we close #7085 ? |
1e1f762 to
29a5c1e
Compare
Fixes #6985.
Top chart is master, bottom is this PR. The all-null point (Page C) connects across; the partial-null point (Page F, only
uvmissing) still renders as 0, so the #7073 regression does not return.Problem
In a stacked AreaChart with
connectNulls, a data point where every series is null renders as a drop to 0 instead of connecting across the gap. d3-stack defaults nulls to 0, sovalue1is never null for stacked data, and the!connectNullsguard is the only thing controlling null behavior there.Change
computeAreainsrc/cartesian/Area.tsxmarks a point as a break point when every dataKey in the stack group is null (wholeStackIsNull). The stack dataKeys are supplied by a newselectStackDataKeysselector insrc/state/selectors/areaSelectors.ts.The
!connectNulls && rawValue == nullguard is unchanged, so a point where only some series are null still renders as 0 in the stack.Prior art
This is the design proposed by @Harikrushn9118 in #7085: keep the existing guard, add a separate all-null check, and pass the stack dataKeys into
computeArea. #7085 was closed by its author before completion. This PR implements that design and commits the VR snapshots #7085 was missing.History
#7041 removed the
!connectNullsguard and was merged, then reverted in #7073 because it made stacked charts with a single null series render incorrectly. This PR keeps that guard and scopes the new behavior to the all-null case, so the #7073 regression does not return.Tests
test/chart/AreaChart.spec.tsx: two regression tests, "connects across points where every stacked series is null if connectNulls is true" and "breaks at points where every stacked series is null if connectNulls is false". Both fail without the source change. The existing "Renders null points as 0 if stacked and connectNulls is true" test covers the partial-null case that must stay unchanged.wwwexampleAreaChartConnectNulls.tsx: adds adataWithGapsdataset with an all-null point at Page C and a partial-null point at Page F.Summary by CodeRabbit
connectNullsnow reliably bridges fully missing stacked points, while keeping breaks whenconnectNullsis disabled.connectNulls.connectNullsbehavior for all-missing stacked points in area charts.