X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-combined.js;h=15d2e5ec3ce655511c4af671b76d69cd10802b2e;hb=b16e636940e6566cc8176c7eb4ed90fba7d118c9;hp=f0123aeb98a58cb967f3a15b7e5bf2f7fb0a96c2;hpb=79f17b42e332b8029a7d574f11a26844530e3120;p=dygraphs.git diff --git a/dygraph-combined.js b/dygraph-combined.js index f0123ae..15d2e5e 100644 --- a/dygraph-combined.js +++ b/dygraph-combined.js @@ -1,6038 +1,1760 @@ -/*** - - MochiKit.MochiKit 1.4 : PACKED VERSION - - THIS FILE IS AUTOMATICALLY GENERATED. If creating patches, please - diff against the source tree, not this file. - - See for documentation, downloads, license, etc. - - (c) 2005 Bob Ippolito. All rights Reserved. - -***/ - -if(typeof (dojo)!="undefined"){ -dojo.provide("MochiKit.Base"); -} -if(typeof (MochiKit)=="undefined"){ -MochiKit={}; -} -if(typeof (MochiKit.Base)=="undefined"){ -MochiKit.Base={}; -} -if(typeof (MochiKit.__export__)=="undefined"){ -MochiKit.__export__=(MochiKit.__compat__||(typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")); -} -MochiKit.Base.VERSION="1.4"; -MochiKit.Base.NAME="MochiKit.Base"; -MochiKit.Base.update=function(_1,_2){ -if(_1===null){ -_1={}; -} -for(var i=1;i1;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}; +DygraphLayout=function(_1,_2){ +this.dygraph_=_1; +this.options={}; +Dygraph.update(this.options,_2?_2:{}); +this.datasets=new Array(); }; -MochiKit.Base.update(MochiKit.Base,{__repr__:function(){ -return "["+this.NAME+" "+this.VERSION+"]"; -},toString:function(){ -return this.__repr__(); -},camelize:function(_6){ -var _7=_6.split("-"); -var cc=_7[0]; -for(var i=1;i<_7.length;i++){ -cc+=_7[i].charAt(0).toUpperCase()+_7[i].substring(1); -} -return cc; -},counter:function(n){ -if(arguments.length===0){ -n=1; -} -return function(){ -return n++; +DygraphLayout.prototype.attr_=function(_3){ +return this.dygraph_.attr_(_3); }; -},clone:function(_b){ -var me=arguments.callee; -if(arguments.length==1){ -me.prototype=_b; -return new me(); -} -},_flattenArray:function(_d,_e){ -for(var i=0;i<_e.length;i++){ -var o=_e[i]; -if(o instanceof Array){ -arguments.callee(_d,o); -}else{ -_d.push(o); -} -} -return _d; -},flattenArray:function(lst){ -return MochiKit.Base._flattenArray([],lst); -},flattenArguments:function(lst){ -var res=[]; -var m=MochiKit.Base; -var _15=m.extend(null,arguments); -while(_15.length){ -var o=_15.shift(); -if(o&&typeof (o)=="object"&&typeof (o.length)=="number"){ -for(var i=o.length-1;i>=0;i--){ -_15.unshift(o[i]); -} -}else{ -res.push(o); -} -} -return res; -},extend:function(_18,obj,_1a){ -if(!_1a){ -_1a=0; +DygraphLayout.prototype.addDataset=function(_4,_5){ +this.datasets[_4]=_5; +}; +DygraphLayout.prototype.evaluate=function(){ +this._evaluateLimits(); +this._evaluateLineCharts(); +this._evaluateLineTicks(); +}; +DygraphLayout.prototype._evaluateLimits=function(){ +this.minxval=this.maxxval=null; +for(var _6 in this.datasets){ +if(!this.datasets.hasOwnProperty(_6)){ +continue; } -if(obj){ -var l=obj.length; -if(typeof (l)!="number"){ -if(typeof (MochiKit.Iter)!="undefined"){ -obj=MochiKit.Iter.list(obj); -l=obj.length; -}else{ -throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); +var _7=this.datasets[_6]; +var x1=_7[0][0]; +if(!this.minxval||x1this.maxxval){ +this.maxxval=x2; } -if(!_18){ -_18=[]; } -for(var i=_1a;i=1){ +_14.y=1; } -for(var i=1;i=0)&&(_14.x<=1)){ +this.points.push(_14); } } } +}; +DygraphLayout.prototype._evaluateLineTicks=function(){ +this.xticks=new Array(); +for(var i=0;i=0)&&(pos<=1)){ +this.xticks.push([pos,_17]); } -return _1d; -},setdefault:function(_23,obj){ -if(_23===null){ -_23={}; } -for(var i=1;i=0)&&(pos<=1)){ +this.yticks.push([pos,_17]); } } +}; +DygraphLayout.prototype.evaluateWithError=function(){ +this.evaluate(); +if(!this.options.errorBars){ +return; } -return _23; -},keys:function(obj){ -var _29=[]; -for(var _2a in obj){ -_29.push(_2a); +var i=0; +for(var _19 in this.datasets){ +if(!this.datasets.hasOwnProperty(_19)){ +continue; } -return _29; -},values:function(obj){ -var _2c=[]; -for(var _2d in obj){ -_2c.push(obj[_2d]); +var j=0; +var _20=this.datasets[_19]; +for(var j=0;j<_20.length;j++,i++){ +var _21=_20[j]; +var xv=parseFloat(_21[0]); +var yv=parseFloat(_21[1]); +if(xv==this.points[i].xval&&yv==this.points[i].yval){ +this.points[i].errorMinus=parseFloat(_21[2]); +this.points[i].errorPlus=parseFloat(_21[3]); } -return _2c; -},items:function(obj){ -var _2f=[]; -var e; -for(var _31 in obj){ -var v; -try{ -v=obj[_31]; } -catch(e){ -continue; } -_2f.push([_31,v]); -} -return _2f; -},_newNamedError:function(_33,_34,_35){ -_35.prototype=new MochiKit.Base.NamedError(_33.NAME+"."+_34); -_33[_34]=_35; -},operator:{truth:function(a){ -return !!a; -},lognot:function(a){ -return !a; -},identity:function(a){ -return a; -},not:function(a){ -return ~a; -},neg:function(a){ -return -a; -},add:function(a,b){ -return a+b; -},sub:function(a,b){ -return a-b; -},div:function(a,b){ -return a/b; -},mod:function(a,b){ -return a%b; -},mul:function(a,b){ -return a*b; -},and:function(a,b){ -return a&b; -},or:function(a,b){ -return a|b; -},xor:function(a,b){ -return a^b; -},lshift:function(a,b){ -return a<>b; -},zrshift:function(a,b){ -return a>>>b; -},eq:function(a,b){ -return a==b; -},ne:function(a,b){ -return a!=b; -},gt:function(a,b){ -return a>b; -},ge:function(a,b){ -return a>=b; -},lt:function(a,b){ -return a0){ +for(var i=0;il){ -_90=l; +var x=this.area.x; +var y=this.area.y+_46[0]*this.area.h; +_40.beginPath(); +_40.moveTo(x,y); +_40.lineTo(x-this.options.axisTickSize,y); +_40.closePath(); +_40.stroke(); +var _47=_42(_46[1]); +var top=(y-this.options.axisLabelFontSize/2); +if(top<0){ +top=0; +} +if(top+this.options.axisLabelFontSize+3>this.height){ +_47.style.bottom="0px"; +}else{ +_47.style.top=top+"px"; +} +_47.style.left="0px"; +_47.style.textAlign="right"; +_47.style.width=this.options.yAxisLabelWidth+"px"; +this.container.appendChild(_47); +this.ylabels.push(_47); +} +var _49=this.ylabels[0]; +var _50=this.options.axisLabelFontSize; +var _51=parseInt(_49.style.top)+_50; +if(_51>this.height-_50){ +_49.style.top=(parseInt(_49.style.top)-_50/2)+"px"; +} +} +_40.beginPath(); +_40.moveTo(this.area.x,this.area.y); +_40.lineTo(this.area.x,this.area.y+this.area.h); +_40.closePath(); +_40.stroke(); } +if(this.options.drawXAxis){ +if(this.layout.xticks){ +for(var i=0;ithis.width){ +_52=this.width-this.options.xAxisLabelWidth; +_47.style.textAlign="right"; +} +if(_52<0){ +_52=0; +_47.style.textAlign="left"; +} +_47.style.left=_52+"px"; +_47.style.width=this.options.xAxisLabelWidth+"px"; +this.container.appendChild(_47); +this.xlabels.push(_47); +} +} +_40.beginPath(); +_40.moveTo(this.area.x,this.area.y+this.area.h); +_40.lineTo(this.area.x+this.area.w,this.area.y+this.area.h); +_40.closePath(); +_40.stroke(); +} +_40.restore(); +}; +DygraphCanvasRenderer.prototype._renderLineChart=function(){ +var _53=this.element.getContext("2d"); +var _54=this.options.colorScheme.length; +var _55=this.options.colorScheme; +var _56=this.layout.options.errorBars; +var _57=[]; +for(var _58 in this.layout.datasets){ +if(this.layout.datasets.hasOwnProperty(_58)){ +_57.push(_58); +} +} +var _59=_57.length; +for(var i=0;i=0){ +ctx.moveTo(_64,_65[0]); +ctx.lineTo(_60.canvasx,_70[0]); +ctx.lineTo(_60.canvasx,_70[1]); +ctx.lineTo(_64,_65[1]); +ctx.closePath(); } -return _8e; +_65[0]=_70[0]; +_65[1]=_70[1]; +_64=_60.canvasx; } -},xfilter:function(fn){ -var _95=[]; -if(fn===null){ -fn=MochiKit.Base.operator.truth; } -for(var i=1;i0){ +if(arguments.length==4){ +this.warn("Using deprecated four-argument dygraph constructor"); +this.__old_init__(div,_75,arguments[2],arguments[3]); }else{ -for(i=0;i=0;i--){ -_af=[_ab[i].apply(this,_af)]; } -return _af[0]; +red=Math.floor(255*red+0.5); +_101=Math.floor(255*_101+0.5); +blue=Math.floor(255*blue+0.5); +return "rgb("+red+","+_101+","+blue+")"; }; -},bind:function(_b1,_b2){ -if(typeof (_b1)=="string"){ -_b1=_b2[_b1]; +Dygraph.prototype.setColors_=function(){ +var num=this.attr_("labels").length-1; +this.colors_=[]; +var _108=this.attr_("colors"); +if(!_108){ +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(Dygraph.hsvToRGB(hue,sat,val)); } -var _b3=_b1.im_func; -var _b4=_b1.im_preargs; -var _b5=_b1.im_self; -var m=MochiKit.Base; -if(typeof (_b1)=="function"&&typeof (_b1.apply)=="undefined"){ -_b1=m._wrapDumbFunction(_b1); +}else{ +for(var i=0;i0){ -_b8=m.concat(me.im_preargs,_b8); +if(obj.x){ +_113+=obj.x; } -var _ba=me.im_self; -if(!_ba){ -_ba=this; } -return me.im_func.apply(_ba,_b8); +return _113; }; -_b7.im_self=_b5; -_b7.im_func=_b3; -_b7.im_preargs=_b4; -return _b7; -},bindMethods:function(_bb){ -var _bc=MochiKit.Base.bind; -for(var k in _bb){ -var _be=_bb[k]; -if(typeof (_be)=="function"){ -_bb[k]=_bc(_be,_bb); -} -} -},registerComparator:function(_bf,_c0,_c1,_c2){ -MochiKit.Base.comparatorRegistry.register(_bf,_c0,_c1,_c2); -},_primitives:{"boolean":true,"string":true,"number":true},compare:function(a,b){ -if(a==b){ -return 0; -} -var _c5=(typeof (a)=="undefined"||a===null); -var _c6=(typeof (b)=="undefined"||b===null); -if(_c5&&_c6){ -return 0; -}else{ -if(_c5){ -return -1; +Dygraph.findPosY=function(obj){ +var _114=0; +if(obj.offsetParent){ +while(obj.offsetParent){ +_114+=obj.offsetTop; +obj=obj.offsetParent; +} }else{ -if(_c6){ -return 1; +if(obj.y){ +_114+=obj.y; } } +return _114; +}; +Dygraph.prototype.createStatusMessage_=function(){ +if(!this.attr_("labelsDiv")){ +var _115=this.attr_("labelsDivWidth"); +var _116={"position":"absolute","fontSize":"14px","zIndex":10,"width":_115+"px","top":"0px","left":(this.width_-_115-2)+"px","background":"white","textAlign":"left","overflow":"hidden"}; +Dygraph.update(_116,this.attr_("labelsDivStyles")); +var div=document.createElement("div"); +for(var name in _116){ +if(_116.hasOwnProperty(name)){ +div.style[name]=_116[name]; } -var m=MochiKit.Base; -var _c8=m._primitives; -if(!(typeof (a) in _c8&&typeof (b) in _c8)){ -try{ -return m.comparatorRegistry.match(a,b); } -catch(e){ -if(e!=m.NotFound){ -throw e; +this.graphDiv.appendChild(div); +this.attrs_.labelsDiv=div; } +}; +Dygraph.prototype.createRollInterface_=function(){ +var _118=this.attr_("showRoller")?"block":"none"; +var _119={"position":"absolute","zIndex":10,"top":(this.plotter_.area.h-25)+"px","left":(this.plotter_.area.x+1)+"px","display":_118}; +var _120=document.createElement("input"); +_120.type="text"; +_120.size="2"; +_120.value=this.rollPeriod_; +for(var name in _119){ +if(_119.hasOwnProperty(name)){ +_120.style[name]=_119[name]; } } -if(ab){ -return 1; -} -} -var _c9=m.repr; -throw new TypeError(_c9(a)+" and "+_c9(b)+" can not be compared"); -},compareDateLike:function(a,b){ -return MochiKit.Base.compare(a.getTime(),b.getTime()); -},compareArrayLike:function(a,b){ -var _ce=MochiKit.Base.compare; -var _cf=a.length; -var _d0=0; -if(_cf>b.length){ -_d0=1; -_cf=b.length; +var de=document; +var b=document.body; +return e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); +} +}; +Dygraph.pageY=function(e){ +if(e.pageY){ +return (!e.pageY||e.pageY<0)?0:e.pageY; }else{ -if(_cf=10){ +self.doZoom_(Math.min(_127,_129),Math.max(_127,_129)); }else{ -if(o===null){ -return "null"; +self.canvas_.getContext("2d").clearRect(0,0,self.canvas_.width,self.canvas_.height); } +_127=null; +_128=null; } -try{ -if(typeof (o.__repr__)=="function"){ -return o.__repr__(); -}else{ -if(typeof (o.repr)=="function"&&o.repr!=arguments.callee){ -return o.repr(); +}); +Dygraph.addEvent(this.hidden_,"dblclick",function(_143){ +if(self.dateWindow_==null){ +return; } +self.dateWindow_=null; +self.drawGraph_(self.rawData_); +var _144=self.rawData_[0][0]; +var _145=self.rawData_[self.rawData_.length-1][0]; +if(self.attr_("zoomCallback")){ +self.attr_("zoomCallback")(_144,_145); } -return MochiKit.Base.reprRegistry.match(o); +}); +}; +Dygraph.prototype.drawZoomRect_=function(_146,endX,_148){ +var ctx=this.canvas_.getContext("2d"); +if(_148){ +ctx.clearRect(Math.min(_146,_148),0,Math.abs(_146-_148),this.height_); } -catch(e){ -if(typeof (o.NAME)=="string"&&(o.toString==Function.prototype.toString||o.toString==Object.prototype.toString)){ -return o.NAME; +if(endX&&_146){ +ctx.fillStyle="rgba(128,128,128,0.33)"; +ctx.fillRect(Math.min(_146,endX),0,Math.abs(endX-_146),this.height_); } +}; +Dygraph.prototype.doZoom_=function(lowX,_150){ +var _151=this.layout_.points; +var _152=null; +var _153=null; +for(var i=0;i<_151.length;i++){ +var cx=_151[i].canvasx; +var x=_151[i].xval; +if(cx_152)){ +_152=x; } -try{ -var _d8=(o+""); +if(cx>_150&&(_153==null||x<_153)){ +_153=x; } -catch(e){ -return "["+typeof (o)+"]"; -} -if(typeof (o)=="function"){ -o=_d8.replace(/^\s+/,""); -var idx=o.indexOf("{"); -if(idx!=-1){ -o=o.substr(0,idx)+"{...}"; -} -} -return _d8; -},reprArrayLike:function(o){ -var m=MochiKit.Base; -return "["+m.map(m.repr,o).join(", ")+"]"; -},reprString:function(o){ -return ("\""+o.replace(/(["\\])/g,"\\$1")+"\"").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r"); -},reprNumber:function(o){ -return o+""; -},registerJSON:function(_de,_df,_e0,_e1){ -MochiKit.Base.jsonRegistry.register(_de,_df,_e0,_e1); -},evalJSON:function(){ -return eval("("+arguments[0]+")"); -},serializeJSON:function(o){ -var _e3=typeof (o); -if(_e3=="number"||_e3=="boolean"){ -return o+""; -}else{ -if(o===null){ -return "null"; } +if(_152==null){ +_152=_151[0].xval; } -var m=MochiKit.Base; -var _e5=m.reprString; -if(_e3=="string"){ -return _e5(o); +if(_153==null){ +_153=_151[_151.length-1].xval; } -var me=arguments.callee; -var _e7; -if(typeof (o.__json__)=="function"){ -_e7=o.__json__(); -if(o!==_e7){ -return me(_e7); +this.dateWindow_=[_152,_153]; +this.drawGraph_(this.rawData_); +if(this.attr_("zoomCallback")){ +this.attr_("zoomCallback")(_152,_153); } +}; +Dygraph.prototype.mouseMove_=function(_155){ +var _156=Dygraph.pageX(_155)-Dygraph.findPosX(this.hidden_); +var _157=this.layout_.points; +var _158=-1; +var _159=-1; +var _160=1e+100; +var idx=-1; +for(var i=0;i<_157.length;i++){ +var dist=Math.abs(_157[i].canvasx-_156); +if(dist>_160){ +break; } -if(typeof (o.json)=="function"){ -_e7=o.json(); -if(o!==_e7){ -return me(_e7); +_160=dist; +idx=i; } +if(idx>=0){ +_158=_157[idx].xval; } -if(_e3!="function"&&typeof (o.length)=="number"){ -var res=[]; -for(var i=0;i_157[_157.length-1].canvasx){ +_158=_157[_157.length-1].xval; } -res.push(val); +this.selPoints_=[]; +for(var i=0;i<_157.length;i++){ +if(_157[i].xval==_158){ +this.selPoints_.push(_157[i]); } -return "["+res.join(", ")+"]"; } -try{ -_e7=m.jsonRegistry.match(o); -if(o!==_e7){ -return me(_e7); +if(this.attr_("highlightCallback")){ +this.attr_("highlightCallback")(_155,_158,this.selPoints_); } +var _163=this.attr_("highlightCircleSize"); +var ctx=this.canvas_.getContext("2d"); +if(this.previousVerticalX_>=0){ +var px=this.previousVerticalX_; +ctx.clearRect(px-_163-1,0,2*_163+2,this.height_); } -catch(e){ -if(e!=m.NotFound){ -throw e; +var isOK=function(x){ +return x&&!isNaN(x); +}; +if(this.selPoints_.length>0){ +var _156=this.selPoints_[0].canvasx; +var _165=this.attr_("xValueFormatter")(_158,this)+":"; +var clen=this.colors_.length; +for(var i=0;i"+_167.name+":"+this.round_(_167.yval,2); } -if(_e3=="function"){ -return null; +this.attr_("labelsDiv").innerHTML=_165; +this.lastx_=_158; +ctx.save(); +for(var i=0;i=Dygraph.DAILY){ +_195.push({v:t,label:new Date(t+3600*1000).strftime(_197)}); +}else{ +_195.push({v:t,label:this.hmsString_(t)}); +} +} +}else{ +var _198; +var _199=1; +if(_194==Dygraph.MONTHLY){ +_198=[0,1,2,3,4,5,6,7,8,9,10,11,12]; +}else{ +if(_194==Dygraph.QUARTERLY){ +_198=[0,3,6,9]; +}else{ +if(_194==Dygraph.BIANNUAL){ +_198=[0,6]; +}else{ +if(_194==Dygraph.ANNUAL){ +_198=[0]; +}else{ +if(_194==Dygraph.DECADAL){ +_198=[0]; +_199=10; +} +} +} +} +} +var _200=new Date(_192).getFullYear(); +var _201=new Date(_193).getFullYear(); +var _202=Dygraph.zeropad; +for(var i=_200;i<=_201;i++){ +if(i%_199!=0){ continue; } -} -val=me(o[k]); -if(typeof (val)!="string"){ +for(var j=0;j<_198.length;j++){ +var _203=i+"/"+_202(1+_198[j])+"/01"; +var t=Date.parse(_203); +if(t<_192||t>_193){ continue; } -res.push(_ec+":"+val); +_195.push({v:t,label:new Date(t).strftime("%b %y")}); } -return "{"+res.join(", ")+"}"; -},objEqual:function(a,b){ -return (MochiKit.Base.compare(a,b)===0); -},arrayEqual:function(_ef,arr){ -if(_ef.length!=arr.length){ -return false; } -return (MochiKit.Base.compare(_ef,arr)===0); -},concat:function(){ -var _f1=[]; -var _f2=MochiKit.Base.extend; -for(var i=0;i=self.attr_("pixelsPerXLabel")){ +_206=i; +break; } -var _f9=m.extend(null,arguments); -return function(a,b){ -var _fc=0; -for(var i=0;(_fc===0)&&(i<_f9.length);i++){ -var key=_f9[i]; -_fc=_f6(a[key],b[key]); } -return _fc; -}; -},reverseKeyComparator:function(key){ -var _100=MochiKit.Base.keyComparator.apply(this,arguments); -return function(a,b){ -return _100(b,a); +if(_206>=0){ +return self.GetXAxis(_204,_205,_206); +}else{ +} }; -},partial:function(func){ -var m=MochiKit.Base; -return m.bind.apply(this,m.extend([func,undefined],arguments,1)); -},listMinMax:function(_105,lst){ -if(lst.length===0){ -return null; +Dygraph.numericTicks=function(minV,maxV,self){ +var _210=[1,2,5]; +var _211,low_val,high_val,nTicks; +var _212=self.attr_("pixelsPerYLabel"); +for(var i=-10;i<50;i++){ +var _213=Math.pow(10,i); +for(var j=0;j<_210.length;j++){ +_211=_213*_210[j]; +low_val=Math.floor(minV/_211)*_211; +high_val=Math.ceil(maxV/_211)*_211; +nTicks=(high_val-low_val)/_211; +var _214=self.height_/nTicks; +if(_214>_212){ +break; } -var cur=lst[0]; -var _108=MochiKit.Base.compare; -for(var i=1;i_212){ +break; } -return cur; -},objMax:function(){ -return MochiKit.Base.listMinMax(1,arguments); -},objMin:function(){ -return MochiKit.Base.listMinMax(-1,arguments); -},findIdentical:function(lst,_10c,_10d,end){ -if(typeof (end)=="undefined"||end===null){ -end=lst.length; } -if(typeof (_10d)=="undefined"||_10d===null){ -_10d=0; +var _215=[]; +var k; +var _217=[]; +if(self.attr_("labelsKMB")){ +k=1000; +_217=["K","M","B","T"]; +} +if(self.attr_("labelsKMG2")){ +if(k){ +self.warn("Setting both labelsKMB and labelsKMG2. Pick one!"); +} +k=1024; +_217=["k","M","G","T"]; +} +for(var i=0;i=0;j--,n/=k){ +if(_219>=n){ +_220=self.round_(_218/n,1)+_217[j]; +break; } -for(var i=_10d;i=0;i--){ -sum+=o[i]; +_215.push({label:_220,v:_218}); } -}else{ -sum+=o; +return _215; +}; +Dygraph.prototype.addYTicks_=function(minY,maxY){ +var _224=Dygraph.numericTicks(minY,maxY,this); +this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_224}); +}; +Dygraph.prototype.extremeValues_=function(_225){ +var minY=null,maxY=null; +var bars=this.attr_("errorBars")||this.attr_("customBars"); +if(bars){ +for(var j=0;j<_225.length;j++){ +var y=_225[j][1][0]; +if(!y){ +continue; } +var low=y-_225[j][1][1]; +var high=y+_225[j][1][2]; +if(low>y){ +low=y; } -if(_113<=0){ -throw new TypeError("mean() requires at least one argument"); +if(highmaxY){ +maxY=high; } -data.sort(compare); -if(data.length%2==0){ -var _117=data.length/2; -return (data[_117]+data[_117-1])/2; -}else{ -return data[(data.length-1)/2]; +if(minY==null||lowmaxY){ +maxY=y; } +if(minY==null||y=low&&_229[k][0]<=high){ +_230.push(_229[k]); +} } -for(var name in _123){ -var o=_123[name]; -if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){ -try{ -o.NAME=base+name; +_229=_230; } -catch(e){ +var _231=this.extremeValues_(_229); +var _232=_231[0]; +var _233=_231[1]; +if(!minY||_232maxY){ +maxY=_233; +} +if(bars){ +var vals=[]; +for(var j=0;j<_229.length;j++){ +vals[j]=[_229[j][0],_229[j][1][0],_229[j][1][1],_229[j][1][2]]; } -} -},queryString:function(_127,_128){ -if(typeof (MochiKit.DOM)!="undefined"&&arguments.length==1&&(typeof (_127)=="string"||(typeof (_127.nodeType)!="undefined"&&_127.nodeType>0))){ -var kv=MochiKit.DOM.formContents(_127); -_127=kv[0]; -_128=kv[1]; +this.layout_.addDataset(this.attr_("labels")[i],vals); }else{ -if(arguments.length==1){ -if(typeof (_127.length)=="number"&&_127.length==2){ -return arguments.callee(_127[0],_127[1]); +this.layout_.addDataset(this.attr_("labels")[i],_229); } -var o=_127; -_127=[]; -_128=[]; -for(var k in o){ -var v=o[k]; -if(typeof (v)=="function"){ -continue; -}else{ -if(typeof (v)!="string"&&typeof (v.length)=="number"){ -for(var i=0;i=0){ +_237=0; } +if(_236>0&&maxY<=0){ +_236=0; } +if(this.attr_("includeZero")){ +if(maxY<0){ +_236=0; } +if(minY>0){ +_237=0; } } -var rval=[]; -var len=Math.min(_127.length,_128.length); -var _130=MochiKit.Base.urlEncode; -for(var i=0;i=0){ +num-=_238[i-_239][1][0]; +den-=_238[i-_239][1][1]; } -arr.push(_136(pair.join("="))); +var date=_238[i][0]; +var _244=den?num/den:0; +if(this.attr_("errorBars")){ +if(this.wilsonInterval_){ +if(den){ +var p=_244<0?0:_244,n=den; +var pm=_241*Math.sqrt(p*(1-p)/n+_241*_241/(4*n*n)); +var _246=1+_241*_241/den; +var low=(p+_241*_241/(2*den)-pm)/_246; +var high=(p+_241*_241/(2*den)+pm)/_246; +_240[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; +}else{ +_240[i]=[date,[0,0,0]]; +} +}else{ +var _247=den?_241*Math.sqrt(_244*(1-_244)/den):1; +_240[i]=[date,[mult*_244,mult*_247,mult*_247]]; } }else{ -for(i=0;i<_134.length;i++){ -pair=_134[i].split("="); -var name=pair.shift(); -if(!name){ -continue; +_240[i]=[date,mult*_244]; } -o[_136(name)]=_136(pair.join("=")); } -} -return o; -}}); -MochiKit.Base.AdapterRegistry=function(){ -this.pairs=[]; -}; -MochiKit.Base.AdapterRegistry.prototype={register:function(name,_13c,wrap,_13e){ -if(_13e){ -this.pairs.unshift([name,_13c,wrap]); }else{ -this.pairs.push([name,_13c,wrap]); -} -},match:function(){ -for(var i=0;i=0){ +var prev=_238[i-_239]; +if(prev[1][1]!=null&&!isNaN(prev[1][1])){ +low-=prev[1][0]; +mid-=prev[1][1]; +high-=prev[1][2]; +_249-=1; } -return false; -}}; -MochiKit.Base.EXPORT=["flattenArray","noop","camelize","counter","clone","extend","update","updatetree","setdefault","keys","values","items","NamedError","operator","forwardCall","itemgetter","typeMatcher","isCallable","isUndefined","isUndefinedOrNull","isNull","isEmpty","isNotEmpty","isArrayLike","isDateLike","xmap","map","xfilter","filter","methodcaller","compose","bind","bindMethods","NotFound","AdapterRegistry","registerComparator","compare","registerRepr","repr","objEqual","arrayEqual","concat","keyComparator","reverseKeyComparator","partial","merge","listMinMax","listMax","listMin","objMax","objMin","nodeWalk","zip","urlEncode","queryString","serializeJSON","registerJSON","evalJSON","parseQueryString","findValue","findIdentical","flattenArguments","method","average","mean","median"]; -MochiKit.Base.EXPORT_OK=["nameFunctions","comparatorRegistry","reprRegistry","jsonRegistry","compareDateLike","compareArrayLike","reprArrayLike","reprString","reprNumber"]; -MochiKit.Base._exportSymbols=function(_144,_145){ -if(!MochiKit.__export__){ -return; } -var all=_145.EXPORT_TAGS[":all"]; -for(var i=0;i_154){ -var i=_15c.length-_154; -res=fmt.separator+_15c.substring(i,_15c.length)+res; -_15c=_15c.substring(0,i); +_240[i]=[_238[i][0],null]; } } -res=_15c+res; -if(_152>0){ -while(frac.length<_155){ -frac=frac+"0"; -} -res=res+fmt.decimal+frac; -} -return _157+res+_158; -}; -}; -MochiKit.Format.numberFormatter=function(_160,_161,_162){ -if(typeof (_161)=="undefined"){ -_161=""; -} -var _163=_160.match(/((?:[0#]+,)?[0#]+)(?:\.([0#]+))?(%)?/); -if(!_163){ -throw TypeError("Invalid pattern"); -} -var _164=_160.substr(0,_163.index); -var _165=_160.substr(_163.index+_163[0].length); -if(_164.search(/-/)==-1){ -_164=_164+"-"; -} -var _166=_163[1]; -var frac=(typeof (_163[2])=="string"&&_163[2]!="")?_163[2]:""; -var _168=(typeof (_163[3])=="string"&&_163[3]!=""); -var tmp=_166.split(/,/); -var _16a; -if(typeof (_162)=="undefined"){ -_162="default"; -} -if(tmp.length==1){ -_16a=null; }else{ -_16a=tmp[1].length; -} -var _16b=_166.length-_166.replace(/0/g,"").length; -var _16c=frac.length-frac.replace(/0/g,"").length; -var _16d=frac.length; -var rval=MochiKit.Format._numberFormatter(_161,_164,_165,_162,_168,_16d,_16b,_16a,_16c); -var m=MochiKit.Base; -if(m){ -var fn=arguments.callee; -var args=m.concat(arguments); -rval.repr=function(){ -return [self.NAME,"(",map(m.repr,args).join(", "),")"].join(""); -}; -} -return rval; -}; -MochiKit.Format.formatLocale=function(_172){ -if(typeof (_172)=="undefined"||_172===null){ -_172="default"; +for(var i=0;i<_238.length;i++){ +var sum=0; +var _254=0; +var _253=0; +for(var j=Math.max(0,i-_239+1);j=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){ +_258=true; }else{ -(function(_18d,_18e){ -if((typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")||(MochiKit.__export__===false)){ -var all=_18e.EXPORT_TAGS[":all"]; -for(var i=0;i"19700101"&&str<"20371231"){ +_258=true; } -try{ -if(typeof (MochiKit.Base)=="undefined"){ -throw ""; -} -} -catch(e){ -throw "MochiKit.DOM depends on MochiKit.Base!"; } -if(typeof (MochiKit.DOM)=="undefined"){ -MochiKit.DOM={}; -} -MochiKit.DOM.NAME="MochiKit.DOM"; -MochiKit.DOM.VERSION="1.4"; -MochiKit.DOM.__repr__=function(){ -return "["+this.NAME+" "+this.VERSION+"]"; +if(_258){ +this.attrs_.xValueFormatter=Dygraph.dateString_; +this.attrs_.xValueParser=Dygraph.dateParser; +this.attrs_.xTicker=Dygraph.dateTicker; +}else{ +this.attrs_.xValueFormatter=function(x){ +return x; }; -MochiKit.DOM.toString=function(){ -return this.__repr__(); +this.attrs_.xValueParser=function(x){ +return parseFloat(x); }; -MochiKit.DOM.EXPORT=["removeEmptyTextNodes","formContents","currentWindow","currentDocument","withWindow","withDocument","registerDOMConverter","coerceToDOM","createDOM","createDOMFunc","isChildNode","getNodeAttribute","removeNodeAttribute","setNodeAttribute","updateNodeAttributes","appendChildNodes","insertSiblingNodesAfter","insertSiblingNodesBefore","replaceChildNodes","removeElement","swapDOM","BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG","getElement","$","getElementsByTagAndClassName","addToCallStack","addLoadEvent","focusOnLoad","setElementClass","toggleElementClass","addElementClass","removeElementClass","swapElementClass","hasElementClass","escapeHTML","toHTML","emitHTML","scrapeText","isParent","getFirstParentByTagAndClassName","makeClipping","undoClipping","makePositioned","undoPositioned","getFirstElementByTagAndClassName"]; -MochiKit.DOM.EXPORT_OK=["domConverters"]; -MochiKit.DOM.DEPRECATED=[["computedStyle","MochiKit.Style.getStyle","1.4"],["elementDimensions","MochiKit.Style.getElementDimensions","1.4"],["elementPosition","MochiKit.Style.getElementPosition","1.4"],["hideElement","MochiKit.Style.hideElement","1.4"],["setElementDimensions","MochiKit.Style.setElementDimensions","1.4"],["setElementPosition","MochiKit.Style.setElementPosition","1.4"],["setDisplayForElement","MochiKit.Style.setDisplayForElement","1.4"],["setOpacity","MochiKit.Style.setOpacity","1.4"],["showElement","MochiKit.Style.showElement","1.4"],["Coordinates","MochiKit.Style.Coordinates","1.4"],["Dimensions","MochiKit.Style.Dimensions","1.4"]]; -MochiKit.DOM.getViewportDimensions=new Function(""+"if (!MochiKit[\"Style\"]) {"+" throw new Error(\"This function has been deprecated and depends on MochiKit.Style.\");"+"}"+"return MochiKit.Style.getViewportDimensions.apply(this, arguments);"); -MochiKit.Base.update(MochiKit.DOM,{currentWindow:function(){ -return MochiKit.DOM._window; -},currentDocument:function(){ -return MochiKit.DOM._document; -},withWindow:function(win,func){ -var self=MochiKit.DOM; -var _194=self._document; -var _195=self._window; -var rval; -try{ -self._window=win; -self._document=win.document; -rval=func(); -} -catch(e){ -self._window=_195; -self._document=_194; -throw e; -} -self._window=_195; -self._document=_194; -return rval; -},formContents:function(elem){ -var _198=[]; -var _199=[]; -var m=MochiKit.Base; -var self=MochiKit.DOM; -if(typeof (elem)=="undefined"||elem===null){ -elem=self._document.body; -}else{ -elem=self.getElement(elem); -} -m.nodeWalk(elem,function(elem){ -var name=elem.name; -if(m.isNotEmpty(name)){ -var _19e=elem.tagName.toUpperCase(); -if(_19e==="INPUT"&&(elem.type=="radio"||elem.type=="checkbox")&&!elem.checked){ -return null; -} -if(_19e==="SELECT"){ -if(elem.type=="select-one"){ -if(elem.selectedIndex>=0){ -var opt=elem.options[elem.selectedIndex]; -var v=opt.value; -if(!v){ -var h=opt.outerHTML; -if(h&&!h.match(/^[^>]+\svalue\s*=/i)){ -v=opt.text; -} -} -_198.push(name); -_199.push(v); -return null; -} -_198.push(name); -_199.push(""); -return null; -}else{ -var opts=elem.options; -if(!opts.length){ -_198.push(name); -_199.push(""); -return null; -} -for(var i=0;i]+\svalue\s*=/i)){ -v=opt.text; -} -} -_198.push(name); -_199.push(v); -} -return null; -} -} -if(_19e==="FORM"||_19e==="P"||_19e==="SPAN"||_19e==="DIV"){ -return elem.childNodes; -} -_198.push(name); -_199.push(elem.value||""); -return null; -} -return elem.childNodes; -}); -return [_198,_199]; -},withDocument:function(doc,func){ -var self=MochiKit.DOM; -var _1a7=self._document; -var rval; -try{ -self._document=doc; -rval=func(); -} -catch(e){ -self._document=_1a7; -throw e; -} -self._document=_1a7; -return rval; -},registerDOMConverter:function(name,_1aa,wrap,_1ac){ -MochiKit.DOM.domConverters.register(name,_1aa,wrap,_1ac); -},coerceToDOM:function(node,ctx){ -var m=MochiKit.Base; -var im=MochiKit.Iter; -var self=MochiKit.DOM; -if(im){ -var iter=im.iter; -var _1b3=im.repeat; -var map=m.map; -} -var _1b5=self.domConverters; -var _1b6=arguments.callee; -var _1b7=m.NotFound; -while(true){ -if(typeof (node)=="undefined"||node===null){ -return null; -} -if(typeof (node)=="function"&&typeof (node.length)=="number"&&!(node instanceof Function)){ -node=im.list(node); -} -if(typeof (node.nodeType)!="undefined"&&node.nodeType>0){ -return node; -} -if(typeof (node)=="number"||typeof (node)=="boolean"){ -node=node.toString(); -} -if(typeof (node)=="string"){ -return self._document.createTextNode(node); +}; +Dygraph.prototype.parseCSV_=function(data){ +var ret=[]; +var _259=data.split("\n"); +var _260=this.attr_("delimiter"); +if(_259[0].indexOf(_260)==-1&&_259[0].indexOf("\t")>=0){ +_260="\t"; } -if(typeof (node.__dom__)=="function"){ -node=node.__dom__(ctx); -continue; +var _261=0; +if(this.labelsFromCSV_){ +_261=1; +this.attrs_.labels=_259[0].split(_260); } -if(typeof (node.dom)=="function"){ -node=node.dom(ctx); +var _262; +var _263=false; +var _264=this.attr_("labels").length; +for(var i=_261;i<_259.length;i++){ +var line=_259[i]; +if(line.length==0){ continue; } -if(typeof (node)=="function"){ -node=node.apply(ctx,[ctx]); +if(line[0]=="#"){ continue; } -if(im){ -var _1b8=null; -try{ -_1b8=iter(node); -} -catch(e){ -} -if(_1b8){ -return map(_1b6,_1b8,_1b3(ctx)); -} -} -try{ -node=_1b5.match(node,ctx); +var _266=line.split(_260); +if(_266.length<2){ continue; } -catch(e){ -if(e!=_1b7){ -throw e; -} -} -return self._document.createTextNode(node.toString()); -} -return undefined; -},isChildNode:function(node,_1ba){ -var self=MochiKit.DOM; -if(typeof (node)=="string"){ -node=self.getElement(node); -} -if(typeof (_1ba)=="string"){ -_1ba=self.getElement(_1ba); +var _267=[]; +if(!_263){ +this.detectTypeFromString_(_266[0]); +_262=this.attr_("xValueParser"); +_263=true; } -if(node===_1ba){ -return true; -} -while(node&&node.tagName.toUpperCase()!="BODY"){ -node=node.parentNode; -if(node===_1ba){ -return true; -} -} -return false; -},setNodeAttribute:function(node,attr,_1be){ -var o={}; -o[attr]=_1be; -try{ -return MochiKit.DOM.updateNodeAttributes(node,o); -} -catch(e){ -} -return null; -},getNodeAttribute:function(node,attr){ -var self=MochiKit.DOM; -var _1c3=self.attributeArray.renames[attr]; -node=self.getElement(node); -try{ -if(_1c3){ -return node[_1c3]; -} -return node.getAttribute(attr); -} -catch(e){ -} -return null; -},removeNodeAttribute:function(node,attr){ -var self=MochiKit.DOM; -var _1c7=self.attributeArray.renames[attr]; -node=self.getElement(node); -try{ -if(_1c7){ -return node[_1c7]; -} -return node.removeAttribute(attr); -} -catch(e){ +_267[0]=_262(_266[0],this); +if(this.fractions_){ +for(var j=1;j<_266.length;j++){ +var vals=_266[j].split("/"); +_267[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; } -return null; -},updateNodeAttributes:function(node,_1c9){ -var elem=node; -var self=MochiKit.DOM; -if(typeof (node)=="string"){ -elem=self.getElement(node); -} -if(_1c9){ -var _1cc=MochiKit.Base.updatetree; -if(self.attributeArray.compliant){ -for(var k in _1c9){ -var v=_1c9[k]; -if(typeof (v)=="object"&&typeof (elem[k])=="object"){ -if(k=="style"&&MochiKit.Style){ -MochiKit.Style.setStyle(elem,v); }else{ -_1cc(elem[k],v); +if(this.attr_("errorBars")){ +for(var j=1;j<_266.length;j+=2){ +_267[(j+1)/2]=[parseFloat(_266[j]),parseFloat(_266[j+1])]; } }else{ -if(k.substring(0,2)=="on"){ -if(typeof (v)=="string"){ -v=new Function(v); +if(this.attr_("customBars")){ +for(var j=1;j<_266.length;j++){ +var vals=_266[j].split(";"); +_267[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; } -elem[k]=v; }else{ -elem.setAttribute(k,v); +for(var j=1;j<_266.length;j++){ +_267[j]=parseFloat(_266[j]); } } } -}else{ -var _1cf=self.attributeArray.renames; -for(var k in _1c9){ -v=_1c9[k]; -var _1d0=_1cf[k]; -if(k=="style"&&typeof (v)=="string"){ -elem.style.cssText=v; -}else{ -if(typeof (_1d0)=="string"){ -elem[_1d0]=v; -}else{ -if(typeof (elem[k])=="object"&&typeof (v)=="object"){ -if(k=="style"&&MochiKit.Style){ -MochiKit.Style.setStyle(elem,v); -}else{ -_1cc(elem[k],v); } -}else{ -if(k.substring(0,2)=="on"){ -if(typeof (v)=="string"){ -v=new Function(v); +ret.push(_267); +if(_267.length!=_264){ +this.error("Number of columns in line "+i+" ("+_267.length+") does not agree with number of labels ("+_264+") "+line); } -elem[k]=v; -}else{ -elem.setAttribute(k,v); } +return ret; +}; +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"; -_1ec=false; -} -} -var d=self._document; -if(_1ec&&d===document){ -elem=d.createElementNS("http://www.w3.org/1999/xhtml",name); -}else{ -elem=d.createElement(name); +var ret=[]; +for(var i=0;i/g,">"); -},toHTML:function(dom){ -return MochiKit.DOM.emitHTML(dom).join(""); -},emitHTML:function(dom,lst){ -if(typeof (lst)=="undefined"||lst===null){ -lst=[]; -} -var _23a=[dom]; -var self=MochiKit.DOM; -var _23c=self.escapeHTML; -var _23d=self.attributeArray; -while(_23a.length){ -dom=_23a.pop(); -if(typeof (dom)=="string"){ -lst.push(dom); +return r; +}; +Dygraph.prototype.start_=function(){ +if(typeof this.file_=="function"){ +this.loadedEvent_(this.file_()); }else{ -if(dom.nodeType==1){ -lst.push("<"+dom.tagName.toLowerCase()); -var _23e=[]; -var _23f=_23d(dom); -for(var i=0;i<_23f.length;i++){ -var a=_23f[i]; -_23e.push([" ",a.name,"=\"",_23c(a.value),"\""]); -} -_23e.sort(); -for(i=0;i<_23e.length;i++){ -var _242=_23e[i]; -for(var j=0;j<_242.length;j++){ -lst.push(_242[j]); -} -} -if(dom.hasChildNodes()){ -lst.push(">"); -_23a.push(""); -var _244=dom.childNodes; -for(i=_244.length-1;i>=0;i--){ -_23a.push(_244[i]); -} +if(Dygraph.isArrayLike(this.file_)){ +this.rawData_=this.parseArray_(this.file_); +this.drawGraph_(this.rawData_); }else{ -lst.push("/>"); -} +if(typeof this.file_=="object"&&typeof this.file_.getColumnRange=="function"){ +this.rawData_=this.parseDataTable_(this.file_); +this.drawGraph_(this.rawData_); }else{ -if(dom.nodeType==3){ -lst.push(_23c(dom.nodeValue)); -} -} -} -} -return lst; -},scrapeText:function(node,_246){ -var rval=[]; -(function(node){ -var cn=node.childNodes; -if(cn){ -for(var i=0;i=0){ +this.loadedEvent_(this.file_); +}else{ +var req=new XMLHttpRequest(); +var _278=this; +req.onreadystatechange=function(){ +if(req.readyState==4){ +if(req.status==200){ +_278.loadedEvent_(req.responseText); } -var _24b=node.nodeValue; -if(typeof (_24b)=="string"){ -rval.push(_24b); } -})(MochiKit.DOM.getElement(node)); -if(_246){ -return rval; -}else{ -return rval.join(""); -} -},removeEmptyTextNodes:function(_24c){ -_24c=MochiKit.DOM.getElement(_24c); -for(var i=0;i<_24c.childNodes.length;i++){ -var node=_24c.childNodes[i]; -if(node.nodeType==3&&!/\S/.test(node.nodeValue)){ -node.parentNode.removeChild(node); -} -} -},makeClipping:function(_24f){ -_24f=MochiKit.DOM.getElement(_24f); -var _250=_24f.style.overflow; -if((MochiKit.Style.getStyle(_24f,"overflow")||"visible")!="hidden"){ -_24f.style.overflow="hidden"; -} -return _250; -},undoClipping:function(_251,_252){ -_251=MochiKit.DOM.getElement(_251); -if(!_252){ -return; +}; +req.open("GET",this.file_,true); +req.send(null); } -_251.style.overflow=_252; -},makePositioned:function(_253){ -_253=MochiKit.DOM.getElement(_253); -var pos=MochiKit.Style.getStyle(_253,"position"); -if(pos=="static"||!pos){ -_253.style.position="relative"; -if(/Opera/.test(navigator.userAgent)){ -_253.style.top=0; -_253.style.left=0; -} -} -},undoPositioned:function(_255){ -_255=MochiKit.DOM.getElement(_255); -if(_255.style.position=="relative"){ -_255.style.position=_255.style.top=_255.style.left=_255.style.bottom=_255.style.right=""; -} -},getFirstElementByTagAndClassName:function(_256,_257,_258){ -var self=MochiKit.DOM; -if(typeof (_256)=="undefined"||_256===null){ -_256="*"; -} -if(typeof (_258)=="undefined"||_258===null){ -_258=self._document; -} -_258=self.getElement(_258); -var _25a=(_258.getElementsByTagName(_256)||self._document.all); -if(typeof (_257)=="undefined"||_257===null){ -return _25a[0]; -} -for(var i=0;i<_25a.length;i++){ -var _25c=_25a[i]; -var _25d=_25c.className.split(" "); -for(var j=0;j<_25d.length;j++){ -if(_25d[j]==_257){ -return _25c; -} -} -} -},getFirstParentByTagAndClassName:function(elem,_260,_261){ -var self=MochiKit.DOM; -elem=self.getElement(elem); -if(typeof (_260)=="undefined"||_260===null){ -_260="*"; -}else{ -_260=_260.toUpperCase(); -} -if(typeof (_261)=="undefined"||_261===null){ -_261=null; -} -var _263=""; -var _264=""; -while(elem&&elem.tagName){ -elem=elem.parentNode; -if(_260=="*"&&_261===null){ -return elem; -} -_263=elem.className.split(" "); -_264=elem.tagName.toUpperCase(); -if(_261===null&&_260==_264){ -return elem; }else{ -if(_261!==null){ -for(var i=0;i<_263.length;i++){ -if(_260=="*"&&_263[i]==_261){ -return elem; -}else{ -if(_260==_264&&_263[i]==_261){ -return elem; -} +this.error("Unknown data format: "+(typeof this.file_)); } } } } +}; +Dygraph.prototype.updateOptions=function(_279){ +if(_279.rollPeriod){ +this.rollPeriod_=_279.rollPeriod; } -return elem; -},isParent:function(_266,_267){ -if(!_266.parentNode||_266==_267){ -return false; +if(_279.dateWindow){ +this.dateWindow_=_279.dateWindow; } -if(_266.parentNode==_267){ -return true; +if(_279.valueRange){ +this.valueRange_=_279.valueRange; } -return MochiKit.DOM.isParent(_266.parentNode,_267); -},__new__:function(win){ -var m=MochiKit.Base; -if(typeof (document)!="undefined"){ -this._document=document; -var _26a="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -this._xhtml=(document.documentElement&&document.createElementNS&&document.documentElement.namespaceURI===_26a); +Dygraph.update(this.user_attrs_,_279); +this.labelsFromCSV_=(this.attr_("labels")==null); +this.layout_.updateOptions({"errorBars":this.attr_("errorBars")}); +if(_279["file"]&&_279["file"]!=this.file_){ +this.file_=_279["file"]; +this.start_(); }else{ -if(MochiKit.MockDOM){ -this._document=MochiKit.MockDOM.document; -} -} -this._window=win; -this.domConverters=new m.AdapterRegistry(); -var _26b=this._document.createElement("span"); -var _26c; -if(_26b&&_26b.attributes&&_26b.attributes.length>0){ -var _26d=m.filter; -_26c=function(node){ -return _26d(_26c.ignoreAttrFilter,node.attributes); +this.drawGraph_(this.rawData_); +} }; -_26c.ignoreAttr={}; -var _26f=_26b.attributes; -var _270=_26c.ignoreAttr; -for(var i=0;i<_26f.length;i++){ -var a=_26f[i]; -_270[a.name]=a.value; -} -_26c.ignoreAttrFilter=function(a){ -return (_26c.ignoreAttr[a.name]!=a.value); +Dygraph.prototype.adjustRoll=function(_280){ +this.rollPeriod_=_280; +this.drawGraph_(this.rawData_); }; -_26c.compliant=false; -_26c.renames={"class":"className","checked":"defaultChecked","usemap":"useMap","for":"htmlFor","readonly":"readOnly","colspan":"colSpan","bgcolor":"bgColor","cellspacing":"cellSpacing","cellpadding":"cellPadding"}; -}else{ -_26c=function(node){ -return node.attributes; +Dygraph.createCanvas=function(){ +var _281=document.createElement("canvas"); +isIE=(/MSIE/.test(navigator.userAgent)&&!window.opera); +if(isIE){ +_281=G_vmlCanvasManager.initElement(_281); +} +return _281; }; -_26c.compliant=true; -_26c.renames={}; -} -this.attributeArray=_26c; -var _275=function(_276,arr){ -var _278=arr[1].split("."); -var str=""; -var obj={}; -str+="if (!MochiKit."+_278[1]+") { throw new Error(\""; -str+="This function has been deprecated and depends on MochiKit."; -str+=_278[1]+".\");}"; -str+="return MochiKit."+_278[1]+"."+arr[0]; -str+=".apply(this, arguments);"; -obj[_278[2]]=new Function(str); -MochiKit.Base.update(MochiKit[_276],obj); +Dygraph.GVizChart=function(_282){ +this.container=_282; }; -for(var i;i255)?255:this.r); +this.g=(this.g<0||isNaN(this.g))?0:((this.g>255)?255:this.g); +this.b=(this.b<0||isNaN(this.b))?0:((this.b>255)?255:this.b); +this.toRGB=function(){ +return "rgb("+this.r+", "+this.g+", "+this.b+")"; +}; +this.toHex=function(){ +var r=this.r.toString(16); +var g=this.g.toString(16); +var b=this.b.toString(16); +if(r.length==1){ +r="0"+r; } -catch(e){ -throw "MochiKit.Style depends on MochiKit.DOM!"; +if(g.length==1){ +g="0"+g; } -if(typeof (MochiKit.Style)=="undefined"){ -MochiKit.Style={}; +if(b.length==1){ +b="0"+b; } -MochiKit.Style.NAME="MochiKit.Style"; -MochiKit.Style.VERSION="1.4"; -MochiKit.Style.__repr__=function(){ -return "["+this.NAME+" "+this.VERSION+"]"; -}; -MochiKit.Style.toString=function(){ -return this.__repr__(); -}; -MochiKit.Style.EXPORT_OK=[]; -MochiKit.Style.EXPORT=["setStyle","setOpacity","getStyle","getElementDimensions","elementDimensions","setElementDimensions","getElementPosition","elementPosition","setElementPosition","setDisplayForElement","hideElement","showElement","getViewportDimensions","getViewportPosition","Dimensions","Coordinates"]; -MochiKit.Style.Dimensions=function(w,h){ -this.w=w; -this.h=h; -}; -MochiKit.Style.Dimensions.prototype.__repr__=function(){ -var repr=MochiKit.Base.repr; -return "{w: "+repr(this.w)+", h: "+repr(this.h)+"}"; -}; -MochiKit.Style.Dimensions.prototype.toString=function(){ -return this.__repr__(); -}; -MochiKit.Style.Coordinates=function(x,y){ -this.x=x; -this.y=y; +return "#"+r+g+b; }; -MochiKit.Style.Coordinates.prototype.__repr__=function(){ -var repr=MochiKit.Base.repr; -return "{x: "+repr(this.x)+", y: "+repr(this.y)+"}"; -}; -MochiKit.Style.Coordinates.prototype.toString=function(){ -return this.__repr__(); -}; -MochiKit.Base.update(MochiKit.Style,{getStyle:function(elem,_283){ -var dom=MochiKit.DOM; -var d=dom._document; -elem=dom.getElement(elem); -_283=MochiKit.Base.camelize(_283); -if(!elem||elem==d){ -return undefined; -} -if(_283=="opacity"&&elem.filters){ -var _286=(MochiKit.Style.getStyle(elem,"filter")||"").match(/alpha\(opacity=(.*)\)/); -if(_286&&_286[1]){ -return parseFloat(_286[1])/100; -} -return 1; -} -var _287=elem.style?elem.style[_283]:null; -if(!_287){ -if(d.defaultView&&d.defaultView.getComputedStyle){ -var css=d.defaultView.getComputedStyle(elem,null); -_283=_283.replace(/([A-Z])/g,"-$1").toLowerCase(); -_287=css?css.getPropertyValue(_283):null; -}else{ -if(elem.currentStyle){ -_287=elem.currentStyle[_283]; -} -} -} -if(_283=="opacity"){ -_287=parseFloat(_287); -} -if(/Opera/.test(navigator.userAgent)&&(MochiKit.Base.find(["left","top","right","bottom"],_283)!=-1)){ -if(MochiKit.Style.getStyle(elem,"position")=="static"){ -_287="auto"; -} -} -return _287=="auto"?null:_287; -},setStyle:function(elem,_28a){ -elem=MochiKit.DOM.getElement(elem); -for(var name in _28a){ -if(name=="opacity"){ -MochiKit.Style.setOpacity(elem,_28a[name]); -}else{ -elem.style[MochiKit.Base.camelize(name)]=_28a[name]; -} -} -},setOpacity:function(elem,o){ -elem=MochiKit.DOM.getElement(elem); -var self=MochiKit.Style; -if(o==1){ -var _28f=/Gecko/.test(navigator.userAgent)&&!(/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent)); -elem.style["opacity"]=_28f?0.999999:1; -if(/MSIE/.test(navigator.userAgent)){ -elem.style["filter"]=self.getStyle(elem,"filter").replace(/alpha\([^\)]*\)/gi,""); -} -}else{ -if(o<0.00001){ -o=0; -} -elem.style["opacity"]=o; -if(/MSIE/.test(navigator.userAgent)){ -elem.style["filter"]=self.getStyle(elem,"filter").replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+o*100+")"; -} -} -},getElementPosition:function(elem,_291){ -var self=MochiKit.Style; -var dom=MochiKit.DOM; -elem=dom.getElement(elem); -if(!elem||(!(elem.x&&elem.y)&&(!elem.parentNode===null||self.getStyle(elem,"display")=="none"))){ -return undefined; -} -var c=new self.Coordinates(0,0); -var box=null; -var _296=null; -var d=MochiKit.DOM._document; -var de=d.documentElement; -var b=d.body; -if(!elem.parentNode&&elem.x&&elem.y){ -c.x+=elem.x||0; -c.y+=elem.y||0; -}else{ -if(elem.getBoundingClientRect){ -box=elem.getBoundingClientRect(); -c.x+=box.left+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); -c.y+=box.top+(de.scrollTop||b.scrollTop)-(de.clientTop||0); -}else{ -if(elem.offsetParent){ -c.x+=elem.offsetLeft; -c.y+=elem.offsetTop; -_296=elem.offsetParent; -if(_296!=elem){ -while(_296){ -c.x+=_296.offsetLeft; -c.y+=_296.offsetTop; -_296=_296.offsetParent; -} -} -var ua=navigator.userAgent.toLowerCase(); -if((typeof (opera)!="undefined"&&parseFloat(opera.version())<9)||(ua.indexOf("AppleWebKit")!=-1&&self.getStyle(elem,"position")=="absolute")){ -c.x-=b.offsetLeft; -c.y-=b.offsetTop; -} -} -} -} -if(typeof (_291)!="undefined"){ -_291=arguments.callee(_291); -if(_291){ -c.x-=(_291.x||0); -c.y-=(_291.y||0); -} -} -if(elem.parentNode){ -_296=elem.parentNode; -}else{ -_296=null; -} -while(_296){ -var _29b=_296.tagName.toUpperCase(); -if(_29b==="BODY"||_29b==="HTML"){ -break; -} -var disp=self.getStyle(_296,"display"); -if(disp!="inline"&&disp!="table-row"){ -c.x-=_296.scrollLeft; -c.y-=_296.scrollTop; -} -if(_296.parentNode){ -_296=_296.parentNode; -}else{ -_296=null; -} -} -return c; -},setElementPosition:function(elem,_29e,_29f){ -elem=MochiKit.DOM.getElement(elem); -if(typeof (_29f)=="undefined"){ -_29f="px"; -} -var _2a0={}; -var _2a1=MochiKit.Base.isUndefinedOrNull; -if(!_2a1(_29e.x)){ -_2a0["left"]=_29e.x+_29f; -} -if(!_2a1(_29e.y)){ -_2a0["top"]=_29e.y+_29f; -} -MochiKit.DOM.updateNodeAttributes(elem,{"style":_2a0}); -},getElementDimensions:function(elem){ -var self=MochiKit.Style; -var dom=MochiKit.DOM; -if(typeof (elem.w)=="number"||typeof (elem.h)=="number"){ -return new self.Dimensions(elem.w||0,elem.h||0); -} -elem=dom.getElement(elem); -if(!elem){ -return undefined; -} -var disp=self.getStyle(elem,"display"); -if(disp!="none"&&disp!==""&&typeof (disp)!="undefined"){ -return new self.Dimensions(elem.offsetWidth||0,elem.offsetHeight||0); -} -var s=elem.style; -var _2a7=s.visibility; -var _2a8=s.position; -s.visibility="hidden"; -s.position="absolute"; -s.display=""; -var _2a9=elem.offsetWidth; -var _2aa=elem.offsetHeight; -s.display="none"; -s.position=_2a8; -s.visibility=_2a7; -return new self.Dimensions(_2a9,_2aa); -},setElementDimensions:function(elem,_2ac,_2ad){ -elem=MochiKit.DOM.getElement(elem); -if(typeof (_2ad)=="undefined"){ -_2ad="px"; -} -var _2ae={}; -var _2af=MochiKit.Base.isUndefinedOrNull; -if(!_2af(_2ac.w)){ -_2ae["width"]=_2ac.w+_2ad; -} -if(!_2af(_2ac.h)){ -_2ae["height"]=_2ac.h+_2ad; -} -MochiKit.DOM.updateNodeAttributes(elem,{"style":_2ae}); -},setDisplayForElement:function(_2b0,_2b1){ -var _2b2=MochiKit.Base.extend(null,arguments,1); -var _2b3=MochiKit.DOM.getElement; -for(var i=0;i<_2b2.length;i++){ -_2b1=_2b3(_2b2[i]); -if(_2b1){ -_2b1.style.display=_2b0; -} -} -},getViewportDimensions:function(){ -var d=new MochiKit.Style.Dimensions(); -var w=MochiKit.DOM._window; -var b=MochiKit.DOM._document.body; -if(w.innerWidth){ -d.w=w.innerWidth; -d.h=w.innerHeight; -}else{ -if(b.parentElement.clientWidth){ -d.w=b.parentElement.clientWidth; -d.h=b.parentElement.clientHeight; -}else{ -if(b&&b.clientWidth){ -d.w=b.clientWidth; -d.h=b.clientHeight; -} -} -} -return d; -},getViewportPosition:function(){ -var c=new MochiKit.Style.Coordinates(0,0); -var d=MochiKit.DOM._document; -var de=d.documentElement; -var db=d.body; -if(de&&(de.scrollTop||de.scrollLeft)){ -c.x=de.scrollLeft; -c.y=de.scrollTop; -}else{ -if(db){ -c.x=db.scrollLeft; -c.y=db.scrollTop; -} -} -return c; -},__new__:function(){ -var m=MochiKit.Base; -this.elementPosition=this.getElementPosition; -this.elementDimensions=this.getElementDimensions; -this.hideElement=m.partial(this.setDisplayForElement,"none"); -this.showElement=m.partial(this.setDisplayForElement,"block"); -this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; -m.nameFunctions(this); -}}); -MochiKit.Style.__new__(); -MochiKit.Base._exportSymbols(this,MochiKit.Style); -if(typeof (dojo)!="undefined"){ -dojo.provide("MochiKit.Color"); -dojo.require("MochiKit.Base"); -dojo.require("MochiKit.DOM"); -dojo.require("MochiKit.Style"); -} -if(typeof (JSAN)!="undefined"){ -JSAN.use("MochiKit.Base",[]); -JSAN.use("MochiKit.DOM",[]); -JSAN.use("MochiKit.Style",[]); -} -try{ -if(typeof (MochiKit.Base)=="undefined"){ -throw ""; -} -} -catch(e){ -throw "MochiKit.Color depends on MochiKit.Base"; -} -try{ -if(typeof (MochiKit.DOM)=="undefined"){ -throw ""; -} -} -catch(e){ -throw "MochiKit.Color depends on MochiKit.DOM"; -} -try{ -if(typeof (MochiKit.Style)=="undefined"){ -throw ""; -} -} -catch(e){ -throw "MochiKit.Color depends on MochiKit.Style"; -} -if(typeof (MochiKit.Color)=="undefined"){ -MochiKit.Color={}; -} -MochiKit.Color.NAME="MochiKit.Color"; -MochiKit.Color.VERSION="1.4"; -MochiKit.Color.__repr__=function(){ -return "["+this.NAME+" "+this.VERSION+"]"; -}; -MochiKit.Color.toString=function(){ -return this.__repr__(); -}; -MochiKit.Color.Color=function(red,_2be,blue,_2c0){ -if(typeof (_2c0)=="undefined"||_2c0===null){ -_2c0=1; -} -this.rgb={r:red,g:_2be,b:blue,a:_2c0}; -}; -MochiKit.Color.Color.prototype={__class__:MochiKit.Color.Color,colorWithAlpha:function(_2c1){ -var rgb=this.rgb; -var m=MochiKit.Color; -return m.Color.fromRGB(rgb.r,rgb.g,rgb.b,_2c1); -},colorWithHue:function(hue){ -var hsl=this.asHSL(); -hsl.h=hue; -var m=MochiKit.Color; -return m.Color.fromHSL(hsl); -},colorWithSaturation:function(_2c7){ -var hsl=this.asHSL(); -hsl.s=_2c7; -var m=MochiKit.Color; -return m.Color.fromHSL(hsl); -},colorWithLightness:function(_2ca){ -var hsl=this.asHSL(); -hsl.l=_2ca; -var m=MochiKit.Color; -return m.Color.fromHSL(hsl); -},darkerColorWithLevel:function(_2cd){ -var hsl=this.asHSL(); -hsl.l=Math.max(hsl.l-_2cd,0); -var m=MochiKit.Color; -return m.Color.fromHSL(hsl); -},lighterColorWithLevel:function(_2d0){ -var hsl=this.asHSL(); -hsl.l=Math.min(hsl.l+_2d0,1); -var m=MochiKit.Color; -return m.Color.fromHSL(hsl); -},blendedColor:function(_2d3,_2d4){ -if(typeof (_2d4)=="undefined"||_2d4===null){ -_2d4=0.5; -} -var sf=1-_2d4; -var s=this.rgb; -var d=_2d3.rgb; -var df=_2d4; -return MochiKit.Color.Color.fromRGB((s.r*sf)+(d.r*df),(s.g*sf)+(d.g*df),(s.b*sf)+(d.b*df),(s.a*sf)+(d.a*df)); -},compareRGB:function(_2d9){ -var a=this.asRGB(); -var b=_2d9.asRGB(); -return MochiKit.Base.compare([a.r,a.g,a.b,a.a],[b.r,b.g,b.b,b.a]); -},isLight:function(){ -return this.asHSL().b>0.5; -},isDark:function(){ -return (!this.isLight()); -},toHSLString:function(){ -var c=this.asHSL(); -var ccc=MochiKit.Color.clampColorComponent; -var rval=this._hslString; -if(!rval){ -var mid=(ccc(c.h,360).toFixed(0)+","+ccc(c.s,100).toPrecision(4)+"%"+","+ccc(c.l,100).toPrecision(4)+"%"); -var a=c.a; -if(a>=1){ -a=1; -rval="hsl("+mid+")"; -}else{ -if(a<=0){ -a=0; -} -rval="hsla("+mid+","+a+")"; -} -this._hslString=rval; -} -return rval; -},toRGBString:function(){ -var c=this.rgb; -var ccc=MochiKit.Color.clampColorComponent; -var rval=this._rgbString; -if(!rval){ -var mid=(ccc(c.r,255).toFixed(0)+","+ccc(c.g,255).toFixed(0)+","+ccc(c.b,255).toFixed(0)); -if(c.a!=1){ -rval="rgba("+mid+","+c.a+")"; -}else{ -rval="rgb("+mid+")"; -} -this._rgbString=rval; -} -return rval; -},asRGB:function(){ -return MochiKit.Base.clone(this.rgb); -},toHexString:function(){ -var m=MochiKit.Color; -var c=this.rgb; -var ccc=MochiKit.Color.clampColorComponent; -var rval=this._hexString; -if(!rval){ -rval=("#"+m.toColorPart(ccc(c.r,255))+m.toColorPart(ccc(c.g,255))+m.toColorPart(ccc(c.b,255))); -this._hexString=rval; -} -return rval; -},asHSV:function(){ -var hsv=this.hsv; -var c=this.rgb; -if(typeof (hsv)=="undefined"||hsv===null){ -hsv=MochiKit.Color.rgbToHSV(this.rgb); -this.hsv=hsv; -} -return MochiKit.Base.clone(hsv); -},asHSL:function(){ -var hsl=this.hsl; -var c=this.rgb; -if(typeof (hsl)=="undefined"||hsl===null){ -hsl=MochiKit.Color.rgbToHSL(this.rgb); -this.hsl=hsl; -} -return MochiKit.Base.clone(hsl); -},toString:function(){ -return this.toRGBString(); -},repr:function(){ -var c=this.rgb; -var col=[c.r,c.g,c.b,c.a]; -return this.__class__.NAME+"("+col.join(", ")+")"; -}}; -MochiKit.Base.update(MochiKit.Color.Color,{fromRGB:function(red,_2f0,blue,_2f2){ -var _2f3=MochiKit.Color.Color; -if(arguments.length==1){ -var rgb=red; -red=rgb.r; -_2f0=rgb.g; -blue=rgb.b; -if(typeof (rgb.a)=="undefined"){ -_2f2=undefined; -}else{ -_2f2=rgb.a; -} -} -return new _2f3(red,_2f0,blue,_2f2); -},fromHSL:function(hue,_2f6,_2f7,_2f8){ -var m=MochiKit.Color; -return m.Color.fromRGB(m.hslToRGB.apply(m,arguments)); -},fromHSV:function(hue,_2fb,_2fc,_2fd){ -var m=MochiKit.Color; -return m.Color.fromRGB(m.hsvToRGB.apply(m,arguments)); -},fromName:function(name){ -var _300=MochiKit.Color.Color; -if(name.charAt(0)=="\""){ -name=name.substr(1,name.length-2); -} -var _301=_300._namedColors[name.toLowerCase()]; -if(typeof (_301)=="string"){ -return _300.fromHexString(_301); -}else{ -if(name=="transparent"){ -return _300.transparentColor(); -} -} -return null; -},fromString:function(_302){ -var self=MochiKit.Color.Color; -var _304=_302.substr(0,3); -if(_304=="rgb"){ -return self.fromRGBString(_302); -}else{ -if(_304=="hsl"){ -return self.fromHSLString(_302); -}else{ -if(_302.charAt(0)=="#"){ -return self.fromHexString(_302); -} -} -} -return self.fromName(_302); -},fromHexString:function(_305){ -if(_305.charAt(0)=="#"){ -_305=_305.substring(1); -} -var _306=[]; -var i,hex; -if(_305.length==3){ -for(i=0;i<3;i++){ -hex=_305.substr(i,1); -_306.push(parseInt(hex+hex,16)/255); -} -}else{ -for(i=0;i<6;i+=2){ -hex=_305.substr(i,2); -_306.push(parseInt(hex,16)/255); -} -} -var _309=MochiKit.Color.Color; -return _309.fromRGB.apply(_309,_306); -},_fromColorString:function(pre,_30b,_30c,_30d){ -if(_30d.indexOf(pre)===0){ -_30d=_30d.substring(_30d.indexOf("(",3)+1,_30d.length-1); -} -var _30e=_30d.split(/\s*,\s*/); -var _30f=[]; -for(var i=0;i<_30e.length;i++){ -var c=_30e[i]; -var val; -var _313=c.substring(c.length-3); -if(c.charAt(c.length-1)=="%"){ -val=0.01*parseFloat(c.substring(0,c.length-1)); -}else{ -if(_313=="deg"){ -val=parseFloat(c)/360; -}else{ -if(_313=="rad"){ -val=parseFloat(c)/(Math.PI*2); -}else{ -val=_30c[i]*parseFloat(c); -} -} -} -_30f.push(val); -} -return this[_30b].apply(this,_30f); -},fromComputedStyle:function(elem,_315){ -var d=MochiKit.DOM; -var cls=MochiKit.Color.Color; -for(elem=d.getElement(elem);elem;elem=elem.parentNode){ -var _318=MochiKit.Style.getStyle.apply(d,arguments); -if(!_318){ -continue; -} -var _319=cls.fromString(_318); -if(!_319){ -break; -} -if(_319.asRGB().a>0){ -return _319; -} -} -return null; -},fromBackground:function(elem){ -var cls=MochiKit.Color.Color; -return cls.fromComputedStyle(elem,"backgroundColor","background-color")||cls.whiteColor(); -},fromText:function(elem){ -var cls=MochiKit.Color.Color; -return cls.fromComputedStyle(elem,"color","color")||cls.blackColor(); -},namedColors:function(){ -return MochiKit.Base.clone(MochiKit.Color.Color._namedColors); -}}); -MochiKit.Base.update(MochiKit.Color,{clampColorComponent:function(v,_31f){ -v*=_31f; -if(v<0){ -return 0; -}else{ -if(v>_31f){ -return _31f; -}else{ -return v; -} -} -},_hslValue:function(n1,n2,hue){ -if(hue>6){ -hue-=6; -}else{ -if(hue<0){ -hue+=6; -} -} -var val; -if(hue<1){ -val=n1+(n2-n1)*hue; -}else{ -if(hue<3){ -val=n2; -}else{ -if(hue<4){ -val=n1+(n2-n1)*(4-hue); -}else{ -val=n1; -} -} -} -return val; -},hsvToRGB:function(hue,_325,_326,_327){ -if(arguments.length==1){ -var hsv=hue; -hue=hsv.h; -_325=hsv.s; -_326=hsv.v; -_327=hsv.a; -} -var red; -var _32a; -var blue; -if(_325===0){ -red=_326; -_32a=_326; -blue=_326; -}else{ -var i=Math.floor(hue*6); -var f=(hue*6)-i; -var p=_326*(1-_325); -var q=_326*(1-(_325*f)); -var t=_326*(1-(_325*(1-f))); -switch(i){ -case 1: -red=q; -_32a=_326; -blue=p; -break; -case 2: -red=p; -_32a=_326; -blue=t; -break; -case 3: -red=p; -_32a=q; -blue=_326; -break; -case 4: -red=t; -_32a=p; -blue=_326; -break; -case 5: -red=_326; -_32a=p; -blue=q; -break; -case 6: -case 0: -red=_326; -_32a=t; -blue=p; -break; -} -} -return {r:red,g:_32a,b:blue,a:_327}; -},hslToRGB:function(hue,_332,_333,_334){ -if(arguments.length==1){ -var hsl=hue; -hue=hsl.h; -_332=hsl.s; -_333=hsl.l; -_334=hsl.a; -} -var red; -var _337; -var blue; -if(_332===0){ -red=_333; -_337=_333; -blue=_333; -}else{ -var m2; -if(_333<=0.5){ -m2=_333*(1+_332); -}else{ -m2=_333+_332-(_333*_332); -} -var m1=(2*_333)-m2; -var f=MochiKit.Color._hslValue; -var h6=hue*6; -red=f(m1,m2,h6+2); -_337=f(m1,m2,h6); -blue=f(m1,m2,h6-2); -} -return {r:red,g:_337,b:blue,a:_334}; -},rgbToHSV:function(red,_33e,blue,_340){ -if(arguments.length==1){ -var rgb=red; -red=rgb.r; -_33e=rgb.g; -blue=rgb.b; -_340=rgb.a; -} -var max=Math.max(Math.max(red,_33e),blue); -var min=Math.min(Math.min(red,_33e),blue); -var hue; -var _345; -var _346=max; -if(min==max){ -hue=0; -_345=0; -}else{ -var _347=(max-min); -_345=_347/max; -if(red==max){ -hue=(_33e-blue)/_347; -}else{ -if(_33e==max){ -hue=2+((blue-red)/_347); -}else{ -hue=4+((red-_33e)/_347); -} -} -hue/=6; -if(hue<0){ -hue+=1; -} -if(hue>1){ -hue-=1; -} -} -return {h:hue,s:_345,v:_346,a:_340}; -},rgbToHSL:function(red,_349,blue,_34b){ -if(arguments.length==1){ -var rgb=red; -red=rgb.r; -_349=rgb.g; -blue=rgb.b; -_34b=rgb.a; -} -var max=Math.max(red,Math.max(_349,blue)); -var min=Math.min(red,Math.min(_349,blue)); -var hue; -var _350; -var _351=(max+min)/2; -var _352=max-min; -if(_352===0){ -hue=0; -_350=0; -}else{ -if(_351<=0.5){ -_350=_352/(max+min); -}else{ -_350=_352/(2-max-min); -} -if(red==max){ -hue=(_349-blue)/_352; -}else{ -if(_349==max){ -hue=2+((blue-red)/_352); -}else{ -hue=4+((red-_349)/_352); -} -} -hue/=6; -if(hue<0){ -hue+=1; -} -if(hue>1){ -hue-=1; -} -} -return {h:hue,s:_350,l:_351,a:_34b}; -},toColorPart:function(num){ -num=Math.round(num); -var _354=num.toString(16); -if(num<16){ -return "0"+_354; -} -return _354; -},__new__:function(){ -var m=MochiKit.Base; -this.Color.fromRGBString=m.bind(this.Color._fromColorString,this.Color,"rgb","fromRGB",[1/255,1/255,1/255,1]); -this.Color.fromHSLString=m.bind(this.Color._fromColorString,this.Color,"hsl","fromHSL",[1/360,0.01,0.01,1]); -var _356=1/3; -var _357={black:[0,0,0],blue:[0,0,1],brown:[0.6,0.4,0.2],cyan:[0,1,1],darkGray:[_356,_356,_356],gray:[0.5,0.5,0.5],green:[0,1,0],lightGray:[2*_356,2*_356,2*_356],magenta:[1,0,1],orange:[1,0.5,0],purple:[0.5,0,0.5],red:[1,0,0],transparent:[0,0,0,0],white:[1,1,1],yellow:[1,1,0]}; -var _358=function(name,r,g,b,a){ -var rval=this.fromRGB(r,g,b,a); -this[name]=function(){ -return rval; -}; -return rval; -}; -for(var k in _357){ -var name=k+"Color"; -var _361=m.concat([_358,this.Color,name],_357[k]); -this.Color[name]=m.bind.apply(null,_361); -} -var _362=function(){ -for(var i=0;i1){ -var src=MochiKit.DOM.getElement(arguments[0]); -var sig=arguments[1]; -var obj=arguments[2]; -var func=arguments[3]; -for(var i=_3a4.length-1;i>=0;i--){ -var o=_3a4[i]; -if(o.source===src&&o.signal===sig&&o.objOrFunc===obj&&o.funcOrStr===func){ -self._disconnect(o); -if(!self._lock){ -_3a4.splice(i,1); -}else{ -self._dirty=true; -} -return true; -} -} -}else{ -var idx=m.findIdentical(_3a4,_3a2); -if(idx>=0){ -self._disconnect(_3a2); -if(!self._lock){ -_3a4.splice(idx,1); -}else{ -self._dirty=true; -} -return true; -} -} -return false; -},disconnectAllTo:function(_3ad,_3ae){ -var self=MochiKit.Signal; -var _3b0=self._observers; -var _3b1=self._disconnect; -var _3b2=self._lock; -var _3b3=self._dirty; -if(typeof (_3ae)==="undefined"){ -_3ae=null; -} -for(var i=_3b0.length-1;i>=0;i--){ -var _3b5=_3b0[i]; -if(_3b5.objOrFunc===_3ad&&(_3ae===null||_3b5.funcOrStr===_3ae)){ -_3b1(_3b5); -if(_3b2){ -_3b3=true; -}else{ -_3b0.splice(i,1); -} -} -} -self._dirty=_3b3; -},disconnectAll:function(src,sig){ -src=MochiKit.DOM.getElement(src); -var m=MochiKit.Base; -var _3b9=m.flattenArguments(m.extend(null,arguments,1)); -var self=MochiKit.Signal; -var _3bb=self._disconnect; -var _3bc=self._observers; -var i,_3be; -var _3bf=self._lock; -var _3c0=self._dirty; -if(_3b9.length===0){ -for(i=_3bc.length-1;i>=0;i--){ -_3be=_3bc[i]; -if(_3be.source===src){ -_3bb(_3be); -if(!_3bf){ -_3bc.splice(i,1); -}else{ -_3c0=true; -} -} -} -}else{ -var sigs={}; -for(i=0;i<_3b9.length;i++){ -sigs[_3b9[i]]=true; -} -for(i=_3bc.length-1;i>=0;i--){ -_3be=_3bc[i]; -if(_3be.source===src&&_3be.signal in sigs){ -_3bb(_3be); -if(!_3bf){ -_3bc.splice(i,1); -}else{ -_3c0=true; -} -} -} -} -self._dirty=_3c0; -},signal:function(src,sig){ -var self=MochiKit.Signal; -var _3c5=self._observers; -src=MochiKit.DOM.getElement(src); -var args=MochiKit.Base.extend(null,arguments,2); -var _3c7=[]; -self._lock=true; -for(var i=0;i<_3c5.length;i++){ -var _3c9=_3c5[i]; -if(_3c9.source===src&&_3c9.signal===sig){ -try{ -_3c9.listener.apply(src,args); -} -catch(e){ -_3c7.push(e); -} -} -} -self._lock=false; -if(self._dirty){ -self._dirty=false; -for(var i=_3c5.length-1;i>=0;i--){ -if(!_3c5[i].connected){ -_3c5.splice(i,1); -} -} -} -if(_3c7.length==1){ -throw _3c7[0]; -}else{ -if(_3c7.length>1){ -var e=new Error("Multiple errors thrown in handling 'sig', see errors property"); -e.errors=_3c7; -throw e; -} -} -}}); -MochiKit.Signal.EXPORT_OK=[]; -MochiKit.Signal.EXPORT=["connect","disconnect","signal","disconnectAll","disconnectAllTo"]; -MochiKit.Signal.__new__=function(win){ -var m=MochiKit.Base; -this._document=document; -this._window=win; -this._lock=false; -this._dirty=false; -try{ -this.connect(window,"onunload",this._unloadCache); -} -catch(e){ -} -this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; -m.nameFunctions(this); -}; -MochiKit.Signal.__new__(this); -if(MochiKit.__export__){ -connect=MochiKit.Signal.connect; -disconnect=MochiKit.Signal.disconnect; -disconnectAll=MochiKit.Signal.disconnectAll; -signal=MochiKit.Signal.signal; -} -MochiKit.Base._exportSymbols(this,MochiKit.Signal); - - -/*** - - PlotKit.PlotKit 0.9.1 : PACKED VERSION - - THIS FILE IS AUTOMATICALLY GENERATED. If creating patches, please - diff against the source tree, not this file. - - For more information, . - - Copyright (c) 2006. Alastair Tse. - -***/ - -try{ -if(typeof (MochiKit.Base)=="undefined"||typeof (MochiKit.DOM)=="undefined"||typeof (MochiKit.Color)=="undefined"||typeof (MochiKit.Format)=="undefined"){ -throw ""; -} -} -catch(e){ -throw "PlotKit depends on MochiKit.{Base,Color,DOM,Format}"; -} -MochiKit.Base.update(MochiKit.Color.Color.prototype,{asFillColor:function(){ -return this.lighterColorWithLevel(0.3); -},asStrokeColor:function(){ -return this.darkerColorWithLevel(0.1); -},asPointColor:function(){ -return this.lighterColorWithLevel(0.1); -}}); -if(typeof (PlotKit)=="undefined"){ -PlotKit={}; -} -PlotKit.NAME="PlotKit"; -PlotKit.VERSION="0.8"; -PlotKit.__repr__=function(){ -return "["+this.NAME+" "+this.VERSION+"]"; -}; -PlotKit.toString=function(){ -return this.__repr__(); -}; -if(typeof (PlotKit.Base)=="undefined"){ -PlotKit.Base={}; -} -PlotKit.Base.NAME="PlotKit.Base"; -PlotKit.Base.VERSION=PlotKit.VERSION; -PlotKit.Base.__repr__=function(){ -return "["+this.NAME+" "+this.VERSION+"]"; -}; -PlotKit.Base.toString=function(){ -return this.__repr__(); -}; -PlotKit.Base.usingPrototype=function(){ -try{ -return (typeof (Object.extend)=="function"); -} -catch(e){ -return false; -} -}; -MochiKit.Base.update(PlotKit.Base,{roundInterval:function(_1,_2,_3){ -var _4=MochiKit.Format.roundToFixed; -var _5=_1/_2; -return parseFloat(_4(_5,_3)); -},collapse:function(_6){ -var m=MochiKit.Base; -var _8=new Array(); -for(var i=0;i<_6.length;i++){ -_8=m.concat(_8,_6[i]); -} -if(PlotKit.Base.usingPrototype()){ -delete _8.extend; -delete _8.from; -delete _8.inspect; -} -return _8; -},uniq:function(_10){ -var m=MochiKit.Base; -if(!m.isArrayLike(_10)||(_10.length<1)){ -return new Array(); -} -var _11=new Array(); -var _12=_10[0]; -_11.push(_10[0]); -for(var i=1;i<_10.length;i++){ -if(m.compare(_10[i],_12)!=0){ -_12=_10[i]; -_11.push(_10[i]); -} -} -return _11; -},colorScheme:function(){ -var mb=MochiKit.Base; -var mc=MochiKit.Color; -var _15=["red","orange","yellow","green","cyan","blue","purple","magenta"]; -var _16=function(_17){ -return mc.Color[_17+"Color"](); -}; -return mb.map(_16,_15); -},baseDarkPrimaryColors:function(){ -var _18=MochiKit.Color.Color.fromHexString; -return [_18("#ad3f40"),_18("#ddac2c"),_18("#dfdd0c"),_18("#5276c4"),_18("#739c5a")]; -},basePrimaryColors:function(){ -var _19=MochiKit.Color.Color.fromHexString; -return [_19("#d24c4d"),_19("#f2b32f"),_19("#ece90e"),_19("#5d83da"),_19("#78a15d")]; -},baseBlueColors:function(){ -var _20=MochiKit.Color.Color.fromHexString; -return [_20("#4b6b94"),_20("#5d81b4"),_20("#acbad2")]; -},palette:function(_21,_22,_23,_24){ -var _25=MochiKit.Base.isUndefinedOrNull; -var _26=new Array(); -if(_25(_24)){ -_24=0.1; -} -if(_25(_23)){ -_23=0.4; -} -if(_25(_22)){ -_22=-0.2; -} -var _27=_22; -while(_27<=_23){ -_26.push(_27); -_27+=_24; -} -var _28=function(_29,_30){ -return _29.lighterColorWithLevel(_30); -}; -return MochiKit.Base.map(partial(_28,_21),_26); -},excanvasSupported:function(){ -if(/MSIE/.test(navigator.userAgent)&&!window.opera){ -return true; -} -return false; -},findPosX:function(obj){ -var _32=0; -if(obj.offsetParent){ -while(obj.offsetParent){ -_32+=obj.offsetLeft; -obj=obj.offsetParent; -} -}else{ -if(obj.x){ -_32+=obj.x; -} -} -return _32; -},findPosY:function(obj){ -var _33=0; -if(obj.offsetParent){ -while(obj.offsetParent){ -_33+=obj.offsetTop; -obj=obj.offsetParent; -} -}else{ -if(obj.y){ -_33+=obj.y; -} -} -return _33; -},isFuncLike:function(obj){ -return (typeof (obj)=="function"); -}}); -PlotKit.Base.map=function(fn,lst){ -if(PlotKit.Base.usingPrototype()){ -var _36=[]; -for(var x in lst){ -if(typeof (lst[x])=="function"){ -continue; -} -_36.push(fn(lst[x])); -} -return _36; -}else{ -return MochiKit.Base.map(fn,lst); -} -}; -PlotKit.Base.items=function(lst){ -if(PlotKit.Base.usingPrototype()){ -var _38=[]; -for(var x in lst){ -if(typeof (lst[x])=="function"){ -continue; -} -_38.push([x,lst[x]]); -} -return _38; -}else{ -return MochiKit.Base.items(lst); -} -}; -PlotKit.Base.keys=function(lst){ -if(PlotKit.Base.usingPrototype()){ -var _39=[]; -for(var x in lst){ -if(typeof (lst[x])=="function"){ -continue; -} -_39.push(x); -} -return _39; -}else{ -return MochiKit.Base.keys(lst); -} -}; -PlotKit.Base.baseColors=function(){ -var _40=MochiKit.Color.Color.fromHexString; -return [_40("#476fb2"),_40("#be2c2b"),_40("#85b730"),_40("#734a99"),_40("#26a1c5"),_40("#fb8707"),_40("#000000")]; -}; -PlotKit.Base.officeBaseStyle={"axisLineWidth":2,"axisLabelColor":Color.grayColor(),"axisLineColor":Color.whiteColor(),"padding":{top:5,bottom:10,left:30,right:30}}; -MochiKit.Base.update(PlotKit.Base,{officeBlue:function(){ -var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),"backgroundColor":PlotKit.Base.baseColors()[0].lighterColorWithLevel(0.45)}; -MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); -return r; -},officeRed:function(){ -var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[1]),"backgroundColor":PlotKit.Base.baseColors()[1].lighterColorWithLevel(0.5)}; -MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); -return r; -},officeGreen:function(){ -var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[2]),"backgroundColor":PlotKit.Base.baseColors()[2].lighterColorWithLevel(0.5)}; -MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); -return r; -},officePurple:function(){ -var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[3]),"backgroundColor":PlotKit.Base.baseColors()[3].lighterColorWithLevel(0.5)}; -MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); -return r; -},officeCyan:function(){ -var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[4]),"backgroundColor":PlotKit.Base.baseColors()[4].lighterColorWithLevel(0.5)}; -MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); -return r; -},officeOrange:function(){ -var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[5]),"backgroundColor":PlotKit.Base.baseColors()[5].lighterColorWithLevel(0.4)}; -MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); -return r; -},officeBlack:function(){ -var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[6],0,0.6),"backgroundColor":PlotKit.Base.baseColors()[6].lighterColorWithLevel(0.9)}; -MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); -return r; -}}); -PlotKit.Base.EXPORT=["baseColors","collapse","colorScheme","findPosX","findPosY","officeBaseStyle","officeBlue","officeRed","officeGreen","officePurple","officeCyan","officeOrange","officeBlack","roundInterval","uniq","isFuncLike","excanvasSupported"]; -PlotKit.Base.EXPORT_OK=[]; -PlotKit.Base.__new__=function(){ -var m=MochiKit.Base; -m.nameFunctions(this); -this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; -}; -PlotKit.Base.__new__(); -MochiKit.Base._exportSymbols(this,PlotKit.Base); -try{ -if(typeof (PlotKit.Base)=="undefined"){ -throw ""; -} -} -catch(e){ -throw "PlotKit.Layout depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.Base"; -} -if(typeof (PlotKit.Layout)=="undefined"){ -PlotKit.Layout={}; -} -PlotKit.Layout.NAME="PlotKit.Layout"; -PlotKit.Layout.VERSION=PlotKit.VERSION; -PlotKit.Layout.__repr__=function(){ -return "["+this.NAME+" "+this.VERSION+"]"; -}; -PlotKit.Layout.toString=function(){ -return this.__repr__(); -}; -PlotKit.Layout.valid_styles=["bar","line","pie","point"]; -PlotKit.Layout=function(_42,_43){ -this.options={"barWidthFillFraction":0.75,"barOrientation":"vertical","xOriginIsZero":true,"yOriginIsZero":true,"xAxis":null,"yAxis":null,"xTicks":null,"yTicks":null,"xNumberOfTicks":10,"yNumberOfTicks":5,"xTickPrecision":1,"yTickPrecision":1,"pieRadius":0.4}; -this.style=_42; -MochiKit.Base.update(this.options,_43?_43:{}); -if(!MochiKit.Base.isUndefinedOrNull(this.options.xAxis)){ -this.minxval=this.options.xAxis[0]; -this.maxxval=this.options.xAxis[1]; -this.xscale=this.maxxval-this.minxval; -}else{ -this.minxval=0; -this.maxxval=null; -this.xscale=null; -} -if(!MochiKit.Base.isUndefinedOrNull(this.options.yAxis)){ -this.minyval=this.options.yAxis[0]; -this.maxyval=this.options.yAxis[1]; -this.yscale=this.maxyval-this.minyval; -}else{ -this.minyval=0; -this.maxyval=null; -this.yscale=null; -} -this.bars=new Array(); -this.points=new Array(); -this.slices=new Array(); -this.xticks=new Array(); -this.yticks=new Array(); -this.datasets=new Array(); -this.minxdelta=0; -this.xrange=1; -this.yrange=1; -this.hitTestCache={x2maxy:null}; -}; -PlotKit.Layout.prototype.addDataset=function(_44,_45){ -this.datasets[_44]=_45; -}; -PlotKit.Layout.prototype.removeDataset=function(_46,_47){ -delete this.datasets[_46]; -}; -PlotKit.Layout.prototype.addDatasetFromTable=function(_48,_49,_50,_51,_52){ -var _53=MochiKit.Base.isUndefinedOrNull; -var _54=MochiKit.DOM.scrapeText; -var _55=MochiKit.Format.strip; -if(_53(_50)){ -_50=0; -} -if(_53(_51)){ -_51=1; -} -if(_53(_52)){ -_52=-1; -} -var _56=_49.tBodies[0].rows; -var _57=new Array(); -var _58=new Array(); -if(!_53(_56)){ -for(var i=0;i<_56.length;i++){ -_57.push([parseFloat(_55(_54(_56[i].cells[_50]))),parseFloat(_55(_54(_56[i].cells[_51])))]); -if(_52>=0){ -_58.push({v:parseFloat(_55(_54(_56[i].cells[_50]))),label:_55(_54(_56[i].cells[_52]))}); -} -} -this.addDataset(_48,_57); -if(_52>=0){ -this.options.xTicks=_58; -} -return true; -} -return false; -}; -PlotKit.Layout.prototype.evaluate=function(){ -this._evaluateLimits(); -this._evaluateScales(); -if(this.style=="bar"){ -if(this.options.barOrientation=="horizontal"){ -this._evaluateHorizBarCharts(); -}else{ -this._evaluateBarCharts(); -} -this._evaluateBarTicks(); -}else{ -if(this.style=="line"){ -this._evaluateLineCharts(); -this._evaluateLineTicks(); -}else{ -if(this.style=="pie"){ -this._evaluatePieCharts(); -this._evaluatePieTicks(); -} -} -} -}; -PlotKit.Layout.prototype.hitTest=function(x,y){ -var f=MochiKit.Format.twoDigitFloat; -if((this.style=="bar")&&this.bars&&(this.bars.length>0)){ -for(var i=0;i=bar.x)&&(x<=bar.x+bar.w)&&(y>=bar.y)&&(y-bar.y<=bar.h)){ -return bar; -} -} -}else{ -if(this.style=="line"){ -if(this.hitTestCache.x2maxy==null){ -this._regenerateHitTestCache(); -} -var _62=x/this.xscale; -var _63=this.hitTestCache.xvalues; -var _64=null; -var _65=null; -for(var i=1;i<_63.length;i++){ -if(_63[i]>_62){ -_64=_63[i-1]; -_65=_63[i]; -break; -} -} -if((_64!=null)){ -var _66=this.hitTestCache.x2maxy[_64]; -var _67=this.hitTestCache.x2maxy[_65]; -var _68=(1-y)/this.yscale; -var _69=(_67-_66)/(_65-_64); -var _70=_66+_69*(_62-_64); -if(_70>=_68){ -var obj={xval:_62,yval:_68,xafter:_65,yafter:_67,xbefore:_64,ybefore:_66,yprojected:_70}; -return obj; -} -} -}else{ -if(this.style=="pie"){ -var _71=Math.sqrt((y-0.5)*(y-0.5)+(x-0.5)*(x-0.5)); -if(_71>this.options.pieRadius){ -return null; -} -var _72=Math.atan2(y-0.5,x-0.5)-Math.PI/2; -for(var i=0;i=_72){ -return _73; -} -} -} -} -} -return null; -}; -PlotKit.Layout.prototype.rectForX=function(x){ -return null; -}; -PlotKit.Layout.prototype.angleRangeForX=function(x){ -return null; -}; -PlotKit.Layout.prototype._evaluateLimits=function(){ -var map=PlotKit.Base.map; -var _75=PlotKit.Base.items; -var _76=MochiKit.Base.itemgetter; -var _77=PlotKit.Base.collapse; -var _78=MochiKit.Base.listMin; -var _79=MochiKit.Base.listMax; -var _80=MochiKit.Base.isUndefinedOrNull; -var all=_77(map(_76(1),_75(this.datasets))); -if(_80(this.options.xAxis)){ -if(this.options.xOriginIsZero){ -this.minxval=0; -}else{ -this.minxval=_78(map(parseFloat,map(_76(0),all))); -} -this.maxxval=_79(map(parseFloat,map(_76(0),all))); -}else{ -this.minxval=this.options.xAxis[0]; -this.maxxval=this.options.xAxis[1]; -this.xscale=this.maxval-this.minxval; -} -if(_80(this.options.yAxis)){ -if(this.options.yOriginIsZero){ -this.minyval=0; -}else{ -this.minyval=_78(map(parseFloat,map(_76(1),all))); -} -this.maxyval=_79(map(parseFloat,map(_76(1),all))); -}else{ -this.minyval=this.options.yAxis[0]; -this.maxyval=this.options.yAxis[1]; -this.yscale=this.maxyval-this.minyval; -} -}; -PlotKit.Layout.prototype._evaluateScales=function(){ -var _82=MochiKit.Base.isUndefinedOrNull; -this.xrange=this.maxxval-this.minxval; -if(this.xrange==0){ -this.xscale=1; -}else{ -this.xscale=1/this.xrange; -} -this.yrange=this.maxyval-this.minyval; -if(this.yrange==0){ -this.yscale=1; -}else{ -this.yscale=1/this.yrange; -} -}; -PlotKit.Layout.prototype._uniqueXValues=function(){ -var _83=PlotKit.Base.collapse; -var map=PlotKit.Base.map; -var _84=PlotKit.Base.uniq; -var _85=MochiKit.Base.itemgetter; -var _86=PlotKit.Base.items; -var _87=map(parseFloat,map(_85(0),_83(map(_85(1),_86(this.datasets))))); -_87.sort(MochiKit.Base.compare); -return _84(_87); -}; -PlotKit.Layout.prototype._evaluateBarCharts=function(){ -var _88=PlotKit.Base.items; -var _89=_88(this.datasets).length; -var _90=10000000; -var _91=this._uniqueXValues(); -for(var i=1;i<_91.length;i++){ -_90=Math.min(Math.abs(_91[i]-_91[i-1]),_90); -} -var _92=0; -var _93=0; -var _94=0; -if(_91.length==1){ -_90=1; -this.xscale=1; -this.minxval=_91[0]; -_92=1*this.options.barWidthFillFraction; -_93=_92/_89; -_94=(1-this.options.barWidthFillFraction)/2; -}else{ -if(this.xrange==1){ -this.xscale=0.5; -}else{ -if(this.xrange==2){ -this.xscale=1/3; -}else{ -this.xscale=(1-_90/this.xrange)/this.xrange; -} -} -_92=_90*this.xscale*this.options.barWidthFillFraction; -_93=_92/_89; -_94=_90*this.xscale*(1-this.options.barWidthFillFraction)/2; -} -this.minxdelta=_90; -this.bars=new Array(); -var i=0; -for(var _95 in this.datasets){ -var _96=this.datasets[_95]; -if(PlotKit.Base.isFuncLike(_96)){ -continue; -} -for(var j=0;j<_96.length;j++){ -var _98=_96[j]; -var _99={x:((parseFloat(_98[0])-this.minxval)*this.xscale)+(i*_93)+_94,y:1-((parseFloat(_98[1])-this.minyval)*this.yscale),w:_93,h:((parseFloat(_98[1])-this.minyval)*this.yscale),xval:parseFloat(_98[0]),yval:parseFloat(_98[1]),name:_95}; -if((_99.x>=0)&&(_99.x<=1)&&(_99.y>=0)&&(_99.y<=1)){ -this.bars.push(_99); -} -} -i++; -} -}; -PlotKit.Layout.prototype._evaluateHorizBarCharts=function(){ -var _100=PlotKit.Base.items; -var _101=_100(this.datasets).length; -var _102=10000000; -var _103=this._uniqueXValues(); -for(var i=1;i<_103.length;i++){ -_102=Math.min(Math.abs(_103[i]-_103[i-1]),_102); -} -var _104=0; -var _105=0; -var _106=0; -if(_103.length==1){ -_102=1; -this.xscale=1; -this.minxval=_103[0]; -_104=1*this.options.barWidthFillFraction; -_105=_104/_101; -_106=(1-this.options.barWidthFillFraction)/2; -}else{ -this.xscale=(1-_102/this.xrange)/this.xrange; -_104=_102*this.xscale*this.options.barWidthFillFraction; -_105=_104/_101; -_106=_102*this.xscale*(1-this.options.barWidthFillFraction)/2; -} -this.minxdelta=_102; -this.bars=new Array(); -var i=0; -for(var _107 in this.datasets){ -var _108=this.datasets[_107]; -if(PlotKit.Base.isFuncLike(_108)){ -continue; -} -for(var j=0;j<_108.length;j++){ -var item=_108[j]; -var rect={y:((parseFloat(item[0])-this.minxval)*this.xscale)+(i*_105)+_106,x:0,h:_105,w:((parseFloat(item[1])-this.minyval)*this.yscale),xval:parseFloat(item[0]),yval:parseFloat(item[1]),name:_107}; -if(rect.y<=0){ -rect.y=0; -} -if(rect.y>=1){ -rect.y=1; -} -if((rect.x>=0)&&(rect.x<=1)){ -this.bars.push(rect); -} -} -i++; -} -}; -PlotKit.Layout.prototype._evaluateLineCharts=function(){ -var _111=PlotKit.Base.items; -var _112=_111(this.datasets).length; -this.points=new Array(); -var i=0; -for(var _113 in this.datasets){ -var _114=this.datasets[_113]; -if(PlotKit.Base.isFuncLike(_114)){ -continue; -} -_114.sort(function(a,b){ -return compare(parseFloat(a[0]),parseFloat(b[0])); -}); -for(var j=0;j<_114.length;j++){ -var item=_114[j]; -var _117={x:((parseFloat(item[0])-this.minxval)*this.xscale),y:1-((parseFloat(item[1])-this.minyval)*this.yscale),xval:parseFloat(item[0]),yval:parseFloat(item[1]),name:_113}; -if(_117.y<=0){ -_117.y=0; -} -if(_117.y>=1){ -_117.y=1; -} -if((_117.x>=0)&&(_117.x<=1)){ -this.points.push(_117); -} -} -i++; -} -}; -PlotKit.Layout.prototype._evaluatePieCharts=function(){ -var _118=PlotKit.Base.items; -var sum=MochiKit.Iter.sum; -var _120=MochiKit.Base.itemgetter; -var _121=_118(this.datasets).length; -var _122=_118(this.datasets)[0][1]; -var _123=sum(map(_120(1),_122)); -this.slices=new Array(); -var _124=0; -for(var i=0;i<_122.length;i++){ -var _125=_122[i][1]/_123; -var _126=_124*Math.PI*2; -var _127=(_124+_125)*Math.PI*2; -var _128={fraction:_125,xval:_122[i][0],yval:_122[i][1],startAngle:_126,endAngle:_127}; -if(_122[i][1]!=0){ -this.slices.push(_128); -} -_124+=_125; -} -}; -PlotKit.Layout.prototype._evaluateLineTicksForXAxis=function(){ -var _129=MochiKit.Base.isUndefinedOrNull; -if(this.options.xTicks){ -this.xticks=new Array(); -var _130=function(tick){ -var _132=tick.label; -if(_129(_132)){ -_132=tick.v.toString(); -} -var pos=this.xscale*(tick.v-this.minxval); -if((pos>=0)&&(pos<=1)){ -this.xticks.push([pos,_132]); -} -}; -MochiKit.Iter.forEach(this.options.xTicks,bind(_130,this)); -}else{ -if(this.options.xNumberOfTicks){ -var _134=this._uniqueXValues(); -var _135=this.xrange/this.options.xNumberOfTicks; -var _136=0; -this.xticks=new Array(); -for(var i=0;i<=_134.length;i++){ -if((_134[i]-this.minxval)>=(_136*_135)){ -var pos=this.xscale*(_134[i]-this.minxval); -if((pos>1)||(pos<0)){ -continue; -} -this.xticks.push([pos,_134[i]]); -_136++; -} -if(_136>this.options.xNumberOfTicks){ -break; -} -} -} -} -}; -PlotKit.Layout.prototype._evaluateLineTicksForYAxis=function(){ -var _137=MochiKit.Base.isUndefinedOrNull; -if(this.options.yTicks){ -this.yticks=new Array(); -var _138=function(tick){ -var _139=tick.label; -if(_137(_139)){ -_139=tick.v.toString(); -} -var pos=1-(this.yscale*(tick.v-this.minyval)); -if((pos>=0)&&(pos<=1)){ -this.yticks.push([pos,_139]); -} -}; -MochiKit.Iter.forEach(this.options.yTicks,bind(_138,this)); -}else{ -if(this.options.yNumberOfTicks){ -this.yticks=new Array(); -var _140=PlotKit.Base.roundInterval; -var prec=this.options.yTickPrecision; -var _142=_140(this.yrange,this.options.yNumberOfTicks,prec); -for(var i=0;i<=this.options.yNumberOfTicks;i++){ -var yval=this.minyval+(i*_142); -var pos=1-((yval-this.minyval)*this.yscale); -if((pos>1)||(pos<0)){ -continue; -} -this.yticks.push([pos,MochiKit.Format.roundToFixed(yval,prec)]); -} -} -} -}; -PlotKit.Layout.prototype._evaluateLineTicks=function(){ -this._evaluateLineTicksForXAxis(); -this._evaluateLineTicksForYAxis(); -}; -PlotKit.Layout.prototype._evaluateBarTicks=function(){ -this._evaluateLineTicks(); -var _144=function(tick){ -return [tick[0]+(this.minxdelta*this.xscale)/2,tick[1]]; -}; -this.xticks=MochiKit.Base.map(bind(_144,this),this.xticks); -if(this.options.barOrientation=="horizontal"){ -var _145=this.xticks; -this.xticks=this.yticks; -this.yticks=_145; -var _146=function(tick){ -return [1-tick[0],tick[1]]; -}; -this.xticks=MochiKit.Base.map(_146,this.xticks); -} -}; -PlotKit.Layout.prototype._evaluatePieTicks=function(){ -var _147=MochiKit.Base.isUndefinedOrNull; -var _148=MochiKit.Format.numberFormatter("#%"); -this.xticks=new Array(); -if(this.options.xTicks){ -var _149=new Array(); -for(var i=0;i0){ -this.__init__(_158,_159,_160); -} -}; -PlotKit.CanvasRenderer.prototype.__init__=function(_161,_162,_163){ -var _164=MochiKit.Base.isUndefinedOrNull; -var _165=MochiKit.Color.Color; -this.options={"drawBackground":true,"backgroundColor":_165.whiteColor(),"padding":{left:30,right:30,top:5,bottom:10},"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),"strokeColor":_165.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":_165.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":_165.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"pieRadius":0.4,"enableEvents":true}; -MochiKit.Base.update(this.options,_163?_163:{}); -this.layout=_162; -this.element=MochiKit.DOM.getElement(_161); -this.container=this.element.parentNode; -this.isIE=PlotKit.Base.excanvasSupported(); -if(this.isIE&&!_164(G_vmlCanvasManager)){ -this.IEDelay=0.5; -this.maxTries=5; -this.renderDelay=null; -this.clearDelay=null; -this.element=G_vmlCanvasManager.initElement(this.element); -} -this.height=this.element.height; -this.width=this.element.width; -if(_164(this.element)){ -throw "CanvasRenderer() - passed canvas is not found"; -} -if(!this.isIE&&!(PlotKit.CanvasRenderer.isSupported(this.element))){ -throw "CanvasRenderer() - Canvas is not supported."; -} -if(_164(this.container)||(this.container.nodeName.toLowerCase()!="div")){ -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}; -MochiKit.DOM.updateNodeAttributes(this.container,{"style":{"position":"relative","width":this.width+"px"}}); -}; -PlotKit.CanvasRenderer.prototype.render=function(){ -if(this.isIE){ -try{ -if(this.renderDelay){ -this.renderDelay.cancel(); -this.renderDelay=null; -} -var _166=this.element.getContext("2d"); -} -catch(e){ -this.isFirstRender=false; -if(this.maxTries-->0){ -this.renderDelay=MochiKit.Async.wait(this.IEDelay); -this.renderDelay.addCallback(bind(this.render,this)); -} -return; -} -} -if(this.options.drawBackground){ -this._renderBackground(); -} -if(this.layout.style=="bar"){ -this._renderBarChart(); -this._renderBarAxis(); -}else{ -if(this.layout.style=="pie"){ -this._renderPieChart(); -this._renderPieAxis(); -}else{ -if(this.layout.style=="line"){ -this._renderLineChart(); -this._renderLineAxis(); -} -} -} -}; -PlotKit.CanvasRenderer.prototype._renderBarChartWrap=function(data,_168){ -var _169=this.element.getContext("2d"); -var _170=this.options.colorScheme.length; -var _171=this.options.colorScheme; -var _172=MochiKit.Base.keys(this.layout.datasets); -var _173=_172.length; -for(var i=0;i<_173;i++){ -var _174=_172[i]; -var _175=_171[i%_170]; -_169.save(); -_169.fillStyle=_175.toRGBString(); -if(this.options.strokeColor){ -_169.strokeStyle=this.options.strokeColor.toRGBString(); -}else{ -if(this.options.strokeColorTransform){ -_169.strokeStyle=_175[this.options.strokeColorTransform]().toRGBString(); -} -} -_169.lineWidth=this.options.strokeWidth; -var _176=function(obj){ -if(obj.name==_174){ -_168(_169,obj); -} -}; -MochiKit.Iter.forEach(data,bind(_176,this)); -_169.restore(); -} -}; -PlotKit.CanvasRenderer.prototype._renderBarChart=function(){ -var bind=MochiKit.Base.bind; -var _178=function(_179,bar){ -var x=this.area.w*bar.x+this.area.x; -var y=this.area.h*bar.y+this.area.y; -var w=this.area.w*bar.w; -var h=this.area.h*bar.h; -if((w<1)||(h<1)){ -return; -} -if(this.options.shouldFill){ -_179.fillRect(x,y,w,h); -} -if(this.options.shouldStroke){ -_179.strokeRect(x,y,w,h); -} -}; -this._renderBarChartWrap(this.layout.bars,bind(_178,this)); -}; -PlotKit.CanvasRenderer.prototype._renderLineChart=function(){ -var _182=this.element.getContext("2d"); -var _183=this.options.colorScheme.length; -var _184=this.options.colorScheme; -var _185=MochiKit.Base.keys(this.layout.datasets); -var _186=_185.length; -var bind=MochiKit.Base.bind; -var _187=MochiKit.Base.partial; -for(var i=0;i<_186;i++){ -var _188=_185[i]; -var _189=_184[i%_183]; -var _190=this.options.strokeColorTransform; -_182.save(); -_182.fillStyle=_189.toRGBString(); -if(this.options.strokeColor){ -_182.strokeStyle=this.options.strokeColor.toRGBString(); -}else{ -if(this.options.strokeColorTransform){ -_182.strokeStyle=_189[_190]().toRGBString(); -} -} -_182.lineWidth=this.options.strokeWidth; -var _191=function(ctx){ -ctx.beginPath(); -ctx.moveTo(this.area.x,this.area.y+this.area.h); -var _193=function(ctx_,_195){ -if(_195.name==_188){ -ctx_.lineTo(this.area.w*_195.x+this.area.x,this.area.h*_195.y+this.area.y); -} -}; -MochiKit.Iter.forEach(this.layout.points,_187(_193,ctx),this); -ctx.lineTo(this.area.w+this.area.x,this.area.h+this.area.y); -ctx.lineTo(this.area.x,this.area.y+this.area.h); -ctx.closePath(); -}; -if(this.options.shouldFill){ -bind(_191,this)(_182); -_182.fill(); -} -if(this.options.shouldStroke){ -bind(_191,this)(_182); -_182.stroke(); -} -_182.restore(); } -}; -PlotKit.CanvasRenderer.prototype._renderPieChart=function(){ -var _196=this.element.getContext("2d"); -var _197=this.options.colorScheme.length; -var _198=this.layout.slices; -var _199=this.area.x+this.area.w*0.5; -var _200=this.area.y+this.area.h*0.5; -var _201=Math.min(this.area.w*this.options.pieRadius,this.area.h*this.options.pieRadius); -if(this.isIE){ -_199=parseInt(_199); -_200=parseInt(_200); -_201=parseInt(_201); -} -for(var i=0;i<_198.length;i++){ -var _202=this.options.colorScheme[i%_197]; -_196.save(); -_196.fillStyle=_202.toRGBString(); -var _203=function(){ -_196.beginPath(); -_196.moveTo(_199,_200); -_196.arc(_199,_200,_201,_198[i].startAngle-Math.PI/2,_198[i].endAngle-Math.PI/2,false); -_196.lineTo(_199,_200); -_196.closePath(); -}; -if(Math.abs(_198[i].startAngle-_198[i].endAngle)>0.001){ -if(this.options.shouldFill){ -_203(); -_196.fill(); -} -if(this.options.shouldStroke){ -_203(); -_196.lineWidth=this.options.strokeWidth; -if(this.options.strokeColor){ -_196.strokeStyle=this.options.strokeColor.toRGBString(); -}else{ -if(this.options.strokeColorTransform){ -_196.strokeStyle=_202[this.options.strokeColorTransform]().toRGBString(); -} -} -_196.stroke(); -} -} -_196.restore(); -} -}; -PlotKit.CanvasRenderer.prototype._renderBarAxis=function(){ -this._renderAxis(); -}; -PlotKit.CanvasRenderer.prototype._renderLineAxis=function(){ -this._renderAxis(); -}; -PlotKit.CanvasRenderer.prototype._renderAxis=function(){ -if(!this.options.drawXAxis&&!this.options.drawYAxis){ -return; -} -var _204=this.element.getContext("2d"); -var _205={"style":{"position":"absolute","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor.toRGBString(),"width":this.options.axisLabelWidth+"px","overflow":"hidden"}}; -_204.save(); -_204.strokeStyle=this.options.axisLineColor.toRGBString(); -_204.lineWidth=this.options.axisLineWidth; -if(this.options.drawYAxis){ -if(this.layout.yticks){ -var _206=function(tick){ -if(typeof (tick)=="function"){ -return; -} -var x=this.area.x; -var y=this.area.y+tick[0]*this.area.h; -_204.beginPath(); -_204.moveTo(x,y); -_204.lineTo(x-this.options.axisTickSize,y); -_204.closePath(); -_204.stroke(); -var _207=DIV(_205,tick[1]); -_207.style.top=(y-this.options.axisLabelFontSize)+"px"; -_207.style.left=(x-this.options.padding.left-this.options.axisTickSize)+"px"; -_207.style.textAlign="right"; -_207.style.width=(this.options.padding.left-this.options.axisTickSize*2)+"px"; -MochiKit.DOM.appendChildNodes(this.container,_207); -this.ylabels.push(_207); -}; -MochiKit.Iter.forEach(this.layout.yticks,bind(_206,this)); -} -_204.beginPath(); -_204.moveTo(this.area.x,this.area.y); -_204.lineTo(this.area.x,this.area.y+this.area.h); -_204.closePath(); -_204.stroke(); -} -if(this.options.drawXAxis){ -if(this.layout.xticks){ -var _206=function(tick){ -if(typeof (dataset)=="function"){ -return; -} -var x=this.area.x+tick[0]*this.area.w; -var y=this.area.y+this.area.h; -_204.beginPath(); -_204.moveTo(x,y); -_204.lineTo(x,y+this.options.axisTickSize); -_204.closePath(); -_204.stroke(); -var _208=DIV(_205,tick[1]); -_208.style.top=(y+this.options.axisTickSize)+"px"; -_208.style.left=(x-this.options.axisLabelWidth/2)+"px"; -_208.style.textAlign="center"; -_208.style.width=this.options.axisLabelWidth+"px"; -MochiKit.DOM.appendChildNodes(this.container,_208); -this.xlabels.push(_208); -}; -MochiKit.Iter.forEach(this.layout.xticks,bind(_206,this)); -} -_204.beginPath(); -_204.moveTo(this.area.x,this.area.y+this.area.h); -_204.lineTo(this.area.x+this.area.w,this.area.y+this.area.h); -_204.closePath(); -_204.stroke(); -} -_204.restore(); -}; -PlotKit.CanvasRenderer.prototype._renderPieAxis=function(){ -if(!this.options.drawXAxis){ -return; -} -if(this.layout.xticks){ -var _209=new Array(); -for(var i=0;iMath.PI*2){ -_216=_216-Math.PI*2; -}else{ -if(_216<0){ -_216=_216+Math.PI*2; -} -} -var _217=_210+Math.sin(_216)*(_212+10); -var _218=_211-Math.cos(_216)*(_212+10); -var _219={"position":"absolute","zIndex":11,"width":_213+"px","fontSize":this.options.axisLabelFontSize+"px","overflow":"hidden","color":this.options.axisLabelColor.toHexString()}; -if(_216<=Math.PI*0.5){ -_219["textAlign"]="left"; -_219["verticalAlign"]="top"; -_219["left"]=_217+"px"; -_219["top"]=(_218-this.options.axisLabelFontSize)+"px"; -}else{ -if((_216>Math.PI*0.5)&&(_216<=Math.PI)){ -_219["textAlign"]="left"; -_219["verticalAlign"]="bottom"; -_219["left"]=_217+"px"; -_219["top"]=_218+"px"; -}else{ -if((_216>Math.PI)&&(_216<=Math.PI*1.5)){ -_219["textAlign"]="right"; -_219["verticalAlign"]="bottom"; -_219["left"]=(_217-_213)+"px"; -_219["top"]=_218+"px"; -}else{ -_219["textAlign"]="right"; -_219["verticalAlign"]="bottom"; -_219["left"]=(_217-_213)+"px"; -_219["top"]=(_218-this.options.axisLabelFontSize)+"px"; -} -} -} -var _220=DIV({"style":_219},this.layout.xticks[i][1]); -this.xlabels.push(_220); -MochiKit.DOM.appendChildNodes(this.container,_220); -} -} -}; -PlotKit.CanvasRenderer.prototype._renderBackground=function(){ -var _221=this.element.getContext("2d"); -_221.save(); -_221.fillStyle=this.options.backgroundColor.toRGBString(); -_221.fillRect(0,0,this.width,this.height); -_221.restore(); -}; -PlotKit.CanvasRenderer.prototype.clear=function(){ -if(this.isIE){ -try{ -if(this.clearDelay){ -this.clearDelay.cancel(); -this.clearDelay=null; -} -var _222=this.element.getContext("2d"); -} -catch(e){ -this.isFirstRender=false; -this.clearDelay=MochiKit.Async.wait(this.IEDelay); -this.clearDelay.addCallback(bind(this.clear,this)); -return; -} -} -var _222=this.element.getContext("2d"); -_222.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 _223=MochiKit.Signal.connect; -var bind=MochiKit.Base.bind; -_223(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 _225=this.layout.hitTest(x,y); -if(_225){ -return _225; -} -return null; -}; -PlotKit.CanvasRenderer.prototype._createEventObject=function(_226,e){ -if(_226==null){ -return null; -} -e.chart=_226; -return e; -}; -PlotKit.CanvasRenderer.prototype.onclick=function(e){ -var _227=this._resolveObject(e); -var _228=this._createEventObject(_227,e); -if(_228!=null){ -MochiKit.Signal.signal(this,"onclick",_228); -} -}; -PlotKit.CanvasRenderer.prototype.onmouseover=function(e){ -var _229=this._resolveObject(e); -var _230=this._createEventObject(_229,e); -if(_230!=null){ -signal(this,"onmouseover",_230); -} -}; -PlotKit.CanvasRenderer.prototype.onmouseout=function(e){ -var _231=this._resolveObject(e); -var _232=this._createEventObject(_231,e); -if(_232==null){ -signal(this,"onmouseout",e); -}else{ -signal(this,"onmouseout",_232); -} -}; -PlotKit.CanvasRenderer.prototype.onmousemove=function(e){ -var _233=this._resolveObject(e); -var _234=this._createEventObject(_233,e); -if((_233==null)&&(this.event_isinside==null)){ -return; -} -if((_233!=null)&&(this.event_isinside==null)){ -signal(this,"onmouseover",_234); -} -if((_233==null)&&(this.event_isinside!=null)){ -signal(this,"onmouseout",_234); -} -if((_233!=null)&&(this.event_isinside!=null)){ -signal(this,"onmousemove",_234); -} -this.event_isinside=_233; -}; -PlotKit.CanvasRenderer.isSupported=function(_235){ -var _236=null; -try{ -if(MochiKit.Base.isUndefinedOrNull(_235)){ -_236=MochiKit.DOM.CANVAS({}); -}else{ -_236=MochiKit.DOM.getElement(_235); -} -var _237=_236.getContext("2d"); -} -catch(e){ -var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); -var _239=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); -if((!ie)||(ie[1]<6)||(_239)){ -return false; -} -return true; -} -return true; -}; -PlotKit.Canvas={}; -PlotKit.Canvas.CanvasRenderer=PlotKit.CanvasRenderer; -PlotKit.Canvas.EXPORT=["CanvasRenderer"]; -PlotKit.Canvas.EXPORT_OK=["CanvasRenderer"]; -PlotKit.Canvas.__new__=function(){ -var m=MochiKit.Base; -m.nameFunctions(this); -this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; -}; -PlotKit.Canvas.__new__(); -MochiKit.Base._exportSymbols(this,PlotKit.Canvas); - - -// Copyright 2006 Dan Vanderkam (danvdk@gmail.com) -// All Rights Reserved. - -/** - * @fileoverview Subclasses various parts of PlotKit to meet the additional - * needs of DateGraph: grid overlays and error bars - */ - -// Subclass PlotKit.Layout to add: -// 1. Sigma/errorBars properties -// 2. Copy error terms for PlotKit.CanvasRenderer._renderLineChart - -/** - * Creates a new DateGraphLayout object. Options are the same as those allowed - * by the PlotKit.Layout constructor. - * @param {Object} options Options for PlotKit.Layout - * @return {Object} The DateGraphLayout object - */ -DateGraphLayout = function(options) { - PlotKit.Layout.call(this, "line", options); -}; -DateGraphLayout.prototype = new PlotKit.Layout(); - -/** - * Behaves the same way as PlotKit.Layout, but also copies the errors - * @private - */ -DateGraphLayout.prototype.evaluateWithError = function() { - this.evaluate(); - if (!this.options.errorBars) return; - - // Copy over the error terms - var i = 0; // index in this.points - for (var setName in this.datasets) { - var j = 0; - var dataset = this.datasets[setName]; - if (PlotKit.Base.isFuncLike(dataset)) continue; - for (var j = 0; j < dataset.length; j++, i++) { - var item = dataset[j]; - var xv = parseFloat(item[0]); - var yv = parseFloat(item[1]); - - if (xv == this.points[i].xval && - yv == this.points[i].yval) { - this.points[i].errorMinus = parseFloat(item[2]); - this.points[i].errorPlus = parseFloat(item[3]); - } - } - } -}; - -/** - * Convenience function to remove all the data sets from a graph - */ -DateGraphLayout.prototype.removeAllDatasets = function() { - delete this.datasets; - this.datasets = new Array(); -}; - -/** - * Change the values of various layout options - * @param {Object} new_options an associative array of new properties - */ -DateGraphLayout.prototype.updateOptions = function(new_options) { - MochiKit.Base.update(this.options, new_options ? new_options : {}); -}; - -// Subclass PlotKit.CanvasRenderer to add: -// 1. X/Y grid overlay -// 2. Ability to draw error bars (if required) - -/** - * Sets some PlotKit.CanvasRenderer options - * @param {Object} element The canvas to attach to - * @param {Layout} layout The DateGraphLayout object for this graph. - * @param {Object} options Options to pass on to CanvasRenderer - */ -DateGraphCanvasRenderer = function(element, layout, options) { - PlotKit.CanvasRenderer.call(this, element, layout, options); - this.options.shouldFill = false; - this.options.shouldStroke = true; - this.options.drawYGrid = true; - this.options.drawXGrid = true; - this.options.gridLineColor = MochiKit.Color.Color.grayColor(); - MochiKit.Base.update(this.options, options); - - // TODO(danvk) This shouldn't be necessary: effects should be overlaid - this.options.drawBackground = false; -}; -DateGraphCanvasRenderer.prototype = new PlotKit.CanvasRenderer(); - -/** - * Draw an X/Y grid on top of the existing plot - */ -DateGraphCanvasRenderer.prototype.render = function() { - // Do the ordinary rendering, as before - // TODO(danvk) Call super.render() - this._renderLineChart(); - this._renderLineAxis(); - - // Draw the new X/Y grid - var ctx = this.element.getContext("2d"); - if (this.options.drawYGrid) { - var ticks = this.layout.yticks; - ctx.save(); - ctx.strokeStyle = this.options.gridLineColor.toRGBString(); - ctx.lineWidth = this.options.axisLineWidth; - for (var i = 0; i < ticks.length; i++) { - var x = this.area.x; - var y = this.area.y + ticks[i][0] * this.area.h; - ctx.beginPath(); - ctx.moveTo(x, y); - ctx.lineTo(x + this.area.w, y); - ctx.closePath(); - ctx.stroke(); - } - } - - if (this.options.drawXGrid) { - var ticks = this.layout.xticks; - ctx.save(); - ctx.strokeStyle = this.options.gridLineColor.toRGBString(); - ctx.lineWidth = this.options.axisLineWidth; - for (var i=0; i= 0) { - ctx_.moveTo(prevX, prevYs[0]); - ctx_.lineTo(point.canvasx, newYs[0]); - ctx_.lineTo(point.canvasx, newYs[1]); - ctx_.lineTo(prevX, prevYs[1]); - ctx_.closePath(); - } - prevYs[0] = newYs[0]; - prevYs[1] = newYs[1]; - prevX = point.canvasx; - } - }; - // should be same color as the lines - var err_color = color.colorWithAlpha(0.15); - ctx.fillStyle = err_color.toRGBString(); - ctx.beginPath(); - MochiKit.Iter.forEach(this.layout.points, partial(errorTrapezoid, ctx), this); - ctx.fill(); - } - }; - if (errorBars) - bind(makeErrorBars, this)(context); - bind(makePath, this)(context); - context.restore(); -}; -// Copyright 2006 Dan Vanderkam (danvdk@gmail.com) -// All Rights Reserved. - -/** - * @fileoverview Creates an interactive, zoomable graph based on a CSV file or - * string. DateGraph can handle multiple series with or without error bars. The - * date/value ranges will be automatically set. DateGraph uses the - * <canvas> tag, so it only works in FF1.5+. - * @author danvdk@gmail.com (Dan Vanderkam) - - Usage: -
- - - The CSV file is of the form - - YYYYMMDD,A1,B1,C1 - YYYYMMDD,A2,B2,C2 - - If null is passed as the third parameter (series names), then the first line - of the CSV file is assumed to contain names for each series. - - If the 'errorBars' option is set in the constructor, the input should be of - the form - - YYYYMMDD,A1,sigmaA1,B1,sigmaB1,... - YYYYMMDD,A2,sigmaA2,B2,sigmaB2,... - - If the 'fractions' option is set, the input should be of the form: - - YYYYMMDD,A1/B1,A2/B2,... - YYYYMMDD,A1/B1,A2/B2,... - - And error bars will be calculated automatically using a binomial distribution. - - For further documentation and examples, see http://www/~danvk/dg/ - - */ - -/** - * An interactive, zoomable graph - * @param {String | Function} file A file containing CSV data or a function that - * returns this data. The expected format for each line is - * YYYYMMDD,val1,val2,... or, if attrs.errorBars is set, - * YYYYMMDD,val1,stddev1,val2,stddev2,... - * @param {Array.} labels Labels for the data series - * @param {Object} attrs Various other attributes, e.g. errorBars determines - * whether the input data contains error ranges. - */ -DateGraph = function(div, file, labels, attrs) { - if (arguments.length > 0) - this.__init__(div, file, labels, attrs); -}; - -DateGraph.NAME = "DateGraph"; -DateGraph.VERSION = "1.1"; -DateGraph.__repr__ = function() { - return "[" + this.NAME + " " + this.VERSION + "]"; -}; -DateGraph.toString = function() { - return this.__repr__(); -}; - -// Various default values -DateGraph.DEFAULT_ROLL_PERIOD = 1; -DateGraph.DEFAULT_WIDTH = 480; -DateGraph.DEFAULT_HEIGHT = 320; -DateGraph.DEFAULT_STROKE_WIDTH = 1.0; -DateGraph.AXIS_LINE_WIDTH = 0.3; - -/** - * Initializes the DateGraph. This creates a new DIV and constructs the PlotKit - * and interaction <canvas> inside of it. See the constructor for details - * on the parameters. - * @param {String | Function} file Source data - * @param {Array.} labels Names of the data series - * @param {Object} attrs Miscellaneous other options - * @private - */ -DateGraph.prototype.__init__ = function(div, file, labels, attrs) { - // Copy the important bits into the object - this.maindiv_ = div; - this.labels_ = labels; - this.file_ = file; - this.rollPeriod_ = attrs.rollPeriod || DateGraph.DEFAULT_ROLL_PERIOD; - this.previousVerticalX_ = -1; - this.width_ = parseInt(div.style.width, 10); - this.height_ = parseInt(div.style.height, 10); - this.errorBars_ = attrs.errorBars || false; - this.fractions_ = attrs.fractions || false; - this.strokeWidth_ = attrs.strokeWidth || DateGraph.DEFAULT_STROKE_WIDTH; - this.dateWindow_ = attrs.dateWindow || null; - this.valueRange_ = attrs.valueRange || null; - this.labelsSeparateLines = attrs.labelsSeparateLines || false; - this.labelsDiv_ = attrs.labelsDiv || null; - this.labelsKMB_ = attrs.labelsKMB || false; - this.minTickSize_ = attrs.minTickSize || 0; - this.xValueParser_ = attrs.xValueParser || DateGraph.prototype.dateParser; - this.xValueFormatter_ = attrs.xValueFormatter || - DateGraph.prototype.dateString_; - this.xTicker_ = attrs.xTicker || DateGraph.prototype.dateTicker; - this.sigma_ = attrs.sigma || 2.0; - this.wilsonInterval_ = attrs.wilsonInterval || true; - this.customBars_ = attrs.customBars || false; - this.attrs_ = attrs; - - // Make a note of whether labels will be pulled from the CSV file. - this.labelsFromCSV_ = (this.labels_ == null); - if (this.labels_ == null) - this.labels_ = []; - - // Prototype of the callback is "void clickCallback(event, date)" - this.clickCallback_ = attrs.clickCallback || null; - - // Prototype of zoom callback is "void dragCallback(minDate, maxDate)" - this.zoomCallback_ = attrs.zoomCallback || null; - - // Create the containing DIV and other interactive elements - this.createInterface_(); - - // Create the PlotKit grapher - this.layoutOptions_ = { 'errorBars': (this.errorBars_ || this.customBars_), - 'xOriginIsZero': false }; - MochiKit.Base.update(this.layoutOptions_, attrs); - this.setColors_(attrs); - - 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_, attrs); - this.plotter_ = new DateGraphCanvasRenderer(this.hidden_, this.layout_, - this.renderOptions_); - - this.createStatusMessage_(); - this.createRollInterface_(); - this.createDragInterface_(); - - connect(window, 'onload', this, function(e) { this.start_(); }); -}; - -/** - * Returns the current rolling period, as set by the user or an option. - * @return {Number} The number of days in the rolling window - */ -DateGraph.prototype.rollPeriod = function() { - return this.rollPeriod_; -} - -/** - * Generates interface elements for the DateGraph: a containing div, a div to - * display the current point, and a textbox to adjust the rolling average - * period. - * @private - */ -DateGraph.prototype.createInterface_ = function() { - // Create the all-enclosing graph div - var enclosing = this.maindiv_; - - this.graphDiv = MochiKit.DOM.DIV( { style: { 'width': this.width_ + "px", - 'height': this.height_ + "px" - }}); - appendChildNodes(enclosing, this.graphDiv); - - // Create the canvas to store - var canvas = MochiKit.DOM.CANVAS; - this.canvas_ = canvas( { 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) { this.mouseMove_(e) }); - connect(this.hidden_, 'onmouseout', this, function(e) { this.mouseOut_(e) }); -} - -/** - * Creates the canvas containing the PlotKit graph. Only plotkit ever draws on - * this particular canvas. All DateGraph work is done on this.canvas_. - * @param {Object} canvas The DateGraph canvas to over which to overlay the plot - * @return {Object} The newly-created canvas - * @private - */ -DateGraph.prototype.createPlotKitCanvas_ = function(canvas) { - var h = document.createElement("canvas"); - h.style.position = "absolute"; - h.style.top = canvas.style.top; - h.style.left = canvas.style.left; - h.width = this.width_; - h.height = this.height_; - MochiKit.DOM.appendChildNodes(this.graphDiv, h); - return h; -}; - -/** - * Generate a set of distinct colors for the data series. This is done with a - * color wheel. Saturation/Value are customizable, and the hue is - * equally-spaced around the color wheel. If a custom set of colors is - * specified, that is used instead. - * @param {Object} attrs Various attributes, e.g. saturation and value - * @private - */ -DateGraph.prototype.setColors_ = function(attrs) { - var num = this.labels_.length; - this.colors_ = []; - if (!attrs.colors) { - var sat = attrs.colorSaturation || 1.0; - var val = attrs.colorValue || 0.5; - for (var i = 1; i <= num; i++) { - var hue = (1.0*i/(1+num)); - this.colors_.push( MochiKit.Color.Color.fromHSV(hue, sat, val) ); - } - } else { - for (var i = 0; i < num; i++) { - var colorStr = attrs.colors[i % attrs.colors.length]; - this.colors_.push( MochiKit.Color.Color.fromString(colorStr) ); - } - } -} - -/** - * Create the div that contains information on the selected point(s) - * This goes in the top right of the canvas, unless an external div has already - * been specified. - * @private - */ -DateGraph.prototype.createStatusMessage_ = function(){ - if (!this.labelsDiv_) { - var divWidth = 250; - var messagestyle = { "style": { - "position": "absolute", - "fontSize": "14px", - "zIndex": 10, - "width": divWidth + "px", - "top": "0px", - "left": this.width_ - divWidth + "px", - "background": "white", - "textAlign": "left", - "overflow": "hidden"}}; - this.labelsDiv_ = MochiKit.DOM.DIV(messagestyle); - MochiKit.DOM.appendChildNodes(this.graphDiv, this.labelsDiv_); - } -}; - -/** - * Create the text box to adjust the averaging period - * @return {Object} The newly-created text box - * @private - */ -DateGraph.prototype.createRollInterface_ = function() { - var padding = this.plotter_.options.padding; - var textAttr = { "type": "text", - "size": "2", - "value": this.rollPeriod_, - "style": { "position": "absolute", - "zIndex": 10, - "top": (this.height_ - 25 - padding.bottom) + "px", - "left": (padding.left+1) + "px" } - }; - var roller = MochiKit.DOM.INPUT(textAttr); - var pa = this.graphDiv; - MochiKit.DOM.appendChildNodes(pa, roller); - connect(roller, 'onchange', this, - function() { this.adjustRoll(roller.value); }); - return roller; -} - -/** - * Set up all the mouse handlers needed to capture dragging behavior for zoom - * events. Uses MochiKit.Signal to attach all the event handlers. - * @private - */ -DateGraph.prototype.createDragInterface_ = function() { - var self = this; - - // Tracks whether the mouse is down right now - var mouseDown = false; - var dragStartX = null; - var dragStartY = null; - var dragEndX = null; - var dragEndY = null; - var prevEndX = null; - - // Utility function to convert page-wide coordinates to canvas coords - var px = PlotKit.Base.findPosX(this.canvas_); - var py = PlotKit.Base.findPosY(this.canvas_); - var getX = function(e) { return e.mouse().page.x - px }; - var getY = function(e) { return e.mouse().page.y - py }; - - // Draw zoom rectangles when the mouse is down and the user moves around - connect(this.hidden_, 'onmousemove', function(event) { - if (mouseDown) { - dragEndX = getX(event); - dragEndY = getY(event); - - self.drawZoomRect_(dragStartX, dragEndX, prevEndX); - prevEndX = dragEndX; - } - }); - - // Track the beginning of drag events - connect(this.hidden_, 'onmousedown', function(event) { - mouseDown = true; - dragStartX = getX(event); - dragStartY = getY(event); - }); - - // If the user releases the mouse button during a drag, but not over the - // canvas, then it doesn't count as a zooming action. - connect(document, 'onmouseup', this, function(event) { - if (mouseDown) { - mouseDown = false; - dragStartX = null; - dragStartY = null; - } - }); - - // Temporarily cancel the dragging event when the mouse leaves the graph - connect(this.hidden_, 'onmouseout', this, function(event) { - if (mouseDown) { - dragEndX = null; - dragEndY = null; - } - }); - - // If the mouse is released on the canvas during a drag event, then it's a - // zoom. Only do the zoom if it's over a large enough area (>= 10 pixels) - connect(this.hidden_, 'onmouseup', this, function(event) { - if (mouseDown) { - mouseDown = false; - dragEndX = getX(event); - dragEndY = getY(event); - var regionWidth = Math.abs(dragEndX - dragStartX); - var regionHeight = Math.abs(dragEndY - dragStartY); - - if (regionWidth < 2 && regionHeight < 2 && - self.clickCallback_ != null && - self.lastx_ != undefined) { - self.clickCallback_(event, new Date(self.lastx_)); - } - - if (regionWidth >= 10) { - self.doZoom_(Math.min(dragStartX, dragEndX), - Math.max(dragStartX, dragEndX)); - } else { - self.canvas_.getContext("2d").clearRect(0, 0, - self.canvas_.width, - self.canvas_.height); - } - - dragStartX = null; - dragStartY = null; - } - }); - - // Double-clicking zooms back out - connect(this.hidden_, 'ondblclick', this, function(event) { - self.dateWindow_ = null; - self.drawGraph_(self.rawData_); - var minDate = self.rawData_[0][0]; - var maxDate = self.rawData_[self.rawData_.length - 1][0]; - self.zoomCallback_(minDate, maxDate); - }); -}; - -/** - * Draw a gray zoom rectangle over the desired area of the canvas. Also clears - * up any previous zoom rectangles that were drawn. This could be optimized to - * avoid extra redrawing, but it's tricky to avoid interactions with the status - * dots. - * @param {Number} startX The X position where the drag started, in canvas - * coordinates. - * @param {Number} endX The current X position of the drag, in canvas coords. - * @param {Number} prevEndX The value of endX on the previous call to this - * function. Used to avoid excess redrawing - * @private - */ -DateGraph.prototype.drawZoomRect_ = function(startX, endX, prevEndX) { - var ctx = this.canvas_.getContext("2d"); - - // Clean up from the previous rect if necessary - if (prevEndX) { - ctx.clearRect(Math.min(startX, prevEndX), 0, - Math.abs(startX - prevEndX), this.height_); - } - - // Draw a light-grey rectangle to show the new viewing area - if (endX && startX) { - ctx.fillStyle = "rgba(128,128,128,0.33)"; - ctx.fillRect(Math.min(startX, endX), 0, - Math.abs(endX - startX), this.height_); - } -}; - -/** - * Zoom to something containing [lowX, highX]. These are pixel coordinates - * in the canvas. The exact zoom window may be slightly larger if there are no - * data points near lowX or highX. This function redraws the graph. - * @param {Number} lowX The leftmost pixel value that should be visible. - * @param {Number} highX The rightmost pixel value that should be visible. - * @private - */ -DateGraph.prototype.doZoom_ = function(lowX, highX) { - // Find the earliest and latest dates contained in this canvasx range. - var points = this.layout_.points; - var minDate = null; - var maxDate = null; - // Find the nearest [minDate, maxDate] that contains [lowX, highX] - for (var i = 0; i < points.length; i++) { - var cx = points[i].canvasx; - var x = points[i].xval; - if (cx < lowX && (minDate == null || x > minDate)) minDate = x; - if (cx > highX && (maxDate == null || x < maxDate)) maxDate = x; - } - // Use the extremes if either is missing - if (minDate == null) minDate = points[0].xval; - if (maxDate == null) maxDate = points[points.length-1].xval; - - this.dateWindow_ = [minDate, maxDate]; - this.drawGraph_(this.rawData_); - this.zoomCallback_(minDate, maxDate); -}; - -/** - * When the mouse moves in the canvas, display information about a nearby data - * point and draw dots over those points in the data series. This function - * takes care of cleanup of previously-drawn dots. - * @param {Object} event The mousemove event from the browser. - * @private - */ -DateGraph.prototype.mouseMove_ = function(event) { - var canvasx = event.mouse().page.x - PlotKit.Base.findPosX(this.hidden_); - var points = this.layout_.points; - - var lastx = -1; - var lasty = -1; - - // Loop through all the points and find the date nearest to our current - // location. - var minDist = 1e+100; - var idx = -1; - for (var i = 0; i < points.length; i++) { - var dist = Math.abs(points[i].canvasx - canvasx); - if (dist > minDist) break; - minDist = dist; - idx = i; - } - if (idx >= 0) lastx = points[idx].xval; - // Check that you can really highlight the last day's data - if (canvasx > points[points.length-1].canvasx) - lastx = points[points.length-1].xval; - - // Extract the points we've selected - var selPoints = []; - for (var i = 0; i < points.length; i++) { - if (points[i].xval == lastx) { - selPoints.push(points[i]); - } - } - - // Clear the previously drawn vertical, if there is one - var circleSize = 3; - var ctx = this.canvas_.getContext("2d"); - if (this.previousVerticalX_ >= 0) { - var px = this.previousVerticalX_; - ctx.clearRect(px - circleSize - 1, 0, 2 * circleSize + 2, this.height_); - } - - if (selPoints.length > 0) { - var canvasx = selPoints[0].canvasx; - - // Set the status message to indicate the selected point(s) - var replace = this.xValueFormatter_(lastx) + ":"; - var clen = this.colors_.length; - for (var i = 0; i < selPoints.length; i++) { - if (this.labelsSeparateLines) { - replace += "
"; - } - var point = selPoints[i]; - replace += " " - + point.name + ":" - + this.round_(point.yval, 2); - } - this.labelsDiv_.innerHTML = replace; - - // Save last x position for callbacks. - this.lastx_ = lastx; - - // Draw colored circles over the center of each selected point - ctx.save() - for (var i = 0; i < selPoints.length; i++) { - ctx.beginPath(); - ctx.fillStyle = this.colors_[i%clen].toRGBString(); - ctx.arc(canvasx, selPoints[i%clen].canvasy, circleSize, 0, 360, false); - ctx.fill(); - } - ctx.restore(); - - this.previousVerticalX_ = canvasx; - } -}; - -/** - * The mouse has left the canvas. Clear out whatever artifacts remain - * @param {Object} event the mouseout event from the browser. - * @private - */ -DateGraph.prototype.mouseOut_ = function(event) { - // Get rid of the overlay data - var ctx = this.canvas_.getContext("2d"); - ctx.clearRect(0, 0, this.width_, this.height_); - this.labelsDiv_.innerHTML = ""; -}; - -/** - * Convert a JS date (millis since epoch) to YYYY/MM/DD - * @param {Number} date The JavaScript date (ms since epoch) - * @return {String} A date of the form "YYYY/MM/DD" - * @private - */ -DateGraph.prototype.dateString_ = function(date) { - var d = new Date(date); - - // Get the year: - var year = "" + d.getFullYear(); - // Get a 0 padded month string - var month = "" + (d.getMonth() + 1); //months are 0-offset, sigh - if (month.length < 2) month = "0" + month; - // Get a 0 padded day string - var day = "" + d.getDate(); - if (day.length < 2) day = "0" + day; - - return year + "/" + month + "/" + day; -}; - -/** - * Round a number to the specified number of digits past the decimal point. - * @param {Number} num The number to round - * @param {Number} places The number of decimals to which to round - * @return {Number} The rounded number - * @private - */ -DateGraph.prototype.round_ = function(num, places) { - var shift = Math.pow(10, places); - return Math.round(num * shift)/shift; -}; - -/** - * Fires when there's data available to be graphed. - * @param {String} data Raw CSV data to be plotted - * @private - */ -DateGraph.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"]; - -/** - * Add ticks on the x-axis representing years, months, quarters, weeks, or days - * @private - */ -DateGraph.prototype.addXTicks_ = function() { - // Determine the correct ticks scale on the x-axis: quarterly, monthly, ... - var startDate, endDate; - if (this.dateWindow_) { - startDate = this.dateWindow_[0]; - endDate = this.dateWindow_[1]; - } else { - startDate = this.rawData_[0][0]; - endDate = this.rawData_[this.rawData_.length - 1][0]; - } - - var xTicks = this.xTicker_(startDate, endDate); - this.layout_.updateOptions({xTicks: xTicks}); -} - -/** - * Add ticks to the x-axis based on a date range. - * @param {Number} startDate Start of the date window (millis since epoch) - * @param {Number} endDate End of the date window (millis since epoch) - * @return {Array.} Array of {label, value} tuples. - * @public - */ -DateGraph.prototype.dateTicker = function(startDate, endDate) { - var ONE_DAY = 24*60*60*1000; - startDate = startDate / ONE_DAY; - endDate = endDate / ONE_DAY; - var dateSpan = endDate - startDate; - - var scale = []; - var isMonthly = false; - var yearMod = 1; - if (dateSpan > 30 * 366) { // decadal - isMonthly = true; - scale = ["Jan"]; - yearMod = 10; - } else if (dateSpan > 4*366) { // annual - scale = ["Jan"]; - isMonthly = true; - } else if (dateSpan > 366) { // quarterly - scale = this.quarters; - isMonthly = true; - } else if (dateSpan > 40) { // monthly - scale = this.months; - isMonthly = true; - } else if (dateSpan > 10) { // weekly - for (var week = startDate - 14; week < endDate + 14; week += 7) { - scale.push(week * ONE_DAY); - } - } else { // daily - for (var day = startDate - 14; day < endDate + 14; day += 1) { - scale.push(day * ONE_DAY); - } - } - - var xTicks = []; - - if (isMonthly) { - var startYear = 1900 + (new Date(startDate* ONE_DAY)).getYear(); - var endYear = 1900 + (new Date(endDate * ONE_DAY)).getYear(); - for (var i = startYear; i <= endYear; i++) { - if (i % yearMod != 0) continue; - for (var j = 0; j < scale.length; j++ ) { - var date = Date.parse(scale[j] + " 1, " + i); - xTicks.push( {label: scale[j] + "'" + ("" + i).substr(2,2), v: date } ); - } - } - } else { - for (var i = 0; i < scale.length; i++) { - var date = new Date(scale[i]); - var year = date.getFullYear().toString(); - var label = this.months[date.getMonth()] + date.getDate(); - label += "'" + year.substr(year.length - 2, 2); - xTicks.push( {label: label, v: date} ); - } - } - return xTicks; -}; - -/** - * Add ticks when the x axis has numbers on it (instead of dates) - * @param {Number} startDate Start of the date window (millis since epoch) - * @param {Number} endDate End of the date window (millis since epoch) - * @return {Array.} Array of {label, value} tuples. - * @public - */ -DateGraph.prototype.numericTicks = function(minV, maxV) { - var scale; - if (maxV <= 0.0) { - scale = 1.0; - } else { - scale = Math.pow( 10, Math.floor(Math.log(maxV)/Math.log(10.0)) ); - } - - // Add a smallish number of ticks at human-friendly points - var nTicks = (maxV - minV) / scale; - while (2 * nTicks < 20) { - nTicks *= 2; - } - if ((maxV - minV) / nTicks < this.minTickSize_) { - nTicks = this.round_((maxV - minV) / this.minTickSize_, 1); - } - - // Construct labels for the ticks - var ticks = []; - for (var i = 0; i <= nTicks; i++) { - var tickV = minV + i * (maxV - minV) / nTicks; - var label = this.round_(tickV, 2); - if (this.labelsKMB_) { - var k = 1000; - if (tickV >= k*k*k) { - label = this.round_(tickV/(k*k*k), 1) + "B"; - } else if (tickV >= k*k) { - label = this.round_(tickV/(k*k), 1) + "M"; - } else if (tickV >= k) { - label = this.round_(tickV/k, 1) + "K"; - } - } - ticks.push( {label: label, v: tickV} ); - } - return ticks; -}; - -/** - * Adds appropriate ticks on the y-axis - * @param {Number} minY The minimum Y value in the data set - * @param {Number} maxY The maximum Y value in the data set - * @private - */ -DateGraph.prototype.addYTicks_ = function(minY, maxY) { - // Set the number of ticks so that the labels are human-friendly. - var ticks = this.numericTicks(minY, maxY); - this.layout_.updateOptions( { yAxis: [minY, maxY], - yTicks: ticks } ); -}; - -/** - * Update the graph with new data. Data is in the format - * [ [date1, val1, val2, ...], [date2, val1, val2, ...] if errorBars=false - * or, if errorBars=true, - * [ [date1, [val1,stddev1], [val2,stddev2], ...], [date2, ...], ...] - * @param {Array.} data The data (see above) - * @private - */ -DateGraph.prototype.drawGraph_ = function(data) { - var maxY = null; - this.layout_.removeAllDatasets(); - // Loop over all fields in the dataset - for (var i = 1; i < data[0].length; i++) { - var series = []; - for (var j = 0; j < data.length; j++) { - var date = data[j][0]; - series[j] = [date, data[j][i]]; - } - series = this.rollingAverage(series, this.rollPeriod_); - - // Prune down to the desired range, if necessary (for zooming) - var bars = this.errorBars_ || this.customBars_; - if (this.dateWindow_) { - var low = this.dateWindow_[0]; - var high= this.dateWindow_[1]; - var pruned = []; - for (var k = 0; k < series.length; k++) { - if (series[k][0] >= low && series[k][0] <= high) { - pruned.push(series[k]); - var y = bars ? series[k][1][0] : series[k][1]; - if (maxY == null || y > maxY) maxY = y; - } - } - series = pruned; - } else { - for (var j = 0; j < series.length; j++) { - var y = bars ? series[j][1][0] : series[j][1]; - if (maxY == null || y > maxY) { - maxY = bars ? y + series[j][1][1] : y; - } - } - } - - if (bars) { - var vals = []; - for (var j=0; j= 0) { - num -= originalData[i - rollPeriod][1][0]; - den -= originalData[i - rollPeriod][1][1]; - } - - var date = originalData[i][0]; - var value = den ? num / den : 0.0; - if (this.errorBars_) { - if (this.wilsonInterval_) { - // For more details on this confidence interval, see: - // http://en.wikipedia.org/wiki/Binomial_confidence_interval - if (den) { - var p = value < 0 ? 0 : value, n = den; - var pm = sigma * Math.sqrt(p*(1-p)/n + sigma*sigma/(4*n*n)); - var denom = 1 + sigma * sigma / den; - var low = (p + sigma * sigma / (2 * den) - pm) / denom; - var high = (p + sigma * sigma / (2 * den) + pm) / denom; - rollingData[i] = [date, - [p * mult, (p - low) * mult, (high - p) * mult]]; - } else { - rollingData[i] = [date, [0, 0, 0]]; - } - } else { - var stddev = den ? sigma * Math.sqrt(value * (1 - value) / den) : 1.0; - rollingData[i] = [date, [mult * value, mult * stddev, mult * stddev]]; - } - } else { - rollingData[i] = [date, mult * value]; - } - } - } else if (this.customBars_) { - // just ignore the rolling for now. - // TODO(danvk): do something reasonable. - for (var i = 0; i < originalData.length; i++) { - var data = originalData[i][1]; - var y = data[1]; - rollingData[i] = [originalData[i][0], [y, y - data[0], data[2] - y]]; - } - } else { - // Calculate the rolling average for the first rollPeriod - 1 points where - // there is not enough data to roll over the full number of days - var num_init_points = Math.min(rollPeriod - 1, originalData.length - 2); - if (!this.errorBars_){ - for (var i = 0; i < num_init_points; i++) { - var sum = 0; - for (var j = 0; j < i + 1; j++) - sum += originalData[j][1]; - rollingData[i] = [originalData[i][0], sum / (i + 1)]; - } - // Calculate the rolling average for the remaining points - for (var i = Math.min(rollPeriod - 1, originalData.length - 2); - i < originalData.length; - i++) { - var sum = 0; - for (var j = i - rollPeriod + 1; j < i + 1; j++) - sum += originalData[j][1]; - rollingData[i] = [originalData[i][0], sum / rollPeriod]; - } - } else { - for (var i = 0; i < num_init_points; i++) { - var sum = 0; - var variance = 0; - for (var j = 0; j < i + 1; j++) { - sum += originalData[j][1][0]; - variance += Math.pow(originalData[j][1][1], 2); - } - var stddev = Math.sqrt(variance)/(i+1); - rollingData[i] = [originalData[i][0], - [sum/(i+1), sigma * stddev, sigma * stddev]]; - } - // Calculate the rolling average for the remaining points - for (var i = Math.min(rollPeriod - 1, originalData.length - 2); - i < originalData.length; - i++) { - var sum = 0; - var variance = 0; - for (var j = i - rollPeriod + 1; j < i + 1; j++) { - sum += originalData[j][1][0]; - variance += Math.pow(originalData[j][1][1], 2); - } - var stddev = Math.sqrt(variance) / rollPeriod; - rollingData[i] = [originalData[i][0], - [sum / rollPeriod, sigma * stddev, sigma * stddev]]; - } - } - } - - return rollingData; -}; - -/** - * Parses a date, returning the number of milliseconds since epoch. This can be - * passed in as an xValueParser in the DateGraph constructor. - * @param {String} A date in YYYYMMDD format. - * @return {Number} Milliseconds since epoch. - * @public - */ -DateGraph.prototype.dateParser = function(dateStr) { - var dateStrSlashed; - if (dateStr.search("-") != -1) { - dateStrSlashed = dateStr.replace("-", "/", "g"); - } else if (dateStr.search("/") != -1) { - return Date.parse(dateStr); - } else { - dateStrSlashed = dateStr.substr(0,4) + "/" + dateStr.substr(4,2) - + "/" + dateStr.substr(6,2); - } - return Date.parse(dateStrSlashed); -}; - -/** - * Parses a string in a special csv format. We expect a csv file where each - * line is a date point, and the first field in each line is the date string. - * We also expect that all remaining fields represent series. - * if this.errorBars_ is set, then interpret the fields as: - * date, series1, stddev1, series2, stddev2, ... - * @param {Array.} data See above. - * @private - */ -DateGraph.prototype.parseCSV_ = function(data) { - var ret = []; - var lines = data.split("\n"); - var start = this.labelsFromCSV_ ? 1 : 0; - if (this.labelsFromCSV_) { - var labels = lines[0].split(","); - labels.shift(); // a "date" parameter is assumed. - this.labels_ = labels; - // regenerate automatic colors. - 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 = start; i < lines.length; i++) { - var line = lines[i]; - if (line.length == 0) continue; // skip blank lines - var inFields = line.split(','); - if (inFields.length < 2) - continue; - - var fields = []; - fields[0] = this.xValueParser_(inFields[0]); - - // If fractions are expected, parse the numbers as "A/B" - if (this.fractions_) { - for (var j = 1; j < inFields.length; j++) { - // TODO(danvk): figure out an appropriate way to flag parse errors. - var vals = inFields[j].split("/"); - fields[j] = [parseFloat(vals[0]), parseFloat(vals[1])]; - } - } else if (this.errorBars_) { - // If there are error bars, values are (value, stddev) pairs - for (var j = 1; j < inFields.length; j += 2) - fields[(j + 1) / 2] = [parseFloat(inFields[j]), - parseFloat(inFields[j + 1])]; - } else if (this.customBars_) { - // Bars are a low;center;high tuple - for (var j = 1; j < inFields.length; j++) { - var vals = inFields[j].split(";"); - fields[j] = [ parseFloat(vals[0]), - parseFloat(vals[1]), - parseFloat(vals[2]) ]; - } - } else { - // Values are just numbers - for (var j = 1; j < inFields.length; j++) - fields[j] = parseFloat(inFields[j]); - } - ret.push(fields); - } - return ret; -}; - -/** - * Get the CSV data. If it's in a function, call that function. If it's in a - * file, do an XMLHttpRequest to get it. - * @private - */ -DateGraph.prototype.start_ = function() { - if (typeof this.file_ == 'function') { - // Stubbed out to allow this to run off a filesystem - this.loadedEvent_(this.file_()); - } else { - var req = new XMLHttpRequest(); - var caller = this; - req.onreadystatechange = function () { - if (req.readyState == 4) { - if (req.status == 200) { - caller.loadedEvent_(req.responseText); - } - } - }; - - req.open("GET", this.file_, true); - req.send(null); - } -}; - -/** - * Changes various properties of the graph. These can include: - *
    - *
  • file: changes the source data for the graph
  • - *
  • errorBars: changes whether the data contains stddev
  • - *
- * @param {Object} attrs The new properties and values - */ -DateGraph.prototype.updateOptions = function(attrs) { - if (attrs.errorBars) { - this.errorBars_ = attrs.errorBars; - } - if (attrs.customBars) { - this.customBars_ = attrs.customBars; - } - if (attrs.strokeWidth) { - this.strokeWidth_ = attrs.strokeWidth; - } - if (attrs.rollPeriod) { - this.rollPeriod_ = attrs.rollPeriod; - } - if (attrs.dateWindow) { - this.dateWindow_ = attrs.dateWindow; - } - if (attrs.valueRange) { - this.valueRange_ = attrs.valueRange; - } - if (attrs.minTickSize) { - this.minTickSize_ = attrs.minTickSize; - } - if (typeof(attrs.labels) != 'undefined') { - this.labels_ = attrs.labels; - this.labelsFromCSV_ = (attrs.labels == null); - } - this.layout_.updateOptions({ 'errorBars': this.errorBars_ }); - if (attrs['file'] && attrs['file'] != this.file_) { - this.file_ = attrs['file']; - this.start_(); - } else { - this.drawGraph_(this.rawData_); - } -}; - -/** - * Adjusts the number of days in the rolling average. Updates the graph to - * reflect the new averaging period. - * @param {Number} length Number of days over which to average the data. - */ -DateGraph.prototype.adjustRoll = function(length) { - this.rollPeriod_ = length; - this.drawGraph_(this.rawData_); -};