Skip to content

Commit 4f314b0

Browse files
committed
Optimize large datasets
1 parent 502c37f commit 4f314b0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/components/ChartContainer.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Legend,
1414
} from 'chart.js';
1515
import zoomPlugin from 'chartjs-plugin-zoom';
16+
import { Decimation } from 'chart.js';
1617
import { getMinSteps } from "../utils/getMinSteps.js";
1718

1819
ChartJS.register(
@@ -23,7 +24,8 @@ ChartJS.register(
2324
Title,
2425
Tooltip,
2526
Legend,
26-
zoomPlugin
27+
zoomPlugin,
28+
Decimation
2729
);
2830

2931
const ChartWrapper = ({ data, options, chartId, onRegisterChart, onSyncHover }) => {
@@ -265,6 +267,13 @@ export default function ChartContainer({
265267
},
266268
interaction: { mode: 'index', intersect: false },
267269
plugins: {
270+
decimation: {
271+
enabled: parsedData.some(file =>
272+
Object.values(file.metricsData || {}).some(arr => arr.length > 1000)
273+
),
274+
algorithm: 'lttb',
275+
samples: 1000
276+
},
268277
zoom: {
269278
pan: {
270279
enabled: true,
@@ -375,7 +384,7 @@ export default function ChartContainer({
375384
}
376385
},
377386
elements: { point: { radius: 0 } }
378-
}), [xRange, onXRangeChange]);
387+
}), [xRange, onXRangeChange, parsedData]);
379388

380389
const createComparisonChartData = (item1, item2, title) => {
381390
const comparisonData = getComparisonData(item1.data, item2.data, compareMode);

src/components/__tests__/ChartContainer.test.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ vi.mock('chart.js', () => {
2020
LineElement: {},
2121
Title: {},
2222
Tooltip: {},
23-
Legend: {}
23+
Legend: {},
24+
Decimation: {}
2425
};
2526
});
2627

0 commit comments

Comments
 (0)