Repository navigation
Conversation
|
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 3 files.
1 file is newly checked for coverage.
|
…total is clicked The totals read like the metric tabs of other widgets, so they now respond: a click dims the other sources in the chart and in the totals, and a second click lets go. The stacked area and comparative bar charts each take an option for it, and the bar chart can leave its legend to the widget. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
614e543 to
efe7aaf
Compare
… source test The lint gate allows no warnings, and `fireEvent.click` carries one. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for working on this! @dognose24 I left a few inline notes, mainly about moving the dimming into @automattic/charts and two accessibility issues.
| const emphasisRule = | ||
| emphasizedIndex === null | ||
| ? null | ||
| : `[data-chart-scope="${ scope }"] .visx-area-stack > path:not(:nth-child(${ | ||
| series.length | ||
| }n + ${ emphasizedIndex + 1 })) { opacity: ${ DIMMED_SERIES_OPACITY }; }`; |
There was a problem hiding this comment.
I wonder if the dimming could live in @automattic/charts instead? This rule relies on visx drawing the areas and then the lines in series order, so a visx update could silently stop it. visx already accepts a per-series opacity, so an emphasizedSeries label option on the charts could replace both rules and the index/label split here.
|
|
||
| .total:focus-visible { | ||
| outline: var(--wpds-border-width-focus) solid var(--wpds-color-stroke-focus); | ||
| outline-offset: var(--wpds-dimension-gap-xs); |
There was a problem hiding this comment.
Could we draw the focus ring inside the button? On the first total, .root's overflow: hidden clips the ring's top and start edges. Other focus rings in this package use the inset offset.
| outline-offset: var(--wpds-dimension-gap-xs); | |
| outline-offset: calc(-1 * var(--wpds-border-width-focus)); |
| .isDimmed { | ||
| opacity: 0.45; | ||
| } |
There was a problem hiding this comment.
Could we dim only the color marker and keep the text at full color? At 0.45 the dimmed numbers drop to about 2.8:1 and the share line to about 1.9:1, below WCAG AA, while those totals are still clickable.
| it( 'brings out one source at a time, and lets it go on a second click', async () => { | ||
| mockUseStatsEdgeBotRequests.mockReturnValue( | ||
| requestsResult( { human: 600, ai: 250, other: 100, blocked: 50 } ) | ||
| ); | ||
| renderWidget( { from: '2026-11-01', to: '2026-11-07', interval: 'day' } ); | ||
| const pressed = () => | ||
| screen | ||
| .getAllByRole( 'button', { pressed: true } ) | ||
| .map( button => button.textContent?.match( /^\D+/ )?.[ 0 ] ); | ||
|
|
||
| await userEvent.click( screen.getByRole( 'button', { name: /AI bots/ } ) ); | ||
| expect( pressed() ).toEqual( [ 'AI bots' ] ); | ||
|
|
||
| await userEvent.click( screen.getByRole( 'button', { name: /Blocked/ } ) ); | ||
| expect( pressed() ).toEqual( [ 'Blocked' ] ); | ||
|
|
||
| await userEvent.click( screen.getByRole( 'button', { name: /Blocked/ } ) ); | ||
| expect( screen.queryByRole( 'button', { pressed: true } ) ).not.toBeInTheDocument(); | ||
| } ); |
There was a problem hiding this comment.
Would it be worth covering the dimming itself? The PR notes jsdom draws the charts at zero width, but @automattic/charts mocks the element size in its own jest setup (setup-element-size-mock.js). This test only checks aria-pressed, so the chart wiring and the dimmed totals go untested.
| const pressed = () => | ||
| screen | ||
| .getAllByRole( 'button', { pressed: true } ) | ||
| .map( button => button.textContent?.match( /^\D+/ )?.[ 0 ] ); |
There was a problem hiding this comment.
nit: Could we assert aria-pressed on the two buttons directly? Pulling the label out with /^\D+/ would break if a label ever held a digit.
| @media not (prefers-reduced-motion) { | ||
|
|
||
| .total { | ||
| transition: opacity 150ms ease-out; |
There was a problem hiding this comment.
nit: Could we use the WPDS motion tokens here, like the charts legend does for the same fade? 150ms is repeated in three files and isn't on the token scale.
| transition: opacity 150ms ease-out; | |
| transition: opacity var(--wpds-motion-duration-md) var(--wpds-motion-easing-subtle); |
| const emphasizedColor = | ||
| emphasizedSeries === null | ||
| ? undefined | ||
| : seriesStyles[ alignedSeries.findIndex( s => s.label === emphasizedSeries ) ]?.stroke; | ||
| const emphasisRule = emphasizedColor | ||
| ? `[data-chart-scope="${ scope }"] .visx-bar:not([fill="${ emphasizedColor }"]) { opacity: ${ DIMMED_SERIES_OPACITY }; }` | ||
| : null; |
There was a problem hiding this comment.
Should we warn in development when emphasizedSeries meets a previous period? In the grouped layout the comparison bars aren't .visx-bar, so they stay fully opaque, and in overlap the emphasized series' own previous bars dim. Only the README guards it today.
| isDimmed, | ||
| onToggle, | ||
| }: SourceTotalProps ) { | ||
| const toggle = useCallback( () => onToggle( source.key ), [ onToggle, source.key ] ); |
There was a problem hiding this comment.
nit: Is the useCallback needed here? SourceTotal isn't memoized and the handler goes to a DOM button, so an inline arrow should do.
| onPointerUp, | ||
| onDatumActivate, | ||
| }: ComparativeBarChartProps ) { | ||
| const scope = useId(); |
There was a problem hiding this comment.
nit: Could scope double as the fallback chart id? Both only need a unique per-instance string, so the second useId() could go.
|
Agreed, the dimming belongs in the charts. #55501 adds |
Part of UNI-1105. Builds on the Requests by source widget from #55331.
Proposed changes
StackedAreaCharttakesemphasizedIndexandComparativeBarCharttakesemphasizedSeries. Both dim the other series with a rule scoped to the chart, since@automattic/chartshas no option for this yet: the areas are matched by their position in the stack, the bars by their fill color.ComparativeBarCharttakesshowLegend. The widget turns it off, since its totals already name the sources; the bar view used to repeat them in a legend below the chart.The tab stays behind the
jetpack-stats-ai-tabflag, so nothing changes for any site.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
There is no site to test against yet, so use Storybook.
cd projects/js-packages/storybook && pnpm run storybook:devRecording
2026-11-26.10.46.01.mov
What I ran:
tsgo --noEmit, ESLint and Stylelint are clean.Not checked:
ComparativeBarChart. They pass neither new option, and the only change they get is an opacity transition on their bars.🤖 Generated with Claude Code