forked from fazalmajid/pingwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delta.js
49 lines (48 loc) · 1.47 KB
/
delta.js
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
var delta = [
{{- range $i, $ts := .Ordered }}
{{- if (ne $i 0) }},{{end}}
[new Date({{$ts -}})
{{- range (index $.Points $ts ) -}},
{{- if (eq . 0.0) -}}
null
{{- else if (eq . -3600e3) -}}
{{- -100.0 -}}
{{- else -}}
{{- . -}}
{{end -}}
{{end -}}
]
{{- end}}
];
if (delta.length > 0) {
let dlen = data.length;
let first = delta[0][0];
// two updates may have collided, get rid of overlapping data
while (data.length > 0 && data[data.length-1][0] > first) {
data.pop();
}
// add the new data at the end
Array.prototype.push.apply(data, delta);
// remove older data until the size of the data window remains the same
// but only once we've met the minimum number of data points, otherwise
// when we first get started the window would remain less than the
// desired window
while (data.length > dlen && data.length > {{$.MinData}}) {
data.shift();
}
if (dmin == 0) {
// there was no initial data, delta is the entire new data
dmin = delta[0][0].getTime();
dmax = delta[delta.length-1][0].getTime();
} else {
let new_dmax = delta[delta.length-1][0].getTime();
dmin = dmin + (new_dmax - dmax);
dmax = new_dmax;
}
rowmax = data.length - 1;
delta = null;
g.updateOptions({
"file": data,
"dateWindow": [dmin, dmax]
});
}