fix: accumulate charts with trailing zeros

This commit is contained in:
Torsten Dittmann committed 2025-03-04 17:45:32 +04:00
1 parent 34ca5d4256
commit 6e6da3fdbc
3 files changed
+15 -7

No files matched your search

+11 -1
View File
@@ -41,10 +41,20 @@
export function accumulateFromEndingTotal(
metrics: Models.Metric[],
endingTotal: number
endingTotal: number,
startingDayToFillZero: Date = null
): Array<[string, number]> {
return (metrics ?? []).reduceRight(
(acc, curr) => {
if (startingDayToFillZero) {
const date = new Date(curr.date);
if (date > new Date(startingDayToFillZero)) {
acc.data.unshift([date.toISOString(), 0]);
acc.total -= 0;
return acc;
}
}
acc.data.unshift([curr.date, acc.total]);
acc.total -= curr.value;
return acc;
@@ -175,8 +175,9 @@
{
name: 'Users',
data: accumulateFromEndingTotal(
data.usersUsageToDate,
data.organizationUsage.usersTotal
data.organizationUsage.users,
data.organizationUsage.usersTotal,
new Date()
)
}
]} />
@@ -78,15 +78,12 @@ export const load: PageLoad = async ({ params, parent }) => {
}
}
const usersUsageToDate = usage.users.filter((user) => new Date(user.date) < new Date());
return {
organizationUsage: usage,
projectNames,
invoices,
currentInvoice,
organizationMembers,
plan,
usersUsageToDate
plan
};
};