+
);
@@ -196,8 +200,10 @@ export default function ChartContainer({
pointHoverBackgroundColor: color,
pointHoverBorderColor: color,
pointHoverBorderWidth: 1,
- animation: false,
- animations: { colors: false, x: false, y: false },
+ animation: {
+ duration: 500,
+ easing: 'easeOutQuart'
+ },
};
})
});
@@ -253,10 +259,10 @@ export default function ChartContainer({
const chartOptions = useMemo(() => ({
responsive: true,
maintainAspectRatio: false,
- animation: { duration: 0 },
- animations: { colors: false, x: false, y: false },
- hover: { animationDuration: 0 },
- responsiveAnimationDuration: 0,
+ animation: {
+ duration: 500,
+ easing: 'easeOutQuart'
+ },
interaction: { mode: 'index', intersect: false },
plugins: {
zoom: {
@@ -308,7 +314,6 @@ export default function ChartContainer({
tooltip: {
mode: 'index',
intersect: false,
- animation: false,
backgroundColor: 'rgba(15, 23, 42, 0.92)',
titleColor: '#f1f5f9',
bodyColor: '#cbd5e1',
@@ -392,8 +397,10 @@ export default function ChartContainer({
pointHoverBackgroundColor: '#dc2626',
pointHoverBorderColor: '#dc2626',
pointHoverBorderWidth: 1,
- animation: false,
- animations: { colors: false, x: false, y: false },
+ animation: {
+ duration: 500,
+ easing: 'easeOutQuart'
+ },
},
];
if (baseline > 0 && (compareMode === 'relative' || compareMode === 'absolute')) {
@@ -415,8 +422,10 @@ export default function ChartContainer({
pointHoverBackgroundColor: '#10b981',
pointHoverBorderColor: '#10b981',
pointHoverBorderWidth: 1,
- animation: false,
- animations: { colors: false, x: false, y: false },
+ animation: {
+ duration: 500,
+ easing: 'easeOutQuart'
+ },
});
}
return { datasets };
From 4f314b0b2e22c1c6879634599b0d25cb677390ba Mon Sep 17 00:00:00 2001
From: JavaZero <71128095+JavaZeroo@users.noreply.github.com>
Date: Mon, 28 Jul 2025 14:59:30 +0800
Subject: [PATCH 3/3] Optimize large datasets
---
src/components/ChartContainer.jsx | 13 +++++++++++--
src/components/__tests__/ChartContainer.test.jsx | 3 ++-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/components/ChartContainer.jsx b/src/components/ChartContainer.jsx
index afc1d3e..ae50754 100644
--- a/src/components/ChartContainer.jsx
+++ b/src/components/ChartContainer.jsx
@@ -13,6 +13,7 @@ import {
Legend,
} from 'chart.js';
import zoomPlugin from 'chartjs-plugin-zoom';
+import { Decimation } from 'chart.js';
import { getMinSteps } from "../utils/getMinSteps.js";
ChartJS.register(
@@ -23,7 +24,8 @@ ChartJS.register(
Title,
Tooltip,
Legend,
- zoomPlugin
+ zoomPlugin,
+ Decimation
);
const ChartWrapper = ({ data, options, chartId, onRegisterChart, onSyncHover }) => {
@@ -265,6 +267,13 @@ export default function ChartContainer({
},
interaction: { mode: 'index', intersect: false },
plugins: {
+ decimation: {
+ enabled: parsedData.some(file =>
+ Object.values(file.metricsData || {}).some(arr => arr.length > 1000)
+ ),
+ algorithm: 'lttb',
+ samples: 1000
+ },
zoom: {
pan: {
enabled: true,
@@ -375,7 +384,7 @@ export default function ChartContainer({
}
},
elements: { point: { radius: 0 } }
- }), [xRange, onXRangeChange]);
+ }), [xRange, onXRangeChange, parsedData]);
const createComparisonChartData = (item1, item2, title) => {
const comparisonData = getComparisonData(item1.data, item2.data, compareMode);
diff --git a/src/components/__tests__/ChartContainer.test.jsx b/src/components/__tests__/ChartContainer.test.jsx
index bb7039d..a992796 100644
--- a/src/components/__tests__/ChartContainer.test.jsx
+++ b/src/components/__tests__/ChartContainer.test.jsx
@@ -20,7 +20,8 @@ vi.mock('chart.js', () => {
LineElement: {},
Title: {},
Tooltip: {},
- Legend: {}
+ Legend: {},
+ Decimation: {}
};
});