diff --git a/examples/weeks.html b/examples/weeks.html index 0e3943f..3623104 100644 --- a/examples/weeks.html +++ b/examples/weeks.html @@ -46,7 +46,11 @@ Morris.Line({ data: week_data, xkey: 'period', ykeys: ['licensed', 'sorned'], - labels: ['Licensed', 'SORN'] + labels: ['Licensed', 'SORN'], + numXLabels: 7, + xLabelFormat: function(x) { + var d = new Date(x); return (d.getMonth()+1)+'-'+d.getFullYear() + } }); diff --git a/morris.coffee b/morris.coffee index 050731e..27bfb2c 100644 --- a/morris.coffee +++ b/morris.coffee @@ -43,6 +43,9 @@ class Morris.Line marginBottom: 30 marginLeft: 25 numLines: 5 + numXLabels: 5 + xLabelMargin: 50 + xLabelFormat: (x) -> new Date(x).getFullYear() gridLineColor: '#aaa' gridTextColor: '#888' gridTextSize: 12 @@ -112,7 +115,7 @@ class Morris.Line @options.ymin = Math.min parseInt(@options.ymin[5..], 10), ymin else @options.ymin = ymin - + # Some instance variables for later @pointGrow = Raphael.animation r: @options.pointSize + 3, 25, 'linear' @pointShrink = Raphael.animation r: @options.pointSize, 25, 'linear' @@ -131,7 +134,7 @@ class Morris.Line return touch @el.bind 'touchstart', touchHandler @el.bind 'touchmove', touchHandler - @el.bind 'touchend', touchHandler + @el.bind 'touchend', touchHandler # Do any size-related calculations # @@ -160,8 +163,8 @@ class Morris.Line scoords.push(x: @columns[i], y: @transY(y)) @seriesCoords.push(scoords) # calculate hover margins - @hoverMargins = $.map @columns.slice(1), (x, i) => (x + @columns[i]) / 2 - + @hoverMargins = $.map @columns.slice(1), (x, i) => (x + @columns[i]) / 2 + # quick translation helpers # transX: (x) => @@ -181,7 +184,7 @@ class Morris.Line # the raphael drawing instance @r = new Raphael(@el[0]) - + @calc() @drawGrid() @drawSeries() @@ -208,31 +211,35 @@ class Morris.Line ## draw x axis labels prevLabelMargin = null - xLabelMargin = 50 # make this an option? + prevLabelText = null if @options.parseTime - x1 = new Date(@xmin).getFullYear() - x2 = new Date(@xmax).getFullYear() + step = (@xmax - @xmin)/(@options.numXLabels-1) + x1 = @xmin/step + x2 = @xmax/step else x1 = 0 x2 = @columnLabels.length for i in [x1..x2] if @options.parseTime - xpos = new Date(i, 0, 1).getTime() + xpos = i*step if xpos < @xmin continue else xpos = i - labelText = if @options.parseTime then i else @columnLabels[@columnLabels.length-i-1] + labelText = if @options.parseTime then @options.xLabelFormat(xpos) else @columnLabels[@columnLabels.length-i-1] + if labelText == prevLabelText + continue + prevLabelText = labelText label = @r.text(@transX(xpos), @options.marginTop + @height + @options.marginBottom / 2, labelText) .attr('font-size', @options.gridTextSize) .attr('fill', @options.gridTextColor) labelBox = label.getBBox() # ensure a minimum of `xLabelMargin` pixels between labels if prevLabelMargin is null or prevLabelMargin <= labelBox.x - prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin + prevLabelMargin = labelBox.x + labelBox.width + @options.xLabelMargin else label.remove() - + # draw the data series # drawSeries: -> @@ -254,7 +261,7 @@ class Morris.Line .attr('stroke-width', 1) .attr('stroke', '#ffffff') @seriesPoints[i].push(circle) - + # create a path for a data series # createPath: (all_coords, top, left, bottom, right) -> @@ -339,7 +346,7 @@ class Morris.Line xloc = Math.min @left + @width - maxLabelWidth / 2 - @options.hoverPaddingX, @columns[index] xloc = Math.max @left + maxLabelWidth / 2 + @options.hoverPaddingX, xloc @hoverSet.attr 'transform', "t#{xloc},#{yloc}" - + hideHover: -> @hoverSet.hide() @@ -363,7 +370,7 @@ class Morris.Line if hoverIndex == 0 || @hoverMargins[hoverIndex - 1] > x @hilight hoverIndex break - + measureText: (text, fontSize = 12) -> tt = @r.text(100, 100, text).attr('font-size', fontSize) ret = tt.getBBox() diff --git a/morris.js b/morris.js index 1213d05..41782b5 100644 --- a/morris.js +++ b/morris.js @@ -37,6 +37,11 @@ marginBottom: 30, marginLeft: 25, numLines: 5, + numXLabels: 5, + xLabelMargin: 50, + xLabelFormat: function(x) { + return new Date(x).getFullYear(); + }, gridLineColor: '#aaa', gridTextColor: '#888', gridTextSize: 12, @@ -219,7 +224,7 @@ }; Line.prototype.drawGrid = function() { - var firstY, i, label, labelBox, labelText, lastY, lineY, prevLabelMargin, v, x1, x2, xLabelMargin, xpos, y, yInterval, _results; + var firstY, i, label, labelBox, labelText, lastY, lineY, prevLabelMargin, prevLabelText, step, v, x1, x2, xpos, y, yInterval, _results; yInterval = (this.options.ymax - this.options.ymin) / (this.options.numLines - 1); firstY = Math.ceil(this.options.ymin / yInterval) * yInterval; lastY = Math.floor(this.options.ymax / yInterval) * yInterval; @@ -230,10 +235,11 @@ this.r.path("M" + this.left + "," + y + "H" + (this.left + this.width)).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth); } prevLabelMargin = null; - xLabelMargin = 50; + prevLabelText = null; if (this.options.parseTime) { - x1 = new Date(this.xmin).getFullYear(); - x2 = new Date(this.xmax).getFullYear(); + step = (this.xmax - this.xmin) / (this.options.numXLabels - 1); + x1 = this.xmin / step; + x2 = this.xmax / step; } else { x1 = 0; x2 = this.columnLabels.length; @@ -241,16 +247,18 @@ _results = []; for (i = x1; x1 <= x2 ? i <= x2 : i >= x2; x1 <= x2 ? i++ : i--) { if (this.options.parseTime) { - xpos = new Date(i, 0, 1).getTime(); + xpos = i * step; if (xpos < this.xmin) continue; } else { xpos = i; } - labelText = this.options.parseTime ? i : this.columnLabels[this.columnLabels.length - i - 1]; + labelText = this.options.parseTime ? this.options.xLabelFormat(xpos) : this.columnLabels[this.columnLabels.length - i - 1]; + if (labelText === prevLabelText) continue; + prevLabelText = labelText; label = this.r.text(this.transX(xpos), this.options.marginTop + this.height + this.options.marginBottom / 2, labelText).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor); labelBox = label.getBBox(); if (prevLabelMargin === null || prevLabelMargin <= labelBox.x) { - _results.push(prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin); + _results.push(prevLabelMargin = labelBox.x + labelBox.width + this.options.xLabelMargin); } else { _results.push(label.remove()); } diff --git a/morris.min.js b/morris.min.js index 25156ed..5bd25d6 100644 --- a/morris.min.js +++ b/morris.min.js @@ -1 +1 @@ -(function(){var a,b,c=function(a,b){return function(){return a.apply(b,arguments)}};a=jQuery,b={},b.Line=function(){function d(d){this.updateHilight=c(this.updateHilight,this),this.hilight=c(this.hilight,this),this.updateHover=c(this.updateHover,this),this.transY=c(this.transY,this),this.transX=c(this.transX,this);if(!(this instanceof b.Line))return new b.Line(d);typeof d.element=="string"?this.el=a(document.getElementById(d.element)):this.el=a(d.element),this.options=a.extend({},this.defaults,d);if(this.options.data===void 0||this.options.data.length===0)return;this.el.addClass("graph-initialised"),this.precalc(),this.redraw()}return d.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()}},d.prototype.precalc=function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=this;this.options.data.sort(function(a,b){return(a[q.options.xkey]=0;o<=0?a++:a--)p.push(a);return p}.apply(this),this.options.parseTime&&(this.columnLabels=a.map(this.columnLabels,function(a){return typeof a=="number"?q.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"&&(f=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),f):this.options.ymax=f),typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"&&(g=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),g):this.options.ymin=g),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 q.updateHilight(a.pageX)}),this.options.hideHover&&this.el.mouseout(function(a){return q.hilight(null)}),d=function(a){var b;return b=a.originalEvent.touches[0]||a.originalEvent.changedTouches[0],q.updateHilight(b.pageX),b},this.el.bind("touchstart",d),this.el.bind("touchmove",d),this.el.bind("touchend",d)},d.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=f;g+=o)i=Math.floor(g),n=this.transY(i),this.r.text(this.left-this.options.marginLeft/2,n,this.commas(i)+this.options.units).attr("font-size",this.options.gridTextSize).attr("fill",this.options.gridTextColor).attr("text-anchor","end"),this.r.path("M"+this.left+","+n+"H"+(this.left+this.width)).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth);h=null,l=50,this.options.parseTime?(j=(new Date(this.xmin)).getFullYear(),k=(new Date(this.xmax)).getFullYear()):(j=0,k=this.columnLabels.length),p=[];for(b=j;j<=k?b<=k:b>=k;j<=k?b++:b--){if(this.options.parseTime){m=(new Date(b,0,1)).getTime();if(m=0;f<=0?d++:d--)c=this.seriesCoords[d],c.length>1&&(e=this.createPath(c,this.options.marginTop,this.left,this.options.marginTop+this.height,this.left+this.width),this.r.path(e).attr("stroke",this.options.lineColors[d]).attr("stroke-width",this.options.lineWidth));this.seriesPoints=function(){var a,b;b=[];for(d=0,a=this.seriesCoords.length-1;0<=a?d<=a:d>=a;0<=a?d++:d--)b.push([]);return b}.call(this),h=[];for(d=g=this.seriesCoords.length-1;g<=0?d<=0:d>=0;g<=0?d++:d--)h.push(function(){var c,e,f,g;f=this.seriesCoords[d],g=[];for(c=0,e=f.length;c=t;0<=t?k++:k--)g=h[k],k===0?o+="M"+g.x+","+g.y:(i=j[k],m=h[k-1],n=j[k-1],l=(g.x-m.x)/4,p=m.x+l,r=Math.min(e,m.y+l*n),q=g.x-l,s=Math.min(e,g.y-l*i),o+="C"+p+","+r+","+q+","+s+","+g.x+","+g.y)}else o="M"+a.map(h,function(a){return""+a.x+","+a.y}).join("L");return o},d.prototype.gradients=function(b){return a.map(b,function(a,c){return c===0?(b[1].y-a.y)/(b[1].x-a.x):c===b.length-1?(a.y-b[c-1].y)/(a.x-b[c-1].x):(b[c+1].y-b[c-1].y)/(b[c+1].x-b[c-1].x)})},d.prototype.drawHover=function(){var a,b,c,d;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=[],d=[];for(a=0,c=this.series.length-1;0<=c?a<=c:a>=c;0<=c?a++:a--)b=this.r.text(0,this.options.hoverFontSize*1.5*(a+1.5)-this.hoverHeight/2,"").attr("fill",this.options.lineColors[a]).attr("font-size",this.options.hoverFontSize),this.yLabels.push(b),d.push(this.hoverSet.push(b));return d},d.prototype.updateHover=function(b){var c,d,e,f,g,h=this;this.hoverSet.show(),this.xLabel.attr("text",this.columnLabels[b]);for(c=0,g=this.series.length-1;0<=g?c<=g:c>=g;0<=g?c++:c--)this.yLabels[c].attr("text",""+this.seriesLabels[c]+": "+this.commas(this.series[c][b])+this.options.units);return d=Math.max.apply(null,a.map(this.yLabels,function(a){return a.getBBox().width})),d=Math.max(d,this.xLabel.getBBox().width),this.hover.attr("width",d+this.options.hoverPaddingX*2),this.hover.attr("x",-this.options.hoverPaddingX-d/2),f=Math.min.apply(null,a.map(this.series,function(a){return h.transY(a[b])})),f>this.hoverHeight+this.options.hoverPaddingY*2+this.options.hoverMargin+this.options.marginTop?f=f-this.hoverHeight/2-this.options.hoverPaddingY-this.options.hoverMargin:f=f+this.hoverHeight/2+this.options.hoverPaddingY+this.options.hoverMargin,f=Math.max(this.options.marginTop+this.hoverHeight/2+this.options.hoverPaddingY,f),f=Math.min(this.options.marginTop+this.height-this.hoverHeight/2-this.options.hoverPaddingY,f),e=Math.min(this.left+this.width-d/2-this.options.hoverPaddingX,this.columns[b]),e=Math.max(this.left+d/2+this.options.hoverPaddingX,e),this.hoverSet.attr("transform","t"+e+","+f)},d.prototype.hideHover=function(){return this.hoverSet.hide()},d.prototype.hilight=function(a){var b,c,d;if(this.prevHilight!==null&&this.prevHilight!==a)for(b=0,c=this.seriesPoints.length-1;0<=c?b<=c:b>=c;0<=c?b++:b--)this.seriesPoints[b][this.prevHilight]&&this.seriesPoints[b][this.prevHilight].animate(this.pointShrink);if(a!==null&&this.prevHilight!==a){for(b=0,d=this.seriesPoints.length-1;0<=d?b<=d:b>=d;0<=d?b++:b--)this.seriesPoints[b][a]&&this.seriesPoints[b][a].animate(this.pointGrow);this.updateHover(a)}this.prevHilight=a;if(a===null)return this.hideHover()},d.prototype.updateHilight=function(a){var b,c,d;a-=this.el.offset().left,d=[];for(b=c=this.hoverMargins.length;c<=0?b<=0:b>=0;c<=0?b++:b--){if(b===0||this.hoverMargins[b-1]>a){this.hilight(b);break}d.push(void 0)}return d},d.prototype.measureText=function(a,b){var c,d;return b==null&&(b=12),d=this.r.text(100,100,a).attr("font-size",b),c=d.getBBox(),d.remove(),c},d.prototype.parseDate=function(a){var b,c,d,e,f,g,h,i,j,k;return typeof a=="number"?a:(c=a.match(/^(\d+) Q(\d)$/),e=a.match(/^(\d+)-(\d+)$/),f=a.match(/^(\d+)-(\d+)-(\d+)$/),g=a.match(/^(\d+) W(\d+)$/),h=a.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)Z?$/),i=a.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)Z?$/),c?(new Date(parseInt(c[1],10),parseInt(c[2],10)*3-1,1)).getTime():e?(new Date(parseInt(e[1],10),parseInt(e[2],10)-1,1)).getTime():f?(new Date(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10))).getTime():g?(j=new Date(parseInt(g[1],10),0,1),j.getDay()!==4&&j.setMonth(0,1+(4-j.getDay()+7)%7),j.getTime()+parseInt(g[2],10)*6048e5):h?(new Date(parseInt(h[1],10),parseInt(h[2],10)-1,parseInt(h[3],10),parseInt(h[4],10),parseInt(h[5],10))).getTime():i?(k=parseFloat(i[6]),b=Math.floor(k),d=Math.floor((k-b)*1e3),(new Date(parseInt(i[1],10),parseInt(i[2],10)-1,parseInt(i[3],10),parseInt(i[4],10),parseInt(i[5],10),b,d)).getTime()):new Date(parseInt(a,10),0,1))},d.prototype.commas=function(a){var b,c,d,e;return a===null?"n/a":(d=a<0?"-":"",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)},d}(),window.Morris=b}).call(this); \ No newline at end of file +(function(){var a,b,c=function(a,b){return function(){return a.apply(b,arguments)}};a=jQuery,b={},b.Line=function(){function d(d){this.updateHilight=c(this.updateHilight,this),this.hilight=c(this.hilight,this),this.updateHover=c(this.updateHover,this),this.transY=c(this.transY,this),this.transX=c(this.transX,this);if(!(this instanceof b.Line))return new b.Line(d);typeof d.element=="string"?this.el=a(document.getElementById(d.element)):this.el=a(d.element),this.options=a.extend({},this.defaults,d);if(this.options.data===void 0||this.options.data.length===0)return;this.el.addClass("graph-initialised"),this.precalc(),this.redraw()}return d.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,numXLabels:5,xLabelMargin:50,xLabelFormat:function(a){return(new Date(a)).getFullYear()},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()}},d.prototype.precalc=function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=this;this.options.data.sort(function(a,b){return(a[q.options.xkey]=0;o<=0?a++:a--)p.push(a);return p}.apply(this),this.options.parseTime&&(this.columnLabels=a.map(this.columnLabels,function(a){return typeof a=="number"?q.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"&&(f=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),f):this.options.ymax=f),typeof this.options.ymin=="string"&&this.options.ymin.slice(0,4)==="auto"&&(g=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),g):this.options.ymin=g),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 q.updateHilight(a.pageX)}),this.options.hideHover&&this.el.mouseout(function(a){return q.hilight(null)}),d=function(a){var b;return b=a.originalEvent.touches[0]||a.originalEvent.changedTouches[0],q.updateHilight(b.pageX),b},this.el.bind("touchstart",d),this.el.bind("touchmove",d),this.el.bind("touchend",d)},d.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=f;g+=p)k=Math.floor(g),o=this.transY(k),this.r.text(this.left-this.options.marginLeft/2,o,this.commas(k)+this.options.units).attr("font-size",this.options.gridTextSize).attr("fill",this.options.gridTextColor).attr("text-anchor","end"),this.r.path("M"+this.left+","+o+"H"+(this.left+this.width)).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth);h=null,i=null,this.options.parseTime?(j=(this.xmax-this.xmin)/(this.options.numXLabels-1),l=this.xmin/j,m=this.xmax/j):(l=0,m=this.columnLabels.length),q=[];for(b=l;l<=m?b<=m:b>=m;l<=m?b++:b--){if(this.options.parseTime){n=b*j;if(n=0;f<=0?d++:d--)c=this.seriesCoords[d],c.length>1&&(e=this.createPath(c,this.options.marginTop,this.left,this.options.marginTop+this.height,this.left+this.width),this.r.path(e).attr("stroke",this.options.lineColors[d]).attr("stroke-width",this.options.lineWidth));this.seriesPoints=function(){var a,b;b=[];for(d=0,a=this.seriesCoords.length-1;0<=a?d<=a:d>=a;0<=a?d++:d--)b.push([]);return b}.call(this),h=[];for(d=g=this.seriesCoords.length-1;g<=0?d<=0:d>=0;g<=0?d++:d--)h.push(function(){var c,e,f,g;f=this.seriesCoords[d],g=[];for(c=0,e=f.length;c=t;0<=t?k++:k--)g=h[k],k===0?o+="M"+g.x+","+g.y:(i=j[k],m=h[k-1],n=j[k-1],l=(g.x-m.x)/4,p=m.x+l,r=Math.min(e,m.y+l*n),q=g.x-l,s=Math.min(e,g.y-l*i),o+="C"+p+","+r+","+q+","+s+","+g.x+","+g.y)}else o="M"+a.map(h,function(a){return""+a.x+","+a.y}).join("L");return o},d.prototype.gradients=function(b){return a.map(b,function(a,c){return c===0?(b[1].y-a.y)/(b[1].x-a.x):c===b.length-1?(a.y-b[c-1].y)/(a.x-b[c-1].x):(b[c+1].y-b[c-1].y)/(b[c+1].x-b[c-1].x)})},d.prototype.drawHover=function(){var a,b,c,d;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=[],d=[];for(a=0,c=this.series.length-1;0<=c?a<=c:a>=c;0<=c?a++:a--)b=this.r.text(0,this.options.hoverFontSize*1.5*(a+1.5)-this.hoverHeight/2,"").attr("fill",this.options.lineColors[a]).attr("font-size",this.options.hoverFontSize),this.yLabels.push(b),d.push(this.hoverSet.push(b));return d},d.prototype.updateHover=function(b){var c,d,e,f,g,h=this;this.hoverSet.show(),this.xLabel.attr("text",this.columnLabels[b]);for(c=0,g=this.series.length-1;0<=g?c<=g:c>=g;0<=g?c++:c--)this.yLabels[c].attr("text",""+this.seriesLabels[c]+": "+this.commas(this.series[c][b])+this.options.units);return d=Math.max.apply(null,a.map(this.yLabels,function(a){return a.getBBox().width})),d=Math.max(d,this.xLabel.getBBox().width),this.hover.attr("width",d+this.options.hoverPaddingX*2),this.hover.attr("x",-this.options.hoverPaddingX-d/2),f=Math.min.apply(null,a.map(this.series,function(a){return h.transY(a[b])})),f>this.hoverHeight+this.options.hoverPaddingY*2+this.options.hoverMargin+this.options.marginTop?f=f-this.hoverHeight/2-this.options.hoverPaddingY-this.options.hoverMargin:f=f+this.hoverHeight/2+this.options.hoverPaddingY+this.options.hoverMargin,f=Math.max(this.options.marginTop+this.hoverHeight/2+this.options.hoverPaddingY,f),f=Math.min(this.options.marginTop+this.height-this.hoverHeight/2-this.options.hoverPaddingY,f),e=Math.min(this.left+this.width-d/2-this.options.hoverPaddingX,this.columns[b]),e=Math.max(this.left+d/2+this.options.hoverPaddingX,e),this.hoverSet.attr("transform","t"+e+","+f)},d.prototype.hideHover=function(){return this.hoverSet.hide()},d.prototype.hilight=function(a){var b,c,d;if(this.prevHilight!==null&&this.prevHilight!==a)for(b=0,c=this.seriesPoints.length-1;0<=c?b<=c:b>=c;0<=c?b++:b--)this.seriesPoints[b][this.prevHilight]&&this.seriesPoints[b][this.prevHilight].animate(this.pointShrink);if(a!==null&&this.prevHilight!==a){for(b=0,d=this.seriesPoints.length-1;0<=d?b<=d:b>=d;0<=d?b++:b--)this.seriesPoints[b][a]&&this.seriesPoints[b][a].animate(this.pointGrow);this.updateHover(a)}this.prevHilight=a;if(a===null)return this.hideHover()},d.prototype.updateHilight=function(a){var b,c,d;a-=this.el.offset().left,d=[];for(b=c=this.hoverMargins.length;c<=0?b<=0:b>=0;c<=0?b++:b--){if(b===0||this.hoverMargins[b-1]>a){this.hilight(b);break}d.push(void 0)}return d},d.prototype.measureText=function(a,b){var c,d;return b==null&&(b=12),d=this.r.text(100,100,a).attr("font-size",b),c=d.getBBox(),d.remove(),c},d.prototype.parseDate=function(a){var b,c,d,e,f,g,h,i,j,k;return typeof a=="number"?a:(c=a.match(/^(\d+) Q(\d)$/),e=a.match(/^(\d+)-(\d+)$/),f=a.match(/^(\d+)-(\d+)-(\d+)$/),g=a.match(/^(\d+) W(\d+)$/),h=a.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)Z?$/),i=a.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)Z?$/),c?(new Date(parseInt(c[1],10),parseInt(c[2],10)*3-1,1)).getTime():e?(new Date(parseInt(e[1],10),parseInt(e[2],10)-1,1)).getTime():f?(new Date(parseInt(f[1],10),parseInt(f[2],10)-1,parseInt(f[3],10))).getTime():g?(j=new Date(parseInt(g[1],10),0,1),j.getDay()!==4&&j.setMonth(0,1+(4-j.getDay()+7)%7),j.getTime()+parseInt(g[2],10)*6048e5):h?(new Date(parseInt(h[1],10),parseInt(h[2],10)-1,parseInt(h[3],10),parseInt(h[4],10),parseInt(h[5],10))).getTime():i?(k=parseFloat(i[6]),b=Math.floor(k),d=Math.floor((k-b)*1e3),(new Date(parseInt(i[1],10),parseInt(i[2],10)-1,parseInt(i[3],10),parseInt(i[4],10),parseInt(i[5],10),b,d)).getTime()):new Date(parseInt(a,10),0,1))},d.prototype.commas=function(a){var b,c,d,e;return a===null?"n/a":(d=a<0?"-":"",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)},d}(),window.Morris=b}).call(this); \ No newline at end of file