Merge pull request #1719 from appwrite/fix-accumulate-charts-with-trailing-zeros

fix: accumulate charts with trailing zeros
This commit is contained in:
Darshan
2025-03-05 11:49:01 +05:30
committed by GitHub
3 changed files with 15 additions and 7 deletions
+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 !== null && startingDayToFillZero instanceof Date) {
const date = new Date(curr.date);
if (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
};
};