diff --git a/lib/morris.line.coffee b/lib/morris.line.coffee index d5b7067..931b6cf 100644 --- a/lib/morris.line.coffee +++ b/lib/morris.line.coffee @@ -454,6 +454,11 @@ Morris.LABEL_SPECS = start: (d) -> new Date(d.getFullYear(), 0, 1) fmt: (d) -> "#{d.getFullYear()}" incr: (d) -> d.setFullYear(d.getFullYear() + 1) + "quarter": + span: 7884000000 # 365 * 24 * 60 * 60 * 1000 / 4 + start: (d) -> new Date(d.getFullYear(), d.getMonth(), 1) + fmt: (d) -> "#{d.getFullYear()} Q#{Math.floor(d.getMonth() / 3) + 1}" + incr: (d) -> d.setMonth(d.getMonth() + 3) "month": span: 2419200000 # 28 * 24 * 60 * 60 * 1000 start: (d) -> new Date(d.getFullYear(), d.getMonth(), 1) diff --git a/morris.js b/morris.js index 35ad207..853bb4e 100644 --- a/morris.js +++ b/morris.js @@ -1,6 +1,6 @@ /* @license morris.js v0.5.1 -Copyright 2014 Olly Smith All rights reserved. +Copyright 2017 Olly Smith All rights reserved. Licensed under the BSD-2-Clause License. */ @@ -169,6 +169,7 @@ Licensed under the BSD-2-Clause License. Grid.prototype.gridDefaults = { dateFormat: null, axes: true, + freePosition: false, grid: true, gridLineColor: '#aaa', gridStrokeWidth: 0.5, @@ -178,6 +179,7 @@ Licensed under the BSD-2-Clause License. gridTextWeight: 'normal', hideHover: false, yLabelFormat: null, + yLabelAlign: 'right', xLabelAngle: 0, numLines: 5, padding: 25, @@ -235,6 +237,11 @@ Licensed under the BSD-2-Clause License. } else if (typeof ret.label === 'number') { ret.label = new Date(ret.label).toString(); } + } else if (this.options.freePosition) { + ret.x = parseFloat(row[this.options.xkey]); + if (this.options.xLabelFormat) { + ret.label = this.options.xLabelFormat(ret); + } } else { ret.x = index; if (this.options.xLabelFormat) { @@ -279,7 +286,7 @@ Licensed under the BSD-2-Clause License. } return _results; }).call(this); - if (this.options.parseTime) { + if (this.options.parseTime || this.options.freePosition) { this.data = this.data.sort(function(a, b) { return (a.x > b.x) - (b.x > a.x); }); @@ -535,7 +542,11 @@ Licensed under the BSD-2-Clause License. }; Grid.prototype.getYAxisLabelX = function() { - return this.left - this.options.padding / 2; + if (this.options.yLabelAlign === 'right') { + return this.left - this.options.padding / 2; + } else { + return this.options.padding / 2; + } }; Grid.prototype.drawGrid = function() { @@ -638,7 +649,17 @@ Licensed under the BSD-2-Clause License. }; Grid.prototype.drawYAxisLabel = function(xPos, yPos, text) { - return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end'); + var label; + label = this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor); + if (this.options.yLabelAlign === 'right') { + return label.attr('text-anchor', 'end'); + } else { + return label.attr('text-anchor', 'start'); + } + }; + + Grid.prototype.drawXAxisLabel = function(xPos, yPos, text) { + return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor); }; Grid.prototype.drawGridLine = function(path) { @@ -847,9 +868,13 @@ Licensed under the BSD-2-Clause License. xLabels: 'auto', xLabelFormat: null, xLabelMargin: 24, + verticalGrid: false, + verticalGridHeight: 'full', + verticalGridStartOffset: 0, hideHover: false, trendLine: false, trendLineWidth: 2, + trendLineWeight: false, trendLineColors: ['#689bc3', '#a2b3bf', '#64b764'] }; @@ -859,7 +884,7 @@ Licensed under the BSD-2-Clause License. }; Line.prototype.calcPoints = function() { - var row, y, _i, _len, _ref, _results; + var i, row, y, _i, _len, _ref, _results; _ref = this.data; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -883,14 +908,14 @@ Licensed under the BSD-2-Clause License. var _j, _len1, _ref1, _results1; _ref1 = row._y; _results1 = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - y = _ref1[_j]; - if (y != null) { + for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { + y = _ref1[i]; + if ((y != null) && this.hasToShow(i)) { _results1.push(y); } } return _results1; - })()))); + }).call(this)))); } return _results; }; @@ -1002,7 +1027,7 @@ Licensed under the BSD-2-Clause License. }; Line.prototype.drawXAxis = function() { - var drawLabel, l, labels, prevAngleMargin, prevLabelMargin, row, ypos, _i, _len, _results, + var drawLabel, l, labels, lines, prevAngleMargin, prevLabelMargin, row, ypos, _i, _j, _len, _len1, _results, _this = this; ypos = this.bottom + this.options.padding / 2; prevLabelMargin = null; @@ -1024,7 +1049,10 @@ Licensed under the BSD-2-Clause License. margin = 1.25 * _this.options.gridTextSize / Math.sin(_this.options.xLabelAngle * Math.PI / 180.0); prevAngleMargin = labelBox.x - margin; } - return prevLabelMargin = labelBox.x - _this.options.xLabelMargin; + prevLabelMargin = labelBox.x - _this.options.xLabelMargin; + if (_this.options.verticalGrid === true) { + return _this.drawVerticalGridLine(xpos); + } } else { return label.remove(); } @@ -1035,6 +1063,17 @@ Licensed under the BSD-2-Clause License. } else { labels = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat); } + } else if (this.options.customLabels) { + labels = (function() { + var _i, _len, _ref, _results; + _ref = this.options.customLabels; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + row = _ref[_i]; + _results.push([row.label, row.x]); + } + return _results; + }).call(this); } else { labels = (function() { var _i, _len, _ref, _results; @@ -1048,12 +1087,31 @@ Licensed under the BSD-2-Clause License. }).call(this); } labels.reverse(); - _results = []; for (_i = 0, _len = labels.length; _i < _len; _i++) { l = labels[_i]; - _results.push(drawLabel(l[0], l[1])); + drawLabel(l[0], l[1]); } - return _results; + if (typeof this.options.verticalGrid === 'string') { + lines = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.verticalGrid); + _results = []; + for (_j = 0, _len1 = lines.length; _j < _len1; _j++) { + l = lines[_j]; + _results.push(this.drawVerticalGridLine(l[1])); + } + return _results; + } + }; + + Line.prototype.drawVerticalGridLine = function(xpos) { + var yEnd, yStart; + xpos = Math.floor(this.transX(xpos)) + 0.5; + yStart = this.yStart + this.options.verticalGridStartOffset; + if (this.options.verticalGridHeight === 'full') { + yEnd = this.yEnd; + } else { + yEnd = this.yStart - this.options.verticalGridHeight; + } + return this.drawGridLine("M" + xpos + "," + yStart + "V" + yEnd); }; Line.prototype.drawSeries = function() { @@ -1103,25 +1161,30 @@ Licensed under the BSD-2-Clause License. }; Line.prototype._drawTrendLine = function(index) { - var a, b, data, datapoints, path, sum_x, sum_xx, sum_xy, sum_y, val, x, y, _i, _len, _ref; + var a, b, data, datapoints, i, path, sum_x, sum_xx, sum_xy, sum_y, val, weight, x, y, _i, _len, _ref; sum_x = 0; sum_y = 0; sum_xx = 0; sum_xy = 0; datapoints = 0; _ref = this.data; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - val = _ref[_i]; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + val = _ref[i]; x = val.x; y = val.y[index]; if (y === void 0) { continue; } - datapoints += 1; - sum_x += x; - sum_y += y; - sum_xx += x * x; - sum_xy += x * y; + if (this.options.trendLineWeight === false) { + weight = 1; + } else { + weight = this.options.data[i][this.options.trendLineWeight]; + } + datapoints += weight; + sum_x += x * weight; + sum_y += y * weight; + sum_xx += x * x * weight; + sum_xy += x * y * weight; } a = (datapoints * sum_xy - sum_x * sum_y) / (datapoints * sum_xx - sum_x * sum_x); b = (sum_y / datapoints) - ((a * sum_x) / datapoints); @@ -1205,14 +1268,14 @@ Licensed under the BSD-2-Clause License. var i, _i, _j, _ref, _ref1; if (this.prevHilight !== null && this.prevHilight !== index) { for (i = _i = 0, _ref = this.seriesPoints.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { - if (this.seriesPoints[i][this.prevHilight]) { + if (this.hasToShow(i) && this.seriesPoints[i][this.prevHilight]) { this.seriesPoints[i][this.prevHilight].animate(this.pointShrinkSeries(i)); } } } if (index !== null && this.prevHilight !== index) { for (i = _j = 0, _ref1 = this.seriesPoints.length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) { - if (this.seriesPoints[i][index]) { + if (this.hasToShow(i) && this.seriesPoints[i][index]) { this.seriesPoints[i][index].animate(this.pointGrowSeries(i)); } } @@ -1225,17 +1288,13 @@ Licensed under the BSD-2-Clause License. return this.options.lineColors.call(this, row, sidx, type); } else if (type === 'point') { return this.options.pointFillColors[sidx % this.options.pointFillColors.length] || this.options.lineColors[sidx % this.options.lineColors.length]; - } else if (type === 'line') { - return this.options.lineColors[sidx % this.options.lineColors.length]; - } else { + } else if (type === 'trendLine') { return this.options.trendLineColors[sidx % this.options.trendLineColors.length]; + } else { + return this.options.lineColors[sidx % this.options.lineColors.length]; } }; - Line.prototype.drawXAxisLabel = function(xPos, yPos, text) { - return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor); - }; - Line.prototype.drawLinePath = function(path, lineColor, lineIndex) { return this.raphael.path(path).attr('stroke', lineColor).attr('stroke-width', this.lineWidthForSeries(lineIndex)); }; @@ -1377,6 +1436,18 @@ Licensed under the BSD-2-Clause License. return d.setFullYear(d.getFullYear() + 1); } }, + "quarter": { + span: 7884000000, + start: function(d) { + return new Date(d.getFullYear(), d.getMonth(), 1); + }, + fmt: function(d) { + return "" + (d.getFullYear()) + " Q" + (Math.floor(d.getMonth() / 3) + 1); + }, + incr: function(d) { + return d.setMonth(d.getMonth() + 3); + } + }, "month": { span: 2419200000, start: function(d) { @@ -1560,10 +1631,16 @@ Licensed under the BSD-2-Clause License. barGap: 3, barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], barOpacity: 1.0, + barHighlightOpacity: 1.0, + highlightSpeed: 150, barRadius: [0, 0, 0, 0], xLabelMargin: 50, horizontal: false, - shown: true + shown: true, + inBarValue: false, + inBarValueTextColor: 'white', + inBarValueMinTopMargin: 1, + inBarValueRightMargin: 4 }; Bar.prototype.calc = function() { @@ -1668,7 +1745,8 @@ Licensed under the BSD-2-Clause License. }; Bar.prototype.drawSeries = function() { - var barWidth, bottom, groupWidth, i, idx, lastTop, left, leftPadding, numBars, row, sidx, size, spaceLeft, top, ypos, zeroPos, _i, _ref; + var barMiddle, barWidth, bottom, groupWidth, i, idx, lastTop, left, leftPadding, numBars, row, sidx, size, spaceLeft, top, ypos, zeroPos, _i, _ref; + this.seriesBars = []; groupWidth = this.xSize / this.options.data.length; if (this.options.stacked) { numBars = 1; @@ -1687,12 +1765,13 @@ Licensed under the BSD-2-Clause License. spaceLeft = groupWidth - barWidth * numBars - this.options.barGap * (numBars - 1); leftPadding = spaceLeft / 2; zeroPos = this.ymin <= 0 && this.ymax >= 0 ? this.transY(0) : null; - return this.bars = (function() { + this.bars = (function() { var _j, _len, _ref1, _results; _ref1 = this.data; _results = []; for (idx = _j = 0, _len = _ref1.length; _j < _len; idx = ++_j) { row = _ref1[idx]; + this.seriesBars[idx] = []; lastTop = 0; _results.push((function() { var _k, _len1, _ref2, _results1; @@ -1727,11 +1806,17 @@ Licensed under the BSD-2-Clause License. top -= lastTop; } if (!this.options.horizontal) { - this.drawBar(left, top, barWidth, size, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius); - _results1.push(lastTop += size); + lastTop += size; + _results1.push(this.seriesBars[idx][sidx] = this.drawBar(left, top, barWidth, size, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius)); } else { - this.drawBar(top, left, size, barWidth, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius); - _results1.push(lastTop -= size); + lastTop -= size; + this.seriesBars[idx][sidx] = this.drawBar(top, left, size, barWidth, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius); + if (this.options.inBarValue && barWidth > this.options.gridTextSize + 2 * this.options.inBarValueMinTopMargin) { + barMiddle = left + 0.5 * barWidth; + _results1.push(this.raphael.text(bottom - this.options.inBarValueRightMargin, barMiddle, this.yLabelFormat(row.y[sidx], sidx)).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.inBarValueTextColor).attr('text-anchor', 'end')); + } else { + _results1.push(void 0); + } } } else { _results1.push(null); @@ -1742,6 +1827,42 @@ Licensed under the BSD-2-Clause License. } return _results; }).call(this); + this.flat_bars = $.map(this.bars, function(n) { + return n; + }); + this.flat_bars = $.grep(this.flat_bars, function(n) { + return n != null; + }); + return this.bar_els = $($.map(this.flat_bars, function(n) { + return n[0]; + })); + }; + + Bar.prototype.hilight = function(index) { + var i, y, _i, _j, _len, _len1, _ref, _ref1; + if (this.seriesBars && this.seriesBars[this.prevHilight] && this.prevHilight !== null && this.prevHilight !== index) { + _ref = this.seriesBars[this.prevHilight]; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + y = _ref[i]; + if (y) { + y.animate({ + 'fill-opacity': this.options.barOpacity + }, this.options.highlightSpeed); + } + } + } + if (this.seriesBars && this.seriesBars[index] && index !== null && this.prevHilight !== index) { + _ref1 = this.seriesBars[index]; + for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { + y = _ref1[i]; + if (y) { + y.animate({ + 'fill-opacity': this.options.barHighlightOpacity + }, this.options.highlightSpeed); + } + } + } + return this.prevHilight = index; }; Bar.prototype.colorFor = function(row, sidx, type) { @@ -1750,7 +1871,8 @@ Licensed under the BSD-2-Clause License. r = { x: row.x, y: row.y[sidx], - label: row.label + label: row.label, + src: row.src }; s = { index: sidx, @@ -1778,18 +1900,27 @@ Licensed under the BSD-2-Clause License. }; Bar.prototype.onGridClick = function(x, y) { - var index; + var bar_hit, index; index = this.hitTest(x, y); - return this.fire('click', index, this.data[index].src, x, y); + bar_hit = !!this.bar_els.filter(function() { + return $(this).is(':hover'); + }).length; + return this.fire('click', index, this.data[index].src, x, y, bar_hit); }; Bar.prototype.onHoverMove = function(x, y) { var index, _ref; index = this.hitTest(x, y); - return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index)); + this.hilight(index); + if (index != null) { + return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index)); + } else { + return this.hover.hide(); + } }; Bar.prototype.onHoverOut = function() { + this.hilight(-1); if (this.options.hideHover !== false) { return this.hover.hide(); } @@ -1821,11 +1952,6 @@ Licensed under the BSD-2-Clause License. } }; - Bar.prototype.drawXAxisLabel = function(xPos, yPos, text) { - var label; - return label = this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor); - }; - Bar.prototype.drawBar = function(xPos, yPos, width, height, barColor, opacity, radiusArray) { var maxRadius, path; maxRadius = Math.max.apply(Math, radiusArray); diff --git a/morris.min.js b/morris.min.js index 819cd67..706afe7 100644 --- a/morris.min.js +++ b/morris.min.js @@ -1,7 +1,7 @@ /* @license morris.js v0.5.1 -Copyright 2014 Olly Smith All rights reserved. +Copyright 2017 Olly Smith All rights reserved. Licensed under the BSD-2-Clause License. */ -(function(){var a,b,c,d,e=[].slice,f=function(a,b){return function(){return a.apply(b,arguments)}},g={}.hasOwnProperty,h=function(a,b){function c(){this.constructor=a}for(var d in b)g.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},i=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};b=window.Morris={},a=jQuery,b.EventEmitter=function(){function a(){}return a.prototype.on=function(a,b){return null==this.handlers&&(this.handlers={}),null==this.handlers[a]&&(this.handlers[a]=[]),this.handlers[a].push(b),this},a.prototype.fire=function(){var a,b,c,d,f,g,h;if(c=arguments[0],a=2<=arguments.length?e.call(arguments,1):[],null!=this.handlers&&null!=this.handlers[c]){for(g=this.handlers[c],h=[],d=0,f=g.length;f>d;d++)b=g[d],h.push(b.apply(null,a));return h}},a}(),b.commas=function(a){var b,c,d,e;return null!=a?(d=0>a?"-":"",b=Math.abs(a),c=Math.floor(b).toFixed(0),d+=c.replace(/(?=(?:\d{3})+$)(?!^)/g,","),e=b.toString(),e.length>c.length&&(d+=e.slice(c.length)),d):"-"},b.pad2=function(a){return(10>a?"0":"")+a},b.Grid=function(c){function d(b){this.hasToShow=f(this.hasToShow,this),this.resizeHandler=f(this.resizeHandler,this);var c=this;if(this.el=a("string"==typeof b.element?document.getElementById(b.element):b.element),null==this.el||0===this.el.length)throw new Error("Graph container element not found");"static"===this.el.css("position")&&this.el.css("position","relative"),this.options=a.extend({},this.gridDefaults,this.defaults||{},b),"string"==typeof this.options.units&&(this.options.postUnits=b.units),this.raphael=new Raphael(this.el[0]),this.elementWidth=null,this.elementHeight=null,this.dirty=!1,this.selectFrom=null,this.init&&this.init(),this.setData(this.options.data),this.el.bind("mousemove",function(a){var b,d,e,f,g;return d=c.el.offset(),g=a.pageX-d.left,c.selectFrom?(b=c.data[c.hitTest(Math.min(g,c.selectFrom))]._x,e=c.data[c.hitTest(Math.max(g,c.selectFrom))]._x,f=e-b,c.selectionRect.attr({x:b,width:f})):c.fire("hovermove",g,a.pageY-d.top)}),this.el.bind("mouseleave",function(){return c.selectFrom&&(c.selectionRect.hide(),c.selectFrom=null),c.fire("hoverout")}),this.el.bind("touchstart touchmove touchend",function(a){var b,d;return d=a.originalEvent.touches[0]||a.originalEvent.changedTouches[0],b=c.el.offset(),c.fire("hovermove",d.pageX-b.left,d.pageY-b.top)}),this.el.bind("click",function(a){var b;return b=c.el.offset(),c.fire("gridclick",a.pageX-b.left,a.pageY-b.top)}),this.options.rangeSelect&&(this.selectionRect=this.raphael.rect(0,0,0,this.el.innerHeight()).attr({fill:this.options.rangeSelectColor,stroke:!1}).toBack().hide(),this.el.bind("mousedown",function(a){var b;return b=c.el.offset(),c.startRange(a.pageX-b.left)}),this.el.bind("mouseup",function(a){var b;return b=c.el.offset(),c.endRange(a.pageX-b.left),c.fire("hovermove",a.pageX-b.left,a.pageY-b.top)})),this.options.resize&&a(window).bind("resize",function(){return null!=c.timeoutId&&window.clearTimeout(c.timeoutId),c.timeoutId=window.setTimeout(c.resizeHandler,100)}),this.el.css("-webkit-tap-highlight-color","rgba(0,0,0,0)"),this.postInit&&this.postInit()}return h(d,c),d.prototype.gridDefaults={dateFormat:null,axes:!0,grid:!0,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,gridTextFamily:"sans-serif",gridTextWeight:"normal",hideHover:!1,yLabelFormat:null,xLabelAngle:0,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0",goals:[],goalStrokeWidth:1,goalLineColors:["#666633","#999966","#cc6666","#663333"],events:[],eventStrokeWidth:1,eventLineColors:["#005a04","#ccffbb","#3a5f0b","#005502"],rangeSelect:null,rangeSelectColor:"#eef",resize:!1},d.prototype.setData=function(c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;if(null==d&&(d=!0),this.options.data=c,null==c||0===c.length)return this.data=[],this.raphael.clear(),void(null!=this.hover&&this.hover.hide());if(s=this.cumulative?0:null,t=this.cumulative?0:null,this.options.goals.length>0&&(k=Math.min.apply(Math,this.options.goals),j=Math.max.apply(Math,this.options.goals),t=null!=t?Math.min(t,k):k,s=null!=s?Math.max(s,j):j),this.data=function(){var a,d,e;for(e=[],i=a=0,d=c.length;d>a;i=++a)m=c[i],l={src:m},l.label=m[this.options.xkey],this.options.parseTime?(l.x=b.parseDate(l.label),this.options.dateFormat?l.label=this.options.dateFormat(l.x):"number"==typeof l.label&&(l.label=new Date(l.label).toString())):(l.x=i,this.options.xLabelFormat&&(l.label=this.options.xLabelFormat(l))),p=0,l.y=function(){var a,b,c,d;for(c=this.options.ykeys,d=[],h=a=0,b=c.length;b>a;h=++a)r=c[h],u=m[r],"string"==typeof u&&(u=parseFloat(u)),null!=u&&"number"!=typeof u&&(u=null),null!=u&&this.hasToShow(h)&&(this.cumulative?p+=u:null!=s?(s=Math.max(u,s),t=Math.min(u,t)):s=t=u),this.cumulative&&null!=p&&(s=Math.max(p,s),t=Math.min(p,t)),d.push(u);return d}.call(this),e.push(l);return e}.call(this),this.options.parseTime&&(this.data=this.data.sort(function(a,b){return(a.x>b.x)-(b.x>a.x)})),this.xmin=this.data[0].x,this.xmax=this.data[this.data.length-1].x,this.events=[],this.options.events.length>0){if(this.options.parseTime)for(x=this.options.events,v=0,w=x.length;w>v;v++)e=x[v],e instanceof Array?(g=e[0],o=e[1],this.events.push([b.parseDate(g),b.parseDate(o)])):this.events.push(b.parseDate(e));else this.events=this.options.events;f=a.map(this.events,function(a){return a}),this.xmax=Math.max(this.xmax,Math.max.apply(Math,f)),this.xmin=Math.min(this.xmin,Math.min.apply(Math,f))}return this.xmin===this.xmax&&(this.xmin-=1,this.xmax+=1),this.ymin=this.yboundary("min",t),this.ymax=this.yboundary("max",s),this.ymin===this.ymax&&(t&&(this.ymin-=1),this.ymax+=1),((y=this.options.axes)===!0||"both"===y||"y"===y||this.options.grid===!0)&&(this.options.ymax===this.gridDefaults.ymax&&this.options.ymin===this.gridDefaults.ymin?(this.grid=this.autoGridLines(this.ymin,this.ymax,this.options.numLines),this.ymin=Math.min(this.ymin,this.grid[0]),this.ymax=Math.max(this.ymax,this.grid[this.grid.length-1])):(n=(this.ymax-this.ymin)/(this.options.numLines-1),this.grid=function(){var a,b,c,d;for(d=[],q=a=b=this.ymin,c=this.ymax;n>0?c>=a:a>=c;q=a+=n)d.push(q);return d}.call(this))),this.dirty=!0,d?this.redraw():void 0},d.prototype.yboundary=function(a,b){var c,d;return c=this.options["y"+a],"string"==typeof c?"auto"===c.slice(0,4)?c.length>5?(d=parseInt(c.slice(5),10),null==b?d:Math[a](b,d)):null!=b?b:0:parseInt(c,10):c},d.prototype.autoGridLines=function(a,b,c){var d,e,f,g,h,i,j,k,l;return h=b-a,l=Math.floor(Math.log(h)/Math.log(10)),j=Math.pow(10,l),e=Math.floor(a/j)*j,d=Math.ceil(b/j)*j,i=(d-e)/(c-1),1===j&&i>1&&Math.ceil(i)!==i&&(i=Math.ceil(i),d=e+i*(c-1)),0>e&&d>0&&(e=Math.floor(a/i)*i,d=Math.ceil(b/i)*i),1>i?(g=Math.floor(Math.log(i)/Math.log(10)),f=function(){var a,b;for(b=[],k=a=e;i>0?d>=a:a>=d;k=a+=i)b.push(parseFloat(k.toFixed(1-g)));return b}()):f=function(){var a,b;for(b=[],k=a=e;i>0?d>=a:a>=d;k=a+=i)b.push(k);return b}(),f},d.prototype._calc=function(){var a,b,c,d,e,f,g,h,i;return f=this.el.width(),d=this.el.height(),(this.elementWidth!==f||this.elementHeight!==d||this.dirty)&&(this.elementWidth=f,this.elementHeight=d,this.dirty=!1,this.left=this.options.padding,this.right=this.elementWidth-this.options.padding,this.top=this.options.padding,this.bottom=this.elementHeight-this.options.padding,((h=this.options.axes)===!0||"both"===h||"y"===h)&&(g=function(){var a,b,d,e;for(d=this.grid,e=[],a=0,b=d.length;b>a;a++)c=d[a],e.push(this.measureText(this.yAxisFormat(c)).width);return e}.call(this),this.options.horizontal?this.bottom-=Math.max.apply(Math,g):this.left+=Math.max.apply(Math,g)),((i=this.options.axes)===!0||"both"===i||"x"===i)&&(a=this.options.horizontal?-90:-this.options.xLabelAngle,b=function(){var b,c,d;for(d=[],e=b=0,c=this.data.length;c>=0?c>b:b>c;e=c>=0?++b:--b)d.push(this.measureText(this.data[e].label,a).height);return d}.call(this),this.options.horizontal?this.left+=Math.max.apply(Math,b):this.bottom-=Math.max.apply(Math,b)),this.width=Math.max(1,this.right-this.left),this.height=Math.max(1,this.bottom-this.top),this.options.horizontal?(this.dx=this.height/(this.xmax-this.xmin),this.dy=this.width/(this.ymax-this.ymin),this.yStart=this.left,this.yEnd=this.right,this.xStart=this.top,this.xEnd=this.bottom,this.xSize=this.height,this.ySize=this.width):(this.dx=this.width/(this.xmax-this.xmin),this.dy=this.height/(this.ymax-this.ymin),this.yStart=this.bottom,this.yEnd=this.top,this.xStart=this.left,this.xEnd=this.right,this.xSize=this.width,this.ySize=this.height),this.calc)?this.calc():void 0},d.prototype.transY=function(a){return this.options.horizontal?this.left+(a-this.ymin)*this.dy:this.bottom-(a-this.ymin)*this.dy},d.prototype.transX=function(a){return 1===this.data.length?(this.xStart+this.xEnd)/2:this.xStart+(a-this.xmin)*this.dx},d.prototype.redraw=function(){return this.raphael.clear(),this._calc(),this.drawGrid(),this.drawGoals(),this.drawEvents(),this.draw?this.draw():void 0},d.prototype.measureText=function(a,b){var c,d;return null==b&&(b=0),d=this.raphael.text(100,100,a).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).rotate(b),c=d.getBBox(),d.remove(),c},d.prototype.yAxisFormat=function(a){return this.yLabelFormat(a,0)},d.prototype.yLabelFormat=function(a,c){return"function"==typeof this.options.yLabelFormat?this.options.yLabelFormat(a,c):""+this.options.preUnits+b.commas(a)+this.options.postUnits},d.prototype.getYAxisLabelX=function(){return this.left-this.options.padding/2},d.prototype.drawGrid=function(){var a,b,c,d,e,f,g,h,i;if(this.options.grid!==!1||(f=this.options.axes)===!0||"both"===f||"y"===f){for(a=this.options.horizontal?this.getXAxisLabelY():this.getYAxisLabelX(),g=this.grid,i=[],d=0,e=g.length;e>d;d++)b=g[d],c=this.transY(b),((h=this.options.axes)===!0||"both"===h||"y"===h)&&(this.options.horizontal?this.drawXAxisLabel(c,a,this.yAxisFormat(b)):this.drawYAxisLabel(a,c,this.yAxisFormat(b))),this.options.grid?(c=Math.floor(c)+.5,i.push(this.options.horizontal?this.drawGridLine("M"+c+","+this.xStart+"V"+this.xEnd):this.drawGridLine("M"+this.xStart+","+c+"H"+this.xEnd))):i.push(void 0);return i}},d.prototype.drawGoals=function(){var a,b,c,d,e,f,g;for(f=this.options.goals,g=[],c=d=0,e=f.length;e>d;c=++d)b=f[c],a=this.options.goalLineColors[c%this.options.goalLineColors.length],g.push(this.drawGoal(b,a));return g},d.prototype.drawEvents=function(){var a,b,c,d,e,f,g;for(f=this.events,g=[],c=d=0,e=f.length;e>d;c=++d)b=f[c],a=this.options.eventLineColors[c%this.options.eventLineColors.length],g.push(this.drawEvent(b,a));return g},d.prototype.drawGoal=function(a,b){var c,d;return d=Math.floor(this.transY(a))+.5,c=this.options.horizontal?"M"+d+","+this.xStart+"V"+this.xEnd:"M"+this.xStart+","+d+"H"+this.xEnd,this.raphael.path(c).attr("stroke",b).attr("stroke-width",this.options.goalStrokeWidth)},d.prototype.drawEvent=function(a,b){var c,d,e,f;return a instanceof Array?(c=a[0],e=a[1],c=Math.floor(this.transX(c))+.5,e=Math.floor(this.transX(e))+.5,this.options.horizontal?this.raphael.rect(this.yStart,c,this.yEnd-this.yStart,e-c).attr({fill:b,stroke:!1}).toBack():this.raphael.rect(c,this.yEnd,e-c,this.yStart-this.yEnd).attr({fill:b,stroke:!1}).toBack()):(f=Math.floor(this.transX(a))+.5,d=this.options.horizontal?"M"+this.yStart+","+f+"H"+this.yEnd:"M"+f+","+this.yStart+"V"+this.yEnd,this.raphael.path(d).attr("stroke",b).attr("stroke-width",this.options.eventStrokeWidth))},d.prototype.drawYAxisLabel=function(a,b,c){return this.raphael.text(a,b,c).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).attr("fill",this.options.gridTextColor).attr("text-anchor","end")},d.prototype.drawGridLine=function(a){return this.raphael.path(a).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth)},d.prototype.startRange=function(a){return this.hover.hide(),this.selectFrom=a,this.selectionRect.attr({x:a,width:0}).show()},d.prototype.endRange=function(a){var b,c;return this.selectFrom?(c=Math.min(this.selectFrom,a),b=Math.max(this.selectFrom,a),this.options.rangeSelect.call(this.el,{start:this.data[this.hitTest(c)].x,end:this.data[this.hitTest(b)].x}),this.selectFrom=null):void 0},d.prototype.resizeHandler=function(){return this.timeoutId=null,this.raphael.setSize(this.el.width(),this.el.height()),this.redraw()},d.prototype.hasToShow=function(a){return this.options.shown===!0||this.options.shown[a]===!0},d}(b.EventEmitter),b.parseDate=function(a){var b,c,d,e,f,g,h,i,j,k,l;return"number"==typeof a?a:(c=a.match(/^(\d+) Q(\d)$/),e=a.match(/^(\d+)-(\d+)$/),f=a.match(/^(\d+)-(\d+)-(\d+)$/),h=a.match(/^(\d+) W(\d+)$/),i=a.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/),j=a.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/),c?new Date(parseInt(c[1],10),3*parseInt(c[2],10)-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():h?(k=new Date(parseInt(h[1],10),0,1),4!==k.getDay()&&k.setMonth(0,1+(4-k.getDay()+7)%7),k.getTime()+6048e5*parseInt(h[2],10)):i?i[6]?(g=0,"Z"!==i[6]&&(g=60*parseInt(i[8],10)+parseInt(i[9],10),"+"===i[7]&&(g=0-g)),Date.UTC(parseInt(i[1],10),parseInt(i[2],10)-1,parseInt(i[3],10),parseInt(i[4],10),parseInt(i[5],10)+g)):new Date(parseInt(i[1],10),parseInt(i[2],10)-1,parseInt(i[3],10),parseInt(i[4],10),parseInt(i[5],10)).getTime():j?(l=parseFloat(j[6]),b=Math.floor(l),d=Math.round(1e3*(l-b)),j[8]?(g=0,"Z"!==j[8]&&(g=60*parseInt(j[10],10)+parseInt(j[11],10),"+"===j[9]&&(g=0-g)),Date.UTC(parseInt(j[1],10),parseInt(j[2],10)-1,parseInt(j[3],10),parseInt(j[4],10),parseInt(j[5],10)+g,b,d)):new Date(parseInt(j[1],10),parseInt(j[2],10)-1,parseInt(j[3],10),parseInt(j[4],10),parseInt(j[5],10),b,d).getTime()):new Date(parseInt(a,10),0,1).getTime())},b.Hover=function(){function c(c){null==c&&(c={}),this.options=a.extend({},b.Hover.defaults,c),this.el=a("
"),this.el.hide(),this.options.parent.append(this.el)}return c.defaults={"class":"morris-hover morris-default-style"},c.prototype.update=function(a,b,c,d){return a?(this.html(a),this.show(),this.moveTo(b,c,d)):this.hide()},c.prototype.html=function(a){return this.el.html(a)},c.prototype.moveTo=function(a,b,c){var d,e,f,g,h,i;return h=this.options.parent.innerWidth(),g=this.options.parent.innerHeight(),e=this.el.outerWidth(),d=this.el.outerHeight(),f=Math.min(Math.max(0,a-e/2),h-e),null!=b?c===!0?(i=b-d/2,0>i&&(i=0)):(i=b-d-10,0>i&&(i=b+10,i+d>g&&(i=g/2-d/2))):i=g/2-d/2,this.el.css({left:f+"px",top:parseInt(i)+"px"})},c.prototype.show=function(){return this.el.show()},c.prototype.hide=function(){return this.el.hide()},c}(),b.Line=function(c){function d(a){return this.hilight=f(this.hilight,this),this.onHoverOut=f(this.onHoverOut,this),this.onHoverMove=f(this.onHoverMove,this),this.onGridClick=f(this.onGridClick,this),this instanceof b.Line?void d.__super__.constructor.call(this,a):new b.Line(a)}return h(d,c),d.prototype.init=function(){return"always"!==this.options.hideHover?(this.hover=new b.Hover({parent:this.el}),this.on("hovermove",this.onHoverMove),this.on("hoverout",this.onHoverOut),this.on("gridclick",this.onGridClick)):void 0},d.prototype.defaults={lineWidth:3,pointSize:4,lineColors:["#0b62a4","#7A92A3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],pointStrokeWidths:[1],pointStrokeColors:["#ffffff"],pointFillColors:[],smooth:!0,shown:!0,xLabels:"auto",xLabelFormat:null,xLabelMargin:24,hideHover:!1,trendLine:!1,trendLineWidth:2,trendLineColors:["#689bc3","#a2b3bf","#64b764"]},d.prototype.calc=function(){return this.calcPoints(),this.generatePaths()},d.prototype.calcPoints=function(){var a,b,c,d,e,f;for(e=this.data,f=[],c=0,d=e.length;d>c;c++)a=e[c],a._x=this.transX(a.x),a._y=function(){var c,d,e,f;for(e=a.y,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(null!=b?this.transY(b):b);return f}.call(this),f.push(a._ymax=Math.min.apply(Math,[this.bottom].concat(function(){var c,d,e,f;for(e=a._y,f=[],c=0,d=e.length;d>c;c++)b=e[c],null!=b&&f.push(b);return f}())));return f},d.prototype.hitTest=function(a){var b,c,d,e,f;if(0===this.data.length)return null;for(f=this.data.slice(1),b=d=0,e=f.length;e>d&&(c=f[b],!(a<(c._x+this.data[b]._x)/2));b=++d);return b},d.prototype.onGridClick=function(a,b){var c;return c=this.hitTest(a),this.fire("click",c,this.data[c].src,a,b)},d.prototype.onHoverMove=function(a){var b;return b=this.hitTest(a),this.displayHoverForRow(b)},d.prototype.onHoverOut=function(){return this.options.hideHover!==!1?this.displayHoverForRow(null):void 0},d.prototype.displayHoverForRow=function(a){var b;return null!=a?((b=this.hover).update.apply(b,this.hoverContentForRow(a)),this.hilight(a)):(this.hover.hide(),this.hilight())},d.prototype.hoverContentForRow=function(b){var c,d,e,f,g,h,i;for(e=this.data[b],c=a("