morris.js/morris.min.js

1 line
31 KiB
JavaScript
Raw Normal View History

(function(){var e,t,n,r,i=[].slice,s={}.hasOwnProperty,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},u=function(e,t){return function(){return e.apply(t,arguments)}},a=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};t=window.Morris={},e=jQuery,t.EventEmitter=function(){function e(){}return e.prototype.on=function(e,t){return this.handlers==null&&(this.handlers={}),this.handlers[e]==null&&(this.handlers[e]=[]),this.handlers[e].push(t)},e.prototype.fire=function(){var e,t,n,r,s,o,u;n=arguments[0],e=2<=arguments.length?i.call(arguments,1):[];if(this.handlers!=null&&this.handlers[n]!=null){o=this.handlers[n],u=[];for(r=0,s=o.length;r<s;r++)t=o[r],u.push(t.apply(null,e));return u}},e}(),t.commas=function(e){var t,n,r,i;return e===null?"-":(r=e<0?"-":"",t=Math.abs(e),n=Math.floor(t).toFixed(0),r+=n.replace(/(?=(?:\d{3})+$)(?!^)/g,","),i=t.toString(),i.length>n.length&&(r+=i.slice(n.length)),r)},t.pad2=function(e){return(e<10?"0":"")+e},t.Grid=function(n){function r(t){typeof t.element=="string"?this.el=e(document.getElementById(t.element)):this.el=e(t.element);if(this.el===null||this.el.length===0)throw new Error("Graph container element not found");this.options=e.extend({},this.gridDefaults,this.defaults||{},t);if(this.options.data===void 0||this.options.data.length===0)return;typeof this.options.units=="string"&&(this.options.postUnits=t.units),this.r=new Raphael(this.el[0]),this.elementWidth=null,this.elementHeight=null,this.dirty=!1,this.init&&this.init(),this.setData(this.options.data)}return o(r,n),r.prototype.gridDefaults={dateFormat:null,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0"},r.prototype.setData=function(n,r){var i,s,o=this;r==null&&(r=!0),i=this.cumulative?0:null,s=this.cumulative?0:null,this.data=e.map(n,function(e,n){var r,u,a,f,l;return u={},u.label=e[o.options.xkey],o.options.parseTime?(u.x=t.parseDate(u.label),o.options.dateFormat?u.label=o.options.dateFormat(u.x):typeof u.label=="number"&&(u.label=(new Date(u.label)).toString())):u.x=n,a=0,u.y=function(){var t,n,o,u;o=this.options.ykeys,u=[];for(r=t=0,n=o.length;t<n;r=++t)f=o[r],l=e[f],typeof l=="string"&&(l=parseFloat(l)),typeof l!="number"&&(l=null),l!==null&&(this.cumulative?a+=l:i===null?i=s=l:(i=Math.max(l,i),s=Math.min(l,s))),this.cumulative&&a!==null&&(i=Math.max(a,i),s=Math.min(a,s)),u.push(l);return u}.call(o),u}),this.options.parseTime&&(this.data=this.data.sort(function(e,t){return(e.x>t.x)-(t.x>e.x)})),this.xmin=this.data[0].x,this.xmax=this.data[this.data.length-1].x,this.xmin===this.xmax&&(this.xmin-=1,this.xmax+=1),typeof this.options.ymax=="string"?this.options.ymax.slice(0,4)==="auto"?this.options.ymax.length>5?(this.ymax=parseInt(this.options.ymax.slice(5),10),i!==null&&(this.ymax=Math.max(i,this.ymax))):this.ymax=i!==null?i:0:this.ymax=parseInt(this.options.ymax,10):this.ymax=this.options.ymax,typeof this.options.ymin=="string"?this.options.ymin.slice(0,4)==="auto"?this.options.ymin.length>5?(this.ymin=parseInt(this.options.ymin.slice(5),10),s!==null&&(this.ymin=Math.min(s,this.ymin))):this.ymin=s!==null?s:0:this.ymin=parseInt(this.options.ymin,10):this.ymin=this.options.ymin,this.ymin===this.ymax&&(s&&(this.ymin-=1),this.ymax+=1),this.yInterval=(this.ymax-this.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(r)return this.redraw()},r.prototype._calc=function(){var e,t,n,r;r=this.el.width(),e=this.el.height();if(this.elementWidth!==r||this.elementHeight!==e||this.dirty){this.elementWidth=r,this.elementHeight=e,this.dirty=!1,t=Math.max(this.measureText(this.yAxisFormat(this.ymin),this.options.gridTextSize).width,this.measureText(this.yAxisFormat(this.ymax),this.options.gridTextSize).width),typeof this.options.padding=="string"?(n=this.o