umami/lib/filters.js

21 lines
770 B
JavaScript
Raw Normal View History

2020-08-07 04:37:19 +02:00
import { BROWSERS, ISO_COUNTRIES, DEVICES } from './constants';
2020-08-01 12:34:56 +02:00
export const browserFilter = data =>
2020-08-07 04:14:44 +02:00
data.map(({ x, ...props }) => ({ x: BROWSERS[x] || x, ...props }));
2020-08-01 12:34:56 +02:00
export const urlFilter = data => data.filter(({ x }) => x !== '' && !x.startsWith('#'));
export const refFilter = data =>
data.filter(({ x }) => x !== '' && !x.startsWith('/') && !x.startsWith('#'));
2020-08-07 04:37:19 +02:00
export const deviceFilter = data =>
data.map(({ x, ...props }) => ({ x: DEVICES[x] || x, ...props }));
2020-08-01 12:34:56 +02:00
export const countryFilter = data =>
2020-08-07 04:14:44 +02:00
data.map(({ x, ...props }) => ({ x: ISO_COUNTRIES[x] || x, ...props }));
2020-08-01 12:34:56 +02:00
export const percentFilter = data => {
const total = data.reduce((n, { y }) => n + y, 0);
return data.map(({ x, y }) => ({ x, y, z: total ? (y / total) * 100 : 0 }));
};