don't ignore zero values in the first column of DataTables
[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);
789if(_140.altKey){
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;
1022Dygraph.TEN_SECONDLY=1;
1023Dygraph.THIRTY_SECONDLY=2;
1024Dygraph.MINUTELY=3;
1025Dygraph.TEN_MINUTELY=4;
1026Dygraph.THIRTY_MINUTELY=5;
1027Dygraph.HOURLY=6;
1028Dygraph.SIX_HOURLY=7;
1029Dygraph.DAILY=8;
1030Dygraph.WEEKLY=9;
1031Dygraph.MONTHLY=10;
1032Dygraph.QUARTERLY=11;
1033Dygraph.BIANNUAL=12;
1034Dygraph.ANNUAL=13;
1035Dygraph.DECADAL=14;
1036Dygraph.NUM_GRANULARITIES=15;
1037Dygraph.SHORT_SPACINGS=[];
1038Dygraph.SHORT_SPACINGS[Dygraph.SECONDLY]=1000*1;
1039Dygraph.SHORT_SPACINGS[Dygraph.TEN_SECONDLY]=1000*10;
1040Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_SECONDLY]=1000*30;
1041Dygraph.SHORT_SPACINGS[Dygraph.MINUTELY]=1000*60;
1042Dygraph.SHORT_SPACINGS[Dygraph.TEN_MINUTELY]=1000*60*10;
1043Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_MINUTELY]=1000*60*30;
1044Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600;
626e8a8b 1045Dygraph.SHORT_SPACINGS[Dygraph.SIX_HOURLY]=1000*3600*6;
285a6bda
DV
1046Dygraph.SHORT_SPACINGS[Dygraph.DAILY]=1000*86400;
1047Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY]=1000*604800;
c776c216
DV
1048Dygraph.prototype.NumXTicks=function(_187,_188,_189){
1049if(_189<Dygraph.MONTHLY){
1050var _190=Dygraph.SHORT_SPACINGS[_189];
1051return Math.floor(0.5+1*(_188-_187)/_190);
285a6bda 1052}else{
c776c216
DV
1053var _191=1;
1054var _192=12;
1055if(_189==Dygraph.QUARTERLY){
1056_192=3;
285a6bda 1057}
c776c216
DV
1058if(_189==Dygraph.BIANNUAL){
1059_192=2;
285a6bda 1060}
c776c216
DV
1061if(_189==Dygraph.ANNUAL){
1062_192=1;
285a6bda 1063}
c776c216
DV
1064if(_189==Dygraph.DECADAL){
1065_192=1;
1066_191=10;
285a6bda 1067}
c776c216
DV
1068var _193=365.2524*24*3600*1000;
1069var _194=1*(_188-_187)/_193;
1070return Math.floor(0.5+1*_194*_192/_191);
285a6bda
DV
1071}
1072};
c776c216
DV
1073Dygraph.prototype.GetXAxis=function(_195,_196,_197){
1074var _198=[];
1075if(_197<Dygraph.MONTHLY){
1076var _199=Dygraph.SHORT_SPACINGS[_197];
1077var _200="%d%b";
1078if(_197<Dygraph.HOURLY){
1079_195=_199*Math.floor(0.5+_195/_199);
bd597afc 1080}
c776c216 1081for(var t=_195;t<=_196;t+=_199){
36615faf
DV
1082var d=new Date(t);
1083var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds();
c776c216
DV
1084if(frac==0||_197>=Dygraph.DAILY){
1085_198.push({v:t,label:new Date(t+3600*1000).strftime(_200)});
b2a516b8 1086}else{
c776c216 1087_198.push({v:t,label:this.hmsString_(t)});
36615faf
DV
1088}
1089}
b2a516b8 1090}else{
c776c216
DV
1091var _201;
1092var _202=1;
1093if(_197==Dygraph.MONTHLY){
1094_201=[0,1,2,3,4,5,6,7,8,9,10,11,12];
b2a516b8 1095}else{
c776c216
DV
1096if(_197==Dygraph.QUARTERLY){
1097_201=[0,3,6,9];
b2a516b8 1098}else{
c776c216
DV
1099if(_197==Dygraph.BIANNUAL){
1100_201=[0,6];
b2a516b8 1101}else{
c776c216
DV
1102if(_197==Dygraph.ANNUAL){
1103_201=[0];
6372d433 1104}else{
c776c216
DV
1105if(_197==Dygraph.DECADAL){
1106_201=[0];
1107_202=10;
b2a516b8
DV
1108}
1109}
1110}
1111}
6372d433 1112}
28e8f5ad 1113var _203=new Date(_195).getFullYear();
c776c216
DV
1114var _204=new Date(_196).getFullYear();
1115var _205=Dygraph.zeropad;
1116for(var i=_203;i<=_204;i++){
1117if(i%_202!=0){
36615faf 1118continue;
6372d433 1119}
c776c216
DV
1120for(var j=0;j<_201.length;j++){
1121var _206=i+"/"+_205(1+_201[j])+"/01";
1122var t=Date.parse(_206);
1123if(t<_195||t>_196){
b2a516b8
DV
1124continue;
1125}
c776c216 1126_198.push({v:t,label:new Date(t).strftime("%b %y")});
b2a516b8
DV
1127}
1128}
b2a516b8 1129}
c776c216 1130return _198;
36615faf 1131};
c776c216
DV
1132Dygraph.dateTicker=function(_207,_208,self){
1133var _209=-1;
285a6bda 1134for(var i=0;i<Dygraph.NUM_GRANULARITIES;i++){
c776c216
DV
1135var _210=self.NumXTicks(_207,_208,i);
1136if(self.width_/_210>=self.attr_("pixelsPerXLabel")){
1137_209=i;
36615faf
DV
1138break;
1139}
b2a516b8 1140}
c776c216
DV
1141if(_209>=0){
1142return self.GetXAxis(_207,_208,_209);
36615faf 1143}else{
6372d433 1144}
6a1aa64f 1145};
285a6bda 1146Dygraph.numericTicks=function(minV,maxV,self){
f09e46d4 1147if(self.attr_("labelsKMG2")){
c776c216 1148var _213=[1,2,4,8];
f09e46d4 1149}else{
c776c216 1150var _213=[1,2,5];
f09e46d4 1151}
c776c216
DV
1152var _214,low_val,high_val,nTicks;
1153var _215=self.attr_("pixelsPerYLabel");
2ce09b19 1154for(var i=-10;i<50;i++){
f09e46d4 1155if(self.attr_("labelsKMG2")){
c776c216 1156var _216=Math.pow(16,i);
f09e46d4 1157}else{
c776c216
DV
1158var _216=Math.pow(10,i);
1159}
1160for(var j=0;j<_213.length;j++){
1161_214=_216*_213[j];
1162low_val=Math.floor(minV/_214)*_214;
1163high_val=Math.ceil(maxV/_214)*_214;
1164nTicks=(high_val-low_val)/_214;
1165var _217=self.height_/nTicks;
1166if(_217>_215){
2ce09b19 1167break;
6a1aa64f 1168}
b2a516b8 1169}
c776c216 1170if(_217>_215){
2ce09b19 1171break;
b2a516b8 1172}
2ce09b19 1173}
c776c216 1174var _218=[];
28e8f5ad 1175var k;
c776c216 1176var _220=[];
285a6bda 1177if(self.attr_("labelsKMB")){
aa8aa4e8 1178k=1000;
c776c216 1179_220=["K","M","B","T"];
aa8aa4e8
DV
1180}
1181if(self.attr_("labelsKMG2")){
1182if(k){
1183self.warn("Setting both labelsKMB and labelsKMG2. Pick one!");
b2a516b8 1184}
aa8aa4e8 1185k=1024;
c776c216 1186_220=["k","M","G","T"];
aa8aa4e8
DV
1187}
1188for(var i=0;i<nTicks;i++){
c776c216
DV
1189var _221=low_val+i*_214;
1190var _222=Math.abs(_221);
1191var _223=self.round_(_221,2);
1192if(_220.length){
aa8aa4e8
DV
1193var n=k*k*k*k;
1194for(var j=3;j>=0;j--,n/=k){
c776c216
DV
1195if(_222>=n){
1196_223=self.round_(_221/n,1)+_220[j];
aa8aa4e8 1197break;
b2a516b8
DV
1198}
1199}
1200}
c776c216 1201_218.push({label:_223,v:_221});
b2a516b8 1202}
c776c216 1203return _218;
6a1aa64f 1204};
285a6bda 1205Dygraph.prototype.addYTicks_=function(minY,maxY){
c776c216
DV
1206var _227=Dygraph.numericTicks(minY,maxY,this);
1207this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_227});
6a1aa64f 1208};
c776c216 1209Dygraph.prototype.extremeValues_=function(_228){
e4007107 1210var minY=null,maxY=null;
b64a4f1a 1211var bars=this.attr_("errorBars")||this.attr_("customBars");
648acd28 1212if(bars){
c776c216
DV
1213for(var j=0;j<_228.length;j++){
1214var y=_228[j][1][0];
648acd28
DV
1215if(!y){
1216continue;
e4007107 1217}
c776c216
DV
1218var low=y-_228[j][1][1];
1219var high=y+_228[j][1][2];
648acd28
DV
1220if(low>y){
1221low=y;
b2a516b8 1222}
648acd28
DV
1223if(high<y){
1224high=y;
b2a516b8 1225}
648acd28
DV
1226if(maxY==null||high>maxY){
1227maxY=high;
285a6bda 1228}
648acd28
DV
1229if(minY==null||low<minY){
1230minY=low;
e4007107 1231}
285a6bda 1232}
b2a516b8 1233}else{
c776c216
DV
1234for(var j=0;j<_228.length;j++){
1235var y=_228[j][1];
28e8f5ad 1236if(y===null||isNaN(y)){
648acd28 1237continue;
285a6bda 1238}
b2a516b8 1239if(maxY==null||y>maxY){
285a6bda
DV
1240maxY=y;
1241}
e4007107
DV
1242if(minY==null||y<minY){
1243minY=y;
1244}
b2a516b8
DV
1245}
1246}
648acd28
DV
1247return [minY,maxY];
1248};
1249Dygraph.prototype.drawGraph_=function(data){
1250var minY=null,maxY=null;
1251this.layout_.removeAllDatasets();
1252this.setColors_();
9317362d 1253this.attrs_["pointSize"]=0.5*this.attr_("highlightCircleSize");
648acd28 1254for(var i=1;i<data[0].length;i++){
c776c216 1255var _232=[];
648acd28
DV
1256for(var j=0;j<data.length;j++){
1257var date=data[j][0];
c776c216 1258_232[j]=[date,data[j][i]];
648acd28 1259}
c776c216 1260_232=this.rollingAverage(_232,this.rollPeriod_);
b64a4f1a 1261var bars=this.attr_("errorBars")||this.attr_("customBars");
648acd28
DV
1262if(this.dateWindow_){
1263var low=this.dateWindow_[0];
1264var high=this.dateWindow_[1];
c776c216
DV
1265var _233=[];
1266for(var k=0;k<_232.length;k++){
1267if(_232[k][0]>=low&&_232[k][0]<=high){
1268_233.push(_232[k]);
648acd28
DV
1269}
1270}
c776c216 1271_232=_233;
648acd28 1272}
c776c216
DV
1273var _234=this.extremeValues_(_232);
1274var _235=_234[0];
1275var _236=_234[1];
1276if(!minY||_235<minY){
1277minY=_235;
648acd28 1278}
c776c216
DV
1279if(!maxY||_236>maxY){
1280maxY=_236;
b2a516b8
DV
1281}
1282if(bars){
1283var vals=[];
c776c216
DV
1284for(var j=0;j<_232.length;j++){
1285vals[j]=[_232[j][0],_232[j][1][0],_232[j][1][1],_232[j][1][2]];
b2a516b8 1286}
285a6bda 1287this.layout_.addDataset(this.attr_("labels")[i],vals);
b2a516b8 1288}else{
c776c216 1289this.layout_.addDataset(this.attr_("labels")[i],_232);
b2a516b8
DV
1290}
1291}
1292if(this.valueRange_!=null){
1293this.addYTicks_(this.valueRange_[0],this.valueRange_[1]);
1294}else{
e4007107 1295var span=maxY-minY;
c776c216
DV
1296var _239=maxY+0.1*span;
1297var _240=minY-0.1*span;
1298if(_240<0&&minY>=0){
1299_240=0;
e4007107 1300}
c776c216
DV
1301if(_239>0&&maxY<=0){
1302_239=0;
681a238e 1303}
e4007107
DV
1304if(this.attr_("includeZero")){
1305if(maxY<0){
c776c216 1306_239=0;
e4007107
DV
1307}
1308if(minY>0){
c776c216 1309_240=0;
e4007107 1310}
b2a516b8 1311}
c776c216 1312this.addYTicks_(_240,_239);
b2a516b8
DV
1313}
1314this.addXTicks_();
28e8f5ad 1315this.layout_.updateOptions({dateWindow:this.dateWindow_});
b2a516b8
DV
1316this.layout_.evaluateWithError();
1317this.plotter_.clear();
1318this.plotter_.render();
1319this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height);
6a1aa64f 1320};
c776c216
DV
1321Dygraph.prototype.rollingAverage=function(_241,_242){
1322if(_241.length<2){
1323return _241;
b2a516b8 1324}
c776c216
DV
1325var _242=Math.min(_242,_241.length-1);
1326var _243=[];
1327var _244=this.attr_("sigma");
b2a516b8
DV
1328if(this.fractions_){
1329var num=0;
1330var den=0;
1331var mult=100;
c776c216
DV
1332for(var i=0;i<_241.length;i++){
1333num+=_241[i][1][0];
1334den+=_241[i][1][1];
1335if(i-_242>=0){
1336num-=_241[i-_242][1][0];
1337den-=_241[i-_242][1][1];
1338}
1339var date=_241[i][0];
1340var _247=den?num/den:0;
285a6bda 1341if(this.attr_("errorBars")){
b2a516b8
DV
1342if(this.wilsonInterval_){
1343if(den){
c776c216
DV
1344var p=_247<0?0:_247,n=den;
1345var pm=_244*Math.sqrt(p*(1-p)/n+_244*_244/(4*n*n));
1346var _249=1+_244*_244/den;
1347var low=(p+_244*_244/(2*den)-pm)/_249;
1348var high=(p+_244*_244/(2*den)+pm)/_249;
1349_243[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]];
b2a516b8 1350}else{
c776c216 1351_243[i]=[date,[0,0,0]];
b2a516b8
DV
1352}
1353}else{
c776c216
DV
1354var _250=den?_244*Math.sqrt(_247*(1-_247)/den):1;
1355_243[i]=[date,[mult*_247,mult*_250,mult*_250]];
b2a516b8
DV
1356}
1357}else{
c776c216 1358_243[i]=[date,mult*_247];
b2a516b8
DV
1359}
1360}
1361}else{
b64a4f1a 1362if(this.attr_("customBars")){
6372d433
DV
1363var low=0;
1364var mid=0;
1365var high=0;
c776c216
DV
1366var _252=0;
1367for(var i=0;i<_241.length;i++){
1368var data=_241[i][1];
b2a516b8 1369var y=data[1];
c776c216 1370_243[i]=[_241[i][0],[y,y-data[0],data[2]-y]];
e244a0d7 1371if(y!=null&&!isNaN(y)){
6372d433
DV
1372low+=data[0];
1373mid+=y;
1374high+=data[2];
c776c216 1375_252+=1;
49a7d0d5 1376}
c776c216
DV
1377if(i-_242>=0){
1378var prev=_241[i-_242];
e244a0d7 1379if(prev[1][1]!=null&&!isNaN(prev[1][1])){
6372d433
DV
1380low-=prev[1][0];
1381mid-=prev[1][1];
1382high-=prev[1][2];
c776c216 1383_252-=1;
6372d433 1384}
49a7d0d5 1385}
c776c216 1386_243[i]=[_241[i][0],[1*mid/_252,1*(mid-low)/_252,1*(high-mid)/_252]];
6372d433
DV
1387}
1388}else{
c776c216 1389var _254=Math.min(_242-1,_241.length-2);
285a6bda 1390if(!this.attr_("errorBars")){
c776c216
DV
1391if(_242==1){
1392return _241;
648acd28 1393}
c776c216 1394for(var i=0;i<_241.length;i++){
b2a516b8 1395var sum=0;
c776c216
DV
1396var _256=0;
1397for(var j=Math.max(0,i-_242+1);j<i+1;j++){
1398var y=_241[j][1];
e244a0d7 1399if(y==null||isNaN(y)){
648acd28 1400continue;
b2a516b8 1401}
c776c216
DV
1402_256++;
1403sum+=_241[j][1];
648acd28 1404}
c776c216
DV
1405if(_256){
1406_243[i]=[_241[i][0],sum/_256];
648acd28 1407}else{
c776c216 1408_243[i]=[_241[i][0],null];
b2a516b8 1409}
648acd28 1410}
2847c1cf 1411}else{
c776c216 1412for(var i=0;i<_241.length;i++){
b2a516b8 1413var sum=0;
c776c216 1414var _257=0;
28e8f5ad 1415var _256=0;
c776c216
DV
1416for(var j=Math.max(0,i-_242+1);j<i+1;j++){
1417var y=_241[j][1][0];
e244a0d7 1418if(y==null||isNaN(y)){
648acd28 1419continue;
b2a516b8 1420}
c776c216
DV
1421_256++;
1422sum+=_241[j][1][0];
1423_257+=Math.pow(_241[j][1][1],2);
b2a516b8 1424}
c776c216
DV
1425if(_256){
1426var _250=Math.sqrt(_257)/_256;
1427_243[i]=[_241[i][0],[sum/_256,_244*_250,_244*_250]];
648acd28 1428}else{
c776c216 1429_243[i]=[_241[i][0],[null,null,null]];
b2a516b8
DV
1430}
1431}
1432}
648acd28
DV
1433}
1434}
c776c216 1435return _243;
6a1aa64f 1436};
c776c216
DV
1437Dygraph.dateParser=function(_258,self){
1438var _259;
285a6bda 1439var d;
c776c216
DV
1440if(_258.length==10&&_258.search("-")!=-1){
1441_259=_258.replace("-","/","g");
1442while(_259.search("-")!=-1){
1443_259=_259.replace("-","/");
353a0294 1444}
c776c216 1445d=Date.parse(_259);
8846615a 1446}else{
c776c216
DV
1447if(_258.length==8){
1448_259=_258.substr(0,4)+"/"+_258.substr(4,2)+"/"+_258.substr(6,2);
1449d=Date.parse(_259);
681a238e 1450}else{
c776c216 1451d=Date.parse(_258);
285a6bda 1452}
b2a516b8 1453}
285a6bda 1454if(!d||isNaN(d)){
c776c216 1455self.error("Couldn't parse "+_258+" as a date");
b2a516b8 1456}
285a6bda 1457return d;
6a1aa64f 1458};
285a6bda 1459Dygraph.prototype.detectTypeFromString_=function(str){
c776c216 1460var _261=false;
285a6bda 1461if(str.indexOf("-")>=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){
c776c216 1462_261=true;
285a6bda
DV
1463}else{
1464if(str.length==8&&str>"19700101"&&str<"20371231"){
c776c216 1465_261=true;
285a6bda
DV
1466}
1467}
c776c216 1468if(_261){
285a6bda
DV
1469this.attrs_.xValueFormatter=Dygraph.dateString_;
1470this.attrs_.xValueParser=Dygraph.dateParser;
1471this.attrs_.xTicker=Dygraph.dateTicker;
1472}else{
1473this.attrs_.xValueFormatter=function(x){
1474return x;
1475};
1476this.attrs_.xValueParser=function(x){
1477return parseFloat(x);
1478};
1479this.attrs_.xTicker=Dygraph.numericTicks;
1480}
1481};
1482Dygraph.prototype.parseCSV_=function(data){
b2a516b8 1483var ret=[];
c776c216
DV
1484var _262=data.split("\n");
1485var _263=this.attr_("delimiter");
1486if(_262[0].indexOf(_263)==-1&&_262[0].indexOf("\t")>=0){
1487_263="\t";
681a238e 1488}
c776c216 1489var _264=0;
b2a516b8 1490if(this.labelsFromCSV_){
c776c216
DV
1491_264=1;
1492this.attrs_.labels=_262[0].split(_263);
1493}
1494var _265;
1495var _266=false;
1496var _267=this.attr_("labels").length;
1497for(var i=_264;i<_262.length;i++){
1498var line=_262[i];
b2a516b8
DV
1499if(line.length==0){
1500continue;
1501}
681a238e
DV
1502if(line[0]=="#"){
1503continue;
1504}
c776c216
DV
1505var _269=line.split(_263);
1506if(_269.length<2){
b2a516b8
DV
1507continue;
1508}
c776c216
DV
1509var _270=[];
1510if(!_266){
1511this.detectTypeFromString_(_269[0]);
1512_265=this.attr_("xValueParser");
1513_266=true;
285a6bda 1514}
c776c216 1515_270[0]=_265(_269[0],this);
b2a516b8 1516if(this.fractions_){
c776c216
DV
1517for(var j=1;j<_269.length;j++){
1518var vals=_269[j].split("/");
1519_270[j]=[parseFloat(vals[0]),parseFloat(vals[1])];
b2a516b8
DV
1520}
1521}else{
285a6bda 1522if(this.attr_("errorBars")){
c776c216
DV
1523for(var j=1;j<_269.length;j+=2){
1524_270[(j+1)/2]=[parseFloat(_269[j]),parseFloat(_269[j+1])];
b2a516b8
DV
1525}
1526}else{
b64a4f1a 1527if(this.attr_("customBars")){
c776c216
DV
1528for(var j=1;j<_269.length;j++){
1529var vals=_269[j].split(";");
1530_270[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])];
b2a516b8
DV
1531}
1532}else{
c776c216
DV
1533for(var j=1;j<_269.length;j++){
1534_270[j]=parseFloat(_269[j]);
285a6bda 1535}
b2a516b8
DV
1536}
1537}
1538}
c776c216
DV
1539ret.push(_270);
1540if(_270.length!=_267){
1541this.error("Number of columns in line "+i+" ("+_270.length+") does not agree with number of labels ("+_267+") "+line);
b2a516b8 1542}
b2a516b8
DV
1543}
1544return ret;
6a1aa64f 1545};
285a6bda
DV
1546Dygraph.prototype.parseArray_=function(data){
1547if(data.length==0){
1548this.error("Can't plot empty data set");
1549return null;
1550}
1551if(data[0].length==0){
1552this.error("Data set cannot contain an empty row");
1553return null;
1554}
1555if(this.attr_("labels")==null){
1556this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter");
1557this.attrs_.labels=["X"];
1558for(var i=1;i<data[0].length;i++){
1559this.attrs_.labels.push("Y"+i);
1560}
1561}
9c97d733 1562if(Dygraph.isDateLike(data[0][0])){
285a6bda
DV
1563this.attrs_.xValueFormatter=Dygraph.dateString_;
1564this.attrs_.xTicker=Dygraph.dateTicker;
c776c216 1565var _271=Dygraph.clone(data);
285a6bda 1566for(var i=0;i<data.length;i++){
c776c216 1567if(_271[i].length==0){
285a6bda
DV
1568this.error("Row "<<(1+i)<<" of data is empty");
1569return null;
1570}
c776c216 1571if(_271[i][0]==null||typeof (_271[i][0].getTime)!="function"){
285a6bda
DV
1572this.error("x value in row "<<(1+i)<<" is not a Date");
1573return null;
1574}
c776c216 1575_271[i][0]=_271[i][0].getTime();
285a6bda 1576}
c776c216 1577return _271;
285a6bda
DV
1578}else{
1579this.attrs_.xValueFormatter=function(x){
1580return x;
1581};
1582this.attrs_.xTicker=Dygraph.numericTicks;
1583return data;
1584}
1585};
1586Dygraph.prototype.parseDataTable_=function(data){
6219c9d6
DV
1587var cols=data.getNumberOfColumns();
1588var rows=data.getNumberOfRows();
c776c216 1589var _274=[];
6219c9d6 1590for(var i=0;i<cols;i++){
c776c216 1591_274.push(data.getColumnLabel(i));
e244a0d7
DV
1592if(i!=0&&this.attr_("errorBars")){
1593i+=1;
1594}
6219c9d6 1595}
c776c216
DV
1596this.attrs_.labels=_274;
1597cols=_274.length;
1598var _275=data.getColumnType(0);
1599if(_275=="date"){
285a6bda
DV
1600this.attrs_.xValueFormatter=Dygraph.dateString_;
1601this.attrs_.xValueParser=Dygraph.dateParser;
1602this.attrs_.xTicker=Dygraph.dateTicker;
1603}else{
c776c216 1604if(_275=="number"){
285a6bda
DV
1605this.attrs_.xValueFormatter=function(x){
1606return x;
1607};
1608this.attrs_.xValueParser=function(x){
1609return parseFloat(x);
1610};
1611this.attrs_.xTicker=Dygraph.numericTicks;
1612}else{
c776c216 1613this.error("only 'date' and 'number' types are supported for column 1 "+"of DataTable input (Got '"+_275+"')");
6219c9d6
DV
1614return null;
1615}
285a6bda 1616}
6219c9d6
DV
1617var ret=[];
1618for(var i=0;i<rows;i++){
1619var row=[];
debe4434
DV
1620if(typeof (data.getValue(i,0))==="undefined"||data.getValue(i,0)===null){
1621this.warning("Ignoring row "+i+" of DataTable because of undefined or null first column.");
b3b20e24
DV
1622continue;
1623}
c776c216 1624if(_275=="date"){
6219c9d6 1625row.push(data.getValue(i,0).getTime());
36615faf
DV
1626}else{
1627row.push(data.getValue(i,0));
1628}
e244a0d7 1629if(!this.attr_("errorBars")){
6219c9d6
DV
1630for(var j=1;j<cols;j++){
1631row.push(data.getValue(i,j));
1632}
e244a0d7
DV
1633}else{
1634for(var j=0;j<cols-1;j++){
1635row.push([data.getValue(i,1+2*j),data.getValue(i,2+2*j)]);
1636}
1637}
6219c9d6
DV
1638ret.push(row);
1639}
1640return ret;
1641};
9c97d733
DV
1642Dygraph.update=function(self,o){
1643if(typeof (o)!="undefined"&&o!==null){
1644for(var k in o){
1d54a333 1645if(o.hasOwnProperty(k)){
9c97d733
DV
1646self[k]=o[k];
1647}
1648}
1d54a333 1649}
9c97d733
DV
1650return self;
1651};
1652Dygraph.isArrayLike=function(o){
1653var typ=typeof (o);
1654if((typ!="object"&&!(typ=="function"&&typeof (o.item)=="function"))||o===null||typeof (o.length)!="number"||o.nodeType===3){
1655return false;
1656}
1657return true;
1658};
1659Dygraph.isDateLike=function(o){
1660if(typeof (o)!="object"||o===null||typeof (o.getTime)!="function"){
1661return false;
1662}
1663return true;
1664};
1665Dygraph.clone=function(o){
1666var r=[];
1667for(var i=0;i<o.length;i++){
1668if(Dygraph.isArrayLike(o[i])){
1669r.push(Dygraph.clone(o[i]));
1670}else{
1671r.push(o[i]);
1672}
1673}
1674return r;
1675};
285a6bda 1676Dygraph.prototype.start_=function(){
b2a516b8
DV
1677if(typeof this.file_=="function"){
1678this.loadedEvent_(this.file_());
1679}else{
9c97d733 1680if(Dygraph.isArrayLike(this.file_)){
285a6bda
DV
1681this.rawData_=this.parseArray_(this.file_);
1682this.drawGraph_(this.rawData_);
1683}else{
6219c9d6
DV
1684if(typeof this.file_=="object"&&typeof this.file_.getColumnRange=="function"){
1685this.rawData_=this.parseDataTable_(this.file_);
1686this.drawGraph_(this.rawData_);
1687}else{
285a6bda
DV
1688if(typeof this.file_=="string"){
1689if(this.file_.indexOf("\n")>=0){
1690this.loadedEvent_(this.file_);
1691}else{
b2a516b8 1692var req=new XMLHttpRequest();
c776c216 1693var _281=this;
b2a516b8
DV
1694req.onreadystatechange=function(){
1695if(req.readyState==4){
1696if(req.status==200){
c776c216 1697_281.loadedEvent_(req.responseText);
b2a516b8
DV
1698}
1699}
6a1aa64f 1700};
b2a516b8
DV
1701req.open("GET",this.file_,true);
1702req.send(null);
1703}
285a6bda
DV
1704}else{
1705this.error("Unknown data format: "+(typeof this.file_));
6219c9d6 1706}
b2a516b8 1707}
b2a516b8 1708}
b2a516b8 1709}
285a6bda 1710};
c776c216
DV
1711Dygraph.prototype.updateOptions=function(_282){
1712if(_282.rollPeriod){
1713this.rollPeriod_=_282.rollPeriod;
b2a516b8 1714}
c776c216
DV
1715if(_282.dateWindow){
1716this.dateWindow_=_282.dateWindow;
b2a516b8 1717}
c776c216
DV
1718if(_282.valueRange){
1719this.valueRange_=_282.valueRange;
b2a516b8 1720}
c776c216 1721Dygraph.update(this.user_attrs_,_282);
285a6bda
DV
1722this.labelsFromCSV_=(this.attr_("labels")==null);
1723this.layout_.updateOptions({"errorBars":this.attr_("errorBars")});
c776c216
DV
1724if(_282["file"]&&_282["file"]!=this.file_){
1725this.file_=_282["file"];
b2a516b8
DV
1726this.start_();
1727}else{
1728this.drawGraph_(this.rawData_);
1729}
6a1aa64f 1730};
c776c216
DV
1731Dygraph.prototype.resize=function(_283,_284){
1732if((_283===null)!=(_284===null)){
626e8a8b 1733this.warn("Dygraph.resize() should be called with zero parameters or "+"two non-NULL parameters. Pretending it was zero.");
c776c216 1734_283=_284=null;
626e8a8b
DV
1735}
1736this.maindiv_.innerHTML="";
1737this.attrs_.labelsDiv=null;
c776c216
DV
1738if(_283){
1739this.maindiv_.style.width=_283+"px";
1740this.maindiv_.style.height=_284+"px";
1741this.width_=_283;
1742this.height_=_284;
626e8a8b
DV
1743}else{
1744this.width_=this.maindiv_.offsetWidth;
1745this.height_=this.maindiv_.offsetHeight;
1746}
1747this.createInterface_();
1748this.drawGraph_(this.rawData_);
1749};
c776c216
DV
1750Dygraph.prototype.adjustRoll=function(_285){
1751this.rollPeriod_=_285;
b2a516b8 1752this.drawGraph_(this.rawData_);
6a1aa64f 1753};
681a238e 1754Dygraph.createCanvas=function(){
c776c216 1755var _286=document.createElement("canvas");
681a238e
DV
1756isIE=(/MSIE/.test(navigator.userAgent)&&!window.opera);
1757if(isIE){
c776c216 1758_286=G_vmlCanvasManager.initElement(_286);
681a238e 1759}
c776c216 1760return _286;
681a238e 1761};
c776c216
DV
1762Dygraph.GVizChart=function(_287){
1763this.container=_287;
6219c9d6 1764};
c776c216 1765Dygraph.GVizChart.prototype.draw=function(data,_288){
6219c9d6 1766this.container.innerHTML="";
c776c216 1767this.date_graph=new Dygraph(this.container,data,_288);
6219c9d6 1768};
285a6bda 1769DateGraph=Dygraph;
c776c216 1770function RGBColor(_289){
f474c2a3 1771this.ok=false;
c776c216
DV
1772if(_289.charAt(0)=="#"){
1773_289=_289.substr(1,6);
f474c2a3 1774}
c776c216
DV
1775_289=_289.replace(/ /g,"");
1776_289=_289.toLowerCase();
1777var _290={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dodgerblue:"1e90ff",feldspar:"d19275",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslateblue:"8470ff",lightslategray:"778899",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"00ff00",limegreen:"32cd32",linen:"faf0e6",magenta:"ff00ff",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"ff0000",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",violetred:"d02090",wheat:"f5deb3",white:"ffffff",whitesmoke:"f5f5f5",yellow:"ffff00",yellowgreen:"9acd32"};
1778for(var key in _290){
1779if(_289==key){
1780_289=_290[key];
f474c2a3
DV
1781}
1782}
c776c216 1783var _292=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:["rgb(123, 234, 45)","rgb(255,234,245)"],process:function(bits){
f474c2a3
DV
1784return [parseInt(bits[1]),parseInt(bits[2]),parseInt(bits[3])];
1785}},{re:/^(\w{2})(\w{2})(\w{2})$/,example:["#00ff00","336699"],process:function(bits){
1786return [parseInt(bits[1],16),parseInt(bits[2],16),parseInt(bits[3],16)];
1787}},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(bits){
1788return [parseInt(bits[1]+bits[1],16),parseInt(bits[2]+bits[2],16),parseInt(bits[3]+bits[3],16)];
1789}}];
c776c216
DV
1790for(var i=0;i<_292.length;i++){
1791var re=_292[i].re;
1792var _295=_292[i].process;
1793var bits=re.exec(_289);
f474c2a3 1794if(bits){
c776c216 1795channels=_295(bits);
f474c2a3
DV
1796this.r=channels[0];
1797this.g=channels[1];
1798this.b=channels[2];
1799this.ok=true;
1800}
1801}
1802this.r=(this.r<0||isNaN(this.r))?0:((this.r>255)?255:this.r);
1803this.g=(this.g<0||isNaN(this.g))?0:((this.g>255)?255:this.g);
1804this.b=(this.b<0||isNaN(this.b))?0:((this.b>255)?255:this.b);
1805this.toRGB=function(){
1806return "rgb("+this.r+", "+this.g+", "+this.b+")";
1807};
1808this.toHex=function(){
1809var r=this.r.toString(16);
1810var g=this.g.toString(16);
1811var b=this.b.toString(16);
1812if(r.length==1){
1813r="0"+r;
1814}
1815if(g.length==1){
1816g="0"+g;
1817}
1818if(b.length==1){
1819b="0"+b;
1820}
1821return "#"+r+g+b;
1822};
1823}
b2a516b8 1824