morris.js/morris.min.js

7 lines
41 KiB
JavaScript
Raw Normal View History

2014-02-23 20:54:38 +01:00
/* @license
2014-07-12 19:20:17 +02:00
morris.js v0.5.1
2017-07-26 19:48:36 +02:00
Copyright 2017 Olly Smith All rights reserved.
2014-02-23 20:54:38 +01:00
Licensed under the BSD-2-Clause License.
*/
2017-07-26 19:48:36 +02:00
(function(){var a,b,c,d,e=[].slice,f=function(a,b){return function(){return a.apply(b,arguments)}},g={}.hasOwnProperty,h=function(a,b){function c(){this.constructor=a}for(var d in b)g.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},i=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};b=window.Morris={},a=jQuery,b.EventEmitter=function(){function a(){}return a.prototype.on=function(a,b){return null==this.handlers&&(this.handlers={}),null==this.handlers[a]&&(this.handlers[a]=[]),this.handlers[a].push(b),this},a.prototype.fire=function(){var a,b,c,d,f,g,h;if(c=arguments[0],a=2<=arguments.length?e.call(arguments,1):[],null!=this.handlers&&null!=this.handlers[c]){for(g=this.handlers[c],h=[],d=0,f=g.length;f>d;d++)b=g[d],h.push(b.apply(null,a));return h}},a}(),b.commas=function(a){var b,c,d,e;return null!=a?(d=0>a?"-":"",b=Math.abs(a),c=Math.floor(b).toFixed(0),d+=c.replace(/(?=(?:\d{3})+$)(?!^)/g,","),e=b.toString(),e.length>c.length&&(d+=e.slice(c.length)),d):"-"},b.pad2=function(a){return(10>a?"0":"")+a},b.Grid=function(c){function d(b){this.hasToShow=f(this.hasToShow,this),this.resizeHandler=f(this.resizeHandler,this);var c=this;if("string"==typeof b.element?this.el=a(document.getElementById(b.element)):this.el=a(b.element),null==this.el||0===this.el.length)throw new Error("Graph container element not found");"static"===this.el.css("position")&&this.el.css("position","relative"),this.options=a.extend({},this.gridDefaults,this.defaults||{},b),"string"==typeof this.options.units&&(this.options.postUnits=b.units),this.raphael=new Raphael(this.el[0]),this.elementWidth=null,this.elementHeight=null,this.dirty=!1,this.selectFrom=null,this.init&&this.init(),this.setData(this.options.data),this.el.bind("mousemove",function(a){var b,d,e,f,g;return d=c.el.offset(),g=a.pageX-d.left,c.selectFrom?(b=c.data[c.hitTest(Math.min(g,c.selectFrom))]._x,e=c.data[c.hitTest(Math.max(g,c.selectFrom))]._x,f=e-b,c.selectionRect.attr({x:b,width:f})):c.fire("hovermove",g,a.pageY-d.top)}),this.el.bind("mouseleave",function(a){return c.selectFrom&&(c.selectionRect.hide(),c.selectFrom=null),c.fire("hoverout")}),this.el.bind("touchstart touchmove touchend",function(a){var b,d;return d=a.originalEvent.touches[0]||a.originalEvent.changedTouches[0],b=c.el.offset(),c.fire("hovermove",d.pageX-b.left,d.pageY-b.top)}),this.el.bind("click",function(a){var b;return b=c.el.offset(),c.fire("gridclick",a.pageX-b.left,a.pageY-b.top)}),this.options.rangeSelect&&(this.selectionRect=this.raphael.rect(0,0,0,this.el.innerHeight()).attr({fill:this.options.rangeSelectColor,stroke:!1}).toBack().hide(),this.el.bind("mousedown",function(a){var b;return b=c.el.offset(),c.startRange(a.pageX-b.left)}),this.el.bind("mouseup",function(a){var b;return b=c.el.offset(),c.endRange(a.pageX-b.left),c.fire("hovermove",a.pageX-b.left,a.pageY-b.top)})),this.options.resize&&a(window).bind("resize",function(a){return null!=c.timeoutId&&window.clearTimeout(c.timeoutId),c.timeoutId=window.setTimeout(c.resizeHandler,100)}),this.el.css("-webkit-tap-highlight-color","rgba(0,0,0,0)"),this.postInit&&this.postInit()}return h(d,c),d.prototype.gridDefaults={dateFormat:null,axes:!0,freePosition:!1,grid:!0,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,gridTextFamily:"sans-serif",gridTextWeight:"normal",hideHover:!1,yLabelFormat:null,yLabelAlign:"right",xLabelAngle:0,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0",goals:[],goalStrokeWidth:1,goalLineColors:["#666633","#999966","#cc6666","#663333"],events:[],eventStrokeWidth:1,eventLineColors:["#005a04","#ccffbb","#3a5f0b","#005502"],rangeSelect:null,rangeSelectColor:"#eef",resize:!1},d.prototype.setData=function(c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;if(null==d&&(d=!0),this.options.data=c,null==c||0===c.length)return this.data=[],this.raphael.clear(),void(null!=this.hover&&this.hover.hide());if(s=this.cumulative?0:null,t=this.cumulative?0:null,this.options.goals.length>0&&(k=
f=s=0,t=this.options.ykeys.length-1;t>=0?t>=s:s>=t;f=t>=0?++s:--s)this.hasToShow(f)&&(k+=1);return c=(e*this.options.barSizeRatio-this.options.barGap*(k-1))/k,this.options.barSize&&(c=Math.min(c,this.options.barSize)),o=e-c*k-this.options.barGap*(k-1),j=o/2,r=this.ymin<=0&&this.ymax>=0?this.transY(0):null,this.bars=function(){var a,f,k,o;for(k=this.data,o=[],g=a=0,f=k.length;f>a;g=++a)l=k[g],this.seriesBars[g]=[],h=0,o.push(function(){var a,f,k,o;for(k=l._y,o=[],m=a=0,f=k.length;f>a;m=++a)q=k[m],this.hasToShow(m)&&(null!==q?(r?(p=Math.min(q,r),d=Math.max(q,r)):(p=q,d=this.bottom),i=this.xStart+g*e+j,this.options.stacked||(i+=m*(c+this.options.barGap)),n=d-p,this.options.verticalGridCondition&&this.options.verticalGridCondition(l.x)&&(this.options.horizontal?this.drawBar(this.yStart,this.xStart+g*e,this.ySize,e,this.options.verticalGridColor,this.options.verticalGridOpacity,this.options.barRadius):this.drawBar(this.xStart+g*e,this.yEnd,e,this.ySize,this.options.verticalGridColor,this.options.verticalGridOpacity,this.options.barRadius)),this.options.stacked&&(p-=h),this.options.horizontal?(h-=n,this.seriesBars[g][m]=this.drawBar(p,i,n,c,this.colorFor(l,m,"bar"),this.options.barOpacity,this.options.barRadius),this.options.inBarValue&&c>this.options.gridTextSize+2*this.options.inBarValueMinTopMargin?(b=i+.5*c,o.push(this.raphael.text(d-this.options.inBarValueRightMargin,b,this.yLabelFormat(l.y[m],m)).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).attr("fill",this.options.inBarValueTextColor).attr("text-anchor","end"))):o.push(void 0)):(h+=n,o.push(this.seriesBars[g][m]=this.drawBar(i,p,c,n,this.colorFor(l,m,"bar"),this.options.barOpacity,this.options.barRadius)))):o.push(null));return o}.call(this));return o}.call(this),this.flat_bars=a.map(this.bars,function(a){return a}),this.flat_bars=a.grep(this.flat_bars,function(a){return null!=a}),this.bar_els=a(a.map(this.flat_bars,function(a){return a[0]}))},d.prototype.hilight=function(a){var b,c,d,e,f,g,h,i;if(this.seriesBars&&this.seriesBars[this.prevHilight]&&null!==this.prevHilight&&this.prevHilight!==a)for(h=this.seriesBars[this.prevHilight],b=d=0,f=h.length;f>d;b=++d)c=h[b],c&&c.animate({"fill-opacity":this.options.barOpacity},this.options.highlightSpeed);if(this.seriesBars&&this.seriesBars[a]&&null!==a&&this.prevHilight!==a)for(i=this.seriesBars[a],b=e=0,g=i.length;g>e;b=++e)c=i[b],c&&c.animate({"fill-opacity":this.options.barHighlightOpacity},this.options.highlightSpeed);return this.prevHilight=a},d.prototype.colorFor=function(a,b,c){var d,e;return"function"==typeof this.options.barColors?(d={x:a.x,y:a.y[b],label:a.label,src:a.src},e={index:b,key:this.options.ykeys[b],label:this.options.labels[b]},this.options.barColors.call(this,d,e,c)):this.options.barColors[b%this.options.barColors.length]},d.prototype.hitTest=function(a,b){var c;return 0===this.data.length?null:(c=this.options.horizontal?b:a,c=Math.max(Math.min(c,this.xEnd),this.xStart),Math.min(this.data.length-1,Math.floor((c-this.xStart)/(this.xSize/this.data.length))))},d.prototype.onGridClick=function(b,c){var d,e;return e=this.hitTest(b,c),d=!!this.bar_els.filter(function(){return a(this).is(":hover")}).length,this.fire("click",e,this.data[e].src,b,c,d)},d.prototype.onHoverMove=function(a,b){var c,d;return c=this.hitTest(a,b),this.hilight(c),null!=c?(d=this.hover).update.apply(d,this.hoverContentForRow(c)):this.hover.hide()},d.prototype.onHoverOut=function(){return this.hilight(-1),this.options.hideHover!==!1?this.hover.hide():void 0},d.prototype.hoverContentForRow=function(b){var c,d,e,f,g,h,i,j;for(e=this.data[b],c=a("<div class='morris-hover-row-label'>").text(e.label),c=c.prop("outerHTML"),j=e.y,d=h=0,i=j.length;i>h;d=++h)g=j[d],this.options.labels[d]!==!1&&(c+="<div class='morris-hover-point' style='color: "+this.colorFor(e,d,"label")+"'>\n "+this.options.labels[d]+":\n "+this.yLabelFormat(g,d)+"\n</div>");return"function"==typeof this.options.hoverCallback&&(c=this.options.hoverCallback(b,this.options,c,e.src)),th