From fbe3ce8201290312d91e7d6e62f7d34570cc58e4 Mon Sep 17 00:00:00 2001 From: Olly Smith Date: Thu, 20 Sep 2012 07:31:31 +0100 Subject: [PATCH 1/5] Formatter option for donut values (#75). --- examples/donut.html | 3 ++- lib/morris.donut.coffee | 33 +++++++++++++++++---------------- morris.js | 13 +++++++------ morris.min.js | 2 +- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/examples/donut.html b/examples/donut.html index 4487daf..752a047 100644 --- a/examples/donut.html +++ b/examples/donut.html @@ -19,7 +19,8 @@ Morris.Donut({ {value: 15, label: 'bar'}, {value: 10, label: 'baz'}, {value: 5, label: 'A really really long label'} - ] + ], + formatter: function (x) { return x + "%"} }); diff --git a/lib/morris.donut.coffee b/lib/morris.donut.coffee index c994507..ad34b0f 100644 --- a/lib/morris.donut.coffee +++ b/lib/morris.donut.coffee @@ -9,18 +9,20 @@ # ] # }); class Morris.Donut - colors: [ - '#0B62A4' - '#3980B5' - '#679DC6' - '#95BBD7' - '#B0CCE1' - '#095791' - '#095085' - '#083E67' - '#052C48' - '#042135' - ] + defaults: + colors: [ + '#0B62A4' + '#3980B5' + '#679DC6' + '#95BBD7' + '#B0CCE1' + '#095791' + '#095085' + '#083E67' + '#052C48' + '#042135' + ], + formatter: Morris.commas # Create and render a donut chart. # @@ -33,8 +35,7 @@ class Morris.Donut else @el = $ options.element - if options.colors? - @colors = options.colors + @options = $.extend {}, @defaults, options if @el == null || @el.length == 0 throw new Error("Graph placeholder not found.") @@ -72,7 +73,7 @@ class Morris.Donut @segments = [] for d in @data next = last + min + C * (d.value / total) - seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @colors[idx % @colors.length], d) + seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @options.colors[idx % @options.colors.length], d) seg.render @r @segments.push seg seg.on 'hover', @select @@ -92,7 +93,7 @@ class Morris.Donut select: (segment) => s.deselect() for s in @segments segment.select() - @setLabels segment.data.label, Morris.commas(segment.data.value) + @setLabels segment.data.label, @options.formatter(segment.data.value) # @private setLabels: (label1, label2) -> diff --git a/morris.js b/morris.js index 8cb070a..f65e999 100644 --- a/morris.js +++ b/morris.js @@ -64,7 +64,10 @@ Morris.Donut = (function() { - Donut.prototype.colors = ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135']; + Donut.prototype.defaults = { + colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], + formatter: Morris.commas + }; function Donut(options) { this.select = __bind(this.select, this); @@ -76,9 +79,7 @@ } else { this.el = $(options.element); } - if (options.colors != null) { - this.colors = options.colors; - } + this.options = $.extend({}, this.defaults, options); if (this.el === null || this.el.length === 0) { throw new Error("Graph placeholder not found."); } @@ -112,7 +113,7 @@ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { d = _ref1[_j]; next = last + min + C * (d.value / total); - seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.colors[idx % this.colors.length], d); + seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.options.colors[idx % this.options.colors.length], d); seg.render(this.r); this.segments.push(seg); seg.on('hover', this.select); @@ -158,7 +159,7 @@ s.deselect(); } segment.select(); - return this.setLabels(segment.data.label, Morris.commas(segment.data.value)); + return this.setLabels(segment.data.label, this.options.formatter(segment.data.value)); }; Donut.prototype.setLabels = function(label1, label2) { diff --git a/morris.min.js b/morris.min.js index 68656db..0bfcb1d 100644 --- a/morris.min.js +++ b/morris.min.js @@ -1 +1 @@ -(function(){var e,t,n,r,i=[].slice,s=function(e,t){return function(){return e.apply(t,arguments)}},o={}.hasOwnProperty,u=function(e,t){function r(){this.constructor=e}for(var n in t)o.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};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;rn.length&&(r+=i.slice(n.length)),r)},t.pad2=function(e){return(e<10?"0":"")+e},t.Donut=function(){function n(n){this.select=s(this.select,this);if(!(this instanceof t.Donut))return new t.Donut(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element),n.colors!=null&&(this.colors=n.colors);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");if(n.data===void 0||n.data.length===0)return;this.data=n.data,this.el.addClass("graph-initialised"),this.redraw()}return n.prototype.colors=["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],n.prototype.redraw=function(){var e,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x;this.el.empty(),this.r=new Raphael(this.el[0]),n=this.el.width()/2,r=this.el.height()/2,h=(Math.min(n,r)-10)/3,c=0,w=this.data;for(d=0,g=w.length;dMath.PI?1:0,this.path=this.calcSegment(this.inner+3,this.inner+this.outer-5),this.selectedPath=this.calcSegment(this.inner+3,this.inner+this.outer),this.hilight=this.calcArc(this.inner)}return u(t,e),t.prototype.calcArcPoints=function(e){return[this.cx+e*this.sin_p0,this.cy+e*this.cos_p0,this.cx+e*this.sin_p1,this.cy+e*this.cos_p1]},t.prototype.calcSegment=function(e,t){var n,r,i,s,o,u,a,f,l,c;return l=this.calcArcPoints(e),n=l[0],i=l[1],r=l[2],s=l[3],c=this.calcArcPoints(t),o=c[0],a=c[1],u=c[2],f=c[3],"M"+n+","+i+("A"+e+","+e+",0,"+this.long+",0,"+r+","+s)+("L"+u+","+f)+("A"+t+","+t+",0,"+this.long+",1,"+o+","+a)+"Z"},t.prototype.calcArc=function(e){var t,n,r,i,s;return s=this.calcArcPoints(e),t=s[0],r=s[1],n=s[2],i=s[3],"M"+t+","+r+("A"+e+","+e+",0,"+this.long+",0,"+n+","+i)},t.prototype.render=function(e){var t=this;return this.arc=e.path(this.hilight).attr({stroke:this.color,"stroke-width":2,opacity:0}),this.seg=e.path(this.path).attr({fill:this.color,stroke:"white","stroke-width":3}).hover(function(){return t.fire("hover",t)})},t.prototype.select=function(){if(!this.selected)return this.seg.animate({path:this.selectedPath},150,"<>"),this.arc.animate({opacity:1},150,"<>"),this.selected=!0},t.prototype.deselect=function(){if(this.selected)return this.seg.animate({path:this.path},150,"<>"),this.arc.animate({opacity:0},150,"<>"),this.selected=!1},t}(t.EventEmitter),t.Line=function(){function n(n){this.updateHilight=s(this.updateHilight,this),this.hilight=s(this.hilight,this),this.updateHover=s(this.updateHover,this),this.transY=s(this.transY,this),this.transX=s(this.transX,this);var r,i=this;if(!(this instanceof t.Line))return new t.Line(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");this.options=e.extend({},this.defaults,n),typeof this.options.units=="string"&&(this.options.postUnits=n.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(e){return i.updateHilight(e.pageX)}),this.options.hideHover&&this.el.mouseout(function(e){return i.hilight(null)}),r=function(e){var t;return t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],i.updateHilight(t.pageX),t},this.el.bind("touchstart",r),this.el.bind("touchmove",r),this.el.bind("touchend",r),this.seriesLabels=this.options.labels,this.setData(this.options.data)}return n.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(e){return(new Date(e)).toString()},xLabels:"auto",xLabelFormat:null},n.prototype.setData=function(n,r){var i,s,o,u,a,f,l,c,h,p,d,v,m,g,y=this;r==null&&(r=!0),this.options.data=n.slice(0),this.options.data.sort(function(e,t){return(e[y.options.xkey]=0;m<=0?e++:e--)g.push(e);return g}.apply(this),this.options.parseTime&&(this.columnLabels=e.map(this.columnLabels,function(e){return typeof e=="number"?y.options.dateFormat(e):e})),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"?(u=Math.max.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymax.length>5?this.ymax=Math.max(parseInt(this.options.ymax.slice(5),10),u):this.ymax=u):typeof this.options.ymax=="string"?this.ymax=parseInt(this.options.ymax,10):this.ymax=this.options.ymax,typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"?(a=Math.min.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymin.length>5?this.ymin=Math.min(parseInt(this.options.ymin.slice(5),10),a):this.ymin=a):typeof this.options.ymin=="string"?this.ymin=parseInt(this.options.ymin,10):this.ymin=this.options.ymin,this.ymin===this.ymax&&(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()},n.prototype.calc=function(){var t,n,r,i,s,o,u,a,f=this;i=this.el.width(),t=this.el.height();if(this.elementWidth!==i||this.elementHeight!==t||this.dirty){this.elementWidth=i,this.elementHeight=t,this.dirty=!1,this.maxYLabelWidth=Math.max(this.measureText(this.yLabelFormat(this.ymin),this.options.gridTextSize).width,this.measureText(this.yLabelFormat(this.ymax),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.ymax-this.ymin),this.columns=function(){var e,t,n,r;n=this.xvals,r=[];for(e=0,t=n.length;e=o;u=p+=g)f=parseFloat(u.toFixed(this.precision)),c=this.transY(f),this.r.text(this.left-this.options.marginLeft/2,c,this.yLabelFormat(f)).attr("font-size",this.options.gridTextSize).attr("fill",this.options.gridTextColor).attr("text-anchor","end"),this.r.path("M"+this.left+","+c+"H"+(this.left+this.width)).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth);h=this.options.marginTop+this.height+this.options.marginBottom/2,l=50,a=null,e=function(e,t){var n,r;return n=S.r.text(S.transX(t),h,e).attr("font-size",S.options.gridTextSize).attr("fill",S.options.gridTextColor),r=n.getBBox(),(a===null||a<=r.x)&&r.x>=0&&r.x+r.width=b;r=0<=b?++v:--v)s=this.columnLabels[this.columnLabels.length-r-1],E.push(e(s,r));return E},n.prototype.drawSeries=function(){var t,n,r,i,s,o,u,a,f,l;for(i=o=a=this.seriesCoords.length-1;a<=0?o<=0:o>=0;i=a<=0?++o:--o)r=e.map(this.seriesCoords[i],function(e){return e}),r.length>1&&(s=this.createPath(r,this.options.marginTop,this.left,this.options.marginTop+this.height,this.left+this.width),this.r.path(s).attr("stroke",this.options.lineColors[i]).attr("stroke-width",this.options.lineWidth));this.seriesPoints=function(){var e,t,n;n=[];for(i=e=0,t=this.seriesCoords.length-1;0<=t?e<=t:e>=t;i=0<=t?++e:--e)n.push([]);return n}.call(this),l=[];for(i=u=f=this.seriesCoords.length-1;f<=0?u<=0:u>=0;i=f<=0?++u:--u)l.push(function(){var e,r,s,o;s=this.seriesCoords[i],o=[];for(e=0,r=s.length;e=b;f=0<=b?++y:--y)o=t[f],f===0?p+="M"+o.x+","+o.y:(u=a[f],c=t[f-1],h=a[f-1],l=(o.x-c.x)/4,d=c.x+l,m=Math.min(i,c.y+l*h),v=o.x-l,g=Math.min(i,o.y-l*u),p+="C"+d+","+m+","+v+","+g+","+o.x+","+o.y)}else p="M"+e.map(t,function(e){return""+e.x+","+e.y}).join("L");return p},n.prototype.gradients=function(t){return e.map(t,function(e,n){return n===0?(t[1].y-e.y)/(t[1].x-e.x):n===t.length-1?(e.y-t[n-1].y)/(e.x-t[n-1].x):(t[n+1].y-t[n-1].y)/(t[n+1].x-t[n-1].x)})},n.prototype.drawHover=function(){var e,t,n,r,i;this.hoverHeight=this.options.hoverFontSize*1.5*(this.series.length+1),this.hover=this.r.rect(-10,-this.hoverHeight/2-this.options.hoverPaddingY,20,this.hoverHeight+this.options.hoverPaddingY*2,10).attr("fill",this.options.hoverFillColor).attr("stroke",this.options.hoverBorderColor).attr("stroke-width",this.options.hoverBorderWidth).attr("opacity",this.options.hoverOpacity),this.xLabel=this.r.text(0,this.options.hoverFontSize*.75-this.hoverHeight/2,"").attr("fill",this.options.hoverLabelColor).attr("font-weight","bold").attr("font-size",this.options.hoverFontSize),this.hoverSet=this.r.set(),this.hoverSet.push(this.hover),this.hoverSet.push(this.xLabel),this.yLabels=[],i=[];for(e=n=0,r=this.series.length-1;0<=r?n<=r:n>=r;e=0<=r?++n:--n)t=this.r.text(0,this.options.hoverFontSize*1.5*(e+1.5)-this.hoverHeight/2,"").attr("fill",this.options.lineColors[e]).attr("font-size",this.options.hoverFontSize),this.yLabels.push(t),i.push(this.hoverSet.push(t));return i},n.prototype.updateHover=function(t){var n,r,i,s,o,u,a=this;this.hoverSet.show(),this.xLabel.attr("text",this.columnLabels[t]);for(n=o=0,u=this.series.length-1;0<=u?o<=u:o>=u;n=0<=u?++o:--o)this.yLabels[n].attr("text",""+this.seriesLabels[n]+": "+this.yLabelFormat(this.series[n][t]));return r=Math.max.apply(null,e.map(this.yLabels,function(e){return e.getBBox().width})),r=Math.max(r,this.xLabel.getBBox().width),this.hover.attr("width",r+this.options.hoverPaddingX*2),this.hover.attr("x",-this.options.hoverPaddingX-r/2),s=Math.min.apply(null,e.map(this.series,function(e){return a.transY(e[t])})),s>this.hoverHeight+this.options.hoverPaddingY*2+this.options.hoverMargin+this.options.marginTop?s=s-this.hoverHeight/2-this.options.hoverPaddingY-this.options.hoverMargin:s=s+this.hoverHeight/2+this.options.hoverPaddingY+this.options.hoverMargin,s=Math.max(this.options.marginTop+this.hoverHeight/2+this.options.hoverPaddingY,s),s=Math.min(this.options.marginTop+this.height-this.hoverHeight/2-this.options.hoverPaddingY,s),i=Math.min(this.left+this.width-r/2-this.options.hoverPaddingX,this.columns[t]),i=Math.max(this.left+r/2+this.options.hoverPaddingX,i),this.hoverSet.attr("transform","t"+i+","+s)},n.prototype.hideHover=function(){return this.hoverSet.hide()},n.prototype.hilight=function(e){var t,n,r,i,s;if(this.prevHilight!==null&&this.prevHilight!==e)for(t=n=0,i=this.seriesPoints.length-1;0<=i?n<=i:n>=i;t=0<=i?++n:--n)this.seriesPoints[t][this.prevHilight]&&this.seriesPoints[t][this.prevHilight].animate(this.pointShrink);if(e!==null&&this.prevHilight!==e){for(t=r=0,s=this.seriesPoints.length-1;0<=s?r<=s:r>=s;t=0<=s?++r:--r)this.seriesPoints[t][e]&&this.seriesPoints[t][e].animate(this.pointGrow);this.updateHover(e)}this.prevHilight=e;if(e===null)return this.hideHover()},n.prototype.updateHilight=function(e){var t,n,r,i;e-=this.el.offset().left,i=[];for(t=n=r=this.hoverMargins.length;r<=0?n<=0:n>=0;t=r<=0?++n:--n){if(t===0||this.hoverMargins[t-1]>e){this.hilight(t);break}i.push(void 0)}return i},n.prototype.measureText=function(e,t){var n,r;return t==null&&(t=12),r=this.r.text(100,100,e).attr("font-size",t),n=r.getBBox(),r.remove(),n},n.prototype.yLabelFormat=function(e){return""+this.options.preUnits+t.commas(e)+this.options.postUnits},n}(),t.parseDate=function(e){var t,n,r,i,s,o,u,a,f,l,c;return typeof e=="number"?e:(n=e.match(/^(\d+) Q(\d)$/),i=e.match(/^(\d+)-(\d+)$/),s=e.match(/^(\d+)-(\d+)-(\d+)$/),u=e.match(/^(\d+) W(\d+)$/),a=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/),f=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/),n?(new Date(parseInt(n[1],10),parseInt(n[2],10)*3-1,1)).getTime():i?(new Date(parseInt(i[1],10),parseInt(i[2],10)-1,1)).getTime():s?(new Date(parseInt(s[1],10),parseInt(s[2],10)-1,parseInt(s[3],10))).getTime():u?(l=new Date(parseInt(u[1],10),0,1),l.getDay()!==4&&l.setMonth(0,1+(4-l.getDay()+7)%7),l.getTime()+parseInt(u[2],10)*6048e5):a?a[6]?(o=0,a[6]!=="Z"&&(o=parseInt(a[8],10)*60+parseInt(a[9],10),a[7]==="+"&&(o=0-o)),Date.UTC(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10)+o)):(new Date(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10))).getTime():f?(c=parseFloat(f[6]),t=Math.floor(c),r=Math.round((c-t)*1e3),f[8]?(o=0,f[8]!=="Z"&&(o=parseInt(f[10],10)*60+parseInt(f[11],10),f[9]==="+"&&(o=0-o)),Date.UTC(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10)+o,t,r)):(new Date(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10),t,r)).getTime()):(new Date(parseInt(e,10),0,1)).getTime())},t.labelSeries=function(n,r,i,s,o){var u,a,f,l,c,h,p,d,v,m,g;f=200*(r-n)/i,a=new Date(n),p=t.LABEL_SPECS[s];if(p===void 0){g=t.AUTO_LABEL_ORDER;for(v=0,m=g.length;v=h.span){p=h;break}}}p===void 0&&(p=t.LABEL_SPECS.second),o&&(p=e.extend({},p,{fmt:o})),u=p.start(a),c=[];while((d=u.getTime())<=r)d>=n&&c.push([p.fmt(u),d]),p.incr(u);return c},n=function(e){return{span:e*60*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())},incr:function(t){return t.setMinutes(t.getMinutes()+e)}}},r=function(e){return{span:e*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())+":"+t.pad2(e.getSeconds())},incr:function(t){return t.setSeconds(t.getSeconds()+e)}}},t.LABEL_SPECS={year:{span:1728e7,start:function(e){return new Date(e.getFullYear(),0,1)},fmt:function(e){return""+e.getFullYear()},incr:function(e){return e.setFullYear(e.getFullYear()+1)}},month:{span:24192e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),1)},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)},incr:function(e){return e.setMonth(e.getMonth()+1)}},day:{span:864e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)+"-"+t.pad2(e.getDate())},incr:function(e){return e.setDate(e.getDate()+1)}},hour:n(60),"30min":n(30),"15min":n(15),"10min":n(10),"5min":n(5),minute:n(1),"30sec":r(30),"15sec":r(15),"10sec":r(10),"5sec":r(5),second:r(1)},t.AUTO_LABEL_ORDER=["year","month","day","hour","30min","15min","10min","5min","minute","30sec","15sec","10sec","5sec","second"]}).call(this); \ No newline at end of file +(function(){var e,t,n,r,i=[].slice,s=function(e,t){return function(){return e.apply(t,arguments)}},o={}.hasOwnProperty,u=function(e,t){function r(){this.constructor=e}for(var n in t)o.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};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;rn.length&&(r+=i.slice(n.length)),r)},t.pad2=function(e){return(e<10?"0":"")+e},t.Donut=function(){function n(n){this.select=s(this.select,this);if(!(this instanceof t.Donut))return new t.Donut(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element),this.options=e.extend({},this.defaults,n);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");if(n.data===void 0||n.data.length===0)return;this.data=n.data,this.el.addClass("graph-initialised"),this.redraw()}return n.prototype.defaults={colors:["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],formatter:t.commas},n.prototype.redraw=function(){var e,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x;this.el.empty(),this.r=new Raphael(this.el[0]),n=this.el.width()/2,r=this.el.height()/2,h=(Math.min(n,r)-10)/3,c=0,w=this.data;for(d=0,g=w.length;dMath.PI?1:0,this.path=this.calcSegment(this.inner+3,this.inner+this.outer-5),this.selectedPath=this.calcSegment(this.inner+3,this.inner+this.outer),this.hilight=this.calcArc(this.inner)}return u(t,e),t.prototype.calcArcPoints=function(e){return[this.cx+e*this.sin_p0,this.cy+e*this.cos_p0,this.cx+e*this.sin_p1,this.cy+e*this.cos_p1]},t.prototype.calcSegment=function(e,t){var n,r,i,s,o,u,a,f,l,c;return l=this.calcArcPoints(e),n=l[0],i=l[1],r=l[2],s=l[3],c=this.calcArcPoints(t),o=c[0],a=c[1],u=c[2],f=c[3],"M"+n+","+i+("A"+e+","+e+",0,"+this.long+",0,"+r+","+s)+("L"+u+","+f)+("A"+t+","+t+",0,"+this.long+",1,"+o+","+a)+"Z"},t.prototype.calcArc=function(e){var t,n,r,i,s;return s=this.calcArcPoints(e),t=s[0],r=s[1],n=s[2],i=s[3],"M"+t+","+r+("A"+e+","+e+",0,"+this.long+",0,"+n+","+i)},t.prototype.render=function(e){var t=this;return this.arc=e.path(this.hilight).attr({stroke:this.color,"stroke-width":2,opacity:0}),this.seg=e.path(this.path).attr({fill:this.color,stroke:"white","stroke-width":3}).hover(function(){return t.fire("hover",t)})},t.prototype.select=function(){if(!this.selected)return this.seg.animate({path:this.selectedPath},150,"<>"),this.arc.animate({opacity:1},150,"<>"),this.selected=!0},t.prototype.deselect=function(){if(this.selected)return this.seg.animate({path:this.path},150,"<>"),this.arc.animate({opacity:0},150,"<>"),this.selected=!1},t}(t.EventEmitter),t.Line=function(){function n(n){this.updateHilight=s(this.updateHilight,this),this.hilight=s(this.hilight,this),this.updateHover=s(this.updateHover,this),this.transY=s(this.transY,this),this.transX=s(this.transX,this);var r,i=this;if(!(this instanceof t.Line))return new t.Line(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");this.options=e.extend({},this.defaults,n),typeof this.options.units=="string"&&(this.options.postUnits=n.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(e){return i.updateHilight(e.pageX)}),this.options.hideHover&&this.el.mouseout(function(e){return i.hilight(null)}),r=function(e){var t;return t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],i.updateHilight(t.pageX),t},this.el.bind("touchstart",r),this.el.bind("touchmove",r),this.el.bind("touchend",r),this.seriesLabels=this.options.labels,this.setData(this.options.data)}return n.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(e){return(new Date(e)).toString()},xLabels:"auto",xLabelFormat:null},n.prototype.setData=function(n,r){var i,s,o,u,a,f,l,c,h,p,d,v,m,g,y=this;r==null&&(r=!0),this.options.data=n.slice(0),this.options.data.sort(function(e,t){return(e[y.options.xkey]=0;m<=0?e++:e--)g.push(e);return g}.apply(this),this.options.parseTime&&(this.columnLabels=e.map(this.columnLabels,function(e){return typeof e=="number"?y.options.dateFormat(e):e})),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"?(u=Math.max.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymax.length>5?this.ymax=Math.max(parseInt(this.options.ymax.slice(5),10),u):this.ymax=u):typeof this.options.ymax=="string"?this.ymax=parseInt(this.options.ymax,10):this.ymax=this.options.ymax,typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"?(a=Math.min.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymin.length>5?this.ymin=Math.min(parseInt(this.options.ymin.slice(5),10),a):this.ymin=a):typeof this.options.ymin=="string"?this.ymin=parseInt(this.options.ymin,10):this.ymin=this.options.ymin,this.ymin===this.ymax&&(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()},n.prototype.calc=function(){var t,n,r,i,s,o,u,a,f=this;i=this.el.width(),t=this.el.height();if(this.elementWidth!==i||this.elementHeight!==t||this.dirty){this.elementWidth=i,this.elementHeight=t,this.dirty=!1,this.maxYLabelWidth=Math.max(this.measureText(this.yLabelFormat(this.ymin),this.options.gridTextSize).width,this.measureText(this.yLabelFormat(this.ymax),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.ymax-this.ymin),this.columns=function(){var e,t,n,r;n=this.xvals,r=[];for(e=0,t=n.length;e=o;u=p+=g)f=parseFloat(u.toFixed(this.precision)),c=this.transY(f),this.r.text(this.left-this.options.marginLeft/2,c,this.yLabelFormat(f)).attr("font-size",this.options.gridTextSize).attr("fill",this.options.gridTextColor).attr("text-anchor","end"),this.r.path("M"+this.left+","+c+"H"+(this.left+this.width)).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth);h=this.options.marginTop+this.height+this.options.marginBottom/2,l=50,a=null,e=function(e,t){var n,r;return n=S.r.text(S.transX(t),h,e).attr("font-size",S.options.gridTextSize).attr("fill",S.options.gridTextColor),r=n.getBBox(),(a===null||a<=r.x)&&r.x>=0&&r.x+r.width=b;r=0<=b?++v:--v)s=this.columnLabels[this.columnLabels.length-r-1],E.push(e(s,r));return E},n.prototype.drawSeries=function(){var t,n,r,i,s,o,u,a,f,l;for(i=o=a=this.seriesCoords.length-1;a<=0?o<=0:o>=0;i=a<=0?++o:--o)r=e.map(this.seriesCoords[i],function(e){return e}),r.length>1&&(s=this.createPath(r,this.options.marginTop,this.left,this.options.marginTop+this.height,this.left+this.width),this.r.path(s).attr("stroke",this.options.lineColors[i]).attr("stroke-width",this.options.lineWidth));this.seriesPoints=function(){var e,t,n;n=[];for(i=e=0,t=this.seriesCoords.length-1;0<=t?e<=t:e>=t;i=0<=t?++e:--e)n.push([]);return n}.call(this),l=[];for(i=u=f=this.seriesCoords.length-1;f<=0?u<=0:u>=0;i=f<=0?++u:--u)l.push(function(){var e,r,s,o;s=this.seriesCoords[i],o=[];for(e=0,r=s.length;e=b;f=0<=b?++y:--y)o=t[f],f===0?p+="M"+o.x+","+o.y:(u=a[f],c=t[f-1],h=a[f-1],l=(o.x-c.x)/4,d=c.x+l,m=Math.min(i,c.y+l*h),v=o.x-l,g=Math.min(i,o.y-l*u),p+="C"+d+","+m+","+v+","+g+","+o.x+","+o.y)}else p="M"+e.map(t,function(e){return""+e.x+","+e.y}).join("L");return p},n.prototype.gradients=function(t){return e.map(t,function(e,n){return n===0?(t[1].y-e.y)/(t[1].x-e.x):n===t.length-1?(e.y-t[n-1].y)/(e.x-t[n-1].x):(t[n+1].y-t[n-1].y)/(t[n+1].x-t[n-1].x)})},n.prototype.drawHover=function(){var e,t,n,r,i;this.hoverHeight=this.options.hoverFontSize*1.5*(this.series.length+1),this.hover=this.r.rect(-10,-this.hoverHeight/2-this.options.hoverPaddingY,20,this.hoverHeight+this.options.hoverPaddingY*2,10).attr("fill",this.options.hoverFillColor).attr("stroke",this.options.hoverBorderColor).attr("stroke-width",this.options.hoverBorderWidth).attr("opacity",this.options.hoverOpacity),this.xLabel=this.r.text(0,this.options.hoverFontSize*.75-this.hoverHeight/2,"").attr("fill",this.options.hoverLabelColor).attr("font-weight","bold").attr("font-size",this.options.hoverFontSize),this.hoverSet=this.r.set(),this.hoverSet.push(this.hover),this.hoverSet.push(this.xLabel),this.yLabels=[],i=[];for(e=n=0,r=this.series.length-1;0<=r?n<=r:n>=r;e=0<=r?++n:--n)t=this.r.text(0,this.options.hoverFontSize*1.5*(e+1.5)-this.hoverHeight/2,"").attr("fill",this.options.lineColors[e]).attr("font-size",this.options.hoverFontSize),this.yLabels.push(t),i.push(this.hoverSet.push(t));return i},n.prototype.updateHover=function(t){var n,r,i,s,o,u,a=this;this.hoverSet.show(),this.xLabel.attr("text",this.columnLabels[t]);for(n=o=0,u=this.series.length-1;0<=u?o<=u:o>=u;n=0<=u?++o:--o)this.yLabels[n].attr("text",""+this.seriesLabels[n]+": "+this.yLabelFormat(this.series[n][t]));return r=Math.max.apply(null,e.map(this.yLabels,function(e){return e.getBBox().width})),r=Math.max(r,this.xLabel.getBBox().width),this.hover.attr("width",r+this.options.hoverPaddingX*2),this.hover.attr("x",-this.options.hoverPaddingX-r/2),s=Math.min.apply(null,e.map(this.series,function(e){return a.transY(e[t])})),s>this.hoverHeight+this.options.hoverPaddingY*2+this.options.hoverMargin+this.options.marginTop?s=s-this.hoverHeight/2-this.options.hoverPaddingY-this.options.hoverMargin:s=s+this.hoverHeight/2+this.options.hoverPaddingY+this.options.hoverMargin,s=Math.max(this.options.marginTop+this.hoverHeight/2+this.options.hoverPaddingY,s),s=Math.min(this.options.marginTop+this.height-this.hoverHeight/2-this.options.hoverPaddingY,s),i=Math.min(this.left+this.width-r/2-this.options.hoverPaddingX,this.columns[t]),i=Math.max(this.left+r/2+this.options.hoverPaddingX,i),this.hoverSet.attr("transform","t"+i+","+s)},n.prototype.hideHover=function(){return this.hoverSet.hide()},n.prototype.hilight=function(e){var t,n,r,i,s;if(this.prevHilight!==null&&this.prevHilight!==e)for(t=n=0,i=this.seriesPoints.length-1;0<=i?n<=i:n>=i;t=0<=i?++n:--n)this.seriesPoints[t][this.prevHilight]&&this.seriesPoints[t][this.prevHilight].animate(this.pointShrink);if(e!==null&&this.prevHilight!==e){for(t=r=0,s=this.seriesPoints.length-1;0<=s?r<=s:r>=s;t=0<=s?++r:--r)this.seriesPoints[t][e]&&this.seriesPoints[t][e].animate(this.pointGrow);this.updateHover(e)}this.prevHilight=e;if(e===null)return this.hideHover()},n.prototype.updateHilight=function(e){var t,n,r,i;e-=this.el.offset().left,i=[];for(t=n=r=this.hoverMargins.length;r<=0?n<=0:n>=0;t=r<=0?++n:--n){if(t===0||this.hoverMargins[t-1]>e){this.hilight(t);break}i.push(void 0)}return i},n.prototype.measureText=function(e,t){var n,r;return t==null&&(t=12),r=this.r.text(100,100,e).attr("font-size",t),n=r.getBBox(),r.remove(),n},n.prototype.yLabelFormat=function(e){return""+this.options.preUnits+t.commas(e)+this.options.postUnits},n}(),t.parseDate=function(e){var t,n,r,i,s,o,u,a,f,l,c;return typeof e=="number"?e:(n=e.match(/^(\d+) Q(\d)$/),i=e.match(/^(\d+)-(\d+)$/),s=e.match(/^(\d+)-(\d+)-(\d+)$/),u=e.match(/^(\d+) W(\d+)$/),a=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/),f=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/),n?(new Date(parseInt(n[1],10),parseInt(n[2],10)*3-1,1)).getTime():i?(new Date(parseInt(i[1],10),parseInt(i[2],10)-1,1)).getTime():s?(new Date(parseInt(s[1],10),parseInt(s[2],10)-1,parseInt(s[3],10))).getTime():u?(l=new Date(parseInt(u[1],10),0,1),l.getDay()!==4&&l.setMonth(0,1+(4-l.getDay()+7)%7),l.getTime()+parseInt(u[2],10)*6048e5):a?a[6]?(o=0,a[6]!=="Z"&&(o=parseInt(a[8],10)*60+parseInt(a[9],10),a[7]==="+"&&(o=0-o)),Date.UTC(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10)+o)):(new Date(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10))).getTime():f?(c=parseFloat(f[6]),t=Math.floor(c),r=Math.round((c-t)*1e3),f[8]?(o=0,f[8]!=="Z"&&(o=parseInt(f[10],10)*60+parseInt(f[11],10),f[9]==="+"&&(o=0-o)),Date.UTC(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10)+o,t,r)):(new Date(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10),t,r)).getTime()):(new Date(parseInt(e,10),0,1)).getTime())},t.labelSeries=function(n,r,i,s,o){var u,a,f,l,c,h,p,d,v,m,g;f=200*(r-n)/i,a=new Date(n),p=t.LABEL_SPECS[s];if(p===void 0){g=t.AUTO_LABEL_ORDER;for(v=0,m=g.length;v=h.span){p=h;break}}}p===void 0&&(p=t.LABEL_SPECS.second),o&&(p=e.extend({},p,{fmt:o})),u=p.start(a),c=[];while((d=u.getTime())<=r)d>=n&&c.push([p.fmt(u),d]),p.incr(u);return c},n=function(e){return{span:e*60*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())},incr:function(t){return t.setMinutes(t.getMinutes()+e)}}},r=function(e){return{span:e*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())+":"+t.pad2(e.getSeconds())},incr:function(t){return t.setSeconds(t.getSeconds()+e)}}},t.LABEL_SPECS={year:{span:1728e7,start:function(e){return new Date(e.getFullYear(),0,1)},fmt:function(e){return""+e.getFullYear()},incr:function(e){return e.setFullYear(e.getFullYear()+1)}},month:{span:24192e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),1)},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)},incr:function(e){return e.setMonth(e.getMonth()+1)}},day:{span:864e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)+"-"+t.pad2(e.getDate())},incr:function(e){return e.setDate(e.getDate()+1)}},hour:n(60),"30min":n(30),"15min":n(15),"10min":n(10),"5min":n(5),minute:n(1),"30sec":r(30),"15sec":r(15),"10sec":r(10),"5sec":r(5),second:r(1)},t.AUTO_LABEL_ORDER=["year","month","day","hour","30min","15min","10min","5min","minute","30sec","15sec","10sec","5sec","second"]}).call(this); \ No newline at end of file From 04e103e5ab33b6817a9512862869fe2ea3b30a67 Mon Sep 17 00:00:00 2001 From: Olly Smith Date: Thu, 20 Sep 2012 07:45:04 +0100 Subject: [PATCH 2/5] Update travis.yml --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 00963c8..5d1cad3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: node_js node_js: - - 0.6 + - 0.8 before_script: - - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" - "npm install -g grunt" - "npm install" script: - - "DISPLAY=:99.0 grunt" + - "grunt" From abd26559abac5467ae63323fa564e3d47a7a8541 Mon Sep 17 00:00:00 2001 From: Olly Smith Date: Thu, 20 Sep 2012 08:03:35 +0100 Subject: [PATCH 3/5] Travis.yml tweak --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5d1cad3..9eec261 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ before_script: - "npm install -g grunt" - "npm install" script: - - "grunt" + - "grunt mocha" From 50833b0ebcb0268f438746cfa30f64c56cea8e69 Mon Sep 17 00:00:00 2001 From: Olly Smith Date: Thu, 20 Sep 2012 08:06:18 +0100 Subject: [PATCH 4/5] Another Travis.yml tweak --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9eec261..7c6926d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ before_script: - "npm install -g grunt" - "npm install" script: - - "grunt mocha" + - "grunt coffee mocha" From a9b0e03b4351bb6048c49aebe32f2f5f515ced70 Mon Sep 17 00:00:00 2001 From: Olly Smith Date: Tue, 25 Sep 2012 21:07:32 +0100 Subject: [PATCH 5/5] Cycle lineColors (#78) Fixes crashes when number of series is larger than number of line colors. --- lib/morris.line.coffee | 10 +++++++--- morris.js | 10 +++++++--- morris.min.js | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/morris.line.coffee b/lib/morris.line.coffee index 8c170fd..fcbb57c 100644 --- a/lib/morris.line.coffee +++ b/lib/morris.line.coffee @@ -283,7 +283,7 @@ class Morris.Line if coords.length > 1 path = @createPath coords, @options.marginTop, @left, @options.marginTop + @height, @left + @width @r.path(path) - .attr('stroke', @options.lineColors[i]) + .attr('stroke', @colorForSeries(i)) .attr('stroke-width', @options.lineWidth) @seriesPoints = ([] for i in [0..@seriesCoords.length-1]) for i in [@seriesCoords.length-1..0] @@ -292,7 +292,7 @@ class Morris.Line circle = null else circle = @r.circle(c.x, c.y, @options.pointSize) - .attr('fill', @options.lineColors[i]) + .attr('fill', @colorForSeries(i)) .attr('stroke-width', 1) .attr('stroke', '#ffffff') @seriesPoints[i].push(circle) @@ -355,7 +355,7 @@ class Morris.Line @yLabels = [] for i in [0..@series.length-1] yLabel = @r.text(0, @options.hoverFontSize * 1.5 * (i + 1.5) - @hoverHeight / 2, '') - .attr('fill', @options.lineColors[i]) + .attr('fill', @colorForSeries(i)) .attr('font-size', @options.hoverFontSize) @yLabels.push(yLabel) @hoverSet.push(yLabel) @@ -423,6 +423,10 @@ class Morris.Line yLabelFormat: (label) -> "#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}" + # @private + colorForSeries: (index) -> + @options.lineColors[index % @options.lineColors.length] + # Parse a date into a javascript timestamp # diff --git a/morris.js b/morris.js index f65e999..e218a14 100644 --- a/morris.js +++ b/morris.js @@ -603,7 +603,7 @@ }); if (coords.length > 1) { path = this.createPath(coords, this.options.marginTop, this.left, this.options.marginTop + this.height, this.left + this.width); - this.r.path(path).attr('stroke', this.options.lineColors[i]).attr('stroke-width', this.options.lineWidth); + this.r.path(path).attr('stroke', this.colorForSeries(i)).attr('stroke-width', this.options.lineWidth); } } this.seriesPoints = (function() { @@ -625,7 +625,7 @@ if (c === null) { circle = null; } else { - circle = this.r.circle(c.x, c.y, this.options.pointSize).attr('fill', this.options.lineColors[i]).attr('stroke-width', 1).attr('stroke', '#ffffff'); + circle = this.r.circle(c.x, c.y, this.options.pointSize).attr('fill', this.colorForSeries(i)).attr('stroke-width', 1).attr('stroke', '#ffffff'); } _results1.push(this.seriesPoints[i].push(circle)); } @@ -687,7 +687,7 @@ this.yLabels = []; _results = []; for (i = _i = 0, _ref = this.series.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { - yLabel = this.r.text(0, this.options.hoverFontSize * 1.5 * (i + 1.5) - this.hoverHeight / 2, '').attr('fill', this.options.lineColors[i]).attr('font-size', this.options.hoverFontSize); + yLabel = this.r.text(0, this.options.hoverFontSize * 1.5 * (i + 1.5) - this.hoverHeight / 2, '').attr('fill', this.colorForSeries(i)).attr('font-size', this.options.hoverFontSize); this.yLabels.push(yLabel); _results.push(this.hoverSet.push(yLabel)); } @@ -780,6 +780,10 @@ return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits; }; + Line.prototype.colorForSeries = function(index) { + return this.options.lineColors[index % this.options.lineColors.length]; + }; + return Line; })(); diff --git a/morris.min.js b/morris.min.js index 0bfcb1d..73a0327 100644 --- a/morris.min.js +++ b/morris.min.js @@ -1 +1 @@ -(function(){var e,t,n,r,i=[].slice,s=function(e,t){return function(){return e.apply(t,arguments)}},o={}.hasOwnProperty,u=function(e,t){function r(){this.constructor=e}for(var n in t)o.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};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;rn.length&&(r+=i.slice(n.length)),r)},t.pad2=function(e){return(e<10?"0":"")+e},t.Donut=function(){function n(n){this.select=s(this.select,this);if(!(this instanceof t.Donut))return new t.Donut(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element),this.options=e.extend({},this.defaults,n);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");if(n.data===void 0||n.data.length===0)return;this.data=n.data,this.el.addClass("graph-initialised"),this.redraw()}return n.prototype.defaults={colors:["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],formatter:t.commas},n.prototype.redraw=function(){var e,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x;this.el.empty(),this.r=new Raphael(this.el[0]),n=this.el.width()/2,r=this.el.height()/2,h=(Math.min(n,r)-10)/3,c=0,w=this.data;for(d=0,g=w.length;dMath.PI?1:0,this.path=this.calcSegment(this.inner+3,this.inner+this.outer-5),this.selectedPath=this.calcSegment(this.inner+3,this.inner+this.outer),this.hilight=this.calcArc(this.inner)}return u(t,e),t.prototype.calcArcPoints=function(e){return[this.cx+e*this.sin_p0,this.cy+e*this.cos_p0,this.cx+e*this.sin_p1,this.cy+e*this.cos_p1]},t.prototype.calcSegment=function(e,t){var n,r,i,s,o,u,a,f,l,c;return l=this.calcArcPoints(e),n=l[0],i=l[1],r=l[2],s=l[3],c=this.calcArcPoints(t),o=c[0],a=c[1],u=c[2],f=c[3],"M"+n+","+i+("A"+e+","+e+",0,"+this.long+",0,"+r+","+s)+("L"+u+","+f)+("A"+t+","+t+",0,"+this.long+",1,"+o+","+a)+"Z"},t.prototype.calcArc=function(e){var t,n,r,i,s;return s=this.calcArcPoints(e),t=s[0],r=s[1],n=s[2],i=s[3],"M"+t+","+r+("A"+e+","+e+",0,"+this.long+",0,"+n+","+i)},t.prototype.render=function(e){var t=this;return this.arc=e.path(this.hilight).attr({stroke:this.color,"stroke-width":2,opacity:0}),this.seg=e.path(this.path).attr({fill:this.color,stroke:"white","stroke-width":3}).hover(function(){return t.fire("hover",t)})},t.prototype.select=function(){if(!this.selected)return this.seg.animate({path:this.selectedPath},150,"<>"),this.arc.animate({opacity:1},150,"<>"),this.selected=!0},t.prototype.deselect=function(){if(this.selected)return this.seg.animate({path:this.path},150,"<>"),this.arc.animate({opacity:0},150,"<>"),this.selected=!1},t}(t.EventEmitter),t.Line=function(){function n(n){this.updateHilight=s(this.updateHilight,this),this.hilight=s(this.hilight,this),this.updateHover=s(this.updateHover,this),this.transY=s(this.transY,this),this.transX=s(this.transX,this);var r,i=this;if(!(this instanceof t.Line))return new t.Line(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");this.options=e.extend({},this.defaults,n),typeof this.options.units=="string"&&(this.options.postUnits=n.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(e){return i.updateHilight(e.pageX)}),this.options.hideHover&&this.el.mouseout(function(e){return i.hilight(null)}),r=function(e){var t;return t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],i.updateHilight(t.pageX),t},this.el.bind("touchstart",r),this.el.bind("touchmove",r),this.el.bind("touchend",r),this.seriesLabels=this.options.labels,this.setData(this.options.data)}return n.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(e){return(new Date(e)).toString()},xLabels:"auto",xLabelFormat:null},n.prototype.setData=function(n,r){var i,s,o,u,a,f,l,c,h,p,d,v,m,g,y=this;r==null&&(r=!0),this.options.data=n.slice(0),this.options.data.sort(function(e,t){return(e[y.options.xkey]=0;m<=0?e++:e--)g.push(e);return g}.apply(this),this.options.parseTime&&(this.columnLabels=e.map(this.columnLabels,function(e){return typeof e=="number"?y.options.dateFormat(e):e})),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"?(u=Math.max.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymax.length>5?this.ymax=Math.max(parseInt(this.options.ymax.slice(5),10),u):this.ymax=u):typeof this.options.ymax=="string"?this.ymax=parseInt(this.options.ymax,10):this.ymax=this.options.ymax,typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"?(a=Math.min.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymin.length>5?this.ymin=Math.min(parseInt(this.options.ymin.slice(5),10),a):this.ymin=a):typeof this.options.ymin=="string"?this.ymin=parseInt(this.options.ymin,10):this.ymin=this.options.ymin,this.ymin===this.ymax&&(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()},n.prototype.calc=function(){var t,n,r,i,s,o,u,a,f=this;i=this.el.width(),t=this.el.height();if(this.elementWidth!==i||this.elementHeight!==t||this.dirty){this.elementWidth=i,this.elementHeight=t,this.dirty=!1,this.maxYLabelWidth=Math.max(this.measureText(this.yLabelFormat(this.ymin),this.options.gridTextSize).width,this.measureText(this.yLabelFormat(this.ymax),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.ymax-this.ymin),this.columns=function(){var e,t,n,r;n=this.xvals,r=[];for(e=0,t=n.length;e=o;u=p+=g)f=parseFloat(u.toFixed(this.precision)),c=this.transY(f),this.r.text(this.left-this.options.marginLeft/2,c,this.yLabelFormat(f)).attr("font-size",this.options.gridTextSize).attr("fill",this.options.gridTextColor).attr("text-anchor","end"),this.r.path("M"+this.left+","+c+"H"+(this.left+this.width)).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth);h=this.options.marginTop+this.height+this.options.marginBottom/2,l=50,a=null,e=function(e,t){var n,r;return n=S.r.text(S.transX(t),h,e).attr("font-size",S.options.gridTextSize).attr("fill",S.options.gridTextColor),r=n.getBBox(),(a===null||a<=r.x)&&r.x>=0&&r.x+r.width=b;r=0<=b?++v:--v)s=this.columnLabels[this.columnLabels.length-r-1],E.push(e(s,r));return E},n.prototype.drawSeries=function(){var t,n,r,i,s,o,u,a,f,l;for(i=o=a=this.seriesCoords.length-1;a<=0?o<=0:o>=0;i=a<=0?++o:--o)r=e.map(this.seriesCoords[i],function(e){return e}),r.length>1&&(s=this.createPath(r,this.options.marginTop,this.left,this.options.marginTop+this.height,this.left+this.width),this.r.path(s).attr("stroke",this.options.lineColors[i]).attr("stroke-width",this.options.lineWidth));this.seriesPoints=function(){var e,t,n;n=[];for(i=e=0,t=this.seriesCoords.length-1;0<=t?e<=t:e>=t;i=0<=t?++e:--e)n.push([]);return n}.call(this),l=[];for(i=u=f=this.seriesCoords.length-1;f<=0?u<=0:u>=0;i=f<=0?++u:--u)l.push(function(){var e,r,s,o;s=this.seriesCoords[i],o=[];for(e=0,r=s.length;e=b;f=0<=b?++y:--y)o=t[f],f===0?p+="M"+o.x+","+o.y:(u=a[f],c=t[f-1],h=a[f-1],l=(o.x-c.x)/4,d=c.x+l,m=Math.min(i,c.y+l*h),v=o.x-l,g=Math.min(i,o.y-l*u),p+="C"+d+","+m+","+v+","+g+","+o.x+","+o.y)}else p="M"+e.map(t,function(e){return""+e.x+","+e.y}).join("L");return p},n.prototype.gradients=function(t){return e.map(t,function(e,n){return n===0?(t[1].y-e.y)/(t[1].x-e.x):n===t.length-1?(e.y-t[n-1].y)/(e.x-t[n-1].x):(t[n+1].y-t[n-1].y)/(t[n+1].x-t[n-1].x)})},n.prototype.drawHover=function(){var e,t,n,r,i;this.hoverHeight=this.options.hoverFontSize*1.5*(this.series.length+1),this.hover=this.r.rect(-10,-this.hoverHeight/2-this.options.hoverPaddingY,20,this.hoverHeight+this.options.hoverPaddingY*2,10).attr("fill",this.options.hoverFillColor).attr("stroke",this.options.hoverBorderColor).attr("stroke-width",this.options.hoverBorderWidth).attr("opacity",this.options.hoverOpacity),this.xLabel=this.r.text(0,this.options.hoverFontSize*.75-this.hoverHeight/2,"").attr("fill",this.options.hoverLabelColor).attr("font-weight","bold").attr("font-size",this.options.hoverFontSize),this.hoverSet=this.r.set(),this.hoverSet.push(this.hover),this.hoverSet.push(this.xLabel),this.yLabels=[],i=[];for(e=n=0,r=this.series.length-1;0<=r?n<=r:n>=r;e=0<=r?++n:--n)t=this.r.text(0,this.options.hoverFontSize*1.5*(e+1.5)-this.hoverHeight/2,"").attr("fill",this.options.lineColors[e]).attr("font-size",this.options.hoverFontSize),this.yLabels.push(t),i.push(this.hoverSet.push(t));return i},n.prototype.updateHover=function(t){var n,r,i,s,o,u,a=this;this.hoverSet.show(),this.xLabel.attr("text",this.columnLabels[t]);for(n=o=0,u=this.series.length-1;0<=u?o<=u:o>=u;n=0<=u?++o:--o)this.yLabels[n].attr("text",""+this.seriesLabels[n]+": "+this.yLabelFormat(this.series[n][t]));return r=Math.max.apply(null,e.map(this.yLabels,function(e){return e.getBBox().width})),r=Math.max(r,this.xLabel.getBBox().width),this.hover.attr("width",r+this.options.hoverPaddingX*2),this.hover.attr("x",-this.options.hoverPaddingX-r/2),s=Math.min.apply(null,e.map(this.series,function(e){return a.transY(e[t])})),s>this.hoverHeight+this.options.hoverPaddingY*2+this.options.hoverMargin+this.options.marginTop?s=s-this.hoverHeight/2-this.options.hoverPaddingY-this.options.hoverMargin:s=s+this.hoverHeight/2+this.options.hoverPaddingY+this.options.hoverMargin,s=Math.max(this.options.marginTop+this.hoverHeight/2+this.options.hoverPaddingY,s),s=Math.min(this.options.marginTop+this.height-this.hoverHeight/2-this.options.hoverPaddingY,s),i=Math.min(this.left+this.width-r/2-this.options.hoverPaddingX,this.columns[t]),i=Math.max(this.left+r/2+this.options.hoverPaddingX,i),this.hoverSet.attr("transform","t"+i+","+s)},n.prototype.hideHover=function(){return this.hoverSet.hide()},n.prototype.hilight=function(e){var t,n,r,i,s;if(this.prevHilight!==null&&this.prevHilight!==e)for(t=n=0,i=this.seriesPoints.length-1;0<=i?n<=i:n>=i;t=0<=i?++n:--n)this.seriesPoints[t][this.prevHilight]&&this.seriesPoints[t][this.prevHilight].animate(this.pointShrink);if(e!==null&&this.prevHilight!==e){for(t=r=0,s=this.seriesPoints.length-1;0<=s?r<=s:r>=s;t=0<=s?++r:--r)this.seriesPoints[t][e]&&this.seriesPoints[t][e].animate(this.pointGrow);this.updateHover(e)}this.prevHilight=e;if(e===null)return this.hideHover()},n.prototype.updateHilight=function(e){var t,n,r,i;e-=this.el.offset().left,i=[];for(t=n=r=this.hoverMargins.length;r<=0?n<=0:n>=0;t=r<=0?++n:--n){if(t===0||this.hoverMargins[t-1]>e){this.hilight(t);break}i.push(void 0)}return i},n.prototype.measureText=function(e,t){var n,r;return t==null&&(t=12),r=this.r.text(100,100,e).attr("font-size",t),n=r.getBBox(),r.remove(),n},n.prototype.yLabelFormat=function(e){return""+this.options.preUnits+t.commas(e)+this.options.postUnits},n}(),t.parseDate=function(e){var t,n,r,i,s,o,u,a,f,l,c;return typeof e=="number"?e:(n=e.match(/^(\d+) Q(\d)$/),i=e.match(/^(\d+)-(\d+)$/),s=e.match(/^(\d+)-(\d+)-(\d+)$/),u=e.match(/^(\d+) W(\d+)$/),a=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/),f=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/),n?(new Date(parseInt(n[1],10),parseInt(n[2],10)*3-1,1)).getTime():i?(new Date(parseInt(i[1],10),parseInt(i[2],10)-1,1)).getTime():s?(new Date(parseInt(s[1],10),parseInt(s[2],10)-1,parseInt(s[3],10))).getTime():u?(l=new Date(parseInt(u[1],10),0,1),l.getDay()!==4&&l.setMonth(0,1+(4-l.getDay()+7)%7),l.getTime()+parseInt(u[2],10)*6048e5):a?a[6]?(o=0,a[6]!=="Z"&&(o=parseInt(a[8],10)*60+parseInt(a[9],10),a[7]==="+"&&(o=0-o)),Date.UTC(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10)+o)):(new Date(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10))).getTime():f?(c=parseFloat(f[6]),t=Math.floor(c),r=Math.round((c-t)*1e3),f[8]?(o=0,f[8]!=="Z"&&(o=parseInt(f[10],10)*60+parseInt(f[11],10),f[9]==="+"&&(o=0-o)),Date.UTC(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10)+o,t,r)):(new Date(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10),t,r)).getTime()):(new Date(parseInt(e,10),0,1)).getTime())},t.labelSeries=function(n,r,i,s,o){var u,a,f,l,c,h,p,d,v,m,g;f=200*(r-n)/i,a=new Date(n),p=t.LABEL_SPECS[s];if(p===void 0){g=t.AUTO_LABEL_ORDER;for(v=0,m=g.length;v=h.span){p=h;break}}}p===void 0&&(p=t.LABEL_SPECS.second),o&&(p=e.extend({},p,{fmt:o})),u=p.start(a),c=[];while((d=u.getTime())<=r)d>=n&&c.push([p.fmt(u),d]),p.incr(u);return c},n=function(e){return{span:e*60*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())},incr:function(t){return t.setMinutes(t.getMinutes()+e)}}},r=function(e){return{span:e*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())+":"+t.pad2(e.getSeconds())},incr:function(t){return t.setSeconds(t.getSeconds()+e)}}},t.LABEL_SPECS={year:{span:1728e7,start:function(e){return new Date(e.getFullYear(),0,1)},fmt:function(e){return""+e.getFullYear()},incr:function(e){return e.setFullYear(e.getFullYear()+1)}},month:{span:24192e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),1)},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)},incr:function(e){return e.setMonth(e.getMonth()+1)}},day:{span:864e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)+"-"+t.pad2(e.getDate())},incr:function(e){return e.setDate(e.getDate()+1)}},hour:n(60),"30min":n(30),"15min":n(15),"10min":n(10),"5min":n(5),minute:n(1),"30sec":r(30),"15sec":r(15),"10sec":r(10),"5sec":r(5),second:r(1)},t.AUTO_LABEL_ORDER=["year","month","day","hour","30min","15min","10min","5min","minute","30sec","15sec","10sec","5sec","second"]}).call(this); \ No newline at end of file +(function(){var e,t,n,r,i=[].slice,s=function(e,t){return function(){return e.apply(t,arguments)}},o={}.hasOwnProperty,u=function(e,t){function r(){this.constructor=e}for(var n in t)o.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};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;rn.length&&(r+=i.slice(n.length)),r)},t.pad2=function(e){return(e<10?"0":"")+e},t.Donut=function(){function n(n){this.select=s(this.select,this);if(!(this instanceof t.Donut))return new t.Donut(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element),this.options=e.extend({},this.defaults,n);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");if(n.data===void 0||n.data.length===0)return;this.data=n.data,this.el.addClass("graph-initialised"),this.redraw()}return n.prototype.defaults={colors:["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],formatter:t.commas},n.prototype.redraw=function(){var e,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x;this.el.empty(),this.r=new Raphael(this.el[0]),n=this.el.width()/2,r=this.el.height()/2,h=(Math.min(n,r)-10)/3,c=0,w=this.data;for(d=0,g=w.length;dMath.PI?1:0,this.path=this.calcSegment(this.inner+3,this.inner+this.outer-5),this.selectedPath=this.calcSegment(this.inner+3,this.inner+this.outer),this.hilight=this.calcArc(this.inner)}return u(t,e),t.prototype.calcArcPoints=function(e){return[this.cx+e*this.sin_p0,this.cy+e*this.cos_p0,this.cx+e*this.sin_p1,this.cy+e*this.cos_p1]},t.prototype.calcSegment=function(e,t){var n,r,i,s,o,u,a,f,l,c;return l=this.calcArcPoints(e),n=l[0],i=l[1],r=l[2],s=l[3],c=this.calcArcPoints(t),o=c[0],a=c[1],u=c[2],f=c[3],"M"+n+","+i+("A"+e+","+e+",0,"+this.long+",0,"+r+","+s)+("L"+u+","+f)+("A"+t+","+t+",0,"+this.long+",1,"+o+","+a)+"Z"},t.prototype.calcArc=function(e){var t,n,r,i,s;return s=this.calcArcPoints(e),t=s[0],r=s[1],n=s[2],i=s[3],"M"+t+","+r+("A"+e+","+e+",0,"+this.long+",0,"+n+","+i)},t.prototype.render=function(e){var t=this;return this.arc=e.path(this.hilight).attr({stroke:this.color,"stroke-width":2,opacity:0}),this.seg=e.path(this.path).attr({fill:this.color,stroke:"white","stroke-width":3}).hover(function(){return t.fire("hover",t)})},t.prototype.select=function(){if(!this.selected)return this.seg.animate({path:this.selectedPath},150,"<>"),this.arc.animate({opacity:1},150,"<>"),this.selected=!0},t.prototype.deselect=function(){if(this.selected)return this.seg.animate({path:this.path},150,"<>"),this.arc.animate({opacity:0},150,"<>"),this.selected=!1},t}(t.EventEmitter),t.Line=function(){function n(n){this.updateHilight=s(this.updateHilight,this),this.hilight=s(this.hilight,this),this.updateHover=s(this.updateHover,this),this.transY=s(this.transY,this),this.transX=s(this.transX,this);var r,i=this;if(!(this instanceof t.Line))return new t.Line(n);typeof n.element=="string"?this.el=e(document.getElementById(n.element)):this.el=e(n.element);if(this.el===null||this.el.length===0)throw new Error("Graph placeholder not found.");this.options=e.extend({},this.defaults,n),typeof this.options.units=="string"&&(this.options.postUnits=n.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(e){return i.updateHilight(e.pageX)}),this.options.hideHover&&this.el.mouseout(function(e){return i.hilight(null)}),r=function(e){var t;return t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],i.updateHilight(t.pageX),t},this.el.bind("touchstart",r),this.el.bind("touchmove",r),this.el.bind("touchend",r),this.seriesLabels=this.options.labels,this.setData(this.options.data)}return n.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(e){return(new Date(e)).toString()},xLabels:"auto",xLabelFormat:null},n.prototype.setData=function(n,r){var i,s,o,u,a,f,l,c,h,p,d,v,m,g,y=this;r==null&&(r=!0),this.options.data=n.slice(0),this.options.data.sort(function(e,t){return(e[y.options.xkey]=0;m<=0?e++:e--)g.push(e);return g}.apply(this),this.options.parseTime&&(this.columnLabels=e.map(this.columnLabels,function(e){return typeof e=="number"?y.options.dateFormat(e):e})),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"?(u=Math.max.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymax.length>5?this.ymax=Math.max(parseInt(this.options.ymax.slice(5),10),u):this.ymax=u):typeof this.options.ymax=="string"?this.ymax=parseInt(this.options.ymax,10):this.ymax=this.options.ymax,typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"?(a=Math.min.apply(null,Array.prototype.concat.apply([],this.series)),this.options.ymin.length>5?this.ymin=Math.min(parseInt(this.options.ymin.slice(5),10),a):this.ymin=a):typeof this.options.ymin=="string"?this.ymin=parseInt(this.options.ymin,10):this.ymin=this.options.ymin,this.ymin===this.ymax&&(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()},n.prototype.calc=function(){var t,n,r,i,s,o,u,a,f=this;i=this.el.width(),t=this.el.height();if(this.elementWidth!==i||this.elementHeight!==t||this.dirty){this.elementWidth=i,this.elementHeight=t,this.dirty=!1,this.maxYLabelWidth=Math.max(this.measureText(this.yLabelFormat(this.ymin),this.options.gridTextSize).width,this.measureText(this.yLabelFormat(this.ymax),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.ymax-this.ymin),this.columns=function(){var e,t,n,r;n=this.xvals,r=[];for(e=0,t=n.length;e=o;u=p+=g)f=parseFloat(u.toFixed(this.precision)),c=this.transY(f),this.r.text(this.left-this.options.marginLeft/2,c,this.yLabelFormat(f)).attr("font-size",this.options.gridTextSize).attr("fill",this.options.gridTextColor).attr("text-anchor","end"),this.r.path("M"+this.left+","+c+"H"+(this.left+this.width)).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth);h=this.options.marginTop+this.height+this.options.marginBottom/2,l=50,a=null,e=function(e,t){var n,r;return n=S.r.text(S.transX(t),h,e).attr("font-size",S.options.gridTextSize).attr("fill",S.options.gridTextColor),r=n.getBBox(),(a===null||a<=r.x)&&r.x>=0&&r.x+r.width=b;r=0<=b?++v:--v)s=this.columnLabels[this.columnLabels.length-r-1],E.push(e(s,r));return E},n.prototype.drawSeries=function(){var t,n,r,i,s,o,u,a,f,l;for(i=o=a=this.seriesCoords.length-1;a<=0?o<=0:o>=0;i=a<=0?++o:--o)r=e.map(this.seriesCoords[i],function(e){return e}),r.length>1&&(s=this.createPath(r,this.options.marginTop,this.left,this.options.marginTop+this.height,this.left+this.width),this.r.path(s).attr("stroke",this.colorForSeries(i)).attr("stroke-width",this.options.lineWidth));this.seriesPoints=function(){var e,t,n;n=[];for(i=e=0,t=this.seriesCoords.length-1;0<=t?e<=t:e>=t;i=0<=t?++e:--e)n.push([]);return n}.call(this),l=[];for(i=u=f=this.seriesCoords.length-1;f<=0?u<=0:u>=0;i=f<=0?++u:--u)l.push(function(){var e,r,s,o;s=this.seriesCoords[i],o=[];for(e=0,r=s.length;e=b;f=0<=b?++y:--y)o=t[f],f===0?p+="M"+o.x+","+o.y:(u=a[f],c=t[f-1],h=a[f-1],l=(o.x-c.x)/4,d=c.x+l,m=Math.min(i,c.y+l*h),v=o.x-l,g=Math.min(i,o.y-l*u),p+="C"+d+","+m+","+v+","+g+","+o.x+","+o.y)}else p="M"+e.map(t,function(e){return""+e.x+","+e.y}).join("L");return p},n.prototype.gradients=function(t){return e.map(t,function(e,n){return n===0?(t[1].y-e.y)/(t[1].x-e.x):n===t.length-1?(e.y-t[n-1].y)/(e.x-t[n-1].x):(t[n+1].y-t[n-1].y)/(t[n+1].x-t[n-1].x)})},n.prototype.drawHover=function(){var e,t,n,r,i;this.hoverHeight=this.options.hoverFontSize*1.5*(this.series.length+1),this.hover=this.r.rect(-10,-this.hoverHeight/2-this.options.hoverPaddingY,20,this.hoverHeight+this.options.hoverPaddingY*2,10).attr("fill",this.options.hoverFillColor).attr("stroke",this.options.hoverBorderColor).attr("stroke-width",this.options.hoverBorderWidth).attr("opacity",this.options.hoverOpacity),this.xLabel=this.r.text(0,this.options.hoverFontSize*.75-this.hoverHeight/2,"").attr("fill",this.options.hoverLabelColor).attr("font-weight","bold").attr("font-size",this.options.hoverFontSize),this.hoverSet=this.r.set(),this.hoverSet.push(this.hover),this.hoverSet.push(this.xLabel),this.yLabels=[],i=[];for(e=n=0,r=this.series.length-1;0<=r?n<=r:n>=r;e=0<=r?++n:--n)t=this.r.text(0,this.options.hoverFontSize*1.5*(e+1.5)-this.hoverHeight/2,"").attr("fill",this.colorForSeries(e)).attr("font-size",this.options.hoverFontSize),this.yLabels.push(t),i.push(this.hoverSet.push(t));return i},n.prototype.updateHover=function(t){var n,r,i,s,o,u,a=this;this.hoverSet.show(),this.xLabel.attr("text",this.columnLabels[t]);for(n=o=0,u=this.series.length-1;0<=u?o<=u:o>=u;n=0<=u?++o:--o)this.yLabels[n].attr("text",""+this.seriesLabels[n]+": "+this.yLabelFormat(this.series[n][t]));return r=Math.max.apply(null,e.map(this.yLabels,function(e){return e.getBBox().width})),r=Math.max(r,this.xLabel.getBBox().width),this.hover.attr("width",r+this.options.hoverPaddingX*2),this.hover.attr("x",-this.options.hoverPaddingX-r/2),s=Math.min.apply(null,e.map(this.series,function(e){return a.transY(e[t])})),s>this.hoverHeight+this.options.hoverPaddingY*2+this.options.hoverMargin+this.options.marginTop?s=s-this.hoverHeight/2-this.options.hoverPaddingY-this.options.hoverMargin:s=s+this.hoverHeight/2+this.options.hoverPaddingY+this.options.hoverMargin,s=Math.max(this.options.marginTop+this.hoverHeight/2+this.options.hoverPaddingY,s),s=Math.min(this.options.marginTop+this.height-this.hoverHeight/2-this.options.hoverPaddingY,s),i=Math.min(this.left+this.width-r/2-this.options.hoverPaddingX,this.columns[t]),i=Math.max(this.left+r/2+this.options.hoverPaddingX,i),this.hoverSet.attr("transform","t"+i+","+s)},n.prototype.hideHover=function(){return this.hoverSet.hide()},n.prototype.hilight=function(e){var t,n,r,i,s;if(this.prevHilight!==null&&this.prevHilight!==e)for(t=n=0,i=this.seriesPoints.length-1;0<=i?n<=i:n>=i;t=0<=i?++n:--n)this.seriesPoints[t][this.prevHilight]&&this.seriesPoints[t][this.prevHilight].animate(this.pointShrink);if(e!==null&&this.prevHilight!==e){for(t=r=0,s=this.seriesPoints.length-1;0<=s?r<=s:r>=s;t=0<=s?++r:--r)this.seriesPoints[t][e]&&this.seriesPoints[t][e].animate(this.pointGrow);this.updateHover(e)}this.prevHilight=e;if(e===null)return this.hideHover()},n.prototype.updateHilight=function(e){var t,n,r,i;e-=this.el.offset().left,i=[];for(t=n=r=this.hoverMargins.length;r<=0?n<=0:n>=0;t=r<=0?++n:--n){if(t===0||this.hoverMargins[t-1]>e){this.hilight(t);break}i.push(void 0)}return i},n.prototype.measureText=function(e,t){var n,r;return t==null&&(t=12),r=this.r.text(100,100,e).attr("font-size",t),n=r.getBBox(),r.remove(),n},n.prototype.yLabelFormat=function(e){return""+this.options.preUnits+t.commas(e)+this.options.postUnits},n.prototype.colorForSeries=function(e){return this.options.lineColors[e%this.options.lineColors.length]},n}(),t.parseDate=function(e){var t,n,r,i,s,o,u,a,f,l,c;return typeof e=="number"?e:(n=e.match(/^(\d+) Q(\d)$/),i=e.match(/^(\d+)-(\d+)$/),s=e.match(/^(\d+)-(\d+)-(\d+)$/),u=e.match(/^(\d+) W(\d+)$/),a=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/),f=e.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/),n?(new Date(parseInt(n[1],10),parseInt(n[2],10)*3-1,1)).getTime():i?(new Date(parseInt(i[1],10),parseInt(i[2],10)-1,1)).getTime():s?(new Date(parseInt(s[1],10),parseInt(s[2],10)-1,parseInt(s[3],10))).getTime():u?(l=new Date(parseInt(u[1],10),0,1),l.getDay()!==4&&l.setMonth(0,1+(4-l.getDay()+7)%7),l.getTime()+parseInt(u[2],10)*6048e5):a?a[6]?(o=0,a[6]!=="Z"&&(o=parseInt(a[8],10)*60+parseInt(a[9],10),a[7]==="+"&&(o=0-o)),Date.UTC(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10)+o)):(new Date(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10))).getTime():f?(c=parseFloat(f[6]),t=Math.floor(c),r=Math.round((c-t)*1e3),f[8]?(o=0,f[8]!=="Z"&&(o=parseInt(f[10],10)*60+parseInt(f[11],10),f[9]==="+"&&(o=0-o)),Date.UTC(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10)+o,t,r)):(new Date(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10),parseInt(f[4],10),parseInt(f[5],10),t,r)).getTime()):(new Date(parseInt(e,10),0,1)).getTime())},t.labelSeries=function(n,r,i,s,o){var u,a,f,l,c,h,p,d,v,m,g;f=200*(r-n)/i,a=new Date(n),p=t.LABEL_SPECS[s];if(p===void 0){g=t.AUTO_LABEL_ORDER;for(v=0,m=g.length;v=h.span){p=h;break}}}p===void 0&&(p=t.LABEL_SPECS.second),o&&(p=e.extend({},p,{fmt:o})),u=p.start(a),c=[];while((d=u.getTime())<=r)d>=n&&c.push([p.fmt(u),d]),p.incr(u);return c},n=function(e){return{span:e*60*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())},incr:function(t){return t.setMinutes(t.getMinutes()+e)}}},r=function(e){return{span:e*1e3,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes())},fmt:function(e){return""+t.pad2(e.getHours())+":"+t.pad2(e.getMinutes())+":"+t.pad2(e.getSeconds())},incr:function(t){return t.setSeconds(t.getSeconds()+e)}}},t.LABEL_SPECS={year:{span:1728e7,start:function(e){return new Date(e.getFullYear(),0,1)},fmt:function(e){return""+e.getFullYear()},incr:function(e){return e.setFullYear(e.getFullYear()+1)}},month:{span:24192e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),1)},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)},incr:function(e){return e.setMonth(e.getMonth()+1)}},day:{span:864e5,start:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())},fmt:function(e){return""+e.getFullYear()+"-"+t.pad2(e.getMonth()+1)+"-"+t.pad2(e.getDate())},incr:function(e){return e.setDate(e.getDate()+1)}},hour:n(60),"30min":n(30),"15min":n(15),"10min":n(10),"5min":n(5),minute:n(1),"30sec":r(30),"15sec":r(15),"10sec":r(10),"5sec":r(5),second:r(1)},t.AUTO_LABEL_ORDER=["year","month","day","hour","30min","15min","10min","5min","minute","30sec","15sec","10sec","5sec","second"]}).call(this); \ No newline at end of file