Skip to content

fix(getNiceTickValues): remove trailing duplicate tick when allowDecimals=false#7482

Merged
PavelVanecek merged 1 commit into
recharts:mainfrom
JSap0914:fix/getTickValuesFixedDomain-allowDecimals-duplicate
Jun 29, 2026
Merged

fix(getNiceTickValues): remove trailing duplicate tick when allowDecimals=false#7482
PavelVanecek merged 1 commit into
recharts:mainfrom
JSap0914:fix/getTickValuesFixedDomain-allowDecimals-duplicate

Conversation

@JSap0914

@JSap0914 JSap0914 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Problem

getTickValuesFixedDomain builds its tick array by calling rangeStep and then appending cormax at the end. When allowDecimals is false, all values are rounded to integers. If cormax rounds down to the same integer as the last value produced by rangeStep, the result contains a duplicate trailing tick.

Example:

getTickValuesFixedDomain([0, 4.4], 5, false) // was: [0, 2, 4, 4]  ← duplicate
getTickValuesFixedDomain([0, 3.4], 5, false) // was: [0, 1, 2, 3, 3]  ← duplicate

Root cause

rangeStep(0, 4.4, 2) produces [0, 2, 4]. Then cormax = 4.4 is appended: [0, 2, 4, 4.4]. After Math.round: [0, 2, 4, 4]. The duplicate 4 is a result of Math.round(4.4) === 4, matching the last step value.

The duplicate can only occur at the trailing position because the step is always an integer when allowDecimals = false, so all interior rangeStep values differ by at least 1 after rounding.

Fix

After rounding, check whether the last two elements are equal and remove the trailing one (values.slice(0, last)). The fix is O(1) and preserves all other output properties including -0 semantics.

Also renames getTickValuesFixedDomain.test.tsgetTickValuesFixedDomain.spec.ts so that vitest (configured with include: ['test/**/*.spec.ts?(x)']) actually picks up those existing tests.

Verification

getTickValuesFixedDomain([0, 4.4], 5, false) // now: [0, 2, 4]
getTickValuesFixedDomain([0, 3.4], 5, false) // now: [0, 1, 2, 3]

All 113 test/util/scale/ tests pass, 962 unit tests pass overall.

AI-assisted contribution.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where duplicate tick values could appear when rounding tick values to integers, particularly near the upper domain boundary in certain scaling scenarios.
  • Tests

    • Added comprehensive test cases to validate tick value generation when using integer-only values, ensuring no duplicate values are produced and confirming expected behavior across various domain configurations.

…mals=false

getTickValuesFixedDomain appends cormax after the rangeStep values, then rounds
all ticks to integers when allowDecimals is false. When cormax rounds down to the
same integer as the last rangeStep value, the result contains a duplicate trailing
tick (e.g. getTickValuesFixedDomain([0, 4.4], 5, false) returned [0, 2, 4, 4]).

Fix: after rounding, check whether the last two values are equal and remove the
trailing duplicate. The duplicate can only appear at the end because the step is
an integer, so all interior rangeStep values differ by at least 1 after rounding.

Also rename getTickValuesFixedDomain.test.ts → getTickValuesFixedDomain.spec.ts so
vitest (configured to include test/**/*.spec.ts) actually picks up those tests.
Copilot AI review requested due to automatic review settings June 22, 2026 11:44

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 22, 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: 7c23f794-3c44-4db2-b363-3d2a38907d3b

📥 Commits

Reviewing files that changed from the base of the PR and between c88f5f3 and cbdac05.

📒 Files selected for processing (2)
  • src/util/scale/getNiceTickValues.ts
  • test/util/scale/getTickValuesFixedDomain.spec.ts

Walkthrough

In getTickValuesFixedDomain, the allowDecimals === false branch now detects and removes a duplicate trailing tick that arises when rounding causes the appended cormax value to collapse onto the last computed step integer. Two new test cases assert the corrected output.

Changes

Duplicate tick deduplication in getTickValuesFixedDomain

Layer / File(s) Summary
Deduplication logic and test coverage
src/util/scale/getNiceTickValues.ts, test/util/scale/getTickValuesFixedDomain.spec.ts
After mapping values with Math.round, the implementation now checks whether the final element equals the preceding one and slices off the duplicate. Two new tests assert [0, 2, 4] for domain [0, 4.4] and [0, 1, 2, 3] for domain [0, 3.4], both with 5 requested ticks and allowDecimals=false.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Suggested reviewers

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

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description covers the problem, root cause, fix, and verification with examples. It includes a bonus file rename note. However, the required sections from the template (Related Issue, Motivation/Context, How Tested, Types of Changes, Checklist) are missing. Complete the description by filling in the template sections: add Related Issue link, clarify motivation, document testing approach, and check the applicable boxes in the checklist.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: removing duplicate trailing ticks when allowDecimals is false in getNiceTickValues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 Jun 22, 2026

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.43MB 351 bytes (0.02%) ⬆️
recharts/bundle-es6 1.26MB 351 bytes (0.03%) ⬆️
recharts/bundle-umd 586.24kB 56 bytes (0.01%) ⬆️
recharts/bundle-treeshaking-cartesian 718.04kB 351 bytes (0.05%) ⬆️
recharts/bundle-treeshaking-polar 474.62kB 351 bytes (0.07%) ⬆️
recharts/bundle-treeshaking-treemap 388.89kB 351 bytes (0.09%) ⬆️
recharts/bundle-treeshaking-sunburst 347.18kB 351 bytes (0.1%) ⬆️
recharts/bundle-treeshaking-sankey 375.62kB 351 bytes (0.09%) ⬆️

Affected Assets, Files, and Routes:

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

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 351 bytes 375.62kB 0.09%
view changes for bundle: recharts/bundle-treeshaking-polar

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 351 bytes 474.62kB 0.07%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 56 bytes 586.24kB 0.01%
view changes for bundle: recharts/bundle-treeshaking-cartesian

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 351 bytes 718.04kB 0.05%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
util/scale/getNiceTickValues.js 351 bytes 13.15kB 2.74%
view changes for bundle: recharts/bundle-treeshaking-sunburst

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 351 bytes 347.18kB 0.1%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
util/scale/getNiceTickValues.js 351 bytes 14.08kB 2.56%
view changes for bundle: recharts/bundle-treeshaking-treemap

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 351 bytes 388.89kB 0.09%

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.40%. Comparing base (c88f5f3) to head (cbdac05).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7482   +/-   ##
=======================================
  Coverage   88.39%   88.40%           
=======================================
  Files         602      602           
  Lines       13911    13914    +3     
  Branches     3514     3515    +1     
=======================================
+ Hits        12296    12300    +4     
+ Misses       1432     1431    -1     
  Partials      183      183           

☔ 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 merged commit 14194f3 into recharts:main Jun 29, 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.

3 participants