From 54e70152c16409269eefba98bd19eeb6d7a17b02 Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Fri, 6 Mar 2026 11:13:51 +0100 Subject: [PATCH] add year sum --- .../js/components/rainfall/YearRainfaill.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/resources/js/components/rainfall/YearRainfaill.tsx b/resources/js/components/rainfall/YearRainfaill.tsx index eb65b24..401211a 100644 --- a/resources/js/components/rainfall/YearRainfaill.tsx +++ b/resources/js/components/rainfall/YearRainfaill.tsx @@ -40,13 +40,29 @@ const YearRainfall: FC = ({loadedAt}) => { {Object.entries(data) - .map(([month, months]) => { - return + .map(([month, months]) => {months[0].label} {months.find(m => m.year === (new Date).getFullYear() && m.month === Number(month))?.values} {months.find(m => m.year === ((new Date).getFullYear() - 1) && m.month === Number(month))?.values} - })} + )} + + Total + {Object.entries(data).at(0).at(1).map(i => i.year) + .sort((a,b) => b > a) + .map(year => + {Object.entries(data).reduce((acc, item) => { + console.log(item.at(1), year) + item.at(1).forEach(month => { + console.log(month) + if(month.year === year) { + acc += month.values + } + }) + return acc + }, 0)} + )} +