Skip to content

fix: SW-1890 Fix PieChart legend rendering unstyled#145

Open
owilliams-tetrascience wants to merge 2 commits into
mainfrom
claude/pedantic-germain-e5502a
Open

fix: SW-1890 Fix PieChart legend rendering unstyled#145
owilliams-tetrascience wants to merge 2 commits into
mainfrom
claude/pedantic-germain-e5502a

Conversation

@owilliams-tetrascience

@owilliams-tetrascience owilliams-tetrascience commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

PieChart rendered its legend and wrapper using global, unscoped class names (legend-container, legend-item, color-box, divider, card-container, chart-container, title-container) whose only CSS rules live in Histogram/Histogram.scss — which PieChart never imports. Any consumer using PieChart without also pulling in Histogram got invisible color swatches and an unstyled, layout-less legend (a wall of plain text).

This implements Option B from SW-1890 (the recommended fix): migrate off the orphaned global classes onto Tailwind utilities — the library's standard pattern — so PieChart ships its own styling and no longer depends on global CSS or namespace-prone class names.

Changes

  • PieChart.tsx — legend container/rows/items, color swatches (size-3 rounded-[4px]), divider (bg-border), title and wrapper all use Tailwind classes. Added text-foreground for dark-mode legibility, and stable data-slot="pie-legend" / data-slot="pie-legend-swatch" hooks for testing (instead of relying on style-bearing class names).
  • LineGraph.tsx / ScatterGraph.tsx — fixed the same orphaned chart-container class flagged in the ticket's audit item (replaced chart-container relativerelative size-full).
  • PieChart.stories.tsx — updated legend selectors to the data-slot hook and added a play-function step asserting the color swatches have non-zero rendered size (acceptance criterion).

Audit note

Chromatogram / ChromatogramChart also reference chart-container, but only on a "No data available" text fallback and a Plotly native legend (no custom HTML swatches) — no broken-swatch bug there, so they were left untouched.

Upstream library change: downstream consumers (ts-service-web, data apps) pick this up after a publish + version bump. fix: → semantic-release patch.

Type of Change

  • Bug fix

Checklist

  • yarn lint passes
  • yarn build passes
  • yarn test:all passes (548 unit + 653 storybook)
  • Storybook stories added/updated
  • Code coverage remains the same or increased

Testing

New swatch-size assertion added to the PieChart "Default" story play function. Existing PieChart Zephyr cases: SW-T1012–SW-T1016.

Verification

  • Deploys to preview environment for manual verification
  • All CI/E2E checks pass

Screenshots

Acceptance: importing PieChart standalone in a fresh app now produces a legend with visible colored swatches and proper layout in both light and dark mode.

🤖 Generated with Claude Code

PieChart rendered its legend and wrapper using global, unscoped class
names (legend-container, legend-item, color-box, divider, card-container,
chart-container, title-container) whose only CSS rules live in
Histogram/Histogram.scss — which PieChart never imports. Consumers using
PieChart standalone got invisible color swatches and an unstyled,
layout-less legend.

Migrate PieChart off the orphaned global classes onto Tailwind utilities
(the library's standard pattern), so it ships its own styling and no
longer depends on global CSS or namespace-prone class names. Add
text-foreground for dark-mode legibility and stable data-slot hooks for
testability.

Also fix the same orphaned chart-container class on LineGraph and
ScatterGraph (replaced with relative size-full).

Add a play-function test asserting the legend color swatches have
non-zero rendered size.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 23, 2026 19:45
@owilliams-tetrascience owilliams-tetrascience requested review from a team as code owners June 23, 2026 19:45
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ts-lib-ui-kit-storybook Ready Ready Preview, Comment Jun 23, 2026 7:56pm

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes PieChart legend rendering by removing reliance on orphaned, global CSS class names (defined only in Histogram.scss) and replacing them with Tailwind utility classes, ensuring the legend is styled correctly when PieChart is consumed standalone.

Changes:

  • Migrated PieChart wrapper/title/legend markup from global class names to Tailwind utilities and added stable data-slot hooks for testing.
  • Removed the orphaned chart-container class usage from LineGraph and ScatterGraph wrappers.
  • Updated PieChart Storybook play function selectors to use data-slot and added a rendered-size assertion for legend swatches.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/components/charts/PieChart/PieChart.tsx Replaces unscoped legend/container classes with Tailwind utilities and adds data-slot hooks to make PieChart styling self-contained.
src/components/charts/PieChart/PieChart.stories.tsx Updates legend selectors to data-slot and adds a play assertion that swatches render with non-zero size.
src/components/charts/LineGraph/LineGraph.tsx Removes orphaned chart-container class usage in the wrapper, switching to Tailwind sizing utilities.
src/components/charts/ScatterGraph/ScatterGraph.tsx Removes orphaned chart-container class usage in the wrapper, switching to Tailwind sizing utilities.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/charts/PieChart/PieChart.tsx Outdated
@owilliams-tetrascience owilliams-tetrascience changed the title SW-1890 Fix PieChart legend rendering unstyled fix: SW-1890 Fix PieChart legend rendering unstyled Jun 23, 2026
Use `${label}-${i}` for the legend item key so repeated labels don't
collide, per review feedback.

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

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 94.75% (🎯 83%)
⬆️ +0.01%
20637 / 21780
🟢 Statements 94.75% (🎯 83%)
⬆️ +0.01%
20637 / 21780
🟢 Functions 93.58% (🎯 74%)
🟰 ±0%
919 / 982
🟢 Branches 88.74% (🎯 81%)
🟰 ±0%
3770 / 4248
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/components/charts/LineGraph/LineGraph.tsx 96.83%
🟰 ±0%
82.75%
🟰 ±0%
100%
🟰 ±0%
96.83%
🟰 ±0%
311-317
src/components/charts/PieChart/PieChart.tsx 100%
🟰 ±0%
76.47%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/components/charts/ScatterGraph/ScatterGraph.tsx 100%
🟰 ±0%
84.61%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
Generated in workflow #811 for commit 97b4fd5 by the Vitest Coverage Report Action

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.

3 participants