fix(dashboard,api): show correct percentage on retention

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-03-28 22:36:08 +01:00
parent e9133aa5a8
commit ecda9a7d1b
3 changed files with 7 additions and 8 deletions

View File

@@ -36,11 +36,12 @@ export function Chart({ data }: Props) {
tickFormatter: (value) => `${value}%`,
});
const averageRow = data[0];
const averageRetentionRate = average(averageRow?.percentages || [], true);
const rechartData = averageRow?.percentages.map((item, index, list) => ({
const averageRetentionRate =
average(averageRow?.percentages || [], true) * 100;
const rechartData = averageRow?.percentages.map((item, index) => ({
days: index,
percentage: item,
value: averageRow.values[index],
percentage: item * 100,
value: averageRow.values?.[index],
sum: averageRow.sum,
}));

View File

@@ -31,7 +31,7 @@ export function RetentionTooltip({ active, payload }: Props) {
<div className="flex justify-between">
<span className="text-muted-foreground">Retention Rate:</span>
<span className="font-medium">
{number.formatWithUnit(percentage, '%')}
{number.formatWithUnit(percentage / 100, '%')}
</span>
</div>
<div className="flex justify-between">

View File

@@ -402,9 +402,7 @@ function processCohortData(
cohort_interval: row.cohort_interval,
sum,
values: values,
percentages: values.map((value) =>
sum > 0 ? round((value / sum) * 100, 2) : 0,
),
percentages: values.map((value) => (sum > 0 ? round(value / sum, 2) : 0)),
};
});