fix: calculate country visitors share relative to total

as opposed to relative to the top-10 countries shown in the breakdown
This commit is contained in:
Dan Kotov 2026-01-11 15:53:57 -05:00
parent 860e6390f1
commit cd1ee8461a
3 changed files with 78 additions and 18 deletions

View file

@ -1,7 +1,7 @@
export const percentFilter = (data: any[]) => {
export const percentFilter = (data: any[], total?: number) => {
if (!Array.isArray(data)) return [];
const total = data.reduce((n, { y }) => n + y, 0);
return data.map(({ x, y, ...props }) => ({ x, y, z: total ? (y / total) * 100 : 0, ...props }));
const sum = total ?? data.reduce((n, { y }) => n + y, 0);
return data.map(({ x, y, ...props }) => ({ x, y, z: sum ? (y / sum) * 100 : 0, ...props }));
};
export const paramFilter = (data: any[]) => {