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