Skip to content

Remove incidental D3 runtime usage - #25

Merged
tannerlinsley merged 2 commits into
mainfrom
taren/d3-dependency-boundaries
Jul 31, 2026
Merged

Remove incidental D3 runtime usage#25
tannerlinsley merged 2 commits into
mainfrom
taren/d3-dependency-boundaries

Conversation

@tannerlinsley

@tannerlinsley tannerlinsley commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

  • replace incidental d3-array use in nearest-point lookup and quantile legends with package-owned implementations
  • remove the production D3 dependency from compact scales with independently structured tick helpers and D3 parity coverage
  • retain D3 as an internal, tree-shakable dependency for bin, stack, polar, curve, and geo features without peers or caller-supplied capabilities
  • preserve root, universal, and exact-subpath D3 curve exports
  • add retained-input gates, reviewed bundle baselines, documentation, and a Changesets release note

Validation

  • pnpm validate
  • pnpm changeset status

Summary by CodeRabbit

  • New Features

    • Added local tick-generation utilities for linear scales, supporting edge cases, reversed ranges, and fractional intervals.
    • Improved compact numeric tick generation without changing scale APIs.
    • Added export coverage for D3 curve helpers and their supported subpaths.
  • Bug Fixes

    • Improved nearest-point selection and quantile threshold calculations.
  • Documentation

    • Clarified D3 feature support, dependency behavior, and tree-shaking guidance.
  • Tests

    • Added comprehensive validation for tick generation and exported curve helpers.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@tannerlinsley, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 89990933-b1a2-44eb-ba5f-46809b8554e1

📥 Commits

Reviewing files that changed from the base of the PR and between 86ff203 and 81498fa.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (19)
  • .changeset/explicit-d3-capabilities.md
  • API-FRICTION.md
  • benchmarks/bundle-size/universal-baseline.json
  • benchmarks/comparison/bundle-baseline.json
  • docs/comparison.md
  • docs/concepts/scales-and-d3.md
  • docs/installation.md
  • packages/charts-core/docs/comparison.md
  • packages/charts-core/docs/concepts/scales-and-d3.md
  • packages/charts-core/docs/installation.md
  • packages/charts-core/src/exports.test.ts
  • packages/charts-core/src/legend.ts
  • packages/charts-core/src/nearest.ts
  • packages/charts-scales/package.json
  • packages/charts-scales/src/linear.ts
  • packages/charts-scales/src/ticks.test.ts
  • packages/charts-scales/src/ticks.ts
  • scripts/check-packed-consumers.mjs
  • scripts/measure-bundles.mjs
📝 Walkthrough

Walkthrough

The change replaces selected incidental d3-array utilities with local implementations. It retains D3-backed features, verifies curve exports, updates documentation and release records, and broadens bundle boundary checks.

Changes

D3 capability ownership

Layer / File(s) Summary
Local utility implementations
packages/charts-core/src/nearest.ts, packages/charts-core/src/legend.ts, packages/charts-scales/src/ticks.ts, packages/charts-scales/src/linear.ts, packages/charts-scales/src/ticks.test.ts, packages/charts-scales/package.json
Nearest-point and quantile calculations use local logic. Compact tick helpers implement D3-compatible behavior and tests compare fixed and randomized inputs. d3-array is removed from runtime dependencies in @tanstack/charts-scales.
Retained D3 contracts and documentation
packages/charts-core/src/exports.test.ts, docs/..., packages/charts-core/docs/..., API-FRICTION.md, .changeset/explicit-d3-capabilities.md
Curve export coverage, D3 ownership documentation, API-friction records, and patch release notes describe retained D3 features and local utility replacements.
Bundle boundary verification
scripts/measure-bundles.mjs, scripts/check-packed-consumers.mjs, benchmarks/bundle-size/universal-baseline.json
Bundle policies distinguish D3 geometry from general D3 runtime inputs. Core, React, scale, tooltip, and compact consumer checks use the updated restrictions and baselines.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the PR's primary change: removing incidental D3 runtime usage.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch taren/d3-dependency-boundaries

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 172a25b and 86ff203.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (16)
  • .changeset/explicit-d3-capabilities.md
  • API-FRICTION.md
  • benchmarks/bundle-size/universal-baseline.json
  • docs/concepts/scales-and-d3.md
  • docs/installation.md
  • packages/charts-core/docs/concepts/scales-and-d3.md
  • packages/charts-core/docs/installation.md
  • packages/charts-core/src/exports.test.ts
  • packages/charts-core/src/legend.ts
  • packages/charts-core/src/nearest.ts
  • packages/charts-scales/package.json
  • packages/charts-scales/src/linear.ts
  • packages/charts-scales/src/ticks.test.ts
  • packages/charts-scales/src/ticks.ts
  • scripts/check-packed-consumers.mjs
  • scripts/measure-bundles.mjs

Comment on lines +13 to +25
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Suggested change
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.

@tannerlinsley
tannerlinsley force-pushed the taren/d3-dependency-boundaries branch from 86ff203 to c422a2c Compare July 31, 2026 21:50
@tannerlinsley
tannerlinsley merged commit 3455403 into main Jul 31, 2026
17 checks passed
@tannerlinsley
tannerlinsley deleted the taren/d3-dependency-boundaries branch July 31, 2026 21:55
@github-actions github-actions Bot mentioned this pull request Jul 31, 2026
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.

1 participant