| 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}; |
| 2 | DygraphLayout=function(_1,_2){ |
| 3 | this.dygraph_=_1; |
| 4 | this.options={}; |
| 5 | Dygraph.update(this.options,_2?_2:{}); |
| 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; |
| 21 | if(this.options.dateWindow){ |
| 22 | this.minxval=this.options.dateWindow[0]; |
| 23 | this.maxxval=this.options.dateWindow[1]; |
| 24 | }else{ |
| 25 | for(var _6 in this.datasets){ |
| 26 | if(!this.datasets.hasOwnProperty(_6)){ |
| 27 | continue; |
| 28 | } |
| 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 | } |
| 39 | } |
| 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){ |
| 50 | if(!this.datasets.hasOwnProperty(_10)){ |
| 51 | continue; |
| 52 | } |
| 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 | } |
| 88 | }; |
| 89 | DygraphLayout.prototype.evaluateWithError=function(){ |
| 90 | this.evaluate(); |
| 91 | if(!this.options.errorBars){ |
| 92 | return; |
| 93 | } |
| 94 | var i=0; |
| 95 | for(var _19 in this.datasets){ |
| 96 | if(!this.datasets.hasOwnProperty(_19)){ |
| 97 | continue; |
| 98 | } |
| 99 | var j=0; |
| 100 | var _20=this.datasets[_19]; |
| 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]); |
| 105 | if(xv==this.points[i].xval&&yv==this.points[i].yval){ |
| 106 | this.points[i].errorMinus=parseFloat(_21[2]); |
| 107 | this.points[i].errorPlus=parseFloat(_21[3]); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | }; |
| 112 | DygraphLayout.prototype.removeAllDatasets=function(){ |
| 113 | delete this.datasets; |
| 114 | this.datasets=new Array(); |
| 115 | }; |
| 116 | DygraphLayout.prototype.updateOptions=function(_24){ |
| 117 | Dygraph.update(this.options,_24?_24:{}); |
| 118 | }; |
| 119 | DygraphCanvasRenderer=function(_25,_26,_27,_28){ |
| 120 | this.dygraph_=_25; |
| 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)"}; |
| 122 | Dygraph.update(this.options,_28); |
| 123 | this.layout=_27; |
| 124 | this.element=_26; |
| 125 | this.container=this.element.parentNode; |
| 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; |
| 136 | this.container.style.position="relative"; |
| 137 | this.container.style.width=this.width+"px"; |
| 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); |
| 156 | for(var i=0;i<this.xlabels.length;i++){ |
| 157 | var el=this.xlabels[i]; |
| 158 | el.parentNode.removeChild(el); |
| 159 | } |
| 160 | for(var i=0;i<this.ylabels.length;i++){ |
| 161 | var el=this.ylabels[i]; |
| 162 | el.parentNode.removeChild(el); |
| 163 | } |
| 164 | this.xlabels=new Array(); |
| 165 | this.ylabels=new Array(); |
| 166 | }; |
| 167 | DygraphCanvasRenderer.isSupported=function(_31){ |
| 168 | var _32=null; |
| 169 | try{ |
| 170 | if(typeof (_31)=="undefined"||_31==null){ |
| 171 | _32=document.createElement("canvas"); |
| 172 | }else{ |
| 173 | _32=_31; |
| 174 | } |
| 175 | var _33=_32.getContext("2d"); |
| 176 | } |
| 177 | catch(e){ |
| 178 | var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); |
| 179 | var _35=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); |
| 180 | if((!ie)||(ie[1]<6)||(_35)){ |
| 181 | return false; |
| 182 | } |
| 183 | return true; |
| 184 | } |
| 185 | return true; |
| 186 | }; |
| 187 | DygraphCanvasRenderer.prototype.render=function(){ |
| 188 | var ctx=this.element.getContext("2d"); |
| 189 | if(this.options.drawYGrid){ |
| 190 | var _37=this.layout.yticks; |
| 191 | ctx.save(); |
| 192 | ctx.strokeStyle=this.options.gridLineColor; |
| 193 | ctx.lineWidth=this.options.axisLineWidth; |
| 194 | for(var i=0;i<_37.length;i++){ |
| 195 | var x=this.area.x; |
| 196 | var y=this.area.y+_37[i][0]*this.area.h; |
| 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){ |
| 205 | var _37=this.layout.xticks; |
| 206 | ctx.save(); |
| 207 | ctx.strokeStyle=this.options.gridLineColor; |
| 208 | ctx.lineWidth=this.options.axisLineWidth; |
| 209 | for(var i=0;i<_37.length;i++){ |
| 210 | var x=this.area.x+_37[i][0]*this.area.w; |
| 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 | } |
| 219 | this._renderLineChart(); |
| 220 | this._renderAxis(); |
| 221 | }; |
| 222 | DygraphCanvasRenderer.prototype._renderAxis=function(){ |
| 223 | if(!this.options.drawXAxis&&!this.options.drawYAxis){ |
| 224 | return; |
| 225 | } |
| 226 | var _40=this.element.getContext("2d"); |
| 227 | var _41={"position":"absolute","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor,"width":this.options.axisLabelWidth+"px","overflow":"hidden"}; |
| 228 | var _42=function(txt){ |
| 229 | var div=document.createElement("div"); |
| 230 | for(var _45 in _41){ |
| 231 | if(_41.hasOwnProperty(_45)){ |
| 232 | div.style[_45]=_41[_45]; |
| 233 | } |
| 234 | } |
| 235 | div.appendChild(document.createTextNode(txt)); |
| 236 | return div; |
| 237 | }; |
| 238 | _40.save(); |
| 239 | _40.strokeStyle=this.options.axisLineColor; |
| 240 | _40.lineWidth=this.options.axisLineWidth; |
| 241 | if(this.options.drawYAxis){ |
| 242 | if(this.layout.yticks&&this.layout.yticks.length>0){ |
| 243 | for(var i=0;i<this.layout.yticks.length;i++){ |
| 244 | var _46=this.layout.yticks[i]; |
| 245 | if(typeof (_46)=="function"){ |
| 246 | return; |
| 247 | } |
| 248 | var x=this.area.x; |
| 249 | var y=this.area.y+_46[0]*this.area.h; |
| 250 | _40.beginPath(); |
| 251 | _40.moveTo(x,y); |
| 252 | _40.lineTo(x-this.options.axisTickSize,y); |
| 253 | _40.closePath(); |
| 254 | _40.stroke(); |
| 255 | var _47=_42(_46[1]); |
| 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){ |
| 261 | _47.style.bottom="0px"; |
| 262 | }else{ |
| 263 | _47.style.top=top+"px"; |
| 264 | } |
| 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); |
| 270 | } |
| 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"; |
| 276 | } |
| 277 | } |
| 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(); |
| 283 | } |
| 284 | if(this.options.drawXAxis){ |
| 285 | if(this.layout.xticks){ |
| 286 | for(var i=0;i<this.layout.xticks.length;i++){ |
| 287 | var _46=this.layout.xticks[i]; |
| 288 | if(typeof (dataset)=="function"){ |
| 289 | return; |
| 290 | } |
| 291 | var x=this.area.x+_46[0]*this.area.w; |
| 292 | var y=this.area.y+this.area.h; |
| 293 | _40.beginPath(); |
| 294 | _40.moveTo(x,y); |
| 295 | _40.lineTo(x,y+this.options.axisTickSize); |
| 296 | _40.closePath(); |
| 297 | _40.stroke(); |
| 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"; |
| 305 | } |
| 306 | if(_52<0){ |
| 307 | _52=0; |
| 308 | _47.style.textAlign="left"; |
| 309 | } |
| 310 | _47.style.left=_52+"px"; |
| 311 | _47.style.width=this.options.xAxisLabelWidth+"px"; |
| 312 | this.container.appendChild(_47); |
| 313 | this.xlabels.push(_47); |
| 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(); |
| 323 | }; |
| 324 | DygraphCanvasRenderer.prototype._renderLineChart=function(){ |
| 325 | var _53=this.element.getContext("2d"); |
| 326 | var _54=this.options.colorScheme.length; |
| 327 | var _55=this.options.colorScheme; |
| 328 | var _56=this.layout.options.errorBars; |
| 329 | var _57=[]; |
| 330 | for(var _58 in this.layout.datasets){ |
| 331 | if(this.layout.datasets.hasOwnProperty(_58)){ |
| 332 | _57.push(_58); |
| 333 | } |
| 334 | } |
| 335 | var _59=_57.length; |
| 336 | for(var i=0;i<this.layout.points.length;i++){ |
| 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; |
| 340 | } |
| 341 | var _61=function(x){ |
| 342 | return x&&!isNaN(x); |
| 343 | }; |
| 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; |
| 351 | ctx.lineWidth=this.options.strokeWidth; |
| 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; |
| 359 | ctx.beginPath(); |
| 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(); |
| 377 | } |
| 378 | _65[0]=_70[0]; |
| 379 | _65[1]=_70[1]; |
| 380 | _64=_60.canvasx; |
| 381 | } |
| 382 | } |
| 383 | ctx.fill(); |
| 384 | } |
| 385 | } |
| 386 | for(var i=0;i<_59;i++){ |
| 387 | var _62=_57[i]; |
| 388 | var _63=_55[i%_54]; |
| 389 | _53.save(); |
| 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{ |
| 406 | ctx.beginPath(); |
| 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(); |
| 414 | } |
| 415 | if(_72||_74){ |
| 416 | ctx.beginPath(); |
| 417 | ctx.fillStyle=_63; |
| 418 | ctx.arc(_60.canvasx,_60.canvasy,_71,0,2*Math.PI,false); |
| 419 | ctx.fill(); |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | _53.restore(); |
| 426 | }; |
| 427 | Dygraph=function(div,_75,_76){ |
| 428 | if(arguments.length>0){ |
| 429 | if(arguments.length==4){ |
| 430 | this.warn("Using deprecated four-argument dygraph constructor"); |
| 431 | this.__old_init__(div,_75,arguments[2],arguments[3]); |
| 432 | }else{ |
| 433 | this.__init__(div,_75,_76); |
| 434 | } |
| 435 | } |
| 436 | }; |
| 437 | Dygraph.NAME="Dygraph"; |
| 438 | Dygraph.VERSION="1.2"; |
| 439 | Dygraph.__repr__=function(){ |
| 440 | return "["+this.NAME+" "+this.VERSION+"]"; |
| 441 | }; |
| 442 | Dygraph.toString=function(){ |
| 443 | return this.__repr__(); |
| 444 | }; |
| 445 | Dygraph.DEFAULT_ROLL_PERIOD=1; |
| 446 | Dygraph.DEFAULT_WIDTH=480; |
| 447 | Dygraph.DEFAULT_HEIGHT=320; |
| 448 | Dygraph.AXIS_LINE_WIDTH=0.3; |
| 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}; |
| 450 | Dygraph.DEBUG=1; |
| 451 | Dygraph.INFO=2; |
| 452 | Dygraph.WARNING=3; |
| 453 | Dygraph.ERROR=3; |
| 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]); |
| 459 | } |
| 460 | Dygraph.update(_79,{"labels":_80}); |
| 461 | } |
| 462 | this.__init__(div,_77,_79); |
| 463 | }; |
| 464 | Dygraph.prototype.__init__=function(div,_81,_82){ |
| 465 | if(_82==null){ |
| 466 | _82={}; |
| 467 | } |
| 468 | this.maindiv_=div; |
| 469 | this.file_=_81; |
| 470 | this.rollPeriod_=_82.rollPeriod||Dygraph.DEFAULT_ROLL_PERIOD; |
| 471 | this.previousVerticalX_=-1; |
| 472 | this.fractions_=_82.fractions||false; |
| 473 | this.dateWindow_=_82.dateWindow||null; |
| 474 | this.valueRange_=_82.valueRange||null; |
| 475 | this.wilsonInterval_=_82.wilsonInterval||true; |
| 476 | div.innerHTML=""; |
| 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 | } |
| 483 | this.width_=parseInt(div.style.width,10); |
| 484 | this.height_=parseInt(div.style.height,10); |
| 485 | this.user_attrs_={}; |
| 486 | Dygraph.update(this.user_attrs_,_82); |
| 487 | this.attrs_={}; |
| 488 | Dygraph.update(this.attrs_,Dygraph.DEFAULT_ATTRS); |
| 489 | this.labelsFromCSV_=(this.attr_("labels")==null); |
| 490 | this.createInterface_(); |
| 491 | this.start_(); |
| 492 | }; |
| 493 | Dygraph.prototype.attr_=function(_83){ |
| 494 | if(typeof (this.user_attrs_[_83])!="undefined"){ |
| 495 | return this.user_attrs_[_83]; |
| 496 | }else{ |
| 497 | if(typeof (this.attrs_[_83])!="undefined"){ |
| 498 | return this.attrs_[_83]; |
| 499 | }else{ |
| 500 | return null; |
| 501 | } |
| 502 | } |
| 503 | }; |
| 504 | Dygraph.prototype.log=function(_84,_85){ |
| 505 | if(typeof (console)!="undefined"){ |
| 506 | switch(_84){ |
| 507 | case Dygraph.DEBUG: |
| 508 | console.debug("dygraphs: "+_85); |
| 509 | break; |
| 510 | case Dygraph.INFO: |
| 511 | console.info("dygraphs: "+_85); |
| 512 | break; |
| 513 | case Dygraph.WARNING: |
| 514 | console.warn("dygraphs: "+_85); |
| 515 | break; |
| 516 | case Dygraph.ERROR: |
| 517 | console.error("dygraphs: "+_85); |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | }; |
| 522 | Dygraph.prototype.info=function(_86){ |
| 523 | this.log(Dygraph.INFO,_86); |
| 524 | }; |
| 525 | Dygraph.prototype.warn=function(_87){ |
| 526 | this.log(Dygraph.WARNING,_87); |
| 527 | }; |
| 528 | Dygraph.prototype.error=function(_88){ |
| 529 | this.log(Dygraph.ERROR,_88); |
| 530 | }; |
| 531 | Dygraph.prototype.rollPeriod=function(){ |
| 532 | return this.rollPeriod_; |
| 533 | }; |
| 534 | Dygraph.addEvent=function(el,evt,fn){ |
| 535 | var _91=function(e){ |
| 536 | if(!e){ |
| 537 | var e=window.event; |
| 538 | } |
| 539 | fn(e); |
| 540 | }; |
| 541 | if(window.addEventListener){ |
| 542 | el.addEventListener(evt,_91,false); |
| 543 | }else{ |
| 544 | el.attachEvent("on"+evt,_91); |
| 545 | } |
| 546 | }; |
| 547 | Dygraph.prototype.createInterface_=function(){ |
| 548 | var _93=this.maindiv_; |
| 549 | this.graphDiv=document.createElement("div"); |
| 550 | this.graphDiv.style.width=this.width_+"px"; |
| 551 | this.graphDiv.style.height=this.height_+"px"; |
| 552 | _93.appendChild(this.graphDiv); |
| 553 | this.canvas_=Dygraph.createCanvas(); |
| 554 | this.canvas_.style.position="absolute"; |
| 555 | this.canvas_.width=this.width_; |
| 556 | this.canvas_.height=this.height_; |
| 557 | this.canvas_.style.width=this.width_+"px"; |
| 558 | this.canvas_.style.height=this.height_+"px"; |
| 559 | this.graphDiv.appendChild(this.canvas_); |
| 560 | this.hidden_=this.createPlotKitCanvas_(this.canvas_); |
| 561 | var _94=this; |
| 562 | Dygraph.addEvent(this.hidden_,"mousemove",function(e){ |
| 563 | _94.mouseMove_(e); |
| 564 | }); |
| 565 | Dygraph.addEvent(this.hidden_,"mouseout",function(e){ |
| 566 | _94.mouseOut_(e); |
| 567 | }); |
| 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_(); |
| 580 | }; |
| 581 | Dygraph.prototype.createPlotKitCanvas_=function(_95){ |
| 582 | var h=Dygraph.createCanvas(); |
| 583 | h.style.position="absolute"; |
| 584 | h.style.top=_95.style.top; |
| 585 | h.style.left=_95.style.left; |
| 586 | h.width=this.width_; |
| 587 | h.height=this.height_; |
| 588 | h.style.width=this.width_+"px"; |
| 589 | h.style.height=this.height_+"px"; |
| 590 | this.graphDiv.appendChild(h); |
| 591 | return h; |
| 592 | }; |
| 593 | Dygraph.hsvToRGB=function(hue,_98,_99){ |
| 594 | var red; |
| 595 | var _101; |
| 596 | var blue; |
| 597 | if(_98===0){ |
| 598 | red=_99; |
| 599 | _101=_99; |
| 600 | blue=_99; |
| 601 | }else{ |
| 602 | var i=Math.floor(hue*6); |
| 603 | var f=(hue*6)-i; |
| 604 | var p=_99*(1-_98); |
| 605 | var q=_99*(1-(_98*f)); |
| 606 | var t=_99*(1-(_98*(1-f))); |
| 607 | switch(i){ |
| 608 | case 1: |
| 609 | red=q; |
| 610 | _101=_99; |
| 611 | blue=p; |
| 612 | break; |
| 613 | case 2: |
| 614 | red=p; |
| 615 | _101=_99; |
| 616 | blue=t; |
| 617 | break; |
| 618 | case 3: |
| 619 | red=p; |
| 620 | _101=q; |
| 621 | blue=_99; |
| 622 | break; |
| 623 | case 4: |
| 624 | red=t; |
| 625 | _101=p; |
| 626 | blue=_99; |
| 627 | break; |
| 628 | case 5: |
| 629 | red=_99; |
| 630 | _101=p; |
| 631 | blue=q; |
| 632 | break; |
| 633 | case 6: |
| 634 | case 0: |
| 635 | red=_99; |
| 636 | _101=t; |
| 637 | blue=p; |
| 638 | break; |
| 639 | } |
| 640 | } |
| 641 | red=Math.floor(255*red+0.5); |
| 642 | _101=Math.floor(255*_101+0.5); |
| 643 | blue=Math.floor(255*blue+0.5); |
| 644 | return "rgb("+red+","+_101+","+blue+")"; |
| 645 | }; |
| 646 | Dygraph.prototype.setColors_=function(){ |
| 647 | var num=this.attr_("labels").length-1; |
| 648 | this.colors_=[]; |
| 649 | var _108=this.attr_("colors"); |
| 650 | if(!_108){ |
| 651 | var sat=this.attr_("colorSaturation")||1; |
| 652 | var val=this.attr_("colorValue")||0.5; |
| 653 | for(var i=1;i<=num;i++){ |
| 654 | var hue=(1*i/(1+num)); |
| 655 | this.colors_.push(Dygraph.hsvToRGB(hue,sat,val)); |
| 656 | } |
| 657 | }else{ |
| 658 | for(var i=0;i<num;i++){ |
| 659 | var _111=_108[i%_108.length]; |
| 660 | this.colors_.push(_111); |
| 661 | } |
| 662 | } |
| 663 | this.renderOptions_.colorScheme=this.colors_; |
| 664 | Dygraph.update(this.plotter_.options,this.renderOptions_); |
| 665 | Dygraph.update(this.layoutOptions_,this.user_attrs_); |
| 666 | Dygraph.update(this.layoutOptions_,this.attrs_); |
| 667 | }; |
| 668 | Dygraph.findPosX=function(obj){ |
| 669 | var _113=0; |
| 670 | if(obj.offsetParent){ |
| 671 | while(obj.offsetParent){ |
| 672 | _113+=obj.offsetLeft; |
| 673 | obj=obj.offsetParent; |
| 674 | } |
| 675 | }else{ |
| 676 | if(obj.x){ |
| 677 | _113+=obj.x; |
| 678 | } |
| 679 | } |
| 680 | return _113; |
| 681 | }; |
| 682 | Dygraph.findPosY=function(obj){ |
| 683 | var _114=0; |
| 684 | if(obj.offsetParent){ |
| 685 | while(obj.offsetParent){ |
| 686 | _114+=obj.offsetTop; |
| 687 | obj=obj.offsetParent; |
| 688 | } |
| 689 | }else{ |
| 690 | if(obj.y){ |
| 691 | _114+=obj.y; |
| 692 | } |
| 693 | } |
| 694 | return _114; |
| 695 | }; |
| 696 | Dygraph.prototype.createStatusMessage_=function(){ |
| 697 | if(!this.attr_("labelsDiv")){ |
| 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")); |
| 701 | var div=document.createElement("div"); |
| 702 | for(var name in _116){ |
| 703 | if(_116.hasOwnProperty(name)){ |
| 704 | div.style[name]=_116[name]; |
| 705 | } |
| 706 | } |
| 707 | this.graphDiv.appendChild(div); |
| 708 | this.attrs_.labelsDiv=div; |
| 709 | } |
| 710 | }; |
| 711 | Dygraph.prototype.createRollInterface_=function(){ |
| 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){ |
| 719 | if(_119.hasOwnProperty(name)){ |
| 720 | _120.style[name]=_119[name]; |
| 721 | } |
| 722 | } |
| 723 | var pa=this.graphDiv; |
| 724 | pa.appendChild(_120); |
| 725 | var _122=this; |
| 726 | _120.onchange=function(){ |
| 727 | _122.adjustRoll(_120.value); |
| 728 | }; |
| 729 | return _120; |
| 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 | } |
| 748 | }; |
| 749 | Dygraph.prototype.createDragInterface_=function(){ |
| 750 | var self=this; |
| 751 | var _126=false; |
| 752 | var _127=false; |
| 753 | var _128=null; |
| 754 | var _129=null; |
| 755 | var _130=null; |
| 756 | var _131=null; |
| 757 | var _132=null; |
| 758 | var _133=null; |
| 759 | var _134=null; |
| 760 | var px=0; |
| 761 | var py=0; |
| 762 | var getX=function(e){ |
| 763 | return Dygraph.pageX(e)-px; |
| 764 | }; |
| 765 | var getY=function(e){ |
| 766 | return Dygraph.pageX(e)-py; |
| 767 | }; |
| 768 | Dygraph.addEvent(this.hidden_,"mousemove",function(_139){ |
| 769 | if(_126){ |
| 770 | _130=getX(_139); |
| 771 | _131=getY(_139); |
| 772 | self.drawZoomRect_(_128,_130,_132); |
| 773 | _132=_130; |
| 774 | }else{ |
| 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; |
| 780 | self.drawGraph_(self.rawData_); |
| 781 | } |
| 782 | } |
| 783 | }); |
| 784 | Dygraph.addEvent(this.hidden_,"mousedown",function(_140){ |
| 785 | px=Dygraph.findPosX(self.canvas_); |
| 786 | py=Dygraph.findPosY(self.canvas_); |
| 787 | _128=getX(_140); |
| 788 | _129=getY(_140); |
| 789 | if(_140.altKey||_140.shiftKey){ |
| 790 | if(!self.dateWindow_){ |
| 791 | return; |
| 792 | } |
| 793 | _127=true; |
| 794 | _134=self.dateWindow_[1]-self.dateWindow_[0]; |
| 795 | _133=(_128/self.width_)*_134+self.dateWindow_[0]; |
| 796 | }else{ |
| 797 | _126=true; |
| 798 | } |
| 799 | }); |
| 800 | Dygraph.addEvent(document,"mouseup",function(_141){ |
| 801 | if(_126||_127){ |
| 802 | _126=false; |
| 803 | _128=null; |
| 804 | _129=null; |
| 805 | } |
| 806 | if(_127){ |
| 807 | _127=false; |
| 808 | _133=null; |
| 809 | _134=null; |
| 810 | } |
| 811 | }); |
| 812 | Dygraph.addEvent(this.hidden_,"mouseout",function(_142){ |
| 813 | if(_126){ |
| 814 | _130=null; |
| 815 | _131=null; |
| 816 | } |
| 817 | }); |
| 818 | Dygraph.addEvent(this.hidden_,"mouseup",function(_143){ |
| 819 | if(_126){ |
| 820 | _126=false; |
| 821 | _130=getX(_143); |
| 822 | _131=getY(_143); |
| 823 | var _144=Math.abs(_130-_128); |
| 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_); |
| 827 | } |
| 828 | if(_144>=10){ |
| 829 | self.doZoom_(Math.min(_128,_130),Math.max(_128,_130)); |
| 830 | }else{ |
| 831 | self.canvas_.getContext("2d").clearRect(0,0,self.canvas_.width,self.canvas_.height); |
| 832 | } |
| 833 | _128=null; |
| 834 | _129=null; |
| 835 | } |
| 836 | if(_127){ |
| 837 | _127=false; |
| 838 | _133=null; |
| 839 | _134=null; |
| 840 | } |
| 841 | }); |
| 842 | Dygraph.addEvent(this.hidden_,"dblclick",function(_146){ |
| 843 | if(self.dateWindow_==null){ |
| 844 | return; |
| 845 | } |
| 846 | self.dateWindow_=null; |
| 847 | self.drawGraph_(self.rawData_); |
| 848 | var _147=self.rawData_[0][0]; |
| 849 | var _148=self.rawData_[self.rawData_.length-1][0]; |
| 850 | if(self.attr_("zoomCallback")){ |
| 851 | self.attr_("zoomCallback")(_147,_148); |
| 852 | } |
| 853 | }); |
| 854 | }; |
| 855 | Dygraph.prototype.drawZoomRect_=function(_149,endX,_151){ |
| 856 | var ctx=this.canvas_.getContext("2d"); |
| 857 | if(_151){ |
| 858 | ctx.clearRect(Math.min(_149,_151),0,Math.abs(_149-_151),this.height_); |
| 859 | } |
| 860 | if(endX&&_149){ |
| 861 | ctx.fillStyle="rgba(128,128,128,0.33)"; |
| 862 | ctx.fillRect(Math.min(_149,endX),0,Math.abs(endX-_149),this.height_); |
| 863 | } |
| 864 | }; |
| 865 | Dygraph.prototype.doZoom_=function(lowX,_153){ |
| 866 | var _154=this.layout_.points; |
| 867 | var _155=null; |
| 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)){ |
| 873 | _155=x; |
| 874 | } |
| 875 | if(cx>_153&&(_156==null||x<_156)){ |
| 876 | _156=x; |
| 877 | } |
| 878 | } |
| 879 | if(_155==null){ |
| 880 | _155=_154[0].xval; |
| 881 | } |
| 882 | if(_156==null){ |
| 883 | _156=_154[_154.length-1].xval; |
| 884 | } |
| 885 | this.dateWindow_=[_155,_156]; |
| 886 | this.drawGraph_(this.rawData_); |
| 887 | if(this.attr_("zoomCallback")){ |
| 888 | this.attr_("zoomCallback")(_155,_156); |
| 889 | } |
| 890 | }; |
| 891 | Dygraph.prototype.mouseMove_=function(_158){ |
| 892 | var _159=Dygraph.pageX(_158)-Dygraph.findPosX(this.hidden_); |
| 893 | var _160=this.layout_.points; |
| 894 | var _161=-1; |
| 895 | var _162=-1; |
| 896 | var _163=1e+100; |
| 897 | var idx=-1; |
| 898 | for(var i=0;i<_160.length;i++){ |
| 899 | var dist=Math.abs(_160[i].canvasx-_159); |
| 900 | if(dist>_163){ |
| 901 | break; |
| 902 | } |
| 903 | _163=dist; |
| 904 | idx=i; |
| 905 | } |
| 906 | if(idx>=0){ |
| 907 | _161=_160[idx].xval; |
| 908 | } |
| 909 | if(_159>_160[_160.length-1].canvasx){ |
| 910 | _161=_160[_160.length-1].xval; |
| 911 | } |
| 912 | this.selPoints_=[]; |
| 913 | for(var i=0;i<_160.length;i++){ |
| 914 | if(_160[i].xval==_161){ |
| 915 | this.selPoints_.push(_160[i]); |
| 916 | } |
| 917 | } |
| 918 | if(this.attr_("highlightCallback")){ |
| 919 | this.attr_("highlightCallback")(_158,_161,this.selPoints_); |
| 920 | } |
| 921 | var _166=this.attr_("highlightCircleSize"); |
| 922 | var ctx=this.canvas_.getContext("2d"); |
| 923 | if(this.previousVerticalX_>=0){ |
| 924 | var px=this.previousVerticalX_; |
| 925 | ctx.clearRect(px-_166-1,0,2*_166+2,this.height_); |
| 926 | } |
| 927 | var isOK=function(x){ |
| 928 | return x&&!isNaN(x); |
| 929 | }; |
| 930 | if(this.selPoints_.length>0){ |
| 931 | var _159=this.selPoints_[0].canvasx; |
| 932 | var _168=this.attr_("xValueFormatter")(_161,this)+":"; |
| 933 | var clen=this.colors_.length; |
| 934 | for(var i=0;i<this.selPoints_.length;i++){ |
| 935 | if(!isOK(this.selPoints_[i].canvasy)){ |
| 936 | continue; |
| 937 | } |
| 938 | if(this.attr_("labelsSeparateLines")){ |
| 939 | _168+="<br/>"; |
| 940 | } |
| 941 | var _170=this.selPoints_[i]; |
| 942 | var c=new RGBColor(this.colors_[i%clen]); |
| 943 | _168+=" <b><font color='"+c.toHex()+"'>"+_170.name+"</font></b>:"+this.round_(_170.yval,2); |
| 944 | } |
| 945 | this.attr_("labelsDiv").innerHTML=_168; |
| 946 | this.lastx_=_161; |
| 947 | ctx.save(); |
| 948 | for(var i=0;i<this.selPoints_.length;i++){ |
| 949 | if(!isOK(this.selPoints_[i%clen].canvasy)){ |
| 950 | continue; |
| 951 | } |
| 952 | ctx.beginPath(); |
| 953 | ctx.fillStyle=this.colors_[i%clen]; |
| 954 | ctx.arc(_159,this.selPoints_[i%clen].canvasy,_166,0,2*Math.PI,false); |
| 955 | ctx.fill(); |
| 956 | } |
| 957 | ctx.restore(); |
| 958 | this.previousVerticalX_=_159; |
| 959 | } |
| 960 | }; |
| 961 | Dygraph.prototype.mouseOut_=function(_172){ |
| 962 | var ctx=this.canvas_.getContext("2d"); |
| 963 | ctx.clearRect(0,0,this.width_,this.height_); |
| 964 | this.attr_("labelsDiv").innerHTML=""; |
| 965 | }; |
| 966 | Dygraph.zeropad=function(x){ |
| 967 | if(x<10){ |
| 968 | return "0"+x; |
| 969 | }else{ |
| 970 | return ""+x; |
| 971 | } |
| 972 | }; |
| 973 | Dygraph.prototype.hmsString_=function(date){ |
| 974 | var _174=Dygraph.zeropad; |
| 975 | var d=new Date(date); |
| 976 | if(d.getSeconds()){ |
| 977 | return _174(d.getHours())+":"+_174(d.getMinutes())+":"+_174(d.getSeconds()); |
| 978 | }else{ |
| 979 | if(d.getMinutes()){ |
| 980 | return _174(d.getHours())+":"+_174(d.getMinutes()); |
| 981 | }else{ |
| 982 | return _174(d.getHours()); |
| 983 | } |
| 984 | } |
| 985 | }; |
| 986 | Dygraph.dateString_=function(date,self){ |
| 987 | var _176=Dygraph.zeropad; |
| 988 | var d=new Date(date); |
| 989 | var year=""+d.getFullYear(); |
| 990 | var _178=_176(d.getMonth()+1); |
| 991 | var day=_176(d.getDate()); |
| 992 | var ret=""; |
| 993 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); |
| 994 | if(frac){ |
| 995 | ret=" "+self.hmsString_(date); |
| 996 | } |
| 997 | return year+"/"+_178+"/"+day+ret; |
| 998 | }; |
| 999 | Dygraph.prototype.round_=function(num,_182){ |
| 1000 | var _183=Math.pow(10,_182); |
| 1001 | return Math.round(num*_183)/_183; |
| 1002 | }; |
| 1003 | Dygraph.prototype.loadedEvent_=function(data){ |
| 1004 | this.rawData_=this.parseCSV_(data); |
| 1005 | this.drawGraph_(this.rawData_); |
| 1006 | }; |
| 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(){ |
| 1010 | var _185,endDate; |
| 1011 | if(this.dateWindow_){ |
| 1012 | _185=this.dateWindow_[0]; |
| 1013 | endDate=this.dateWindow_[1]; |
| 1014 | }else{ |
| 1015 | _185=this.rawData_[0][0]; |
| 1016 | endDate=this.rawData_[this.rawData_.length-1][0]; |
| 1017 | } |
| 1018 | var _186=this.attr_("xTicker")(_185,endDate,this); |
| 1019 | this.layout_.updateOptions({xTicks:_186}); |
| 1020 | }; |
| 1021 | Dygraph.SECONDLY=0; |
| 1022 | Dygraph.TEN_SECONDLY=1; |
| 1023 | Dygraph.THIRTY_SECONDLY=2; |
| 1024 | Dygraph.MINUTELY=3; |
| 1025 | Dygraph.TEN_MINUTELY=4; |
| 1026 | Dygraph.THIRTY_MINUTELY=5; |
| 1027 | Dygraph.HOURLY=6; |
| 1028 | Dygraph.SIX_HOURLY=7; |
| 1029 | Dygraph.DAILY=8; |
| 1030 | Dygraph.WEEKLY=9; |
| 1031 | Dygraph.MONTHLY=10; |
| 1032 | Dygraph.QUARTERLY=11; |
| 1033 | Dygraph.BIANNUAL=12; |
| 1034 | Dygraph.ANNUAL=13; |
| 1035 | Dygraph.DECADAL=14; |
| 1036 | Dygraph.NUM_GRANULARITIES=15; |
| 1037 | Dygraph.SHORT_SPACINGS=[]; |
| 1038 | Dygraph.SHORT_SPACINGS[Dygraph.SECONDLY]=1000*1; |
| 1039 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_SECONDLY]=1000*10; |
| 1040 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_SECONDLY]=1000*30; |
| 1041 | Dygraph.SHORT_SPACINGS[Dygraph.MINUTELY]=1000*60; |
| 1042 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_MINUTELY]=1000*60*10; |
| 1043 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_MINUTELY]=1000*60*30; |
| 1044 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600; |
| 1045 | Dygraph.SHORT_SPACINGS[Dygraph.SIX_HOURLY]=1000*3600*6; |
| 1046 | Dygraph.SHORT_SPACINGS[Dygraph.DAILY]=1000*86400; |
| 1047 | Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY]=1000*604800; |
| 1048 | Dygraph.prototype.NumXTicks=function(_187,_188,_189){ |
| 1049 | if(_189<Dygraph.MONTHLY){ |
| 1050 | var _190=Dygraph.SHORT_SPACINGS[_189]; |
| 1051 | return Math.floor(0.5+1*(_188-_187)/_190); |
| 1052 | }else{ |
| 1053 | var _191=1; |
| 1054 | var _192=12; |
| 1055 | if(_189==Dygraph.QUARTERLY){ |
| 1056 | _192=3; |
| 1057 | } |
| 1058 | if(_189==Dygraph.BIANNUAL){ |
| 1059 | _192=2; |
| 1060 | } |
| 1061 | if(_189==Dygraph.ANNUAL){ |
| 1062 | _192=1; |
| 1063 | } |
| 1064 | if(_189==Dygraph.DECADAL){ |
| 1065 | _192=1; |
| 1066 | _191=10; |
| 1067 | } |
| 1068 | var _193=365.2524*24*3600*1000; |
| 1069 | var _194=1*(_188-_187)/_193; |
| 1070 | return Math.floor(0.5+1*_194*_192/_191); |
| 1071 | } |
| 1072 | }; |
| 1073 | Dygraph.prototype.GetXAxis=function(_195,_196,_197){ |
| 1074 | var _198=[]; |
| 1075 | if(_197<Dygraph.MONTHLY){ |
| 1076 | var _199=Dygraph.SHORT_SPACINGS[_197]; |
| 1077 | var _200="%d%b"; |
| 1078 | if(_197<Dygraph.HOURLY){ |
| 1079 | _195=_199*Math.floor(0.5+_195/_199); |
| 1080 | } |
| 1081 | for(var t=_195;t<=_196;t+=_199){ |
| 1082 | var d=new Date(t); |
| 1083 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); |
| 1084 | if(frac==0||_197>=Dygraph.DAILY){ |
| 1085 | _198.push({v:t,label:new Date(t+3600*1000).strftime(_200)}); |
| 1086 | }else{ |
| 1087 | _198.push({v:t,label:this.hmsString_(t)}); |
| 1088 | } |
| 1089 | } |
| 1090 | }else{ |
| 1091 | var _201; |
| 1092 | var _202=1; |
| 1093 | if(_197==Dygraph.MONTHLY){ |
| 1094 | _201=[0,1,2,3,4,5,6,7,8,9,10,11,12]; |
| 1095 | }else{ |
| 1096 | if(_197==Dygraph.QUARTERLY){ |
| 1097 | _201=[0,3,6,9]; |
| 1098 | }else{ |
| 1099 | if(_197==Dygraph.BIANNUAL){ |
| 1100 | _201=[0,6]; |
| 1101 | }else{ |
| 1102 | if(_197==Dygraph.ANNUAL){ |
| 1103 | _201=[0]; |
| 1104 | }else{ |
| 1105 | if(_197==Dygraph.DECADAL){ |
| 1106 | _201=[0]; |
| 1107 | _202=10; |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | var _203=new Date(_195).getFullYear(); |
| 1114 | var _204=new Date(_196).getFullYear(); |
| 1115 | var _205=Dygraph.zeropad; |
| 1116 | for(var i=_203;i<=_204;i++){ |
| 1117 | if(i%_202!=0){ |
| 1118 | continue; |
| 1119 | } |
| 1120 | for(var j=0;j<_201.length;j++){ |
| 1121 | var _206=i+"/"+_205(1+_201[j])+"/01"; |
| 1122 | var t=Date.parse(_206); |
| 1123 | if(t<_195||t>_196){ |
| 1124 | continue; |
| 1125 | } |
| 1126 | _198.push({v:t,label:new Date(t).strftime("%b %y")}); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | return _198; |
| 1131 | }; |
| 1132 | Dygraph.dateTicker=function(_207,_208,self){ |
| 1133 | var _209=-1; |
| 1134 | for(var i=0;i<Dygraph.NUM_GRANULARITIES;i++){ |
| 1135 | var _210=self.NumXTicks(_207,_208,i); |
| 1136 | if(self.width_/_210>=self.attr_("pixelsPerXLabel")){ |
| 1137 | _209=i; |
| 1138 | break; |
| 1139 | } |
| 1140 | } |
| 1141 | if(_209>=0){ |
| 1142 | return self.GetXAxis(_207,_208,_209); |
| 1143 | }else{ |
| 1144 | } |
| 1145 | }; |
| 1146 | Dygraph.numericTicks=function(minV,maxV,self){ |
| 1147 | if(self.attr_("labelsKMG2")){ |
| 1148 | var _213=[1,2,4,8]; |
| 1149 | }else{ |
| 1150 | var _213=[1,2,5]; |
| 1151 | } |
| 1152 | var _214,low_val,high_val,nTicks; |
| 1153 | var _215=self.attr_("pixelsPerYLabel"); |
| 1154 | for(var i=-10;i<50;i++){ |
| 1155 | if(self.attr_("labelsKMG2")){ |
| 1156 | var _216=Math.pow(16,i); |
| 1157 | }else{ |
| 1158 | var _216=Math.pow(10,i); |
| 1159 | } |
| 1160 | for(var j=0;j<_213.length;j++){ |
| 1161 | _214=_216*_213[j]; |
| 1162 | low_val=Math.floor(minV/_214)*_214; |
| 1163 | high_val=Math.ceil(maxV/_214)*_214; |
| 1164 | nTicks=(high_val-low_val)/_214; |
| 1165 | var _217=self.height_/nTicks; |
| 1166 | if(_217>_215){ |
| 1167 | break; |
| 1168 | } |
| 1169 | } |
| 1170 | if(_217>_215){ |
| 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | var _218=[]; |
| 1175 | var k; |
| 1176 | var _220=[]; |
| 1177 | if(self.attr_("labelsKMB")){ |
| 1178 | k=1000; |
| 1179 | _220=["K","M","B","T"]; |
| 1180 | } |
| 1181 | if(self.attr_("labelsKMG2")){ |
| 1182 | if(k){ |
| 1183 | self.warn("Setting both labelsKMB and labelsKMG2. Pick one!"); |
| 1184 | } |
| 1185 | k=1024; |
| 1186 | _220=["k","M","G","T"]; |
| 1187 | } |
| 1188 | for(var i=0;i<nTicks;i++){ |
| 1189 | var _221=low_val+i*_214; |
| 1190 | var _222=Math.abs(_221); |
| 1191 | var _223=self.round_(_221,2); |
| 1192 | if(_220.length){ |
| 1193 | var n=k*k*k*k; |
| 1194 | for(var j=3;j>=0;j--,n/=k){ |
| 1195 | if(_222>=n){ |
| 1196 | _223=self.round_(_221/n,1)+_220[j]; |
| 1197 | break; |
| 1198 | } |
| 1199 | } |
| 1200 | } |
| 1201 | _218.push({label:_223,v:_221}); |
| 1202 | } |
| 1203 | return _218; |
| 1204 | }; |
| 1205 | Dygraph.prototype.addYTicks_=function(minY,maxY){ |
| 1206 | var _227=Dygraph.numericTicks(minY,maxY,this); |
| 1207 | this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_227}); |
| 1208 | }; |
| 1209 | Dygraph.prototype.extremeValues_=function(_228){ |
| 1210 | var minY=null,maxY=null; |
| 1211 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
| 1212 | if(bars){ |
| 1213 | for(var j=0;j<_228.length;j++){ |
| 1214 | var y=_228[j][1][0]; |
| 1215 | if(!y){ |
| 1216 | continue; |
| 1217 | } |
| 1218 | var low=y-_228[j][1][1]; |
| 1219 | var high=y+_228[j][1][2]; |
| 1220 | if(low>y){ |
| 1221 | low=y; |
| 1222 | } |
| 1223 | if(high<y){ |
| 1224 | high=y; |
| 1225 | } |
| 1226 | if(maxY==null||high>maxY){ |
| 1227 | maxY=high; |
| 1228 | } |
| 1229 | if(minY==null||low<minY){ |
| 1230 | minY=low; |
| 1231 | } |
| 1232 | } |
| 1233 | }else{ |
| 1234 | for(var j=0;j<_228.length;j++){ |
| 1235 | var y=_228[j][1]; |
| 1236 | if(y===null||isNaN(y)){ |
| 1237 | continue; |
| 1238 | } |
| 1239 | if(maxY==null||y>maxY){ |
| 1240 | maxY=y; |
| 1241 | } |
| 1242 | if(minY==null||y<minY){ |
| 1243 | minY=y; |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | return [minY,maxY]; |
| 1248 | }; |
| 1249 | Dygraph.prototype.drawGraph_=function(data){ |
| 1250 | var minY=null,maxY=null; |
| 1251 | this.layout_.removeAllDatasets(); |
| 1252 | this.setColors_(); |
| 1253 | this.attrs_["pointSize"]=0.5*this.attr_("highlightCircleSize"); |
| 1254 | for(var i=1;i<data[0].length;i++){ |
| 1255 | var _232=[]; |
| 1256 | for(var j=0;j<data.length;j++){ |
| 1257 | var date=data[j][0]; |
| 1258 | _232[j]=[date,data[j][i]]; |
| 1259 | } |
| 1260 | _232=this.rollingAverage(_232,this.rollPeriod_); |
| 1261 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
| 1262 | if(this.dateWindow_){ |
| 1263 | var low=this.dateWindow_[0]; |
| 1264 | var high=this.dateWindow_[1]; |
| 1265 | var _233=[]; |
| 1266 | for(var k=0;k<_232.length;k++){ |
| 1267 | if(_232[k][0]>=low&&_232[k][0]<=high){ |
| 1268 | _233.push(_232[k]); |
| 1269 | } |
| 1270 | } |
| 1271 | _232=_233; |
| 1272 | } |
| 1273 | var _234=this.extremeValues_(_232); |
| 1274 | var _235=_234[0]; |
| 1275 | var _236=_234[1]; |
| 1276 | if(!minY||_235<minY){ |
| 1277 | minY=_235; |
| 1278 | } |
| 1279 | if(!maxY||_236>maxY){ |
| 1280 | maxY=_236; |
| 1281 | } |
| 1282 | if(bars){ |
| 1283 | var vals=[]; |
| 1284 | for(var j=0;j<_232.length;j++){ |
| 1285 | vals[j]=[_232[j][0],_232[j][1][0],_232[j][1][1],_232[j][1][2]]; |
| 1286 | } |
| 1287 | this.layout_.addDataset(this.attr_("labels")[i],vals); |
| 1288 | }else{ |
| 1289 | this.layout_.addDataset(this.attr_("labels")[i],_232); |
| 1290 | } |
| 1291 | } |
| 1292 | if(this.valueRange_!=null){ |
| 1293 | this.addYTicks_(this.valueRange_[0],this.valueRange_[1]); |
| 1294 | }else{ |
| 1295 | var span=maxY-minY; |
| 1296 | var _239=maxY+0.1*span; |
| 1297 | var _240=minY-0.1*span; |
| 1298 | if(_240<0&&minY>=0){ |
| 1299 | _240=0; |
| 1300 | } |
| 1301 | if(_239>0&&maxY<=0){ |
| 1302 | _239=0; |
| 1303 | } |
| 1304 | if(this.attr_("includeZero")){ |
| 1305 | if(maxY<0){ |
| 1306 | _239=0; |
| 1307 | } |
| 1308 | if(minY>0){ |
| 1309 | _240=0; |
| 1310 | } |
| 1311 | } |
| 1312 | this.addYTicks_(_240,_239); |
| 1313 | } |
| 1314 | this.addXTicks_(); |
| 1315 | this.layout_.updateOptions({dateWindow:this.dateWindow_}); |
| 1316 | this.layout_.evaluateWithError(); |
| 1317 | this.plotter_.clear(); |
| 1318 | this.plotter_.render(); |
| 1319 | this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height); |
| 1320 | }; |
| 1321 | Dygraph.prototype.rollingAverage=function(_241,_242){ |
| 1322 | if(_241.length<2){ |
| 1323 | return _241; |
| 1324 | } |
| 1325 | var _242=Math.min(_242,_241.length-1); |
| 1326 | var _243=[]; |
| 1327 | var _244=this.attr_("sigma"); |
| 1328 | if(this.fractions_){ |
| 1329 | var num=0; |
| 1330 | var den=0; |
| 1331 | var mult=100; |
| 1332 | for(var i=0;i<_241.length;i++){ |
| 1333 | num+=_241[i][1][0]; |
| 1334 | den+=_241[i][1][1]; |
| 1335 | if(i-_242>=0){ |
| 1336 | num-=_241[i-_242][1][0]; |
| 1337 | den-=_241[i-_242][1][1]; |
| 1338 | } |
| 1339 | var date=_241[i][0]; |
| 1340 | var _247=den?num/den:0; |
| 1341 | if(this.attr_("errorBars")){ |
| 1342 | if(this.wilsonInterval_){ |
| 1343 | if(den){ |
| 1344 | var p=_247<0?0:_247,n=den; |
| 1345 | var pm=_244*Math.sqrt(p*(1-p)/n+_244*_244/(4*n*n)); |
| 1346 | var _249=1+_244*_244/den; |
| 1347 | var low=(p+_244*_244/(2*den)-pm)/_249; |
| 1348 | var high=(p+_244*_244/(2*den)+pm)/_249; |
| 1349 | _243[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; |
| 1350 | }else{ |
| 1351 | _243[i]=[date,[0,0,0]]; |
| 1352 | } |
| 1353 | }else{ |
| 1354 | var _250=den?_244*Math.sqrt(_247*(1-_247)/den):1; |
| 1355 | _243[i]=[date,[mult*_247,mult*_250,mult*_250]]; |
| 1356 | } |
| 1357 | }else{ |
| 1358 | _243[i]=[date,mult*_247]; |
| 1359 | } |
| 1360 | } |
| 1361 | }else{ |
| 1362 | if(this.attr_("customBars")){ |
| 1363 | var low=0; |
| 1364 | var mid=0; |
| 1365 | var high=0; |
| 1366 | var _252=0; |
| 1367 | for(var i=0;i<_241.length;i++){ |
| 1368 | var data=_241[i][1]; |
| 1369 | var y=data[1]; |
| 1370 | _243[i]=[_241[i][0],[y,y-data[0],data[2]-y]]; |
| 1371 | if(y!=null&&!isNaN(y)){ |
| 1372 | low+=data[0]; |
| 1373 | mid+=y; |
| 1374 | high+=data[2]; |
| 1375 | _252+=1; |
| 1376 | } |
| 1377 | if(i-_242>=0){ |
| 1378 | var prev=_241[i-_242]; |
| 1379 | if(prev[1][1]!=null&&!isNaN(prev[1][1])){ |
| 1380 | low-=prev[1][0]; |
| 1381 | mid-=prev[1][1]; |
| 1382 | high-=prev[1][2]; |
| 1383 | _252-=1; |
| 1384 | } |
| 1385 | } |
| 1386 | _243[i]=[_241[i][0],[1*mid/_252,1*(mid-low)/_252,1*(high-mid)/_252]]; |
| 1387 | } |
| 1388 | }else{ |
| 1389 | var _254=Math.min(_242-1,_241.length-2); |
| 1390 | if(!this.attr_("errorBars")){ |
| 1391 | if(_242==1){ |
| 1392 | return _241; |
| 1393 | } |
| 1394 | for(var i=0;i<_241.length;i++){ |
| 1395 | var sum=0; |
| 1396 | var _256=0; |
| 1397 | for(var j=Math.max(0,i-_242+1);j<i+1;j++){ |
| 1398 | var y=_241[j][1]; |
| 1399 | if(y==null||isNaN(y)){ |
| 1400 | continue; |
| 1401 | } |
| 1402 | _256++; |
| 1403 | sum+=_241[j][1]; |
| 1404 | } |
| 1405 | if(_256){ |
| 1406 | _243[i]=[_241[i][0],sum/_256]; |
| 1407 | }else{ |
| 1408 | _243[i]=[_241[i][0],null]; |
| 1409 | } |
| 1410 | } |
| 1411 | }else{ |
| 1412 | for(var i=0;i<_241.length;i++){ |
| 1413 | var sum=0; |
| 1414 | var _257=0; |
| 1415 | var _256=0; |
| 1416 | for(var j=Math.max(0,i-_242+1);j<i+1;j++){ |
| 1417 | var y=_241[j][1][0]; |
| 1418 | if(y==null||isNaN(y)){ |
| 1419 | continue; |
| 1420 | } |
| 1421 | _256++; |
| 1422 | sum+=_241[j][1][0]; |
| 1423 | _257+=Math.pow(_241[j][1][1],2); |
| 1424 | } |
| 1425 | if(_256){ |
| 1426 | var _250=Math.sqrt(_257)/_256; |
| 1427 | _243[i]=[_241[i][0],[sum/_256,_244*_250,_244*_250]]; |
| 1428 | }else{ |
| 1429 | _243[i]=[_241[i][0],[null,null,null]]; |
| 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | return _243; |
| 1436 | }; |
| 1437 | Dygraph.dateParser=function(_258,self){ |
| 1438 | var _259; |
| 1439 | var d; |
| 1440 | if(_258.length==10&&_258.search("-")!=-1){ |
| 1441 | _259=_258.replace("-","/","g"); |
| 1442 | while(_259.search("-")!=-1){ |
| 1443 | _259=_259.replace("-","/"); |
| 1444 | } |
| 1445 | d=Date.parse(_259); |
| 1446 | }else{ |
| 1447 | if(_258.length==8){ |
| 1448 | _259=_258.substr(0,4)+"/"+_258.substr(4,2)+"/"+_258.substr(6,2); |
| 1449 | d=Date.parse(_259); |
| 1450 | }else{ |
| 1451 | d=Date.parse(_258); |
| 1452 | } |
| 1453 | } |
| 1454 | if(!d||isNaN(d)){ |
| 1455 | self.error("Couldn't parse "+_258+" as a date"); |
| 1456 | } |
| 1457 | return d; |
| 1458 | }; |
| 1459 | Dygraph.prototype.detectTypeFromString_=function(str){ |
| 1460 | var _261=false; |
| 1461 | if(str.indexOf("-")>=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){ |
| 1462 | _261=true; |
| 1463 | }else{ |
| 1464 | if(str.length==8&&str>"19700101"&&str<"20371231"){ |
| 1465 | _261=true; |
| 1466 | } |
| 1467 | } |
| 1468 | if(_261){ |
| 1469 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
| 1470 | this.attrs_.xValueParser=Dygraph.dateParser; |
| 1471 | this.attrs_.xTicker=Dygraph.dateTicker; |
| 1472 | }else{ |
| 1473 | this.attrs_.xValueFormatter=function(x){ |
| 1474 | return x; |
| 1475 | }; |
| 1476 | this.attrs_.xValueParser=function(x){ |
| 1477 | return parseFloat(x); |
| 1478 | }; |
| 1479 | this.attrs_.xTicker=Dygraph.numericTicks; |
| 1480 | } |
| 1481 | }; |
| 1482 | Dygraph.prototype.parseCSV_=function(data){ |
| 1483 | var ret=[]; |
| 1484 | var _262=data.split("\n"); |
| 1485 | var _263=this.attr_("delimiter"); |
| 1486 | if(_262[0].indexOf(_263)==-1&&_262[0].indexOf("\t")>=0){ |
| 1487 | _263="\t"; |
| 1488 | } |
| 1489 | var _264=0; |
| 1490 | if(this.labelsFromCSV_){ |
| 1491 | _264=1; |
| 1492 | this.attrs_.labels=_262[0].split(_263); |
| 1493 | } |
| 1494 | var _265; |
| 1495 | var _266=false; |
| 1496 | var _267=this.attr_("labels").length; |
| 1497 | for(var i=_264;i<_262.length;i++){ |
| 1498 | var line=_262[i]; |
| 1499 | if(line.length==0){ |
| 1500 | continue; |
| 1501 | } |
| 1502 | if(line[0]=="#"){ |
| 1503 | continue; |
| 1504 | } |
| 1505 | var _269=line.split(_263); |
| 1506 | if(_269.length<2){ |
| 1507 | continue; |
| 1508 | } |
| 1509 | var _270=[]; |
| 1510 | if(!_266){ |
| 1511 | this.detectTypeFromString_(_269[0]); |
| 1512 | _265=this.attr_("xValueParser"); |
| 1513 | _266=true; |
| 1514 | } |
| 1515 | _270[0]=_265(_269[0],this); |
| 1516 | if(this.fractions_){ |
| 1517 | for(var j=1;j<_269.length;j++){ |
| 1518 | var vals=_269[j].split("/"); |
| 1519 | _270[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; |
| 1520 | } |
| 1521 | }else{ |
| 1522 | if(this.attr_("errorBars")){ |
| 1523 | for(var j=1;j<_269.length;j+=2){ |
| 1524 | _270[(j+1)/2]=[parseFloat(_269[j]),parseFloat(_269[j+1])]; |
| 1525 | } |
| 1526 | }else{ |
| 1527 | if(this.attr_("customBars")){ |
| 1528 | for(var j=1;j<_269.length;j++){ |
| 1529 | var vals=_269[j].split(";"); |
| 1530 | _270[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; |
| 1531 | } |
| 1532 | }else{ |
| 1533 | for(var j=1;j<_269.length;j++){ |
| 1534 | _270[j]=parseFloat(_269[j]); |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | } |
| 1539 | ret.push(_270); |
| 1540 | if(_270.length!=_267){ |
| 1541 | this.error("Number of columns in line "+i+" ("+_270.length+") does not agree with number of labels ("+_267+") "+line); |
| 1542 | } |
| 1543 | } |
| 1544 | return ret; |
| 1545 | }; |
| 1546 | Dygraph.prototype.parseArray_=function(data){ |
| 1547 | if(data.length==0){ |
| 1548 | this.error("Can't plot empty data set"); |
| 1549 | return null; |
| 1550 | } |
| 1551 | if(data[0].length==0){ |
| 1552 | this.error("Data set cannot contain an empty row"); |
| 1553 | return null; |
| 1554 | } |
| 1555 | if(this.attr_("labels")==null){ |
| 1556 | this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter"); |
| 1557 | this.attrs_.labels=["X"]; |
| 1558 | for(var i=1;i<data[0].length;i++){ |
| 1559 | this.attrs_.labels.push("Y"+i); |
| 1560 | } |
| 1561 | } |
| 1562 | if(Dygraph.isDateLike(data[0][0])){ |
| 1563 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
| 1564 | this.attrs_.xTicker=Dygraph.dateTicker; |
| 1565 | var _271=Dygraph.clone(data); |
| 1566 | for(var i=0;i<data.length;i++){ |
| 1567 | if(_271[i].length==0){ |
| 1568 | this.error("Row "<<(1+i)<<" of data is empty"); |
| 1569 | return null; |
| 1570 | } |
| 1571 | if(_271[i][0]==null||typeof (_271[i][0].getTime)!="function"){ |
| 1572 | this.error("x value in row "<<(1+i)<<" is not a Date"); |
| 1573 | return null; |
| 1574 | } |
| 1575 | _271[i][0]=_271[i][0].getTime(); |
| 1576 | } |
| 1577 | return _271; |
| 1578 | }else{ |
| 1579 | this.attrs_.xValueFormatter=function(x){ |
| 1580 | return x; |
| 1581 | }; |
| 1582 | this.attrs_.xTicker=Dygraph.numericTicks; |
| 1583 | return data; |
| 1584 | } |
| 1585 | }; |
| 1586 | Dygraph.prototype.parseDataTable_=function(data){ |
| 1587 | var cols=data.getNumberOfColumns(); |
| 1588 | var rows=data.getNumberOfRows(); |
| 1589 | var _274=[]; |
| 1590 | for(var i=0;i<cols;i++){ |
| 1591 | _274.push(data.getColumnLabel(i)); |
| 1592 | if(i!=0&&this.attr_("errorBars")){ |
| 1593 | i+=1; |
| 1594 | } |
| 1595 | } |
| 1596 | this.attrs_.labels=_274; |
| 1597 | cols=_274.length; |
| 1598 | var _275=data.getColumnType(0); |
| 1599 | if(_275=="date"){ |
| 1600 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
| 1601 | this.attrs_.xValueParser=Dygraph.dateParser; |
| 1602 | this.attrs_.xTicker=Dygraph.dateTicker; |
| 1603 | }else{ |
| 1604 | if(_275=="number"){ |
| 1605 | this.attrs_.xValueFormatter=function(x){ |
| 1606 | return x; |
| 1607 | }; |
| 1608 | this.attrs_.xValueParser=function(x){ |
| 1609 | return parseFloat(x); |
| 1610 | }; |
| 1611 | this.attrs_.xTicker=Dygraph.numericTicks; |
| 1612 | }else{ |
| 1613 | this.error("only 'date' and 'number' types are supported for column 1 "+"of DataTable input (Got '"+_275+"')"); |
| 1614 | return null; |
| 1615 | } |
| 1616 | } |
| 1617 | var ret=[]; |
| 1618 | for(var i=0;i<rows;i++){ |
| 1619 | var row=[]; |
| 1620 | if(typeof (data.getValue(i,0))==="undefined"||data.getValue(i,0)===null){ |
| 1621 | this.warning("Ignoring row "+i+" of DataTable because of undefined or null first column."); |
| 1622 | continue; |
| 1623 | } |
| 1624 | if(_275=="date"){ |
| 1625 | row.push(data.getValue(i,0).getTime()); |
| 1626 | }else{ |
| 1627 | row.push(data.getValue(i,0)); |
| 1628 | } |
| 1629 | if(!this.attr_("errorBars")){ |
| 1630 | for(var j=1;j<cols;j++){ |
| 1631 | row.push(data.getValue(i,j)); |
| 1632 | } |
| 1633 | }else{ |
| 1634 | for(var j=0;j<cols-1;j++){ |
| 1635 | row.push([data.getValue(i,1+2*j),data.getValue(i,2+2*j)]); |
| 1636 | } |
| 1637 | } |
| 1638 | ret.push(row); |
| 1639 | } |
| 1640 | return ret; |
| 1641 | }; |
| 1642 | Dygraph.update=function(self,o){ |
| 1643 | if(typeof (o)!="undefined"&&o!==null){ |
| 1644 | for(var k in o){ |
| 1645 | if(o.hasOwnProperty(k)){ |
| 1646 | self[k]=o[k]; |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | return self; |
| 1651 | }; |
| 1652 | Dygraph.isArrayLike=function(o){ |
| 1653 | var typ=typeof (o); |
| 1654 | if((typ!="object"&&!(typ=="function"&&typeof (o.item)=="function"))||o===null||typeof (o.length)!="number"||o.nodeType===3){ |
| 1655 | return false; |
| 1656 | } |
| 1657 | return true; |
| 1658 | }; |
| 1659 | Dygraph.isDateLike=function(o){ |
| 1660 | if(typeof (o)!="object"||o===null||typeof (o.getTime)!="function"){ |
| 1661 | return false; |
| 1662 | } |
| 1663 | return true; |
| 1664 | }; |
| 1665 | Dygraph.clone=function(o){ |
| 1666 | var r=[]; |
| 1667 | for(var i=0;i<o.length;i++){ |
| 1668 | if(Dygraph.isArrayLike(o[i])){ |
| 1669 | r.push(Dygraph.clone(o[i])); |
| 1670 | }else{ |
| 1671 | r.push(o[i]); |
| 1672 | } |
| 1673 | } |
| 1674 | return r; |
| 1675 | }; |
| 1676 | Dygraph.prototype.start_=function(){ |
| 1677 | if(typeof this.file_=="function"){ |
| 1678 | this.loadedEvent_(this.file_()); |
| 1679 | }else{ |
| 1680 | if(Dygraph.isArrayLike(this.file_)){ |
| 1681 | this.rawData_=this.parseArray_(this.file_); |
| 1682 | this.drawGraph_(this.rawData_); |
| 1683 | }else{ |
| 1684 | if(typeof this.file_=="object"&&typeof this.file_.getColumnRange=="function"){ |
| 1685 | this.rawData_=this.parseDataTable_(this.file_); |
| 1686 | this.drawGraph_(this.rawData_); |
| 1687 | }else{ |
| 1688 | if(typeof this.file_=="string"){ |
| 1689 | if(this.file_.indexOf("\n")>=0){ |
| 1690 | this.loadedEvent_(this.file_); |
| 1691 | }else{ |
| 1692 | var req=new XMLHttpRequest(); |
| 1693 | var _281=this; |
| 1694 | req.onreadystatechange=function(){ |
| 1695 | if(req.readyState==4){ |
| 1696 | if(req.status==200){ |
| 1697 | _281.loadedEvent_(req.responseText); |
| 1698 | } |
| 1699 | } |
| 1700 | }; |
| 1701 | req.open("GET",this.file_,true); |
| 1702 | req.send(null); |
| 1703 | } |
| 1704 | }else{ |
| 1705 | this.error("Unknown data format: "+(typeof this.file_)); |
| 1706 | } |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | }; |
| 1711 | Dygraph.prototype.updateOptions=function(_282){ |
| 1712 | if(_282.rollPeriod){ |
| 1713 | this.rollPeriod_=_282.rollPeriod; |
| 1714 | } |
| 1715 | if(_282.dateWindow){ |
| 1716 | this.dateWindow_=_282.dateWindow; |
| 1717 | } |
| 1718 | if(_282.valueRange){ |
| 1719 | this.valueRange_=_282.valueRange; |
| 1720 | } |
| 1721 | Dygraph.update(this.user_attrs_,_282); |
| 1722 | this.labelsFromCSV_=(this.attr_("labels")==null); |
| 1723 | this.layout_.updateOptions({"errorBars":this.attr_("errorBars")}); |
| 1724 | if(_282["file"]&&_282["file"]!=this.file_){ |
| 1725 | this.file_=_282["file"]; |
| 1726 | this.start_(); |
| 1727 | }else{ |
| 1728 | this.drawGraph_(this.rawData_); |
| 1729 | } |
| 1730 | }; |
| 1731 | Dygraph.prototype.resize=function(_283,_284){ |
| 1732 | if((_283===null)!=(_284===null)){ |
| 1733 | this.warn("Dygraph.resize() should be called with zero parameters or "+"two non-NULL parameters. Pretending it was zero."); |
| 1734 | _283=_284=null; |
| 1735 | } |
| 1736 | this.maindiv_.innerHTML=""; |
| 1737 | this.attrs_.labelsDiv=null; |
| 1738 | if(_283){ |
| 1739 | this.maindiv_.style.width=_283+"px"; |
| 1740 | this.maindiv_.style.height=_284+"px"; |
| 1741 | this.width_=_283; |
| 1742 | this.height_=_284; |
| 1743 | }else{ |
| 1744 | this.width_=this.maindiv_.offsetWidth; |
| 1745 | this.height_=this.maindiv_.offsetHeight; |
| 1746 | } |
| 1747 | this.createInterface_(); |
| 1748 | this.drawGraph_(this.rawData_); |
| 1749 | }; |
| 1750 | Dygraph.prototype.adjustRoll=function(_285){ |
| 1751 | this.rollPeriod_=_285; |
| 1752 | this.drawGraph_(this.rawData_); |
| 1753 | }; |
| 1754 | Dygraph.createCanvas=function(){ |
| 1755 | var _286=document.createElement("canvas"); |
| 1756 | isIE=(/MSIE/.test(navigator.userAgent)&&!window.opera); |
| 1757 | if(isIE){ |
| 1758 | _286=G_vmlCanvasManager.initElement(_286); |
| 1759 | } |
| 1760 | return _286; |
| 1761 | }; |
| 1762 | Dygraph.GVizChart=function(_287){ |
| 1763 | this.container=_287; |
| 1764 | }; |
| 1765 | Dygraph.GVizChart.prototype.draw=function(data,_288){ |
| 1766 | this.container.innerHTML=""; |
| 1767 | this.date_graph=new Dygraph(this.container,data,_288); |
| 1768 | }; |
| 1769 | DateGraph=Dygraph; |
| 1770 | function RGBColor(_289){ |
| 1771 | this.ok=false; |
| 1772 | if(_289.charAt(0)=="#"){ |
| 1773 | _289=_289.substr(1,6); |
| 1774 | } |
| 1775 | _289=_289.replace(/ /g,""); |
| 1776 | _289=_289.toLowerCase(); |
| 1777 | var _290={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"}; |
| 1778 | for(var key in _290){ |
| 1779 | if(_289==key){ |
| 1780 | _289=_290[key]; |
| 1781 | } |
| 1782 | } |
| 1783 | var _292=[{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){ |
| 1784 | return [parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])]; |
| 1785 | }},{re:/^(\w{2})(\w{2})(\w{2})$/,example:["#00ff00","336699"],process:function(bits){ |
| 1786 | return [parseInt(bits[1],16),parseInt(bits[2],16),parseInt(bits[3],16)]; |
| 1787 | }},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(bits){ |
| 1788 | return [parseInt(bits[1]+bits[1],16),parseInt(bits[2]+bits[2],16),parseInt(bits[3]+bits[3],16)]; |
| 1789 | }}]; |
| 1790 | for(var i=0;i<_292.length;i++){ |
| 1791 | var re=_292[i].re; |
| 1792 | var _295=_292[i].process; |
| 1793 | var bits=re.exec(_289); |
| 1794 | if(bits){ |
| 1795 | channels=_295(bits); |
| 1796 | this.r=channels[0]; |
| 1797 | this.g=channels[1]; |
| 1798 | this.b=channels[2]; |
| 1799 | this.ok=true; |
| 1800 | } |
| 1801 | } |
| 1802 | this.r=(this.r<0||isNaN(this.r))?0:((this.r>255)?255:this.r); |
| 1803 | this.g=(this.g<0||isNaN(this.g))?0:((this.g>255)?255:this.g); |
| 1804 | this.b=(this.b<0||isNaN(this.b))?0:((this.b>255)?255:this.b); |
| 1805 | this.toRGB=function(){ |
| 1806 | return "rgb("+this.r+", "+this.g+", "+this.b+")"; |
| 1807 | }; |
| 1808 | this.toHex=function(){ |
| 1809 | var r=this.r.toString(16); |
| 1810 | var g=this.g.toString(16); |
| 1811 | var b=this.b.toString(16); |
| 1812 | if(r.length==1){ |
| 1813 | r="0"+r; |
| 1814 | } |
| 1815 | if(g.length==1){ |
| 1816 | g="0"+g; |
| 1817 | } |
| 1818 | if(b.length==1){ |
| 1819 | b="0"+b; |
| 1820 | } |
| 1821 | return "#"+r+g+b; |
| 1822 | }; |
| 1823 | } |
| 1824 | |