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