mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 16:45:35 +01:00
Update device filtering.
This commit is contained in:
parent
e17c9da3d5
commit
9d09d89aef
5 changed files with 32 additions and 26 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { BROWSERS, ISO_COUNTRIES } from './constants';
|
||||
import { BROWSERS, ISO_COUNTRIES, DEVICES } from './constants';
|
||||
|
||||
export const browserFilter = data =>
|
||||
data.map(({ x, ...props }) => ({ x: BROWSERS[x] || x, ...props }));
|
||||
|
|
@ -8,28 +8,8 @@ export const urlFilter = data => data.filter(({ x }) => x !== '' && !x.startsWit
|
|||
export const refFilter = data =>
|
||||
data.filter(({ x }) => x !== '' && !x.startsWith('/') && !x.startsWith('#'));
|
||||
|
||||
export const deviceFilter = data => {
|
||||
if (data.length === 0) return [];
|
||||
|
||||
const devices = data.reduce(
|
||||
(obj, { x, y }) => {
|
||||
const [width] = x.split('x');
|
||||
if (width >= 1920) {
|
||||
obj.Desktop += +y;
|
||||
} else if (width >= 1024) {
|
||||
obj.Laptop += +y;
|
||||
} else if (width >= 767) {
|
||||
obj.Tablet += +y;
|
||||
} else {
|
||||
obj.Mobile += +y;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
{ Desktop: 0, Laptop: 0, Tablet: 0, Mobile: 0 },
|
||||
);
|
||||
|
||||
return percentFilter(Object.keys(devices).map(key => ({ x: key, y: devices[key] })));
|
||||
};
|
||||
export const deviceFilter = data =>
|
||||
data.map(({ x, ...props }) => ({ x: DEVICES[x] || x, ...props }));
|
||||
|
||||
export const countryFilter = data =>
|
||||
data.map(({ x, ...props }) => ({ x: ISO_COUNTRIES[x] || x, ...props }));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue