-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathperformance-mode-point-worker.js
More file actions
41 lines (35 loc) · 1.01 KB
/
Copy pathperformance-mode-point-worker.js
File metadata and controls
41 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-env worker */
/* eslint no-restricted-globals: 1 */
const worker = function worker() {
self.onmessage = function onmessage(event) {
const num = event.data;
const bins = 10;
try {
let points = [];
const range = 2 / bins;
const numPerBin = num / bins ** 2;
for (let i = 0; i < bins; i++) {
for (let j = 0; j < bins; j++) {
const xStart = -1 + j * range;
const yStart = -1 + i * range;
const tmp = [];
for (let k = 0; k < numPerBin; k++) {
tmp.push([
xStart + Math.random() * range, // x
yStart + Math.random() * range, // y
Math.round(Math.random()), // category
Math.random(), // value
]);
}
points = points.concat(
tmp.sort((a, b) => a[0] - b[0] || a[1] - b[1])
);
}
}
self.postMessage({ points });
} catch (error) {
self.postMessage({ error });
}
};
};
export default worker;