Skip to content
Source
Sign inSign up
TanStack/charts

perf(interaction): look up axis values by key and binary search #171

Closedandersk(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/171/headopened

Scale-bound interactions with explicit values scanned every value on each pointer event: indexOf searched the array of value keys, and valueAt measured the distance to every position. A brushX over 120,000 hourly values spent about 12 ms per mouse move in these scans, enough to make dragging stutter.

Record each value's index in the map that already checks values for uniqueness, and find the nearest position by binary search, which assertMonotonePositions already makes valid. Ties still resolve to the lower index, as with the linear search.

Summary by CodeRabbit

  • Performance
    • Improved pointer snapping and value lookups for charts with many explicitly defined values, including brush, zoom, handle, and cursor interactions.
    • Preserved consistent snapping behavior for forward and reversed axes, including when a pointer falls equally between two values.
    1. 🦋 Changeset detected

      Latest commit: d73c50c013294c1b08fa34943bd05cc1f9f96d37

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 12 packages
      NameType
      @tanstack/chartsPatch
      @tanstack/alpine-chartsPatch
      @tanstack/angular-chartsPatch
      @tanstack/lit-chartsPatch
      @tanstack/octane-chartsPatch
      @tanstack/preact-chartsPatch
      @tanstack/react-chartsPatch
      @tanstack/react-native-chartsPatch
      @tanstack/solid-chartsPatch
      @tanstack/svelte-chartsPatch
      @tanstack/vue-chartsPatch
      @tanstack/charts-scalesPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 0b32c5e7-540b-4d76-8996-b62e984935d1
      📥 Commits

      Reviewing files that changed from the base of the PR and between e6a51a836e0bf9ea5288822a4247a995f43a768c and d73c50c013294c1b08fa34943bd05cc1f9f96d37.

      📒 Files selected for processing (3)
      • .changeset/interaction-axis-lookups.md
      • packages/charts-core/src/interaction-axis-internal.test.ts
      • packages/charts-core/src/interaction-axis-internal.ts

      Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


      📝 Walkthrough

      Walkthrough

      The interaction axis now maps explicit values to indexes and uses binary search to select the nearest mapped position. Tests cover forward and reversed mappings, ties, and present or absent values.

      Changes

      Interaction axis lookups

      Layer / File(s)Summary
      Explicit-value index
      packages/charts-core/src/interaction-axis-internal.ts
      The axis builds a key-to-index map while validating explicit values. indexOf uses the map and returns -1 for absent values.
      Nearest-position search
      packages/charts-core/src/interaction-axis-internal.ts, packages/charts-core/src/interaction-axis-internal.test.ts, .changeset/interaction-axis-lookups.md
      Explicit-value snapping uses binary search for ascending and descending positions. Tests cover nearest-value selection, endpoint clamping, ties, and indexOf. The changeset records a patch for @tanstack/charts.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~15 minutes

      Change: Refactor

      Merge Risk: ⚪ Minimal · up to d73c5

      No issue requiring a fix before merge is identified for the interaction-axis lookup change.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1…Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title clearly summarizes the main change: faster interaction-axis lookups by key and binary search.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      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.
    3. Thanks @andersk, the keyed lookup and binary-search work is included in #184 and released in 1.1.0, with coverage for reversed axes, ties, Dates, missing values, and singleton candidates. Closing this PR as incorporated into the release batch.

    4. tannerlinsley closed this

Sign in to join this conversation.