From c9a9e484a27706aec8c98bf02d5e1daadb4b4c52 Mon Sep 17 00:00:00 2001 From: Howard Zhang Date: Thu, 18 Jan 2024 22:05:59 +0800 Subject: [PATCH] feat: add scatter test page --- .../browser/test-page/scatter-player.ts | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 packages/vchart/__tests__/runtime/browser/test-page/scatter-player.ts diff --git a/packages/vchart/__tests__/runtime/browser/test-page/scatter-player.ts b/packages/vchart/__tests__/runtime/browser/test-page/scatter-player.ts new file mode 100644 index 0000000000..c7b86e5cf8 --- /dev/null +++ b/packages/vchart/__tests__/runtime/browser/test-page/scatter-player.ts @@ -0,0 +1,122 @@ +import { isMobile } from 'react-device-detect'; +// eslint-disable-next-line no-duplicate-imports +import { default as VChart } from '../../../../src/index'; + +const yearData: any = {}; +const firstYear = 1950; +const lastYear = 2023; + +for (let year = firstYear; year <= lastYear; year++) { + const data: any[] = []; + yearData[year] = data; + + for (let i = 0; i < 50; i++) { + if (year === firstYear) { + data.push({ + x: Math.round(Math.random() * 100 - 90), + y: Math.round(Math.random() * 100 - 90), + value: Math.round(Math.random() * 1000), + index: i + }); + } else { + const previous = yearData[year - 1][i]; + data.push({ + x: previous.x + Math.round(Math.random() * 5 - 2 + i / 50), + y: previous.y + Math.round(Math.random() * 5 - 2 + i / 50), + value: Math.abs(previous.value + Math.round(Math.random() * 100 - 45)), + index: i + }); + } + } +} + +const specs = Object.values(yearData).map((data, index) => { + return { + data: [ + { + id: 'id', + values: data + }, + { + id: 'year', + values: [{ year: Object.keys(yearData)[index] }] + } + ] + }; +}); + +const DURATION = 300; + +const spec = { + type: 'common', + player: { + orient: 'bottom', + auto: true, + interval: DURATION, + dy: 10, + specs + }, + data: specs[0].data, + axes: [ + { + orient: 'left', + type: 'linear', + range: { min: -100, max: 100 } + }, + { + orient: 'bottom', + type: 'linear', + range: { min: -100, max: 100 } + } + ], + series: [ + { + type: 'scatter', + // 通过数据中的 index 进行数据匹配 + dataKey: 'index', + // 声明点半径大小 + sizeField: 'value', + size: { + type: 'linear', + range: [5, 30] + }, + xField: 'x', + yField: 'y', + animationAppear: { + duration: DURATION, + easing: 'linear' + }, + animationUpdate: { + duration: DURATION, + easing: 'linear' + } + } + ], + crosshair: { + xField: { visible: true }, + yField: { visible: true } + }, + legends: { + visible: true, + type: 'size', + orient: 'right', + field: 'value', + width: 100 + } as any +}; + +const run = () => { + // VChart.ThemeManager.setCurrentTheme('dark'); + const cs = new VChart(spec, { + dom: document.getElementById('chart') as HTMLElement, + mode: isMobile ? 'mobile-browser' : 'desktop-browser' + }); + console.time('renderTime'); + + cs.renderAsync().then(() => { + console.timeEnd('renderTime'); + }); + window['vchart'] = cs; + console.log(cs); +}; +run();