is large data

This commit is contained in:
Nate Kelley 2025-03-29 22:49:43 -06:00
parent 84b974b4a5
commit 87cfb8d45d
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import type { ChartProps } from '../../core'; import type { ChartProps } from '../../core';
import type { ChartType as ChartJSChartType } from 'chart.js'; import { ChartType as ChartJSChartType } from 'chart.js';
import type { import type {
BusterChartConfigProps, BusterChartConfigProps,
BusterChartProps, BusterChartProps,
@ -178,11 +178,11 @@ export const useOptions = ({
const options: ChartProps<ChartJSChartType>['options'] = useMemo(() => { const options: ChartProps<ChartJSChartType>['options'] = useMemo(() => {
const chartAnnotations = chartPlugins?.annotation?.annotations; const chartAnnotations = chartPlugins?.annotation?.annotations;
const isLargeDataset = datasetOptions[0].source.length > 125;
return { return {
indexAxis: isHorizontalBar ? 'y' : 'x', indexAxis: isHorizontalBar ? 'y' : 'x',
animation: animate ? { duration: 1000 } : { duration: 0 }, animation: animate && !isLargeDataset ? { duration: 1000 } : { duration: 0 },
responsive: true,
maintainAspectRatio: false,
backgroundColor: colors, backgroundColor: colors,
borderColor: colors, borderColor: colors,
scales, scales,
@ -195,7 +195,7 @@ export const useOptions = ({
annotations: { ...goalLinesAnnotations, ...chartAnnotations, ...trendlineAnnotations } annotations: { ...goalLinesAnnotations, ...chartAnnotations, ...trendlineAnnotations }
}, },
decimation: { decimation: {
enabled: datasetOptions[0].source.length > 500, enabled: isLargeDataset,
algorithm: 'min-max' algorithm: 'min-max'
} }
}, },

View File

@ -48,6 +48,14 @@ export const Default: Story = {
style: 'string' style: 'string'
} satisfies IColumnLabelFormat } satisfies IColumnLabelFormat
} satisfies Record<keyof ScatterChartData, IColumnLabelFormat>, } satisfies Record<keyof ScatterChartData, IColumnLabelFormat>,
className: 'w-[800px] h-[600px]' className: 'w-[400px] h-[400px]'
}
};
export const LargeDataset: Story = {
args: {
...Default.args,
data: generateScatterChartData(3000),
className: 'w-[400px] h-[400px]'
} }
}; };