[charts-pro] Sampled band highlight falls back to single-band width for Date/object values#23024
Conversation
Deploy previewhttps://deploy-preview-23024--material-ui-x.netlify.app/Bundle size
PerformanceTotal 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%)
…and 16 more (+5 within noise) — details Metric alarms
…and 2 more metric alarms — details Check out the code infra dashboard for more information about this PR. |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
@zannager Please add label: |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
alexfauquette
left a comment
There was a problem hiding this comment.
I think your fix got affected by the merge of #23052 Seems like some pats where similar (about the indexOf())
63e6cf7 to
7c73c4c
Compare
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. |
|
Thanks, can you add a regression test? |
|
Here's what changed based on @alexfauquette's suggestions:
|
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
@copilot resolve the merge conflicts in this pull request |
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