X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-combined.js;h=0768e2474098488e95843991b24d824cb245e5b1;hb=1723e3d602478556b48e220d20eeba780c923d7c;hp=8fd362c3a09b7968bf9f1cc993f2cb0c45bcd0e6;hpb=36615faf46e6d8ace2cc90a176be32f189387838;p=dygraphs.git diff --git a/dygraph-combined.js b/dygraph-combined.js index 8fd362c..0768e24 100644 --- a/dygraph-combined.js +++ b/dygraph-combined.js @@ -1593,7 +1593,7 @@ throw MochiKit.Iter.StopIteration; return rval; }}; }}); -MochiKit.Iter.EXPORT_OK=["iteratorRegistry","arrayLikeIter","hasIterateNext","iterateNextIter",]; +MochiKit.Iter.EXPORT_OK=["iteratorRegistry","arrayLikeIter","hasIterateNext","iterateNextIter"]; MochiKit.Iter.EXPORT=["StopIteration","registerIteratorFactory","iter","count","cycle","repeat","next","izip","ifilter","ifilterfalse","islice","imap","applymap","chain","takewhile","dropwhile","tee","list","reduce","range","sum","exhaust","forEach","every","sorted","reversed","some","iextend","groupby","groupby_as_array"]; MochiKit.Iter.__new__=function(){ var m=MochiKit.Base; @@ -4304,7 +4304,7 @@ this.__init__(_69,_70,_71); PlotKit.CanvasRenderer.prototype.__init__=function(_72,_73,_74){ var _75=MochiKit.Base.isUndefinedOrNull; var _76=MochiKit.Color.Color; -this.options={"drawBackground":true,"backgroundColor":_76.whiteColor(),"padding":{left:30,right:30,top:5,bottom:10},"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),"strokeColor":_76.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":_76.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":_76.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"pieRadius":0.4,"enableEvents":true}; +this.options={"drawBackground":true,"backgroundColor":_76.whiteColor(),"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),"strokeColor":_76.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":_76.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":_76.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"pieRadius":0.4,"enableEvents":true}; MochiKit.Base.update(this.options,_74?_74:{}); this.layout=_73; this.element=MochiKit.DOM.getElement(_72); @@ -4331,7 +4331,9 @@ throw "CanvasRenderer() - needs to be enclosed in
"; this.xlabels=new Array(); this.ylabels=new Array(); this.isFirstRender=true; -this.area={x:this.options.padding.left,y:this.options.padding.top,w:this.width-this.options.padding.left-this.options.padding.right,h:this.height-this.options.padding.top-this.options.padding.bottom}; +this.area={x:this.options.yAxisLabelWidth+2*this.options.axisTickSize,y:0}; +this.area.w=this.width-this.area.x-this.options.rightGap; +this.area.h=this.height-this.options.axisLabelFontSize-2*this.options.axisTickSize; MochiKit.DOM.updateNodeAttributes(this.container,{"style":{"position":"relative","width":this.width+"px"}}); }; PlotKit.CanvasRenderer.prototype.render=function(){ @@ -4432,14 +4434,28 @@ _93.lineTo(x-this.options.axisTickSize,y); _93.closePath(); _93.stroke(); var _98=DIV(_94,_96[1]); -_98.style.top=(y-this.options.axisLabelFontSize)+"px"; -_98.style.left=(x-this.options.padding.left-this.options.axisTickSize)+"px"; +var top=(y-this.options.axisLabelFontSize/2); +if(top<0){ +top=0; +} +if(top+this.options.axisLabelFontSize+3>this.height){ +_98.style.bottom="0px"; +}else{ +_98.style.top=top+"px"; +} +_98.style.left="0px"; _98.style.textAlign="right"; -_98.style.width=(this.options.padding.left-this.options.axisTickSize*2)+"px"; +_98.style.width=this.options.yAxisLabelWidth+"px"; MochiKit.DOM.appendChildNodes(this.container,_98); this.ylabels.push(_98); }; MochiKit.Iter.forEach(this.layout.yticks,bind(_95,this)); +var _100=this.ylabels[0]; +var _101=this.options.axisLabelFontSize; +var _102=parseInt(_100.style.top)+_101; +if(_102>this.height-_101){ +_100.style.top=(parseInt(_100.style.top)-_101/2)+"px"; +} } _93.beginPath(); _93.moveTo(this.area.x,this.area.y); @@ -4449,24 +4465,33 @@ _93.stroke(); } if(this.options.drawXAxis){ if(this.layout.xticks){ -var _95=function(_99){ +var _95=function(tick){ if(typeof (dataset)=="function"){ return; } -var x=this.area.x+_99[0]*this.area.w; +var x=this.area.x+tick[0]*this.area.w; var y=this.area.y+this.area.h; _93.beginPath(); _93.moveTo(x,y); _93.lineTo(x,y+this.options.axisTickSize); _93.closePath(); _93.stroke(); -var _100=DIV(_94,_99[1]); -_100.style.top=(y+this.options.axisTickSize)+"px"; -_100.style.left=(x-this.options.axisLabelWidth/2)+"px"; -_100.style.textAlign="center"; -_100.style.width=this.options.axisLabelWidth+"px"; -MochiKit.DOM.appendChildNodes(this.container,_100); -this.xlabels.push(_100); +var _104=DIV(_94,tick[1]); +_104.style.textAlign="center"; +_104.style.bottom="0px"; +var left=(x-this.options.axisLabelWidth/2); +if(left+this.options.axisLabelWidth>this.width){ +left=this.width-this.options.xAxisLabelWidth; +_104.style.textAlign="right"; +} +if(left<0){ +left=0; +_104.style.textAlign="left"; +} +_104.style.left=left+"px"; +_104.style.width=this.options.xAxisLabelWidth+"px"; +MochiKit.DOM.appendChildNodes(this.container,_104); +this.xlabels.push(_104); }; MochiKit.Iter.forEach(this.layout.xticks,bind(_95,this)); } @@ -4479,11 +4504,11 @@ _93.stroke(); _93.restore(); }; PlotKit.CanvasRenderer.prototype._renderBackground=function(){ -var _101=this.element.getContext("2d"); -_101.save(); -_101.fillStyle=this.options.backgroundColor.toRGBString(); -_101.fillRect(0,0,this.width,this.height); -_101.restore(); +var _106=this.element.getContext("2d"); +_106.save(); +_106.fillStyle=this.options.backgroundColor.toRGBString(); +_106.fillRect(0,0,this.width,this.height); +_106.restore(); }; PlotKit.CanvasRenderer.prototype.clear=function(){ if(this.isIE){ @@ -4492,7 +4517,7 @@ if(this.clearDelay){ this.clearDelay.cancel(); this.clearDelay=null; } -var _102=this.element.getContext("2d"); +var _107=this.element.getContext("2d"); } catch(e){ this.isFirstRender=false; @@ -4501,88 +4526,88 @@ this.clearDelay.addCallback(bind(this.clear,this)); return; } } -var _102=this.element.getContext("2d"); -_102.clearRect(0,0,this.width,this.height); +var _107=this.element.getContext("2d"); +_107.clearRect(0,0,this.width,this.height); MochiKit.Iter.forEach(this.xlabels,MochiKit.DOM.removeElement); MochiKit.Iter.forEach(this.ylabels,MochiKit.DOM.removeElement); this.xlabels=new Array(); this.ylabels=new Array(); }; PlotKit.CanvasRenderer.prototype._initialiseEvents=function(){ -var _103=MochiKit.Signal.connect; +var _108=MochiKit.Signal.connect; var bind=MochiKit.Base.bind; -_103(this.element,"onclick",bind(this.onclick,this)); +_108(this.element,"onclick",bind(this.onclick,this)); }; PlotKit.CanvasRenderer.prototype._resolveObject=function(e){ var x=(e.mouse().page.x-PlotKit.Base.findPosX(this.element)-this.area.x)/this.area.w; var y=(e.mouse().page.y-PlotKit.Base.findPosY(this.element)-this.area.y)/this.area.h; -var _106=this.layout.hitTest(x,y); -if(_106){ -return _106; +var _111=this.layout.hitTest(x,y); +if(_111){ +return _111; } return null; }; -PlotKit.CanvasRenderer.prototype._createEventObject=function(_107,e){ -if(_107==null){ +PlotKit.CanvasRenderer.prototype._createEventObject=function(_112,e){ +if(_112==null){ return null; } -e.chart=_107; +e.chart=_112; return e; }; PlotKit.CanvasRenderer.prototype.onclick=function(e){ -var _108=this._resolveObject(e); -var _109=this._createEventObject(_108,e); -if(_109!=null){ -MochiKit.Signal.signal(this,"onclick",_109); +var _113=this._resolveObject(e); +var _114=this._createEventObject(_113,e); +if(_114!=null){ +MochiKit.Signal.signal(this,"onclick",_114); } }; PlotKit.CanvasRenderer.prototype.onmouseover=function(e){ -var _110=this._resolveObject(e); -var _111=this._createEventObject(_110,e); -if(_111!=null){ -signal(this,"onmouseover",_111); +var _115=this._resolveObject(e); +var _116=this._createEventObject(_115,e); +if(_116!=null){ +signal(this,"onmouseover",_116); } }; PlotKit.CanvasRenderer.prototype.onmouseout=function(e){ -var _112=this._resolveObject(e); -var _113=this._createEventObject(_112,e); -if(_113==null){ +var _117=this._resolveObject(e); +var _118=this._createEventObject(_117,e); +if(_118==null){ signal(this,"onmouseout",e); }else{ -signal(this,"onmouseout",_113); +signal(this,"onmouseout",_118); } }; PlotKit.CanvasRenderer.prototype.onmousemove=function(e){ -var _114=this._resolveObject(e); -var _115=this._createEventObject(_114,e); -if((_114==null)&&(this.event_isinside==null)){ +var _119=this._resolveObject(e); +var _120=this._createEventObject(_119,e); +if((_119==null)&&(this.event_isinside==null)){ return; } -if((_114!=null)&&(this.event_isinside==null)){ -signal(this,"onmouseover",_115); +if((_119!=null)&&(this.event_isinside==null)){ +signal(this,"onmouseover",_120); } -if((_114==null)&&(this.event_isinside!=null)){ -signal(this,"onmouseout",_115); +if((_119==null)&&(this.event_isinside!=null)){ +signal(this,"onmouseout",_120); } -if((_114!=null)&&(this.event_isinside!=null)){ -signal(this,"onmousemove",_115); +if((_119!=null)&&(this.event_isinside!=null)){ +signal(this,"onmousemove",_120); } -this.event_isinside=_114; +this.event_isinside=_119; }; -PlotKit.CanvasRenderer.isSupported=function(_116){ -var _117=null; +PlotKit.CanvasRenderer.isSupported=function(_121){ +var _122=null; try{ -if(MochiKit.Base.isUndefinedOrNull(_116)){ -_117=MochiKit.DOM.CANVAS({}); +if(MochiKit.Base.isUndefinedOrNull(_121)){ +_122=MochiKit.DOM.CANVAS({}); }else{ -_117=MochiKit.DOM.getElement(_116); +_122=MochiKit.DOM.getElement(_121); } -var _118=_117.getContext("2d"); +var _123=_122.getContext("2d"); } catch(e){ var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); -var _120=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); -if((!ie)||(ie[1]<6)||(_120)){ +var _125=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); +if((!ie)||(ie[1]<6)||(_125)){ return false; } return true; @@ -4603,11 +4628,11 @@ MochiKit.Base._exportSymbols(this,PlotKit.Canvas); Date.ext={};Date.ext.util={};Date.ext.util.xPad=function(x,pad,r){if(typeof (r)=="undefined"){r=10}for(;parseInt(x,10)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}; -DateGraphLayout=function(_1){ +DygraphLayout=function(_1){ PlotKit.Layout.call(this,"line",_1); }; -DateGraphLayout.prototype=new PlotKit.Layout(); -DateGraphLayout.prototype.evaluateWithError=function(){ +DygraphLayout.prototype=new PlotKit.Layout(); +DygraphLayout.prototype.evaluateWithError=function(){ this.evaluate(); if(!this.options.errorBars){ return; @@ -4630,14 +4655,14 @@ this.points[i].errorPlus=parseFloat(_6[3]); } } }; -DateGraphLayout.prototype.removeAllDatasets=function(){ +DygraphLayout.prototype.removeAllDatasets=function(){ delete this.datasets; this.datasets=new Array(); }; -DateGraphLayout.prototype.updateOptions=function(_9){ +DygraphLayout.prototype.updateOptions=function(_9){ MochiKit.Base.update(this.options,_9?_9:{}); }; -DateGraphCanvasRenderer=function(_10,_11,_12){ +DygraphCanvasRenderer=function(_10,_11,_12){ PlotKit.CanvasRenderer.call(this,_10,_11,_12); this.options.shouldFill=false; this.options.shouldStroke=true; @@ -4647,10 +4672,8 @@ this.options.gridLineColor=MochiKit.Color.Color.grayColor(); MochiKit.Base.update(this.options,_12); this.options.drawBackground=false; }; -DateGraphCanvasRenderer.prototype=new PlotKit.CanvasRenderer(); -DateGraphCanvasRenderer.prototype.render=function(){ -this._renderLineChart(); -this._renderLineAxis(); +DygraphCanvasRenderer.prototype=new PlotKit.CanvasRenderer(); +DygraphCanvasRenderer.prototype.render=function(){ var ctx=this.element.getContext("2d"); if(this.options.drawYGrid){ var _14=this.layout.yticks; @@ -4682,8 +4705,10 @@ ctx.closePath(); ctx.stroke(); } } +this._renderLineChart(); +this._renderLineAxis(); }; -DateGraphCanvasRenderer.prototype._renderLineChart=function(){ +DygraphCanvasRenderer.prototype._renderLineChart=function(){ var _17=this.element.getContext("2d"); var _18=this.options.colorScheme.length; var _19=this.options.colorScheme; @@ -4710,12 +4735,16 @@ var _31=this.layout.points[0]; var _32=true; var _33=function(_34,_31){ if(_31.name==_28){ +if(!_31.canvasy||isNaN(_31.canvasy)){ +_32=true; +}else{ if(_32){ _34.moveTo(_31.canvasx,_31.canvasy); +_32=false; }else{ _34.lineTo(_31.canvasx,_31.canvasy); } -_32=false; +} } }; MochiKit.Iter.forEach(this.layout.points,_24(_33,ctx),this); @@ -4737,6 +4766,10 @@ var _42=this.layout.yscale; var _43=function(_44,_45){ _41++; if(_45.name==_36){ +if(!_45.y||isNaN(_45.y)){ +_39=-1; +return; +} var _46=[_45.y-_45.errorPlus*_42,_45.y+_45.errorMinus*_42]; _46[0]=this.area.h*_46[0]+this.area.y; _46[1]=this.area.h*_46[1]+this.area.y; @@ -4765,79 +4798,131 @@ _23(_35,this)(_17); _23(_27,this)(_17); _17.restore(); }; -DateGraph=function(div,_49,_50,_51){ +Dygraph=function(div,_49,_50){ if(arguments.length>0){ -this.__init__(div,_49,_50,_51); +if(arguments.length==4){ +this.warn("Using deprecated four-argument dygraph constructor"); +this.__old_init__(div,_49,arguments[2],arguments[3]); +}else{ +this.__init__(div,_49,_50); +} } }; -DateGraph.NAME="DateGraph"; -DateGraph.VERSION="1.1"; -DateGraph.__repr__=function(){ +Dygraph.NAME="Dygraph"; +Dygraph.VERSION="1.2"; +Dygraph.__repr__=function(){ return "["+this.NAME+" "+this.VERSION+"]"; }; -DateGraph.toString=function(){ +Dygraph.toString=function(){ return this.__repr__(); }; -DateGraph.DEFAULT_ROLL_PERIOD=1; -DateGraph.DEFAULT_WIDTH=480; -DateGraph.DEFAULT_HEIGHT=320; -DateGraph.DEFAULT_STROKE_WIDTH=1; -DateGraph.AXIS_LINE_WIDTH=0.3; -DateGraph.prototype.__init__=function(div,_52,_53,_54){ +Dygraph.DEFAULT_ROLL_PERIOD=1; +Dygraph.DEFAULT_WIDTH=480; +Dygraph.DEFAULT_HEIGHT=320; +Dygraph.AXIS_LINE_WIDTH=0.3; +Dygraph.DEFAULT_ATTRS={highlightCircleSize:3,pixelsPerXLabel:60,pixelsPerYLabel:30,labelsDivWidth:250,labelsDivStyles:{},labelsSeparateLines:false,labelsKMB:false,strokeWidth:1,axisTickSize:3,axisLabelFontSize:14,xAxisLabelWidth:50,yAxisLabelWidth:50,rightGap:5,showRoller:false,xValueFormatter:Dygraph.dateString_,xValueParser:Dygraph.dateParser,xTicker:Dygraph.dateTicker,sigma:2,errorBars:false,fractions:false,wilsonInterval:true,customBars:false}; +Dygraph.DEBUG=1; +Dygraph.INFO=2; +Dygraph.WARNING=3; +Dygraph.ERROR=3; +Dygraph.prototype.__old_init__=function(div,_51,_52,_53){ +if(_52!=null){ +var _54=["Date"]; +for(var i=0;i<_52.length;i++){ +_54.push(_52[i]); +} +MochiKit.Base.update(_53,{"labels":_54}); +} +this.__init__(div,_51,_53); +}; +Dygraph.prototype.__init__=function(div,_55,_56){ +if(_56==null){ +_56={}; +} this.maindiv_=div; -this.labels_=_53; -this.file_=_52; -this.rollPeriod_=_54.rollPeriod||DateGraph.DEFAULT_ROLL_PERIOD; +this.file_=_55; +this.rollPeriod_=_56.rollPeriod||Dygraph.DEFAULT_ROLL_PERIOD; this.previousVerticalX_=-1; +this.fractions_=_56.fractions||false; +this.dateWindow_=_56.dateWindow||null; +this.valueRange_=_56.valueRange||null; +this.wilsonInterval_=_56.wilsonInterval||true; +this.customBars_=_56.customBars||false; +div.innerHTML=""; +if(div.style.width==""){ +div.style.width=Dygraph.DEFAULT_WIDTH+"px"; +} +if(div.style.height==""){ +div.style.height=Dygraph.DEFAULT_HEIGHT+"px"; +} this.width_=parseInt(div.style.width,10); this.height_=parseInt(div.style.height,10); -this.errorBars_=_54.errorBars||false; -this.fractions_=_54.fractions||false; -this.strokeWidth_=_54.strokeWidth||DateGraph.DEFAULT_STROKE_WIDTH; -this.dateWindow_=_54.dateWindow||null; -this.valueRange_=_54.valueRange||null; -this.labelsSeparateLines=_54.labelsSeparateLines||false; -this.labelsDiv_=_54.labelsDiv||null; -this.labelsKMB_=_54.labelsKMB||false; -this.minTickSize_=_54.minTickSize||0; -this.xValueParser_=_54.xValueParser||DateGraph.prototype.dateParser; -this.xValueFormatter_=_54.xValueFormatter||DateGraph.prototype.dateString_; -this.xTicker_=_54.xTicker||DateGraph.prototype.dateTicker; -this.sigma_=_54.sigma||2; -this.wilsonInterval_=_54.wilsonInterval||true; -this.customBars_=_54.customBars||false; -this.attrs_=_54; -if(typeof this.attrs_.pixelsPerXLabel=="undefined"){ -this.attrs_.pixelsPerXLabel=60; -} -this.labelsFromCSV_=(this.labels_==null); -if(this.labels_==null){ -this.labels_=[]; -} -this.clickCallback_=_54.clickCallback||null; -this.zoomCallback_=_54.zoomCallback||null; +this.user_attrs_={}; +MochiKit.Base.update(this.user_attrs_,_56); +this.attrs_={}; +MochiKit.Base.update(this.attrs_,Dygraph.DEFAULT_ATTRS); +this.labelsFromCSV_=(this.attr_("labels")==null); this.createInterface_(); -this.layoutOptions_={"errorBars":(this.errorBars_||this.customBars_),"xOriginIsZero":false}; -MochiKit.Base.update(this.layoutOptions_,_54); -this.setColors_(_54); -this.layout_=new DateGraphLayout(this.layoutOptions_); -this.renderOptions_={colorScheme:this.colors_,strokeColor:null,strokeWidth:this.strokeWidth_,axisLabelFontSize:14,axisLineWidth:DateGraph.AXIS_LINE_WIDTH}; -MochiKit.Base.update(this.renderOptions_,_54); -this.plotter_=new DateGraphCanvasRenderer(this.hidden_,this.layout_,this.renderOptions_); +this.layoutOptions_={"errorBars":(this.attr_("errorBars")||this.customBars_),"xOriginIsZero":false}; +MochiKit.Base.update(this.layoutOptions_,this.attrs_); +MochiKit.Base.update(this.layoutOptions_,this.user_attrs_); +this.layout_=new DygraphLayout(this.layoutOptions_); +this.renderOptions_={colorScheme:this.colors_,strokeColor:null,axisLineWidth:Dygraph.AXIS_LINE_WIDTH}; +MochiKit.Base.update(this.renderOptions_,this.attrs_); +MochiKit.Base.update(this.renderOptions_,this.user_attrs_); +this.plotter_=new DygraphCanvasRenderer(this.hidden_,this.layout_,this.renderOptions_); this.createStatusMessage_(); this.createRollInterface_(); this.createDragInterface_(); this.start_(); }; -DateGraph.prototype.rollPeriod=function(){ +Dygraph.prototype.attr_=function(_57){ +if(typeof (this.user_attrs_[_57])!="undefined"){ +return this.user_attrs_[_57]; +}else{ +if(typeof (this.attrs_[_57])!="undefined"){ +return this.attrs_[_57]; +}else{ +return null; +} +} +}; +Dygraph.prototype.log=function(_58,_59){ +if(typeof (console)!="undefined"){ +switch(_58){ +case Dygraph.DEBUG: +console.debug("dygraphs: "+_59); +break; +case Dygraph.INFO: +console.info("dygraphs: "+_59); +break; +case Dygraph.WARNING: +console.warn("dygraphs: "+_59); +break; +case Dygraph.ERROR: +console.error("dygraphs: "+_59); +break; +} +} +}; +Dygraph.prototype.info=function(_60){ +this.log(Dygraph.INFO,_60); +}; +Dygraph.prototype.warn=function(_61){ +this.log(Dygraph.WARNING,_61); +}; +Dygraph.prototype.error=function(_62){ +this.log(Dygraph.ERROR,_62); +}; +Dygraph.prototype.rollPeriod=function(){ return this.rollPeriod_; }; -DateGraph.prototype.createInterface_=function(){ -var _55=this.maindiv_; +Dygraph.prototype.createInterface_=function(){ +var _63=this.maindiv_; this.graphDiv=MochiKit.DOM.DIV({style:{"width":this.width_+"px","height":this.height_+"px"}}); -appendChildNodes(_55,this.graphDiv); -var _56=MochiKit.DOM.CANVAS; -this.canvas_=_56({style:{"position":"absolute"},width:this.width_,height:this.height_}); +appendChildNodes(_63,this.graphDiv); +var _64=MochiKit.DOM.CANVAS; +this.canvas_=_64({style:{"position":"absolute"},width:this.width_,height:this.height_}); appendChildNodes(this.graphDiv,this.canvas_); this.hidden_=this.createPlotKitCanvas_(this.canvas_); connect(this.hidden_,"onmousemove",this,function(e){ @@ -4847,488 +4932,568 @@ connect(this.hidden_,"onmouseout",this,function(e){ this.mouseOut_(e); }); }; -DateGraph.prototype.createPlotKitCanvas_=function(_58){ +Dygraph.prototype.createPlotKitCanvas_=function(_66){ var h=document.createElement("canvas"); h.style.position="absolute"; -h.style.top=_58.style.top; -h.style.left=_58.style.left; +h.style.top=_66.style.top; +h.style.left=_66.style.left; h.width=this.width_; h.height=this.height_; MochiKit.DOM.appendChildNodes(this.graphDiv,h); return h; }; -DateGraph.prototype.setColors_=function(_60){ -var num=this.labels_.length; +Dygraph.prototype.setColors_=function(){ +var num=this.attr_("labels").length-1; this.colors_=[]; -if(!_60.colors){ -var sat=_60.colorSaturation||1; -var val=_60.colorValue||0.5; +var _69=this.attr_("colors"); +if(!_69){ +var sat=this.attr_("colorSaturation")||1; +var val=this.attr_("colorValue")||0.5; for(var i=1;i<=num;i++){ var hue=(1*i/(1+num)); this.colors_.push(MochiKit.Color.Color.fromHSV(hue,sat,val)); } }else{ for(var i=0;i=10){ -_73.doZoom_(Math.min(_75,_77),Math.max(_75,_77)); +if(_96>=10){ +_80.doZoom_(Math.min(_82,_84),Math.max(_82,_84)); }else{ -_73.canvas_.getContext("2d").clearRect(0,0,_73.canvas_.width,_73.canvas_.height); +_80.canvas_.getContext("2d").clearRect(0,0,_80.canvas_.width,_80.canvas_.height); } -_75=null; -_76=null; +_82=null; +_83=null; } }); -connect(this.hidden_,"ondblclick",this,function(_91){ -_73.dateWindow_=null; -_73.drawGraph_(_73.rawData_); -var _92=_73.rawData_[0][0]; -var _93=_73.rawData_[_73.rawData_.length-1][0]; -if(_73.zoomCallback_){ -_73.zoomCallback_(_92,_93); +connect(this.hidden_,"ondblclick",this,function(_98){ +_80.dateWindow_=null; +_80.drawGraph_(_80.rawData_); +var _99=_80.rawData_[0][0]; +var _100=_80.rawData_[_80.rawData_.length-1][0]; +if(_80.attr_("zoomCallback")){ +_80.attr_("zoomCallback")(_99,_100); } }); }; -DateGraph.prototype.drawZoomRect_=function(_94,_95,_96){ +Dygraph.prototype.drawZoomRect_=function(_101,endX,_103){ var ctx=this.canvas_.getContext("2d"); -if(_96){ -ctx.clearRect(Math.min(_94,_96),0,Math.abs(_94-_96),this.height_); +if(_103){ +ctx.clearRect(Math.min(_101,_103),0,Math.abs(_101-_103),this.height_); } -if(_95&&_94){ +if(endX&&_101){ ctx.fillStyle="rgba(128,128,128,0.33)"; -ctx.fillRect(Math.min(_94,_95),0,Math.abs(_95-_94),this.height_); +ctx.fillRect(Math.min(_101,endX),0,Math.abs(endX-_101),this.height_); } }; -DateGraph.prototype.doZoom_=function(_97,_98){ -var _99=this.layout_.points; -var _100=null; -var _101=null; -for(var i=0;i<_99.length;i++){ -var cx=_99[i].canvasx; -var x=_99[i].xval; -if(cx<_97&&(_100==null||x>_100)){ -_100=x; +Dygraph.prototype.doZoom_=function(lowX,_105){ +var _106=this.layout_.points; +var _107=null; +var _108=null; +for(var i=0;i<_106.length;i++){ +var cx=_106[i].canvasx; +var x=_106[i].xval; +if(cx_107)){ +_107=x; } -if(cx>_98&&(_101==null||x<_101)){ -_101=x; +if(cx>_105&&(_108==null||x<_108)){ +_108=x; } } -if(_100==null){ -_100=_99[0].xval; +if(_107==null){ +_107=_106[0].xval; } -if(_101==null){ -_101=_99[_99.length-1].xval; +if(_108==null){ +_108=_106[_106.length-1].xval; } -this.dateWindow_=[_100,_101]; +this.dateWindow_=[_107,_108]; this.drawGraph_(this.rawData_); -if(this.zoomCallback_){ -this.zoomCallback_(_100,_101); +if(this.attr_("zoomCallback")){ +this.attr_("zoomCallback")(_107,_108); } }; -DateGraph.prototype.mouseMove_=function(_103){ -var _104=_103.mouse().page.x-PlotKit.Base.findPosX(this.hidden_); -var _105=this.layout_.points; -var _106=-1; -var _107=-1; -var _108=1e+100; +Dygraph.prototype.mouseMove_=function(_110){ +var _111=_110.mouse().page.x-PlotKit.Base.findPosX(this.hidden_); +var _112=this.layout_.points; +var _113=-1; +var _114=-1; +var _115=1e+100; var idx=-1; -for(var i=0;i<_105.length;i++){ -var dist=Math.abs(_105[i].canvasx-_104); -if(dist>_108){ +for(var i=0;i<_112.length;i++){ +var dist=Math.abs(_112[i].canvasx-_111); +if(dist>_115){ break; } -_108=dist; +_115=dist; idx=i; } if(idx>=0){ -_106=_105[idx].xval; +_113=_112[idx].xval; } -if(_104>_105[_105.length-1].canvasx){ -_106=_105[_105.length-1].xval; +if(_111>_112[_112.length-1].canvasx){ +_113=_112[_112.length-1].xval; } -var _111=[]; -for(var i=0;i<_105.length;i++){ -if(_105[i].xval==_106){ -_111.push(_105[i]); +var _118=[]; +for(var i=0;i<_112.length;i++){ +if(_112[i].xval==_113){ +_118.push(_112[i]); } } -var _112=3; +var _119=this.attr_("highlightCircleSize"); var ctx=this.canvas_.getContext("2d"); if(this.previousVerticalX_>=0){ var px=this.previousVerticalX_; -ctx.clearRect(px-_112-1,0,2*_112+2,this.height_); +ctx.clearRect(px-_119-1,0,2*_119+2,this.height_); } -if(_111.length>0){ -var _104=_111[0].canvasx; -var _113=this.xValueFormatter_(_106)+":"; +var isOK=function(x){ +return x&&!isNaN(x); +}; +if(_118.length>0){ +var _111=_118[0].canvasx; +var _121=this.attr_("xValueFormatter")(_113,this)+":"; var clen=this.colors_.length; -for(var i=0;i<_111.length;i++){ -if(this.labelsSeparateLines){ -_113+="
"; +for(var i=0;i<_118.length;i++){ +if(!isOK(_118[i].canvasy)){ +continue; } -var _115=_111[i]; -_113+=" "+_115.name+":"+this.round_(_115.yval,2); +if(this.attr_("labelsSeparateLines")){ +_121+="
"; } -this.labelsDiv_.innerHTML=_113; -this.lastx_=_106; +var _123=_118[i]; +_121+=" "+_123.name+":"+this.round_(_123.yval,2); +} +this.attr_("labelsDiv").innerHTML=_121; +this.lastx_=_113; ctx.save(); -for(var i=0;i<_111.length;i++){ +for(var i=0;i<_118.length;i++){ +if(!isOK(_118[i%clen].canvasy)){ +continue; +} ctx.beginPath(); ctx.fillStyle=this.colors_[i%clen].toRGBString(); -ctx.arc(_104,_111[i%clen].canvasy,_112,0,360,false); +ctx.arc(_111,_118[i%clen].canvasy,_119,0,360,false); ctx.fill(); } ctx.restore(); -this.previousVerticalX_=_104; +this.previousVerticalX_=_111; } }; -DateGraph.prototype.mouseOut_=function(_116){ +Dygraph.prototype.mouseOut_=function(_124){ var ctx=this.canvas_.getContext("2d"); ctx.clearRect(0,0,this.width_,this.height_); -this.labelsDiv_.innerHTML=""; +this.attr_("labelsDiv").innerHTML=""; }; -DateGraph.zeropad=function(x){ +Dygraph.zeropad=function(x){ if(x<10){ return "0"+x; }else{ return ""+x; } }; -DateGraph.prototype.hmsString_=function(date){ -var _118=DateGraph.zeropad; +Dygraph.prototype.hmsString_=function(date){ +var _126=Dygraph.zeropad; var d=new Date(date); if(d.getSeconds()){ -return _118(d.getHours())+":"+_118(d.getMinutes())+":"+_118(d.getSeconds()); +return _126(d.getHours())+":"+_126(d.getMinutes())+":"+_126(d.getSeconds()); }else{ if(d.getMinutes()){ -return _118(d.getHours())+":"+_118(d.getMinutes()); +return _126(d.getHours())+":"+_126(d.getMinutes()); }else{ -return _118(d.getHours()); +return _126(d.getHours()); } } }; -DateGraph.prototype.dateString_=function(date){ -var _120=DateGraph.zeropad; +Dygraph.dateString_=function(date,self){ +var _129=Dygraph.zeropad; var d=new Date(date); var year=""+d.getFullYear(); -var _122=_120(d.getMonth()+1); -var day=_120(d.getDate()); +var _131=_129(d.getMonth()+1); +var day=_129(d.getDate()); var ret=""; var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); if(frac){ -ret=" "+this.hmsString_(date); +ret=" "+self.hmsString_(date); } -return year+"/"+_122+"/"+day+ret; +return year+"/"+_131+"/"+day+ret; }; -DateGraph.prototype.round_=function(num,_126){ -var _127=Math.pow(10,_126); -return Math.round(num*_127)/_127; +Dygraph.prototype.round_=function(num,_135){ +var _136=Math.pow(10,_135); +return Math.round(num*_136)/_136; }; -DateGraph.prototype.loadedEvent_=function(data){ +Dygraph.prototype.loadedEvent_=function(data){ this.rawData_=this.parseCSV_(data); this.drawGraph_(this.rawData_); }; -DateGraph.prototype.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; -DateGraph.prototype.quarters=["Jan","Apr","Jul","Oct"]; -DateGraph.prototype.addXTicks_=function(){ -var _129,endDate; +Dygraph.prototype.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; +Dygraph.prototype.quarters=["Jan","Apr","Jul","Oct"]; +Dygraph.prototype.addXTicks_=function(){ +var _138,endDate; if(this.dateWindow_){ -_129=this.dateWindow_[0]; +_138=this.dateWindow_[0]; endDate=this.dateWindow_[1]; }else{ -_129=this.rawData_[0][0]; +_138=this.rawData_[0][0]; endDate=this.rawData_[this.rawData_.length-1][0]; } -var _130=this.xTicker_(_129,endDate); -this.layout_.updateOptions({xTicks:_130}); -}; -DateGraph.SECONDLY=0; -DateGraph.MINUTELY=1; -DateGraph.HOURLY=2; -DateGraph.DAILY=3; -DateGraph.WEEKLY=4; -DateGraph.MONTHLY=5; -DateGraph.QUARTERLY=6; -DateGraph.BIANNUAL=7; -DateGraph.ANNUAL=8; -DateGraph.DECADAL=9; -DateGraph.NUM_GRANULARITIES=10; -DateGraph.SHORT_SPACINGS=[]; -DateGraph.SHORT_SPACINGS[DateGraph.SECONDLY]=1000*1; -DateGraph.SHORT_SPACINGS[DateGraph.MINUTELY]=1000*60; -DateGraph.SHORT_SPACINGS[DateGraph.HOURLY]=1000*3600; -DateGraph.SHORT_SPACINGS[DateGraph.DAILY]=1000*86400; -DateGraph.SHORT_SPACINGS[DateGraph.WEEKLY]=1000*604800; -DateGraph.prototype.NumXTicks=function(_131,_132,_133){ -if(_133=DateGraph.DAILY){ -_142.push({v:t,label:new Date(t+3600*1000).strftime(_144)}); +if(frac==0||_150>=Dygraph.DAILY){ +_151.push({v:t,label:new Date(t+3600*1000).strftime(_153)}); }else{ -_142.push({v:t,label:this.hmsString_(t)}); +_151.push({v:t,label:this.hmsString_(t)}); } } }else{ -var _146; -var _147=1; -if(_141==DateGraph.MONTHLY){ -_146=[0,1,2,3,4,5,6,7,8,9,10,11,12]; +var _155; +var _156=1; +if(_150==Dygraph.MONTHLY){ +_155=[0,1,2,3,4,5,6,7,8,9,10,11,12]; }else{ -if(_141==DateGraph.QUARTERLY){ -_146=[0,3,6,9]; +if(_150==Dygraph.QUARTERLY){ +_155=[0,3,6,9]; }else{ -if(_141==DateGraph.BIANNUAL){ -_146=[0,6]; +if(_150==Dygraph.BIANNUAL){ +_155=[0,6]; }else{ -if(_141==DateGraph.ANNUAL){ -_146=[0]; +if(_150==Dygraph.ANNUAL){ +_155=[0]; }else{ -if(_141==DateGraph.DECADAL){ -_146=[0]; -_147=10; +if(_150==Dygraph.DECADAL){ +_155=[0]; +_156=10; } } } } } -var _148=new Date(_139).getFullYear(); -var _149=new Date(_140).getFullYear(); -var _150=DateGraph.zeropad; -for(var i=_148;i<=_149;i++){ -if(i%_147!=0){ +var _157=new Date(_148).getFullYear(); +var _158=new Date(_149).getFullYear(); +var _159=Dygraph.zeropad; +for(var i=_157;i<=_158;i++){ +if(i%_156!=0){ continue; } -for(var j=0;j<_146.length;j++){ -var _151=i+"/"+_150(1+_146[j])+"/01"; -var t=Date.parse(_151); -if(t<_139||t>_140){ +for(var j=0;j<_155.length;j++){ +var _160=i+"/"+_159(1+_155[j])+"/01"; +var t=Date.parse(_160); +if(t<_148||t>_149){ continue; } -_142.push({v:t,label:new Date(t).strftime("%b %y")}); +_151.push({v:t,label:new Date(t).strftime("%b %y")}); } } } -return _142; +return _151; }; -DateGraph.prototype.dateTicker=function(_152,_153){ -var _154=-1; -for(var i=0;i=this.attrs_.pixelsPerXLabel){ -_154=i; +Dygraph.dateTicker=function(_161,_162,self){ +var _163=-1; +for(var i=0;i=self.attr_("pixelsPerXLabel")){ +_163=i; break; } } -if(_154>=0){ -return this.GetXAxis(_152,_153,_154); +if(_163>=0){ +return self.GetXAxis(_161,_162,_163); }else{ } }; -DateGraph.prototype.numericTicks=function(minV,maxV){ -var _158; -if(maxV<=0){ -_158=1; -}else{ -_158=Math.pow(10,Math.floor(Math.log(maxV)/Math.log(10))); +Dygraph.numericTicks=function(minV,maxV,self){ +var _167=[1,2,5]; +var _168,low_val,high_val,nTicks; +var _169=self.attr_("pixelsPerYLabel"); +for(var i=-10;i<50;i++){ +var _170=Math.pow(10,i); +for(var j=0;j<_167.length;j++){ +_168=_170*_167[j]; +low_val=Math.floor(minV/_168)*_168; +high_val=Math.ceil(maxV/_168)*_168; +nTicks=(high_val-low_val)/_168; +var _171=self.height_/nTicks; +if(_171>_169){ +break; } -var _159=(maxV-minV)/_158; -while(2*_159<20){ -_159*=2; } -if((maxV-minV)/_159_169){ +break; +} } -var _160=[]; -for(var i=0;i<=_159;i++){ -var _161=minV+i*(maxV-minV)/_159; -var _162=this.round_(_161,2); -if(this.labelsKMB_){ +var _172=[]; +for(var i=0;i=k*k*k){ -_162=this.round_(_161/(k*k*k),1)+"B"; +if(_173>=k*k*k){ +_174=self.round_(_173/(k*k*k),1)+"B"; }else{ -if(_161>=k*k){ -_162=this.round_(_161/(k*k),1)+"M"; +if(_173>=k*k){ +_174=self.round_(_173/(k*k),1)+"M"; }else{ -if(_161>=k){ -_162=this.round_(_161/k,1)+"K"; +if(_173>=k){ +_174=self.round_(_173/k,1)+"K"; } } } } -_160.push({label:_162,v:_161}); +_172.push({label:_174,v:_173}); } -return _160; +return _172; }; -DateGraph.prototype.addYTicks_=function(minY,maxY){ -var _166=this.numericTicks(minY,maxY); -this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_166}); +Dygraph.prototype.addYTicks_=function(minY,maxY){ +var _178=Dygraph.numericTicks(minY,maxY,this); +this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_178}); +}; +Dygraph.prototype.extremeValues_=function(_179){ +var minY=null,maxY=null; +var bars=this.attr_("errorBars")||this.customBars_; +if(bars){ +for(var j=0;j<_179.length;j++){ +var y=_179[j][1][0]; +if(!y){ +continue; +} +var low=y-_179[j][1][1]; +var high=y+_179[j][1][2]; +if(low>y){ +low=y; +} +if(highmaxY){ +maxY=high; +} +if(minY==null||lowmaxY){ +maxY=y; +} +if(minY==null||y=low&&_167[k][0]<=high){ -_171.push(_167[k]); -var y=bars?_167[k][1][0]:_167[k][1]; -if(maxY==null||y>maxY){ -maxY=y; +var _184=[]; +for(var k=0;k<_183.length;k++){ +if(_183[k][0]>=low&&_183[k][0]<=high){ +_184.push(_183[k]); } } +_183=_184; } -_167=_171; -}else{ -for(var j=0;j<_167.length;j++){ -var y=bars?_167[j][1][0]:_167[j][1]; -if(maxY==null||y>maxY){ -maxY=bars?y+_167[j][1][1]:y; -} +var _185=this.extremeValues_(_183); +var _186=_185[0]; +var _187=_185[1]; +if(!minY||_186maxY){ +maxY=_187; } if(bars){ var vals=[]; -for(var j=0;j<_167.length;j++){ -vals[j]=[_167[j][0],_167[j][1][0],_167[j][1][1],_167[j][1][2]]; +for(var j=0;j<_183.length;j++){ +vals[j]=[_183[j][0],_183[j][1][0],_183[j][1][1],_183[j][1][2]]; } -this.layout_.addDataset(this.labels_[i-1],vals); +this.layout_.addDataset(this.attr_("labels")[i],vals); }else{ -this.layout_.addDataset(this.labels_[i-1],_167); +this.layout_.addDataset(this.attr_("labels")[i],_183); } } if(this.valueRange_!=null){ this.addYTicks_(this.valueRange_[0],this.valueRange_[1]); }else{ -maxY*=1.1; -if(maxY<=0){ -maxY=1; -}else{ -var _173=Math.pow(10,Math.floor(Math.log(maxY)/Math.log(10))); -maxY=_173*Math.ceil(maxY/_173); +var span=maxY-minY; +var _190=maxY+0.1*span; +var _191=minY-0.1*span; +if(_191<0&&minY>=0){ +_191=0; +} +if(_190>0&&maxY<=0){ +_190=0; +} +if(this.attr_("includeZero")){ +if(maxY<0){ +_190=0; +} +if(minY>0){ +_191=0; } -this.addYTicks_(0,maxY); +} +this.addYTicks_(_191,_190); } this.addXTicks_(); this.layout_.evaluateWithError(); @@ -5336,44 +5501,44 @@ this.plotter_.clear(); this.plotter_.render(); this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height); }; -DateGraph.prototype.rollingAverage=function(_174,_175){ -if(_174.length<2){ -return _174; +Dygraph.prototype.rollingAverage=function(_192,_193){ +if(_192.length<2){ +return _192; } -var _175=Math.min(_175,_174.length-1); -var _176=[]; -var _177=this.sigma_; +var _193=Math.min(_193,_192.length-1); +var _194=[]; +var _195=this.attr_("sigma"); if(this.fractions_){ var num=0; var den=0; var mult=100; -for(var i=0;i<_174.length;i++){ -num+=_174[i][1][0]; -den+=_174[i][1][1]; -if(i-_175>=0){ -num-=_174[i-_175][1][0]; -den-=_174[i-_175][1][1]; -} -var date=_174[i][0]; -var _180=den?num/den:0; -if(this.errorBars_){ +for(var i=0;i<_192.length;i++){ +num+=_192[i][1][0]; +den+=_192[i][1][1]; +if(i-_193>=0){ +num-=_192[i-_193][1][0]; +den-=_192[i-_193][1][1]; +} +var date=_192[i][0]; +var _198=den?num/den:0; +if(this.attr_("errorBars")){ if(this.wilsonInterval_){ if(den){ -var p=_180<0?0:_180,n=den; -var pm=_177*Math.sqrt(p*(1-p)/n+_177*_177/(4*n*n)); -var _183=1+_177*_177/den; -var low=(p+_177*_177/(2*den)-pm)/_183; -var high=(p+_177*_177/(2*den)+pm)/_183; -_176[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; +var p=_198<0?0:_198,n=den; +var pm=_195*Math.sqrt(p*(1-p)/n+_195*_195/(4*n*n)); +var _201=1+_195*_195/den; +var low=(p+_195*_195/(2*den)-pm)/_201; +var high=(p+_195*_195/(2*den)+pm)/_201; +_194[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; }else{ -_176[i]=[date,[0,0,0]]; +_194[i]=[date,[0,0,0]]; } }else{ -var _184=den?_177*Math.sqrt(_180*(1-_180)/den):1; -_176[i]=[date,[mult*_180,mult*_184,mult*_184]]; +var _202=den?_195*Math.sqrt(_198*(1-_198)/den):1; +_194[i]=[date,[mult*_198,mult*_202,mult*_202]]; } }else{ -_176[i]=[date,mult*_180]; +_194[i]=[date,mult*_198]; } } }else{ @@ -5381,157 +5546,266 @@ if(this.customBars_){ var low=0; var mid=0; var high=0; -var _186=0; -for(var i=0;i<_174.length;i++){ -var data=_174[i][1]; +var _204=0; +for(var i=0;i<_192.length;i++){ +var data=_192[i][1]; var y=data[1]; -_176[i]=[_174[i][0],[y,y-data[0],data[2]-y]]; +_194[i]=[_192[i][0],[y,y-data[0],data[2]-y]]; low+=data[0]; mid+=y; high+=data[2]; -_186+=1; -if(i-_175>=0){ -var prev=_174[i-_175]; +_204+=1; +if(i-_193>=0){ +var prev=_192[i-_193]; low-=prev[1][0]; mid-=prev[1][1]; high-=prev[1][2]; -_186-=1; +_204-=1; } -_176[i]=[_174[i][0],[1*mid/_186,1*(mid-low)/_186,1*(high-mid)/_186]]; +_194[i]=[_192[i][0],[1*mid/_204,1*(mid-low)/_204,1*(high-mid)/_204]]; } }else{ -var _188=Math.min(_175-1,_174.length-2); -if(!this.errorBars_){ -for(var i=0;i<_188;i++){ +var _206=Math.min(_193-1,_192.length-2); +if(!this.attr_("errorBars")){ +if(_193==1){ +return _192; +} +for(var i=0;i<_206;i++){ var sum=0; for(var j=0;j=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){ +_213=true; +}else{ +if(str.length==8&&str>"19700101"&&str<"20371231"){ +_213=true; +} +} +if(_213){ +this.attrs_.xValueFormatter=Dygraph.dateString_; +this.attrs_.xValueParser=Dygraph.dateParser; +this.attrs_.xTicker=Dygraph.dateTicker; +}else{ +this.attrs_.xValueFormatter=function(x){ +return x; +}; +this.attrs_.xValueParser=function(x){ +return parseFloat(x); +}; +this.attrs_.xTicker=Dygraph.numericTicks; } }; -DateGraph.prototype.parseCSV_=function(data){ +Dygraph.prototype.parseCSV_=function(data){ var ret=[]; -var _193=data.split("\n"); -var _194=this.labelsFromCSV_?1:0; +var _214=data.split("\n"); +var _215=0; if(this.labelsFromCSV_){ -var _195=_193[0].split(","); -_195.shift(); -this.labels_=_195; -this.setColors_(this.attrs_); -this.renderOptions_.colorScheme=this.colors_; -MochiKit.Base.update(this.plotter_.options,this.renderOptions_); -MochiKit.Base.update(this.layoutOptions_,this.attrs_); -} -for(var i=_194;i<_193.length;i++){ -var line=_193[i]; +_215=1; +this.attrs_.labels=_214[0].split(","); +} +var _216; +var _217=false; +var _218=this.attr_("labels").length; +for(var i=_215;i<_214.length;i++){ +var line=_214[i]; if(line.length==0){ continue; } -var _197=line.split(","); -if(_197.length<2){ +var _220=line.split(","); +if(_220.length<2){ continue; } -var _198=[]; -_198[0]=this.xValueParser_(_197[0]); +var _221=[]; +if(!_217){ +this.detectTypeFromString_(_220[0]); +_216=this.attr_("xValueParser"); +_217=true; +} +_221[0]=_216(_220[0],this); if(this.fractions_){ -for(var j=1;j<_197.length;j++){ -var vals=_197[j].split("/"); -_198[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; +for(var j=1;j<_220.length;j++){ +var vals=_220[j].split("/"); +_221[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; } }else{ -if(this.errorBars_){ -for(var j=1;j<_197.length;j+=2){ -_198[(j+1)/2]=[parseFloat(_197[j]),parseFloat(_197[j+1])]; +if(this.attr_("errorBars")){ +for(var j=1;j<_220.length;j+=2){ +_221[(j+1)/2]=[parseFloat(_220[j]),parseFloat(_220[j+1])]; } }else{ if(this.customBars_){ -for(var j=1;j<_197.length;j++){ -var vals=_197[j].split(";"); -_198[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; +for(var j=1;j<_220.length;j++){ +var vals=_220[j].split(";"); +_221[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; } }else{ -for(var j=1;j<_197.length;j++){ -_198[j]=parseFloat(_197[j]); +for(var j=1;j<_220.length;j++){ +_221[j]=parseFloat(_220[j]); +} } } } +ret.push(_221); +if(_221.length!=_218){ +this.error("Number of columns in line "+i+" ("+_221.length+") does not agree with number of labels ("+_218+") "+line); } -ret.push(_198); } return ret; }; -DateGraph.prototype.parseDataTable_=function(data){ +Dygraph.prototype.parseArray_=function(data){ +if(data.length==0){ +this.error("Can't plot empty data set"); +return null; +} +if(data[0].length==0){ +this.error("Data set cannot contain an empty row"); +return null; +} +if(this.attr_("labels")==null){ +this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter"); +this.attrs_.labels=["X"]; +for(var i=1;i=0){ +this.loadedEvent_(this.file_); +}else{ var req=new XMLHttpRequest(); -var _205=this; +var _229=this; req.onreadystatechange=function(){ if(req.readyState==4){ if(req.status==200){ -_205.loadedEvent_(req.responseText); +_229.loadedEvent_(req.responseText); } } }; req.open("GET",this.file_,true); req.send(null); } +}else{ +this.error("Unknown data format: "+(typeof this.file_)); } -}; -DateGraph.prototype.updateOptions=function(_206){ -if(_206.errorBars){ -this.errorBars_=_206.errorBars; -} -if(_206.customBars){ -this.customBars_=_206.customBars; } -if(_206.strokeWidth){ -this.strokeWidth_=_206.strokeWidth; } -if(_206.rollPeriod){ -this.rollPeriod_=_206.rollPeriod; } -if(_206.dateWindow){ -this.dateWindow_=_206.dateWindow; +}; +Dygraph.prototype.updateOptions=function(_230){ +if(_230.customBars){ +this.customBars_=_230.customBars; } -if(_206.valueRange){ -this.valueRange_=_206.valueRange; +if(_230.rollPeriod){ +this.rollPeriod_=_230.rollPeriod; } -if(_206.minTickSize){ -this.minTickSize_=_206.minTickSize; +if(_230.dateWindow){ +this.dateWindow_=_230.dateWindow; } -if(typeof (_206.labels)!="undefined"){ -this.labels_=_206.labels; -this.labelsFromCSV_=(_206.labels==null); +if(_230.valueRange){ +this.valueRange_=_230.valueRange; } -this.layout_.updateOptions({"errorBars":this.errorBars_}); -if(_206["file"]&&_206["file"]!=this.file_){ -this.file_=_206["file"]; +MochiKit.Base.update(this.user_attrs_,_230); +this.labelsFromCSV_=(this.attr_("labels")==null); +this.layout_.updateOptions({"errorBars":this.attr_("errorBars")}); +if(_230["file"]&&_230["file"]!=this.file_){ +this.file_=_230["file"]; this.start_(); }else{ this.drawGraph_(this.rawData_); } }; -DateGraph.prototype.adjustRoll=function(_207){ -this.rollPeriod_=_207; +Dygraph.prototype.adjustRoll=function(_231){ +this.rollPeriod_=_231; this.drawGraph_(this.rawData_); }; -DateGraph.GVizChart=function(_208){ -this.container=_208; +Dygraph.GVizChart=function(_232){ +this.container=_232; }; -DateGraph.GVizChart.prototype.draw=function(data,_209){ +Dygraph.GVizChart.prototype.draw=function(data,_233){ this.container.innerHTML=""; -this.date_graph=new DateGraph(this.container,data,null,_209||{}); +this.date_graph=new Dygraph(this.container,data,_233); }; +DateGraph=Dygraph;