-
Notifications
You must be signed in to change notification settings - Fork 25
/
vis.helper.js
196 lines (173 loc) · 5.37 KB
/
vis.helper.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var view =
{
start:0,
end:0,
mode: "interval",
fixinterval:false,
'zoomout':function ()
{
var time_window = this.end - this.start;
var middle = this.start + time_window / 2;
time_window = time_window * 2;
this.start = middle - (time_window/2);
this.end = middle + (time_window/2);
this.calc_interval();
},
'zoomin':function ()
{
var time_window = this.end - this.start;
var middle = this.start + time_window / 2;
time_window = time_window * 0.5;
this.start = middle - (time_window/2);
this.end = middle + (time_window/2);
this.calc_interval();
},
'panright':function ()
{
var time_window = this.end - this.start;
var shiftsize = time_window * 0.2;
this.start += shiftsize;
this.end += shiftsize;
this.calc_interval();
},
'panleft':function ()
{
var time_window = this.end - this.start;
var shiftsize = time_window * 0.2;
this.start -= shiftsize;
this.end -= shiftsize;
this.calc_interval();
},
'timewindow':function(time)
{
this.start = ((new Date()).getTime())-(3600000*24*time); //Get start time
this.end = (new Date()).getTime(); //Get end time
this.calc_interval();
},
'calc_interval':function()
{
if (this.mode=="interval") {
var npoints = 600;
var interval = Math.round(((this.end - this.start)*0.001)/npoints);
var outinterval = 1;
if (interval>1) outinterval = 1;
if (interval>5) outinterval = 5;
if (min_feed_interval>=5) {
outinterval = 5;
}
if (min_feed_interval>=10) {
outinterval = 10;
}
if (interval>10) outinterval = 10;
if (interval>15) outinterval = 15;
if (interval>20) outinterval = 20;
if (interval>30) outinterval = 30;
if (interval>60) outinterval = 60;
if (interval>120) outinterval = 120;
if (interval>180) outinterval = 180;
if (interval>300) outinterval = 300;
if (interval>600) outinterval = 600;
if (interval>900) outinterval = 900;
if (interval>1200) outinterval = 1200;
if (interval>1800) outinterval = 1800;
if (interval>3600*1) outinterval = 3600*1;
if (interval>3600*2) outinterval = 3600*2;
if (interval>3600*3) outinterval = 3600*3;
if (interval>3600*4) outinterval = 3600*4;
if (interval>3600*5) outinterval = 3600*5;
if (interval>3600*6) outinterval = 3600*6;
if (interval>3600*12) outinterval = 3600*12;
if (interval>3600*24) outinterval = 3600*24;
if (!this.fixinterval) this.interval = outinterval;
this.start = Math.floor((this.start*0.001) / this.interval) * this.interval * 1000;
this.end = Math.ceil((this.end*0.001) / this.interval) * this.interval * 1000;
}
}
}
function stats(data)
{
var sum = 0;
var i=0;
var minval = 0;
var maxval = 0;
var npoints = 0;
var npointsnull = 0;
var val = null;
for (var z in data)
{
var val = data[z][1]; // 1) only calculated based on present values
//if (data[z][1]!=null) val = data[z][1]; // 2) if value is missing use last value
if (val!=null)
{
if (i==0) {
maxval = val;
minval = val;
}
if (val>maxval) maxval = val;
if (val<minval) minval = val;
sum += val;
i++;
}
if (data[z][1]==null) npointsnull++;
npoints ++;
}
var mean = sum / i;
sum = 0, i=0;
for (z in data)
{
sum += (data[z][1] - mean) * (data[z][1] - mean);
i++;
}
var stdev = Math.sqrt(sum / i);
return {
"minval":minval,
"maxval":maxval,
"diff":maxval-minval,
"mean":mean,
"stdev":stdev,
"npointsnull":npointsnull,
"npoints":npoints
};
};
// http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values/901144#901144
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
function tooltip(x, y, contents, bgColour)
{
var offset = 15; // use higher values for a little spacing between `x,y` and tooltip
var elem = $('<div id="tooltip">' + contents + '</div>').css({
position: 'absolute',
display: 'none',
'font-weight':'bold',
border: '1px solid rgb(255, 221, 221)',
padding: '2px',
'background-color': bgColour,
opacity: '0.8'
}).appendTo("body").fadeIn(200);
var elemY = y - elem.height() - offset;
var elemX = x - elem.width() - offset;
if (elemY < 0) { elemY = 0; }
if (elemX < 0) { elemX = 0; }
elem.css({
top: elemY,
left: elemX
});
};
function parseTimepickerTime(timestr){
var tmp = timestr.split(" ");
if (tmp.length!=2) return false;
var date = tmp[0].split("/");
if (date.length!=3) return false;
var time = tmp[1].split(":");
if (time.length!=3) return false;
return new Date(date[2],date[1]-1,date[0],time[0],time[1],time[2],0).getTime() / 1000;
}