Skip to content

fix(Area): connectNulls works correctly across null values in stacked AreaChart#7041

Merged
PavelVanecek merged 1 commit into
recharts:mainfrom
Harikrushn9118:fix-area-connect-nulls-stacked
Feb 28, 2026
Merged

fix(Area): connectNulls works correctly across null values in stacked AreaChart#7041
PavelVanecek merged 1 commit into
recharts:mainfrom
Harikrushn9118:fix-area-connect-nulls-stacked

Conversation

@Harikrushn9118

@Harikrushn9118 Harikrushn9118 commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #6985. As discussed in the issue, this allows Area charts with both stackId and connectNulls={true} to correctly connect across missing data points without erroneously treating the points as 0.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of null data points in stacked area charts when connectNulls is enabled, producing more consistent path connections across gaps.
  • Tests

    • Updated tests to more precisely verify generated path commands and exact coordinates for null-point rendering in stacked area scenarios.

@coderabbitai

coderabbitai Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉


Walkthrough

Removed connectNulls from the areaSettings destructuring in computeArea and simplified the isBreakPoint null-handling logic for stacked areas; updated tests to assert the adjusted SVG path command sequences when connectNulls is enabled with stacked charts.

Changes

Cohort / File(s) Summary
Area Chart Core Logic
src/cartesian/Area.tsx
Removed connectNulls from areaSettings destructuring in computeArea and changed isBreakPoint calculation so it no longer depends on connectNulls when hasStack is true; null break detection now relies on value nullability and stack presence.
Area Chart Tests
test/chart/AreaChart.spec.tsx
Updated test description, introduced getCommands helper for parsing SVG path commands, and adjusted assertions to expect modified command sequences and exact coordinates reflecting the new null-handling behavior for stacked areas with connectNulls.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is minimal but correctly identifies the issue being fixed (#6985) and explains the core problem. It lacks detailed context on motivation, testing, and checklist completion as specified in the template. Complete the PR description template by adding Motivation/Context, testing details, types of changes, and relevant checklist items to meet repository standards.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: enabling connectNulls to work correctly in stacked AreaCharts across null values, matching the core change in the code.
Linked Issues check ✅ Passed The PR directly addresses issue #6985 by modifying the connectNulls logic in stacked AreaCharts to prevent treating null/undefined values as zero and allow continuous line drawing across missing data.
Out of Scope Changes check ✅ Passed All changes are focused on fixing connectNulls behavior in stacked AreaCharts; test updates validate the fix. No unrelated modifications detected outside the stated objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/chart/AreaChart.spec.tsx (1)

728-732: getCommands regex won't match negative coordinates.

The pattern /[a-zA-Z][\d ,.]+/g requires digits, spaces, dots, or commas after the command letter. A negative coordinate (e.g., L-10,20) would cause the -10 portion to be missed, splitting one command into two. Not a problem with the current test data, but worth noting if this helper gets reused.

🔧 Suggested more robust regex
-      return [...d.matchAll(/[a-zA-Z][\d ,.]+/g)];
+      return [...d.matchAll(/[a-zA-Z][\d ,.\-]+/g)];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/chart/AreaChart.spec.tsx` around lines 728 - 732, The helper getCommands
uses the regex /[a-zA-Z][\d ,.]+/g which fails to include negative coordinates;
update the regex used in getCommands (the matcher on d from
path.getAttribute('d')) to also accept plus/minus signs and any non-command
characters (for example include '-' and '+' or switch to a pattern like matching
a letter followed by all non-letter chars) so commands like "L-10,20" are
captured as a single command token.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/chart/AreaChart.spec.tsx`:
- Around line 728-732: The helper getCommands uses the regex /[a-zA-Z][\d ,.]+/g
which fails to include negative coordinates; update the regex used in
getCommands (the matcher on d from path.getAttribute('d')) to also accept
plus/minus signs and any non-command characters (for example include '-' and '+'
or switch to a pattern like matching a letter followed by all non-letter chars)
so commands like "L-10,20" are captured as a single command token.

@Harikrushn9118
Harikrushn9118 force-pushed the fix-area-connect-nulls-stacked branch from 558836b to 3b13dab Compare February 22, 2026 17:41
@Harikrushn9118
Harikrushn9118 force-pushed the fix-area-connect-nulls-stacked branch from 3b13dab to 60444ce Compare February 22, 2026 18:06
@codecov

codecov Bot commented Feb 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (c49b263) to head (60444ce).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7041   +/-   ##
=======================================
  Coverage   90.13%   90.13%           
=======================================
  Files         526      526           
  Lines       39254    39254           
  Branches     5438     5438           
=======================================
  Hits        35380    35380           
  Misses       3865     3865           
  Partials        9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PavelVanecek
PavelVanecek merged commit a5333dd into recharts:main Feb 28, 2026
41 checks passed
@PavelVanecek

Copy link
Copy Markdown
Collaborator

So I think we're going to revert this PR until we have a fix for this regression: https://www.chromatic.com/test?appId=63da8268a0da9970db6992aa&id=69a3a5c4a8428a9961c0a8ca

FYI @ckifer

Copilot AI added a commit that referenced this pull request Mar 2, 2026
PavelVanecek added a commit that referenced this pull request Mar 3, 2026
…tConnectNulls to website example (#7073)

PR #7041 fixed stacked `AreaChart` null handling but broke
`connectNulls={true}` — null points became break points even when the
user explicitly opted into connecting them.

## Changes

- **Revert `src/cartesian/Area.tsx`**: Restore `connectNulls`
destructuring and `!connectNulls &&` guard in `isBreakPoint`. With
`connectNulls={true}` on a stacked chart, null entries are treated as 0
(connected through) rather than skipped.
- **Revert `test/chart/AreaChart.spec.tsx`**: Restore original test
name, expected `d` path, and assertions — `pv` area correctly curves
through the null point at y=43 rather than jumping straight across.
- **Migrate stacked story to website example**:
`StackedAreaChartConnectNulls` storybook story removed;
`AreaChartConnectNulls.tsx` website example now shows all four cases:
simple with/without `connectNulls` and stacked with/without
`connectNulls`.
- **Delete stale VR snapshots**: Old screenshots for
`AreaChartConnectNulls` removed so CI regenerates them against the
updated component.

## Related Issue

Fixes #7070

Reopens #6985

## Motivation and Context

`!connectNulls &&` was the intentional guard that let users opt into
connecting through null values in stacked charts. Removing it (PR #7041)
meant `connectNulls={true}` had no effect in stacked mode, producing a
single straight interpolated line instead of a smooth stacked curve,
causing visible visual artifacts.

## How Has This Been Tested?

Unit test `'Renders null points as 0 if stacked and connectNulls is
true'` in `test/chart/AreaChart.spec.tsx` verifies the correct path `d`
values. VR test for `AreaChartConnectNulls` will generate new
screenshots covering all four chart variants.

## Screenshots (if appropriate):

## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] I have added a storybook story or VR test, or extended an existing
story or VR test to show my changes

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>[Unreleased] Area connect nulls overlaps</issue_title>
> <issue_description>## What is the current behavior?
> ## What is the expected behavior?
> 
>
https://www.chromatic.com/test?appId=63da8268a0da9970db6992aa&id=69a3a5c4a8428a9961c0a8ca
> 
> #7041 fixed some problems but
created new different problems.</issue_description>
> 
> <agent_instructions>Please revert changes from the PR that caused this
problem. Then, migrate the AreaChartConnectNulls.tsx storybook from
stories to a website example, and then add a VR test for
it.</agent_instructions>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #7070

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/recharts/recharts/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Fixed stacked area charts to properly treat missing data points as
zero when the connectNulls option is enabled, preventing unwanted
breakpoints in the chart visualization.

* **Documentation**
* Added examples demonstrating stacked area chart behavior with and
without connectNulls for handling missing data.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: PavelVanecek <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Harikrushn9118 added a commit to Harikrushn9118/recharts that referenced this pull request Mar 3, 2026
…ies are null

Fixes recharts#6985. PR recharts#7041 removed the !connectNulls guard entirely, which caused
a regression (recharts#7070) where stacked areas overlapped when connectNulls={true}
and only some series had null values.

This v2 fix preserves the original !connectNulls guard and adds a new
allStackedSeriesNull check: when connectNulls is true and a stacked chart has
a data point where ALL series in the stack are null, only then treat it as a
breakpoint. If only some series are null, they are connected through as 0
(the correct stacking behavior).

Changes:
- Added selectStackDataKeys selector to retrieve all dataKeys in a stack group
- Pass stackDataKeys into computeArea
- isBreakPoint now has three conditions:
  1. value1 == null (basic null check)
  2. hasStack && !connectNulls && rawValue == null (original guard, preserved)
  3. allStackedSeriesNull (new: all series null → break even with connectNulls)
PavelVanecek pushed a commit that referenced this pull request Jul 20, 2026
…ries is null (#7566)

Fixes #6985.

![Stacked AreaChart with connectNulls, dataWithGaps dataset. Before:
all-null point at Page C collapses to 0. After: Page C connects across,
and the partial-null uv at Page F still renders as
0.](https://raw.githubusercontent.com/kimlj/recharts/pr-6985-assets/6985-before-after.png)

Top chart is master, bottom is this PR. The all-null point (Page C)
connects across; the partial-null point (Page F, only `uv` missing)
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, so `value1` is never null for stacked
data, and the `!connectNulls` guard is the only thing controlling null
behavior there.

## Change

`computeArea` in `src/cartesian/Area.tsx` marks a point as a break point
when every dataKey in the stack group is null (`wholeStackIsNull`). The
stack dataKeys are supplied by a new `selectStackDataKeys` selector in
`src/state/selectors/areaSelectors.ts`.

The `!connectNulls && rawValue == null` guard is unchanged, so a point
where only some series are null still renders as 0 in the stack.

- Every series null at a point: connects across (new behavior).
- Some series null at a point: unchanged, renders as 0 to preserve stack
offsets.

## 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 `!connectNulls` guard 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.
- `www` example `AreaChartConnectNulls.tsx`: adds a `dataWithGaps`
dataset with an all-null point at Page C and a partial-null point at
Page F.
- VR snapshots committed for chromium, firefox, and webkit.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved stacked area gap/break detection when an entire stacked point
has all series values missing, so gaps are handled correctly.
* `connectNulls` now reliably bridges fully missing stacked points,
while keeping breaks when `connectNulls` is disabled.
* Partial missing values still render with correct stacked
contributions.
* **Documentation**
* Added stacked area examples showing how gaps are rendered with and
without `connectNulls`.
* **Tests**
* Added coverage validating `connectNulls` behavior for all-missing
stacked points in area charts.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stackId and connectNulls don't work together for points with no data

2 participants