Skip to content

[dark mode] line chart examples#6916

Merged
ckifer merged 23 commits intorecharts:mainfrom
cloud-walker:dark-mode-one-chart
Feb 25, 2026
Merged

[dark mode] line chart examples#6916
ckifer merged 23 commits intorecharts:mainfrom
cloud-walker:dark-mode-one-chart

Conversation

@cloud-walker
Copy link
Contributor

@cloud-walker cloud-walker commented Jan 22, 2026

Description

based on #6882 discoveries, we have to:

  1. support stackblitz examples
  2. update docs only snapshots

So I'm preparing a smaller PR to solve those first

Related Issue

#6825

Motivation and Context

Otherwise stackblitz does not work anymore

How Has This Been Tested?

Playwright and manually

Screenshots (if appropriate):

Are in the diff

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or VR test, or extended an existing story or VR test to show my changes

Summary by CodeRabbit

  • New Features

    • Expanded color system with new light/dark tokens and emphasis colors.
    • StackBlitz previews now include global CSS and respect a default theme.
  • Improvements

    • Line chart examples restyled to use theme variables (axes, grid, tooltip, dots).
    • Vertical charts accept optional external animation control.
    • ColorMode type is now publicly available for consumers.
  • Tests

    • Visual tests updated: per-test color-mode wrapper, consolidated mount fixture, router-driven snapshots, animations disabled by default.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a per-test ColorMode provider and test fixture, updates visual tests to use the fixture and disable chart animations, converts many LineChart examples to CSS-variable theming (some now accept isAnimationActive), expands theme tokens, and updates StackBlitz index payload.

Changes

Cohort / File(s) Summary
Test fixtures & provider
test-vr/tests/www/fixtures.tsx, test-vr/tests/www/TestColorModeProvider.tsx
New TestColorModeProvider creates/disposes a per-test ColorMode store; new test fixture overrides mount to wrap mounts with the provider and re-exports expect.
Visual tests
test-vr/tests/www/LineChartApiExamples.spec-vr.tsx, test-vr/tests/www/dark-mode.spec-vr.tsx
Tests now import local fixtures and mount components wrapped with TestColorModeProvider; chart mounts pass isAnimationActive={false}; dark-mode spec switched to router-based snapshots and adds a Simple Line Chart snapshot.
StackBlitz integration
www/src/components/Shared/StackBlitzLink.tsx
StackBlitz payload updated to include src/index.css, indexHtml generator accepts { title, mode } and sets data-mode, and StackBlitz open options include theme.
LineChart examples (theming & API)
www/src/docs/exampleComponents/LineChart/* (multiple files)
Replaced hard-coded colors with CSS-variable tokens across CartesianGrid/XAxis/YAxis/Tooltip/Line; added dot/activeDot styling; introduced shared fragments and small internal refactors; some vertical charts now accept and forward optional isAnimationActive?: boolean.
Theme tokens / variables
www/src/styles/_variables.css
Added new light-theme tokens and translucent variants; adjusted dark-theme border/solid tokens and text-emphasis; aligned semantic color mappings across themes.
Color-mode API visibility
www/src/components/color-mode/defineColorModeStore.ts
Made ColorMode type public: `export type ColorMode = 'light'

Sequence Diagram(s)

sequenceDiagram
  participant TestRunner as rgba(66,133,244,0.5) Test Runner
  participant Fixtures as rgba(34,139,34,0.5) fixtures.mount
  participant Provider as rgba(128,0,128,0.5) TestColorModeProvider
  participant Store as rgba(255,165,0,0.5) defineColorModeStore
  participant Component as rgba(220,20,60,0.5) MountedComponent

  TestRunner->>Fixtures: request mount(MountedComponent)
  Fixtures->>Provider: render wrapper around component
  Provider->>Store: create per-test ColorMode store
  Provider->>Component: provide ColorModeStore via ColorModeProvider
  Component-->>TestRunner: render and produce screenshot
  Note right of Provider: on unmount\ndispose store
  Provider->>Store: dispose store
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • ckifer
  • PavelVanecek
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title '[dark mode] line chart examples' is directly related to the core changes in the PR, which update line chart example components with dark mode theming and CSS variables.
Description check ✅ Passed The description covers key sections: references related issue #6825, explains motivation (StackBlitz support), testing approach (Playwright and manual), and completes the checklist items. However, it lacks specific detail about implementation approach and could be more comprehensive about the scope of changes.
Docstring Coverage ✅ Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@cloud-walker cloud-walker changed the title link css vars to stackblitz [dark mode] migrate one chart only Jan 22, 2026
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 97.42063% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.18%. Comparing base (c3b308c) to head (15e0429).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
...Components/LineChart/HighlightAndZoomLineChart.tsx 86.44% 8 Missing ⚠️
www/src/components/Shared/StackBlitzLink.tsx 28.57% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6916      +/-   ##
==========================================
+ Coverage   90.12%   90.18%   +0.06%     
==========================================
  Files         526      526              
  Lines       39183    39557     +374     
  Branches     5423     5423              
==========================================
+ Hits        35312    35676     +364     
- Misses       3862     3872      +10     
  Partials        9        9              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link

codecov bot commented Jan 22, 2026

Bundle Report

Bundle size has no change ✅

@cloud-walker cloud-walker changed the title [dark mode] migrate one chart only [dark mode] line chart examples Jan 23, 2026
@cloud-walker
Copy link
Contributor Author

I need to study how to support storybook also

@cloud-walker cloud-walker marked this pull request as ready for review January 23, 2026 09:41
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
www/src/docs/exampleComponents/LineChart/CustomizedLabelLineChart.tsx (1)

59-67: Replace any with BaseTickContentProps from recharts.
Line 59 uses any, which violates the TS guideline. Recharts exports BaseTickContentProps from the public API which includes x, y, and payload properties. Use this type instead of any to keep it properly typed and aligned with the public API.

♻️ Suggested fix
-import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
+import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BaseTickContentProps } from 'recharts';

-const CustomizedAxisTick = ({ x, y, payload }: any) => {
+const CustomizedAxisTick = ({ x, y, payload }: BaseTickContentProps) => {
   return (
     <g transform={`translate(${x},${y})`}>
       <text x={0} y={0} dy={16} textAnchor="end" fill="#666" transform="rotate(-35)">
-        {payload.value}
+        {payload?.value}
       </text>
     </g>
   );
 };
🧹 Nitpick comments (2)
www/src/docs/exampleComponents/LineChart/CompareTwoLines.tsx (1)

37-43: Avoid using any type in TypeScript.

The TooltipContentProps<any, any> uses any for both generic parameters, which violates the coding guidelines. Consider using more specific types or unknown if the actual types are not known.

As per coding guidelines, prefer unknown over any and refine the type.

♻️ Suggested improvement
-const CustomTooltip: FC<TooltipContentProps<any, any>> = ({ active, payload }) => {
+const CustomTooltip: FC<TooltipContentProps<number, string>> = ({ active, payload }) => {

Alternatively, if the exact types are uncertain:

-const CustomTooltip: FC<TooltipContentProps<any, any>> = ({ active, payload }) => {
+const CustomTooltip: FC<TooltipContentProps<unknown, unknown>> = ({ active, payload }) => {
www/src/docs/exampleComponents/LineChart/LineChartHasMultiSeries.tsx (1)

44-57: Consider using distinct colors for each series.

All three series use the same var(--color-chart-1) stroke color, which may make them visually indistinguishable. Consider cycling through chart color tokens (e.g., --color-chart-1, --color-chart-2, --color-chart-3) based on the series index to improve visual differentiation.

💡 Suggested improvement
       {series.map((s, index) => (
         <Line
           dataKey="value"
           data={s.data}
           name={s.name}
           key={s.name}
-          stroke="var(--color-chart-1)"
+          stroke={`var(--color-chart-${index + 1})`}
           dot={{
             fill: 'var(--color-surface-base)',
           }}

@PavelVanecek
Copy link
Collaborator

Storybook already has dark mode included

@cloud-walker
Copy link
Contributor Author

But its not in sync with the color-mode algo, I will see in a future PR btw

@cloud-walker
Copy link
Contributor Author

what do you think about the fixture? I will need to use it wrap all www related VR tests

@cloud-walker
Copy link
Contributor Author

VerticalLineChartWithSpecifiedDomain vr test is failing in the CI but not locally 🫠

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@www/src/docs/exampleComponents/LineChart/LineChartHasMultiSeries.tsx`:
- Around line 44-57: The Line components rendered in series.map currently all
use the same stroke "var(--color-chart-1)" so multi-series lines are
indistinguishable; update the map callback to include the series index (e.g.,
series.map((s, i) => ...)) and set each Line's stroke to a token derived from
the index (for example "var(--color-chart-{i+1})" or a small array of tokens) so
each series rendered by the Line component has a distinct color; keep the
existing props (dataKey, data, name, key, dot, activeDot) but replace the
hard-coded stroke with an index-driven token.

Copy link
Collaborator

@PavelVanecek PavelVanecek left a comment

Choose a reason for hiding this comment

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

Let's find some solution for the VR test that doesn't include maxDiffPixelRatio.

What was the failure? Do you run the tests in Docker?

@PavelVanecek
Copy link
Collaborator

Dark mode sounds simple until it doesn't, right @cloud-walker ?

@cloud-walker
Copy link
Contributor Author

we will found a way sooner or later 😄

@ckifer
Copy link
Member

ckifer commented Jan 26, 2026

Why do we need to support the stackblitz examples? Just let them go back to light mode. Our website is being themed, not recharts (or at least not in this PR) and stackblitz is outside of that

@cloud-walker
Copy link
Contributor Author

Why do we need to support the stackblitz examples?

At least we need to pass the CSS variables, the code is the same of the docs, but yeah we can keep the light mode by default. But why you think its not a good idea to support color-mode propagation? Its a plus to me that the end user can benefit from it also there. That said, merging it now would worsen the experience for not yet migrated chart, so yeah, better keep light mode at least for now.

Our website is being themed, not recharts (or at least not in this PR)

Yeah, lets continue the recharts itself theming discussione elsewhere, I agree, but @ckifer what to do you think about the strategy to continue the docs theming?

So to recap, I need to:

  1. keep stackblitz in light mode
  2. do another attempt on avoiding the maxDiffPixelRatio thing

@ckifer
Copy link
Member

ckifer commented Jan 26, 2026

Not saying that we shouldn't support theme in stackblitz or we need to keep it in light mode, only that if we want to do that it doesn't have to be in this PR for the sake of getting this merged

@PavelVanecek
Copy link
Collaborator

PavelVanecek commented Jan 28, 2026

Okay so the example list fails on timeout, looks like some animation never settles? Or github runner is too slow?

The vertical line chart appears to be 1 pixel off. Let me try to checkout your branch and see if I can reproduce the failure.

image

@PavelVanecek
Copy link
Collaborator

I can see the same failure on my laptop so let's see if this helps

cloud-walker and others added 15 commits February 17, 2026 22:08
- Updated CartesianGrid, XAxis, YAxis, and Tooltip components across various LineChart examples to use color variables for better theming.
- Modified Line components to utilize color variables for strokes and active dots, enhancing visual consistency.
- Improved accessibility and readability by adjusting stroke colors and adding active dot styles.
- Refactored common chart elements into reusable components to reduce redundancy and improve maintainability.
- Updated snapshot images for LineChart examples to reflect the new styles and ensure visual accuracy in tests.
…n and BiaxialLineChart with maxDiffPixelRatio
@cloud-walker cloud-walker marked this pull request as ready for review February 19, 2026 06:30
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
www/src/components/Shared/StackBlitzLink.tsx (1)

159-161: Hardcoded mode: 'light' aligns with the PR strategy to defer dark-mode StackBlitz support.

Consider adding a brief comment at line 160 noting the light-mode lock is intentional and temporary, so future contributors know to wire it to the actual color mode when ready.

💡 Suggestion
-              'index.html': indexHtmlCode({ title, mode: 'light' }),
+              // TODO: wire `mode` to the active color mode once dark-mode StackBlitz support is ready
+              'index.html': indexHtmlCode({ title, mode: 'light' }),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@www/src/components/Shared/StackBlitzLink.tsx` around lines 159 - 161, Add a
short inline comment next to the files entry where indexHtmlCode is called (the
'index.html': indexHtmlCode({ title, mode: 'light' }) line in
StackBlitzLink.tsx) stating that mode: 'light' is intentionally hardcoded as a
temporary decision to defer dark-mode support and should be wired to the app
color mode (e.g., from context or a prop) when dark-mode StackBlitz is
implemented; place the comment immediately above or beside the call so future
contributors understand this is deliberate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test-vr/tests/www/dark-mode.spec-vr.tsx`:
- Around line 13-15: The current test.beforeEach only calls page.emulateMedia({
reducedMotion: 'reduce' }) which does not stop Recharts animations; update the
setup to explicitly disable Recharts by adding an initialization script before
pages load that sets a global flag or stubs Recharts animation behavior (for
example, use page.addInitScript to set window.__RECHARTS_DISABLE_ANIMATION =
true or override requestAnimationFrame/animation functions) so Recharts will
render without animations; keep the existing test.beforeEach and add this
explicit disabling step (reference test.beforeEach, page.emulateMedia,
page.addInitScript and the global flag name) so screenshot tests are
deterministic.

In `@www/src/docs/exampleComponents/LineChart/CompareTwoLines.tsx`:
- Around line 910-911: The Portfolio line's activeDot.fill still uses the
hardcoded color constant (color) while its stroke uses the CSS variable
var(--color-chart-1), causing a mismatch in dark mode; update the Portfolio
Line's activeDot.fill to match its stroke theming (use the same CSS variable or
the same color variable used for the stroke) so the hover dot and line stay
visually consistent (mirror the pattern used by the Compare line where
compareColor is used for both stroke/gradient and activeDot.fill).

---

Duplicate comments:
In `@test-vr/tests/www/dark-mode.spec-vr.tsx`:
- Around line 37-48: The VR snapshot is flaky because SimpleLineChart renders
with animations enabled; either update the SimpleLineChart component to accept
an isAnimationActive prop and default it to false (modify the SimpleLineChart
React component to read isAnimationActive and pass it into the underlying chart
rendering), or disable animations in the test by mounting <SimpleLineChart
isAnimationActive={false} /> in the dark-mode.spec-vr.tsx test; make sure the
prop name is exactly isAnimationActive so it matches other examples like
LineChartExample/BarChartExample/PieChartExample.

---

Nitpick comments:
In `@www/src/components/Shared/StackBlitzLink.tsx`:
- Around line 159-161: Add a short inline comment next to the files entry where
indexHtmlCode is called (the 'index.html': indexHtmlCode({ title, mode: 'light'
}) line in StackBlitzLink.tsx) stating that mode: 'light' is intentionally
hardcoded as a temporary decision to defer dark-mode support and should be wired
to the app color mode (e.g., from context or a prop) when dark-mode StackBlitz
is implemented; place the comment immediately above or beside the call so future
contributors understand this is deliberate.

Copy link
Collaborator

@PavelVanecek PavelVanecek left a comment

Choose a reason for hiding this comment

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

I am still secretly hoping for the Theme provider one day

@ckifer
Copy link
Member

ckifer commented Feb 25, 2026

merging this before conflicts

@ckifer ckifer merged commit 8cf73b2 into recharts:main Feb 25, 2026
41 checks passed
@PavelVanecek PavelVanecek mentioned this pull request Feb 26, 2026
PavelVanecek added a commit that referenced this pull request Feb 26, 2026
We have merged #6916 and
#7034 but they affected each
other and now we have semantic conflict in main branch so let's fix it.
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