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