Commit | Line | Data |
---|---|---|
6219c9d6 | 1 | Date.ext={};Date.ext.util={};Date.ext.util.xPad=function(x,pad,r){if(typeof (r)=="undefined"){r=10}for(;parseInt(x,10)<r&&r>1;r/=10){x=pad.toString()+x}return x.toString()};Date.prototype.locale="en-GB";if(document.getElementsByTagName("html")&&document.getElementsByTagName("html")[0].lang){Date.prototype.locale=document.getElementsByTagName("html")[0].lang}Date.ext.locales={};Date.ext.locales.en={a:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],b:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],B:["January","February","March","April","May","June","July","August","September","October","November","December"],c:"%a %d %b %Y %T %Z",p:["AM","PM"],P:["am","pm"],x:"%d/%m/%y",X:"%T"};Date.ext.locales["en-US"]=Date.ext.locales.en;Date.ext.locales["en-US"].c="%a %d %b %Y %r %Z";Date.ext.locales["en-US"].x="%D";Date.ext.locales["en-US"].X="%r";Date.ext.locales["en-GB"]=Date.ext.locales.en;Date.ext.locales["en-AU"]=Date.ext.locales["en-GB"];Date.ext.formats={a:function(d){return Date.ext.locales[d.locale].a[d.getDay()]},A:function(d){return Date.ext.locales[d.locale].A[d.getDay()]},b:function(d){return Date.ext.locales[d.locale].b[d.getMonth()]},B:function(d){return Date.ext.locales[d.locale].B[d.getMonth()]},c:"toLocaleString",C:function(d){return Date.ext.util.xPad(parseInt(d.getFullYear()/100,10),0)},d:["getDate","0"],e:["getDate"," "],g:function(d){return Date.ext.util.xPad(parseInt(Date.ext.util.G(d)/100,10),0)},G:function(d){var y=d.getFullYear();var V=parseInt(Date.ext.formats.V(d),10);var W=parseInt(Date.ext.formats.W(d),10);if(W>V){y++}else{if(W===0&&V>=52){y--}}return y},H:["getHours","0"],I:function(d){var I=d.getHours()%12;return Date.ext.util.xPad(I===0?12:I,0)},j:function(d){var ms=d-new Date(""+d.getFullYear()+"/1/1 GMT");ms+=d.getTimezoneOffset()*60000;var doy=parseInt(ms/60000/60/24,10)+1;return Date.ext.util.xPad(doy,0,100)},m:function(d){return Date.ext.util.xPad(d.getMonth()+1,0)},M:["getMinutes","0"],p:function(d){return Date.ext.locales[d.locale].p[d.getHours()>=12?1:0]},P:function(d){return Date.ext.locales[d.locale].P[d.getHours()>=12?1:0]},S:["getSeconds","0"],u:function(d){var dow=d.getDay();return dow===0?7:dow},U:function(d){var doy=parseInt(Date.ext.formats.j(d),10);var rdow=6-d.getDay();var woy=parseInt((doy+rdow)/7,10);return Date.ext.util.xPad(woy,0)},V:function(d){var woy=parseInt(Date.ext.formats.W(d),10);var dow1_1=(new Date(""+d.getFullYear()+"/1/1")).getDay();var idow=woy+(dow1_1>4||dow1_1<=1?0:1);if(idow==53&&(new Date(""+d.getFullYear()+"/12/31")).getDay()<4){idow=1}else{if(idow===0){idow=Date.ext.formats.V(new Date(""+(d.getFullYear()-1)+"/12/31"))}}return Date.ext.util.xPad(idow,0)},w:"getDay",W:function(d){var doy=parseInt(Date.ext.formats.j(d),10);var rdow=7-Date.ext.formats.u(d);var woy=parseInt((doy+rdow)/7,10);return Date.ext.util.xPad(woy,0,10)},y:function(d){return Date.ext.util.xPad(d.getFullYear()%100,0)},Y:"getFullYear",z:function(d){var o=d.getTimezoneOffset();var H=Date.ext.util.xPad(parseInt(Math.abs(o/60),10),0);var M=Date.ext.util.xPad(o%60,0);return(o>0?"-":"+")+H+M},Z:function(d){return d.toString().replace(/^.*\(([^)]+)\)$/,"$1")},"%":function(d){return"%"}};Date.ext.aggregates={c:"locale",D:"%m/%d/%y",h:"%b",n:"\n",r:"%I:%M:%S %p",R:"%H:%M",t:"\t",T:"%H:%M:%S",x:"locale",X:"locale"};Date.ext.aggregates.z=Date.ext.formats.z(new Date());Date.ext.aggregates.Z=Date.ext.formats.Z(new Date());Date.ext.unsupported={};Date.prototype.strftime=function(fmt){if(!(this.locale in Date.ext.locales)){if(this.locale.replace(/-[a-zA-Z]+$/,"") in Date.ext.locales){this.locale=this.locale.replace(/-[a-zA-Z]+$/,"")}else{this.locale="en-GB"}}var d=this;while(fmt.match(/%[cDhnrRtTxXzZ]/)){fmt=fmt.replace(/%([cDhnrRtTxXzZ])/g,function(m0,m1){var f=Date.ext.aggregates[m1];return(f=="locale"?Date.ext.locales[d.locale][m1]:f)})}var str=fmt.replace(/%([aAbBCdegGHIjmMpPSuUVwWyY%])/g,function(m0,m1){var f=Date.ext.formats[m1];if(typeof (f)=="string"){return d[f]()}else{if(typeof (f)=="function"){return f.call(d,d)}else{if(typeof (f)=="object"&&typeof (f[0])=="string"){return Date.ext.util.xPad(d[f[0]](),f[1])}else{return m1}}}});d=null;return str}; |
efe0829a DV |
2 | DygraphLayout=function(_1,_2){ |
3 | this.dygraph_=_1; | |
4 | this.options={}; | |
9c97d733 | 5 | Dygraph.update(this.options,_2?_2:{}); |
efe0829a DV |
6 | this.datasets=new Array(); |
7 | }; | |
8 | DygraphLayout.prototype.attr_=function(_3){ | |
9 | return this.dygraph_.attr_(_3); | |
10 | }; | |
11 | DygraphLayout.prototype.addDataset=function(_4,_5){ | |
12 | this.datasets[_4]=_5; | |
13 | }; | |
14 | DygraphLayout.prototype.evaluate=function(){ | |
15 | this._evaluateLimits(); | |
16 | this._evaluateLineCharts(); | |
17 | this._evaluateLineTicks(); | |
18 | }; | |
19 | DygraphLayout.prototype._evaluateLimits=function(){ | |
20 | this.minxval=this.maxxval=null; | |
28e8f5ad DV |
21 | if(this.options.dateWindow){ |
22 | this.minxval=this.options.dateWindow[0]; | |
23 | this.maxxval=this.options.dateWindow[1]; | |
24 | }else{ | |
efe0829a | 25 | for(var _6 in this.datasets){ |
1d54a333 DV |
26 | if(!this.datasets.hasOwnProperty(_6)){ |
27 | continue; | |
28 | } | |
efe0829a DV |
29 | var _7=this.datasets[_6]; |
30 | var x1=_7[0][0]; | |
31 | if(!this.minxval||x1<this.minxval){ | |
32 | this.minxval=x1; | |
33 | } | |
34 | var x2=_7[_7.length-1][0]; | |
35 | if(!this.maxxval||x2>this.maxxval){ | |
36 | this.maxxval=x2; | |
37 | } | |
38 | } | |
28e8f5ad | 39 | } |
efe0829a DV |
40 | this.xrange=this.maxxval-this.minxval; |
41 | this.xscale=(this.xrange!=0?1/this.xrange:1); | |
42 | this.minyval=this.options.yAxis[0]; | |
43 | this.maxyval=this.options.yAxis[1]; | |
44 | this.yrange=this.maxyval-this.minyval; | |
45 | this.yscale=(this.yrange!=0?1/this.yrange:1); | |
46 | }; | |
47 | DygraphLayout.prototype._evaluateLineCharts=function(){ | |
48 | this.points=new Array(); | |
49 | for(var _10 in this.datasets){ | |
1d54a333 DV |
50 | if(!this.datasets.hasOwnProperty(_10)){ |
51 | continue; | |
52 | } | |
efe0829a DV |
53 | var _11=this.datasets[_10]; |
54 | for(var j=0;j<_11.length;j++){ | |
55 | var _13=_11[j]; | |
56 | var _14={x:((parseFloat(_13[0])-this.minxval)*this.xscale),y:1-((parseFloat(_13[1])-this.minyval)*this.yscale),xval:parseFloat(_13[0]),yval:parseFloat(_13[1]),name:_10}; | |
57 | if(_14.y<=0){ | |
58 | _14.y=0; | |
59 | } | |
60 | if(_14.y>=1){ | |
61 | _14.y=1; | |
62 | } | |
63 | if((_14.x>=0)&&(_14.x<=1)){ | |
64 | this.points.push(_14); | |
65 | } | |
66 | } | |
67 | } | |
68 | }; | |
69 | DygraphLayout.prototype._evaluateLineTicks=function(){ | |
70 | this.xticks=new Array(); | |
71 | for(var i=0;i<this.options.xTicks.length;i++){ | |
72 | var _16=this.options.xTicks[i]; | |
73 | var _17=_16.label; | |
74 | var pos=this.xscale*(_16.v-this.minxval); | |
75 | if((pos>=0)&&(pos<=1)){ | |
76 | this.xticks.push([pos,_17]); | |
77 | } | |
78 | } | |
79 | this.yticks=new Array(); | |
80 | for(var i=0;i<this.options.yTicks.length;i++){ | |
81 | var _16=this.options.yTicks[i]; | |
82 | var _17=_16.label; | |
83 | var pos=1-(this.yscale*(_16.v-this.minyval)); | |
84 | if((pos>=0)&&(pos<=1)){ | |
85 | this.yticks.push([pos,_17]); | |
86 | } | |
87 | } | |
6a1aa64f | 88 | }; |
285a6bda | 89 | DygraphLayout.prototype.evaluateWithError=function(){ |
b2a516b8 DV |
90 | this.evaluate(); |
91 | if(!this.options.errorBars){ | |
92 | return; | |
93 | } | |
94 | var i=0; | |
efe0829a | 95 | for(var _19 in this.datasets){ |
1d54a333 DV |
96 | if(!this.datasets.hasOwnProperty(_19)){ |
97 | continue; | |
98 | } | |
b2a516b8 | 99 | var j=0; |
efe0829a | 100 | var _20=this.datasets[_19]; |
efe0829a DV |
101 | for(var j=0;j<_20.length;j++,i++){ |
102 | var _21=_20[j]; | |
103 | var xv=parseFloat(_21[0]); | |
104 | var yv=parseFloat(_21[1]); | |
b2a516b8 | 105 | if(xv==this.points[i].xval&&yv==this.points[i].yval){ |
efe0829a DV |
106 | this.points[i].errorMinus=parseFloat(_21[2]); |
107 | this.points[i].errorPlus=parseFloat(_21[3]); | |
b2a516b8 DV |
108 | } |
109 | } | |
110 | } | |
6a1aa64f | 111 | }; |
285a6bda | 112 | DygraphLayout.prototype.removeAllDatasets=function(){ |
b2a516b8 DV |
113 | delete this.datasets; |
114 | this.datasets=new Array(); | |
6a1aa64f | 115 | }; |
efe0829a | 116 | DygraphLayout.prototype.updateOptions=function(_24){ |
9c97d733 | 117 | Dygraph.update(this.options,_24?_24:{}); |
b2a516b8 | 118 | }; |
efe0829a | 119 | DygraphCanvasRenderer=function(_25,_26,_27,_28){ |
efe0829a | 120 | this.dygraph_=_25; |
f474c2a3 | 121 | this.options={"strokeWidth":0.5,"drawXAxis":true,"drawYAxis":true,"axisLineColor":"black","axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":"black","axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"drawYGrid":true,"drawXGrid":true,"gridLineColor":"rgb(128,128,128)"}; |
9c97d733 | 122 | Dygraph.update(this.options,_28); |
fbe31dc8 | 123 | this.layout=_27; |
b0c3b730 | 124 | this.element=_26; |
fbe31dc8 | 125 | this.container=this.element.parentNode; |
fbe31dc8 DV |
126 | this.height=this.element.height; |
127 | this.width=this.element.width; | |
128 | if(!this.isIE&&!(DygraphCanvasRenderer.isSupported(this.element))){ | |
129 | throw "Canvas is not supported."; | |
130 | } | |
131 | this.xlabels=new Array(); | |
132 | this.ylabels=new Array(); | |
133 | this.area={x:this.options.yAxisLabelWidth+2*this.options.axisTickSize,y:0}; | |
134 | this.area.w=this.width-this.area.x-this.options.rightGap; | |
135 | this.area.h=this.height-this.options.axisLabelFontSize-2*this.options.axisTickSize; | |
b0c3b730 DV |
136 | this.container.style.position="relative"; |
137 | this.container.style.width=this.width+"px"; | |
fbe31dc8 DV |
138 | }; |
139 | DygraphCanvasRenderer.prototype.clear=function(){ | |
140 | if(this.isIE){ | |
141 | try{ | |
142 | if(this.clearDelay){ | |
143 | this.clearDelay.cancel(); | |
144 | this.clearDelay=null; | |
145 | } | |
146 | var _29=this.element.getContext("2d"); | |
147 | } | |
148 | catch(e){ | |
149 | this.clearDelay=MochiKit.Async.wait(this.IEDelay); | |
150 | this.clearDelay.addCallback(bind(this.clear,this)); | |
151 | return; | |
152 | } | |
153 | } | |
154 | var _29=this.element.getContext("2d"); | |
155 | _29.clearRect(0,0,this.width,this.height); | |
2160ed4a | 156 | for(var i=0;i<this.xlabels.length;i++){ |
b0c3b730 DV |
157 | var el=this.xlabels[i]; |
158 | el.parentNode.removeChild(el); | |
2160ed4a DV |
159 | } |
160 | for(var i=0;i<this.ylabels.length;i++){ | |
b0c3b730 DV |
161 | var el=this.ylabels[i]; |
162 | el.parentNode.removeChild(el); | |
2160ed4a | 163 | } |
fbe31dc8 DV |
164 | this.xlabels=new Array(); |
165 | this.ylabels=new Array(); | |
166 | }; | |
b0c3b730 DV |
167 | DygraphCanvasRenderer.isSupported=function(_31){ |
168 | var _32=null; | |
fbe31dc8 | 169 | try{ |
21d3323f | 170 | if(typeof (_31)=="undefined"||_31==null){ |
b0c3b730 | 171 | _32=document.createElement("canvas"); |
fbe31dc8 | 172 | }else{ |
b0c3b730 | 173 | _32=_31; |
fbe31dc8 | 174 | } |
b0c3b730 | 175 | var _33=_32.getContext("2d"); |
fbe31dc8 DV |
176 | } |
177 | catch(e){ | |
178 | var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); | |
b0c3b730 DV |
179 | var _35=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); |
180 | if((!ie)||(ie[1]<6)||(_35)){ | |
fbe31dc8 DV |
181 | return false; |
182 | } | |
183 | return true; | |
184 | } | |
185 | return true; | |
b2a516b8 | 186 | }; |
285a6bda | 187 | DygraphCanvasRenderer.prototype.render=function(){ |
b2a516b8 DV |
188 | var ctx=this.element.getContext("2d"); |
189 | if(this.options.drawYGrid){ | |
b0c3b730 | 190 | var _37=this.layout.yticks; |
b2a516b8 | 191 | ctx.save(); |
f474c2a3 | 192 | ctx.strokeStyle=this.options.gridLineColor; |
b2a516b8 | 193 | ctx.lineWidth=this.options.axisLineWidth; |
b0c3b730 | 194 | for(var i=0;i<_37.length;i++){ |
b2a516b8 | 195 | var x=this.area.x; |
b0c3b730 | 196 | var y=this.area.y+_37[i][0]*this.area.h; |
b2a516b8 DV |
197 | ctx.beginPath(); |
198 | ctx.moveTo(x,y); | |
199 | ctx.lineTo(x+this.area.w,y); | |
200 | ctx.closePath(); | |
201 | ctx.stroke(); | |
202 | } | |
203 | } | |
204 | if(this.options.drawXGrid){ | |
b0c3b730 | 205 | var _37=this.layout.xticks; |
b2a516b8 | 206 | ctx.save(); |
f474c2a3 | 207 | ctx.strokeStyle=this.options.gridLineColor; |
b2a516b8 | 208 | ctx.lineWidth=this.options.axisLineWidth; |
b0c3b730 DV |
209 | for(var i=0;i<_37.length;i++){ |
210 | var x=this.area.x+_37[i][0]*this.area.w; | |
b2a516b8 DV |
211 | var y=this.area.y+this.area.h; |
212 | ctx.beginPath(); | |
213 | ctx.moveTo(x,y); | |
214 | ctx.lineTo(x,this.area.y); | |
215 | ctx.closePath(); | |
216 | ctx.stroke(); | |
217 | } | |
218 | } | |
2ce09b19 | 219 | this._renderLineChart(); |
fbe31dc8 | 220 | this._renderAxis(); |
b2a516b8 | 221 | }; |
fbe31dc8 DV |
222 | DygraphCanvasRenderer.prototype._renderAxis=function(){ |
223 | if(!this.options.drawXAxis&&!this.options.drawYAxis){ | |
224 | return; | |
225 | } | |
b0c3b730 | 226 | var _40=this.element.getContext("2d"); |
f474c2a3 | 227 | var _41={"position":"absolute","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor,"width":this.options.axisLabelWidth+"px","overflow":"hidden"}; |
bd597afc DV |
228 | var _42=function(txt){ |
229 | var div=document.createElement("div"); | |
230 | for(var _45 in _41){ | |
1d54a333 | 231 | if(_41.hasOwnProperty(_45)){ |
bd597afc DV |
232 | div.style[_45]=_41[_45]; |
233 | } | |
1d54a333 | 234 | } |
bd597afc DV |
235 | div.appendChild(document.createTextNode(txt)); |
236 | return div; | |
237 | }; | |
b0c3b730 | 238 | _40.save(); |
f474c2a3 | 239 | _40.strokeStyle=this.options.axisLineColor; |
b0c3b730 | 240 | _40.lineWidth=this.options.axisLineWidth; |
fbe31dc8 | 241 | if(this.options.drawYAxis){ |
d9369404 | 242 | if(this.layout.yticks&&this.layout.yticks.length>0){ |
2160ed4a | 243 | for(var i=0;i<this.layout.yticks.length;i++){ |
bd597afc DV |
244 | var _46=this.layout.yticks[i]; |
245 | if(typeof (_46)=="function"){ | |
fbe31dc8 DV |
246 | return; |
247 | } | |
248 | var x=this.area.x; | |
bd597afc | 249 | var y=this.area.y+_46[0]*this.area.h; |
b0c3b730 DV |
250 | _40.beginPath(); |
251 | _40.moveTo(x,y); | |
252 | _40.lineTo(x-this.options.axisTickSize,y); | |
253 | _40.closePath(); | |
254 | _40.stroke(); | |
bd597afc | 255 | var _47=_42(_46[1]); |
fbe31dc8 DV |
256 | var top=(y-this.options.axisLabelFontSize/2); |
257 | if(top<0){ | |
258 | top=0; | |
259 | } | |
260 | if(top+this.options.axisLabelFontSize+3>this.height){ | |
bd597afc | 261 | _47.style.bottom="0px"; |
fbe31dc8 | 262 | }else{ |
bd597afc | 263 | _47.style.top=top+"px"; |
fbe31dc8 | 264 | } |
bd597afc DV |
265 | _47.style.left="0px"; |
266 | _47.style.textAlign="right"; | |
267 | _47.style.width=this.options.yAxisLabelWidth+"px"; | |
268 | this.container.appendChild(_47); | |
269 | this.ylabels.push(_47); | |
2160ed4a | 270 | } |
bd597afc DV |
271 | var _49=this.ylabels[0]; |
272 | var _50=this.options.axisLabelFontSize; | |
273 | var _51=parseInt(_49.style.top)+_50; | |
274 | if(_51>this.height-_50){ | |
275 | _49.style.top=(parseInt(_49.style.top)-_50/2)+"px"; | |
fbe31dc8 DV |
276 | } |
277 | } | |
b0c3b730 DV |
278 | _40.beginPath(); |
279 | _40.moveTo(this.area.x,this.area.y); | |
280 | _40.lineTo(this.area.x,this.area.y+this.area.h); | |
281 | _40.closePath(); | |
282 | _40.stroke(); | |
fbe31dc8 DV |
283 | } |
284 | if(this.options.drawXAxis){ | |
285 | if(this.layout.xticks){ | |
2160ed4a | 286 | for(var i=0;i<this.layout.xticks.length;i++){ |
bd597afc | 287 | var _46=this.layout.xticks[i]; |
fbe31dc8 DV |
288 | if(typeof (dataset)=="function"){ |
289 | return; | |
290 | } | |
bd597afc | 291 | var x=this.area.x+_46[0]*this.area.w; |
fbe31dc8 | 292 | var y=this.area.y+this.area.h; |
b0c3b730 DV |
293 | _40.beginPath(); |
294 | _40.moveTo(x,y); | |
295 | _40.lineTo(x,y+this.options.axisTickSize); | |
296 | _40.closePath(); | |
297 | _40.stroke(); | |
bd597afc DV |
298 | var _47=_42(_46[1]); |
299 | _47.style.textAlign="center"; | |
300 | _47.style.bottom="0px"; | |
301 | var _52=(x-this.options.axisLabelWidth/2); | |
302 | if(_52+this.options.axisLabelWidth>this.width){ | |
303 | _52=this.width-this.options.xAxisLabelWidth; | |
304 | _47.style.textAlign="right"; | |
b0c3b730 | 305 | } |
bd597afc DV |
306 | if(_52<0){ |
307 | _52=0; | |
308 | _47.style.textAlign="left"; | |
b0c3b730 | 309 | } |
bd597afc DV |
310 | _47.style.left=_52+"px"; |
311 | _47.style.width=this.options.xAxisLabelWidth+"px"; | |
312 | this.container.appendChild(_47); | |
313 | this.xlabels.push(_47); | |
b0c3b730 DV |
314 | } |
315 | } | |
316 | _40.beginPath(); | |
317 | _40.moveTo(this.area.x,this.area.y+this.area.h); | |
318 | _40.lineTo(this.area.x+this.area.w,this.area.y+this.area.h); | |
319 | _40.closePath(); | |
320 | _40.stroke(); | |
321 | } | |
322 | _40.restore(); | |
efe0829a | 323 | }; |
fbe31dc8 | 324 | DygraphCanvasRenderer.prototype._renderLineChart=function(){ |
bd597afc DV |
325 | var _53=this.element.getContext("2d"); |
326 | var _54=this.options.colorScheme.length; | |
327 | var _55=this.options.colorScheme; | |
21d3323f | 328 | var _56=this.layout.options.errorBars; |
9c97d733 DV |
329 | var _57=[]; |
330 | for(var _58 in this.layout.datasets){ | |
1d54a333 | 331 | if(this.layout.datasets.hasOwnProperty(_58)){ |
9c97d733 | 332 | _57.push(_58); |
21d3323f | 333 | } |
1d54a333 | 334 | } |
9c97d733 | 335 | var _59=_57.length; |
2160ed4a | 336 | for(var i=0;i<this.layout.points.length;i++){ |
9c97d733 DV |
337 | var _60=this.layout.points[i]; |
338 | _60.canvasx=this.area.w*_60.x+this.area.x; | |
339 | _60.canvasy=this.area.h*_60.y+this.area.y; | |
2160ed4a | 340 | } |
9c97d733 | 341 | var _61=function(x){ |
9317362d DV |
342 | return x&&!isNaN(x); |
343 | }; | |
9c97d733 DV |
344 | var ctx=_53; |
345 | if(_56){ | |
346 | for(var i=0;i<_59;i++){ | |
347 | var _62=_57[i]; | |
348 | var _63=_55[i%_54]; | |
349 | ctx.save(); | |
350 | ctx.strokeStyle=_63; | |
f474c2a3 | 351 | ctx.lineWidth=this.options.strokeWidth; |
9c97d733 DV |
352 | var _64=-1; |
353 | var _65=[-1,-1]; | |
354 | var _66=0; | |
355 | var _67=this.layout.yscale; | |
356 | var rgb=new RGBColor(_63); | |
357 | var _69="rgba("+rgb.r+","+rgb.g+","+rgb.b+",0.15)"; | |
358 | ctx.fillStyle=_69; | |
9317362d | 359 | ctx.beginPath(); |
9c97d733 DV |
360 | for(var j=0;j<this.layout.points.length;j++){ |
361 | var _60=this.layout.points[j]; | |
362 | _66++; | |
363 | if(_60.name==_62){ | |
364 | if(!_60.y||isNaN(_60.y)){ | |
365 | _64=-1; | |
366 | continue; | |
367 | } | |
368 | var _70=[_60.y-_60.errorPlus*_67,_60.y+_60.errorMinus*_67]; | |
369 | _70[0]=this.area.h*_70[0]+this.area.y; | |
370 | _70[1]=this.area.h*_70[1]+this.area.y; | |
371 | if(_64>=0){ | |
372 | ctx.moveTo(_64,_65[0]); | |
373 | ctx.lineTo(_60.canvasx,_70[0]); | |
374 | ctx.lineTo(_60.canvasx,_70[1]); | |
375 | ctx.lineTo(_64,_65[1]); | |
376 | ctx.closePath(); | |
9317362d | 377 | } |
9c97d733 DV |
378 | _65[0]=_70[0]; |
379 | _65[1]=_70[1]; | |
380 | _64=_60.canvasx; | |
b2a516b8 | 381 | } |
648acd28 | 382 | } |
9c97d733 | 383 | ctx.fill(); |
b2a516b8 | 384 | } |
b2a516b8 | 385 | } |
9c97d733 DV |
386 | for(var i=0;i<_59;i++){ |
387 | var _62=_57[i]; | |
388 | var _63=_55[i%_54]; | |
bd597afc | 389 | _53.save(); |
9c97d733 DV |
390 | var _60=this.layout.points[0]; |
391 | var _71=this.dygraph_.attr_("pointSize"); | |
392 | var _64=null,prevY=null; | |
393 | var _72=this.dygraph_.attr_("drawPoints"); | |
394 | var _73=this.layout.points; | |
395 | for(var j=0;j<_73.length;j++){ | |
396 | var _60=_73[j]; | |
397 | if(_60.name==_62){ | |
398 | if(!_61(_60.canvasy)){ | |
399 | _64=prevY=null; | |
400 | }else{ | |
401 | var _74=(!_64&&(j==_73.length-1||!_61(_73[j+1].canvasy))); | |
402 | if(!_64){ | |
403 | _64=_60.canvasx; | |
404 | prevY=_60.canvasy; | |
405 | }else{ | |
5fb1199a | 406 | ctx.beginPath(); |
9c97d733 DV |
407 | ctx.strokeStyle=_63; |
408 | ctx.lineWidth=this.options.strokeWidth; | |
409 | ctx.moveTo(_64,prevY); | |
410 | _64=_60.canvasx; | |
411 | prevY=_60.canvasy; | |
412 | ctx.lineTo(_64,prevY); | |
413 | ctx.stroke(); | |
648acd28 | 414 | } |
9c97d733 DV |
415 | if(_72||_74){ |
416 | ctx.beginPath(); | |
417 | ctx.fillStyle=_63; | |
681a238e | 418 | ctx.arc(_60.canvasx,_60.canvasy,_71,0,2*Math.PI,false); |
9c97d733 | 419 | ctx.fill(); |
5fb1199a | 420 | } |
b2a516b8 | 421 | } |
b2a516b8 | 422 | } |
b2a516b8 | 423 | } |
b2a516b8 | 424 | } |
bd597afc | 425 | _53.restore(); |
6a1aa64f | 426 | }; |
9c97d733 | 427 | Dygraph=function(div,_75,_76){ |
b2a516b8 | 428 | if(arguments.length>0){ |
285a6bda DV |
429 | if(arguments.length==4){ |
430 | this.warn("Using deprecated four-argument dygraph constructor"); | |
9c97d733 | 431 | this.__old_init__(div,_75,arguments[2],arguments[3]); |
285a6bda | 432 | }else{ |
9c97d733 | 433 | this.__init__(div,_75,_76); |
285a6bda | 434 | } |
b2a516b8 | 435 | } |
6a1aa64f | 436 | }; |
285a6bda DV |
437 | Dygraph.NAME="Dygraph"; |
438 | Dygraph.VERSION="1.2"; | |
439 | Dygraph.__repr__=function(){ | |
b2a516b8 | 440 | return "["+this.NAME+" "+this.VERSION+"]"; |
6a1aa64f | 441 | }; |
285a6bda | 442 | Dygraph.toString=function(){ |
b2a516b8 | 443 | return this.__repr__(); |
6a1aa64f | 444 | }; |
285a6bda DV |
445 | Dygraph.DEFAULT_ROLL_PERIOD=1; |
446 | Dygraph.DEFAULT_WIDTH=480; | |
447 | Dygraph.DEFAULT_HEIGHT=320; | |
448 | Dygraph.AXIS_LINE_WIDTH=0.3; | |
aa8aa4e8 | 449 | Dygraph.DEFAULT_ATTRS={highlightCircleSize:3,pixelsPerXLabel:60,pixelsPerYLabel:30,labelsDivWidth:250,labelsDivStyles:{},labelsSeparateLines:false,labelsKMB:false,labelsKMG2:false,strokeWidth:1,axisTickSize:3,axisLabelFontSize:14,xAxisLabelWidth:50,yAxisLabelWidth:50,rightGap:5,showRoller:false,xValueFormatter:Dygraph.dateString_,xValueParser:Dygraph.dateParser,xTicker:Dygraph.dateTicker,delimiter:",",sigma:2,errorBars:false,fractions:false,wilsonInterval:true,customBars:false}; |
285a6bda DV |
450 | Dygraph.DEBUG=1; |
451 | Dygraph.INFO=2; | |
452 | Dygraph.WARNING=3; | |
453 | Dygraph.ERROR=3; | |
9c97d733 DV |
454 | Dygraph.prototype.__old_init__=function(div,_77,_78,_79){ |
455 | if(_78!=null){ | |
456 | var _80=["Date"]; | |
457 | for(var i=0;i<_78.length;i++){ | |
458 | _80.push(_78[i]); | |
285a6bda | 459 | } |
9c97d733 | 460 | Dygraph.update(_79,{"labels":_80}); |
285a6bda | 461 | } |
9c97d733 | 462 | this.__init__(div,_77,_79); |
285a6bda | 463 | }; |
9c97d733 DV |
464 | Dygraph.prototype.__init__=function(div,_81,_82){ |
465 | if(_82==null){ | |
466 | _82={}; | |
285a6bda | 467 | } |
b2a516b8 | 468 | this.maindiv_=div; |
9c97d733 DV |
469 | this.file_=_81; |
470 | this.rollPeriod_=_82.rollPeriod||Dygraph.DEFAULT_ROLL_PERIOD; | |
b2a516b8 | 471 | this.previousVerticalX_=-1; |
9c97d733 DV |
472 | this.fractions_=_82.fractions||false; |
473 | this.dateWindow_=_82.dateWindow||null; | |
474 | this.valueRange_=_82.valueRange||null; | |
475 | this.wilsonInterval_=_82.wilsonInterval||true; | |
caf49918 | 476 | div.innerHTML=""; |
285a6bda DV |
477 | if(div.style.width==""){ |
478 | div.style.width=Dygraph.DEFAULT_WIDTH+"px"; | |
479 | } | |
480 | if(div.style.height==""){ | |
481 | div.style.height=Dygraph.DEFAULT_HEIGHT+"px"; | |
482 | } | |
b2a516b8 DV |
483 | this.width_=parseInt(div.style.width,10); |
484 | this.height_=parseInt(div.style.height,10); | |
285a6bda | 485 | this.user_attrs_={}; |
9c97d733 | 486 | Dygraph.update(this.user_attrs_,_82); |
b8339f6e | 487 | this.attrs_={}; |
9c97d733 | 488 | Dygraph.update(this.attrs_,Dygraph.DEFAULT_ATTRS); |
285a6bda | 489 | this.labelsFromCSV_=(this.attr_("labels")==null); |
b2a516b8 | 490 | this.createInterface_(); |
b2a516b8 | 491 | this.start_(); |
6a1aa64f | 492 | }; |
9c97d733 DV |
493 | Dygraph.prototype.attr_=function(_83){ |
494 | if(typeof (this.user_attrs_[_83])!="undefined"){ | |
495 | return this.user_attrs_[_83]; | |
285a6bda | 496 | }else{ |
9c97d733 DV |
497 | if(typeof (this.attrs_[_83])!="undefined"){ |
498 | return this.attrs_[_83]; | |
285a6bda DV |
499 | }else{ |
500 | return null; | |
501 | } | |
502 | } | |
503 | }; | |
9c97d733 | 504 | Dygraph.prototype.log=function(_84,_85){ |
285a6bda | 505 | if(typeof (console)!="undefined"){ |
9c97d733 | 506 | switch(_84){ |
285a6bda | 507 | case Dygraph.DEBUG: |
9c97d733 | 508 | console.debug("dygraphs: "+_85); |
285a6bda DV |
509 | break; |
510 | case Dygraph.INFO: | |
9c97d733 | 511 | console.info("dygraphs: "+_85); |
285a6bda DV |
512 | break; |
513 | case Dygraph.WARNING: | |
9c97d733 | 514 | console.warn("dygraphs: "+_85); |
285a6bda DV |
515 | break; |
516 | case Dygraph.ERROR: | |
9c97d733 | 517 | console.error("dygraphs: "+_85); |
285a6bda DV |
518 | break; |
519 | } | |
520 | } | |
521 | }; | |
9c97d733 DV |
522 | Dygraph.prototype.info=function(_86){ |
523 | this.log(Dygraph.INFO,_86); | |
285a6bda | 524 | }; |
9c97d733 DV |
525 | Dygraph.prototype.warn=function(_87){ |
526 | this.log(Dygraph.WARNING,_87); | |
285a6bda | 527 | }; |
9c97d733 DV |
528 | Dygraph.prototype.error=function(_88){ |
529 | this.log(Dygraph.ERROR,_88); | |
285a6bda DV |
530 | }; |
531 | Dygraph.prototype.rollPeriod=function(){ | |
b2a516b8 DV |
532 | return this.rollPeriod_; |
533 | }; | |
76171648 | 534 | Dygraph.addEvent=function(el,evt,fn){ |
9c97d733 | 535 | var _91=function(e){ |
76171648 DV |
536 | if(!e){ |
537 | var e=window.event; | |
538 | } | |
539 | fn(e); | |
540 | }; | |
541 | if(window.addEventListener){ | |
9c97d733 | 542 | el.addEventListener(evt,_91,false); |
76171648 | 543 | }else{ |
9c97d733 | 544 | el.attachEvent("on"+evt,_91); |
76171648 DV |
545 | } |
546 | }; | |
285a6bda | 547 | Dygraph.prototype.createInterface_=function(){ |
9c97d733 | 548 | var _93=this.maindiv_; |
b0c3b730 DV |
549 | this.graphDiv=document.createElement("div"); |
550 | this.graphDiv.style.width=this.width_+"px"; | |
551 | this.graphDiv.style.height=this.height_+"px"; | |
9c97d733 | 552 | _93.appendChild(this.graphDiv); |
681a238e | 553 | this.canvas_=Dygraph.createCanvas(); |
b0c3b730 DV |
554 | this.canvas_.style.position="absolute"; |
555 | this.canvas_.width=this.width_; | |
556 | this.canvas_.height=this.height_; | |
681a238e DV |
557 | this.canvas_.style.width=this.width_+"px"; |
558 | this.canvas_.style.height=this.height_+"px"; | |
b0c3b730 | 559 | this.graphDiv.appendChild(this.canvas_); |
b2a516b8 | 560 | this.hidden_=this.createPlotKitCanvas_(this.canvas_); |
9c97d733 | 561 | var _94=this; |
76171648 | 562 | Dygraph.addEvent(this.hidden_,"mousemove",function(e){ |
9c97d733 | 563 | _94.mouseMove_(e); |
b2a516b8 | 564 | }); |
76171648 | 565 | Dygraph.addEvent(this.hidden_,"mouseout",function(e){ |
9c97d733 | 566 | _94.mouseOut_(e); |
b2a516b8 | 567 | }); |
626e8a8b DV |
568 | this.layoutOptions_={"xOriginIsZero":false}; |
569 | Dygraph.update(this.layoutOptions_,this.attrs_); | |
570 | Dygraph.update(this.layoutOptions_,this.user_attrs_); | |
571 | Dygraph.update(this.layoutOptions_,{"errorBars":(this.attr_("errorBars")||this.attr_("customBars"))}); | |
572 | this.layout_=new DygraphLayout(this,this.layoutOptions_); | |
573 | this.renderOptions_={colorScheme:this.colors_,strokeColor:null,axisLineWidth:Dygraph.AXIS_LINE_WIDTH}; | |
574 | Dygraph.update(this.renderOptions_,this.attrs_); | |
575 | Dygraph.update(this.renderOptions_,this.user_attrs_); | |
576 | this.plotter_=new DygraphCanvasRenderer(this,this.hidden_,this.layout_,this.renderOptions_); | |
577 | this.createStatusMessage_(); | |
578 | this.createRollInterface_(); | |
579 | this.createDragInterface_(); | |
6a1aa64f | 580 | }; |
9c97d733 | 581 | Dygraph.prototype.createPlotKitCanvas_=function(_95){ |
681a238e | 582 | var h=Dygraph.createCanvas(); |
b2a516b8 | 583 | h.style.position="absolute"; |
9c97d733 DV |
584 | h.style.top=_95.style.top; |
585 | h.style.left=_95.style.left; | |
b2a516b8 DV |
586 | h.width=this.width_; |
587 | h.height=this.height_; | |
681a238e DV |
588 | h.style.width=this.width_+"px"; |
589 | h.style.height=this.height_+"px"; | |
b0c3b730 | 590 | this.graphDiv.appendChild(h); |
b2a516b8 DV |
591 | return h; |
592 | }; | |
9c97d733 | 593 | Dygraph.hsvToRGB=function(hue,_98,_99){ |
f474c2a3 | 594 | var red; |
9c97d733 | 595 | var _101; |
f474c2a3 | 596 | var blue; |
9c97d733 DV |
597 | if(_98===0){ |
598 | red=_99; | |
599 | _101=_99; | |
600 | blue=_99; | |
f474c2a3 DV |
601 | }else{ |
602 | var i=Math.floor(hue*6); | |
603 | var f=(hue*6)-i; | |
9c97d733 DV |
604 | var p=_99*(1-_98); |
605 | var q=_99*(1-(_98*f)); | |
606 | var t=_99*(1-(_98*(1-f))); | |
f474c2a3 DV |
607 | switch(i){ |
608 | case 1: | |
609 | red=q; | |
9c97d733 | 610 | _101=_99; |
f474c2a3 DV |
611 | blue=p; |
612 | break; | |
613 | case 2: | |
614 | red=p; | |
9c97d733 | 615 | _101=_99; |
f474c2a3 DV |
616 | blue=t; |
617 | break; | |
618 | case 3: | |
619 | red=p; | |
9c97d733 DV |
620 | _101=q; |
621 | blue=_99; | |
f474c2a3 DV |
622 | break; |
623 | case 4: | |
624 | red=t; | |
9c97d733 DV |
625 | _101=p; |
626 | blue=_99; | |
f474c2a3 DV |
627 | break; |
628 | case 5: | |
9c97d733 DV |
629 | red=_99; |
630 | _101=p; | |
f474c2a3 DV |
631 | blue=q; |
632 | break; | |
633 | case 6: | |
634 | case 0: | |
9c97d733 DV |
635 | red=_99; |
636 | _101=t; | |
f474c2a3 DV |
637 | blue=p; |
638 | break; | |
639 | } | |
640 | } | |
641 | red=Math.floor(255*red+0.5); | |
9c97d733 | 642 | _101=Math.floor(255*_101+0.5); |
f474c2a3 | 643 | blue=Math.floor(255*blue+0.5); |
9c97d733 | 644 | return "rgb("+red+","+_101+","+blue+")"; |
f474c2a3 | 645 | }; |
285a6bda DV |
646 | Dygraph.prototype.setColors_=function(){ |
647 | var num=this.attr_("labels").length-1; | |
b2a516b8 | 648 | this.colors_=[]; |
9c97d733 DV |
649 | var _108=this.attr_("colors"); |
650 | if(!_108){ | |
285a6bda DV |
651 | var sat=this.attr_("colorSaturation")||1; |
652 | var val=this.attr_("colorValue")||0.5; | |
b2a516b8 DV |
653 | for(var i=1;i<=num;i++){ |
654 | var hue=(1*i/(1+num)); | |
f474c2a3 | 655 | this.colors_.push(Dygraph.hsvToRGB(hue,sat,val)); |
b2a516b8 DV |
656 | } |
657 | }else{ | |
658 | for(var i=0;i<num;i++){ | |
9c97d733 DV |
659 | var _111=_108[i%_108.length]; |
660 | this.colors_.push(_111); | |
b2a516b8 | 661 | } |
b2a516b8 | 662 | } |
285a6bda | 663 | this.renderOptions_.colorScheme=this.colors_; |
9c97d733 DV |
664 | Dygraph.update(this.plotter_.options,this.renderOptions_); |
665 | Dygraph.update(this.layoutOptions_,this.user_attrs_); | |
666 | Dygraph.update(this.layoutOptions_,this.attrs_); | |
b2a516b8 | 667 | }; |
3df0ccf0 | 668 | Dygraph.findPosX=function(obj){ |
9c97d733 | 669 | var _113=0; |
3df0ccf0 DV |
670 | if(obj.offsetParent){ |
671 | while(obj.offsetParent){ | |
9c97d733 | 672 | _113+=obj.offsetLeft; |
3df0ccf0 DV |
673 | obj=obj.offsetParent; |
674 | } | |
675 | }else{ | |
676 | if(obj.x){ | |
9c97d733 | 677 | _113+=obj.x; |
3df0ccf0 DV |
678 | } |
679 | } | |
9c97d733 | 680 | return _113; |
3df0ccf0 DV |
681 | }; |
682 | Dygraph.findPosY=function(obj){ | |
9c97d733 | 683 | var _114=0; |
3df0ccf0 DV |
684 | if(obj.offsetParent){ |
685 | while(obj.offsetParent){ | |
9c97d733 | 686 | _114+=obj.offsetTop; |
3df0ccf0 DV |
687 | obj=obj.offsetParent; |
688 | } | |
689 | }else{ | |
690 | if(obj.y){ | |
9c97d733 | 691 | _114+=obj.y; |
3df0ccf0 DV |
692 | } |
693 | } | |
9c97d733 | 694 | return _114; |
3df0ccf0 | 695 | }; |
285a6bda DV |
696 | Dygraph.prototype.createStatusMessage_=function(){ |
697 | if(!this.attr_("labelsDiv")){ | |
9c97d733 DV |
698 | var _115=this.attr_("labelsDivWidth"); |
699 | var _116={"position":"absolute","fontSize":"14px","zIndex":10,"width":_115+"px","top":"0px","left":(this.width_-_115-2)+"px","background":"white","textAlign":"left","overflow":"hidden"}; | |
700 | Dygraph.update(_116,this.attr_("labelsDivStyles")); | |
b0c3b730 | 701 | var div=document.createElement("div"); |
9c97d733 | 702 | for(var name in _116){ |
1d54a333 | 703 | if(_116.hasOwnProperty(name)){ |
9c97d733 | 704 | div.style[name]=_116[name]; |
b0c3b730 | 705 | } |
1d54a333 | 706 | } |
b0c3b730 | 707 | this.graphDiv.appendChild(div); |
285a6bda DV |
708 | this.attrs_.labelsDiv=div; |
709 | } | |
710 | }; | |
711 | Dygraph.prototype.createRollInterface_=function(){ | |
9c97d733 DV |
712 | var _118=this.attr_("showRoller")?"block":"none"; |
713 | var _119={"position":"absolute","zIndex":10,"top":(this.plotter_.area.h-25)+"px","left":(this.plotter_.area.x+1)+"px","display":_118}; | |
714 | var _120=document.createElement("input"); | |
715 | _120.type="text"; | |
716 | _120.size="2"; | |
717 | _120.value=this.rollPeriod_; | |
718 | for(var name in _119){ | |
1d54a333 | 719 | if(_119.hasOwnProperty(name)){ |
9c97d733 | 720 | _120.style[name]=_119[name]; |
b0c3b730 | 721 | } |
1d54a333 | 722 | } |
b2a516b8 | 723 | var pa=this.graphDiv; |
9c97d733 DV |
724 | pa.appendChild(_120); |
725 | var _122=this; | |
726 | _120.onchange=function(){ | |
727 | _122.adjustRoll(_120.value); | |
76171648 | 728 | }; |
9c97d733 | 729 | return _120; |
76171648 DV |
730 | }; |
731 | Dygraph.pageX=function(e){ | |
732 | if(e.pageX){ | |
733 | return (!e.pageX||e.pageX<0)?0:e.pageX; | |
734 | }else{ | |
735 | var de=document; | |
736 | var b=document.body; | |
737 | return e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); | |
738 | } | |
739 | }; | |
740 | Dygraph.pageY=function(e){ | |
741 | if(e.pageY){ | |
742 | return (!e.pageY||e.pageY<0)?0:e.pageY; | |
743 | }else{ | |
744 | var de=document; | |
745 | var b=document.body; | |
746 | return e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0); | |
747 | } | |
285a6bda DV |
748 | }; |
749 | Dygraph.prototype.createDragInterface_=function(){ | |
fbe31dc8 | 750 | var self=this; |
9c97d733 | 751 | var _126=false; |
c776c216 | 752 | var _127=false; |
9c97d733 DV |
753 | var _128=null; |
754 | var _129=null; | |
755 | var _130=null; | |
756 | var _131=null; | |
28e8f5ad DV |
757 | var _132=null; |
758 | var _133=null; | |
c776c216 | 759 | var _134=null; |
353a0294 DV |
760 | var px=0; |
761 | var py=0; | |
efe0829a | 762 | var getX=function(e){ |
76171648 | 763 | return Dygraph.pageX(e)-px; |
b2a516b8 | 764 | }; |
efe0829a | 765 | var getY=function(e){ |
76171648 | 766 | return Dygraph.pageX(e)-py; |
b2a516b8 | 767 | }; |
c776c216 | 768 | Dygraph.addEvent(this.hidden_,"mousemove",function(_139){ |
9c97d733 | 769 | if(_126){ |
c776c216 DV |
770 | _130=getX(_139); |
771 | _131=getY(_139); | |
772 | self.drawZoomRect_(_128,_130,_132); | |
773 | _132=_130; | |
28e8f5ad | 774 | }else{ |
c776c216 DV |
775 | if(_127){ |
776 | _130=getX(_139); | |
777 | _131=getY(_139); | |
778 | self.dateWindow_[0]=_133-(_130/self.width_)*_134; | |
779 | self.dateWindow_[1]=self.dateWindow_[0]+_134; | |
28e8f5ad DV |
780 | self.drawGraph_(self.rawData_); |
781 | } | |
6a1aa64f | 782 | } |
b2a516b8 | 783 | }); |
c776c216 | 784 | Dygraph.addEvent(this.hidden_,"mousedown",function(_140){ |
3df0ccf0 DV |
785 | px=Dygraph.findPosX(self.canvas_); |
786 | py=Dygraph.findPosY(self.canvas_); | |
c776c216 DV |
787 | _128=getX(_140); |
788 | _129=getY(_140); | |
2dab69c3 | 789 | if(_140.altKey||_140.shiftKey){ |
28e8f5ad DV |
790 | if(!self.dateWindow_){ |
791 | return; | |
792 | } | |
c776c216 DV |
793 | _127=true; |
794 | _134=self.dateWindow_[1]-self.dateWindow_[0]; | |
795 | _133=(_128/self.width_)*_134+self.dateWindow_[0]; | |
28e8f5ad DV |
796 | }else{ |
797 | _126=true; | |
798 | } | |
b2a516b8 | 799 | }); |
c776c216 DV |
800 | Dygraph.addEvent(document,"mouseup",function(_141){ |
801 | if(_126||_127){ | |
9c97d733 | 802 | _126=false; |
9c97d733 | 803 | _128=null; |
c776c216 | 804 | _129=null; |
6a1aa64f | 805 | } |
c776c216 DV |
806 | if(_127){ |
807 | _127=false; | |
28e8f5ad | 808 | _133=null; |
c776c216 | 809 | _134=null; |
28e8f5ad | 810 | } |
b2a516b8 | 811 | }); |
c776c216 | 812 | Dygraph.addEvent(this.hidden_,"mouseout",function(_142){ |
9c97d733 | 813 | if(_126){ |
9c97d733 | 814 | _130=null; |
c776c216 | 815 | _131=null; |
6a1aa64f | 816 | } |
b2a516b8 | 817 | }); |
c776c216 | 818 | Dygraph.addEvent(this.hidden_,"mouseup",function(_143){ |
9c97d733 DV |
819 | if(_126){ |
820 | _126=false; | |
c776c216 DV |
821 | _130=getX(_143); |
822 | _131=getY(_143); | |
28e8f5ad | 823 | var _144=Math.abs(_130-_128); |
c776c216 DV |
824 | var _145=Math.abs(_131-_129); |
825 | if(_144<2&&_145<2&&self.attr_("clickCallback")!=null&&self.lastx_!=undefined){ | |
826 | self.attr_("clickCallback")(_143,self.lastx_,self.selPoints_); | |
28e8f5ad | 827 | } |
c776c216 DV |
828 | if(_144>=10){ |
829 | self.doZoom_(Math.min(_128,_130),Math.max(_128,_130)); | |
b2a516b8 | 830 | }else{ |
fbe31dc8 | 831 | self.canvas_.getContext("2d").clearRect(0,0,self.canvas_.width,self.canvas_.height); |
b2a516b8 | 832 | } |
9c97d733 | 833 | _128=null; |
c776c216 | 834 | _129=null; |
b2a516b8 | 835 | } |
c776c216 DV |
836 | if(_127){ |
837 | _127=false; | |
28e8f5ad | 838 | _133=null; |
c776c216 | 839 | _134=null; |
28e8f5ad | 840 | } |
b2a516b8 | 841 | }); |
c776c216 | 842 | Dygraph.addEvent(this.hidden_,"dblclick",function(_146){ |
681a238e DV |
843 | if(self.dateWindow_==null){ |
844 | return; | |
845 | } | |
fbe31dc8 DV |
846 | self.dateWindow_=null; |
847 | self.drawGraph_(self.rawData_); | |
c776c216 DV |
848 | var _147=self.rawData_[0][0]; |
849 | var _148=self.rawData_[self.rawData_.length-1][0]; | |
fbe31dc8 | 850 | if(self.attr_("zoomCallback")){ |
c776c216 | 851 | self.attr_("zoomCallback")(_147,_148); |
67e650dc | 852 | } |
b2a516b8 | 853 | }); |
6a1aa64f | 854 | }; |
c776c216 | 855 | Dygraph.prototype.drawZoomRect_=function(_149,endX,_151){ |
b2a516b8 | 856 | var ctx=this.canvas_.getContext("2d"); |
c776c216 DV |
857 | if(_151){ |
858 | ctx.clearRect(Math.min(_149,_151),0,Math.abs(_149-_151),this.height_); | |
b2a516b8 | 859 | } |
c776c216 | 860 | if(endX&&_149){ |
b2a516b8 | 861 | ctx.fillStyle="rgba(128,128,128,0.33)"; |
c776c216 | 862 | ctx.fillRect(Math.min(_149,endX),0,Math.abs(endX-_149),this.height_); |
b2a516b8 DV |
863 | } |
864 | }; | |
c776c216 DV |
865 | Dygraph.prototype.doZoom_=function(lowX,_153){ |
866 | var _154=this.layout_.points; | |
28e8f5ad | 867 | var _155=null; |
c776c216 DV |
868 | var _156=null; |
869 | for(var i=0;i<_154.length;i++){ | |
870 | var cx=_154[i].canvasx; | |
871 | var x=_154[i].xval; | |
872 | if(cx<lowX&&(_155==null||x>_155)){ | |
28e8f5ad | 873 | _155=x; |
b2a516b8 | 874 | } |
c776c216 DV |
875 | if(cx>_153&&(_156==null||x<_156)){ |
876 | _156=x; | |
b2a516b8 | 877 | } |
b2a516b8 | 878 | } |
28e8f5ad | 879 | if(_155==null){ |
c776c216 | 880 | _155=_154[0].xval; |
b0c3b730 | 881 | } |
c776c216 DV |
882 | if(_156==null){ |
883 | _156=_154[_154.length-1].xval; | |
884 | } | |
885 | this.dateWindow_=[_155,_156]; | |
b2a516b8 | 886 | this.drawGraph_(this.rawData_); |
285a6bda | 887 | if(this.attr_("zoomCallback")){ |
c776c216 | 888 | this.attr_("zoomCallback")(_155,_156); |
67e650dc | 889 | } |
b2a516b8 | 890 | }; |
c776c216 DV |
891 | Dygraph.prototype.mouseMove_=function(_158){ |
892 | var _159=Dygraph.pageX(_158)-Dygraph.findPosX(this.hidden_); | |
893 | var _160=this.layout_.points; | |
28e8f5ad | 894 | var _161=-1; |
c776c216 DV |
895 | var _162=-1; |
896 | var _163=1e+100; | |
b2a516b8 | 897 | var idx=-1; |
c776c216 DV |
898 | for(var i=0;i<_160.length;i++){ |
899 | var dist=Math.abs(_160[i].canvasx-_159); | |
900 | if(dist>_163){ | |
b2a516b8 DV |
901 | break; |
902 | } | |
c776c216 | 903 | _163=dist; |
b2a516b8 DV |
904 | idx=i; |
905 | } | |
906 | if(idx>=0){ | |
c776c216 | 907 | _161=_160[idx].xval; |
b2a516b8 | 908 | } |
c776c216 DV |
909 | if(_159>_160[_160.length-1].canvasx){ |
910 | _161=_160[_160.length-1].xval; | |
b2a516b8 | 911 | } |
681a238e | 912 | this.selPoints_=[]; |
c776c216 DV |
913 | for(var i=0;i<_160.length;i++){ |
914 | if(_160[i].xval==_161){ | |
915 | this.selPoints_.push(_160[i]); | |
681a238e | 916 | } |
b2a516b8 | 917 | } |
681a238e | 918 | if(this.attr_("highlightCallback")){ |
c776c216 | 919 | this.attr_("highlightCallback")(_158,_161,this.selPoints_); |
b2a516b8 | 920 | } |
c776c216 | 921 | var _166=this.attr_("highlightCircleSize"); |
b2a516b8 DV |
922 | var ctx=this.canvas_.getContext("2d"); |
923 | if(this.previousVerticalX_>=0){ | |
924 | var px=this.previousVerticalX_; | |
c776c216 | 925 | ctx.clearRect(px-_166-1,0,2*_166+2,this.height_); |
b2a516b8 | 926 | } |
648acd28 DV |
927 | var isOK=function(x){ |
928 | return x&&!isNaN(x); | |
929 | }; | |
681a238e | 930 | if(this.selPoints_.length>0){ |
c776c216 DV |
931 | var _159=this.selPoints_[0].canvasx; |
932 | var _168=this.attr_("xValueFormatter")(_161,this)+":"; | |
b2a516b8 | 933 | var clen=this.colors_.length; |
681a238e DV |
934 | for(var i=0;i<this.selPoints_.length;i++){ |
935 | if(!isOK(this.selPoints_[i].canvasy)){ | |
648acd28 DV |
936 | continue; |
937 | } | |
285a6bda | 938 | if(this.attr_("labelsSeparateLines")){ |
c776c216 | 939 | _168+="<br/>"; |
b2a516b8 | 940 | } |
c776c216 | 941 | var _170=this.selPoints_[i]; |
f474c2a3 | 942 | var c=new RGBColor(this.colors_[i%clen]); |
c776c216 | 943 | _168+=" <b><font color='"+c.toHex()+"'>"+_170.name+"</font></b>:"+this.round_(_170.yval,2); |
b2a516b8 | 944 | } |
c776c216 DV |
945 | this.attr_("labelsDiv").innerHTML=_168; |
946 | this.lastx_=_161; | |
b2a516b8 | 947 | ctx.save(); |
681a238e DV |
948 | for(var i=0;i<this.selPoints_.length;i++){ |
949 | if(!isOK(this.selPoints_[i%clen].canvasy)){ | |
648acd28 DV |
950 | continue; |
951 | } | |
b2a516b8 | 952 | ctx.beginPath(); |
f474c2a3 | 953 | ctx.fillStyle=this.colors_[i%clen]; |
c776c216 | 954 | ctx.arc(_159,this.selPoints_[i%clen].canvasy,_166,0,2*Math.PI,false); |
b2a516b8 DV |
955 | ctx.fill(); |
956 | } | |
957 | ctx.restore(); | |
c776c216 | 958 | this.previousVerticalX_=_159; |
b2a516b8 | 959 | } |
6a1aa64f | 960 | }; |
c776c216 | 961 | Dygraph.prototype.mouseOut_=function(_172){ |
b2a516b8 DV |
962 | var ctx=this.canvas_.getContext("2d"); |
963 | ctx.clearRect(0,0,this.width_,this.height_); | |
285a6bda | 964 | this.attr_("labelsDiv").innerHTML=""; |
6a1aa64f | 965 | }; |
285a6bda | 966 | Dygraph.zeropad=function(x){ |
6372d433 DV |
967 | if(x<10){ |
968 | return "0"+x; | |
969 | }else{ | |
970 | return ""+x; | |
971 | } | |
972 | }; | |
285a6bda | 973 | Dygraph.prototype.hmsString_=function(date){ |
c776c216 | 974 | var _174=Dygraph.zeropad; |
6372d433 DV |
975 | var d=new Date(date); |
976 | if(d.getSeconds()){ | |
c776c216 | 977 | return _174(d.getHours())+":"+_174(d.getMinutes())+":"+_174(d.getSeconds()); |
6372d433 DV |
978 | }else{ |
979 | if(d.getMinutes()){ | |
c776c216 | 980 | return _174(d.getHours())+":"+_174(d.getMinutes()); |
6372d433 | 981 | }else{ |
c776c216 | 982 | return _174(d.getHours()); |
6372d433 DV |
983 | } |
984 | } | |
985 | }; | |
285a6bda | 986 | Dygraph.dateString_=function(date,self){ |
c776c216 | 987 | var _176=Dygraph.zeropad; |
b2a516b8 DV |
988 | var d=new Date(date); |
989 | var year=""+d.getFullYear(); | |
c776c216 DV |
990 | var _178=_176(d.getMonth()+1); |
991 | var day=_176(d.getDate()); | |
6372d433 DV |
992 | var ret=""; |
993 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
994 | if(frac){ | |
285a6bda | 995 | ret=" "+self.hmsString_(date); |
b2a516b8 | 996 | } |
c776c216 | 997 | return year+"/"+_178+"/"+day+ret; |
6a1aa64f | 998 | }; |
c776c216 DV |
999 | Dygraph.prototype.round_=function(num,_182){ |
1000 | var _183=Math.pow(10,_182); | |
1001 | return Math.round(num*_183)/_183; | |
6a1aa64f | 1002 | }; |
285a6bda | 1003 | Dygraph.prototype.loadedEvent_=function(data){ |
b2a516b8 DV |
1004 | this.rawData_=this.parseCSV_(data); |
1005 | this.drawGraph_(this.rawData_); | |
6a1aa64f | 1006 | }; |
285a6bda DV |
1007 | Dygraph.prototype.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; |
1008 | Dygraph.prototype.quarters=["Jan","Apr","Jul","Oct"]; | |
1009 | Dygraph.prototype.addXTicks_=function(){ | |
c776c216 | 1010 | var _185,endDate; |
b2a516b8 | 1011 | if(this.dateWindow_){ |
c776c216 | 1012 | _185=this.dateWindow_[0]; |
b2a516b8 DV |
1013 | endDate=this.dateWindow_[1]; |
1014 | }else{ | |
c776c216 | 1015 | _185=this.rawData_[0][0]; |
b2a516b8 DV |
1016 | endDate=this.rawData_[this.rawData_.length-1][0]; |
1017 | } | |
c776c216 DV |
1018 | var _186=this.attr_("xTicker")(_185,endDate,this); |
1019 | this.layout_.updateOptions({xTicks:_186}); | |
285a6bda DV |
1020 | }; |
1021 | Dygraph.SECONDLY=0; | |
3ef5b91a DV |
1022 | Dygraph.TWO_SECONDLY=1; |
1023 | Dygraph.FIVE_SECONDLY=2; | |
1024 | Dygraph.TEN_SECONDLY=3; | |
1025 | Dygraph.THIRTY_SECONDLY=4; | |
1026 | Dygraph.MINUTELY=5; | |
1027 | Dygraph.TWO_MINUTELY=6; | |
1028 | Dygraph.FIVE_MINUTELY=7; | |
1029 | Dygraph.TEN_MINUTELY=8; | |
1030 | Dygraph.THIRTY_MINUTELY=9; | |
1031 | Dygraph.HOURLY=10; | |
1032 | Dygraph.TWO_HOURLY=11; | |
1033 | Dygraph.SIX_HOURLY=12; | |
1034 | Dygraph.DAILY=13; | |
1035 | Dygraph.WEEKLY=14; | |
1036 | Dygraph.MONTHLY=15; | |
1037 | Dygraph.QUARTERLY=16; | |
1038 | Dygraph.BIANNUAL=17; | |
1039 | Dygraph.ANNUAL=18; | |
1040 | Dygraph.DECADAL=19; | |
1041 | Dygraph.NUM_GRANULARITIES=20; | |
285a6bda DV |
1042 | Dygraph.SHORT_SPACINGS=[]; |
1043 | Dygraph.SHORT_SPACINGS[Dygraph.SECONDLY]=1000*1; | |
3ef5b91a DV |
1044 | Dygraph.SHORT_SPACINGS[Dygraph.TWO_SECONDLY]=1000*2; |
1045 | Dygraph.SHORT_SPACINGS[Dygraph.FIVE_SECONDLY]=1000*5; | |
285a6bda DV |
1046 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_SECONDLY]=1000*10; |
1047 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_SECONDLY]=1000*30; | |
1048 | Dygraph.SHORT_SPACINGS[Dygraph.MINUTELY]=1000*60; | |
3ef5b91a DV |
1049 | Dygraph.SHORT_SPACINGS[Dygraph.TWO_MINUTELY]=1000*60*2; |
1050 | Dygraph.SHORT_SPACINGS[Dygraph.FIVE_MINUTELY]=1000*60*5; | |
285a6bda DV |
1051 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_MINUTELY]=1000*60*10; |
1052 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_MINUTELY]=1000*60*30; | |
1053 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600; | |
3ef5b91a | 1054 | Dygraph.SHORT_SPACINGS[Dygraph.TWO_HOURLY]=1000*3600*2; |
626e8a8b | 1055 | Dygraph.SHORT_SPACINGS[Dygraph.SIX_HOURLY]=1000*3600*6; |
285a6bda DV |
1056 | Dygraph.SHORT_SPACINGS[Dygraph.DAILY]=1000*86400; |
1057 | Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY]=1000*604800; | |
c776c216 DV |
1058 | Dygraph.prototype.NumXTicks=function(_187,_188,_189){ |
1059 | if(_189<Dygraph.MONTHLY){ | |
1060 | var _190=Dygraph.SHORT_SPACINGS[_189]; | |
1061 | return Math.floor(0.5+1*(_188-_187)/_190); | |
285a6bda | 1062 | }else{ |
c776c216 DV |
1063 | var _191=1; |
1064 | var _192=12; | |
1065 | if(_189==Dygraph.QUARTERLY){ | |
1066 | _192=3; | |
285a6bda | 1067 | } |
c776c216 DV |
1068 | if(_189==Dygraph.BIANNUAL){ |
1069 | _192=2; | |
285a6bda | 1070 | } |
c776c216 DV |
1071 | if(_189==Dygraph.ANNUAL){ |
1072 | _192=1; | |
285a6bda | 1073 | } |
c776c216 DV |
1074 | if(_189==Dygraph.DECADAL){ |
1075 | _192=1; | |
1076 | _191=10; | |
285a6bda | 1077 | } |
c776c216 DV |
1078 | var _193=365.2524*24*3600*1000; |
1079 | var _194=1*(_188-_187)/_193; | |
1080 | return Math.floor(0.5+1*_194*_192/_191); | |
285a6bda DV |
1081 | } |
1082 | }; | |
c776c216 DV |
1083 | Dygraph.prototype.GetXAxis=function(_195,_196,_197){ |
1084 | var _198=[]; | |
1085 | if(_197<Dygraph.MONTHLY){ | |
1086 | var _199=Dygraph.SHORT_SPACINGS[_197]; | |
1087 | var _200="%d%b"; | |
3ef5b91a | 1088 | var g=_199/1000; |
3ef5b91a DV |
1089 | var d=new Date(_195); |
1090 | if(g<=60){ | |
1091 | var x=d.getSeconds(); | |
1092 | d.setSeconds(x-x%g); | |
1093 | }else{ | |
1094 | d.setSeconds(0); | |
1095 | g/=60; | |
1096 | if(g<=60){ | |
1097 | var x=d.getMinutes(); | |
1098 | d.setMinutes(x-x%g); | |
1099 | }else{ | |
1100 | d.setMinutes(0); | |
1101 | g/=60; | |
1102 | if(g<=24){ | |
1103 | var x=d.getHours(); | |
1104 | d.setHours(x-x%g); | |
1105 | }else{ | |
1106 | d.setHours(0); | |
1107 | g/=24; | |
1108 | if(g==7){ | |
1109 | d.setDate(d.getDate()-d.getDay()); | |
1110 | } | |
1111 | } | |
bd597afc | 1112 | } |
3ef5b91a DV |
1113 | } |
1114 | _195=d.getTime(); | |
c776c216 | 1115 | for(var t=_195;t<=_196;t+=_199){ |
36615faf DV |
1116 | var d=new Date(t); |
1117 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
c776c216 DV |
1118 | if(frac==0||_197>=Dygraph.DAILY){ |
1119 | _198.push({v:t,label:new Date(t+3600*1000).strftime(_200)}); | |
b2a516b8 | 1120 | }else{ |
c776c216 | 1121 | _198.push({v:t,label:this.hmsString_(t)}); |
36615faf DV |
1122 | } |
1123 | } | |
b2a516b8 | 1124 | }else{ |
3ef5b91a DV |
1125 | var _202; |
1126 | var _203=1; | |
c776c216 | 1127 | if(_197==Dygraph.MONTHLY){ |
3ef5b91a | 1128 | _202=[0,1,2,3,4,5,6,7,8,9,10,11,12]; |
b2a516b8 | 1129 | }else{ |
c776c216 | 1130 | if(_197==Dygraph.QUARTERLY){ |
3ef5b91a | 1131 | _202=[0,3,6,9]; |
b2a516b8 | 1132 | }else{ |
c776c216 | 1133 | if(_197==Dygraph.BIANNUAL){ |
3ef5b91a | 1134 | _202=[0,6]; |
b2a516b8 | 1135 | }else{ |
c776c216 | 1136 | if(_197==Dygraph.ANNUAL){ |
3ef5b91a | 1137 | _202=[0]; |
6372d433 | 1138 | }else{ |
c776c216 | 1139 | if(_197==Dygraph.DECADAL){ |
3ef5b91a DV |
1140 | _202=[0]; |
1141 | _203=10; | |
b2a516b8 DV |
1142 | } |
1143 | } | |
1144 | } | |
1145 | } | |
6372d433 | 1146 | } |
3ef5b91a DV |
1147 | var _204=new Date(_195).getFullYear(); |
1148 | var _205=new Date(_196).getFullYear(); | |
1149 | var _206=Dygraph.zeropad; | |
1150 | for(var i=_204;i<=_205;i++){ | |
1151 | if(i%_203!=0){ | |
36615faf | 1152 | continue; |
6372d433 | 1153 | } |
3ef5b91a DV |
1154 | for(var j=0;j<_202.length;j++){ |
1155 | var _207=i+"/"+_206(1+_202[j])+"/01"; | |
1156 | var t=Date.parse(_207); | |
c776c216 | 1157 | if(t<_195||t>_196){ |
b2a516b8 DV |
1158 | continue; |
1159 | } | |
c776c216 | 1160 | _198.push({v:t,label:new Date(t).strftime("%b %y")}); |
b2a516b8 DV |
1161 | } |
1162 | } | |
b2a516b8 | 1163 | } |
c776c216 | 1164 | return _198; |
36615faf | 1165 | }; |
3ef5b91a DV |
1166 | Dygraph.dateTicker=function(_208,_209,self){ |
1167 | var _210=-1; | |
285a6bda | 1168 | for(var i=0;i<Dygraph.NUM_GRANULARITIES;i++){ |
3ef5b91a DV |
1169 | var _211=self.NumXTicks(_208,_209,i); |
1170 | if(self.width_/_211>=self.attr_("pixelsPerXLabel")){ | |
1171 | _210=i; | |
36615faf DV |
1172 | break; |
1173 | } | |
b2a516b8 | 1174 | } |
3ef5b91a DV |
1175 | if(_210>=0){ |
1176 | return self.GetXAxis(_208,_209,_210); | |
36615faf | 1177 | }else{ |
6372d433 | 1178 | } |
6a1aa64f | 1179 | }; |
285a6bda | 1180 | Dygraph.numericTicks=function(minV,maxV,self){ |
f09e46d4 | 1181 | if(self.attr_("labelsKMG2")){ |
3ef5b91a | 1182 | var _214=[1,2,4,8]; |
f09e46d4 | 1183 | }else{ |
3ef5b91a | 1184 | var _214=[1,2,5]; |
f09e46d4 | 1185 | } |
3ef5b91a DV |
1186 | var _215,low_val,high_val,nTicks; |
1187 | var _216=self.attr_("pixelsPerYLabel"); | |
2ce09b19 | 1188 | for(var i=-10;i<50;i++){ |
f09e46d4 | 1189 | if(self.attr_("labelsKMG2")){ |
3ef5b91a | 1190 | var _217=Math.pow(16,i); |
f09e46d4 | 1191 | }else{ |
3ef5b91a DV |
1192 | var _217=Math.pow(10,i); |
1193 | } | |
1194 | for(var j=0;j<_214.length;j++){ | |
1195 | _215=_217*_214[j]; | |
1196 | low_val=Math.floor(minV/_215)*_215; | |
1197 | high_val=Math.ceil(maxV/_215)*_215; | |
1198 | nTicks=(high_val-low_val)/_215; | |
1199 | var _218=self.height_/nTicks; | |
1200 | if(_218>_216){ | |
2ce09b19 | 1201 | break; |
6a1aa64f | 1202 | } |
b2a516b8 | 1203 | } |
3ef5b91a | 1204 | if(_218>_216){ |
2ce09b19 | 1205 | break; |
b2a516b8 | 1206 | } |
2ce09b19 | 1207 | } |
3ef5b91a | 1208 | var _219=[]; |
28e8f5ad | 1209 | var k; |
3ef5b91a | 1210 | var _221=[]; |
285a6bda | 1211 | if(self.attr_("labelsKMB")){ |
aa8aa4e8 | 1212 | k=1000; |
3ef5b91a | 1213 | _221=["K","M","B","T"]; |
aa8aa4e8 DV |
1214 | } |
1215 | if(self.attr_("labelsKMG2")){ | |
1216 | if(k){ | |
1217 | self.warn("Setting both labelsKMB and labelsKMG2. Pick one!"); | |
b2a516b8 | 1218 | } |
aa8aa4e8 | 1219 | k=1024; |
3ef5b91a | 1220 | _221=["k","M","G","T"]; |
aa8aa4e8 DV |
1221 | } |
1222 | for(var i=0;i<nTicks;i++){ | |
3ef5b91a DV |
1223 | var _222=low_val+i*_215; |
1224 | var _223=Math.abs(_222); | |
1225 | var _224=self.round_(_222,2); | |
1226 | if(_221.length){ | |
aa8aa4e8 DV |
1227 | var n=k*k*k*k; |
1228 | for(var j=3;j>=0;j--,n/=k){ | |
3ef5b91a DV |
1229 | if(_223>=n){ |
1230 | _224=self.round_(_222/n,1)+_221[j]; | |
aa8aa4e8 | 1231 | break; |
b2a516b8 DV |
1232 | } |
1233 | } | |
1234 | } | |
3ef5b91a | 1235 | _219.push({label:_224,v:_222}); |
b2a516b8 | 1236 | } |
3ef5b91a | 1237 | return _219; |
6a1aa64f | 1238 | }; |
285a6bda | 1239 | Dygraph.prototype.addYTicks_=function(minY,maxY){ |
3ef5b91a DV |
1240 | var _228=Dygraph.numericTicks(minY,maxY,this); |
1241 | this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_228}); | |
6a1aa64f | 1242 | }; |
3ef5b91a | 1243 | Dygraph.prototype.extremeValues_=function(_229){ |
e4007107 | 1244 | var minY=null,maxY=null; |
b64a4f1a | 1245 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
648acd28 | 1246 | if(bars){ |
3ef5b91a DV |
1247 | for(var j=0;j<_229.length;j++){ |
1248 | var y=_229[j][1][0]; | |
648acd28 DV |
1249 | if(!y){ |
1250 | continue; | |
e4007107 | 1251 | } |
3ef5b91a DV |
1252 | var low=y-_229[j][1][1]; |
1253 | var high=y+_229[j][1][2]; | |
648acd28 DV |
1254 | if(low>y){ |
1255 | low=y; | |
b2a516b8 | 1256 | } |
648acd28 DV |
1257 | if(high<y){ |
1258 | high=y; | |
b2a516b8 | 1259 | } |
648acd28 DV |
1260 | if(maxY==null||high>maxY){ |
1261 | maxY=high; | |
285a6bda | 1262 | } |
648acd28 DV |
1263 | if(minY==null||low<minY){ |
1264 | minY=low; | |
e4007107 | 1265 | } |
285a6bda | 1266 | } |
b2a516b8 | 1267 | }else{ |
3ef5b91a DV |
1268 | for(var j=0;j<_229.length;j++){ |
1269 | var y=_229[j][1]; | |
28e8f5ad | 1270 | if(y===null||isNaN(y)){ |
648acd28 | 1271 | continue; |
285a6bda | 1272 | } |
b2a516b8 | 1273 | if(maxY==null||y>maxY){ |
285a6bda DV |
1274 | maxY=y; |
1275 | } | |
e4007107 DV |
1276 | if(minY==null||y<minY){ |
1277 | minY=y; | |
1278 | } | |
b2a516b8 DV |
1279 | } |
1280 | } | |
648acd28 DV |
1281 | return [minY,maxY]; |
1282 | }; | |
1283 | Dygraph.prototype.drawGraph_=function(data){ | |
1284 | var minY=null,maxY=null; | |
1285 | this.layout_.removeAllDatasets(); | |
1286 | this.setColors_(); | |
9317362d | 1287 | this.attrs_["pointSize"]=0.5*this.attr_("highlightCircleSize"); |
648acd28 | 1288 | for(var i=1;i<data[0].length;i++){ |
3ef5b91a | 1289 | var _233=[]; |
648acd28 DV |
1290 | for(var j=0;j<data.length;j++){ |
1291 | var date=data[j][0]; | |
3ef5b91a | 1292 | _233[j]=[date,data[j][i]]; |
648acd28 | 1293 | } |
3ef5b91a | 1294 | _233=this.rollingAverage(_233,this.rollPeriod_); |
b64a4f1a | 1295 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
648acd28 DV |
1296 | if(this.dateWindow_){ |
1297 | var low=this.dateWindow_[0]; | |
1298 | var high=this.dateWindow_[1]; | |
3ef5b91a DV |
1299 | var _234=[]; |
1300 | for(var k=0;k<_233.length;k++){ | |
1301 | if(_233[k][0]>=low&&_233[k][0]<=high){ | |
1302 | _234.push(_233[k]); | |
648acd28 DV |
1303 | } |
1304 | } | |
3ef5b91a | 1305 | _233=_234; |
648acd28 | 1306 | } |
3ef5b91a DV |
1307 | var _235=this.extremeValues_(_233); |
1308 | var _236=_235[0]; | |
1309 | var _237=_235[1]; | |
1310 | if(!minY||_236<minY){ | |
1311 | minY=_236; | |
648acd28 | 1312 | } |
3ef5b91a DV |
1313 | if(!maxY||_237>maxY){ |
1314 | maxY=_237; | |
b2a516b8 DV |
1315 | } |
1316 | if(bars){ | |
1317 | var vals=[]; | |
3ef5b91a DV |
1318 | for(var j=0;j<_233.length;j++){ |
1319 | vals[j]=[_233[j][0],_233[j][1][0],_233[j][1][1],_233[j][1][2]]; | |
b2a516b8 | 1320 | } |
285a6bda | 1321 | this.layout_.addDataset(this.attr_("labels")[i],vals); |
b2a516b8 | 1322 | }else{ |
3ef5b91a | 1323 | this.layout_.addDataset(this.attr_("labels")[i],_233); |
b2a516b8 DV |
1324 | } |
1325 | } | |
1326 | if(this.valueRange_!=null){ | |
1327 | this.addYTicks_(this.valueRange_[0],this.valueRange_[1]); | |
1328 | }else{ | |
e4007107 | 1329 | var span=maxY-minY; |
3ef5b91a DV |
1330 | var _240=maxY+0.1*span; |
1331 | var _241=minY-0.1*span; | |
1332 | if(_241<0&&minY>=0){ | |
1333 | _241=0; | |
e4007107 | 1334 | } |
3ef5b91a DV |
1335 | if(_240>0&&maxY<=0){ |
1336 | _240=0; | |
681a238e | 1337 | } |
e4007107 DV |
1338 | if(this.attr_("includeZero")){ |
1339 | if(maxY<0){ | |
3ef5b91a | 1340 | _240=0; |
e4007107 DV |
1341 | } |
1342 | if(minY>0){ | |
3ef5b91a | 1343 | _241=0; |
e4007107 | 1344 | } |
b2a516b8 | 1345 | } |
3ef5b91a | 1346 | this.addYTicks_(_241,_240); |
b2a516b8 DV |
1347 | } |
1348 | this.addXTicks_(); | |
28e8f5ad | 1349 | this.layout_.updateOptions({dateWindow:this.dateWindow_}); |
b2a516b8 DV |
1350 | this.layout_.evaluateWithError(); |
1351 | this.plotter_.clear(); | |
1352 | this.plotter_.render(); | |
1353 | this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height); | |
6a1aa64f | 1354 | }; |
3ef5b91a DV |
1355 | Dygraph.prototype.rollingAverage=function(_242,_243){ |
1356 | if(_242.length<2){ | |
1357 | return _242; | |
b2a516b8 | 1358 | } |
3ef5b91a DV |
1359 | var _243=Math.min(_243,_242.length-1); |
1360 | var _244=[]; | |
1361 | var _245=this.attr_("sigma"); | |
b2a516b8 DV |
1362 | if(this.fractions_){ |
1363 | var num=0; | |
1364 | var den=0; | |
1365 | var mult=100; | |
3ef5b91a DV |
1366 | for(var i=0;i<_242.length;i++){ |
1367 | num+=_242[i][1][0]; | |
1368 | den+=_242[i][1][1]; | |
1369 | if(i-_243>=0){ | |
1370 | num-=_242[i-_243][1][0]; | |
1371 | den-=_242[i-_243][1][1]; | |
1372 | } | |
1373 | var date=_242[i][0]; | |
1374 | var _248=den?num/den:0; | |
285a6bda | 1375 | if(this.attr_("errorBars")){ |
b2a516b8 DV |
1376 | if(this.wilsonInterval_){ |
1377 | if(den){ | |
3ef5b91a DV |
1378 | var p=_248<0?0:_248,n=den; |
1379 | var pm=_245*Math.sqrt(p*(1-p)/n+_245*_245/(4*n*n)); | |
1380 | var _250=1+_245*_245/den; | |
1381 | var low=(p+_245*_245/(2*den)-pm)/_250; | |
1382 | var high=(p+_245*_245/(2*den)+pm)/_250; | |
1383 | _244[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; | |
b2a516b8 | 1384 | }else{ |
3ef5b91a | 1385 | _244[i]=[date,[0,0,0]]; |
b2a516b8 DV |
1386 | } |
1387 | }else{ | |
3ef5b91a DV |
1388 | var _251=den?_245*Math.sqrt(_248*(1-_248)/den):1; |
1389 | _244[i]=[date,[mult*_248,mult*_251,mult*_251]]; | |
b2a516b8 DV |
1390 | } |
1391 | }else{ | |
3ef5b91a | 1392 | _244[i]=[date,mult*_248]; |
b2a516b8 DV |
1393 | } |
1394 | } | |
1395 | }else{ | |
b64a4f1a | 1396 | if(this.attr_("customBars")){ |
6372d433 DV |
1397 | var low=0; |
1398 | var mid=0; | |
1399 | var high=0; | |
3ef5b91a DV |
1400 | var _253=0; |
1401 | for(var i=0;i<_242.length;i++){ | |
1402 | var data=_242[i][1]; | |
b2a516b8 | 1403 | var y=data[1]; |
3ef5b91a | 1404 | _244[i]=[_242[i][0],[y,y-data[0],data[2]-y]]; |
e244a0d7 | 1405 | if(y!=null&&!isNaN(y)){ |
6372d433 DV |
1406 | low+=data[0]; |
1407 | mid+=y; | |
1408 | high+=data[2]; | |
3ef5b91a | 1409 | _253+=1; |
49a7d0d5 | 1410 | } |
3ef5b91a DV |
1411 | if(i-_243>=0){ |
1412 | var prev=_242[i-_243]; | |
e244a0d7 | 1413 | if(prev[1][1]!=null&&!isNaN(prev[1][1])){ |
6372d433 DV |
1414 | low-=prev[1][0]; |
1415 | mid-=prev[1][1]; | |
1416 | high-=prev[1][2]; | |
3ef5b91a | 1417 | _253-=1; |
6372d433 | 1418 | } |
49a7d0d5 | 1419 | } |
3ef5b91a | 1420 | _244[i]=[_242[i][0],[1*mid/_253,1*(mid-low)/_253,1*(high-mid)/_253]]; |
6372d433 DV |
1421 | } |
1422 | }else{ | |
3ef5b91a | 1423 | var _255=Math.min(_243-1,_242.length-2); |
285a6bda | 1424 | if(!this.attr_("errorBars")){ |
3ef5b91a DV |
1425 | if(_243==1){ |
1426 | return _242; | |
648acd28 | 1427 | } |
3ef5b91a | 1428 | for(var i=0;i<_242.length;i++){ |
b2a516b8 | 1429 | var sum=0; |
3ef5b91a DV |
1430 | var _257=0; |
1431 | for(var j=Math.max(0,i-_243+1);j<i+1;j++){ | |
1432 | var y=_242[j][1]; | |
e244a0d7 | 1433 | if(y==null||isNaN(y)){ |
648acd28 | 1434 | continue; |
b2a516b8 | 1435 | } |
3ef5b91a DV |
1436 | _257++; |
1437 | sum+=_242[j][1]; | |
648acd28 | 1438 | } |
3ef5b91a DV |
1439 | if(_257){ |
1440 | _244[i]=[_242[i][0],sum/_257]; | |
648acd28 | 1441 | }else{ |
3ef5b91a | 1442 | _244[i]=[_242[i][0],null]; |
b2a516b8 | 1443 | } |
648acd28 | 1444 | } |
2847c1cf | 1445 | }else{ |
3ef5b91a | 1446 | for(var i=0;i<_242.length;i++){ |
b2a516b8 | 1447 | var sum=0; |
3ef5b91a | 1448 | var _258=0; |
c776c216 | 1449 | var _257=0; |
3ef5b91a DV |
1450 | for(var j=Math.max(0,i-_243+1);j<i+1;j++){ |
1451 | var y=_242[j][1][0]; | |
e244a0d7 | 1452 | if(y==null||isNaN(y)){ |
648acd28 | 1453 | continue; |
b2a516b8 | 1454 | } |
3ef5b91a DV |
1455 | _257++; |
1456 | sum+=_242[j][1][0]; | |
1457 | _258+=Math.pow(_242[j][1][1],2); | |
b2a516b8 | 1458 | } |
3ef5b91a DV |
1459 | if(_257){ |
1460 | var _251=Math.sqrt(_258)/_257; | |
1461 | _244[i]=[_242[i][0],[sum/_257,_245*_251,_245*_251]]; | |
648acd28 | 1462 | }else{ |
3ef5b91a | 1463 | _244[i]=[_242[i][0],[null,null,null]]; |
b2a516b8 DV |
1464 | } |
1465 | } | |
1466 | } | |
648acd28 DV |
1467 | } |
1468 | } | |
3ef5b91a | 1469 | return _244; |
6a1aa64f | 1470 | }; |
3ef5b91a DV |
1471 | Dygraph.dateParser=function(_259,self){ |
1472 | var _260; | |
285a6bda | 1473 | var d; |
3ef5b91a DV |
1474 | if(_259.length==10&&_259.search("-")!=-1){ |
1475 | _260=_259.replace("-","/","g"); | |
1476 | while(_260.search("-")!=-1){ | |
1477 | _260=_260.replace("-","/"); | |
353a0294 | 1478 | } |
3ef5b91a | 1479 | d=Date.parse(_260); |
8846615a | 1480 | }else{ |
3ef5b91a DV |
1481 | if(_259.length==8){ |
1482 | _260=_259.substr(0,4)+"/"+_259.substr(4,2)+"/"+_259.substr(6,2); | |
1483 | d=Date.parse(_260); | |
681a238e | 1484 | }else{ |
3ef5b91a | 1485 | d=Date.parse(_259); |
285a6bda | 1486 | } |
b2a516b8 | 1487 | } |
285a6bda | 1488 | if(!d||isNaN(d)){ |
3ef5b91a | 1489 | self.error("Couldn't parse "+_259+" as a date"); |
b2a516b8 | 1490 | } |
285a6bda | 1491 | return d; |
6a1aa64f | 1492 | }; |
285a6bda | 1493 | Dygraph.prototype.detectTypeFromString_=function(str){ |
3ef5b91a | 1494 | var _262=false; |
285a6bda | 1495 | if(str.indexOf("-")>=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){ |
3ef5b91a | 1496 | _262=true; |
285a6bda DV |
1497 | }else{ |
1498 | if(str.length==8&&str>"19700101"&&str<"20371231"){ | |
3ef5b91a | 1499 | _262=true; |
285a6bda DV |
1500 | } |
1501 | } | |
3ef5b91a | 1502 | if(_262){ |
285a6bda DV |
1503 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
1504 | this.attrs_.xValueParser=Dygraph.dateParser; | |
1505 | this.attrs_.xTicker=Dygraph.dateTicker; | |
1506 | }else{ | |
1507 | this.attrs_.xValueFormatter=function(x){ | |
1508 | return x; | |
1509 | }; | |
1510 | this.attrs_.xValueParser=function(x){ | |
1511 | return parseFloat(x); | |
1512 | }; | |
1513 | this.attrs_.xTicker=Dygraph.numericTicks; | |
1514 | } | |
1515 | }; | |
1516 | Dygraph.prototype.parseCSV_=function(data){ | |
b2a516b8 | 1517 | var ret=[]; |
3ef5b91a DV |
1518 | var _263=data.split("\n"); |
1519 | var _264=this.attr_("delimiter"); | |
1520 | if(_263[0].indexOf(_264)==-1&&_263[0].indexOf("\t")>=0){ | |
1521 | _264="\t"; | |
681a238e | 1522 | } |
3ef5b91a | 1523 | var _265=0; |
b2a516b8 | 1524 | if(this.labelsFromCSV_){ |
3ef5b91a DV |
1525 | _265=1; |
1526 | this.attrs_.labels=_263[0].split(_264); | |
1527 | } | |
1528 | var _266; | |
1529 | var _267=false; | |
1530 | var _268=this.attr_("labels").length; | |
1531 | for(var i=_265;i<_263.length;i++){ | |
1532 | var line=_263[i]; | |
b2a516b8 DV |
1533 | if(line.length==0){ |
1534 | continue; | |
1535 | } | |
681a238e DV |
1536 | if(line[0]=="#"){ |
1537 | continue; | |
1538 | } | |
3ef5b91a DV |
1539 | var _270=line.split(_264); |
1540 | if(_270.length<2){ | |
b2a516b8 DV |
1541 | continue; |
1542 | } | |
3ef5b91a DV |
1543 | var _271=[]; |
1544 | if(!_267){ | |
1545 | this.detectTypeFromString_(_270[0]); | |
1546 | _266=this.attr_("xValueParser"); | |
1547 | _267=true; | |
285a6bda | 1548 | } |
3ef5b91a | 1549 | _271[0]=_266(_270[0],this); |
b2a516b8 | 1550 | if(this.fractions_){ |
3ef5b91a DV |
1551 | for(var j=1;j<_270.length;j++){ |
1552 | var vals=_270[j].split("/"); | |
1553 | _271[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; | |
b2a516b8 DV |
1554 | } |
1555 | }else{ | |
285a6bda | 1556 | if(this.attr_("errorBars")){ |
3ef5b91a DV |
1557 | for(var j=1;j<_270.length;j+=2){ |
1558 | _271[(j+1)/2]=[parseFloat(_270[j]),parseFloat(_270[j+1])]; | |
b2a516b8 DV |
1559 | } |
1560 | }else{ | |
b64a4f1a | 1561 | if(this.attr_("customBars")){ |
3ef5b91a DV |
1562 | for(var j=1;j<_270.length;j++){ |
1563 | var vals=_270[j].split(";"); | |
1564 | _271[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; | |
b2a516b8 DV |
1565 | } |
1566 | }else{ | |
3ef5b91a DV |
1567 | for(var j=1;j<_270.length;j++){ |
1568 | _271[j]=parseFloat(_270[j]); | |
285a6bda | 1569 | } |
b2a516b8 DV |
1570 | } |
1571 | } | |
1572 | } | |
3ef5b91a DV |
1573 | ret.push(_271); |
1574 | if(_271.length!=_268){ | |
1575 | this.error("Number of columns in line "+i+" ("+_271.length+") does not agree with number of labels ("+_268+") "+line); | |
b2a516b8 | 1576 | } |
b2a516b8 DV |
1577 | } |
1578 | return ret; | |
6a1aa64f | 1579 | }; |
285a6bda DV |
1580 | Dygraph.prototype.parseArray_=function(data){ |
1581 | if(data.length==0){ | |
1582 | this.error("Can't plot empty data set"); | |
1583 | return null; | |
1584 | } | |
1585 | if(data[0].length==0){ | |
1586 | this.error("Data set cannot contain an empty row"); | |
1587 | return null; | |
1588 | } | |
1589 | if(this.attr_("labels")==null){ | |
1590 | this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter"); | |
1591 | this.attrs_.labels=["X"]; | |
1592 | for(var i=1;i<data[0].length;i++){ | |
1593 | this.attrs_.labels.push("Y"+i); | |
1594 | } | |
1595 | } | |
9c97d733 | 1596 | if(Dygraph.isDateLike(data[0][0])){ |
285a6bda DV |
1597 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
1598 | this.attrs_.xTicker=Dygraph.dateTicker; | |
3ef5b91a | 1599 | var _272=Dygraph.clone(data); |
285a6bda | 1600 | for(var i=0;i<data.length;i++){ |
3ef5b91a | 1601 | if(_272[i].length==0){ |
285a6bda DV |
1602 | this.error("Row "<<(1+i)<<" of data is empty"); |
1603 | return null; | |
1604 | } | |
3ef5b91a | 1605 | if(_272[i][0]==null||typeof (_272[i][0].getTime)!="function"){ |
285a6bda DV |
1606 | this.error("x value in row "<<(1+i)<<" is not a Date"); |
1607 | return null; | |
1608 | } | |
3ef5b91a | 1609 | _272[i][0]=_272[i][0].getTime(); |
285a6bda | 1610 | } |
3ef5b91a | 1611 | return _272; |
285a6bda DV |
1612 | }else{ |
1613 | this.attrs_.xValueFormatter=function(x){ | |
1614 | return x; | |
1615 | }; | |
1616 | this.attrs_.xTicker=Dygraph.numericTicks; | |
1617 | return data; | |
1618 | } | |
1619 | }; | |
1620 | Dygraph.prototype.parseDataTable_=function(data){ | |
6219c9d6 DV |
1621 | var cols=data.getNumberOfColumns(); |
1622 | var rows=data.getNumberOfRows(); | |
3ef5b91a | 1623 | var _275=[]; |
6219c9d6 | 1624 | for(var i=0;i<cols;i++){ |
3ef5b91a | 1625 | _275.push(data.getColumnLabel(i)); |
e244a0d7 DV |
1626 | if(i!=0&&this.attr_("errorBars")){ |
1627 | i+=1; | |
1628 | } | |
6219c9d6 | 1629 | } |
3ef5b91a DV |
1630 | this.attrs_.labels=_275; |
1631 | cols=_275.length; | |
1632 | var _276=data.getColumnType(0); | |
1633 | if(_276=="date"){ | |
285a6bda DV |
1634 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
1635 | this.attrs_.xValueParser=Dygraph.dateParser; | |
1636 | this.attrs_.xTicker=Dygraph.dateTicker; | |
1637 | }else{ | |
3ef5b91a | 1638 | if(_276=="number"){ |
285a6bda DV |
1639 | this.attrs_.xValueFormatter=function(x){ |
1640 | return x; | |
1641 | }; | |
1642 | this.attrs_.xValueParser=function(x){ | |
1643 | return parseFloat(x); | |
1644 | }; | |
1645 | this.attrs_.xTicker=Dygraph.numericTicks; | |
1646 | }else{ | |
3ef5b91a | 1647 | this.error("only 'date' and 'number' types are supported for column 1 "+"of DataTable input (Got '"+_276+"')"); |
6219c9d6 DV |
1648 | return null; |
1649 | } | |
285a6bda | 1650 | } |
6219c9d6 DV |
1651 | var ret=[]; |
1652 | for(var i=0;i<rows;i++){ | |
1653 | var row=[]; | |
debe4434 DV |
1654 | if(typeof (data.getValue(i,0))==="undefined"||data.getValue(i,0)===null){ |
1655 | this.warning("Ignoring row "+i+" of DataTable because of undefined or null first column."); | |
b3b20e24 DV |
1656 | continue; |
1657 | } | |
3ef5b91a | 1658 | if(_276=="date"){ |
6219c9d6 | 1659 | row.push(data.getValue(i,0).getTime()); |
36615faf DV |
1660 | }else{ |
1661 | row.push(data.getValue(i,0)); | |
1662 | } | |
e244a0d7 | 1663 | if(!this.attr_("errorBars")){ |
6219c9d6 DV |
1664 | for(var j=1;j<cols;j++){ |
1665 | row.push(data.getValue(i,j)); | |
1666 | } | |
e244a0d7 DV |
1667 | }else{ |
1668 | for(var j=0;j<cols-1;j++){ | |
1669 | row.push([data.getValue(i,1+2*j),data.getValue(i,2+2*j)]); | |
1670 | } | |
1671 | } | |
6219c9d6 DV |
1672 | ret.push(row); |
1673 | } | |
1674 | return ret; | |
1675 | }; | |
9c97d733 DV |
1676 | Dygraph.update=function(self,o){ |
1677 | if(typeof (o)!="undefined"&&o!==null){ | |
1678 | for(var k in o){ | |
1d54a333 | 1679 | if(o.hasOwnProperty(k)){ |
9c97d733 DV |
1680 | self[k]=o[k]; |
1681 | } | |
1682 | } | |
1d54a333 | 1683 | } |
9c97d733 DV |
1684 | return self; |
1685 | }; | |
1686 | Dygraph.isArrayLike=function(o){ | |
1687 | var typ=typeof (o); | |
1688 | if((typ!="object"&&!(typ=="function"&&typeof (o.item)=="function"))||o===null||typeof (o.length)!="number"||o.nodeType===3){ | |
1689 | return false; | |
1690 | } | |
1691 | return true; | |
1692 | }; | |
1693 | Dygraph.isDateLike=function(o){ | |
1694 | if(typeof (o)!="object"||o===null||typeof (o.getTime)!="function"){ | |
1695 | return false; | |
1696 | } | |
1697 | return true; | |
1698 | }; | |
1699 | Dygraph.clone=function(o){ | |
1700 | var r=[]; | |
1701 | for(var i=0;i<o.length;i++){ | |
1702 | if(Dygraph.isArrayLike(o[i])){ | |
1703 | r.push(Dygraph.clone(o[i])); | |
1704 | }else{ | |
1705 | r.push(o[i]); | |
1706 | } | |
1707 | } | |
1708 | return r; | |
1709 | }; | |
285a6bda | 1710 | Dygraph.prototype.start_=function(){ |
b2a516b8 DV |
1711 | if(typeof this.file_=="function"){ |
1712 | this.loadedEvent_(this.file_()); | |
1713 | }else{ | |
9c97d733 | 1714 | if(Dygraph.isArrayLike(this.file_)){ |
285a6bda DV |
1715 | this.rawData_=this.parseArray_(this.file_); |
1716 | this.drawGraph_(this.rawData_); | |
1717 | }else{ | |
6219c9d6 DV |
1718 | if(typeof this.file_=="object"&&typeof this.file_.getColumnRange=="function"){ |
1719 | this.rawData_=this.parseDataTable_(this.file_); | |
1720 | this.drawGraph_(this.rawData_); | |
1721 | }else{ | |
285a6bda DV |
1722 | if(typeof this.file_=="string"){ |
1723 | if(this.file_.indexOf("\n")>=0){ | |
1724 | this.loadedEvent_(this.file_); | |
1725 | }else{ | |
b2a516b8 | 1726 | var req=new XMLHttpRequest(); |
3ef5b91a | 1727 | var _282=this; |
b2a516b8 DV |
1728 | req.onreadystatechange=function(){ |
1729 | if(req.readyState==4){ | |
1730 | if(req.status==200){ | |
3ef5b91a | 1731 | _282.loadedEvent_(req.responseText); |
b2a516b8 DV |
1732 | } |
1733 | } | |
6a1aa64f | 1734 | }; |
b2a516b8 DV |
1735 | req.open("GET",this.file_,true); |
1736 | req.send(null); | |
1737 | } | |
285a6bda DV |
1738 | }else{ |
1739 | this.error("Unknown data format: "+(typeof this.file_)); | |
6219c9d6 | 1740 | } |
b2a516b8 | 1741 | } |
b2a516b8 | 1742 | } |
b2a516b8 | 1743 | } |
285a6bda | 1744 | }; |
3ef5b91a DV |
1745 | Dygraph.prototype.updateOptions=function(_283){ |
1746 | if(_283.rollPeriod){ | |
1747 | this.rollPeriod_=_283.rollPeriod; | |
b2a516b8 | 1748 | } |
3ef5b91a DV |
1749 | if(_283.dateWindow){ |
1750 | this.dateWindow_=_283.dateWindow; | |
b2a516b8 | 1751 | } |
3ef5b91a DV |
1752 | if(_283.valueRange){ |
1753 | this.valueRange_=_283.valueRange; | |
b2a516b8 | 1754 | } |
3ef5b91a | 1755 | Dygraph.update(this.user_attrs_,_283); |
285a6bda DV |
1756 | this.labelsFromCSV_=(this.attr_("labels")==null); |
1757 | this.layout_.updateOptions({"errorBars":this.attr_("errorBars")}); | |
3ef5b91a DV |
1758 | if(_283["file"]&&_283["file"]!=this.file_){ |
1759 | this.file_=_283["file"]; | |
b2a516b8 DV |
1760 | this.start_(); |
1761 | }else{ | |
1762 | this.drawGraph_(this.rawData_); | |
1763 | } | |
6a1aa64f | 1764 | }; |
3ef5b91a DV |
1765 | Dygraph.prototype.resize=function(_284,_285){ |
1766 | if((_284===null)!=(_285===null)){ | |
626e8a8b | 1767 | this.warn("Dygraph.resize() should be called with zero parameters or "+"two non-NULL parameters. Pretending it was zero."); |
3ef5b91a | 1768 | _284=_285=null; |
626e8a8b DV |
1769 | } |
1770 | this.maindiv_.innerHTML=""; | |
1771 | this.attrs_.labelsDiv=null; | |
3ef5b91a DV |
1772 | if(_284){ |
1773 | this.maindiv_.style.width=_284+"px"; | |
1774 | this.maindiv_.style.height=_285+"px"; | |
1775 | this.width_=_284; | |
1776 | this.height_=_285; | |
626e8a8b DV |
1777 | }else{ |
1778 | this.width_=this.maindiv_.offsetWidth; | |
1779 | this.height_=this.maindiv_.offsetHeight; | |
1780 | } | |
1781 | this.createInterface_(); | |
1782 | this.drawGraph_(this.rawData_); | |
1783 | }; | |
3ef5b91a DV |
1784 | Dygraph.prototype.adjustRoll=function(_286){ |
1785 | this.rollPeriod_=_286; | |
b2a516b8 | 1786 | this.drawGraph_(this.rawData_); |
6a1aa64f | 1787 | }; |
681a238e | 1788 | Dygraph.createCanvas=function(){ |
3ef5b91a | 1789 | var _287=document.createElement("canvas"); |
681a238e DV |
1790 | isIE=(/MSIE/.test(navigator.userAgent)&&!window.opera); |
1791 | if(isIE){ | |
3ef5b91a | 1792 | _287=G_vmlCanvasManager.initElement(_287); |
681a238e | 1793 | } |
3ef5b91a | 1794 | return _287; |
681a238e | 1795 | }; |
3ef5b91a DV |
1796 | Dygraph.GVizChart=function(_288){ |
1797 | this.container=_288; | |
6219c9d6 | 1798 | }; |
3ef5b91a | 1799 | Dygraph.GVizChart.prototype.draw=function(data,_289){ |
6219c9d6 | 1800 | this.container.innerHTML=""; |
3ef5b91a | 1801 | this.date_graph=new Dygraph(this.container,data,_289); |
6219c9d6 | 1802 | }; |
285a6bda | 1803 | DateGraph=Dygraph; |
3ef5b91a | 1804 | function RGBColor(_290){ |
f474c2a3 | 1805 | this.ok=false; |
3ef5b91a DV |
1806 | if(_290.charAt(0)=="#"){ |
1807 | _290=_290.substr(1,6); | |
f474c2a3 | 1808 | } |
3ef5b91a DV |
1809 | _290=_290.replace(/ /g,""); |
1810 | _290=_290.toLowerCase(); | |
1811 | var _291={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dodgerblue:"1e90ff",feldspar:"d19275",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslateblue:"8470ff",lightslategray:"778899",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"00ff00",limegreen:"32cd32",linen:"faf0e6",magenta:"ff00ff",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"ff0000",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",violetred:"d02090",wheat:"f5deb3",white:"ffffff",whitesmoke:"f5f5f5",yellow:"ffff00",yellowgreen:"9acd32"}; | |
1812 | for(var key in _291){ | |
1813 | if(_290==key){ | |
1814 | _290=_291[key]; | |
f474c2a3 DV |
1815 | } |
1816 | } | |
3ef5b91a | 1817 | var _293=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:["rgb(123, 234, 45)","rgb(255,234,245)"],process:function(bits){ |
f474c2a3 DV |
1818 | return [parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])]; |
1819 | }},{re:/^(\w{2})(\w{2})(\w{2})$/,example:["#00ff00","336699"],process:function(bits){ | |
1820 | return [parseInt(bits[1],16),parseInt(bits[2],16),parseInt(bits[3],16)]; | |
1821 | }},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(bits){ | |
1822 | return [parseInt(bits[1]+bits[1],16),parseInt(bits[2]+bits[2],16),parseInt(bits[3]+bits[3],16)]; | |
1823 | }}]; | |
3ef5b91a DV |
1824 | for(var i=0;i<_293.length;i++){ |
1825 | var re=_293[i].re; | |
1826 | var _296=_293[i].process; | |
1827 | var bits=re.exec(_290); | |
f474c2a3 | 1828 | if(bits){ |
3ef5b91a | 1829 | channels=_296(bits); |
f474c2a3 DV |
1830 | this.r=channels[0]; |
1831 | this.g=channels[1]; | |
1832 | this.b=channels[2]; | |
1833 | this.ok=true; | |
1834 | } | |
1835 | } | |
1836 | this.r=(this.r<0||isNaN(this.r))?0:((this.r>255)?255:this.r); | |
1837 | this.g=(this.g<0||isNaN(this.g))?0:((this.g>255)?255:this.g); | |
1838 | this.b=(this.b<0||isNaN(this.b))?0:((this.b>255)?255:this.b); | |
1839 | this.toRGB=function(){ | |
1840 | return "rgb("+this.r+", "+this.g+", "+this.b+")"; | |
1841 | }; | |
1842 | this.toHex=function(){ | |
1843 | var r=this.r.toString(16); | |
1844 | var g=this.g.toString(16); | |
1845 | var b=this.b.toString(16); | |
1846 | if(r.length==1){ | |
1847 | r="0"+r; | |
1848 | } | |
1849 | if(g.length==1){ | |
1850 | g="0"+g; | |
1851 | } | |
1852 | if(b.length==1){ | |
1853 | b="0"+b; | |
1854 | } | |
1855 | return "#"+r+g+b; | |
1856 | }; | |
1857 | } | |
b2a516b8 | 1858 |