Conversation
WalkthroughThis PR introduces a new rounding utility module with Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Areas requiring extra attention:
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/shape/Sector.tsx (1)
177-178: Inconsistent rounding: this path segment is not rounded.Line 178 uses a plain template literal instead of
roundTemplateLiteral, which could produce unroundedcxandcyvalues in the output path wheninnerArcAngle < 0 && cornerRadius === 0.Consider applying rounding here for consistency:
if (innerArcAngle < 0 && cornerRadius === 0) { - return `${path}L${cx},${cy}Z`; + return roundTemplateLiteral`${path}L${cx},${cy}Z`; }Note: Since
pathis already a string (built withroundTemplateLiteral), it will pass through unchanged, whilecxandcywill be rounded.
🧹 Nitpick comments (3)
src/util/round.ts (1)
1-29: Rounding helpers match the intended behavior; consider adding explicit return type
roundandroundTemplateLiteralcorrectly implement 4‑decimal rounding and-0normalization, and the tag logic for interleaving rounded values with template strings is sound.To better align with your TypeScript guidelines about explicit typing, you could annotate the tag’s return type:
-export function roundTemplateLiteral(strings: TemplateStringsArray, ...values: ReadonlyArray<number | string>) { +export function roundTemplateLiteral( + strings: TemplateStringsArray, + ...values: ReadonlyArray<number | string>, +): string {test/polar/Radar.animation.spec.tsx (1)
203-213: Radar animation expectations updated consistently; consider future float-tolerance only if neededThe new numeric literals for animated polygon paths, dot positions, and radii correctly reflect the rounded SVG output and keep the animation tests’ structure intact. If floating‑point differences across future Node versions ever resurface, you could optionally loosen these tests (e.g., by rounding radii inside the helpers) rather than comparing raw doubles, but that’s not required for this PR.
Also applies to: 245-295, 277-285, 327-333, 339-345, 349-375, 407-413, 419-425, 431-457, 495-501, 507-513, 519-545, 577-583, 589-615, 621-627
test/polar/Pie.animation.spec.tsx (1)
173-175: Update comment to match canonicalized endAngle assertionThe assertion now checks that the last sector’s
endAngleis0, while the comment still says “should be 360 degrees”. Given the normalization to0for a full circle, it would be clearer to align the comment with the behavior:- // Also, because the Pie is always a full circle, the end angle of the last sector should be 360 degrees - expect(finalAngles[finalAngles.length - 1].endAngle).toBe(0); + // Also, because the Pie is always a full circle, the last sector ends at 360 degrees, + // which is represented as 0 degrees in the normalized angle space + expect(finalAngles[finalAngles.length - 1].endAngle).toBe(0);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
test/cartesian/__snapshots__/ReferenceArea.spec.tsx.snapis excluded by!**/*.snaptest/shape/__snapshots__/Sector.spec.tsx.snapis excluded by!**/*.snap
📒 Files selected for processing (33)
scripts/snapshots/es6Files.txt(1 hunks)scripts/snapshots/libFiles.txt(1 hunks)scripts/snapshots/typesFiles.txt(1 hunks)src/shape/Polygon.tsx(2 hunks)src/shape/Rectangle.tsx(4 hunks)src/shape/Sector.tsx(6 hunks)src/shape/Trapezoid.tsx(1 hunks)src/util/DataUtils.ts(2 hunks)src/util/round.ts(1 hunks)test/cartesian/Area.animation.spec.tsx(1 hunks)test/cartesian/Bar.animation.spec.tsx(7 hunks)test/cartesian/Bar.spec.tsx(33 hunks)test/cartesian/ErrorBar.spec.tsx(2 hunks)test/cartesian/Funnel.animation.spec.tsx(5 hunks)test/cartesian/Line.animation.spec.tsx(5 hunks)test/cartesian/ReferenceArea.spec.tsx(2 hunks)test/cartesian/Scatter.animation.spec.tsx(1 hunks)test/cartesian/XAxis/XAxis.barSize.spec.tsx(3 hunks)test/cartesian/XAxis/XAxis.padding.spec.tsx(10 hunks)test/chart/BarChart.spec.tsx(26 hunks)test/chart/PieChart.spec.tsx(4 hunks)test/chart/RadialBarChart.spec.tsx(4 hunks)test/component/Legend.spec.tsx(4 hunks)test/helper/expectPieSectors.ts(2 hunks)test/polar/Pie.animation.spec.tsx(11 hunks)test/polar/Pie.spec.tsx(6 hunks)test/polar/PolarAngleAxis.spec.tsx(1 hunks)test/polar/Radar.animation.spec.tsx(13 hunks)test/polar/Radar.spec.tsx(2 hunks)test/polar/RadialBar.animation.spec.tsx(6 hunks)test/polar/RadialBar.spec.tsx(3 hunks)test/shape/Rectangle.animation.spec.tsx(2 hunks)test/util/round.spec.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (DEVELOPING.md)
Run type checking on the codebase using
npm run check-types
**/*.{ts,tsx}: Never useanytype (implicit or explicit) in TypeScript code
Preferunknownoveranyand refine the type in TypeScript
Type function parameters and return values explicitly in TypeScript, do not rely on implicit any or inference; exceptions are React components and trivial functions
Do not useastype assertions in TypeScript; the only exception isas const
Files:
test/helper/expectPieSectors.tstest/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/polar/Pie.spec.tsxsrc/util/round.tstest/util/round.spec.tstest/cartesian/XAxis/XAxis.padding.spec.tsxtest/chart/RadialBarChart.spec.tsxtest/polar/PolarAngleAxis.spec.tsxsrc/shape/Trapezoid.tsxsrc/shape/Polygon.tsxtest/cartesian/Scatter.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxsrc/shape/Rectangle.tsxtest/chart/PieChart.spec.tsxsrc/util/DataUtils.tstest/cartesian/ReferenceArea.spec.tsxsrc/shape/Sector.tsxtest/component/Legend.spec.tsxtest/cartesian/Area.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/cartesian/Bar.spec.tsxtest/polar/RadialBar.spec.tsxtest/cartesian/Line.animation.spec.tsxtest/polar/Radar.spec.tsxtest/chart/BarChart.spec.tsxtest/cartesian/XAxis/XAxis.barSize.spec.tsxtest/cartesian/ErrorBar.spec.tsxtest/polar/Pie.animation.spec.tsx
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Ensure code lints by running
npm run lintand follows Airbnb's Style Guide
Files:
test/helper/expectPieSectors.tstest/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/polar/Pie.spec.tsxsrc/util/round.tstest/util/round.spec.tstest/cartesian/XAxis/XAxis.padding.spec.tsxtest/chart/RadialBarChart.spec.tsxtest/polar/PolarAngleAxis.spec.tsxsrc/shape/Trapezoid.tsxsrc/shape/Polygon.tsxtest/cartesian/Scatter.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxsrc/shape/Rectangle.tsxtest/chart/PieChart.spec.tsxsrc/util/DataUtils.tstest/cartesian/ReferenceArea.spec.tsxsrc/shape/Sector.tsxtest/component/Legend.spec.tsxtest/cartesian/Area.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/cartesian/Bar.spec.tsxtest/polar/RadialBar.spec.tsxtest/cartesian/Line.animation.spec.tsxtest/polar/Radar.spec.tsxtest/chart/BarChart.spec.tsxtest/cartesian/XAxis/XAxis.barSize.spec.tsxtest/cartesian/ErrorBar.spec.tsxtest/polar/Pie.animation.spec.tsx
{test,www/test}/**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (DEVELOPING.md)
Write unit tests in the
testorwww/testdirectories with.spec.tsxfile extension
Files:
test/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/polar/Pie.spec.tsxtest/util/round.spec.tstest/cartesian/XAxis/XAxis.padding.spec.tsxtest/chart/RadialBarChart.spec.tsxtest/polar/PolarAngleAxis.spec.tsxtest/cartesian/Scatter.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxtest/chart/PieChart.spec.tsxtest/cartesian/ReferenceArea.spec.tsxtest/component/Legend.spec.tsxtest/cartesian/Area.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/cartesian/Bar.spec.tsxtest/polar/RadialBar.spec.tsxtest/cartesian/Line.animation.spec.tsxtest/polar/Radar.spec.tsxtest/chart/BarChart.spec.tsxtest/cartesian/XAxis/XAxis.barSize.spec.tsxtest/cartesian/ErrorBar.spec.tsxtest/polar/Pie.animation.spec.tsx
test/**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Aim for 100% unit test code coverage when writing new code
Files:
test/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/polar/Pie.spec.tsxtest/util/round.spec.tstest/cartesian/XAxis/XAxis.padding.spec.tsxtest/chart/RadialBarChart.spec.tsxtest/polar/PolarAngleAxis.spec.tsxtest/cartesian/Scatter.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxtest/chart/PieChart.spec.tsxtest/cartesian/ReferenceArea.spec.tsxtest/component/Legend.spec.tsxtest/cartesian/Area.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/cartesian/Bar.spec.tsxtest/polar/RadialBar.spec.tsxtest/cartesian/Line.animation.spec.tsxtest/polar/Radar.spec.tsxtest/chart/BarChart.spec.tsxtest/cartesian/XAxis/XAxis.barSize.spec.tsxtest/cartesian/ErrorBar.spec.tsxtest/polar/Pie.animation.spec.tsx
test/**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (test/README.md)
test/**/*.{test,spec}.{ts,tsx}: Aim for 100% unit test code coverage when writing new code
Prefer to use thecreateSelectorTestCasehelper function when writing or modifying tests
Use theexpectLastCalledWithhelper function instead ofexpect(spy).toHaveBeenLastCalledWith(...)for better typing and autocompletion
Verify the number of selector calls using the spy object fromcreateSelectorTestCaseto spot unnecessary re-renders and improve performance
MockgetBoundingClientRectin tests using the helper function provided intest/helper/MockGetBoundingClientRect.ts
Usevi.useFakeTimers()in all tests due to Redux autoBatchEnhancer dependency on timers andrequestAnimationFrame
Callvi.runOnlyPendingTimers()to advance timers after renders when not usingcreateSelectorTestCasehelper, and avoidvi.runAllTimers()to prevent infinite loops
UseuserEvent.setup({ advanceTimers: vi.runOnlyPendingTimers })or theuserEventSetuphelper function fromtest/helper/userEventSetup.tswhen creating userEvent instances
When testing tooltips on hover, usevi.runOnlyPendingTimers()after eachuserEvent.hover()call or use theshowTooltiphelper function fromtooltipTestHelpers.tsto account for requestAnimationFrame delays
Files:
test/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/polar/Pie.spec.tsxtest/util/round.spec.tstest/cartesian/XAxis/XAxis.padding.spec.tsxtest/chart/RadialBarChart.spec.tsxtest/polar/PolarAngleAxis.spec.tsxtest/cartesian/Scatter.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxtest/chart/PieChart.spec.tsxtest/cartesian/ReferenceArea.spec.tsxtest/component/Legend.spec.tsxtest/cartesian/Area.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/cartesian/Bar.spec.tsxtest/polar/RadialBar.spec.tsxtest/cartesian/Line.animation.spec.tsxtest/polar/Radar.spec.tsxtest/chart/BarChart.spec.tsxtest/cartesian/XAxis/XAxis.barSize.spec.tsxtest/cartesian/ErrorBar.spec.tsxtest/polar/Pie.animation.spec.tsx
**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
When running unit tests, prefer to run a single test file using
npm run test -- path/to/TestFile.spec.tsxrather than running all tests withnpm test
Files:
test/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/polar/Pie.spec.tsxtest/util/round.spec.tstest/cartesian/XAxis/XAxis.padding.spec.tsxtest/chart/RadialBarChart.spec.tsxtest/polar/PolarAngleAxis.spec.tsxtest/cartesian/Scatter.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxtest/chart/PieChart.spec.tsxtest/cartesian/ReferenceArea.spec.tsxtest/component/Legend.spec.tsxtest/cartesian/Area.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/cartesian/Bar.spec.tsxtest/polar/RadialBar.spec.tsxtest/cartesian/Line.animation.spec.tsxtest/polar/Radar.spec.tsxtest/chart/BarChart.spec.tsxtest/cartesian/XAxis/XAxis.barSize.spec.tsxtest/cartesian/ErrorBar.spec.tsxtest/polar/Pie.animation.spec.tsx
src/**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (DEVELOPING.md)
Run ESLint and Prettier on the codebase using
npm run lint
Files:
src/util/round.tssrc/shape/Trapezoid.tsxsrc/shape/Polygon.tsxsrc/shape/Rectangle.tsxsrc/util/DataUtils.tssrc/shape/Sector.tsx
src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Do not hardcode any strings or formatting choices in library code; users should provide localized strings as desired
Files:
src/util/round.tssrc/shape/Trapezoid.tsxsrc/shape/Polygon.tsxsrc/shape/Rectangle.tsxsrc/util/DataUtils.tssrc/shape/Sector.tsx
test/component/**/*.spec.tsx
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Use React Testing Library for testing component interactions and behavior upon rendering
Files:
test/component/Legend.spec.tsx
🧠 Learnings (10)
📚 Learning: 2025-11-25T01:23:08.237Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.237Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Verify the number of selector calls using the spy object from `createSelectorTestCase` to spot unnecessary re-renders and improve performance
Applied to files:
test/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/chart/RadialBarChart.spec.tsxtest/polar/PolarAngleAxis.spec.tsxtest/cartesian/Scatter.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxtest/chart/PieChart.spec.tsxtest/cartesian/ReferenceArea.spec.tsxtest/component/Legend.spec.tsxtest/cartesian/Area.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/polar/RadialBar.spec.tsxtest/cartesian/Line.animation.spec.tsxtest/polar/Radar.spec.tsxtest/chart/BarChart.spec.tsxtest/cartesian/ErrorBar.spec.tsxtest/polar/Pie.animation.spec.tsx
📚 Learning: 2025-11-25T01:23:08.237Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.237Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Use the `expectLastCalledWith` helper function instead of `expect(spy).toHaveBeenLastCalledWith(...)` for better typing and autocompletion
Applied to files:
test/cartesian/Bar.animation.spec.tsxtest/polar/Radar.animation.spec.tsxtest/shape/Rectangle.animation.spec.tsxtest/cartesian/Funnel.animation.spec.tsxtest/polar/RadialBar.animation.spec.tsxtest/cartesian/Line.animation.spec.tsx
📚 Learning: 2025-11-25T01:23:08.237Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.237Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Call `vi.runOnlyPendingTimers()` to advance timers after renders when not using `createSelectorTestCase` helper, and avoid `vi.runAllTimers()` to prevent infinite loops
Applied to files:
test/polar/Radar.animation.spec.tsx
📚 Learning: 2025-11-25T01:23:08.237Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.237Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : When testing tooltips on hover, use `vi.runOnlyPendingTimers()` after each `userEvent.hover()` call or use the `showTooltip` helper function from `tooltipTestHelpers.ts` to account for requestAnimationFrame delays
Applied to files:
test/polar/Radar.animation.spec.tsxtest/cartesian/Scatter.animation.spec.tsx
📚 Learning: 2025-11-25T01:22:59.699Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-25T01:22:59.699Z
Learning: Applies to test/component/**/*.spec.tsx : Use React Testing Library for testing component interactions and behavior upon rendering
Applied to files:
test/polar/Radar.animation.spec.tsx
📚 Learning: 2025-11-25T01:23:08.237Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.237Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Mock `getBoundingClientRect` in tests using the helper function provided in `test/helper/MockGetBoundingClientRect.ts`
Applied to files:
test/shape/Rectangle.animation.spec.tsxtest/util/round.spec.tstest/cartesian/ReferenceArea.spec.tsxtest/component/Legend.spec.tsx
📚 Learning: 2025-11-25T01:22:59.699Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-25T01:22:59.699Z
Learning: Applies to test/**/*.spec.{ts,tsx} : Aim for 100% unit test code coverage when writing new code
Applied to files:
test/util/round.spec.ts
📚 Learning: 2025-11-25T01:23:08.237Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.237Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Aim for 100% unit test code coverage when writing new code
Applied to files:
test/util/round.spec.ts
📚 Learning: 2025-11-25T01:22:48.279Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: DEVELOPING.md:0-0
Timestamp: 2025-11-25T01:22:48.279Z
Learning: Applies to {test,www/test}/**/*.spec.{ts,tsx} : Write unit tests in the `test` or `www/test` directories with `.spec.tsx` file extension
Applied to files:
test/util/round.spec.ts
📚 Learning: 2025-11-25T01:22:59.699Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-25T01:22:59.699Z
Learning: Applies to storybook/stories/**/*.stories.tsx : Update Storybook stories when APIs have been changed to ensure they work as expected
Applied to files:
test/chart/BarChart.spec.tsx
🧬 Code graph analysis (11)
test/helper/expectPieSectors.ts (1)
src/util/round.ts (1)
round(4-11)
test/cartesian/Bar.animation.spec.tsx (1)
test/animation/MockProgressAnimationManager.ts (1)
prime(137-158)
test/shape/Rectangle.animation.spec.tsx (1)
test/animation/MockProgressAnimationManager.ts (1)
prime(137-158)
test/util/round.spec.ts (1)
src/util/round.ts (2)
round(4-11)roundTemplateLiteral(18-29)
src/shape/Trapezoid.tsx (1)
src/util/round.ts (1)
roundTemplateLiteral(18-29)
src/shape/Polygon.tsx (1)
src/util/round.ts (1)
roundTemplateLiteral(18-29)
src/shape/Rectangle.tsx (2)
storybook/stories/API/props/RectangleProps.ts (1)
radius(8-21)src/util/round.ts (2)
round(4-11)roundTemplateLiteral(18-29)
test/chart/PieChart.spec.tsx (1)
test/helper/expectPieSectors.ts (1)
expectPieSectors(13-20)
src/util/DataUtils.ts (1)
src/util/round.ts (1)
round(4-11)
src/shape/Sector.tsx (1)
src/util/round.ts (1)
roundTemplateLiteral(18-29)
test/cartesian/Line.animation.spec.tsx (1)
test/helper/expectDots.ts (1)
expectDots(6-14)
🪛 Biome (2.1.2)
test/util/round.spec.ts
[error] 48-48: This number literal will lose precision at runtime.
The value at runtime will be 123456789.12345679
(lint/correctness/noPrecisionLoss)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Build, Test, Pack
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (49)
test/polar/RadialBar.animation.spec.tsx (1)
72-111: Rounded RadialBar path expectations look consistent with new path formattingAll updated
dstrings and expected path arrays simply reflect rounded coordinates while preserving path structure and test intent. No behavioral or assertion‑logic regressions spotted.Also applies to: 88-113, 148-167, 260-283, 325-343
test/polar/PolarAngleAxis.spec.tsx (1)
1351-1352: Polygon axisLine path expectation correctly updated to rounded coordinatesThe
dattribute now uses rounded coordinates while keeping the same polygon structure and closure (...L250,54Z). This aligns with the new rounding behavior without changing test semantics.test/polar/RadialBar.spec.tsx (1)
411-429: RadialBar sector path expectations correctly updated for rounded coordinatesThe updated
dstrings preserve the same sector geometry while trimming numeric noise, matching the new rounding utility behavior. Test logic and coverage remain the same.Also applies to: 797-813, 1049-1059
test/chart/RadialBarChart.spec.tsx (1)
69-88: Rounded sector and bar geometry expectations align with new rendering precisionThe modified
dpath strings, label arc paths, and bar widths are consistent with rounding to a few decimal places while preserving overall geometry and test intent. No behavioral changes to the test suite beyond stricter, cleaner numeric expectations.Also applies to: 141-160, 222-241, 264-283, 1649-1679, 1797-1825
test/cartesian/ErrorBar.spec.tsx (1)
1649-1679: Bar geometry expectations updated to match rounded widths and path dataThe adjusted
dattributes andwidthvalues now use rounded decimals, consistent with the new rounding behavior, while keeping bar positions and relative sizes intact. ErrorBar logic and axis‑domain tests remain unaffected.Also applies to: 1797-1827
scripts/snapshots/libFiles.txt (1)
193-233: Snapshot manifest correctly includes new round utilAdding
"lib/util/round.js"tolibFiles.txtin the util section keeps snapshots aligned with the new exported utility and maintains the existing directory ordering.test/helper/expectPieSectors.ts (1)
3-3: Pie sector angle helper now uses shared rounding, improving consistencyImporting
roundand applying it incalculateAnglemakes the angle expectations robust to minor FP drift and aligns test calculations with the same rounding used in production SVG paths. The underlying angle math and parsing logic remain correct.Also applies to: 32-46
scripts/snapshots/es6Files.txt (1)
232-232: LGTM! Snapshot entry for new rounding utility.The addition of
es6/util/round.jscorrectly tracks the new rounding utility module in the ES6 exports manifest.src/util/DataUtils.ts (2)
3-3: LGTM! Import for new rounding utility.The import statement correctly brings in the
roundfunction needed for the interpolation rounding below.
108-108: LGTM! Rounding applied to interpolation results.The addition of
round()to the interpolation result is appropriate for SVG/DOM coordinate values and addresses the floating-point precision differences between Node versions mentioned in the PR objectives.test/cartesian/Scatter.animation.spec.tsx (1)
316-318: LGTM! Test expectations updated for rounded coordinates.The
cyvalues have been correctly updated to reflect the rounded numeric output from the new rounding utilities. The precision is consistent with the 4-decimal-place rounding applied throughout the PR.scripts/snapshots/typesFiles.txt (1)
232-232: LGTM! Type declaration snapshot entry.The addition of
types/util/round.d.tscorrectly tracks the type declarations for the new rounding utility.test/component/Legend.spec.tsx (1)
991-1099: LGTM! Test expectations updated for rounded Bar coordinates.The updated assertions reflect the rounded numeric values produced by the new rounding utilities in the Rectangle/Bar shape components. All values are consistently rounded to 4 decimal places, matching the precision chosen in the PR.
test/cartesian/Funnel.animation.spec.tsx (1)
102-169: LGTM! Funnel trapezoid path expectations updated for rounding.The SVG path data strings have been correctly updated to reflect the rounded coordinates generated by the
roundTemplateLiteralutility used in the Trapezoid shape component. All values consistently use 4-decimal-place precision.test/cartesian/Bar.animation.spec.tsx (1)
211-442: LGTM! Bar animation expectations updated for rounded values.The test expectations for heights, y-coordinates, and path data have been correctly updated to match the rounded output from the Rectangle shape component. All values consistently use 4-decimal-place precision, aligning with the rounding utilities introduced in this PR.
The minor wording improvement on line 275 also improves readability.
test/cartesian/Area.animation.spec.tsx (1)
411-412: LGTM! Area dot coordinate expectations updated for rounding.The
cycoordinate strings have been correctly updated to reflect the rounded values produced by the interpolation function in DataUtils. The precision is consistent with the 4-decimal-place rounding applied throughout the PR.src/shape/Polygon.tsx (1)
9-9: Polygon path rounding viaroundTemplateLiterallooks correctUsing
roundTemplateLiteralhere cleanly rounds only the numeric coordinates while preserving the accumulatedpathstring and command characters, without changing control flow orconnectNullssemantics. This aligns with the PR goal of DOM-only rounding.Also applies to: 52-52
test/polar/Radar.spec.tsx (1)
40-46: Updated Radar polygondexpectations match new rounded path outputThe new
dstrings use the compactM250,167.68L...Zform with rounded coordinates, consistent withPolygonnow building paths viaroundTemplateLiteral. No behavioral change to the tests beyond formatting.Also applies to: 60-66
src/shape/Trapezoid.tsx (1)
14-24: Rounding ingetTrapezoidPathis consistent and non-invasiveSwitching to
roundTemplateLiteralfor each segment correctly rounds all numeric coordinates while preserving the existing trapezoid geometry and control flow. This keeps Trapezoid aligned with the other rounded shapes.test/chart/BarChart.spec.tsx (1)
337-447: BarexpectBarssnapshots correctly updated for rounded geometryAll modified
expectBarscases now assert rounded coordinates and dimensions (up to 4 decimals), matching the new Rectangle/rounding behavior while leaving test intent and chart semantics unchanged. Nothing here suggests functional regressions.Also applies to: 465-531, 563-629, 647-713, 731-765, 1004-1070, 1106-1172, 1769-1835, 1933-2037, 2192-2407, 2573-2686, 2699-2841, 2854-2919, 2933-2999, 3012-3077, 3092-3156, 3169-3233
test/cartesian/XAxis/XAxis.padding.spec.tsx (1)
122-168: XAxis padding bar expectations aligned with rounded Rectangle outputThe modified
expectBarsexpectations for the different padding modes now match the rounded Rectangle geometry (x/y/d/height/width), with no change to how padding logic or selector behavior is tested.Also applies to: 211-268, 310-367, 409-467, 508-565, 607-665
test/polar/Pie.spec.tsx (1)
60-67: Pie sector angle and path expectations updated for rounding without changing semanticsRounding
pageDataSectorPathscoordinates and theendAnglevalues in active-shape/event assertions to 4 decimals matches the new Pie/Sector rounding utilities while preserving payload structure and all behavioral checks.Also applies to: 335-412, 1872-2128
src/shape/Rectangle.tsx (1)
15-25: Rectangle rounding integration looks sound and localized to DOM output
roundedWidth/roundedHeightare used only formaxRadiusand sign, bringing radius capping in line with the rendered (rounded) dimensions while changing only sub‑pixel cases.- Converting all path construction to
roundTemplateLiteraland adding roundedx/y/width/heightattributes in the non-update branch cleanly normalizes DOM output without altering validation or animation control flow.- Animated rectangles still route through
getRectanglePath, so theirdstrings are rounded as well, even thoughx/y/width/heightattributes are omitted there (tests appear to rely on the non-animated cases).Also applies to: 34-72, 171-184
test/shape/Rectangle.animation.spec.tsx (2)
234-240: Test expectations correctly updated to reflect 4-decimal rounding.The animated path values (e.g.,
127.8959,139.6508,144.8153) now reflect the rounding applied byroundTemplateLiteralin Rectangle.tsx. These intermediate animation frames demonstrate consistent precision across Node versions.
332-347: Animation path expectations for both increase and decrease transitions look correct.The rounded path coordinates maintain visual fidelity while ensuring cross-Node-version consistency. Both the width-increase (lines 334-337) and width-decrease (lines 343-346) animations show proper interpolation with 4-decimal precision.
test/cartesian/ReferenceArea.spec.tsx (3)
99-99: Path data correctly rounded.The
dattribute now uses rounded values consistent with the Rectangle component's rounding implementation.
363-366: Numeric attributes rounded to 4 decimal places.The
xandwidthattributes now show112.2727and59.0909respectively, matching the rounding precision applied in the Rectangle component.
434-437: Custom shape elements retain full precision as expected.When
shapeis a React Element (line 388), the props are injected directly without going through Rectangle's path rendering, so these attributes (x: '112.27272727272728',width: '59.09090909090909') correctly retain their original precision. This is the expected behavior since only the Rectangle's internal path construction uses rounding.src/shape/Sector.tsx (3)
9-9: Import of rounding utility is appropriate.The
roundTemplateLiteralimport enables consistent numeric rounding across all path string constructions in this file.
59-73: Path construction ingetSectorPathcorrectly uses rounding.The outer arc path (lines 59-63), inner arc path (lines 68-71), and center fallback (line 73) all use
roundTemplateLiteralto ensure consistent numeric precision in the SVG path data.
123-142: Corner radius path segments correctly use rounding.Both the
forceCornerRadiusreturn path (lines 123-126), the main sector path with corners (lines 138-142), and the inner arc segments (lines 181-186) properly applyroundTemplateLiteralfor consistent precision.Also applies to: 181-186
test/cartesian/XAxis/XAxis.barSize.spec.tsx (2)
40-97: Bar position expectations correctly updated with rounded values.The expected bar attributes (
d,height,x,y) now use 4-decimal precision (e.g.,65.8377,144.8179,120.5556), consistent with the rounding applied in the Rectangle component's path generation.
211-219: Single data point bar expectations correctly rounded.These test cases for single data points with various
barSizeconfigurations show properly rounded coordinates and dimensions.Also applies to: 267-275
test/cartesian/Line.animation.spec.tsx (4)
218-218: Stroke-dasharray expectation is correct.The value
'10px 90px'represents the expected stroke-dasharray at 10% animation progress.
371-371: Dashed line stroke-dasharray format updated.The expected value uses comma separation (
'7px, 3px, 0px, 90px') consistent with the dashed stroke animation pattern.
599-627: Animated dot positions correctly show 4-decimal precision.The
cyvalues during animation (e.g.,32.7794,38.4836,40.6985,46.139) reflect the rounded interpolated coordinates, ensuring consistent output across Node versions.
766-794: Additional animation frame expectations correctly updated.These dot position expectations maintain the 4-decimal precision pattern throughout the animation tests, covering both the "interrupting initial animation" and "interaction after initial animation completes" scenarios.
Also applies to: 1124-1162
test/cartesian/Bar.spec.tsx (4)
73-114: Horizontal bar layout expectations correctly rounded.The bar dimension and position values (e.g.,
413.3333,81.6667,331.6667,163.3333) now use consistent 4-decimal precision, matching the Rectangle component's rounding behavior.
178-219: Vertical bar layout expectations correctly rounded.The width values (e.g.,
71.6667,143.3333,286.6667,358.3333) for vertical bars show proper rounding, maintaining visual accuracy while ensuring cross-Node-version consistency.
1165-1182: Zero-value bar handling shows appropriate precision.The small bar heights (e.g.,
0.046for near-zero values) demonstrate that the rounding doesn't eliminate visually meaningful precision for edge cases.
1444-1463: Stacked bar and tooltip interaction tests correctly updated.The stacked bar position expectations maintain the 4-decimal precision pattern, ensuring tooltip interactions work correctly with the rounded coordinates.
Also applies to: 1496-1521, 1536-1555, 1750-1759
test/chart/PieChart.spec.tsx (4)
41-41: Single sector path correctly rounded.The arc coordinates in the path data (
285,205.0014) show proper 4-decimal precision for a full-circle sector.
67-72: Angle values normalized correctly.The angle expectations now use canonical representations:
startAngle: 0instead of-0(line 68)endAngle: 0instead of360(line 71) - mathematically equivalent for a full rotationThis aligns with the
round()utility's-0to0normalization mentioned in the AI summary.
91-98: Sector arc coordinates properly rounded.All sector path data now uses 4-decimal precision for coordinates (e.g.,
202.3541,125.0438,129.4422,178.7128), ensuring consistent rendering across different Node.js versions.
218-225: Cell-based sector rendering expectations correctly updated.The path data for sectors rendered with explicit
<Cell>components shows the same 4-decimal rounding, confirming the rounding is applied consistently regardless of how sectors are configured.test/util/round.spec.ts (1)
4-57: Round / roundTemplateLiteral test matrix looks solid and matches util semanticsThe test suite exercises default/custom precision, negative numbers and
-0, small/large values, and typical SVG path/template use cases, including string passthrough and spacing. This is in line with the coverage expectations for new utilities and should give high confidence in the behavior.Based on learnings, this looks consistent with the “aim for 100% coverage” goal for new test code.
Also applies to: 60-112
test/polar/Pie.animation.spec.tsx (3)
22-26: Updated final sector paths and static angle expectations align with 4‑decimal roundingThe
finalSectorPathsand the non‑animatedexpectPieSectorAnglesexpectations now use coordinates/angles rounded to 4 decimal places and remain internally consistent (paths close correctly, angles describe a full circle with the last sector wrapping viaendAngle: 0). This matches the new rounding behavior used across the shapes.Also applies to: 208-216
272-303: Animated path/angle expectations for the simple props case look consistent with new roundingThe intermediate
dattributes and angle arrays inshould render sectors with animationandshould render sectors with animated anglesare updated to 4‑decimal values, with each step showing smooth progression and sectors that still partition the circle correctly. No logic changes beyond the expected numeric normalization.Also applies to: 306-333
363-440: Angle expectations for dataKey/data array/visibility interactions correctly reflect rounded interpolationAcross the interaction tests (changing
dataKey, changing data array, forcing re‑animation viakey, and hide/show), the updated angle sequences now:
- Use 4‑decimal precision.
- Maintain sector continuity (
startAngleof each sector equals the previous sector’sendAngleor the wrapped equivalent).- Preserve the expected qualitative behavior (growth from a fixed start for the first sector, rearrangements, and wraparound with
endAngle: 0for a full circle).These updates look mechanically consistent with the new rounding behavior and the helper used in
expectPieSectors.Also applies to: 487-510, 538-607, 644-680
| // eslint-disable-next-line no-loss-of-precision | ||
| expect(round(123456789.123456789, 2)).toBe(123456789.12); | ||
| expect(round(999999.999999, 4)).toBe(1000000); | ||
| }); |
There was a problem hiding this comment.
Address precision‑loss lint on large numeric literal
Static analysis flags the 123456789.123456789 literal for precision loss, even though it’s acceptable in this test context. To keep npm run lint / Biome happy, either construct the value without a high‑precision literal or explicitly ignore this rule.
One minimal option is to add a Biome ignore alongside the existing ESLint suppression:
- it('should handle very large numbers', () => {
- // eslint-disable-next-line no-loss-of-precision
- expect(round(123456789.123456789, 2)).toBe(123456789.12);
+ it('should handle very large numbers', () => {
+ // eslint-disable-next-line no-loss-of-precision
+ // biome-ignore lint/correctness/noPrecisionLoss: high-precision literal is intentional for this rounding test
+ expect(round(123456789.123456789, 2)).toBe(123456789.12);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // eslint-disable-next-line no-loss-of-precision | |
| expect(round(123456789.123456789, 2)).toBe(123456789.12); | |
| expect(round(999999.999999, 4)).toBe(1000000); | |
| }); | |
| it('should handle very large numbers', () => { | |
| // eslint-disable-next-line no-loss-of-precision | |
| // biome-ignore lint/correctness/noPrecisionLoss: high-precision literal is intentional for this rounding test | |
| expect(round(123456789.123456789, 2)).toBe(123456789.12); | |
| expect(round(999999.999999, 4)).toBe(1000000); | |
| }); |
🧰 Tools
🪛 Biome (2.1.2)
[error] 48-48: This number literal will lose precision at runtime.
The value at runtime will be 123456789.12345679
(lint/correctness/noPrecisionLoss)
🤖 Prompt for AI Agents
In test/util/round.spec.ts around lines 47 to 50, the numeric literal triggers
Biome's no-loss-of-precision lint rule; add a Biome ignore directive for that
rule alongside the existing ESLint suppression so the test keeps the
high-precision literal but linting passes (place the biome-ignore
no-loss-of-precision directive on the line before the numeric literal, next to
the existing eslint-disable-next-line comment).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6707 +/- ##
=======================================
Coverage 94.02% 94.03%
=======================================
Files 499 500 +1
Lines 42625 42657 +32
Branches 4892 4901 +9
=======================================
+ Hits 40079 40111 +32
Misses 2541 2541
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 8.26kB (0.31%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
|
Description
Round numbers to 4 decimal places before using them as paths. Also updates all relevant tests.
Related Issue
#6704
Motivation and Context
Something between node22 and node24 changed how floating numbers are calculated and that made our numbers differ somewhere at 10th decimal place. Since we're dealing with pixels we don't care about anything after the decimal dot so I figured we may just as well round it. I tried rounding to 0 decimal places but that creates ton of visual diff (somehow), so I made it 4 decimal places. The tests are now passing at node22, node24, and 25 the same.
I have considered rounding in the test helpers instead but that's an uphill battle.
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.