mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Moved code into src folder. Added build for component library.
This commit is contained in:
parent
7a7233ead4
commit
ede658771e
490 changed files with 749 additions and 442 deletions
|
|
@ -1,78 +0,0 @@
|
|||
export const urlFilter = data => {
|
||||
const map = data.reduce((obj, { x, y }) => {
|
||||
if (x) {
|
||||
if (!obj[x]) {
|
||||
obj[x] = y;
|
||||
} else {
|
||||
obj[x] += y;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return Object.keys(map).map(key => ({ x: key, y: map[key] }));
|
||||
};
|
||||
|
||||
export const refFilter = data => {
|
||||
const links = {};
|
||||
|
||||
const map = data.reduce((obj, { x, y }) => {
|
||||
let id;
|
||||
|
||||
try {
|
||||
const url = new URL(x);
|
||||
|
||||
id = url.hostname.replace(/www\./, '') || url.href;
|
||||
} catch {
|
||||
id = '';
|
||||
}
|
||||
|
||||
links[id] = x;
|
||||
|
||||
if (!obj[id]) {
|
||||
obj[id] = y;
|
||||
} else {
|
||||
obj[id] += y;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return Object.keys(map).map(key => ({ x: key, y: map[key], w: links[key] }));
|
||||
};
|
||||
|
||||
export const emptyFilter = data => {
|
||||
return data.map(item => (item.x ? item : null)).filter(n => n);
|
||||
};
|
||||
|
||||
export const percentFilter = data => {
|
||||
const total = data.reduce((n, { y }) => n + y, 0);
|
||||
return data.map(({ x, y, ...props }) => ({ x, y, z: total ? (y / total) * 100 : 0, ...props }));
|
||||
};
|
||||
|
||||
export const paramFilter = data => {
|
||||
const map = data.reduce((obj, { x, y }) => {
|
||||
try {
|
||||
const searchParams = new URLSearchParams(x);
|
||||
|
||||
for (const [key, value] of searchParams) {
|
||||
if (!obj[key]) {
|
||||
obj[key] = { [value]: y };
|
||||
} else if (!obj[key][value]) {
|
||||
obj[key][value] = y;
|
||||
} else {
|
||||
obj[key][value] += y;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return Object.keys(map).flatMap(key =>
|
||||
Object.keys(map[key]).map(n => ({ x: `${key}=${n}`, p: key, v: n, y: map[key][n] })),
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue