morris.js/morris.min.js

1 line
15 KiB
JavaScript
Raw Normal View History

(function(){var a,b,c,d,e=function(a,b){return function(){return a.apply(b,arguments)}};a=jQuery,b={},b.Line=function(){function c(c){this.updateHilight=e(this.updateHilight,this),this.hilight=e(this.hilight,this),this.updateHover=e(this.updateHover,this),this.transY=e(this.transY,this),this.transX=e(this.transX,this);var d,f=this;if(!(this instanceof b.Line))return new b.Line(c);typeof c.element=="string"?this.el=a(document.getElementById(c.element)):this.el=a(c.element);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");this.options=a.extend({},this.defaults,c),typeof this.options.units=="string"&&(this.options.postUnits=c.units);if(this.options.data===void 0||this.options.data.length===0)return;this.el.addClass("graph-initialised"),this.r=new Raphael(this.el[0]),this.pointGrow=Raphael.animation({r:this.options.pointSize+3},25,"linear"),this.pointShrink=Raphael.animation({r:this.options.pointSize},25,"linear"),this.elementWidth=null,this.elementHeight=null,this.dirty=!1,this.prevHilight=null,this.el.mousemove(function(a){return f.updateHilight(a.pageX)}),this.options.hideHover&&this.el.mouseout(function(a){return f.hilight(null)}),d=function(a){var b;return b=a.originalEvent.touches[0]||a.originalEvent.changedTouches[0],f.updateHilight(b.pageX),b},this.el.bind("touchstart",d),this.el.bind("touchmove",d),this.el.bind("touchend",d),this.setData(this.options.data)}return c.prototype.defaults={lineWidth:3,pointSize:4,lineColors:["#0b62a4","#7A92A3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],ymax:"auto",ymin:"auto 0",marginTop:25,marginRight:25,marginBottom:30,marginLeft:25,numLines:5,gridLineColor:"#aaa",gridTextColor:"#888",gridTextSize:12,gridStrokeWidth:.5,hoverPaddingX:10,hoverPaddingY:5,hoverMargin:10,hoverFillColor:"#fff",hoverBorderColor:"#ccc",hoverBorderWidth:2,hoverOpacity:.95,hoverLabelColor:"#444",hoverFontSize:12,smooth:!0,hideHover:!1,parseTime:!0,preUnits:"",postUnits:"",dateFormat:function(a){return(new Date(a)).toString()},xLabels:"auto",xLabelFormat:null},c.prototype.setData=function(c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s=this;d==null&&(d=!0),this.options.data=c.slice(0),this.options.data.sort(function(a,b){return(a[s.options.xkey]<b[s.options.xkey])-(b[s.options.xkey]<a[s.options.xkey])}),this.columnLabels=a.map(this.options.data,function(a){return a[s.options.xkey]}),this.seriesLabels=this.options.labels,this.series=[],o=this.options.ykeys;for(j=0,m=o.length;j<m;j++){g=o[j],f=[],p=this.options.data;for(k=0,n=p.length;k<n;k++)e=p[k],f.push(function(){switch(typeof e[g]){case"number":return e[g];case"string":return parseFloat(e[g]);default:return null}}());this.series.push(f)}this.options.parseTime?this.xvals=a.map(this.columnLabels,function(a){return b.parseDate(a)}):this.xvals=function(){r=[];for(var a=q=this.columnLabels.length-1;q<=0?a<=0:a>=0;q<=0?a++:a--)r.push(a);return r}.apply(this),this.options.parseTime&&(this.columnLabels=a.map(this.columnLabels,function(a){return typeof a=="number"?s.options.dateFormat(a):a})),this.xmin=Math.min.apply(null,this.xvals),this.xmax=Math.max.apply(null,this.xvals),this.xmin===this.xmax&&(this.xmin-=1,this.xmax+=1),typeof this.options.ymax=="string"&&this.options.ymax.slice(0,4)==="auto"&&(h=Math.max.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymax.length>5?this.options.ymax=Math.max(parseInt(this.options.ymax.slice(5),10),h):this.options.ymax=h),typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"&&(i=Math.min.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymin.length>5?this.options.ymin=Math.min(parseInt(this.options.ymin.slice(5),10),i):this.options.ymin=i),this.yInterval=(this.options.ymax-this.options.ymin)/(this.options.numLines-1),this.yInterval>0&&this.yInterval<1?this.precision=-Math.floor(Math.log(this.yInterval)/Math.log(10)):this.precision=0,this.dirty=!0;if(d)return this.redraw()},c.prototype.calc=function(){var b,c,d,e,f,g,h,i,j=this;e=this.el.width(),b=this.el.height();if(this.elementWidth!==e||this.elementHeight!==b||this.dirty){this.ele