[charts-pro] Fix highlight shifting on sampled bar charts#23190
Conversation
Deploy previewhttps://deploy-preview-23190--material-ui-x.netlify.app/Bundle size
PerformanceTotal duration: 1,358.36 ms -117.28 ms(-7.9%) | Renders: 63 (+0) | Paint: 1,924.33 ms -122.10 ms(-6.0%)
…and 6 more (+15 within noise) — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
JCQuintas
left a comment
There was a problem hiding this comment.
Nice work, mostly nit picks
It also seems that argos picked a fix where we were drawing the initial bar from edge rather than from the "gap" 👍
| const geometry = (reverse: boolean) => { | ||
| const { container } = render( | ||
| <BarChartPro | ||
| series={[{ data: range(256) }]} | ||
| xAxis={[{ data: range(256).map(String), zoom: true, reverse }]} | ||
| yAxis={[{ position: 'none' }]} | ||
| width={width} | ||
| height={200} | ||
| margin={0} | ||
| sampling="minmax" | ||
| skipAnimation | ||
| />, | ||
| ); | ||
| return Array.from(container.querySelectorAll(`.${barClasses.element}`)) | ||
| .map((bar) => ({ x: Number(bar.getAttribute('x')), width: Number(bar.getAttribute('width')) })) | ||
| .sort((a, b) => a.x - b.x); | ||
| }; | ||
|
|
||
| const normal = geometry(false); | ||
| const reversed = geometry(true); |
There was a problem hiding this comment.
Not sure it is a good idea to call render twice in the same test 🤔
Probably a more orthodox approach would be to either render both and use selectors for each, or "render, select, update props to reverse, select"
| [ | ||
| { reverse: false, leftIndex: 0 }, | ||
| { reverse: true, leftIndex: 3 }, | ||
| ].forEach(({ reverse, leftIndex }) => { |
There was a problem hiding this comment.
Vitest has a it.for for these cases, but it's not necessary to change 😆
| // Anchor at the left edge: on a reversed axis `data[bucketStart]` is the right-most slot. | ||
| bandStart = Math.min(scale(data[bucketStart])!, scale(data[bucketEnd])!) - halfPadding; |
There was a problem hiding this comment.
Maybe we should have a getBucketRegion(scale, startIndex, endIndex) fn
so that this and the code in createGetBarDimension are synced
Fix sampled bars and axis highlight misaligning on band axes (#22997):
Before:


After:
closes #22997