Skip to content

[charts-pro] Sampled band highlight falls back to single-band width for Date/object values#23024

Merged
JCQuintas merged 6 commits into
mui:masterfrom
SamanPandey-in:fix-date-highlight
Jul 23, 2026
Merged

[charts-pro] Sampled band highlight falls back to single-band width for Date/object values#23024
JCQuintas merged 6 commits into
mui:masterfrom
SamanPandey-in:fix-date-highlight

Conversation

@SamanPandey-in

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #22830 (data sampling for bar/line).

ChartsXAxisHighlight/ChartsYAxisHighlight widen the band highlight to span a whole sampled bucket by looking up the highlighted value's index with data.indexOf(value). indexOf uses reference equality, so for axes keyed by Date (or other objects) it returns -1 whenever value isn't the exact same instance as the matching entry in axis.data — which is generally the case for values derived from pointer/keyboard interaction. The lookup then silently fails and the highlight falls back to a single-band width instead of covering the merged bucket.

Fix

The highlight selectors already resolve a dataIndex (the exact index into axis.data) for pointer, keyboard, and controlled highlights. Both components now use that dataIndex directly instead of re-deriving it via indexOf.
Added a findDataIndex fallback (used only when dataIndex isn't available) that compares Date values by getTime() instead of by reference, falling back to plain indexOf for primitives/other objects.

Testing

Extended useChartCartesianAxis.axisHighlight.test.tsx (and/or added a new test) covering a Date-keyed band axis with bucketSize > 1, asserting the rendered highlight path spans the full bucket rather than a single band.
Manually verified against the LineSampling/BarSampling perf demos with a Date-keyed dataset, zoomed out so bucketing is active.

Closes the follow-up noted in #22830 re: axis-highlight widening for non-primitive band values.
Closes issue #22999

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23024--material-ui-x.netlify.app/
QR code for https://deploy-preview-23024--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 🔺+130B(+0.03%) 🔺+43B(+0.04%)
@mui/x-charts-pro 🔺+130B(+0.02%) 🔺+70B(+0.04%)
@mui/x-charts-premium 🔺+130B(+0.02%) 🔺+58B(+0.03%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

Total duration: 1,650.99 ms -62.46 ms(-3.6%, p=0.046) | Renders: 63 (+0) | Paint: 2,259.06 ms -35.66 ms(-1.6%)

Test Duration Renders
LineChart stacked area with multiple series 416.58 ms 🔺+69.24 ms(+19.9%, p<0.001) 2 (+0)
LineChart with date axis and big data amount 56.99 ms 🔺+16.00 ms(+39.0%, p=0.012) 2 (+0)
ScatterChartPremium with big data amount and zoomed in (webgl renderer) 22.88 ms 🔺+2.54 ms(+12.5%, p=0.025) 5 (+0)
PieChart with big data amount 10.69 ms 🔺+1.45 ms(+15.7%, p<0.001) 2 (+0)
FunnelChart with big data amount 6.29 ms 🔺+0.69 ms(+12.4%, p<0.001) 2 (+0)

…and 16 more (+5 within noise) — details

Metric alarms

Test Metric Change
LineChart stacked area with multiple series bench:paint 🔺 +75.67 ms
LineChart with date axis and big data amount bench:paint 🔺 +14.72 ms
ScatterChartPremium with big data amount and zoomed in (webgl renderer) bench:paint 🔺 +3.32 ms
PieChart with big data amount bench:paint 🔺 +2.20 ms
FunnelChart with big data amount bench:paint 🔺 +1.02 ms

…and 2 more metric alarms — details


Check out the code infra dashboard for more information about this PR.

@zannager zannager added plan: Pro Impact at least one Pro user. scope: charts Changes related to the charts. labels Jul 1, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 5, 2026
@SamanPandey-in

Copy link
Copy Markdown
Contributor Author

@zannager Please add label: type:bug

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@alexfauquette alexfauquette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think your fix got affected by the merge of #23052 Seems like some pats where similar (about the indexOf())

@SamanPandey-in SamanPandey-in reopened this Jul 7, 2026
@SamanPandey-in
SamanPandey-in marked this pull request as draft July 7, 2026 19:13
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 7, 2026
@SamanPandey-in SamanPandey-in reopened this Jul 7, 2026
@SamanPandey-in
SamanPandey-in marked this pull request as ready for review July 7, 2026 19:33
@SamanPandey-in

Copy link
Copy Markdown
Contributor Author

I think your fix got affected by the merge of #23052 Seems like some pats where similar (about the indexOf())

Thanks for flagging that @alexfauquette! Rebased cleanly onto master, the fix now lives entirely in getSampledBandHighlight.ts where the fallback data.indexOf(value) was still present. Added a small findDataIndex helper that handles Date values by comparing getTime() instead of by reference. ChartsXAxisHighlight and ChartsYAxisHighlight are untouched from master. Single commit, no conflict markers.

@alexfauquette

Copy link
Copy Markdown
Member

Thanks, can you add a regression test?

Comment thread packages/x-charts/src/ChartsAxisHighlight/findDataIndex.ts Outdated
@SamanPandey-in

Copy link
Copy Markdown
Contributor Author

Here's what changed based on @alexfauquette's suggestions:

  1. findDataIndex inlined: no separate file anymore. It's a plain unexported function at the top of getSampledBandHighlight.ts, no JSDoc.
  2. Regression test: getSampledBandHighlight.test.ts covers:
    • Normal single-band (no sampling)
    • Bucket widening (sampled, bucketSize > 1)
    • Last bucket clamping (odd-length data)
    • The actual regression: a Date-keyed axis where value is a different reference than the matching entry in data, with no pre-resolved dataIndex, forcing the findDataIndex fallback path

@alexfauquette alexfauquette added the type: bug It doesn't behave as expected. label Jul 10, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@JCQuintas

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

Master added getSampledBandHighlight.test.ts in mui#23052/mui#23190; keep that
suite and re-add the Date-reference regression test on top of it.
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 23, 2026
@JCQuintas
JCQuintas merged commit bf2425e into mui:master Jul 23, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plan: Pro Impact at least one Pro user. scope: charts Changes related to the charts. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants