Repository navigation
Conversation
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>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 4 files.
2 files are newly checked for coverage.
|
adamwoodnz
left a comment
There was a problem hiding this comment.
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 ) } |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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.
| warnOnce( | ||
| `series-emphasis-${ emphasizedSeries }`, | ||
| `emphasizedSeries "${ emphasizedSeries }" matches no series label, so nothing is dimmed.` | ||
| ); |
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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 } } |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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>
|
Thanks for the thorough pass, @adamwoodnz. All taken in d45c6cd:
|
Proposed changes
Add
emphasizedSeriestoAreaChartandBarChart. Pass the label of a primary series and every other series dims toDIMMED_SERIES_OPACITY(0.2, exported by the package); a comparison bar dims with the primary series it shadows, in every layout.nulldims 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
ClassifiedBarSerieswhenever the host passes the prop at all,undefinedornullincluded, and the bars keep their identity while the emphasis comes and goes. The fade uses the WPDS motion tokens and honorsprefers-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
jp test js js-packages/charts(orpnpm test -- src/charts/bar-chart src/charts/area-chartin the package).jp build js-packages/storybookand open Charts Library → Charts → Bar Chart → Emphasized Series and Area Chart → Emphasized Series. One series keeps its color, the rest are faint.emphasizedSeriesas a control. Open Bar Chart → Comparison Multi Overlap and set it toViewsin the Controls panel (or append&args=emphasizedSeries:Viewsto the story URL): Views and Previous views stay, Visitors and Previous visitors dim. On Stacked Comparison set it toDesktop: the Desktop segments and the comparison total stay, the other segments dim.emphasizedSeriesto a label that is not in the data, or to a comparison series' label such asPrevious views: nothing dims and the console shows one[Charts] emphasizedSeries "…" matches no primary series labelwarning.🤖 Generated with Claude Code