-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfaketimeseries.js
More file actions
65 lines (54 loc) · 1.33 KB
/
Copy pathfaketimeseries.js
File metadata and controls
65 lines (54 loc) · 1.33 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
export function forceSeries(min_, max_, opts_) {
var min = min_ ?? 0,
max = max_ ?? 1,
opts = opts_ ?? {},
fmax = opts.fmax ?? 0.01,
damping = opts.damping ?? 0.9,
wrap = opts.wrap ?? false,
x = Math.random(),
v = 0;
function next() {
x += v;
v += (2*Math.random()-1)*fmax;
v *= damping;
if (x < 0 || x > 1) {
if (!wrap) {
v = -v;
x = x < 0 ? -x : 2-x;
} else {
x = x > 1 ? x - 1 : x + 1;
}
}
return x * (max - min) + min;
}
return next;
}
export function categoricalSeries(values) {
var n = values.length,
vs = forceSeries(0, n, {wrap: true});
function next() {
return values[Math.min(Math.floor(vs()), n-1)];
}
return next;
}
export function datetimeSeries() {
function next() {
return new Date();
}
return next;
}
export function midnightSecondsSeries() {
function next() {
let dt = new Date(),
msSinceMidnight = dt.getTime() - dt.setHours(0,0,0,0);
return msSinceMidnight/1000;
}
return next;
}
export function elapsedSecondsSeries() {
const dt = new Date();
function next() {
return (new Date() - dt)/1000;
}
return next;
}