X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-combined.js;h=a2772ca9b21992dd4b1dffdfc9270f893b8e6da7;hb=2ce09b195610a182c6f81cfd3322c4da0ea3b4e0;hp=2ea5555ec5b357d0a208dc4fcc234895df1a1c6f;hpb=223ddf66a6b79373044f178c87c69065e4dba75c;p=dygraphs.git diff --git a/dygraph-combined.js b/dygraph-combined.js index 2ea5555..a2772ca 100644 --- a/dygraph-combined.js +++ b/dygraph-combined.js @@ -4602,6 +4602,7 @@ PlotKit.Canvas.__new__(); 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){ PlotKit.Layout.call(this,"line",_1); }; @@ -4648,8 +4649,6 @@ this.options.drawBackground=false; }; DateGraphCanvasRenderer.prototype=new PlotKit.CanvasRenderer(); DateGraphCanvasRenderer.prototype.render=function(){ -this._renderLineChart(); -this._renderLineAxis(); var ctx=this.element.getContext("2d"); if(this.options.drawYGrid){ var _14=this.layout.yticks; @@ -4681,6 +4680,8 @@ ctx.closePath(); ctx.stroke(); } } +this._renderLineChart(); +this._renderLineAxis(); }; DateGraphCanvasRenderer.prototype._renderLineChart=function(){ var _17=this.element.getContext("2d"); @@ -4782,6 +4783,7 @@ DateGraph.DEFAULT_WIDTH=480; DateGraph.DEFAULT_HEIGHT=320; DateGraph.DEFAULT_STROKE_WIDTH=1; DateGraph.AXIS_LINE_WIDTH=0.3; +DateGraph.DEFAULT_ATTRS={highlightCircleSize:3,pixelsPerXLabel:60,pixelsPerYLabel:30,labelsDivWidth:250,labelsDivStyles:{}}; DateGraph.prototype.__init__=function(div,_52,_53,_54){ this.maindiv_=div; this.labels_=_53; @@ -4798,14 +4800,18 @@ 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; +this.attrs_={}; +MochiKit.Base.update(this.attrs_,DateGraph.DEFAULT_ATTRS); +MochiKit.Base.update(this.attrs_,_54); +if(typeof this.attrs_.pixelsPerXLabel=="undefined"){ +this.attrs_.pixelsPerXLabel=60; +} this.labelsFromCSV_=(this.labels_==null); if(this.labels_==null){ this.labels_=[]; @@ -4823,19 +4829,17 @@ this.plotter_=new DateGraphCanvasRenderer(this.hidden_,this.layout_,this.renderO this.createStatusMessage_(); this.createRollInterface_(); this.createDragInterface_(); -connect(window,"onload",this,function(e){ this.start_(); -}); }; DateGraph.prototype.rollPeriod=function(){ return this.rollPeriod_; }; DateGraph.prototype.createInterface_=function(){ -var _56=this.maindiv_; +var _55=this.maindiv_; this.graphDiv=MochiKit.DOM.DIV({style:{"width":this.width_+"px","height":this.height_+"px"}}); -appendChildNodes(_56,this.graphDiv); -var _57=MochiKit.DOM.CANVAS; -this.canvas_=_57({style:{"position":"absolute"},width:this.width_,height:this.height_}); +appendChildNodes(_55,this.graphDiv); +var _56=MochiKit.DOM.CANVAS; +this.canvas_=_56({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){ @@ -4874,204 +4878,235 @@ this.colors_.push(MochiKit.Color.Color.fromString(_65)); }; DateGraph.prototype.createStatusMessage_=function(){ if(!this.labelsDiv_){ -var _66=250; +var _66=this.attrs_.labelsDivWidth; var _67={"style":{"position":"absolute","fontSize":"14px","zIndex":10,"width":_66+"px","top":"0px","left":this.width_-_66+"px","background":"white","textAlign":"left","overflow":"hidden"}}; +MochiKit.Base.update(_67["style"],this.attrs_.labelsDivStyles); this.labelsDiv_=MochiKit.DOM.DIV(_67); MochiKit.DOM.appendChildNodes(this.graphDiv,this.labelsDiv_); } }; DateGraph.prototype.createRollInterface_=function(){ var _68=this.plotter_.options.padding; -var _69={"type":"text","size":"2","value":this.rollPeriod_,"style":{"position":"absolute","zIndex":10,"top":(this.height_-25-_68.bottom)+"px","left":(_68.left+1)+"px"}}; -var _70=MochiKit.DOM.INPUT(_69); +if(typeof this.attrs_.showRoller=="undefined"){ +this.attrs_.showRoller=false; +} +var _69=this.attrs_.showRoller?"block":"none"; +var _70={"type":"text","size":"2","value":this.rollPeriod_,"style":{"position":"absolute","zIndex":10,"top":(this.height_-25-_68.bottom)+"px","left":(_68.left+1)+"px","display":_69}}; +var _71=MochiKit.DOM.INPUT(_70); var pa=this.graphDiv; -MochiKit.DOM.appendChildNodes(pa,_70); -connect(_70,"onchange",this,function(){ -this.adjustRoll(_70.value); +MochiKit.DOM.appendChildNodes(pa,_71); +connect(_71,"onchange",this,function(){ +this.adjustRoll(_71.value); }); -return _70; +return _71; }; DateGraph.prototype.createDragInterface_=function(){ -var _72=this; -var _73=false; -var _74=null; +var _73=this; +var _74=false; var _75=null; var _76=null; var _77=null; var _78=null; -var px=PlotKit.Base.findPosX(this.canvas_); -var py=PlotKit.Base.findPosY(this.canvas_); -var _81=function(e){ +var _79=null; +var px=0; +var py=0; +var _82=function(e){ return e.mouse().page.x-px; }; -var _82=function(e){ +var _83=function(e){ return e.mouse().page.y-py; }; -connect(this.hidden_,"onmousemove",function(_83){ -if(_73){ -_76=_81(_83); -_77=_82(_83); -_72.drawZoomRect_(_74,_76,_78); -_78=_76; +connect(this.hidden_,"onmousemove",function(_84){ +if(_74){ +_77=_82(_84); +_78=_83(_84); +_73.drawZoomRect_(_75,_77,_79); +_79=_77; } }); -connect(this.hidden_,"onmousedown",function(_84){ -_73=true; -_74=_81(_84); -_75=_82(_84); +connect(this.hidden_,"onmousedown",function(_85){ +_74=true; +px=PlotKit.Base.findPosX(_73.canvas_); +py=PlotKit.Base.findPosY(_73.canvas_); +_75=_82(_85); +_76=_83(_85); }); -connect(document,"onmouseup",this,function(_85){ -if(_73){ -_73=false; -_74=null; +connect(document,"onmouseup",this,function(_86){ +if(_74){ +_74=false; _75=null; +_76=null; } }); -connect(this.hidden_,"onmouseout",this,function(_86){ -if(_73){ -_76=null; +connect(this.hidden_,"onmouseout",this,function(_87){ +if(_74){ _77=null; +_78=null; } }); -connect(this.hidden_,"onmouseup",this,function(_87){ -if(_73){ -_73=false; -_76=_81(_87); -_77=_82(_87); -var _88=Math.abs(_76-_74); +connect(this.hidden_,"onmouseup",this,function(_88){ +if(_74){ +_74=false; +_77=_82(_88); +_78=_83(_88); var _89=Math.abs(_77-_75); -if(_88<2&&_89<2&&_72.clickCallback_!=null&&_72.lastx_!=undefined){ -_72.clickCallback_(_87,new Date(_72.lastx_)); +var _90=Math.abs(_78-_76); +if(_89<2&&_90<2&&_73.clickCallback_!=null&&_73.lastx_!=undefined){ +_73.clickCallback_(_88,new Date(_73.lastx_)); } -if(_88>=10){ -_72.doZoom_(Math.min(_74,_76),Math.max(_74,_76)); +if(_89>=10){ +_73.doZoom_(Math.min(_75,_77),Math.max(_75,_77)); }else{ -_72.canvas_.getContext("2d").clearRect(0,0,_72.canvas_.width,_72.canvas_.height); +_73.canvas_.getContext("2d").clearRect(0,0,_73.canvas_.width,_73.canvas_.height); } -_74=null; _75=null; +_76=null; } }); -connect(this.hidden_,"ondblclick",this,function(_90){ -_72.dateWindow_=null; -_72.drawGraph_(_72.rawData_); -var _91=_72.rawData_[0][0]; -var _92=_72.rawData_[_72.rawData_.length-1][0]; -_72.zoomCallback_(_91,_92); +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); +} }); }; -DateGraph.prototype.drawZoomRect_=function(_93,_94,_95){ +DateGraph.prototype.drawZoomRect_=function(_94,_95,_96){ var ctx=this.canvas_.getContext("2d"); -if(_95){ -ctx.clearRect(Math.min(_93,_95),0,Math.abs(_93-_95),this.height_); +if(_96){ +ctx.clearRect(Math.min(_94,_96),0,Math.abs(_94-_96),this.height_); } -if(_94&&_93){ +if(_95&&_94){ ctx.fillStyle="rgba(128,128,128,0.33)"; -ctx.fillRect(Math.min(_93,_94),0,Math.abs(_94-_93),this.height_); +ctx.fillRect(Math.min(_94,_95),0,Math.abs(_95-_94),this.height_); } }; -DateGraph.prototype.doZoom_=function(_96,_97){ -var _98=this.layout_.points; -var _99=null; +DateGraph.prototype.doZoom_=function(_97,_98){ +var _99=this.layout_.points; var _100=null; -for(var i=0;i<_98.length;i++){ -var cx=_98[i].canvasx; -var x=_98[i].xval; -if(cx<_96&&(_99==null||x>_99)){ -_99=x; -} -if(cx>_97&&(_100==null||x<_100)){ +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; } +if(cx>_98&&(_101==null||x<_101)){ +_101=x; } -if(_99==null){ -_99=_98[0].xval; } if(_100==null){ -_100=_98[_98.length-1].xval; +_100=_99[0].xval; } -this.dateWindow_=[_99,_100]; +if(_101==null){ +_101=_99[_99.length-1].xval; +} +this.dateWindow_=[_100,_101]; this.drawGraph_(this.rawData_); -this.zoomCallback_(_99,_100); +if(this.zoomCallback_){ +this.zoomCallback_(_100,_101); +} }; -DateGraph.prototype.mouseMove_=function(_102){ -var _103=_102.mouse().page.x-PlotKit.Base.findPosX(this.hidden_); -var _104=this.layout_.points; -var _105=-1; +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=1e+100; +var _107=-1; +var _108=1e+100; var idx=-1; -for(var i=0;i<_104.length;i++){ -var dist=Math.abs(_104[i].canvasx-_103); -if(dist>_107){ +for(var i=0;i<_105.length;i++){ +var dist=Math.abs(_105[i].canvasx-_104); +if(dist>_108){ break; } -_107=dist; +_108=dist; idx=i; } if(idx>=0){ -_105=_104[idx].xval; +_106=_105[idx].xval; } -if(_103>_104[_104.length-1].canvasx){ -_105=_104[_104.length-1].xval; +if(_104>_105[_105.length-1].canvasx){ +_106=_105[_105.length-1].xval; } -var _110=[]; -for(var i=0;i<_104.length;i++){ -if(_104[i].xval==_105){ -_110.push(_104[i]); +var _111=[]; +for(var i=0;i<_105.length;i++){ +if(_105[i].xval==_106){ +_111.push(_105[i]); } } -var _111=3; +var _112=this.attrs_.highlightCircleSize; var ctx=this.canvas_.getContext("2d"); if(this.previousVerticalX_>=0){ var px=this.previousVerticalX_; -ctx.clearRect(px-_111-1,0,2*_111+2,this.height_); +ctx.clearRect(px-_112-1,0,2*_112+2,this.height_); } -if(_110.length>0){ -var _103=_110[0].canvasx; -var _112=this.xValueFormatter_(_105)+":"; +if(_111.length>0){ +var _104=_111[0].canvasx; +var _113=this.xValueFormatter_(_106)+":"; var clen=this.colors_.length; -for(var i=0;i<_110.length;i++){ +for(var i=0;i<_111.length;i++){ if(this.labelsSeparateLines){ -_112+="
"; +_113+="
"; } -var _114=_110[i]; -_112+=" "+_114.name+":"+this.round_(_114.yval,2); +var _115=_111[i]; +_113+=" "+_115.name+":"+this.round_(_115.yval,2); } -this.labelsDiv_.innerHTML=_112; -this.lastx_=_105; +this.labelsDiv_.innerHTML=_113; +this.lastx_=_106; ctx.save(); -for(var i=0;i<_110.length;i++){ +for(var i=0;i<_111.length;i++){ ctx.beginPath(); ctx.fillStyle=this.colors_[i%clen].toRGBString(); -ctx.arc(_103,_110[i%clen].canvasy,_111,0,360,false); +ctx.arc(_104,_111[i%clen].canvasy,_112,0,360,false); ctx.fill(); } ctx.restore(); -this.previousVerticalX_=_103; +this.previousVerticalX_=_104; } }; -DateGraph.prototype.mouseOut_=function(_115){ +DateGraph.prototype.mouseOut_=function(_116){ var ctx=this.canvas_.getContext("2d"); ctx.clearRect(0,0,this.width_,this.height_); this.labelsDiv_.innerHTML=""; }; +DateGraph.zeropad=function(x){ +if(x<10){ +return "0"+x; +}else{ +return ""+x; +} +}; +DateGraph.prototype.hmsString_=function(date){ +var _118=DateGraph.zeropad; +var d=new Date(date); +if(d.getSeconds()){ +return _118(d.getHours())+":"+_118(d.getMinutes())+":"+_118(d.getSeconds()); +}else{ +if(d.getMinutes()){ +return _118(d.getHours())+":"+_118(d.getMinutes()); +}else{ +return _118(d.getHours()); +} +} +}; DateGraph.prototype.dateString_=function(date){ +var _120=DateGraph.zeropad; var d=new Date(date); var year=""+d.getFullYear(); -var _119=""+(d.getMonth()+1); -if(_119.length<2){ -_119="0"+_119; +var _122=_120(d.getMonth()+1); +var day=_120(d.getDate()); +var ret=""; +var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); +if(frac){ +ret=" "+this.hmsString_(date); } -var day=""+d.getDate(); -if(day.length<2){ -day="0"+day; -} -return year+"/"+_119+"/"+day; +return year+"/"+_122+"/"+day+ret; }; -DateGraph.prototype.round_=function(num,_121){ -var _122=Math.pow(10,_121); -return Math.round(num*_122)/_122; +DateGraph.prototype.round_=function(num,_126){ +var _127=Math.pow(10,_126); +return Math.round(num*_127)/_127; }; DateGraph.prototype.loadedEvent_=function(data){ this.rawData_=this.parseCSV_(data); @@ -5080,160 +5115,215 @@ 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 _124,endDate; +var _129,endDate; if(this.dateWindow_){ -_124=this.dateWindow_[0]; +_129=this.dateWindow_[0]; endDate=this.dateWindow_[1]; }else{ -_124=this.rawData_[0][0]; +_129=this.rawData_[0][0]; endDate=this.rawData_[this.rawData_.length-1][0]; } -var _125=this.xTicker_(_124,endDate); -this.layout_.updateOptions({xTicks:_125}); -}; -DateGraph.prototype.dateTicker=function(_126,_127){ -var _128=24*60*60*1000; -_126=_126/_128; -_127=_127/_128; -var _129=_127-_126; -var _130=[]; -var _131=false; -var _132=1; -if(_129>30*366){ -_131=true; -_130=["Jan"]; -_132=10; +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)}); }else{ -if(_129>4*366){ -_130=["Jan"]; -_131=true; +_142.push({v:t,label:this.hmsString_(t)}); +} +} }else{ -if(_129>366){ -_130=this.quarters; -_131=true; +var _146; +var _147=1; +if(_141==DateGraph.MONTHLY){ +_146=[0,1,2,3,4,5,6,7,8,9,10,11,12]; }else{ -if(_129>40){ -_130=this.months; -_131=true; +if(_141==DateGraph.QUARTERLY){ +_146=[0,3,6,9]; }else{ -if(_129>10){ -for(var week=_126-14;week<_127+14;week+=7){ -_130.push(week*_128); -} +if(_141==DateGraph.BIANNUAL){ +_146=[0,6]; }else{ -for(var day=_126-14;day<_127+14;day+=1){ -_130.push(day*_128); +if(_141==DateGraph.ANNUAL){ +_146=[0]; +}else{ +if(_141==DateGraph.DECADAL){ +_146=[0]; +_147=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){ +continue; } -var _134=[]; -if(_131){ -var _135=1900+(new Date(_126*_128)).getYear(); -var _136=1900+(new Date(_127*_128)).getYear(); -for(var i=_135;i<=_136;i++){ -if(i%_132!=0){ +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){ continue; } -for(var j=0;j<_130.length;j++){ -var date=Date.parse(_130[j]+" 1, "+i); -_134.push({label:_130[j]+"'"+(""+i).substr(2,2),v:date}); +_142.push({v:t,label:new Date(t).strftime("%b %y")}); } } -}else{ -for(var i=0;i<_130.length;i++){ -var date=new Date(_130[i]); -var year=date.getFullYear().toString(); -var _137=this.months[date.getMonth()]+date.getDate(); -_137+="'"+year.substr(year.length-2,2); -_134.push({label:_137,v:date}); } +return _142; +}; +DateGraph.prototype.dateTicker=function(_152,_153){ +var _154=-1; +for(var i=0;i=this.attrs_.pixelsPerXLabel){ +_154=i; +break; +} +} +if(_154>=0){ +return this.GetXAxis(_152,_153,_154); +}else{ } -return _134; }; DateGraph.prototype.numericTicks=function(minV,maxV){ -var _140; -if(maxV<=0){ -_140=1; -}else{ -_140=Math.pow(10,Math.floor(Math.log(maxV)/Math.log(10))); +var _158=[1,2,5]; +var _159,low_val,high_val,nTicks; +for(var i=-10;i<50;i++){ +var _160=Math.pow(10,i); +for(var j=0;j<_158.length;j++){ +_159=_160*_158[j]; +low_val=Math.floor(minV/_159)*_159; +high_val=Math.ceil(maxV/_159)*_159; +nTicks=(high_val-low_val)/_159; +var _161=this.height_/nTicks; +if(_161>this.attrs_.pixelsPerYLabel){ +break; } -var _141=(maxV-minV)/_140; -while(2*_141<20){ -_141*=2; } -if((maxV-minV)/_141this.attrs_.pixelsPerYLabel){ +break; } -var _142=[]; -for(var i=0;i<=_141;i++){ -var _143=minV+i*(maxV-minV)/_141; -var _144=this.round_(_143,2); +} +var _162=[]; +for(var i=0;i=k*k*k){ -_144=this.round_(_143/(k*k*k),1)+"B"; +if(_163>=k*k*k){ +_164=this.round_(_163/(k*k*k),1)+"B"; }else{ -if(_143>=k*k){ -_144=this.round_(_143/(k*k),1)+"M"; +if(_163>=k*k){ +_164=this.round_(_163/(k*k),1)+"M"; }else{ -if(_143>=k){ -_144=this.round_(_143/k,1)+"K"; +if(_163>=k){ +_164=this.round_(_163/k,1)+"K"; } } } } -_142.push({label:_144,v:_143}); +_162.push({label:_164,v:_163}); } -return _142; +return _162; }; DateGraph.prototype.addYTicks_=function(minY,maxY){ -var _148=this.numericTicks(minY,maxY); -this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_148}); +var _168=this.numericTicks(minY,maxY); +this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_168}); }; DateGraph.prototype.drawGraph_=function(data){ var maxY=null; this.layout_.removeAllDatasets(); for(var i=1;i=low&&_149[k][0]<=high){ -_153.push(_149[k]); -var y=bars?_149[k][1][0]:_149[k][1]; +var _173=[]; +for(var k=0;k<_169.length;k++){ +if(_169[k][0]>=low&&_169[k][0]<=high){ +_173.push(_169[k]); +var y=bars?_169[k][1][0]:_169[k][1]; if(maxY==null||y>maxY){ maxY=y; } } } -_149=_153; +_169=_173; }else{ -for(var j=0;j<_149.length;j++){ -var y=bars?_149[j][1][0]:_149[j][1]; +for(var j=0;j<_169.length;j++){ +var y=bars?_169[j][1][0]:_169[j][1]; if(maxY==null||y>maxY){ -maxY=bars?y+_149[j][1][1]:y; +maxY=bars?y+_169[j][1][1]:y; } } } if(bars){ var vals=[]; -for(var j=0;j<_149.length;j++){ -vals[j]=[_149[j][0],_149[j][1][0],_149[j][1][1],_149[j][1][2]]; +for(var j=0;j<_169.length;j++){ +vals[j]=[_169[j][0],_169[j][1][0],_169[j][1][1],_169[j][1][2]]; } this.layout_.addDataset(this.labels_[i-1],vals); }else{ -this.layout_.addDataset(this.labels_[i-1],_149); +this.layout_.addDataset(this.labels_[i-1],_169); } } if(this.valueRange_!=null){ @@ -5242,9 +5332,6 @@ this.addYTicks_(this.valueRange_[0],this.valueRange_[1]); maxY*=1.1; if(maxY<=0){ maxY=1; -}else{ -var _155=Math.pow(10,Math.floor(Math.log(maxY)/Math.log(10))); -maxY=_155*Math.ceil(maxY/_155); } this.addYTicks_(0,maxY); } @@ -5254,157 +5341,210 @@ this.plotter_.clear(); this.plotter_.render(); this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height); }; -DateGraph.prototype.rollingAverage=function(_156,_157){ -if(_156.length<2){ -return _156; +DateGraph.prototype.rollingAverage=function(_175,_176){ +if(_175.length<2){ +return _175; } -var _157=Math.min(_157,_156.length-1); -var _158=[]; -var _159=this.sigma_; +var _176=Math.min(_176,_175.length-1); +var _177=[]; +var _178=this.sigma_; if(this.fractions_){ var num=0; var den=0; var mult=100; -for(var i=0;i<_156.length;i++){ -num+=_156[i][1][0]; -den+=_156[i][1][1]; -if(i-_157>=0){ -num-=_156[i-_157][1][0]; -den-=_156[i-_157][1][1]; -} -var date=_156[i][0]; -var _162=den?num/den:0; +for(var i=0;i<_175.length;i++){ +num+=_175[i][1][0]; +den+=_175[i][1][1]; +if(i-_176>=0){ +num-=_175[i-_176][1][0]; +den-=_175[i-_176][1][1]; +} +var date=_175[i][0]; +var _181=den?num/den:0; if(this.errorBars_){ if(this.wilsonInterval_){ if(den){ -var p=_162<0?0:_162,n=den; -var pm=_159*Math.sqrt(p*(1-p)/n+_159*_159/(4*n*n)); -var _165=1+_159*_159/den; -var low=(p+_159*_159/(2*den)-pm)/_165; -var high=(p+_159*_159/(2*den)+pm)/_165; -_158[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; +var p=_181<0?0:_181,n=den; +var pm=_178*Math.sqrt(p*(1-p)/n+_178*_178/(4*n*n)); +var _184=1+_178*_178/den; +var low=(p+_178*_178/(2*den)-pm)/_184; +var high=(p+_178*_178/(2*den)+pm)/_184; +_177[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; }else{ -_158[i]=[date,[0,0,0]]; +_177[i]=[date,[0,0,0]]; } }else{ -var _166=den?_159*Math.sqrt(_162*(1-_162)/den):1; -_158[i]=[date,[mult*_162,mult*_166,mult*_166]]; +var _185=den?_178*Math.sqrt(_181*(1-_181)/den):1; +_177[i]=[date,[mult*_181,mult*_185,mult*_185]]; } }else{ -_158[i]=[date,mult*_162]; +_177[i]=[date,mult*_181]; } } }else{ if(this.customBars_){ -for(var i=0;i<_156.length;i++){ -var data=_156[i][1]; +var low=0; +var mid=0; +var high=0; +var _187=0; +for(var i=0;i<_175.length;i++){ +var data=_175[i][1]; var y=data[1]; -_158[i]=[_156[i][0],[y,y-data[0],data[2]-y]]; -} -}else{ -var _167=Math.min(_157-1,_156.length-2); +_177[i]=[_175[i][0],[y,y-data[0],data[2]-y]]; +low+=data[0]; +mid+=y; +high+=data[2]; +_187+=1; +if(i-_176>=0){ +var prev=_175[i-_176]; +low-=prev[1][0]; +mid-=prev[1][1]; +high-=prev[1][2]; +_187-=1; +} +_177[i]=[_175[i][0],[1*mid/_187,1*(mid-low)/_187,1*(high-mid)/_187]]; +} +}else{ +var _189=Math.min(_176-1,_175.length-2); if(!this.errorBars_){ -for(var i=0;i<_167;i++){ +for(var i=0;i<_189;i++){ var sum=0; for(var j=0;j