Skip to content

Commit 003ebe7

Browse files
committed
feat: truncate timestamps to the nearest minute in trend chart
1 parent b583c51 commit 003ebe7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

components/charts/echarts-trend-chart.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// components/charts/echarts-trend-chart.tsx
21
"use client";
32

43
import ReactECharts from 'echarts-for-react';
@@ -15,15 +14,20 @@ interface EchartsTrendChartProps {
1514
const EchartsTrendChart: React.FC<EchartsTrendChartProps> = ({ trendData }) => {
1615
const { theme } = useTheme();
1716

17+
const truncateToMinute = (timestamp: number): number => {
18+
const date = new Date(timestamp);
19+
date.setSeconds(0, 0);
20+
return date.getTime();
21+
};
22+
1823
const allTimePoints = new Set<number>();
1924
trendData.forEach(user => {
2025
user.history.forEach(point => {
21-
allTimePoints.add(new Date(point.time).getTime());
26+
allTimePoints.add(truncateToMinute(new Date(point.time).getTime()));
2227
});
2328
});
2429

25-
// Add the current time to the set to extend the axis to now
26-
allTimePoints.add(new Date().getTime());
30+
allTimePoints.add(truncateToMinute(new Date().getTime()));
2731

2832
const sortedTimePoints = Array.from(allTimePoints).sort((a, b) => a - b);
2933

0 commit comments

Comments
 (0)