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; | |
21 | for(var _6 in this.datasets){ | |
22 | var _7=this.datasets[_6]; | |
23 | var x1=_7[0][0]; | |
24 | if(!this.minxval||x1<this.minxval){ | |
25 | this.minxval=x1; | |
26 | } | |
27 | var x2=_7[_7.length-1][0]; | |
28 | if(!this.maxxval||x2>this.maxxval){ | |
29 | this.maxxval=x2; | |
30 | } | |
31 | } | |
32 | this.xrange=this.maxxval-this.minxval; | |
33 | this.xscale=(this.xrange!=0?1/this.xrange:1); | |
34 | this.minyval=this.options.yAxis[0]; | |
35 | this.maxyval=this.options.yAxis[1]; | |
36 | this.yrange=this.maxyval-this.minyval; | |
37 | this.yscale=(this.yrange!=0?1/this.yrange:1); | |
38 | }; | |
39 | DygraphLayout.prototype._evaluateLineCharts=function(){ | |
40 | this.points=new Array(); | |
41 | for(var _10 in this.datasets){ | |
42 | var _11=this.datasets[_10]; | |
43 | for(var j=0;j<_11.length;j++){ | |
44 | var _13=_11[j]; | |
45 | 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}; | |
46 | if(_14.y<=0){ | |
47 | _14.y=0; | |
48 | } | |
49 | if(_14.y>=1){ | |
50 | _14.y=1; | |
51 | } | |
52 | if((_14.x>=0)&&(_14.x<=1)){ | |
53 | this.points.push(_14); | |
54 | } | |
55 | } | |
56 | } | |
57 | }; | |
58 | DygraphLayout.prototype._evaluateLineTicks=function(){ | |
59 | this.xticks=new Array(); | |
60 | for(var i=0;i<this.options.xTicks.length;i++){ | |
61 | var _16=this.options.xTicks[i]; | |
62 | var _17=_16.label; | |
63 | var pos=this.xscale*(_16.v-this.minxval); | |
64 | if((pos>=0)&&(pos<=1)){ | |
65 | this.xticks.push([pos,_17]); | |
66 | } | |
67 | } | |
68 | this.yticks=new Array(); | |
69 | for(var i=0;i<this.options.yTicks.length;i++){ | |
70 | var _16=this.options.yTicks[i]; | |
71 | var _17=_16.label; | |
72 | var pos=1-(this.yscale*(_16.v-this.minyval)); | |
73 | if((pos>=0)&&(pos<=1)){ | |
74 | this.yticks.push([pos,_17]); | |
75 | } | |
76 | } | |
6a1aa64f | 77 | }; |
285a6bda | 78 | DygraphLayout.prototype.evaluateWithError=function(){ |
b2a516b8 DV |
79 | this.evaluate(); |
80 | if(!this.options.errorBars){ | |
81 | return; | |
82 | } | |
83 | var i=0; | |
efe0829a | 84 | for(var _19 in this.datasets){ |
b2a516b8 | 85 | var j=0; |
efe0829a | 86 | var _20=this.datasets[_19]; |
efe0829a DV |
87 | for(var j=0;j<_20.length;j++,i++){ |
88 | var _21=_20[j]; | |
89 | var xv=parseFloat(_21[0]); | |
90 | var yv=parseFloat(_21[1]); | |
b2a516b8 | 91 | if(xv==this.points[i].xval&&yv==this.points[i].yval){ |
efe0829a DV |
92 | this.points[i].errorMinus=parseFloat(_21[2]); |
93 | this.points[i].errorPlus=parseFloat(_21[3]); | |
b2a516b8 DV |
94 | } |
95 | } | |
96 | } | |
6a1aa64f | 97 | }; |
285a6bda | 98 | DygraphLayout.prototype.removeAllDatasets=function(){ |
b2a516b8 DV |
99 | delete this.datasets; |
100 | this.datasets=new Array(); | |
6a1aa64f | 101 | }; |
efe0829a | 102 | DygraphLayout.prototype.updateOptions=function(_24){ |
9c97d733 | 103 | Dygraph.update(this.options,_24?_24:{}); |
b2a516b8 | 104 | }; |
efe0829a | 105 | DygraphCanvasRenderer=function(_25,_26,_27,_28){ |
efe0829a | 106 | this.dygraph_=_25; |
f474c2a3 | 107 | 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 | 108 | Dygraph.update(this.options,_28); |
fbe31dc8 | 109 | this.layout=_27; |
b0c3b730 | 110 | this.element=_26; |
fbe31dc8 | 111 | this.container=this.element.parentNode; |
3df0ccf0 | 112 | this.isIE=(/MSIE/.test(navigator.userAgent)&&!window.opera); |
fbe31dc8 DV |
113 | if(this.isIE&&!isNil(G_vmlCanvasManager)){ |
114 | this.IEDelay=0.5; | |
115 | this.maxTries=5; | |
116 | this.renderDelay=null; | |
117 | this.clearDelay=null; | |
118 | this.element=G_vmlCanvasManager.initElement(this.element); | |
119 | } | |
120 | this.height=this.element.height; | |
121 | this.width=this.element.width; | |
122 | if(!this.isIE&&!(DygraphCanvasRenderer.isSupported(this.element))){ | |
123 | throw "Canvas is not supported."; | |
124 | } | |
125 | this.xlabels=new Array(); | |
126 | this.ylabels=new Array(); | |
127 | this.area={x:this.options.yAxisLabelWidth+2*this.options.axisTickSize,y:0}; | |
128 | this.area.w=this.width-this.area.x-this.options.rightGap; | |
129 | this.area.h=this.height-this.options.axisLabelFontSize-2*this.options.axisTickSize; | |
b0c3b730 DV |
130 | this.container.style.position="relative"; |
131 | this.container.style.width=this.width+"px"; | |
fbe31dc8 DV |
132 | }; |
133 | DygraphCanvasRenderer.prototype.clear=function(){ | |
134 | if(this.isIE){ | |
135 | try{ | |
136 | if(this.clearDelay){ | |
137 | this.clearDelay.cancel(); | |
138 | this.clearDelay=null; | |
139 | } | |
140 | var _29=this.element.getContext("2d"); | |
141 | } | |
142 | catch(e){ | |
143 | this.clearDelay=MochiKit.Async.wait(this.IEDelay); | |
144 | this.clearDelay.addCallback(bind(this.clear,this)); | |
145 | return; | |
146 | } | |
147 | } | |
148 | var _29=this.element.getContext("2d"); | |
149 | _29.clearRect(0,0,this.width,this.height); | |
2160ed4a | 150 | for(var i=0;i<this.xlabels.length;i++){ |
b0c3b730 DV |
151 | var el=this.xlabels[i]; |
152 | el.parentNode.removeChild(el); | |
2160ed4a DV |
153 | } |
154 | for(var i=0;i<this.ylabels.length;i++){ | |
b0c3b730 DV |
155 | var el=this.ylabels[i]; |
156 | el.parentNode.removeChild(el); | |
2160ed4a | 157 | } |
fbe31dc8 DV |
158 | this.xlabels=new Array(); |
159 | this.ylabels=new Array(); | |
160 | }; | |
b0c3b730 DV |
161 | DygraphCanvasRenderer.isSupported=function(_31){ |
162 | var _32=null; | |
fbe31dc8 | 163 | try{ |
21d3323f | 164 | if(typeof (_31)=="undefined"||_31==null){ |
b0c3b730 | 165 | _32=document.createElement("canvas"); |
fbe31dc8 | 166 | }else{ |
b0c3b730 | 167 | _32=_31; |
fbe31dc8 | 168 | } |
b0c3b730 | 169 | var _33=_32.getContext("2d"); |
fbe31dc8 DV |
170 | } |
171 | catch(e){ | |
172 | var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); | |
b0c3b730 DV |
173 | var _35=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); |
174 | if((!ie)||(ie[1]<6)||(_35)){ | |
fbe31dc8 DV |
175 | return false; |
176 | } | |
177 | return true; | |
178 | } | |
179 | return true; | |
b2a516b8 | 180 | }; |
285a6bda | 181 | DygraphCanvasRenderer.prototype.render=function(){ |
b2a516b8 DV |
182 | var ctx=this.element.getContext("2d"); |
183 | if(this.options.drawYGrid){ | |
b0c3b730 | 184 | var _37=this.layout.yticks; |
b2a516b8 | 185 | ctx.save(); |
f474c2a3 | 186 | ctx.strokeStyle=this.options.gridLineColor; |
b2a516b8 | 187 | ctx.lineWidth=this.options.axisLineWidth; |
b0c3b730 | 188 | for(var i=0;i<_37.length;i++){ |
b2a516b8 | 189 | var x=this.area.x; |
b0c3b730 | 190 | var y=this.area.y+_37[i][0]*this.area.h; |
b2a516b8 DV |
191 | ctx.beginPath(); |
192 | ctx.moveTo(x,y); | |
193 | ctx.lineTo(x+this.area.w,y); | |
194 | ctx.closePath(); | |
195 | ctx.stroke(); | |
196 | } | |
197 | } | |
198 | if(this.options.drawXGrid){ | |
b0c3b730 | 199 | var _37=this.layout.xticks; |
b2a516b8 | 200 | ctx.save(); |
f474c2a3 | 201 | ctx.strokeStyle=this.options.gridLineColor; |
b2a516b8 | 202 | ctx.lineWidth=this.options.axisLineWidth; |
b0c3b730 DV |
203 | for(var i=0;i<_37.length;i++){ |
204 | var x=this.area.x+_37[i][0]*this.area.w; | |
b2a516b8 DV |
205 | var y=this.area.y+this.area.h; |
206 | ctx.beginPath(); | |
207 | ctx.moveTo(x,y); | |
208 | ctx.lineTo(x,this.area.y); | |
209 | ctx.closePath(); | |
210 | ctx.stroke(); | |
211 | } | |
212 | } | |
2ce09b19 | 213 | this._renderLineChart(); |
fbe31dc8 | 214 | this._renderAxis(); |
b2a516b8 | 215 | }; |
fbe31dc8 DV |
216 | DygraphCanvasRenderer.prototype._renderAxis=function(){ |
217 | if(!this.options.drawXAxis&&!this.options.drawYAxis){ | |
218 | return; | |
219 | } | |
b0c3b730 | 220 | var _40=this.element.getContext("2d"); |
f474c2a3 | 221 | var _41={"position":"absolute","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor,"width":this.options.axisLabelWidth+"px","overflow":"hidden"}; |
bd597afc DV |
222 | var _42=function(txt){ |
223 | var div=document.createElement("div"); | |
224 | for(var _45 in _41){ | |
225 | div.style[_45]=_41[_45]; | |
226 | } | |
227 | div.appendChild(document.createTextNode(txt)); | |
228 | return div; | |
229 | }; | |
b0c3b730 | 230 | _40.save(); |
f474c2a3 | 231 | _40.strokeStyle=this.options.axisLineColor; |
b0c3b730 | 232 | _40.lineWidth=this.options.axisLineWidth; |
fbe31dc8 DV |
233 | if(this.options.drawYAxis){ |
234 | if(this.layout.yticks){ | |
2160ed4a | 235 | for(var i=0;i<this.layout.yticks.length;i++){ |
bd597afc DV |
236 | var _46=this.layout.yticks[i]; |
237 | if(typeof (_46)=="function"){ | |
fbe31dc8 DV |
238 | return; |
239 | } | |
240 | var x=this.area.x; | |
bd597afc | 241 | var y=this.area.y+_46[0]*this.area.h; |
b0c3b730 DV |
242 | _40.beginPath(); |
243 | _40.moveTo(x,y); | |
244 | _40.lineTo(x-this.options.axisTickSize,y); | |
245 | _40.closePath(); | |
246 | _40.stroke(); | |
bd597afc | 247 | var _47=_42(_46[1]); |
fbe31dc8 DV |
248 | var top=(y-this.options.axisLabelFontSize/2); |
249 | if(top<0){ | |
250 | top=0; | |
251 | } | |
252 | if(top+this.options.axisLabelFontSize+3>this.height){ | |
bd597afc | 253 | _47.style.bottom="0px"; |
fbe31dc8 | 254 | }else{ |
bd597afc | 255 | _47.style.top=top+"px"; |
fbe31dc8 | 256 | } |
bd597afc DV |
257 | _47.style.left="0px"; |
258 | _47.style.textAlign="right"; | |
259 | _47.style.width=this.options.yAxisLabelWidth+"px"; | |
260 | this.container.appendChild(_47); | |
261 | this.ylabels.push(_47); | |
2160ed4a | 262 | } |
bd597afc DV |
263 | var _49=this.ylabels[0]; |
264 | var _50=this.options.axisLabelFontSize; | |
265 | var _51=parseInt(_49.style.top)+_50; | |
266 | if(_51>this.height-_50){ | |
267 | _49.style.top=(parseInt(_49.style.top)-_50/2)+"px"; | |
fbe31dc8 DV |
268 | } |
269 | } | |
b0c3b730 DV |
270 | _40.beginPath(); |
271 | _40.moveTo(this.area.x,this.area.y); | |
272 | _40.lineTo(this.area.x,this.area.y+this.area.h); | |
273 | _40.closePath(); | |
274 | _40.stroke(); | |
fbe31dc8 DV |
275 | } |
276 | if(this.options.drawXAxis){ | |
277 | if(this.layout.xticks){ | |
2160ed4a | 278 | for(var i=0;i<this.layout.xticks.length;i++){ |
bd597afc | 279 | var _46=this.layout.xticks[i]; |
fbe31dc8 DV |
280 | if(typeof (dataset)=="function"){ |
281 | return; | |
282 | } | |
bd597afc | 283 | var x=this.area.x+_46[0]*this.area.w; |
fbe31dc8 | 284 | var y=this.area.y+this.area.h; |
b0c3b730 DV |
285 | _40.beginPath(); |
286 | _40.moveTo(x,y); | |
287 | _40.lineTo(x,y+this.options.axisTickSize); | |
288 | _40.closePath(); | |
289 | _40.stroke(); | |
bd597afc DV |
290 | var _47=_42(_46[1]); |
291 | _47.style.textAlign="center"; | |
292 | _47.style.bottom="0px"; | |
293 | var _52=(x-this.options.axisLabelWidth/2); | |
294 | if(_52+this.options.axisLabelWidth>this.width){ | |
295 | _52=this.width-this.options.xAxisLabelWidth; | |
296 | _47.style.textAlign="right"; | |
b0c3b730 | 297 | } |
bd597afc DV |
298 | if(_52<0){ |
299 | _52=0; | |
300 | _47.style.textAlign="left"; | |
b0c3b730 | 301 | } |
bd597afc DV |
302 | _47.style.left=_52+"px"; |
303 | _47.style.width=this.options.xAxisLabelWidth+"px"; | |
304 | this.container.appendChild(_47); | |
305 | this.xlabels.push(_47); | |
b0c3b730 DV |
306 | } |
307 | } | |
308 | _40.beginPath(); | |
309 | _40.moveTo(this.area.x,this.area.y+this.area.h); | |
310 | _40.lineTo(this.area.x+this.area.w,this.area.y+this.area.h); | |
311 | _40.closePath(); | |
312 | _40.stroke(); | |
313 | } | |
314 | _40.restore(); | |
efe0829a | 315 | }; |
fbe31dc8 | 316 | DygraphCanvasRenderer.prototype._renderLineChart=function(){ |
bd597afc DV |
317 | var _53=this.element.getContext("2d"); |
318 | var _54=this.options.colorScheme.length; | |
319 | var _55=this.options.colorScheme; | |
21d3323f | 320 | var _56=this.layout.options.errorBars; |
9c97d733 DV |
321 | var _57=[]; |
322 | for(var _58 in this.layout.datasets){ | |
323 | _57.push(_58); | |
21d3323f | 324 | } |
9c97d733 | 325 | var _59=_57.length; |
2160ed4a | 326 | for(var i=0;i<this.layout.points.length;i++){ |
9c97d733 DV |
327 | var _60=this.layout.points[i]; |
328 | _60.canvasx=this.area.w*_60.x+this.area.x; | |
329 | _60.canvasy=this.area.h*_60.y+this.area.y; | |
2160ed4a | 330 | } |
9c97d733 | 331 | var _61=function(x){ |
9317362d DV |
332 | return x&&!isNaN(x); |
333 | }; | |
9c97d733 DV |
334 | var ctx=_53; |
335 | if(_56){ | |
336 | for(var i=0;i<_59;i++){ | |
337 | var _62=_57[i]; | |
338 | var _63=_55[i%_54]; | |
339 | ctx.save(); | |
340 | ctx.strokeStyle=_63; | |
f474c2a3 | 341 | ctx.lineWidth=this.options.strokeWidth; |
9c97d733 DV |
342 | var _64=-1; |
343 | var _65=[-1,-1]; | |
344 | var _66=0; | |
345 | var _67=this.layout.yscale; | |
346 | var rgb=new RGBColor(_63); | |
347 | var _69="rgba("+rgb.r+","+rgb.g+","+rgb.b+",0.15)"; | |
348 | ctx.fillStyle=_69; | |
9317362d | 349 | ctx.beginPath(); |
9c97d733 DV |
350 | for(var j=0;j<this.layout.points.length;j++){ |
351 | var _60=this.layout.points[j]; | |
352 | _66++; | |
353 | if(_60.name==_62){ | |
354 | if(!_60.y||isNaN(_60.y)){ | |
355 | _64=-1; | |
356 | continue; | |
357 | } | |
358 | var _70=[_60.y-_60.errorPlus*_67,_60.y+_60.errorMinus*_67]; | |
359 | _70[0]=this.area.h*_70[0]+this.area.y; | |
360 | _70[1]=this.area.h*_70[1]+this.area.y; | |
361 | if(_64>=0){ | |
362 | ctx.moveTo(_64,_65[0]); | |
363 | ctx.lineTo(_60.canvasx,_70[0]); | |
364 | ctx.lineTo(_60.canvasx,_70[1]); | |
365 | ctx.lineTo(_64,_65[1]); | |
366 | ctx.closePath(); | |
9317362d | 367 | } |
9c97d733 DV |
368 | _65[0]=_70[0]; |
369 | _65[1]=_70[1]; | |
370 | _64=_60.canvasx; | |
b2a516b8 | 371 | } |
648acd28 | 372 | } |
9c97d733 | 373 | ctx.fill(); |
b2a516b8 | 374 | } |
b2a516b8 | 375 | } |
9c97d733 DV |
376 | for(var i=0;i<_59;i++){ |
377 | var _62=_57[i]; | |
378 | var _63=_55[i%_54]; | |
bd597afc | 379 | _53.save(); |
9c97d733 DV |
380 | var _60=this.layout.points[0]; |
381 | var _71=this.dygraph_.attr_("pointSize"); | |
382 | var _64=null,prevY=null; | |
383 | var _72=this.dygraph_.attr_("drawPoints"); | |
384 | var _73=this.layout.points; | |
385 | for(var j=0;j<_73.length;j++){ | |
386 | var _60=_73[j]; | |
387 | if(_60.name==_62){ | |
388 | if(!_61(_60.canvasy)){ | |
389 | _64=prevY=null; | |
390 | }else{ | |
391 | var _74=(!_64&&(j==_73.length-1||!_61(_73[j+1].canvasy))); | |
392 | if(!_64){ | |
393 | _64=_60.canvasx; | |
394 | prevY=_60.canvasy; | |
395 | }else{ | |
5fb1199a | 396 | ctx.beginPath(); |
9c97d733 DV |
397 | ctx.strokeStyle=_63; |
398 | ctx.lineWidth=this.options.strokeWidth; | |
399 | ctx.moveTo(_64,prevY); | |
400 | _64=_60.canvasx; | |
401 | prevY=_60.canvasy; | |
402 | ctx.lineTo(_64,prevY); | |
403 | ctx.stroke(); | |
648acd28 | 404 | } |
9c97d733 DV |
405 | if(_72||_74){ |
406 | ctx.beginPath(); | |
407 | ctx.fillStyle=_63; | |
408 | ctx.arc(_60.canvasx,_60.canvasy,_71,0,360,false); | |
409 | ctx.fill(); | |
5fb1199a | 410 | } |
b2a516b8 | 411 | } |
b2a516b8 | 412 | } |
b2a516b8 | 413 | } |
b2a516b8 | 414 | } |
bd597afc | 415 | _53.restore(); |
6a1aa64f | 416 | }; |
9c97d733 | 417 | Dygraph=function(div,_75,_76){ |
b2a516b8 | 418 | if(arguments.length>0){ |
285a6bda DV |
419 | if(arguments.length==4){ |
420 | this.warn("Using deprecated four-argument dygraph constructor"); | |
9c97d733 | 421 | this.__old_init__(div,_75,arguments[2],arguments[3]); |
285a6bda | 422 | }else{ |
9c97d733 | 423 | this.__init__(div,_75,_76); |
285a6bda | 424 | } |
b2a516b8 | 425 | } |
6a1aa64f | 426 | }; |
285a6bda DV |
427 | Dygraph.NAME="Dygraph"; |
428 | Dygraph.VERSION="1.2"; | |
429 | Dygraph.__repr__=function(){ | |
b2a516b8 | 430 | return "["+this.NAME+" "+this.VERSION+"]"; |
6a1aa64f | 431 | }; |
285a6bda | 432 | Dygraph.toString=function(){ |
b2a516b8 | 433 | return this.__repr__(); |
6a1aa64f | 434 | }; |
285a6bda DV |
435 | Dygraph.DEFAULT_ROLL_PERIOD=1; |
436 | Dygraph.DEFAULT_WIDTH=480; | |
437 | Dygraph.DEFAULT_HEIGHT=320; | |
438 | Dygraph.AXIS_LINE_WIDTH=0.3; | |
8846615a | 439 | Dygraph.DEFAULT_ATTRS={highlightCircleSize:3,pixelsPerXLabel:60,pixelsPerYLabel:30,labelsDivWidth:250,labelsDivStyles:{},labelsSeparateLines:false,labelsKMB:false,strokeWidth:1,axisTickSize:3,axisLabelFontSize:14,xAxisLabelWidth:50,yAxisLabelWidth:50,rightGap:5,showRoller:false,xValueFormatter:Dygraph.dateString_,xValueParser:Dygraph.dateParser,xTicker:Dygraph.dateTicker,sigma:2,errorBars:false,fractions:false,wilsonInterval:true,customBars:false}; |
285a6bda DV |
440 | Dygraph.DEBUG=1; |
441 | Dygraph.INFO=2; | |
442 | Dygraph.WARNING=3; | |
443 | Dygraph.ERROR=3; | |
9c97d733 DV |
444 | Dygraph.prototype.__old_init__=function(div,_77,_78,_79){ |
445 | if(_78!=null){ | |
446 | var _80=["Date"]; | |
447 | for(var i=0;i<_78.length;i++){ | |
448 | _80.push(_78[i]); | |
285a6bda | 449 | } |
9c97d733 | 450 | Dygraph.update(_79,{"labels":_80}); |
285a6bda | 451 | } |
9c97d733 | 452 | this.__init__(div,_77,_79); |
285a6bda | 453 | }; |
9c97d733 DV |
454 | Dygraph.prototype.__init__=function(div,_81,_82){ |
455 | if(_82==null){ | |
456 | _82={}; | |
285a6bda | 457 | } |
b2a516b8 | 458 | this.maindiv_=div; |
9c97d733 DV |
459 | this.file_=_81; |
460 | this.rollPeriod_=_82.rollPeriod||Dygraph.DEFAULT_ROLL_PERIOD; | |
b2a516b8 | 461 | this.previousVerticalX_=-1; |
9c97d733 DV |
462 | this.fractions_=_82.fractions||false; |
463 | this.dateWindow_=_82.dateWindow||null; | |
464 | this.valueRange_=_82.valueRange||null; | |
465 | this.wilsonInterval_=_82.wilsonInterval||true; | |
caf49918 | 466 | div.innerHTML=""; |
285a6bda DV |
467 | if(div.style.width==""){ |
468 | div.style.width=Dygraph.DEFAULT_WIDTH+"px"; | |
469 | } | |
470 | if(div.style.height==""){ | |
471 | div.style.height=Dygraph.DEFAULT_HEIGHT+"px"; | |
472 | } | |
b2a516b8 DV |
473 | this.width_=parseInt(div.style.width,10); |
474 | this.height_=parseInt(div.style.height,10); | |
285a6bda | 475 | this.user_attrs_={}; |
9c97d733 | 476 | Dygraph.update(this.user_attrs_,_82); |
b8339f6e | 477 | this.attrs_={}; |
9c97d733 | 478 | Dygraph.update(this.attrs_,Dygraph.DEFAULT_ATTRS); |
285a6bda | 479 | this.labelsFromCSV_=(this.attr_("labels")==null); |
b2a516b8 | 480 | this.createInterface_(); |
b64a4f1a | 481 | this.layoutOptions_={"errorBars":(this.attr_("errorBars")||this.attr_("customBars")),"xOriginIsZero":false}; |
9c97d733 DV |
482 | Dygraph.update(this.layoutOptions_,this.attrs_); |
483 | Dygraph.update(this.layoutOptions_,this.user_attrs_); | |
efe0829a | 484 | this.layout_=new DygraphLayout(this,this.layoutOptions_); |
8846615a | 485 | this.renderOptions_={colorScheme:this.colors_,strokeColor:null,axisLineWidth:Dygraph.AXIS_LINE_WIDTH}; |
9c97d733 DV |
486 | Dygraph.update(this.renderOptions_,this.attrs_); |
487 | Dygraph.update(this.renderOptions_,this.user_attrs_); | |
9317362d | 488 | this.plotter_=new DygraphCanvasRenderer(this,this.hidden_,this.layout_,this.renderOptions_); |
b2a516b8 DV |
489 | this.createStatusMessage_(); |
490 | this.createRollInterface_(); | |
491 | this.createDragInterface_(); | |
b2a516b8 | 492 | this.start_(); |
6a1aa64f | 493 | }; |
9c97d733 DV |
494 | Dygraph.prototype.attr_=function(_83){ |
495 | if(typeof (this.user_attrs_[_83])!="undefined"){ | |
496 | return this.user_attrs_[_83]; | |
285a6bda | 497 | }else{ |
9c97d733 DV |
498 | if(typeof (this.attrs_[_83])!="undefined"){ |
499 | return this.attrs_[_83]; | |
285a6bda DV |
500 | }else{ |
501 | return null; | |
502 | } | |
503 | } | |
504 | }; | |
9c97d733 | 505 | Dygraph.prototype.log=function(_84,_85){ |
285a6bda | 506 | if(typeof (console)!="undefined"){ |
9c97d733 | 507 | switch(_84){ |
285a6bda | 508 | case Dygraph.DEBUG: |
9c97d733 | 509 | console.debug("dygraphs: "+_85); |
285a6bda DV |
510 | break; |
511 | case Dygraph.INFO: | |
9c97d733 | 512 | console.info("dygraphs: "+_85); |
285a6bda DV |
513 | break; |
514 | case Dygraph.WARNING: | |
9c97d733 | 515 | console.warn("dygraphs: "+_85); |
285a6bda DV |
516 | break; |
517 | case Dygraph.ERROR: | |
9c97d733 | 518 | console.error("dygraphs: "+_85); |
285a6bda DV |
519 | break; |
520 | } | |
521 | } | |
522 | }; | |
9c97d733 DV |
523 | Dygraph.prototype.info=function(_86){ |
524 | this.log(Dygraph.INFO,_86); | |
285a6bda | 525 | }; |
9c97d733 DV |
526 | Dygraph.prototype.warn=function(_87){ |
527 | this.log(Dygraph.WARNING,_87); | |
285a6bda | 528 | }; |
9c97d733 DV |
529 | Dygraph.prototype.error=function(_88){ |
530 | this.log(Dygraph.ERROR,_88); | |
285a6bda DV |
531 | }; |
532 | Dygraph.prototype.rollPeriod=function(){ | |
b2a516b8 DV |
533 | return this.rollPeriod_; |
534 | }; | |
76171648 | 535 | Dygraph.addEvent=function(el,evt,fn){ |
9c97d733 | 536 | var _91=function(e){ |
76171648 DV |
537 | if(!e){ |
538 | var e=window.event; | |
539 | } | |
540 | fn(e); | |
541 | }; | |
542 | if(window.addEventListener){ | |
9c97d733 | 543 | el.addEventListener(evt,_91,false); |
76171648 | 544 | }else{ |
9c97d733 | 545 | el.attachEvent("on"+evt,_91); |
76171648 DV |
546 | } |
547 | }; | |
285a6bda | 548 | Dygraph.prototype.createInterface_=function(){ |
9c97d733 | 549 | var _93=this.maindiv_; |
b0c3b730 DV |
550 | this.graphDiv=document.createElement("div"); |
551 | this.graphDiv.style.width=this.width_+"px"; | |
552 | this.graphDiv.style.height=this.height_+"px"; | |
9c97d733 | 553 | _93.appendChild(this.graphDiv); |
b0c3b730 DV |
554 | this.canvas_=document.createElement("canvas"); |
555 | this.canvas_.style.position="absolute"; | |
556 | this.canvas_.width=this.width_; | |
557 | this.canvas_.height=this.height_; | |
558 | this.graphDiv.appendChild(this.canvas_); | |
b2a516b8 | 559 | this.hidden_=this.createPlotKitCanvas_(this.canvas_); |
9c97d733 | 560 | var _94=this; |
76171648 | 561 | Dygraph.addEvent(this.hidden_,"mousemove",function(e){ |
9c97d733 | 562 | _94.mouseMove_(e); |
b2a516b8 | 563 | }); |
76171648 | 564 | Dygraph.addEvent(this.hidden_,"mouseout",function(e){ |
9c97d733 | 565 | _94.mouseOut_(e); |
b2a516b8 | 566 | }); |
6a1aa64f | 567 | }; |
9c97d733 | 568 | Dygraph.prototype.createPlotKitCanvas_=function(_95){ |
b2a516b8 DV |
569 | var h=document.createElement("canvas"); |
570 | h.style.position="absolute"; | |
9c97d733 DV |
571 | h.style.top=_95.style.top; |
572 | h.style.left=_95.style.left; | |
b2a516b8 DV |
573 | h.width=this.width_; |
574 | h.height=this.height_; | |
b0c3b730 | 575 | this.graphDiv.appendChild(h); |
b2a516b8 DV |
576 | return h; |
577 | }; | |
9c97d733 | 578 | Dygraph.hsvToRGB=function(hue,_98,_99){ |
f474c2a3 | 579 | var red; |
9c97d733 | 580 | var _101; |
f474c2a3 | 581 | var blue; |
9c97d733 DV |
582 | if(_98===0){ |
583 | red=_99; | |
584 | _101=_99; | |
585 | blue=_99; | |
f474c2a3 DV |
586 | }else{ |
587 | var i=Math.floor(hue*6); | |
588 | var f=(hue*6)-i; | |
9c97d733 DV |
589 | var p=_99*(1-_98); |
590 | var q=_99*(1-(_98*f)); | |
591 | var t=_99*(1-(_98*(1-f))); | |
f474c2a3 DV |
592 | switch(i){ |
593 | case 1: | |
594 | red=q; | |
9c97d733 | 595 | _101=_99; |
f474c2a3 DV |
596 | blue=p; |
597 | break; | |
598 | case 2: | |
599 | red=p; | |
9c97d733 | 600 | _101=_99; |
f474c2a3 DV |
601 | blue=t; |
602 | break; | |
603 | case 3: | |
604 | red=p; | |
9c97d733 DV |
605 | _101=q; |
606 | blue=_99; | |
f474c2a3 DV |
607 | break; |
608 | case 4: | |
609 | red=t; | |
9c97d733 DV |
610 | _101=p; |
611 | blue=_99; | |
f474c2a3 DV |
612 | break; |
613 | case 5: | |
9c97d733 DV |
614 | red=_99; |
615 | _101=p; | |
f474c2a3 DV |
616 | blue=q; |
617 | break; | |
618 | case 6: | |
619 | case 0: | |
9c97d733 DV |
620 | red=_99; |
621 | _101=t; | |
f474c2a3 DV |
622 | blue=p; |
623 | break; | |
624 | } | |
625 | } | |
626 | red=Math.floor(255*red+0.5); | |
9c97d733 | 627 | _101=Math.floor(255*_101+0.5); |
f474c2a3 | 628 | blue=Math.floor(255*blue+0.5); |
9c97d733 | 629 | return "rgb("+red+","+_101+","+blue+")"; |
f474c2a3 | 630 | }; |
285a6bda DV |
631 | Dygraph.prototype.setColors_=function(){ |
632 | var num=this.attr_("labels").length-1; | |
b2a516b8 | 633 | this.colors_=[]; |
9c97d733 DV |
634 | var _108=this.attr_("colors"); |
635 | if(!_108){ | |
285a6bda DV |
636 | var sat=this.attr_("colorSaturation")||1; |
637 | var val=this.attr_("colorValue")||0.5; | |
b2a516b8 DV |
638 | for(var i=1;i<=num;i++){ |
639 | var hue=(1*i/(1+num)); | |
f474c2a3 | 640 | this.colors_.push(Dygraph.hsvToRGB(hue,sat,val)); |
b2a516b8 DV |
641 | } |
642 | }else{ | |
643 | for(var i=0;i<num;i++){ | |
9c97d733 DV |
644 | var _111=_108[i%_108.length]; |
645 | this.colors_.push(_111); | |
b2a516b8 | 646 | } |
b2a516b8 | 647 | } |
285a6bda | 648 | this.renderOptions_.colorScheme=this.colors_; |
9c97d733 DV |
649 | Dygraph.update(this.plotter_.options,this.renderOptions_); |
650 | Dygraph.update(this.layoutOptions_,this.user_attrs_); | |
651 | Dygraph.update(this.layoutOptions_,this.attrs_); | |
b2a516b8 | 652 | }; |
3df0ccf0 | 653 | Dygraph.findPosX=function(obj){ |
9c97d733 | 654 | var _113=0; |
3df0ccf0 DV |
655 | if(obj.offsetParent){ |
656 | while(obj.offsetParent){ | |
9c97d733 | 657 | _113+=obj.offsetLeft; |
3df0ccf0 DV |
658 | obj=obj.offsetParent; |
659 | } | |
660 | }else{ | |
661 | if(obj.x){ | |
9c97d733 | 662 | _113+=obj.x; |
3df0ccf0 DV |
663 | } |
664 | } | |
9c97d733 | 665 | return _113; |
3df0ccf0 DV |
666 | }; |
667 | Dygraph.findPosY=function(obj){ | |
9c97d733 | 668 | var _114=0; |
3df0ccf0 DV |
669 | if(obj.offsetParent){ |
670 | while(obj.offsetParent){ | |
9c97d733 | 671 | _114+=obj.offsetTop; |
3df0ccf0 DV |
672 | obj=obj.offsetParent; |
673 | } | |
674 | }else{ | |
675 | if(obj.y){ | |
9c97d733 | 676 | _114+=obj.y; |
3df0ccf0 DV |
677 | } |
678 | } | |
9c97d733 | 679 | return _114; |
3df0ccf0 | 680 | }; |
285a6bda DV |
681 | Dygraph.prototype.createStatusMessage_=function(){ |
682 | if(!this.attr_("labelsDiv")){ | |
9c97d733 DV |
683 | var _115=this.attr_("labelsDivWidth"); |
684 | 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"}; | |
685 | Dygraph.update(_116,this.attr_("labelsDivStyles")); | |
b0c3b730 | 686 | var div=document.createElement("div"); |
9c97d733 DV |
687 | for(var name in _116){ |
688 | div.style[name]=_116[name]; | |
b0c3b730 DV |
689 | } |
690 | this.graphDiv.appendChild(div); | |
285a6bda DV |
691 | this.attrs_.labelsDiv=div; |
692 | } | |
693 | }; | |
694 | Dygraph.prototype.createRollInterface_=function(){ | |
9c97d733 DV |
695 | var _118=this.attr_("showRoller")?"block":"none"; |
696 | var _119={"position":"absolute","zIndex":10,"top":(this.plotter_.area.h-25)+"px","left":(this.plotter_.area.x+1)+"px","display":_118}; | |
697 | var _120=document.createElement("input"); | |
698 | _120.type="text"; | |
699 | _120.size="2"; | |
700 | _120.value=this.rollPeriod_; | |
701 | for(var name in _119){ | |
702 | _120.style[name]=_119[name]; | |
b0c3b730 | 703 | } |
b2a516b8 | 704 | var pa=this.graphDiv; |
9c97d733 DV |
705 | pa.appendChild(_120); |
706 | var _122=this; | |
707 | _120.onchange=function(){ | |
708 | _122.adjustRoll(_120.value); | |
76171648 | 709 | }; |
9c97d733 | 710 | return _120; |
76171648 DV |
711 | }; |
712 | Dygraph.pageX=function(e){ | |
713 | if(e.pageX){ | |
714 | return (!e.pageX||e.pageX<0)?0:e.pageX; | |
715 | }else{ | |
716 | var de=document; | |
717 | var b=document.body; | |
718 | return e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); | |
719 | } | |
720 | }; | |
721 | Dygraph.pageY=function(e){ | |
722 | if(e.pageY){ | |
723 | return (!e.pageY||e.pageY<0)?0:e.pageY; | |
724 | }else{ | |
725 | var de=document; | |
726 | var b=document.body; | |
727 | return e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0); | |
728 | } | |
285a6bda DV |
729 | }; |
730 | Dygraph.prototype.createDragInterface_=function(){ | |
fbe31dc8 | 731 | var self=this; |
9c97d733 DV |
732 | var _126=false; |
733 | var _127=null; | |
734 | var _128=null; | |
735 | var _129=null; | |
736 | var _130=null; | |
737 | var _131=null; | |
353a0294 DV |
738 | var px=0; |
739 | var py=0; | |
efe0829a | 740 | var getX=function(e){ |
76171648 | 741 | return Dygraph.pageX(e)-px; |
b2a516b8 | 742 | }; |
efe0829a | 743 | var getY=function(e){ |
76171648 | 744 | return Dygraph.pageX(e)-py; |
b2a516b8 | 745 | }; |
9c97d733 DV |
746 | Dygraph.addEvent(this.hidden_,"mousemove",function(_136){ |
747 | if(_126){ | |
748 | _129=getX(_136); | |
749 | _130=getY(_136); | |
750 | self.drawZoomRect_(_127,_129,_131); | |
751 | _131=_129; | |
6a1aa64f | 752 | } |
b2a516b8 | 753 | }); |
9c97d733 DV |
754 | Dygraph.addEvent(this.hidden_,"mousedown",function(_137){ |
755 | _126=true; | |
3df0ccf0 DV |
756 | px=Dygraph.findPosX(self.canvas_); |
757 | py=Dygraph.findPosY(self.canvas_); | |
9c97d733 DV |
758 | _127=getX(_137); |
759 | _128=getY(_137); | |
b2a516b8 | 760 | }); |
9c97d733 DV |
761 | Dygraph.addEvent(document,"mouseup",function(_138){ |
762 | if(_126){ | |
763 | _126=false; | |
764 | _127=null; | |
765 | _128=null; | |
6a1aa64f | 766 | } |
b2a516b8 | 767 | }); |
9c97d733 DV |
768 | Dygraph.addEvent(this.hidden_,"mouseout",function(_139){ |
769 | if(_126){ | |
770 | _129=null; | |
771 | _130=null; | |
6a1aa64f | 772 | } |
b2a516b8 | 773 | }); |
9c97d733 DV |
774 | Dygraph.addEvent(this.hidden_,"mouseup",function(_140){ |
775 | if(_126){ | |
776 | _126=false; | |
777 | _129=getX(_140); | |
778 | _130=getY(_140); | |
779 | var _141=Math.abs(_129-_127); | |
780 | var _142=Math.abs(_130-_128); | |
781 | if(_141<2&&_142<2&&self.attr_("clickCallback")!=null&&self.lastx_!=undefined){ | |
782 | self.attr_("clickCallback")(_140,new Date(self.lastx_)); | |
783 | } | |
784 | if(_141>=10){ | |
785 | self.doZoom_(Math.min(_127,_129),Math.max(_127,_129)); | |
b2a516b8 | 786 | }else{ |
fbe31dc8 | 787 | self.canvas_.getContext("2d").clearRect(0,0,self.canvas_.width,self.canvas_.height); |
b2a516b8 | 788 | } |
9c97d733 DV |
789 | _127=null; |
790 | _128=null; | |
b2a516b8 DV |
791 | } |
792 | }); | |
9c97d733 | 793 | Dygraph.addEvent(this.hidden_,"dblclick",function(_143){ |
fbe31dc8 DV |
794 | self.dateWindow_=null; |
795 | self.drawGraph_(self.rawData_); | |
9c97d733 DV |
796 | var _144=self.rawData_[0][0]; |
797 | var _145=self.rawData_[self.rawData_.length-1][0]; | |
fbe31dc8 | 798 | if(self.attr_("zoomCallback")){ |
9c97d733 | 799 | self.attr_("zoomCallback")(_144,_145); |
67e650dc | 800 | } |
b2a516b8 | 801 | }); |
6a1aa64f | 802 | }; |
9c97d733 | 803 | Dygraph.prototype.drawZoomRect_=function(_146,endX,_148){ |
b2a516b8 | 804 | var ctx=this.canvas_.getContext("2d"); |
9c97d733 DV |
805 | if(_148){ |
806 | ctx.clearRect(Math.min(_146,_148),0,Math.abs(_146-_148),this.height_); | |
b2a516b8 | 807 | } |
9c97d733 | 808 | if(endX&&_146){ |
b2a516b8 | 809 | ctx.fillStyle="rgba(128,128,128,0.33)"; |
9c97d733 | 810 | ctx.fillRect(Math.min(_146,endX),0,Math.abs(endX-_146),this.height_); |
b2a516b8 DV |
811 | } |
812 | }; | |
9c97d733 DV |
813 | Dygraph.prototype.doZoom_=function(lowX,_150){ |
814 | var _151=this.layout_.points; | |
815 | var _152=null; | |
816 | var _153=null; | |
817 | for(var i=0;i<_151.length;i++){ | |
818 | var cx=_151[i].canvasx; | |
819 | var x=_151[i].xval; | |
820 | if(cx<lowX&&(_152==null||x>_152)){ | |
821 | _152=x; | |
b2a516b8 | 822 | } |
9c97d733 DV |
823 | if(cx>_150&&(_153==null||x<_153)){ |
824 | _153=x; | |
b2a516b8 | 825 | } |
b2a516b8 | 826 | } |
9c97d733 DV |
827 | if(_152==null){ |
828 | _152=_151[0].xval; | |
b2a516b8 | 829 | } |
9c97d733 DV |
830 | if(_153==null){ |
831 | _153=_151[_151.length-1].xval; | |
b0c3b730 | 832 | } |
9c97d733 | 833 | this.dateWindow_=[_152,_153]; |
b2a516b8 | 834 | this.drawGraph_(this.rawData_); |
285a6bda | 835 | if(this.attr_("zoomCallback")){ |
9c97d733 | 836 | this.attr_("zoomCallback")(_152,_153); |
67e650dc | 837 | } |
b2a516b8 | 838 | }; |
9c97d733 DV |
839 | Dygraph.prototype.mouseMove_=function(_155){ |
840 | var _156=Dygraph.pageX(_155)-Dygraph.findPosX(this.hidden_); | |
841 | var _157=this.layout_.points; | |
842 | var _158=-1; | |
843 | var _159=-1; | |
844 | var _160=1e+100; | |
b2a516b8 | 845 | var idx=-1; |
9c97d733 DV |
846 | for(var i=0;i<_157.length;i++){ |
847 | var dist=Math.abs(_157[i].canvasx-_156); | |
848 | if(dist>_160){ | |
b2a516b8 DV |
849 | break; |
850 | } | |
9c97d733 | 851 | _160=dist; |
b2a516b8 DV |
852 | idx=i; |
853 | } | |
854 | if(idx>=0){ | |
9c97d733 | 855 | _158=_157[idx].xval; |
b2a516b8 | 856 | } |
9c97d733 DV |
857 | if(_156>_157[_157.length-1].canvasx){ |
858 | _158=_157[_157.length-1].xval; | |
b2a516b8 | 859 | } |
9c97d733 DV |
860 | var _163=[]; |
861 | for(var i=0;i<_157.length;i++){ | |
862 | if(_157[i].xval==_158){ | |
863 | _163.push(_157[i]); | |
b2a516b8 DV |
864 | } |
865 | } | |
9c97d733 | 866 | var _164=this.attr_("highlightCircleSize"); |
b2a516b8 DV |
867 | var ctx=this.canvas_.getContext("2d"); |
868 | if(this.previousVerticalX_>=0){ | |
869 | var px=this.previousVerticalX_; | |
9c97d733 | 870 | ctx.clearRect(px-_164-1,0,2*_164+2,this.height_); |
b2a516b8 | 871 | } |
648acd28 DV |
872 | var isOK=function(x){ |
873 | return x&&!isNaN(x); | |
874 | }; | |
9c97d733 DV |
875 | if(_163.length>0){ |
876 | var _156=_163[0].canvasx; | |
877 | var _166=this.attr_("xValueFormatter")(_158,this)+":"; | |
b2a516b8 | 878 | var clen=this.colors_.length; |
9c97d733 DV |
879 | for(var i=0;i<_163.length;i++){ |
880 | if(!isOK(_163[i].canvasy)){ | |
648acd28 DV |
881 | continue; |
882 | } | |
285a6bda | 883 | if(this.attr_("labelsSeparateLines")){ |
9c97d733 | 884 | _166+="<br/>"; |
b2a516b8 | 885 | } |
9c97d733 | 886 | var _168=_163[i]; |
f474c2a3 | 887 | var c=new RGBColor(this.colors_[i%clen]); |
9c97d733 | 888 | _166+=" <b><font color='"+c.toHex()+"'>"+_168.name+"</font></b>:"+this.round_(_168.yval,2); |
b2a516b8 | 889 | } |
9c97d733 DV |
890 | this.attr_("labelsDiv").innerHTML=_166; |
891 | this.lastx_=_158; | |
b2a516b8 | 892 | ctx.save(); |
9c97d733 DV |
893 | for(var i=0;i<_163.length;i++){ |
894 | if(!isOK(_163[i%clen].canvasy)){ | |
648acd28 DV |
895 | continue; |
896 | } | |
b2a516b8 | 897 | ctx.beginPath(); |
f474c2a3 | 898 | ctx.fillStyle=this.colors_[i%clen]; |
9c97d733 | 899 | ctx.arc(_156,_163[i%clen].canvasy,_164,0,360,false); |
b2a516b8 DV |
900 | ctx.fill(); |
901 | } | |
902 | ctx.restore(); | |
9c97d733 | 903 | this.previousVerticalX_=_156; |
b2a516b8 | 904 | } |
6a1aa64f | 905 | }; |
9c97d733 | 906 | Dygraph.prototype.mouseOut_=function(_170){ |
b2a516b8 DV |
907 | var ctx=this.canvas_.getContext("2d"); |
908 | ctx.clearRect(0,0,this.width_,this.height_); | |
285a6bda | 909 | this.attr_("labelsDiv").innerHTML=""; |
6a1aa64f | 910 | }; |
285a6bda | 911 | Dygraph.zeropad=function(x){ |
6372d433 DV |
912 | if(x<10){ |
913 | return "0"+x; | |
914 | }else{ | |
915 | return ""+x; | |
916 | } | |
917 | }; | |
285a6bda | 918 | Dygraph.prototype.hmsString_=function(date){ |
9c97d733 | 919 | var _172=Dygraph.zeropad; |
6372d433 DV |
920 | var d=new Date(date); |
921 | if(d.getSeconds()){ | |
9c97d733 | 922 | return _172(d.getHours())+":"+_172(d.getMinutes())+":"+_172(d.getSeconds()); |
6372d433 DV |
923 | }else{ |
924 | if(d.getMinutes()){ | |
9c97d733 | 925 | return _172(d.getHours())+":"+_172(d.getMinutes()); |
6372d433 | 926 | }else{ |
9c97d733 | 927 | return _172(d.getHours()); |
6372d433 DV |
928 | } |
929 | } | |
930 | }; | |
285a6bda | 931 | Dygraph.dateString_=function(date,self){ |
9c97d733 | 932 | var _174=Dygraph.zeropad; |
b2a516b8 DV |
933 | var d=new Date(date); |
934 | var year=""+d.getFullYear(); | |
9c97d733 DV |
935 | var _176=_174(d.getMonth()+1); |
936 | var day=_174(d.getDate()); | |
6372d433 DV |
937 | var ret=""; |
938 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
939 | if(frac){ | |
285a6bda | 940 | ret=" "+self.hmsString_(date); |
b2a516b8 | 941 | } |
9c97d733 | 942 | return year+"/"+_176+"/"+day+ret; |
6a1aa64f | 943 | }; |
9c97d733 DV |
944 | Dygraph.prototype.round_=function(num,_180){ |
945 | var _181=Math.pow(10,_180); | |
946 | return Math.round(num*_181)/_181; | |
6a1aa64f | 947 | }; |
285a6bda | 948 | Dygraph.prototype.loadedEvent_=function(data){ |
b2a516b8 DV |
949 | this.rawData_=this.parseCSV_(data); |
950 | this.drawGraph_(this.rawData_); | |
6a1aa64f | 951 | }; |
285a6bda DV |
952 | Dygraph.prototype.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; |
953 | Dygraph.prototype.quarters=["Jan","Apr","Jul","Oct"]; | |
954 | Dygraph.prototype.addXTicks_=function(){ | |
9c97d733 | 955 | var _183,endDate; |
b2a516b8 | 956 | if(this.dateWindow_){ |
9c97d733 | 957 | _183=this.dateWindow_[0]; |
b2a516b8 DV |
958 | endDate=this.dateWindow_[1]; |
959 | }else{ | |
9c97d733 | 960 | _183=this.rawData_[0][0]; |
b2a516b8 DV |
961 | endDate=this.rawData_[this.rawData_.length-1][0]; |
962 | } | |
9c97d733 DV |
963 | var _184=this.attr_("xTicker")(_183,endDate,this); |
964 | this.layout_.updateOptions({xTicks:_184}); | |
285a6bda DV |
965 | }; |
966 | Dygraph.SECONDLY=0; | |
967 | Dygraph.TEN_SECONDLY=1; | |
968 | Dygraph.THIRTY_SECONDLY=2; | |
969 | Dygraph.MINUTELY=3; | |
970 | Dygraph.TEN_MINUTELY=4; | |
971 | Dygraph.THIRTY_MINUTELY=5; | |
972 | Dygraph.HOURLY=6; | |
973 | Dygraph.SIX_HOURLY=7; | |
974 | Dygraph.DAILY=8; | |
975 | Dygraph.WEEKLY=9; | |
976 | Dygraph.MONTHLY=10; | |
977 | Dygraph.QUARTERLY=11; | |
978 | Dygraph.BIANNUAL=12; | |
979 | Dygraph.ANNUAL=13; | |
980 | Dygraph.DECADAL=14; | |
981 | Dygraph.NUM_GRANULARITIES=15; | |
982 | Dygraph.SHORT_SPACINGS=[]; | |
983 | Dygraph.SHORT_SPACINGS[Dygraph.SECONDLY]=1000*1; | |
984 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_SECONDLY]=1000*10; | |
985 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_SECONDLY]=1000*30; | |
986 | Dygraph.SHORT_SPACINGS[Dygraph.MINUTELY]=1000*60; | |
987 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_MINUTELY]=1000*60*10; | |
988 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_MINUTELY]=1000*60*30; | |
989 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600; | |
990 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600*6; | |
991 | Dygraph.SHORT_SPACINGS[Dygraph.DAILY]=1000*86400; | |
992 | Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY]=1000*604800; | |
9c97d733 DV |
993 | Dygraph.prototype.NumXTicks=function(_185,_186,_187){ |
994 | if(_187<Dygraph.MONTHLY){ | |
995 | var _188=Dygraph.SHORT_SPACINGS[_187]; | |
996 | return Math.floor(0.5+1*(_186-_185)/_188); | |
285a6bda | 997 | }else{ |
9c97d733 DV |
998 | var _189=1; |
999 | var _190=12; | |
1000 | if(_187==Dygraph.QUARTERLY){ | |
1001 | _190=3; | |
285a6bda | 1002 | } |
9c97d733 DV |
1003 | if(_187==Dygraph.BIANNUAL){ |
1004 | _190=2; | |
285a6bda | 1005 | } |
9c97d733 DV |
1006 | if(_187==Dygraph.ANNUAL){ |
1007 | _190=1; | |
285a6bda | 1008 | } |
9c97d733 DV |
1009 | if(_187==Dygraph.DECADAL){ |
1010 | _190=1; | |
1011 | _189=10; | |
285a6bda | 1012 | } |
9c97d733 DV |
1013 | var _191=365.2524*24*3600*1000; |
1014 | var _192=1*(_186-_185)/_191; | |
1015 | return Math.floor(0.5+1*_192*_190/_189); | |
285a6bda DV |
1016 | } |
1017 | }; | |
9c97d733 DV |
1018 | Dygraph.prototype.GetXAxis=function(_193,_194,_195){ |
1019 | var _196=[]; | |
1020 | if(_195<Dygraph.MONTHLY){ | |
1021 | var _197=Dygraph.SHORT_SPACINGS[_195]; | |
1022 | var _198="%d%b"; | |
1023 | if(_195<Dygraph.HOURLY){ | |
1024 | _193=_197*Math.floor(0.5+_193/_197); | |
bd597afc | 1025 | } |
9c97d733 | 1026 | for(var t=_193;t<=_194;t+=_197){ |
36615faf DV |
1027 | var d=new Date(t); |
1028 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
9c97d733 DV |
1029 | if(frac==0||_195>=Dygraph.DAILY){ |
1030 | _196.push({v:t,label:new Date(t+3600*1000).strftime(_198)}); | |
b2a516b8 | 1031 | }else{ |
9c97d733 | 1032 | _196.push({v:t,label:this.hmsString_(t)}); |
36615faf DV |
1033 | } |
1034 | } | |
b2a516b8 | 1035 | }else{ |
9c97d733 DV |
1036 | var _199; |
1037 | var _200=1; | |
1038 | if(_195==Dygraph.MONTHLY){ | |
1039 | _199=[0,1,2,3,4,5,6,7,8,9,10,11,12]; | |
b2a516b8 | 1040 | }else{ |
9c97d733 DV |
1041 | if(_195==Dygraph.QUARTERLY){ |
1042 | _199=[0,3,6,9]; | |
b2a516b8 | 1043 | }else{ |
9c97d733 DV |
1044 | if(_195==Dygraph.BIANNUAL){ |
1045 | _199=[0,6]; | |
b2a516b8 | 1046 | }else{ |
9c97d733 DV |
1047 | if(_195==Dygraph.ANNUAL){ |
1048 | _199=[0]; | |
6372d433 | 1049 | }else{ |
9c97d733 DV |
1050 | if(_195==Dygraph.DECADAL){ |
1051 | _199=[0]; | |
1052 | _200=10; | |
b2a516b8 DV |
1053 | } |
1054 | } | |
1055 | } | |
1056 | } | |
6372d433 | 1057 | } |
9c97d733 DV |
1058 | var _201=new Date(_193).getFullYear(); |
1059 | var _202=new Date(_194).getFullYear(); | |
1060 | var _203=Dygraph.zeropad; | |
1061 | for(var i=_201;i<=_202;i++){ | |
1062 | if(i%_200!=0){ | |
36615faf | 1063 | continue; |
6372d433 | 1064 | } |
9c97d733 DV |
1065 | for(var j=0;j<_199.length;j++){ |
1066 | var _204=i+"/"+_203(1+_199[j])+"/01"; | |
1067 | var t=Date.parse(_204); | |
1068 | if(t<_193||t>_194){ | |
b2a516b8 DV |
1069 | continue; |
1070 | } | |
9c97d733 | 1071 | _196.push({v:t,label:new Date(t).strftime("%b %y")}); |
b2a516b8 DV |
1072 | } |
1073 | } | |
b2a516b8 | 1074 | } |
9c97d733 | 1075 | return _196; |
36615faf | 1076 | }; |
9c97d733 DV |
1077 | Dygraph.dateTicker=function(_205,_206,self){ |
1078 | var _207=-1; | |
285a6bda | 1079 | for(var i=0;i<Dygraph.NUM_GRANULARITIES;i++){ |
9c97d733 DV |
1080 | var _208=self.NumXTicks(_205,_206,i); |
1081 | if(self.width_/_208>=self.attr_("pixelsPerXLabel")){ | |
1082 | _207=i; | |
36615faf DV |
1083 | break; |
1084 | } | |
b2a516b8 | 1085 | } |
9c97d733 DV |
1086 | if(_207>=0){ |
1087 | return self.GetXAxis(_205,_206,_207); | |
36615faf | 1088 | }else{ |
6372d433 | 1089 | } |
6a1aa64f | 1090 | }; |
285a6bda | 1091 | Dygraph.numericTicks=function(minV,maxV,self){ |
9c97d733 DV |
1092 | var _211=[1,2,5]; |
1093 | var _212,low_val,high_val,nTicks; | |
1094 | var _213=self.attr_("pixelsPerYLabel"); | |
2ce09b19 | 1095 | for(var i=-10;i<50;i++){ |
9c97d733 DV |
1096 | var _214=Math.pow(10,i); |
1097 | for(var j=0;j<_211.length;j++){ | |
1098 | _212=_214*_211[j]; | |
1099 | low_val=Math.floor(minV/_212)*_212; | |
1100 | high_val=Math.ceil(maxV/_212)*_212; | |
1101 | nTicks=(high_val-low_val)/_212; | |
1102 | var _215=self.height_/nTicks; | |
1103 | if(_215>_213){ | |
2ce09b19 | 1104 | break; |
6a1aa64f | 1105 | } |
b2a516b8 | 1106 | } |
9c97d733 | 1107 | if(_215>_213){ |
2ce09b19 | 1108 | break; |
b2a516b8 | 1109 | } |
2ce09b19 | 1110 | } |
9c97d733 | 1111 | var _216=[]; |
2ce09b19 | 1112 | for(var i=0;i<nTicks;i++){ |
9c97d733 DV |
1113 | var _217=low_val+i*_212; |
1114 | var _218=self.round_(_217,2); | |
285a6bda | 1115 | if(self.attr_("labelsKMB")){ |
b2a516b8 | 1116 | var k=1000; |
9c97d733 DV |
1117 | if(_217>=k*k*k){ |
1118 | _218=self.round_(_217/(k*k*k),1)+"B"; | |
b2a516b8 | 1119 | }else{ |
9c97d733 DV |
1120 | if(_217>=k*k){ |
1121 | _218=self.round_(_217/(k*k),1)+"M"; | |
b2a516b8 | 1122 | }else{ |
9c97d733 DV |
1123 | if(_217>=k){ |
1124 | _218=self.round_(_217/k,1)+"K"; | |
b2a516b8 DV |
1125 | } |
1126 | } | |
1127 | } | |
1128 | } | |
9c97d733 | 1129 | _216.push({label:_218,v:_217}); |
b2a516b8 | 1130 | } |
9c97d733 | 1131 | return _216; |
6a1aa64f | 1132 | }; |
285a6bda | 1133 | Dygraph.prototype.addYTicks_=function(minY,maxY){ |
9c97d733 DV |
1134 | var _222=Dygraph.numericTicks(minY,maxY,this); |
1135 | this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_222}); | |
6a1aa64f | 1136 | }; |
9c97d733 | 1137 | Dygraph.prototype.extremeValues_=function(_223){ |
e4007107 | 1138 | var minY=null,maxY=null; |
b64a4f1a | 1139 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
648acd28 | 1140 | if(bars){ |
9c97d733 DV |
1141 | for(var j=0;j<_223.length;j++){ |
1142 | var y=_223[j][1][0]; | |
648acd28 DV |
1143 | if(!y){ |
1144 | continue; | |
e4007107 | 1145 | } |
9c97d733 DV |
1146 | var low=y-_223[j][1][1]; |
1147 | var high=y+_223[j][1][2]; | |
648acd28 DV |
1148 | if(low>y){ |
1149 | low=y; | |
b2a516b8 | 1150 | } |
648acd28 DV |
1151 | if(high<y){ |
1152 | high=y; | |
b2a516b8 | 1153 | } |
648acd28 DV |
1154 | if(maxY==null||high>maxY){ |
1155 | maxY=high; | |
285a6bda | 1156 | } |
648acd28 DV |
1157 | if(minY==null||low<minY){ |
1158 | minY=low; | |
e4007107 | 1159 | } |
285a6bda | 1160 | } |
b2a516b8 | 1161 | }else{ |
9c97d733 DV |
1162 | for(var j=0;j<_223.length;j++){ |
1163 | var y=_223[j][1]; | |
648acd28 DV |
1164 | if(!y){ |
1165 | continue; | |
285a6bda | 1166 | } |
b2a516b8 | 1167 | if(maxY==null||y>maxY){ |
285a6bda DV |
1168 | maxY=y; |
1169 | } | |
e4007107 DV |
1170 | if(minY==null||y<minY){ |
1171 | minY=y; | |
1172 | } | |
b2a516b8 DV |
1173 | } |
1174 | } | |
648acd28 DV |
1175 | return [minY,maxY]; |
1176 | }; | |
1177 | Dygraph.prototype.drawGraph_=function(data){ | |
1178 | var minY=null,maxY=null; | |
1179 | this.layout_.removeAllDatasets(); | |
1180 | this.setColors_(); | |
9317362d | 1181 | this.attrs_["pointSize"]=0.5*this.attr_("highlightCircleSize"); |
648acd28 | 1182 | for(var i=1;i<data[0].length;i++){ |
9c97d733 | 1183 | var _227=[]; |
648acd28 DV |
1184 | for(var j=0;j<data.length;j++){ |
1185 | var date=data[j][0]; | |
9c97d733 | 1186 | _227[j]=[date,data[j][i]]; |
648acd28 | 1187 | } |
9c97d733 | 1188 | _227=this.rollingAverage(_227,this.rollPeriod_); |
b64a4f1a | 1189 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
648acd28 DV |
1190 | if(this.dateWindow_){ |
1191 | var low=this.dateWindow_[0]; | |
1192 | var high=this.dateWindow_[1]; | |
9c97d733 DV |
1193 | var _228=[]; |
1194 | for(var k=0;k<_227.length;k++){ | |
1195 | if(_227[k][0]>=low&&_227[k][0]<=high){ | |
1196 | _228.push(_227[k]); | |
648acd28 DV |
1197 | } |
1198 | } | |
9c97d733 | 1199 | _227=_228; |
648acd28 | 1200 | } |
9c97d733 DV |
1201 | var _229=this.extremeValues_(_227); |
1202 | var _230=_229[0]; | |
1203 | var _231=_229[1]; | |
1204 | if(!minY||_230<minY){ | |
1205 | minY=_230; | |
648acd28 | 1206 | } |
9c97d733 DV |
1207 | if(!maxY||_231>maxY){ |
1208 | maxY=_231; | |
b2a516b8 DV |
1209 | } |
1210 | if(bars){ | |
1211 | var vals=[]; | |
9c97d733 DV |
1212 | for(var j=0;j<_227.length;j++){ |
1213 | vals[j]=[_227[j][0],_227[j][1][0],_227[j][1][1],_227[j][1][2]]; | |
b2a516b8 | 1214 | } |
285a6bda | 1215 | this.layout_.addDataset(this.attr_("labels")[i],vals); |
b2a516b8 | 1216 | }else{ |
9c97d733 | 1217 | this.layout_.addDataset(this.attr_("labels")[i],_227); |
b2a516b8 DV |
1218 | } |
1219 | } | |
1220 | if(this.valueRange_!=null){ | |
1221 | this.addYTicks_(this.valueRange_[0],this.valueRange_[1]); | |
1222 | }else{ | |
e4007107 | 1223 | var span=maxY-minY; |
9c97d733 DV |
1224 | var _234=maxY+0.1*span; |
1225 | var _235=minY-0.1*span; | |
1226 | if(_235<0&&minY>=0){ | |
1227 | _235=0; | |
e4007107 | 1228 | } |
9c97d733 DV |
1229 | if(_234>0&&maxY<=0){ |
1230 | _234=0; | |
e4007107 DV |
1231 | } |
1232 | if(this.attr_("includeZero")){ | |
1233 | if(maxY<0){ | |
9c97d733 | 1234 | _234=0; |
e4007107 DV |
1235 | } |
1236 | if(minY>0){ | |
9c97d733 | 1237 | _235=0; |
e4007107 | 1238 | } |
b2a516b8 | 1239 | } |
9c97d733 | 1240 | this.addYTicks_(_235,_234); |
b2a516b8 DV |
1241 | } |
1242 | this.addXTicks_(); | |
1243 | this.layout_.evaluateWithError(); | |
1244 | this.plotter_.clear(); | |
1245 | this.plotter_.render(); | |
1246 | this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height); | |
6a1aa64f | 1247 | }; |
9c97d733 DV |
1248 | Dygraph.prototype.rollingAverage=function(_236,_237){ |
1249 | if(_236.length<2){ | |
1250 | return _236; | |
b2a516b8 | 1251 | } |
9c97d733 DV |
1252 | var _237=Math.min(_237,_236.length-1); |
1253 | var _238=[]; | |
1254 | var _239=this.attr_("sigma"); | |
b2a516b8 DV |
1255 | if(this.fractions_){ |
1256 | var num=0; | |
1257 | var den=0; | |
1258 | var mult=100; | |
9c97d733 DV |
1259 | for(var i=0;i<_236.length;i++){ |
1260 | num+=_236[i][1][0]; | |
1261 | den+=_236[i][1][1]; | |
1262 | if(i-_237>=0){ | |
1263 | num-=_236[i-_237][1][0]; | |
1264 | den-=_236[i-_237][1][1]; | |
1265 | } | |
1266 | var date=_236[i][0]; | |
1267 | var _242=den?num/den:0; | |
285a6bda | 1268 | if(this.attr_("errorBars")){ |
b2a516b8 DV |
1269 | if(this.wilsonInterval_){ |
1270 | if(den){ | |
9c97d733 DV |
1271 | var p=_242<0?0:_242,n=den; |
1272 | var pm=_239*Math.sqrt(p*(1-p)/n+_239*_239/(4*n*n)); | |
1273 | var _244=1+_239*_239/den; | |
1274 | var low=(p+_239*_239/(2*den)-pm)/_244; | |
1275 | var high=(p+_239*_239/(2*den)+pm)/_244; | |
1276 | _238[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; | |
b2a516b8 | 1277 | }else{ |
9c97d733 | 1278 | _238[i]=[date,[0,0,0]]; |
b2a516b8 DV |
1279 | } |
1280 | }else{ | |
9c97d733 DV |
1281 | var _245=den?_239*Math.sqrt(_242*(1-_242)/den):1; |
1282 | _238[i]=[date,[mult*_242,mult*_245,mult*_245]]; | |
b2a516b8 DV |
1283 | } |
1284 | }else{ | |
9c97d733 | 1285 | _238[i]=[date,mult*_242]; |
b2a516b8 DV |
1286 | } |
1287 | } | |
1288 | }else{ | |
b64a4f1a | 1289 | if(this.attr_("customBars")){ |
6372d433 DV |
1290 | var low=0; |
1291 | var mid=0; | |
1292 | var high=0; | |
9c97d733 DV |
1293 | var _247=0; |
1294 | for(var i=0;i<_236.length;i++){ | |
1295 | var data=_236[i][1]; | |
b2a516b8 | 1296 | var y=data[1]; |
9c97d733 | 1297 | _238[i]=[_236[i][0],[y,y-data[0],data[2]-y]]; |
6372d433 DV |
1298 | low+=data[0]; |
1299 | mid+=y; | |
1300 | high+=data[2]; | |
9c97d733 DV |
1301 | _247+=1; |
1302 | if(i-_237>=0){ | |
1303 | var prev=_236[i-_237]; | |
6372d433 DV |
1304 | low-=prev[1][0]; |
1305 | mid-=prev[1][1]; | |
1306 | high-=prev[1][2]; | |
9c97d733 | 1307 | _247-=1; |
6372d433 | 1308 | } |
9c97d733 | 1309 | _238[i]=[_236[i][0],[1*mid/_247,1*(mid-low)/_247,1*(high-mid)/_247]]; |
6372d433 DV |
1310 | } |
1311 | }else{ | |
9c97d733 | 1312 | var _249=Math.min(_237-1,_236.length-2); |
285a6bda | 1313 | if(!this.attr_("errorBars")){ |
9c97d733 DV |
1314 | if(_237==1){ |
1315 | return _236; | |
648acd28 | 1316 | } |
9c97d733 | 1317 | for(var i=0;i<_236.length;i++){ |
b2a516b8 | 1318 | var sum=0; |
9c97d733 DV |
1319 | var _251=0; |
1320 | for(var j=Math.max(0,i-_237+1);j<i+1;j++){ | |
1321 | var y=_236[j][1]; | |
648acd28 DV |
1322 | if(!y||isNaN(y)){ |
1323 | continue; | |
b2a516b8 | 1324 | } |
9c97d733 DV |
1325 | _251++; |
1326 | sum+=_236[j][1]; | |
648acd28 | 1327 | } |
9c97d733 DV |
1328 | if(_251){ |
1329 | _238[i]=[_236[i][0],sum/_251]; | |
648acd28 | 1330 | }else{ |
9c97d733 | 1331 | _238[i]=[_236[i][0],null]; |
b2a516b8 | 1332 | } |
648acd28 | 1333 | } |
2847c1cf | 1334 | }else{ |
9c97d733 | 1335 | for(var i=0;i<_236.length;i++){ |
b2a516b8 | 1336 | var sum=0; |
9c97d733 DV |
1337 | var _252=0; |
1338 | var _251=0; | |
1339 | for(var j=Math.max(0,i-_237+1);j<i+1;j++){ | |
1340 | var y=_236[j][1][0]; | |
648acd28 DV |
1341 | if(!y||isNaN(y)){ |
1342 | continue; | |
b2a516b8 | 1343 | } |
9c97d733 DV |
1344 | _251++; |
1345 | sum+=_236[j][1][0]; | |
1346 | _252+=Math.pow(_236[j][1][1],2); | |
b2a516b8 | 1347 | } |
9c97d733 DV |
1348 | if(_251){ |
1349 | var _245=Math.sqrt(_252)/_251; | |
1350 | _238[i]=[_236[i][0],[sum/_251,_239*_245,_239*_245]]; | |
648acd28 | 1351 | }else{ |
9c97d733 | 1352 | _238[i]=[_236[i][0],[null,null,null]]; |
b2a516b8 DV |
1353 | } |
1354 | } | |
1355 | } | |
648acd28 DV |
1356 | } |
1357 | } | |
9c97d733 | 1358 | return _238; |
6a1aa64f | 1359 | }; |
9c97d733 DV |
1360 | Dygraph.dateParser=function(_253,self){ |
1361 | var _254; | |
285a6bda | 1362 | var d; |
9c97d733 DV |
1363 | if(_253.length==10&&_253.search("-")!=-1){ |
1364 | _254=_253.replace("-","/","g"); | |
1365 | while(_254.search("-")!=-1){ | |
1366 | _254=_254.replace("-","/"); | |
353a0294 | 1367 | } |
9c97d733 | 1368 | d=Date.parse(_254); |
b2a516b8 | 1369 | }else{ |
9c97d733 DV |
1370 | if(_253.length==8){ |
1371 | _254=_253.substr(0,4)+"/"+_253.substr(4,2)+"/"+_253.substr(6,2); | |
1372 | d=Date.parse(_254); | |
8846615a | 1373 | }else{ |
9c97d733 | 1374 | d=Date.parse(_253); |
285a6bda | 1375 | } |
b2a516b8 | 1376 | } |
285a6bda | 1377 | if(!d||isNaN(d)){ |
9c97d733 | 1378 | self.error("Couldn't parse "+_253+" as a date"); |
b2a516b8 | 1379 | } |
285a6bda | 1380 | return d; |
6a1aa64f | 1381 | }; |
285a6bda | 1382 | Dygraph.prototype.detectTypeFromString_=function(str){ |
9c97d733 | 1383 | var _256=false; |
285a6bda | 1384 | if(str.indexOf("-")>=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){ |
9c97d733 | 1385 | _256=true; |
285a6bda DV |
1386 | }else{ |
1387 | if(str.length==8&&str>"19700101"&&str<"20371231"){ | |
9c97d733 | 1388 | _256=true; |
285a6bda DV |
1389 | } |
1390 | } | |
9c97d733 | 1391 | if(_256){ |
285a6bda DV |
1392 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
1393 | this.attrs_.xValueParser=Dygraph.dateParser; | |
1394 | this.attrs_.xTicker=Dygraph.dateTicker; | |
1395 | }else{ | |
1396 | this.attrs_.xValueFormatter=function(x){ | |
1397 | return x; | |
1398 | }; | |
1399 | this.attrs_.xValueParser=function(x){ | |
1400 | return parseFloat(x); | |
1401 | }; | |
1402 | this.attrs_.xTicker=Dygraph.numericTicks; | |
1403 | } | |
1404 | }; | |
1405 | Dygraph.prototype.parseCSV_=function(data){ | |
b2a516b8 | 1406 | var ret=[]; |
9c97d733 DV |
1407 | var _257=data.split("\n"); |
1408 | var _258=0; | |
b2a516b8 | 1409 | if(this.labelsFromCSV_){ |
9c97d733 DV |
1410 | _258=1; |
1411 | this.attrs_.labels=_257[0].split(","); | |
1412 | } | |
1413 | var _259; | |
1414 | var _260=false; | |
1415 | var _261=this.attr_("labels").length; | |
1416 | for(var i=_258;i<_257.length;i++){ | |
1417 | var line=_257[i]; | |
b2a516b8 DV |
1418 | if(line.length==0){ |
1419 | continue; | |
1420 | } | |
9c97d733 DV |
1421 | var _263=line.split(","); |
1422 | if(_263.length<2){ | |
b2a516b8 DV |
1423 | continue; |
1424 | } | |
9c97d733 DV |
1425 | var _264=[]; |
1426 | if(!_260){ | |
1427 | this.detectTypeFromString_(_263[0]); | |
1428 | _259=this.attr_("xValueParser"); | |
1429 | _260=true; | |
285a6bda | 1430 | } |
9c97d733 | 1431 | _264[0]=_259(_263[0],this); |
b2a516b8 | 1432 | if(this.fractions_){ |
9c97d733 DV |
1433 | for(var j=1;j<_263.length;j++){ |
1434 | var vals=_263[j].split("/"); | |
1435 | _264[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; | |
b2a516b8 DV |
1436 | } |
1437 | }else{ | |
285a6bda | 1438 | if(this.attr_("errorBars")){ |
9c97d733 DV |
1439 | for(var j=1;j<_263.length;j+=2){ |
1440 | _264[(j+1)/2]=[parseFloat(_263[j]),parseFloat(_263[j+1])]; | |
b2a516b8 DV |
1441 | } |
1442 | }else{ | |
b64a4f1a | 1443 | if(this.attr_("customBars")){ |
9c97d733 DV |
1444 | for(var j=1;j<_263.length;j++){ |
1445 | var vals=_263[j].split(";"); | |
1446 | _264[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; | |
b2a516b8 DV |
1447 | } |
1448 | }else{ | |
9c97d733 DV |
1449 | for(var j=1;j<_263.length;j++){ |
1450 | _264[j]=parseFloat(_263[j]); | |
285a6bda | 1451 | } |
b2a516b8 DV |
1452 | } |
1453 | } | |
1454 | } | |
9c97d733 DV |
1455 | ret.push(_264); |
1456 | if(_264.length!=_261){ | |
1457 | this.error("Number of columns in line "+i+" ("+_264.length+") does not agree with number of labels ("+_261+") "+line); | |
b2a516b8 | 1458 | } |
b2a516b8 DV |
1459 | } |
1460 | return ret; | |
6a1aa64f | 1461 | }; |
285a6bda DV |
1462 | Dygraph.prototype.parseArray_=function(data){ |
1463 | if(data.length==0){ | |
1464 | this.error("Can't plot empty data set"); | |
1465 | return null; | |
1466 | } | |
1467 | if(data[0].length==0){ | |
1468 | this.error("Data set cannot contain an empty row"); | |
1469 | return null; | |
1470 | } | |
1471 | if(this.attr_("labels")==null){ | |
1472 | this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter"); | |
1473 | this.attrs_.labels=["X"]; | |
1474 | for(var i=1;i<data[0].length;i++){ | |
1475 | this.attrs_.labels.push("Y"+i); | |
1476 | } | |
1477 | } | |
9c97d733 | 1478 | if(Dygraph.isDateLike(data[0][0])){ |
285a6bda DV |
1479 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
1480 | this.attrs_.xTicker=Dygraph.dateTicker; | |
9c97d733 | 1481 | var _265=Dygraph.clone(data); |
285a6bda | 1482 | for(var i=0;i<data.length;i++){ |
9c97d733 | 1483 | if(_265[i].length==0){ |
285a6bda DV |
1484 | this.error("Row "<<(1+i)<<" of data is empty"); |
1485 | return null; | |
1486 | } | |
9c97d733 | 1487 | if(_265[i][0]==null||typeof (_265[i][0].getTime)!="function"){ |
285a6bda DV |
1488 | this.error("x value in row "<<(1+i)<<" is not a Date"); |
1489 | return null; | |
1490 | } | |
9c97d733 | 1491 | _265[i][0]=_265[i][0].getTime(); |
285a6bda | 1492 | } |
9c97d733 | 1493 | return _265; |
285a6bda DV |
1494 | }else{ |
1495 | this.attrs_.xValueFormatter=function(x){ | |
1496 | return x; | |
1497 | }; | |
1498 | this.attrs_.xTicker=Dygraph.numericTicks; | |
1499 | return data; | |
1500 | } | |
1501 | }; | |
1502 | Dygraph.prototype.parseDataTable_=function(data){ | |
6219c9d6 DV |
1503 | var cols=data.getNumberOfColumns(); |
1504 | var rows=data.getNumberOfRows(); | |
9c97d733 | 1505 | var _268=[]; |
6219c9d6 | 1506 | for(var i=0;i<cols;i++){ |
9c97d733 | 1507 | _268.push(data.getColumnLabel(i)); |
6219c9d6 | 1508 | } |
9c97d733 DV |
1509 | this.attrs_.labels=_268; |
1510 | var _269=data.getColumnType(0); | |
1511 | if(_269=="date"){ | |
285a6bda DV |
1512 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
1513 | this.attrs_.xValueParser=Dygraph.dateParser; | |
1514 | this.attrs_.xTicker=Dygraph.dateTicker; | |
1515 | }else{ | |
9c97d733 | 1516 | if(_269=="number"){ |
285a6bda DV |
1517 | this.attrs_.xValueFormatter=function(x){ |
1518 | return x; | |
1519 | }; | |
1520 | this.attrs_.xValueParser=function(x){ | |
1521 | return parseFloat(x); | |
1522 | }; | |
1523 | this.attrs_.xTicker=Dygraph.numericTicks; | |
1524 | }else{ | |
9c97d733 | 1525 | this.error("only 'date' and 'number' types are supported for column 1 "+"of DataTable input (Got '"+_269+"')"); |
6219c9d6 DV |
1526 | return null; |
1527 | } | |
285a6bda | 1528 | } |
6219c9d6 DV |
1529 | var ret=[]; |
1530 | for(var i=0;i<rows;i++){ | |
1531 | var row=[]; | |
b3b20e24 DV |
1532 | if(!data.getValue(i,0)){ |
1533 | continue; | |
1534 | } | |
9c97d733 | 1535 | if(_269=="date"){ |
6219c9d6 | 1536 | row.push(data.getValue(i,0).getTime()); |
36615faf DV |
1537 | }else{ |
1538 | row.push(data.getValue(i,0)); | |
1539 | } | |
6219c9d6 DV |
1540 | for(var j=1;j<cols;j++){ |
1541 | row.push(data.getValue(i,j)); | |
1542 | } | |
1543 | ret.push(row); | |
1544 | } | |
1545 | return ret; | |
1546 | }; | |
9c97d733 DV |
1547 | Dygraph.update=function(self,o){ |
1548 | if(typeof (o)!="undefined"&&o!==null){ | |
1549 | for(var k in o){ | |
1550 | self[k]=o[k]; | |
1551 | } | |
1552 | } | |
1553 | return self; | |
1554 | }; | |
1555 | Dygraph.isArrayLike=function(o){ | |
1556 | var typ=typeof (o); | |
1557 | if((typ!="object"&&!(typ=="function"&&typeof (o.item)=="function"))||o===null||typeof (o.length)!="number"||o.nodeType===3){ | |
1558 | return false; | |
1559 | } | |
1560 | return true; | |
1561 | }; | |
1562 | Dygraph.isDateLike=function(o){ | |
1563 | if(typeof (o)!="object"||o===null||typeof (o.getTime)!="function"){ | |
1564 | return false; | |
1565 | } | |
1566 | return true; | |
1567 | }; | |
1568 | Dygraph.clone=function(o){ | |
1569 | var r=[]; | |
1570 | for(var i=0;i<o.length;i++){ | |
1571 | if(Dygraph.isArrayLike(o[i])){ | |
1572 | r.push(Dygraph.clone(o[i])); | |
1573 | }else{ | |
1574 | r.push(o[i]); | |
1575 | } | |
1576 | } | |
1577 | return r; | |
1578 | }; | |
285a6bda | 1579 | Dygraph.prototype.start_=function(){ |
b2a516b8 DV |
1580 | if(typeof this.file_=="function"){ |
1581 | this.loadedEvent_(this.file_()); | |
1582 | }else{ | |
9c97d733 | 1583 | if(Dygraph.isArrayLike(this.file_)){ |
285a6bda DV |
1584 | this.rawData_=this.parseArray_(this.file_); |
1585 | this.drawGraph_(this.rawData_); | |
1586 | }else{ | |
6219c9d6 DV |
1587 | if(typeof this.file_=="object"&&typeof this.file_.getColumnRange=="function"){ |
1588 | this.rawData_=this.parseDataTable_(this.file_); | |
1589 | this.drawGraph_(this.rawData_); | |
1590 | }else{ | |
285a6bda DV |
1591 | if(typeof this.file_=="string"){ |
1592 | if(this.file_.indexOf("\n")>=0){ | |
1593 | this.loadedEvent_(this.file_); | |
1594 | }else{ | |
b2a516b8 | 1595 | var req=new XMLHttpRequest(); |
9c97d733 | 1596 | var _275=this; |
b2a516b8 DV |
1597 | req.onreadystatechange=function(){ |
1598 | if(req.readyState==4){ | |
1599 | if(req.status==200){ | |
9c97d733 | 1600 | _275.loadedEvent_(req.responseText); |
b2a516b8 DV |
1601 | } |
1602 | } | |
6a1aa64f | 1603 | }; |
b2a516b8 DV |
1604 | req.open("GET",this.file_,true); |
1605 | req.send(null); | |
1606 | } | |
285a6bda DV |
1607 | }else{ |
1608 | this.error("Unknown data format: "+(typeof this.file_)); | |
6219c9d6 | 1609 | } |
b2a516b8 | 1610 | } |
b2a516b8 | 1611 | } |
b2a516b8 | 1612 | } |
285a6bda | 1613 | }; |
9c97d733 DV |
1614 | Dygraph.prototype.updateOptions=function(_276){ |
1615 | if(_276.rollPeriod){ | |
1616 | this.rollPeriod_=_276.rollPeriod; | |
b2a516b8 | 1617 | } |
9c97d733 DV |
1618 | if(_276.dateWindow){ |
1619 | this.dateWindow_=_276.dateWindow; | |
b2a516b8 | 1620 | } |
9c97d733 DV |
1621 | if(_276.valueRange){ |
1622 | this.valueRange_=_276.valueRange; | |
b2a516b8 | 1623 | } |
9c97d733 | 1624 | Dygraph.update(this.user_attrs_,_276); |
285a6bda DV |
1625 | this.labelsFromCSV_=(this.attr_("labels")==null); |
1626 | this.layout_.updateOptions({"errorBars":this.attr_("errorBars")}); | |
9c97d733 DV |
1627 | if(_276["file"]&&_276["file"]!=this.file_){ |
1628 | this.file_=_276["file"]; | |
b2a516b8 DV |
1629 | this.start_(); |
1630 | }else{ | |
1631 | this.drawGraph_(this.rawData_); | |
1632 | } | |
6a1aa64f | 1633 | }; |
9c97d733 DV |
1634 | Dygraph.prototype.adjustRoll=function(_277){ |
1635 | this.rollPeriod_=_277; | |
b2a516b8 | 1636 | this.drawGraph_(this.rawData_); |
6a1aa64f | 1637 | }; |
9c97d733 DV |
1638 | Dygraph.GVizChart=function(_278){ |
1639 | this.container=_278; | |
6219c9d6 | 1640 | }; |
9c97d733 | 1641 | Dygraph.GVizChart.prototype.draw=function(data,_279){ |
6219c9d6 | 1642 | this.container.innerHTML=""; |
9c97d733 | 1643 | this.date_graph=new Dygraph(this.container,data,_279); |
6219c9d6 | 1644 | }; |
285a6bda | 1645 | DateGraph=Dygraph; |
9c97d733 | 1646 | function RGBColor(_280){ |
f474c2a3 | 1647 | this.ok=false; |
9c97d733 DV |
1648 | if(_280.charAt(0)=="#"){ |
1649 | _280=_280.substr(1,6); | |
f474c2a3 | 1650 | } |
9c97d733 DV |
1651 | _280=_280.replace(/ /g,""); |
1652 | _280=_280.toLowerCase(); | |
1653 | var _281={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"}; | |
1654 | for(var key in _281){ | |
1655 | if(_280==key){ | |
1656 | _280=_281[key]; | |
f474c2a3 DV |
1657 | } |
1658 | } | |
9c97d733 | 1659 | var _283=[{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 |
1660 | return [parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])]; |
1661 | }},{re:/^(\w{2})(\w{2})(\w{2})$/,example:["#00ff00","336699"],process:function(bits){ | |
1662 | return [parseInt(bits[1],16),parseInt(bits[2],16),parseInt(bits[3],16)]; | |
1663 | }},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(bits){ | |
1664 | return [parseInt(bits[1]+bits[1],16),parseInt(bits[2]+bits[2],16),parseInt(bits[3]+bits[3],16)]; | |
1665 | }}]; | |
9c97d733 DV |
1666 | for(var i=0;i<_283.length;i++){ |
1667 | var re=_283[i].re; | |
1668 | var _286=_283[i].process; | |
1669 | var bits=re.exec(_280); | |
f474c2a3 | 1670 | if(bits){ |
9c97d733 | 1671 | channels=_286(bits); |
f474c2a3 DV |
1672 | this.r=channels[0]; |
1673 | this.g=channels[1]; | |
1674 | this.b=channels[2]; | |
1675 | this.ok=true; | |
1676 | } | |
1677 | } | |
1678 | this.r=(this.r<0||isNaN(this.r))?0:((this.r>255)?255:this.r); | |
1679 | this.g=(this.g<0||isNaN(this.g))?0:((this.g>255)?255:this.g); | |
1680 | this.b=(this.b<0||isNaN(this.b))?0:((this.b>255)?255:this.b); | |
1681 | this.toRGB=function(){ | |
1682 | return "rgb("+this.r+", "+this.g+", "+this.b+")"; | |
1683 | }; | |
1684 | this.toHex=function(){ | |
1685 | var r=this.r.toString(16); | |
1686 | var g=this.g.toString(16); | |
1687 | var b=this.b.toString(16); | |
1688 | if(r.length==1){ | |
1689 | r="0"+r; | |
1690 | } | |
1691 | if(g.length==1){ | |
1692 | g="0"+g; | |
1693 | } | |
1694 | if(b.length==1){ | |
1695 | b="0"+b; | |
1696 | } | |
1697 | return "#"+r+g+b; | |
1698 | }; | |
1699 | } | |
b2a516b8 | 1700 |