morris.js/morris.min.js

1 line
14 KiB
JavaScript
Raw Normal View History

2012-04-03 17:31:59 +02:00
(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);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),this.options=a.extend({},this.defaults,c);if(this.options.data===void 0||this.options.data.length===0)return;this.el.addClass("graph-initialised"),this.precalc(),this.redraw()}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,units:"",dateFormat:function(a){return(new Date(a)).toString()},xLabels:"auto",xLabelsFormat:null},c.prototype.precalc=function(){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=this;this.options.data.sort(function(a,b){return(a[r.options.xkey]<b[r.options.xkey])-(b[r.options.xkey]<a[r.options.xkey])}),this.columnLabels=a.map(this.options.data,function(a){return a[r.options.xkey]}),this.seriesLabels=this.options.labels,this.series=[],n=this.options.ykeys;for(i=0,l=n.length;i<l;i++){f=n[i],d=[],o=this.options.data;for(j=0,m=o.length;j<m;j++)c=o[j],d.push(c[f]);this.series.push(d)}return this.options.parseTime?this.xvals=a.map(this.columnLabels,function(a){return b.parseDate(a)}):this.xvals=function(){q=[];for(var a=p=this.columnLabels.length-1;p<=0?a<=0:a>=0;p<=0?a++:a--)q.push(a);return q}.apply(this),this.options.parseTime&&(this.columnLabels=a.map(this.columnLabels,function(a){return typeof a=="number"?r.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"&&(g=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),g):this.options.ymax=g),typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"&&(h=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),h):this.options.ymin=h),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.prevHilight=null,this.el.mousemove(function(a){return r.updateHilight(a.pageX)}),this.options.hideHover&&this.el.mouseout(function(a){return r.hilight(null)}),e=function(a){var b;return b=a.originalEvent.touches[0]||a.originalEvent.changedTouches[0],r.updateHilight(b.pageX),b},this.el.bind("touchstart",e),this.el.bind("touchmove",e),this.el.bind("touchend",e)},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.maxYLabelWidth=Math.max(this.measureText(this.options.ymin+this.options.units,this.options.gridTextSize).width,this.measureText(this.options.ymax+this.options.units,this.options.gridTextSize).width),this.left=this.maxYLabelWidth+this.options.marginLeft,this.width=this.el.width()-this.left-this.options.marginRight,this.height=this.el.height()-this.options.marginTop-this.options.marginBottom,this.dx=this.width/(this.xmax-this.xmin),this.dy=this.height/(this.options.ymax-this.options.ymin),this.columns=function(){var a,b,c,d;c=this.xvals,d=[];for(a=0,b=c.length;a<b;a++)f=c[a],d.push(this.transX(f));return d}.call(this),this.series