Skip to content

Update niceTicks to enum, add support for nice log and symlog scale ticks#7042

Merged
PavelVanecek merged 11 commits intomainfrom
copilot/clarify-nice-ticks
Mar 2, 2026
Merged

Update niceTicks to enum, add support for nice log and symlog scale ticks#7042
PavelVanecek merged 11 commits intomainfrom
copilot/clarify-nice-ticks

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

Okay so I added couple changes here on my own:

  • Changed nicecTicks from boolean to enum ('adaptive' | 'snap125') - let me know if you can think of better names
  • Added support for log and symlog scales
  • Added guide page and playground
  • Fixed a bug where ticks were not aligned in composed chart (this wasn't intentional but a happy coincidence, I'll take it)
  • Updated scale type definition to better match what is actually going on

See https://recharts.github.io/recharts/pr-7042/www/en-US/guide/axisTicks/

  • Define NiceTicks type: 'none' | 'auto' | 'equidistant' | 'nice' in cartesianAxisSlice.ts
  • Update TicksSettings.niceTicks from boolean to NiceTicks
  • Update combineNiceTicks in axisSelectors.ts to handle enum values
  • Update defaults from false'auto' in all axis settings and default props files
  • Update component prop types in XAxis.tsx, YAxis.tsx, PolarAngleAxis.tsx, PolarRadiusAxis.tsx
  • Export NiceTicks type from src/index.ts
  • Update tests that referenced niceTicks: false to use niceTicks: 'auto'
  • Add 3 new tests for 'none', 'equidistant', and 'nice' enum values
  • Add NiceTicks storybook story for visual documentation
  • Add NiceTicks to the exportsThatNeedExamples list in verifyExamples.spec.ts
  • Update www/ example components using niceTicks (boolean shorthand) → niceTicks="nice"
  • TypeScript checks pass, all 14000+ tests pass, ESLint clean, CodeQL clean
Original prompt

This section details on the original issue you should resolve

<issue_title>Clarify niceTicks</issue_title>
<issue_description>Recharts now has three ways of rendering axis ticks:

  1. ticks decided by d3, evenly spaced and not rounded
  2. "nice ticks A" calculated using getFormatStep (defined in getNiceTickValues.ts)
  3. "nice ticks B" calculated using getFormatStepNice (unreleased, scheduled for 3.8)

Recharts sometimes decides to calculate ticks using variant 1 and sometimes variant 2, the conditions for selecting are not at all intuitive (only for numerical axes with linear scales of type "auto" with tickCount > 0 where at least one of the domain definitions contains the keyword "auto", how's that sound? see combineNiceTicks in axisSelectors.ts).

Then just recently we have added variant 3 which is only activated if all of those rules above are true, AND there is niceTicks=true prop set on the axis.

The initial idea was to replace the "nice ticks A" algorithm completely, only use the "B" variant and delete "A" variant for good. Turns out that the old A is sometimes nicer than B! It uses the space more efficiently, at the expense of making some numbers look less rounded. The B on the other hand uses nice rounded numbers, but sometimes wastes space. Depending on user data.

So let's do this:

  • Keep both A and B nice ticks variants
  • Come up with some meaningful names ("nice nice ticks" and "nice ticks" don't cut it, A and B is also not great naming)
  • Swap the niceTicks prop from boolean to an enum
  • Set the magical selecting algorithm behind "niceTicks=auto" prop (default)
  • Set the other two A/B using their own props
  • If that prop is set explicitly then Recharts won't apply the magical selector, it will just calculate nice ticks using the selected algorithm
  • One of the enum options will also be "none" where Recharts will not attempt any tick niceties
  • Document what is going on</issue_description>

Comments on the Issue (you are @copilot in this section)

@PavelVanecek @ckifer @MaxGhenis thoughts? @ckifer Sounds good to me, better than what we have going on if we release as-is for sure

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@codecov
Copy link

codecov bot commented Feb 23, 2026

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.27MB 2.71kB (0.21%) ⬆️
recharts/bundle-es6 1.1MB 2.65kB (0.24%) ⬆️
recharts/bundle-treeshaking-sankey 336.47kB 2.58kB (0.77%) ⬆️
recharts/bundle-treeshaking-polar 439.95kB 967 bytes (0.22%) ⬆️
recharts/bundle-treeshaking-treemap 344.95kB 2.58kB (0.75%) ⬆️
recharts/bundle-treeshaking-sunburst 314.15kB 2.58kB (0.83%) ⬆️

Affected Assets, Files, and Routes:

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

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 2.58kB 344.95kB 0.75%
view changes for bundle: recharts/bundle-treeshaking-polar

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 967 bytes 439.95kB 0.22%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/axisSelectors.js 810 bytes 65.77kB 1.25%
polar/PolarAngleAxis.js 1 bytes 12.95kB 0.01%
polar/PolarRadiusAxis.js 1 bytes 11.79kB 0.01%
util/scale/getNiceTickValues.js 224 bytes 11.74kB 1.95%
state/selectors/polarAxisSelectors.js 2 bytes 8.78kB 0.02%
state/cartesianAxisSlice.js 1.61kB 8.02kB 25.2% ⚠️
state/selectors/combiners/combineConfiguredScale.js 6 bytes 2.47kB 0.24%
state/selectors/combiners/combineRealScaleType.js 45 bytes 1.72kB 2.69%
polar/defaultPolarAngleAxisProps.js 1 bytes 770 bytes 0.13%
polar/defaultPolarRadiusAxisProps.js 1 bytes 663 bytes 0.15%
view changes for bundle: recharts/bundle-treeshaking-sunburst

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 2.58kB 314.15kB 0.83%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/axisSelectors.js 756 bytes 55.89kB 1.37%
polar/PolarAngleAxis.js 1 bytes 11.51kB 0.01%
util/scale/getNiceTickValues.js 227 bytes 10.8kB 2.15%
polar/PolarRadiusAxis.js 1 bytes 10.34kB 0.01%
state/cartesianAxisSlice.js 1.61kB 7.1kB 29.47% ⚠️
state/selectors/polarAxisSelectors.js 2 bytes 7.06kB 0.03%
state/selectors/combiners/combineConfiguredScale.js 6 bytes 1.59kB 0.38%
state/selectors/combiners/combineRealScaleType.js 45 bytes 872 bytes 5.44% ⚠️
polar/defaultPolarAngleAxisProps.js 1 bytes 598 bytes 0.17%
polar/defaultPolarRadiusAxisProps.js 1 bytes 489 bytes 0.2%
view changes for bundle: recharts/bundle-treeshaking-sankey

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 2.58kB 336.47kB 0.77%

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 37.79264% with 186 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.80%. Comparing base (758c6d4) to head (f782614).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...onents/GuideView/AxisTicks/NiceTicksPlayground.tsx 16.34% 87 Missing ⚠️
www/src/components/GuideView/AxisTicks/index.tsx 11.11% 48 Missing ⚠️
...components/GuideView/AxisTicks/CustomAxisTicks.tsx 27.11% 43 Missing ⚠️
src/state/selectors/axisSelectors.ts 77.77% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7042      +/-   ##
==========================================
- Coverage   90.20%   89.80%   -0.41%     
==========================================
  Files         526      529       +3     
  Lines       39650    39883     +233     
  Branches     5442     5446       +4     
==========================================
+ Hits        35768    35815      +47     
- Misses       3873     4059     +186     
  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.

@github-actions
Copy link
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@PavelVanecek PavelVanecek added bug General bug label feature request Issues that are feature requests labels Feb 26, 2026
@PavelVanecek PavelVanecek changed the title [WIP] Clarify behavior of niceTicks in Recharts Update niceTicks to enum, add support for nice log and symlog scale ticks Feb 26, 2026
@PavelVanecek PavelVanecek marked this pull request as ready for review February 26, 2026 14:29
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one I did not mean to touch but the change looks like an improvement for me so I kept it. I couldn't find any related issues.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Chromium renders different ticks than the other two browsers which is interesting I suppose. At least it's consistent.

@github-actions
Copy link
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@PavelVanecek PavelVanecek force-pushed the copilot/clarify-nice-ticks branch from 35704e2 to 1067efc Compare February 27, 2026 12:05
@github-actions
Copy link
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@PavelVanecek PavelVanecek force-pushed the copilot/clarify-nice-ticks branch from 1067efc to 16fd6e2 Compare February 28, 2026 12:42
@github-actions
Copy link
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@PavelVanecek PavelVanecek force-pushed the copilot/clarify-nice-ticks branch from 16fd6e2 to f782614 Compare March 1, 2026 14:49
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@PavelVanecek PavelVanecek merged commit 798d6b1 into main Mar 2, 2026
43 of 47 checks passed
@PavelVanecek PavelVanecek deleted the copilot/clarify-nice-ticks branch March 2, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug General bug label feature request Issues that are feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify niceTicks

3 participants