Skip to content

fix(charts): readable labels on colored fills (treemap/sunburst/circle-packing) - #1095

Merged
alfredo1996 merged 4 commits into
release/1.1from
design/chart-label-readability
Jun 19, 2026
Merged

fix(charts): readable labels on colored fills (treemap/sunburst/circle-packing)#1095
alfredo1996 merged 4 commits into
release/1.1from
design/chart-label-readability

Conversation

@alfredo1996

@alfredo1996 alfredo1996 commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes chart label readability on colored fills. Labels drawn on cells/segments/circles used three different strategies (color: "inherit" on treemap/sunburst, hardcoded white on circle-packing). On the light-tinted cells the palette generates, white-only labels washed out — worst in dark mode.

Approach (revised after review)

A first pass used a hard text outline, but a stroke haloes every glyph and muddies the text on the saturated cells where plain white was already crisp. The refined treatment:

  • treemap / sunburst — white text + a soft blurred drop-shadow (not a hard outline): invisible on saturated/dark cells, a gentle lift on pale cells.
  • circle-packingper-cell contrast (contrastTextColor): black text on the light moss/mint leaves, white on the dark blue parents — maximally readable, zero halo.

Before / after (old → hard-outline → final)

Treemap
treemap 3-way

Circle-packing
circle-packing 3-way

Tests

  • treemap/sunburst assert the white + soft-shadow treatment; circle-packing asserts per-cell contrast (white on dark, black on light). tsc clean · chart suite passes.

Follow-ups (flagged, not here)

  • circle-packing uses an off-brand blue/green DEPTH_COLORS palette (not citrine) — separate vibrancy fix.
  • circle-packing parent labels overlap children (layout).

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced chart label rendering with improved color contrast and consistent soft text shadows.
  • Bug Fixes

    • Fixed “no data” title text colors to correctly match both light and dark themes.
    • Updated circle packing, sunburst, and treemap labels to use fill-based contrast styling for better readability.
  • Tests

    • Added/expanded coverage for label contrast behavior across light/dark scenarios.

…e-packing)

Labels rendered directly on colored chart fills used inconsistent strategies
(treemap/sunburst color:"inherit", circle-packing hardcoded white with no
outline). On the light-tinted cells the palette generates (light-lavender /
light-cyan children), white-only labels washed out — unreadable, especially
in dark mode.

Unifies on a single treatment in chart-utils — FILL_LABEL_COLOR (white) +
FILL_LABEL_OUTLINE / _WIDTH (subtle dark outline) — applied to treemap,
sunburst and circle-packing labels. Reads on light- and dark-tinted fills
alike, in both themes. Also aligns the chart empty-state color to the exact
theme --muted-foreground hex.

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

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e48995a8-1992-43d2-9a03-c28974cd79df

📥 Commits

Reviewing files that changed from the base of the PR and between 39d228e and b86ba7a.

⛔ Files ignored due to path filters (2)
  • claude_code_docs/component-review/img/comp3-circlepack.png is excluded by !**/*.png
  • claude_code_docs/component-review/img/comp3-treemap.png is excluded by !**/*.png
📒 Files selected for processing (7)
  • component/src/charts/__tests__/circle-packing-chart.test.tsx
  • component/src/charts/__tests__/sunburst-chart.test.tsx
  • component/src/charts/__tests__/treemap-chart.test.tsx
  • component/src/charts/chart-utils.ts
  • component/src/charts/circle-packing-chart.tsx
  • component/src/charts/sunburst-chart.tsx
  • component/src/charts/treemap-chart.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • component/src/charts/sunburst-chart.tsx

Walkthrough

Introduces three exported label-styling constants (FILL_LABEL_COLOR, FILL_LABEL_SHADOW, FILL_LABEL_SHADOW_BLUR) and a fillLabelStyle object in chart-utils.ts, then applies them to circle-packing (via dynamic contrast coloring), sunburst (via series and level labels), and treemap (via label and upperLabel) charts. Updates resolveEmptyDataColor() fallback hex values for theme-aware dark/light mode. Adds comprehensive test coverage for all styling changes and theme behavior.

Changes

Chart Label Styling Constants and Implementation

Layer / File(s) Summary
Fill-label styling constants and empty-data color fallbacks
component/src/charts/chart-utils.ts
Introduces exported FILL_LABEL_COLOR (#ffffff), FILL_LABEL_SHADOW (rgba(0, 0, 0, 0.55)), and FILL_LABEL_SHADOW_BLUR (4), plus fillLabelStyle object combining them. Updates resolveEmptyDataColor() to return theme-matched muted-foreground hex values (#959ba7 dark, #666d7a light).
Circle-packing dynamic contrast-based label coloring
component/src/charts/circle-packing-chart.tsx
Expands imports to include contrastTextColor. Updates leaf node labels to derive fill color dynamically from each circle's computed fill using contrastTextColor() instead of hardcoded white, with documentation of per-circle contrast intent.
Sunburst and treemap shared fill-label styling
component/src/charts/sunburst-chart.tsx, component/src/charts/treemap-chart.tsx
Sunburst applies fillLabelStyle to series and emphasis labels, and uses explicit FILL_LABEL_COLOR with conditional text-shadow for per-level labels based on visibility. Treemap spreads fillLabelStyle into both label and upperLabel, replacing prior inherit behavior.
Tests for empty-data colors and chart label styling
component/src/charts/__tests__/empty-data-option.test.ts, component/src/charts/__tests__/circle-packing-chart.test.tsx, component/src/charts/__tests__/sunburst-chart.test.tsx, component/src/charts/__tests__/treemap-chart.test.tsx
Adds buildEmptyDataOption suite for light/dark color validation. Adds circle-packing leaf text contrast tests. Adds sunburst series label, emphasis, and maxLabelDepth shadow tests. Adds treemap label color and shadow assertions. Reformats existing styling-rule array literals in sunburst and treemap tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • alfredo1996/neoboard#468: Modifies sunburst-chart.tsx label rendering (sizing, truncation, minAngle), directly overlapping with this PR's label styling changes in the same file.
  • alfredo1996/neoboard#870: Consolidates and adds contrastTextColor in component/src/charts/chart-utils.ts, which this PR now applies to circle-packing label contrast logic.
  • alfredo1996/neoboard#942: Removes color: "inherit" from sunburst-chart.tsx and treemap-chart.tsx label configuration, the same fields this PR replaces with shared shadow-based constants.

Suggested labels

bug

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 accurately summarizes the main change: fixing label readability on colored fills in treemap, sunburst, and circle-packing charts through improved contrast treatment.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch design/chart-label-readability

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 and usage tips.

alfredorubin96 and others added 2 commits June 19, 2026 18:55
Invokes the custom renderItem so the leaf-label text element (white fill +
dark outline) executes, lifting new-code coverage above the 80% gate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
SonarCloud new_coverage counts condition coverage. Adds tests for the
previously-uncovered branches: sunburst series/emphasis label treatment and
the withinDepth=false (transparent) level label, plus buildEmptyDataOption's
dark-mode branch. Lifts new-code coverage above the 80% gate.

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

@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 `@component/src/charts/__tests__/circle-packing-chart.test.tsx`:
- Line 92: Remove the duplicate const api declaration in the test file. There
are two declarations of the api variable in the same scope, which causes a
compile-time error. Keep only one declaration of the api object that contains
the value and style methods, and delete the redundant duplicate declaration of
api.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5376690f-b427-445d-9cd4-c2a490303107

📥 Commits

Reviewing files that changed from the base of the PR and between 155dd02 and 39d228e.

⛔ Files ignored due to path filters (2)
  • claude_code_docs/component-review/img/comp-circlepack.png is excluded by !**/*.png
  • claude_code_docs/component-review/img/comp-treemap.png is excluded by !**/*.png
📒 Files selected for processing (8)
  • component/src/charts/__tests__/circle-packing-chart.test.tsx
  • component/src/charts/__tests__/empty-data-option.test.ts
  • component/src/charts/__tests__/sunburst-chart.test.tsx
  • component/src/charts/__tests__/treemap-chart.test.tsx
  • component/src/charts/chart-utils.ts
  • component/src/charts/circle-packing-chart.tsx
  • component/src/charts/sunburst-chart.tsx
  • component/src/charts/treemap-chart.tsx

Comment thread component/src/charts/__tests__/circle-packing-chart.test.tsx
Replaces the hard text outline (which haloed glyphs and muddied labels on
saturated cells) with a cleaner treatment:
- treemap / sunburst: white text + a soft blurred drop-shadow — crisp on
  saturated cells, still readable on the pale child cells the palette makes.
- circle-packing: per-cell contrast (contrastTextColor) — black text on the
  light moss/mint leaves, white on the dark blue parents — no halo.

Tests updated to assert the shadow/contrast treatment. tsc clean; chart
suite passes.

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

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:a11y Accessibility area:charts Chart rendering area:design Visual design, tokens, typography pkg:component UI component library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants