|
| 1 | +import * as React from 'react'; |
| 2 | +// eslint-disable-next-line no-restricted-imports |
| 3 | +import { render, cleanup } from '@testing-library/react'; |
| 4 | +import { bench, describe } from 'vitest'; |
| 5 | +import { ScatterChartPro } from '@mui/x-charts-pro/ScatterChartPro'; |
| 6 | +import { options } from '../utils/options'; |
| 7 | + |
| 8 | +describe('ScatterChartPro', () => { |
| 9 | + const dataLength = 50; |
| 10 | + const data = Array.from({ length: dataLength }).map((_, i) => ({ |
| 11 | + x: i, |
| 12 | + y: 50 + Math.sin(i / 5) * 25, |
| 13 | + })); |
| 14 | + |
| 15 | + const xData = data.map((d) => d.x); |
| 16 | + |
| 17 | + bench( |
| 18 | + 'ScatterChartPro with big data amount', |
| 19 | + async () => { |
| 20 | + const { findByText } = render( |
| 21 | + <ScatterChartPro |
| 22 | + xAxis={[ |
| 23 | + { |
| 24 | + id: 'x', |
| 25 | + data: xData, |
| 26 | + zoom: { filterMode: 'discard' }, |
| 27 | + valueFormatter: (v: number) => v.toLocaleString('en-US'), |
| 28 | + }, |
| 29 | + ]} |
| 30 | + initialZoom={[{ axisId: 'x', start: 20, end: 70 }]} |
| 31 | + series={[ |
| 32 | + { |
| 33 | + data, |
| 34 | + }, |
| 35 | + ]} |
| 36 | + width={500} |
| 37 | + height={300} |
| 38 | + />, |
| 39 | + ); |
| 40 | + |
| 41 | + await findByText('60', { ignore: 'span' }); |
| 42 | + |
| 43 | + cleanup(); |
| 44 | + }, |
| 45 | + options, |
| 46 | + ); |
| 47 | + |
| 48 | + bench( |
| 49 | + 'ScatterChartPro with big data amount and zoomed in', |
| 50 | + async () => { |
| 51 | + const { findByText } = render( |
| 52 | + <ScatterChartPro |
| 53 | + xAxis={[ |
| 54 | + { |
| 55 | + id: 'x', |
| 56 | + data: xData, |
| 57 | + valueFormatter: (v: number) => v.toLocaleString('en-US'), |
| 58 | + zoom: { minSpan: 0 }, |
| 59 | + }, |
| 60 | + ]} |
| 61 | + yAxis={[{ id: 'y', zoom: { minSpan: 0 } }]} |
| 62 | + series={[{ data }]} |
| 63 | + width={500} |
| 64 | + height={300} |
| 65 | + initialZoom={[ |
| 66 | + { axisId: 'x', start: 50, end: 50.001 }, |
| 67 | + { axisId: 'y', start: 50, end: 50.001 }, |
| 68 | + ]} |
| 69 | + />, |
| 70 | + ); |
| 71 | + |
| 72 | + await findByText('50.0006', { ignore: 'span' }); |
| 73 | + |
| 74 | + cleanup(); |
| 75 | + }, |
| 76 | + options, |
| 77 | + ); |
| 78 | +}); |
0 commit comments