Skip to content

[Bug Fix] Chart: fix theme colors and default to --chart-1..5 - #582

Merged
cirdes merged 4 commits into
mainfrom
fix/chart-controller-theme-colors
Oct 30, 2026
Merged

cirdes merged 4 commits into
mainfrom
fix/chart-controller-theme-colors

Conversation

@cirdes

@cirdes cirdes commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

The Chart controller was drawing every chart in black. getThemeColor split each CSS token on spaces and wrapped it in hsl(), which worked when the tokens were HSL triples. The theme now uses oklch(...), so the controller produced strings like hsl(oklch(20.5%, 0, 0)). The canvas rejects those, and Chart.js fell back to black for bars, grid lines, ticks and tooltips. In dark mode the bar and line charts were close to invisible. Found while working on #581.

Changes

  • getThemeColor returns the token value unchanged. The canvas accepts oklch() in current Chrome, Safari (16.4+) and Firefox (113+).
  • The legend borderRadius was also read through getThemeColor('radius') and came out as hsl(.625rem, undefined, undefined). It is now a fixed 2px, matching the rounded-[2px] legend indicator in shadcn's Base UI chart.
  • Datasets now default to --chart-1 through --chart-5 in order, as in shadcn's chart examples. Pie, doughnut and polar area charts color each slice instead. Before this, every dataset got a --background fill with a --primary border, so all series looked alike. Colors set on a dataset still take precedence, as the pie example on the docs page shows.
  • Docs: a short note on the default colors and a "Multiple datasets" bar example, in both docs/app/views/docs/chart.rb and gem/lib/ruby_ui/chart/chart_docs.rb.

With the neutral --chart-N values from #581, the default series come out in grays, as in shadcn's neutral theme.

Screenshots

Before After
Light
before-light-charts
after-light-charts

| Dark | before-dark-charts

| final-dark-charts|

Testing

  1. cd docs && bin/dev, open /docs/chart.
  2. In light and dark mode, check that bars, lines, grid lines and ticks use theme colors, and that the "Multiple datasets" example shows two distinct colors.
  3. Toggle the theme while on the page. The charts re-render with the new mode's colors.
  4. cd gem && bundle exec rake; cd docs && bin/rails db:test:prepare test && bundle exec standardrb.

🤖 Generated with Claude Code


Summary by cubic

Fixes charts rendering entirely in black and making every series look alike. The chart controller wrapped the theme's oklch() tokens in hsl(), which the canvas rejects, and gave every dataset the same background fill with a primary border.

  • Theme tokens are now passed through unchanged; the legend borderRadius is a fixed 2px instead of reading --radius through the same path.
  • Datasets cycle through --chart-1 to --chart-5 in order, while pie, doughnut, and polar area charts color each slice instead. Explicit dataset colors still take precedence.
  • Pie slice colors work with both array and keyed object data.
  • Rebuilt the MCP registry to include the updated controller and a new "Multiple datasets" docs example.

Written for commit ced33e4. Summary will update on new commits.

View guided diff Turn on auto-fix

cirdes and others added 2 commits October 29, 2026 13:48
getThemeColor split each token on spaces and wrapped it in hsl(), which
dates from when the tokens were HSL triples. The theme now uses
oklch(...), so it produced strings like hsl(oklch(20.5%, 0, 0)). The
canvas rejects them and Chart.js drew everything in black, which made
bar and line charts nearly invisible in dark mode.

Pass the token value through as-is. The legend borderRadius also read
--radius through getThemeColor; use a fixed 2px instead, matching the
rounded-[2px] legend indicator in shadcn's chart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Datasets defaulted to a background fill with a primary border, so every
series looked the same. Color dataset i with --chart-(i % 5 + 1), as
shadcn's chart examples do; pie, doughnut and polar area charts color
each slice instead. Colors set on a dataset still win.

Docs: explain the default and add a multiple datasets example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cirdes cirdes self-assigned this Oct 29, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

cirdes and others added 2 commits October 29, 2026 13:53
Chart.js accepts keyed object data ({ a: 10, b: 20 }); calling .map on
it threw while building the default slice colors. Use Object.values so
array and object data both get one color per value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks up the updated chart controller and the new "Multiple datasets"
docs example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread mcp/data/registry.json Resolved
@cirdes
cirdes merged commit 8581221 into main Oct 30, 2026
10 checks passed
@cirdes
cirdes deleted the fix/chart-controller-theme-colors branch October 30, 2026 11:29
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