Skip to content

fix(YAxis): render explicit ticks when a non-literal domain can't resolve on empty data (#7362)#7393

Merged
PavelVanecek merged 1 commit into
recharts:mainfrom
blackfuel-ai:fix/issue-7362-ticks-fallback
Jun 24, 2026
Merged

fix(YAxis): render explicit ticks when a non-literal domain can't resolve on empty data (#7362)#7393
PavelVanecek merged 1 commit into
recharts:mainfrom
blackfuel-ai:fix/issue-7362-ticks-fallback

Conversation

@nlenepveu

@nlenepveu nlenepveu commented May 31, 2026

Copy link
Copy Markdown
Contributor

Draft — proposes the approach @PavelVanecek suggested on #7362 (derive the domain from explicit ticks when data is absent). Opening as a draft for a steer on the approach before polishing.

What

Follow-up to #7384 (the failing repro). When a numeric axis supplies an explicit ticks array but its domain cannot be resolved without data — a function bound, or 'auto'/'dataMin'/'dataMax' — the scale never builds on empty/all-null data, so the axis renders zero ticks. A literal numeric domain already works; this extends that to derived domains.

This avoids the typing problem raised on the issue (the AxisDomain function form is typed (NumberDomain, boolean) => NumberDomain, so feeding it undefined/NaN would be a breaking change): instead of calling the user's function without data, we fall back to the explicit ticks' extent.

How

combineNumericalDomain falls back to [Math.min(...ticks), Math.max(...ticks)] of the explicit numeric ticks only when all of:

  • the user domain could not be resolved without data (numericalDomainSpecifiedWithoutRequiringDataundefined), and
  • parseNumericalUserDomain also returned undefined (no data domain — empty/all-null data and no domain-extending reference elements), and
  • allowDataOverflow is set, and
  • the axis is type="number" with ≥1 numeric tick.

So it never overrides a resolvable literal domain, never engages when data is present, and leaves category / polar / tooltip paths untouched.

  • adds combineNumericTicksDomain + selectNumericTicksDomain (the ticks [min,max] extent)
  • threads it as an optional input to combineNumericalDomain (polar/tooltip pass nothing → unchanged)
  • does not touch parseNumericalUserDomain / numericalDomainSpecifiedWithoutRequiringData — their "undefined without data" contract is preserved
  • converts the test(YAxis): failing repro for #7362 — function domain doesn't render ticks on empty/all-null data #7384 it.fails repro into passing tests + adds edge-case coverage (unsorted/non-numeric/single ticks, tickCount-only, literal-wins, no-overflow, data-present guards)

Test plan

  • YAxis.7362.derivedDomain.spec.tsx — 13 cases (positive + negative guards) pass
  • Affected selectors/axis/scatter/polar inventory + full unit:lib suite green locally (vitest 4)
  • format / lint / typecheck clean
  • Maintainer steer on the approach
  • Open question: should the fallback also apply without allowDataOverflow? (kept it required, for parity with the literal-domain path)

Refs #7362. Follows #7384.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue where axis ticks would not render properly when no data is available but explicit numeric ticks are specified. The axis domain now intelligently falls back to the explicit tick range when allowDataOverflow is enabled.
  • Tests

    • Expanded test coverage to verify axis behavior with explicit ticks on empty or null data scenarios.

…olve on empty data (recharts#7362)

Follow-up to recharts#7384 (which added the failing repro). When a numeric axis specifies
an explicit `ticks` array but its `domain` cannot be resolved without data — a
function bound, or 'auto'/'dataMin'/'dataMax' — the scale never built on
empty/all-null data, so the axis rendered zero ticks. A literal numeric domain
already works; this extends that to derived domains, as discussed on recharts#7362.

combineNumericalDomain now falls back to the [min, max] extent of the explicit
numeric ticks when: the user domain could not be resolved without data, there is
no data domain (no data and no domain-extending reference elements),
allowDataOverflow is set, and the axis is type='number' with numeric ticks. The
fallback never overrides a resolvable literal domain, never engages when data is
present, and leaves category/polar/tooltip paths untouched.

- add combineNumericTicksDomain + selectNumericTicksDomain (ticks [min,max] extent)
- thread it as an optional input to combineNumericalDomain (polar/tooltip unaffected)
- does NOT alter parseNumericalUserDomain / numericalDomainSpecifiedWithoutRequiringData
- converts the recharts#7384 it.fails repro into passing tests + adds edge-case coverage

Refs recharts#7362.

Signed-off-by: Nicolas <[email protected]>
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: db51dbc1-2b0c-40c0-8ec3-5f643c8b4d13

📥 Commits

Reviewing files that changed from the base of the PR and between 7a23854 and 9e3a4e4.

📒 Files selected for processing (2)
  • src/state/selectors/axisSelectors.ts
  • test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx

Walkthrough

This PR implements a numeric ticks-derived domain fallback for axis resolution on empty/all-null data. It exports new helpers to extract [min,max] from explicit numeric ticks, updates combineNumericalDomain to accept and use this fallback when data-driven domains cannot resolve under allowDataOverflow, and converts a test suite from documenting gaps to asserting the resolved behavior with comprehensive edge-case validation.

Changes

Numeric ticks domain fallback

Layer / File(s) Summary
Numeric ticks domain extraction
src/state/selectors/axisSelectors.ts
combineNumericTicksDomain derives [min,max] extent from explicit numeric ticks for number axes; selectNumericTicksDomain memoizes this via createSelector for use in axis selectors.
Domain resolution with ticks fallback
src/state/selectors/axisSelectors.ts
combineNumericalDomain now accepts numericTicksDomain parameter and implements fallback: when allowDataOverflow is enabled, mergedDomains is null, and numeric ticks exist, it returns the derived ticks domain instead of unresolved; selectNumericalDomain is rewired to include selectNumericTicksDomain.
Test suite for derived domain fallback
test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx
Test suite converted from it.fails to passing assertions; introduces renderChart/renderChartEx helpers with axis domain spying to parameterize rendering across function/auto/dataMin/dataMax domains on empty/null data; adds comprehensive guards verifying no fallback on literal resolvable domains, missing allowDataOverflow, presence of data, tickCount-only, mixed/non-numeric ticks, or no numeric ticks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • recharts/recharts#7362: The PR directly implements the numeric ticks-derived domain fallback mechanism to resolve YAxis tick rendering on empty/all-null data when function or auto domains are specified with explicit numeric ticks and allowDataOverflow enabled.

Possibly related PRs

  • recharts/recharts#7384: Related PR that adds the selector and fallback logic in combineNumericalDomain to use explicit numeric ticks as a domain fallback when data-driven resolution fails.
  • recharts/recharts#7379: Related PR that adds React/Vitest + Playwright CT test cases directly validating the new combineNumericalDomain fallback path using derived numericTicksDomain for YAxis behavior on empty/all-null data.

Suggested labels

typescript

Suggested reviewers

  • PavelVanecek
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing YAxis to render explicit ticks when a non-literal domain fails to resolve on empty data, with a reference to the issue number.
Description check ✅ Passed The description provides comprehensive context, motivation, implementation details, test coverage, and checklist items, though some checkbox items are marked incomplete pending maintainer review.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 7.84kB (0.14%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.4MB 2.05kB (0.15%) ⬆️
recharts/bundle-es6 1.23MB 1.85kB (0.15%) ⬆️
recharts/bundle-umd 585.12kB 277 bytes (0.05%) ⬆️
recharts/bundle-treeshaking-cartesian 695.42kB 1.83kB (0.26%) ⬆️
recharts/bundle-treeshaking-polar 461.27kB 1.83kB (0.4%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-treeshaking-cartesian

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 1.83kB 695.42kB 0.26%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/axisSelectors.js 2.05kB 73.05kB 2.88%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/axisSelectors.js 1.85kB 62.83kB 3.03%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 277 bytes 585.12kB 0.05%
view changes for bundle: recharts/bundle-treeshaking-polar

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 1.83kB 461.27kB 0.4%

@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.07%. Comparing base (7a23854) to head (9e3a4e4).
⚠️ Report is 56 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7393      +/-   ##
==========================================
+ Coverage   89.01%   89.07%   +0.05%     
==========================================
  Files         579      579              
  Lines       13562    13579      +17     
  Branches     3426     3433       +7     
==========================================
+ Hits        12072    12095      +23     
+ Misses       1328     1324       -4     
+ Partials      162      160       -2     

☔ View full report in Codecov by Harness.
📢 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 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am not quite certain if allowDataOverflow should make a difference here. We're talking about a chart that has all null data anyway, the overflow makes no sense. Maybe let's have the new code only when it's true so that we affect fewer people? Someone else might rely on the old behaviour.

@nlenepveu

Copy link
Copy Markdown
Contributor Author

Agreed — let's keep it gated on allowDataOverflow (that's what the PR does). Thanks for the review!

@nlenepveu
nlenepveu marked this pull request as ready for review June 1, 2026 12:56
@PavelVanecek
PavelVanecek merged commit 89fc87b into recharts:main Jun 24, 2026
58 checks passed
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.

2 participants