fix(CartesianAxis): render the axis line when there are no ticks#4433
Merged
Conversation
ckifer
commented
Apr 16, 2024
| const width = useChartWidth(); | ||
| const height = useChartHeight(); | ||
| const axisOptions = useYAxisOrThrow(yAxisId); | ||
|
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 3.x #4433 +/- ##
==========================================
- Coverage 95.04% 95.04% -0.01%
==========================================
Files 106 106
Lines 20723 20722 -1
Branches 2818 2820 +2
==========================================
- Hits 19696 19695 -1
Misses 1021 1021
Partials 6 6 ☔ View full report in Codecov by Sentry. |
1 task
ckifer
commented
Apr 18, 2024
ckifer
left a comment
Member
Author
There was a problem hiding this comment.
I'm just going to ship this. Willing to defend it if anyone thinks its an issue
PavelVanecek
pushed a commit
that referenced
this pull request
May 30, 2026
… ticks on empty/all-null data (#7384) ## What A single, TDD-style **red** spec — `test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx` — documenting the unresolved half of #7362. **Tests only; no `src/` changes** and no behavior/contract change. ## Context PR #7379 (`YAxis.7362.spec.tsx`) showed the **literal** case already works: `type="number"` + `domain={[0, 100]}` + `ticks` (or `tickCount`) + `allowDataOverflow` renders the `0/25/50/75/100` ladder even when every series value is `null` (or `data={[]}`). This spec covers the case that does **not** work yet: a **function** `domain`. A function bound already decides its own value — e.g. `[0, (dataMax) => (Number.isFinite(dataMax) && dataMax > 0 ? dataMax : 100)]` returns a finite `100` when there is no data. The desired behavior is that recharts invokes that function even when the data domain is empty, so the returned finite bounds resolve the scale and the explicit `ticks` render — exactly like the literal case. ## Current behavior (the gap) recharts skips function domains when there is no data domain: - `numericalDomainSpecifiedWithoutRequiringData` returns `undefined` for any function, and - `parseNumericalUserDomain` only calls the function when `dataDomain != null` (`src/util/isDomainSpecifiedByUser.ts`). With empty/all-null data the data domain is `null`, so the function is never called and the axis renders **0 ticks**. ## Why `it.fails` The three specs assert the **desired** behavior (the ladder renders), which currently throws — so `it.fails` passes and the suite stays green while documenting the gap. They flip to **FAILING** the moment recharts resolves a function domain without data, signalling it's time to drop `.fails` and lock the behavior in. Cases covered: - function upper bound `[0, (dataMax) => …]`, all-null data - function upper bound, empty `data={[]}` - whole-domain function `() => [0, 100]`, all-null data ## Running ``` npm ci npx vitest run --config vitest.config.mts test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx ``` Refs #7362. Related: #7379, #4433, #4426. Signed-off-by: Nicolas <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Bug reported in linked issue where after recharts 2.5 the YAxis line would "disappear" with 0 data points or ticks, where it would previously show.
It would previously show because
NaNwas being calculated as a tick value and added to the dom as a tick item. This was fixed in #3454.I would not call this a regression because as per the lines changed in this PR, the axis lines were never meant to show unless there were ticks. (See
!finalTicks || !finalTicks.length). I believe however, that they should be able to.Thus, this is a breaking change for both X and Y axes where even with 0 ticks or 0 valid data items, the axis lines will still render.
For a user to return to the old behavior of no Axis, they only have to do something simple like
YAxis hide={data.length === 0} />or use React convention and conditionally render itRelated Issue
#4426
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: