Skip to content
Source
Sign inSign up
TanStack/charts

fix: align diagonal Canvas gradients on non-square charts #258

Mergedtannerlinsleymerged 2 commits intomain fromtaren/gradient-current-0212merged by tannerlinsley

tannerlinsleycommented

Canvas diagonal gradients shift color stops when the chart geometry has unequal width and height. Project the gradient normal through the chart transform so the stops line up with the intended direction. The regression tests cover the non-square case along with very large and very small dimensions.

The focused Canvas suite and package checks pass. The two affected bundles are 40.399 and 46.845 kB gzip, within the approved ceilings of 40.399 and 46.846 kB. This addresses the Canvas gradient part of #191.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected linear-gradient projections for non-square Canvas areas, improving alignment between Canvas gradients and SVG rendering.
  • Documentation

    • Updated chart comparison results to reflect the measured workspace revision.
  • Chores

    • Adjusted bundle size budgets to match current measurements.
    1. 🦋 Changeset detected

      Latest commit: 6d13e89be5eaf8448d2a1553ab22ae8ac718e243

      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
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Canvas linear-gradient endpoint calculation now adjusts the gradient normal for non-square bounds when dimensions and endpoint deltas are nonzero. Tests check unit-space projection across multiple dimensions and directions. The changeset, benchmark metadata, comparison revision notes, and two bundle budgets are also updated.

      Changes: Canvas Linear-Gradient Projection

      Layer / File(s)Summary
      Gradient projection calculation
      packages/charts-core/src/canvas.ts, packages/charts-core/src/canvas.test.ts, .changeset/canvas-linear-gradient-projection.md
      The Canvas gradient endpoint vector is recalculated for non-square bounds when the dimensions and endpoint deltas are nonzero. Tests check the projection for varied dimensions and directions. A patch changeset records the update.
      Benchmark and comparison records
      benchmarks/comparison/bundle-baseline.json, benchmarks/conformance/previews/manifest.json, docs/comparison.md, packages/charts-core/docs/comparison.md, scripts/measure-bundles.mjs
      The benchmark source revision and digest, preview source hash, and comparison revision notes are updated. Two bundle budgets increase.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Possibly related issues

      • TanStack/charts issue 191 — The PR addresses its Canvas gradient geometry topic. Its stop-tweening and SVG gradient-units topics remain unaddressed.

      Suggested reviewers: greglum

      Merge Risk: Minimal · up to 6d13e

      Non-square Canvas gradients are corrected, with no actionable merge-blocking issue identified.

      Pre-merge checks: Passed 4 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…Write docstrings for the functions missing them to satisfy the coverage threshold.
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Description CheckPassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title checkPassedThe title clearly and concisely describes the main change: fixing diagonal Canvas gradient alignment on non-square charts.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files. (5 skipped: 5 unsupported.)

      Resolution

      Write docstrings for the functions missing them to satisfy the coverage threshold.

      Finishing Touches
      Generate docstrings
      • Commit to this branch
      • Create a new PR
      Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · 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
      Recent review info
      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 807905d7-0d00-4b3e-a27f-e2f0e450cc79
      Commits

      Reviewing files that changed from the base of the PR and between b62bb678bcce4b92ff8741a75b48349a4ef01987 and 6d13e89be5eaf8448d2a1553ab22ae8ac718e243.

      Files selected for processing: 8
      • .changeset/canvas-linear-gradient-projection.md
      • benchmarks/comparison/bundle-baseline.json
      • benchmarks/conformance/previews/manifest.json
      • docs/comparison.md
      • packages/charts-core/docs/comparison.md
      • packages/charts-core/src/canvas.test.ts
      • packages/charts-core/src/canvas.ts
      • scripts/measure-bundles.mjs

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

    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 6d13e89be5eaf8448d2a1553ab22ae8ac718e243

      CommandStatusDurationResult
      nx run charts-workspace:ci-distributed✅ Succeeded6m 45sView ↗
      nx run charts-workspace:package-check✅ Succeeded1m 43sView ↗
      nx run charts-workspace:benchmark-check✅ Succeeded46sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-11-04 19:51:55 UTC

    4. tannerlinsley merged this3b8922a

    5. tannerlinsley closed this

Sign in to join this conversation.