Skip to content

Charts: Add emphasizedSeries to the area and bar charts - #55501

Open
dognose24 wants to merge 2 commits into
trunkfrom
add/charts-emphasized-series
Open

dognose24 wants to merge 2 commits into
trunkfrom
add/charts-emphasized-series

Conversation

@dognose24

@dognose24 dognose24 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

Add emphasizedSeries to AreaChart and BarChart. Pass the label of a primary series and every other series dims to DIMMED_SERIES_OPACITY (0.2, exported by the package); a comparison bar dims with the primary series it shadows, in every layout. null dims nothing. A label no series carries dims nothing and warns once in development.

Until now a host that wanted this had to dim the series itself, with CSS that counts the paths visx draws or matches bars by their fill, which breaks silently on a visx update and misses the comparison bars. The chart now owns the opacity: areas and their lines through the series' own props, bars through the four series renderers and the comparison layer. A comparison bar follows the primary it shadows in every layout, and the stacked layout's comparison total stays while the emphasized series has a comparison in it. In a grouped layout visx's own bars take no per-series opacity, so the chart draws them with ClassifiedBarSeries whenever the host passes the prop at all, undefined or null included, and the bars keep their identity while the emphasis comes and goes. The fade uses the WPDS motion tokens and honors prefers-reduced-motion.

Docs and a story for each chart. No plugin changelog entries: nothing renders differently until a host passes the prop; the first consumer is the Requests by source widget in #55390.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • Run the charts suites: jp test js js-packages/charts (or pnpm test -- src/charts/bar-chart src/charts/area-chart in the package).
  • jp build js-packages/storybook and open Charts Library → Charts → Bar Chart → Emphasized Series and Area Chart → Emphasized Series. One series keeps its color, the rest are faint.
  • Every bar and area story declares emphasizedSeries as a control. Open Bar Chart → Comparison Multi Overlap and set it to Views in the Controls panel (or append &args=emphasizedSeries:Views to the story URL): Views and Previous views stay, Visitors and Previous visitors dim. On Stacked Comparison set it to Desktop: the Desktop segments and the comparison total stay, the other segments dim.
  • Set emphasizedSeries to a label that is not in the data, or to a comparison series' label such as Previous views: nothing dims and the console shows one [Charts] emphasizedSeries "…" matches no primary series label warning.

🤖 Generated with Claude Code

Pass the label of a primary series and every other series dims to
DIMMED_SERIES_OPACITY, comparison bars along with the series they
shadow. The chart owns the opacity, so hosts no longer need CSS that
counts visx paths or matches bar fills.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dognose24 dognose24 added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Nov 26, 2026
@dognose24 dognose24 self-assigned this Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the add/charts-emphasized-series branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/charts-emphasized-series
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/charts-emphasized-series

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/js-packages/charts/src/charts/area-chart/area-chart.tsx 123/123 (100.00%) 0.00% 0 💚
projects/js-packages/charts/src/charts/bar-chart/bar-chart.tsx 235/236 (99.58%) 0.03% 0 💚
projects/js-packages/charts/src/charts/bar-chart/private/bar-layer.tsx 19/19 (100.00%) 0.00% 0 💚
projects/js-packages/charts/src/charts/bar-chart/private/comparison-bars.tsx 36/37 (97.30%) 0.08% 0 💚

2 files are newly checked for coverage.

File Coverage
projects/js-packages/charts/src/charts/private/series-emphasis.ts 7/7 (100.00%) 💚
projects/js-packages/charts/src/constants.ts 1/1 (100.00%) 💚

Full summary · PHP report · JS report

@adamwoodnz adamwoodnz 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.

Thanks for adding this! @dognose24 I ran the charts suite (125 suites, 2392 tests green), typecheck, ESLint and Stylelint, and went through the Emphasized Series stories in Storybook. The one thing I'd like sorted before merging is the comparison pairing: it holds in grouped, but in overlap and stacked a comparison bar dims by its own label instead of following the primary it shadows, so it doesn't match what the docs promise. The rest are smaller notes inline.

Testing step 3 didn't work for me as written: ?args=emphasizedSeries:Visitors has no effect on ComparisonMultiOverlap, because Storybook drops an arg a story doesn't declare. Adding emphasizedSeries to the comparison stories' args would make that step followable, and would cover the pairing in the stories too.

xAccessor={ xAccessor }
yAccessor={ yAccessor }
colorAccessor={ getBarBackground( index ) }
opacity={ getSeriesOpacity?.( series.label ) }

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.

Could we key this on the primary the series shadows, the way comparison-bars.tsx does for the grouped layout? I emphasized Views on ComparisonMultiOverlap and its own comparison bar dimmed along with the rest, and switching that data to stacked behaves the same way, so the pairing the docs promise holds in grouped only.

<BarChart
data={ data }
layout={ layout }
emphasizedSeries="Visitors"

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.

Could this emphasize Views instead, or add a row for it? Visitors is the only primary here with no comparison series, so the shadow assertions pass in all three layouts whether or not a comparison follows its primary, and the overlap and stacked pairing can break with the suite green.

emphasizedSeries: string | null | undefined
): GetSeriesOpacity | undefined {
const known =
emphasizedSeries != null && data.some( series => series.label === emphasizedSeries );

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.

Should known look at primary series only? data.some matches a comparison label too, so emphasizedSeries="Views last year" dims every primary with nothing left at full strength and no warning, where the prop documents a primary's label.

Comment on lines +26 to +29
warnOnce(
`series-emphasis-${ emphasizedSeries }`,
`emphasizedSeries "${ emphasizedSeries }" matches no series label, so nothing is dimmed.`
);

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.

nit: Would it be worth holding the warning while data is still empty? A host that mounts the chart with its emphasis already set gets the warning on the first loading render, before any label exists to match.

}

return useMemo( () => {
if ( emphasizedSeries === undefined ) {

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.

Just a thought: is there a way to avoid the renderer swap when a host passes undefined? emphasizedSeries={ hovered } with hovered as undefined moves the bars between BarGroup and ClassifiedBarSeries on every hover and remounts them, and the docs line about passing null instead is all that stands between a caller and that.

opacity={ opacity }
{ ...( stacked ? {} : { renderLine: resolvedWithStroke, curve } ) }
lineProps={ { stroke: color, ...lineStyles } }
lineProps={ { stroke: color, ...lineStyles, opacity } }

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.

nit: Should the opacity override only go in when there is one? A series or theme that sets seriesLineStyle.opacity has it overwritten with undefined whenever nothing is dimmed, making the stroke fully opaque; nothing in the monorepo sets it today, so it is latent. Codex flagged this one too.

Suggested change
lineProps={ { stroke: color, ...lineStyles, opacity } }
lineProps={ { stroke: color, ...lineStyles, ...( opacity === undefined ? {} : { opacity } ) } }


### Emphasized Series

Set `emphasizedSeries` to the label of a primary series to bring it out: every other series dims to `DIMMED_SERIES_OPACITY` (0.2, exported by the package), and a comparison bar follows the series it shadows. The chart owns the drawing, so the dimming holds in every layout and survives a visx update. Drive it from your own control, such as a total or legend item the reader hovers or presses, and pass `null` to let the emphasis go. Keep passing `null` rather than dropping the prop while the emphasis can return, so the bars keep their identity. A label no series carries dims nothing and warns in development.

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.

Could the comparison sentence name the layout it holds in, and the visx clause come out? The pairing works in grouped today but not in overlap or stacked, see my note on bar-layer.tsx, and "survives a visx update" is a design note a reader can't act on.

export interface SeriesEmphasisProps {
/**
* Label of the primary series to bring out. Every other series dims to
* `DIMMED_SERIES_OPACITY`, comparison series along with the primary series they shadow.

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.

Should the comparison sentence live on BarChartProps instead? SeriesEmphasisProps is shared with the area chart, which has no comparison series, so that clause describes bar behavior only.

export { BaseTooltip, TooltipBox } from './components/tooltip';
export { Legend, useChartLegendItems } from './components/legend';
export { TrendIndicator } from './components/trend-indicator';
export { DIMMED_SERIES_OPACITY } from './charts/private/series-emphasis';

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.

nit: Should DIMMED_SERIES_OPACITY move out of private/ before it ships? It's the only export here reaching into a private directory, and the docs point consumers at it.

],
},
];
// eslint-disable-next-line testing-library/no-node-access -- visx renders the bars and takes no test id.

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.

nit: Could these bars be reached by a test id instead? Every branch this block exercises draws its rects from the package's own SlottedBarSeries, ClassifiedBarSeries or StackedBarSeries rather than from visx, so the stated reason doesn't quite hold and AGENTS.md asks new tests not to silence the rule.

A comparison bar now follows the primary series it shadows in the
overlap and stacked layouts too, and the stacked total stays while the
emphasized series has a comparison in it. The grouped renderer follows
the prop's presence, so an undefined value no longer remounts the bars;
an unknown label warns only once the data is in and only against
primary series. DIMMED_SERIES_OPACITY moves out of private/.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dognose24

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough pass, @adamwoodnz. All taken in d45c6cd:

  • Pairing in overlap and stacked: BarChart now maps each comparison series to the primary it shadows (its group's primary, or the only one) and reads a bar's opacity through that map, so a slotted comparison bar follows its primary in overlap. In stacked the comparison total sums every comparison, so it stays at full strength while the emphasized series has a comparison in it and dims otherwise. The test now emphasizes Views, which carries the comparison, asserts the shadow in all three layouts, and adds the Visitors case where the stacked total dims.
  • known and the warning: only primary series count, and nothing warns until data has rows. Both covered.
  • Renderer swap: the grouped bars draw with ClassifiedBarSeries whenever the host passes emphasizedSeries at all, undefined included ('emphasizedSeries' in props), so emphasizedSeries={ hovered } no longer remounts them. The docs line about passing null is gone, and a test rerenders from undefined to a label and checks the same node survives.
  • lineProps only carries opacity when there is one, as suggested.
  • DIMMED_SERIES_OPACITY lives in src/constants.ts now; the comparison sentence moved to BarChartProps, and the docs name the layouts and drop the visx clause.
  • The new bars from SlottedBarSeries and ClassifiedBarSeries carry data-testid="bar-chart-bar", so the tests reach them by test id.
  • Both charts' meta argTypes declare emphasizedSeries, so &args=emphasizedSeries:Views works on every story, the comparison ones included; the testing instructions now use ComparisonMultiOverlap and StackedComparison that way.

@dognose24
dognose24 requested a review from adamwoodnz November 27, 2026 14:43

This branch has not been deployed

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

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [JS Package] Charts RNA [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants