Skip to content

fix(charts): one gridline treatment for cartesian axes, keep category labels when compact (#1247) - #1271

Merged
alfredo1996 merged 2 commits into
release/1.4from
fix/issue-1247-chart-grid-axis
Jul 27, 2026
Merged

fix(charts): one gridline treatment for cartesian axes, keep category labels when compact (#1247)#1271
alfredo1996 merged 2 commits into
release/1.4from
fix/issue-1247-chart-grid-axis

Conversation

@alfredo1996

@alfredo1996 alfredo1996 commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Closes #1247

What was actually wrong

The issue reported "bar draws heavy gridlines, line's are almost invisible". Reading the code, bar and line both already inherit the theme's splitLine — the drift was elsewhere:

  • timeAxis was never registered in either theme. The themes define categoryAxis and valueAxis only, so the gantt (type: "time") and any date-based line chart fell back to ECharts' un-themed light grey — near-white on the dark canvas. This is the real "different tools on one dashboard" cause.
  • The gantt also carried a local dashed / opacity 0.3 override, the one genuine per-chart gridline style in the package.
  • buildCategoryAxisLabel returned show: !compact — under 300px the bar widget dropped category identification entirely. That is the four unlabelled bars in appshell-light.png.

Changes

  • GRID_LINE_COLOR token in charts/theme.ts, used by both themes; timeAxis registered alongside categoryAxis/valueAxis.
  • Gantt sets only splitLine: { show }.
  • Compact keeps category labels. The existing sub-400px rule already truncates to 10 chars, so no new budget was needed — which left the compact option dead, and it is removed. A tighter 6-char budget was tried first and collapsed Widget A..Widget G into seven identical Widge… stubs.
  • Line chart's x-axis labels survive compact too (ECharts thins overlapping ones itself).
  • Design-review skill §4 now documents the gridline token and the compact axis policy, plus two anti-patterns — the doc's silence is what let the drift happen.

Tests

component/src/charts/__tests__/cartesian-axis-defaults.test.tsx (new) pins the option shape across bar, line and gantt:

  • no chart declares its own splitLine.lineStyle
  • both themes resolve one gridline colour for category, value and time axes
  • compact keeps category labels and still drops the value numbers

axis-label-utils.test.ts gains a common-prefix case so an over-tight truncation budget fails loudly.

Verification

  • npm run verify — 248 + 116 + 28 files, all green
  • Playwright: 328 passed. 21 first-run failures were all AuthPage.login: failed to reach / (login contention, no chart assertion among them); 19 passed on re-run, the remaining 2 pass in isolation (14/14)
  • Storybook, both themes: appshell, bar, gantt, and a 280px bar widget

Known, out of scope

The gantt's dataZoom slider renders in ECharts' default lavender-blue in both themes. Not filed.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Improved compact chart behavior: category labels remain visible with truncation when space is limited, while value-axis numbers are hidden.
  • Bug Fixes
    • Prevented compact modes from hiding category-axis tick labels.
    • Standardized cartesian gridline styling by relying on registered themes (no local split-line styling).
  • Tests
    • Added coverage for compact/container label rendering and cross-chart axis/gridline defaults.
  • Documentation
    • Updated chart design guidance for compact behavior and gridline anti-patterns.

… labels when compact (#1247)

Two defects made charts on one dashboard look like they came from
different tools.

Gridlines: bar and line already inherit the theme's splitLine, so the
drift was narrower than reported — neither theme registers a `timeAxis`
entry, so the gantt and any date-based line chart fell back to ECharts'
un-themed light grey, which reads near-white on the dark canvas. Both
themes now register timeAxis, the colour is the GRID_LINE_COLOR token,
and the gantt's local `dashed / opacity 0.3` override is gone.

Axis labels: buildCategoryAxisLabel returned `show: !compact`, so under
300px the bar widget dropped category identification entirely — four
unlabelled bars. Compact now keeps the labels; the existing sub-400px
rule already truncates them to 10 chars, which also leaves the `compact`
option dead, so it goes. (A tighter 6-char budget was tried first and
collapsed "Widget A".."Widget G" into seven identical stubs.)

cartesian-axis-defaults.test.tsx pins the option shape across bar, line
and gantt so a future chart re-adding its own splitLine.lineStyle, or
hiding category labels at a breakpoint, fails loudly.

Verified in Storybook, both themes: appshell, bar, gantt, and a 280px
bar widget.

Closes #1247

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@alfredo1996 alfredo1996 added pkg:component UI component library area:charts Chart rendering area:design Visual design, tokens, typography priority:P2 Should-fix polish type: fix labels Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 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 Plus

Run ID: 0ad6234d-0684-4c8c-90f0-2eccf07dba44

📥 Commits

Reviewing files that changed from the base of the PR and between ee21a06 and d689edb.

📒 Files selected for processing (2)
  • component/src/charts/__tests__/cartesian-axis-defaults.test.tsx
  • component/src/charts/line-chart.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • component/src/charts/line-chart.tsx
  • component/src/charts/tests/cartesian-axis-defaults.test.tsx

Walkthrough

Cartesian charts preserve category labels in compact containers, centralize gridline styling in light and dark themes, apply shared styling to time axes, and add tests for emitted ECharts options across chart types.

Changes

Cartesian chart defaults

Layer / File(s) Summary
Compact category-axis labels
component/src/charts/chart-utils.ts, component/src/charts/bar-chart.tsx, component/src/charts/line-chart.tsx, component/src/charts/__tests__/*, .claude/skills/design-review/skill.md
Category labels remain visible and truncate in narrow containers; compact mode hides value-axis numbers, with updated bar and line chart configuration and tests.
Theme-owned gridline styling
component/src/charts/theme.ts, component/src/charts/gantt-chart.tsx, component/src/charts/__tests__/cartesian-axis-defaults.test.tsx, .claude/skills/design-review/skill.md
Light and dark themes provide shared gridline colors, time axes use the corresponding axis style, and chart modules configure only splitLine.show.

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

Possibly related issues

  • #1273: Related theme-centralization changes also affect gantt-chart.tsx and charts/theme.ts, but target dataZoom styling rather than gridlines.

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 clearly summarizes the shared cartesian gridline update and compact label fix.
Linked Issues check ✅ Passed The changes implement shared theme-aware gridlines, compact label retention, and option-shape tests across bar, line, and gantt charts.
Out of Scope Changes check ✅ Passed I didn't see unrelated code changes; the docs, tests, theme, and chart updates all support the stated chart-defaults fix.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-1247-chart-grid-axis

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.

@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/line-chart.tsx`:
- Around line 254-256: Update the compact category-axis configuration in the
line chart to use the shared buildCategoryAxisLabel helper with the xValues
length and container width, while retaining { show: true } for time axes. Add
width to the relevant memo dependency list so truncation responds to resizing,
and extend cartesian-axis-defaults.test.tsx to assert compact line-label
truncation.
🪄 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 Plus

Run ID: 840cd18a-21f4-4f20-bd77-5316d48cf8fb

📥 Commits

Reviewing files that changed from the base of the PR and between 6cafc74 and ee21a06.

📒 Files selected for processing (8)
  • .claude/skills/design-review/skill.md
  • component/src/charts/__tests__/axis-label-utils.test.ts
  • component/src/charts/__tests__/cartesian-axis-defaults.test.tsx
  • component/src/charts/bar-chart.tsx
  • component/src/charts/chart-utils.ts
  • component/src/charts/gantt-chart.tsx
  • component/src/charts/line-chart.tsx
  • component/src/charts/theme.ts
💤 Files with no reviewable changes (1)
  • component/src/charts/bar-chart.tsx

Comment thread component/src/charts/line-chart.tsx Outdated
…label config

CodeRabbit on #1271: the line chart kept labels visible in compact mode but
never truncated them, so a narrow widget with long category names rendered
overlapping text where the bar chart truncated cleanly — the cross-chart
inconsistency #1247 exists to remove.

Only the category branch takes buildCategoryAxisLabel. A time axis keeps
plain labels: ECharts formats and thins dates itself, and the width-based
rotation heuristic is meaningless for them. That distinction is what made
this safe to apply — the original objection was that routing every x axis
through the helper would add rotation to dense time series.

Built as two object literals rather than one with ternaries, because
ECharts discriminates the axis union on `type` and a "time" | "category"
union defeats narrowing.

`width` joins the memo deps so truncation responds to resize.

Refs #1247

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

Copy link
Copy Markdown
Owner Author

Applied — good catch, and the distinction you drew is what made it safe.

My original reason for not routing the line chart through buildCategoryAxisLabel was that it would apply the width-based rotation heuristic to dense time series, where it is meaningless. Splitting on useTimeAxis avoids that entirely: the category branch gets the shared config so long labels truncate exactly as they do on the bar chart, and the time branch keeps plain labels, since ECharts formats and thins dates itself.

Leaving it as it was would have perpetuated precisely the inconsistency #1247 exists to remove.

Two things worth noting for review:

  1. The axis is now built as two object literals rather than one with ternaries. ECharts discriminates the axis union on type, so a "time" | "category" union defeats narrowing and the whole option fails to type-check — I hit that on the first attempt.
  2. width joins the memo dependency list, as you suggested, so truncation responds to a resize rather than freezing at first render.

Test added to cartesian-axis-defaults.test.tsx: a line chart with a long category label truncates to Electroni…. 625 chart tests green, types clean.

@sonarqubecloud

Copy link
Copy Markdown

@alfredo1996
alfredo1996 merged commit 38106c9 into release/1.4 Jul 27, 2026
15 checks passed
@alfredo1996
alfredo1996 deleted the fix/issue-1247-chart-grid-axis branch July 27, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:charts Chart rendering area:design Visual design, tokens, typography pkg:component UI component library priority:P2 Should-fix polish type: fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants