Remove incidental D3 runtime usage - #25
Conversation
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (19)
📝 WalkthroughWalkthroughThe change replaces selected incidental ChangesD3 capability ownership
Estimated code review effort: 4 (Complex) | ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/charts-core/src/nearest.ts`:
- Around line 13-25: Update the nearest-point calculation in the loop to use
Math.hypot(dx, dy) instead of squared deltas, and compare the resulting direct
distance against maxDistance without squaring it. Add a regression test covering
large finite coordinates, such as a point at 2e200 within a 3e200 maximum
distance, while preserving existing nearest-point behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8d29c89c-ec88-4b33-9e65-3374707a721b
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (16)
.changeset/explicit-d3-capabilities.mdAPI-FRICTION.mdbenchmarks/bundle-size/universal-baseline.jsondocs/concepts/scales-and-d3.mddocs/installation.mdpackages/charts-core/docs/concepts/scales-and-d3.mdpackages/charts-core/docs/installation.mdpackages/charts-core/src/exports.test.tspackages/charts-core/src/legend.tspackages/charts-core/src/nearest.tspackages/charts-scales/package.jsonpackages/charts-scales/src/linear.tspackages/charts-scales/src/ticks.test.tspackages/charts-scales/src/ticks.tsscripts/check-packed-consumers.mjsscripts/measure-bundles.mjs
| let result: ChartPoint<TDatum, TXValue, TYValue> | undefined | ||
| let resultDistance = Infinity | ||
| for (const point of points) { | ||
| const dx = point.x - x | ||
| const dy = point.y - y | ||
| return dx * dx + dy * dy | ||
| }) | ||
| const distance = dx * dx + dy * dy | ||
| if (distance < resultDistance) { | ||
| result = point | ||
| resultDistance = distance | ||
| } | ||
| } | ||
| if (!result) return null | ||
| const dx = result.x - x | ||
| const dy = result.y - y | ||
| return dx * dx + dy * dy <= Math.max(0, maxDistance) ** 2 ? result : null | ||
| return resultDistance <= Math.max(0, maxDistance) ** 2 ? result : null |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Prevent overflow in nearest-point distance comparison.
dx * dx + dy * dy overflows to Infinity for finite coordinate deltas above approximately 1.34e154. Line 19 then does not select the point because Infinity < Infinity is false. For example, a point at { x: 2e200, y: 0 } is within a 3e200 maximum distance but returns null.
Use Math.hypot(dx, dy) and compare the direct distance with maxDistance. Add a regression test for large finite coordinates.
Proposed fix
- const distance = dx * dx + dy * dy
+ const distance = Math.hypot(dx, dy)
...
- return resultDistance <= Math.max(0, maxDistance) ** 2 ? result : null
+ return resultDistance <= Math.max(0, maxDistance) ? result : null📝 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.
| let result: ChartPoint<TDatum, TXValue, TYValue> | undefined | |
| let resultDistance = Infinity | |
| for (const point of points) { | |
| const dx = point.x - x | |
| const dy = point.y - y | |
| return dx * dx + dy * dy | |
| }) | |
| const distance = dx * dx + dy * dy | |
| if (distance < resultDistance) { | |
| result = point | |
| resultDistance = distance | |
| } | |
| } | |
| if (!result) return null | |
| const dx = result.x - x | |
| const dy = result.y - y | |
| return dx * dx + dy * dy <= Math.max(0, maxDistance) ** 2 ? result : null | |
| return resultDistance <= Math.max(0, maxDistance) ** 2 ? result : null | |
| let result: ChartPoint<TDatum, TXValue, TYValue> | undefined | |
| let resultDistance = Infinity | |
| for (const point of points) { | |
| const dx = point.x - x | |
| const dy = point.y - y | |
| const distance = Math.hypot(dx, dy) | |
| if (distance < resultDistance) { | |
| result = point | |
| resultDistance = distance | |
| } | |
| } | |
| if (!result) return null | |
| return resultDistance <= Math.max(0, maxDistance) ? result : null |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/charts-core/src/nearest.ts` around lines 13 - 25, Update the
nearest-point calculation in the loop to use Math.hypot(dx, dy) instead of
squared deltas, and compare the resulting direct distance against maxDistance
without squaring it. Add a regression test covering large finite coordinates,
such as a point at 2e200 within a 3e200 maximum distance, while preserving
existing nearest-point behavior.
86ff203 to
c422a2c
Compare
Summary
d3-arrayuse in nearest-point lookup and quantile legends with package-owned implementationsValidation
pnpm validatepnpm changeset statusSummary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests