diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2025-10-28 10:33:14 +0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-28 09:33:14 +0300 |
| commit | 12b3662c5aaa9820f96846af44e5db163791512f (patch) | |
| tree | e202f85912a8617ed501ee85a9e623b05ddfcac4 | |
| parent | fix/backend: have timeline start at 2013 for mp (#293) (diff) | |
| download | lphub-12b3662c5aaa9820f96846af44e5db163791512f.tar.gz lphub-12b3662c5aaa9820f96846af44e5db163791512f.tar.bz2 lphub-12b3662c5aaa9820f96846af44e5db163791512f.zip | |
fix/frontend: start timeline at the start of the year (#294)
Diffstat (limited to '')
| -rw-r--r-- | frontend/src/pages/Homepage.tsx | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/frontend/src/pages/Homepage.tsx b/frontend/src/pages/Homepage.tsx index 77dc220..c0dbf68 100644 --- a/frontend/src/pages/Homepage.tsx +++ b/frontend/src/pages/Homepage.tsx | |||
| @@ -18,19 +18,18 @@ const Homepage: React.FC = () => { | |||
| 18 | if (data.length === 0) { | 18 | if (data.length === 0) { |
| 19 | return []; | 19 | return []; |
| 20 | }; | 20 | }; |
| 21 | const sortedData = [...data].sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()); | 21 | const startDate = new Date(data[0].date); |
| 22 | const startDate = new Date(sortedData[0].date); | ||
| 23 | const today = new Date(); | 22 | const today = new Date(); |
| 24 | 23 | ||
| 25 | const result: PortalCountData[] = []; | 24 | const result: PortalCountData[] = []; |
| 26 | let currentDate = new Date(startDate.getFullYear(), startDate.getMonth(), 1); | 25 | let currentDate = new Date(startDate.getFullYear(), 0, 1); |
| 27 | 26 | ||
| 28 | let dataIndex = 0; | 27 | let dataIndex = 0; |
| 29 | let currentCount = sortedData[0].count; | 28 | let currentCount = data[0].count; |
| 30 | 29 | ||
| 31 | while (currentDate <= today) { | 30 | while (currentDate <= today) { |
| 32 | while (dataIndex < sortedData.length && new Date(sortedData[dataIndex].date) <= currentDate) { | 31 | while (dataIndex < data.length && new Date(data[dataIndex].date) <= currentDate) { |
| 33 | currentCount = sortedData[dataIndex].count; | 32 | currentCount = data[dataIndex].count; |
| 34 | dataIndex++; | 33 | dataIndex++; |
| 35 | } | 34 | } |
| 36 | result.push({ | 35 | result.push({ |