Path: blob/master/web-gui/buildyourownbotnet/assets/js/morris.min.js
1292 views
(function() {1var $, Morris, minutesSpecHelper, secondsSpecHelper,2__slice = [].slice,3__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },4__hasProp = {}.hasOwnProperty,5__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },6__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };78Morris = window.Morris = {};910$ = jQuery;1112Morris.EventEmitter = (function() {13function EventEmitter() {}1415EventEmitter.prototype.on = function(name, handler) {16if (this.handlers == null) {17this.handlers = {};18}19if (this.handlers[name] == null) {20this.handlers[name] = [];21}22this.handlers[name].push(handler);23return this;24};2526EventEmitter.prototype.fire = function() {27var args, handler, name, _i, _len, _ref, _results;28name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];29if ((this.handlers != null) && (this.handlers[name] != null)) {30_ref = this.handlers[name];31_results = [];32for (_i = 0, _len = _ref.length; _i < _len; _i++) {33handler = _ref[_i];34_results.push(handler.apply(null, args));35}36return _results;37}38};3940return EventEmitter;4142})();4344Morris.commas = function(num) {45var absnum, intnum, ret, strabsnum;46if (num != null) {47ret = num < 0 ? "-" : "";48absnum = Math.abs(num);49intnum = Math.floor(absnum).toFixed(0);50ret += intnum.replace(/(?=(?:\d{3})+$)(?!^)/g, ',');51strabsnum = absnum.toString();52if (strabsnum.length > intnum.length) {53ret += strabsnum.slice(intnum.length);54}55return ret;56} else {57return '-';58}59};6061Morris.pad2 = function(number) {62return (number < 10 ? '0' : '') + number;63};6465Morris.Grid = (function(_super) {66__extends(Grid, _super);6768function Grid(options) {69this.resizeHandler = __bind(this.resizeHandler, this);70var _this = this;71if (typeof options.element === 'string') {72this.el = $(document.getElementById(options.element));73} else {74this.el = $(options.element);75}76if ((this.el == null) || this.el.length === 0) {77throw new Error("Graph container element not found");78}79if (this.el.css('position') === 'static') {80this.el.css('position', 'relative');81}82this.options = $.extend({}, this.gridDefaults, this.defaults || {}, options);83if (typeof this.options.units === 'string') {84this.options.postUnits = options.units;85}86this.raphael = new Raphael(this.el[0]);87this.elementWidth = null;88this.elementHeight = null;89this.dirty = false;90this.selectFrom = null;91if (this.init) {92this.init();93}94this.setData(this.options.data);95this.el.bind('mousemove', function(evt) {96var left, offset, right, width, x;97offset = _this.el.offset();98x = evt.pageX - offset.left;99if (_this.selectFrom) {100left = _this.data[_this.hitTest(Math.min(x, _this.selectFrom))]._x;101right = _this.data[_this.hitTest(Math.max(x, _this.selectFrom))]._x;102width = right - left;103return _this.selectionRect.attr({104x: left,105width: width106});107} else {108return _this.fire('hovermove', x, evt.pageY - offset.top);109}110});111this.el.bind('mouseleave', function(evt) {112if (_this.selectFrom) {113_this.selectionRect.hide();114_this.selectFrom = null;115}116return _this.fire('hoverout');117});118this.el.bind('touchstart touchmove touchend', function(evt) {119var offset, touch;120touch = evt.originalEvent.touches[0] || evt.originalEvent.changedTouches[0];121offset = _this.el.offset();122_this.fire('hover', touch.pageX - offset.left, touch.pageY - offset.top);123return touch;124});125this.el.bind('click', function(evt) {126var offset;127offset = _this.el.offset();128return _this.fire('gridclick', evt.pageX - offset.left, evt.pageY - offset.top);129});130if (this.options.rangeSelect) {131this.selectionRect = this.raphael.rect(0, 0, 0, this.el.innerHeight()).attr({132fill: this.options.rangeSelectColor,133stroke: false134}).toBack().hide();135this.el.bind('mousedown', function(evt) {136var offset;137offset = _this.el.offset();138return _this.startRange(evt.pageX - offset.left);139});140this.el.bind('mouseup', function(evt) {141var offset;142offset = _this.el.offset();143_this.endRange(evt.pageX - offset.left);144return _this.fire('hovermove', evt.pageX - offset.left, evt.pageY - offset.top);145});146}147if (this.options.resize) {148$(window).bind('resize', function(evt) {149if (_this.timeoutId != null) {150window.clearTimeout(_this.timeoutId);151}152return _this.timeoutId = window.setTimeout(_this.resizeHandler, 100);153});154}155if (this.postInit) {156this.postInit();157}158}159160Grid.prototype.gridDefaults = {161dateFormat: null,162axes: true,163grid: true,164gridLineColor: '#aaa',165gridStrokeWidth: 0.5,166gridTextColor: '#888',167gridTextSize: 12,168gridTextFamily: 'sans-serif',169gridTextWeight: 'normal',170hideHover: false,171yLabelFormat: null,172xLabelAngle: 0,173numLines: 5,174padding: 25,175parseTime: true,176postUnits: '',177preUnits: '',178ymax: 'auto',179ymin: 'auto 0',180goals: [],181goalStrokeWidth: 1.0,182goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'],183events: [],184eventStrokeWidth: 1.0,185eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502'],186rangeSelect: null,187rangeSelectColor: '#eef',188resize: false189};190191Grid.prototype.setData = function(data, redraw) {192var e, idx, index, maxGoal, minGoal, ret, row, step, total, y, ykey, ymax, ymin, yval, _ref;193if (redraw == null) {194redraw = true;195}196this.options.data = data;197if ((data == null) || data.length === 0) {198this.data = [];199this.raphael.clear();200if (this.hover != null) {201this.hover.hide();202}203return;204}205ymax = this.cumulative ? 0 : null;206ymin = this.cumulative ? 0 : null;207if (this.options.goals.length > 0) {208minGoal = Math.min.apply(Math, this.options.goals);209maxGoal = Math.max.apply(Math, this.options.goals);210ymin = ymin != null ? Math.min(ymin, minGoal) : minGoal;211ymax = ymax != null ? Math.max(ymax, maxGoal) : maxGoal;212}213this.data = (function() {214var _i, _len, _results;215_results = [];216for (index = _i = 0, _len = data.length; _i < _len; index = ++_i) {217row = data[index];218ret = {219src: row220};221ret.label = row[this.options.xkey];222if (this.options.parseTime) {223ret.x = Morris.parseDate(ret.label);224if (this.options.dateFormat) {225ret.label = this.options.dateFormat(ret.x);226} else if (typeof ret.label === 'number') {227ret.label = new Date(ret.label).toString();228}229} else {230ret.x = index;231if (this.options.xLabelFormat) {232ret.label = this.options.xLabelFormat(ret);233}234}235total = 0;236ret.y = (function() {237var _j, _len1, _ref, _results1;238_ref = this.options.ykeys;239_results1 = [];240for (idx = _j = 0, _len1 = _ref.length; _j < _len1; idx = ++_j) {241ykey = _ref[idx];242yval = row[ykey];243if (typeof yval === 'string') {244yval = parseFloat(yval);245}246if ((yval != null) && typeof yval !== 'number') {247yval = null;248}249if (yval != null) {250if (this.cumulative) {251total += yval;252} else {253if (ymax != null) {254ymax = Math.max(yval, ymax);255ymin = Math.min(yval, ymin);256} else {257ymax = ymin = yval;258}259}260}261if (this.cumulative && (total != null)) {262ymax = Math.max(total, ymax);263ymin = Math.min(total, ymin);264}265_results1.push(yval);266}267return _results1;268}).call(this);269_results.push(ret);270}271return _results;272}).call(this);273if (this.options.parseTime) {274this.data = this.data.sort(function(a, b) {275return (a.x > b.x) - (b.x > a.x);276});277}278this.xmin = this.data[0].x;279this.xmax = this.data[this.data.length - 1].x;280this.events = [];281if (this.options.events.length > 0) {282if (this.options.parseTime) {283this.events = (function() {284var _i, _len, _ref, _results;285_ref = this.options.events;286_results = [];287for (_i = 0, _len = _ref.length; _i < _len; _i++) {288e = _ref[_i];289_results.push(Morris.parseDate(e));290}291return _results;292}).call(this);293} else {294this.events = this.options.events;295}296this.xmax = Math.max(this.xmax, Math.max.apply(Math, this.events));297this.xmin = Math.min(this.xmin, Math.min.apply(Math, this.events));298}299if (this.xmin === this.xmax) {300this.xmin -= 1;301this.xmax += 1;302}303this.ymin = this.yboundary('min', ymin);304this.ymax = this.yboundary('max', ymax);305if (this.ymin === this.ymax) {306if (ymin) {307this.ymin -= 1;308}309this.ymax += 1;310}311if (((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'y') || this.options.grid === true) {312if (this.options.ymax === this.gridDefaults.ymax && this.options.ymin === this.gridDefaults.ymin) {313this.grid = this.autoGridLines(this.ymin, this.ymax, this.options.numLines);314this.ymin = Math.min(this.ymin, this.grid[0]);315this.ymax = Math.max(this.ymax, this.grid[this.grid.length - 1]);316} else {317step = (this.ymax - this.ymin) / (this.options.numLines - 1);318this.grid = (function() {319var _i, _ref1, _ref2, _results;320_results = [];321for (y = _i = _ref1 = this.ymin, _ref2 = this.ymax; step > 0 ? _i <= _ref2 : _i >= _ref2; y = _i += step) {322_results.push(y);323}324return _results;325}).call(this);326}327}328this.dirty = true;329if (redraw) {330return this.redraw();331}332};333334Grid.prototype.yboundary = function(boundaryType, currentValue) {335var boundaryOption, suggestedValue;336boundaryOption = this.options["y" + boundaryType];337if (typeof boundaryOption === 'string') {338if (boundaryOption.slice(0, 4) === 'auto') {339if (boundaryOption.length > 5) {340suggestedValue = parseInt(boundaryOption.slice(5), 10);341if (currentValue == null) {342return suggestedValue;343}344return Math[boundaryType](currentValue, suggestedValue);345} else {346if (currentValue != null) {347return currentValue;348} else {349return 0;350}351}352} else {353return parseInt(boundaryOption, 10);354}355} else {356return boundaryOption;357}358};359360Grid.prototype.autoGridLines = function(ymin, ymax, nlines) {361var gmax, gmin, grid, smag, span, step, unit, y, ymag;362span = ymax - ymin;363ymag = Math.floor(Math.log(span) / Math.log(10));364unit = Math.pow(10, ymag);365gmin = Math.floor(ymin / unit) * unit;366gmax = Math.ceil(ymax / unit) * unit;367step = (gmax - gmin) / (nlines - 1);368if (unit === 1 && step > 1 && Math.ceil(step) !== step) {369step = Math.ceil(step);370gmax = gmin + step * (nlines - 1);371}372if (gmin < 0 && gmax > 0) {373gmin = Math.floor(ymin / step) * step;374gmax = Math.ceil(ymax / step) * step;375}376if (step < 1) {377smag = Math.floor(Math.log(step) / Math.log(10));378grid = (function() {379var _i, _results;380_results = [];381for (y = _i = gmin; step > 0 ? _i <= gmax : _i >= gmax; y = _i += step) {382_results.push(parseFloat(y.toFixed(1 - smag)));383}384return _results;385})();386} else {387grid = (function() {388var _i, _results;389_results = [];390for (y = _i = gmin; step > 0 ? _i <= gmax : _i >= gmax; y = _i += step) {391_results.push(y);392}393return _results;394})();395}396return grid;397};398399Grid.prototype._calc = function() {400var bottomOffsets, gridLine, h, i, w, yLabelWidths, _ref, _ref1;401w = this.el.width();402h = this.el.height();403if (this.elementWidth !== w || this.elementHeight !== h || this.dirty) {404this.elementWidth = w;405this.elementHeight = h;406this.dirty = false;407this.left = this.options.padding;408this.right = this.elementWidth - this.options.padding;409this.top = this.options.padding;410this.bottom = this.elementHeight - this.options.padding;411if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'y') {412yLabelWidths = (function() {413var _i, _len, _ref1, _results;414_ref1 = this.grid;415_results = [];416for (_i = 0, _len = _ref1.length; _i < _len; _i++) {417gridLine = _ref1[_i];418_results.push(this.measureText(this.yAxisFormat(gridLine)).width);419}420return _results;421}).call(this);422this.left += Math.max.apply(Math, yLabelWidths);423}424if ((_ref1 = this.options.axes) === true || _ref1 === 'both' || _ref1 === 'x') {425bottomOffsets = (function() {426var _i, _ref2, _results;427_results = [];428for (i = _i = 0, _ref2 = this.data.length; 0 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 0 <= _ref2 ? ++_i : --_i) {429_results.push(this.measureText(this.data[i].text, -this.options.xLabelAngle).height);430}431return _results;432}).call(this);433this.bottom -= Math.max.apply(Math, bottomOffsets);434}435this.width = Math.max(1, this.right - this.left);436this.height = Math.max(1, this.bottom - this.top);437this.dx = this.width / (this.xmax - this.xmin);438this.dy = this.height / (this.ymax - this.ymin);439if (this.calc) {440return this.calc();441}442}443};444445Grid.prototype.transY = function(y) {446return this.bottom - (y - this.ymin) * this.dy;447};448449Grid.prototype.transX = function(x) {450if (this.data.length === 1) {451return (this.left + this.right) / 2;452} else {453return this.left + (x - this.xmin) * this.dx;454}455};456457Grid.prototype.redraw = function() {458this.raphael.clear();459this._calc();460this.drawGrid();461this.drawGoals();462this.drawEvents();463if (this.draw) {464return this.draw();465}466};467468Grid.prototype.measureText = function(text, angle) {469var ret, tt;470if (angle == null) {471angle = 0;472}473tt = this.raphael.text(100, 100, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).rotate(angle);474ret = tt.getBBox();475tt.remove();476return ret;477};478479Grid.prototype.yAxisFormat = function(label) {480return this.yLabelFormat(label);481};482483Grid.prototype.yLabelFormat = function(label) {484if (typeof this.options.yLabelFormat === 'function') {485return this.options.yLabelFormat(label);486} else {487return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;488}489};490491Grid.prototype.drawGrid = function() {492var lineY, y, _i, _len, _ref, _ref1, _ref2, _results;493if (this.options.grid === false && ((_ref = this.options.axes) !== true && _ref !== 'both' && _ref !== 'y')) {494return;495}496_ref1 = this.grid;497_results = [];498for (_i = 0, _len = _ref1.length; _i < _len; _i++) {499lineY = _ref1[_i];500y = this.transY(lineY);501if ((_ref2 = this.options.axes) === true || _ref2 === 'both' || _ref2 === 'y') {502this.drawYAxisLabel(this.left - this.options.padding / 2, y, this.yAxisFormat(lineY));503}504if (this.options.grid) {505_results.push(this.drawGridLine("M" + this.left + "," + y + "H" + (this.left + this.width)));506} else {507_results.push(void 0);508}509}510return _results;511};512513Grid.prototype.drawGoals = function() {514var color, goal, i, _i, _len, _ref, _results;515_ref = this.options.goals;516_results = [];517for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {518goal = _ref[i];519color = this.options.goalLineColors[i % this.options.goalLineColors.length];520_results.push(this.drawGoal(goal, color));521}522return _results;523};524525Grid.prototype.drawEvents = function() {526var color, event, i, _i, _len, _ref, _results;527_ref = this.events;528_results = [];529for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {530event = _ref[i];531color = this.options.eventLineColors[i % this.options.eventLineColors.length];532_results.push(this.drawEvent(event, color));533}534return _results;535};536537Grid.prototype.drawGoal = function(goal, color) {538return this.raphael.path("M" + this.left + "," + (this.transY(goal)) + "H" + this.right).attr('stroke', color).attr('stroke-width', this.options.goalStrokeWidth);539};540541Grid.prototype.drawEvent = function(event, color) {542return this.raphael.path("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top).attr('stroke', color).attr('stroke-width', this.options.eventStrokeWidth);543};544545Grid.prototype.drawYAxisLabel = function(xPos, yPos, text) {546return 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');547};548549Grid.prototype.drawGridLine = function(path) {550return this.raphael.path(path).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth);551};552553Grid.prototype.startRange = function(x) {554this.hover.hide();555this.selectFrom = x;556return this.selectionRect.attr({557x: x,558width: 0559}).show();560};561562Grid.prototype.endRange = function(x) {563var end, start;564if (this.selectFrom) {565start = Math.min(this.selectFrom, x);566end = Math.max(this.selectFrom, x);567this.options.rangeSelect.call(this.el, {568start: this.data[this.hitTest(start)].x,569end: this.data[this.hitTest(end)].x570});571return this.selectFrom = null;572}573};574575Grid.prototype.resizeHandler = function() {576this.timeoutId = null;577this.raphael.setSize(this.el.width(), this.el.height());578return this.redraw();579};580581return Grid;582583})(Morris.EventEmitter);584585Morris.parseDate = function(date) {586var isecs, m, msecs, n, o, offsetmins, p, q, r, ret, secs;587if (typeof date === 'number') {588return date;589}590m = date.match(/^(\d+) Q(\d)$/);591n = date.match(/^(\d+)-(\d+)$/);592o = date.match(/^(\d+)-(\d+)-(\d+)$/);593p = date.match(/^(\d+) W(\d+)$/);594q = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/);595r = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/);596if (m) {597return new Date(parseInt(m[1], 10), parseInt(m[2], 10) * 3 - 1, 1).getTime();598} else if (n) {599return new Date(parseInt(n[1], 10), parseInt(n[2], 10) - 1, 1).getTime();600} else if (o) {601return new Date(parseInt(o[1], 10), parseInt(o[2], 10) - 1, parseInt(o[3], 10)).getTime();602} else if (p) {603ret = new Date(parseInt(p[1], 10), 0, 1);604if (ret.getDay() !== 4) {605ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7);606}607return ret.getTime() + parseInt(p[2], 10) * 604800000;608} else if (q) {609if (!q[6]) {610return new Date(parseInt(q[1], 10), parseInt(q[2], 10) - 1, parseInt(q[3], 10), parseInt(q[4], 10), parseInt(q[5], 10)).getTime();611} else {612offsetmins = 0;613if (q[6] !== 'Z') {614offsetmins = parseInt(q[8], 10) * 60 + parseInt(q[9], 10);615if (q[7] === '+') {616offsetmins = 0 - offsetmins;617}618}619return Date.UTC(parseInt(q[1], 10), parseInt(q[2], 10) - 1, parseInt(q[3], 10), parseInt(q[4], 10), parseInt(q[5], 10) + offsetmins);620}621} else if (r) {622secs = parseFloat(r[6]);623isecs = Math.floor(secs);624msecs = Math.round((secs - isecs) * 1000);625if (!r[8]) {626return new Date(parseInt(r[1], 10), parseInt(r[2], 10) - 1, parseInt(r[3], 10), parseInt(r[4], 10), parseInt(r[5], 10), isecs, msecs).getTime();627} else {628offsetmins = 0;629if (r[8] !== 'Z') {630offsetmins = parseInt(r[10], 10) * 60 + parseInt(r[11], 10);631if (r[9] === '+') {632offsetmins = 0 - offsetmins;633}634}635return Date.UTC(parseInt(r[1], 10), parseInt(r[2], 10) - 1, parseInt(r[3], 10), parseInt(r[4], 10), parseInt(r[5], 10) + offsetmins, isecs, msecs);636}637} else {638return new Date(parseInt(date, 10), 0, 1).getTime();639}640};641642Morris.Hover = (function() {643Hover.defaults = {644"class": 'morris-hover morris-default-style'645};646647function Hover(options) {648if (options == null) {649options = {};650}651this.options = $.extend({}, Morris.Hover.defaults, options);652this.el = $("<div class='" + this.options["class"] + "'></div>");653this.el.hide();654this.options.parent.append(this.el);655}656657Hover.prototype.update = function(html, x, y) {658this.html(html);659this.show();660return this.moveTo(x, y);661};662663Hover.prototype.html = function(content) {664return this.el.html(content);665};666667Hover.prototype.moveTo = function(x, y) {668var hoverHeight, hoverWidth, left, parentHeight, parentWidth, top;669parentWidth = this.options.parent.innerWidth();670parentHeight = this.options.parent.innerHeight();671hoverWidth = this.el.outerWidth();672hoverHeight = this.el.outerHeight();673left = Math.min(Math.max(0, x - hoverWidth / 2), parentWidth - hoverWidth);674if (y != null) {675top = y - hoverHeight - 10;676if (top < 0) {677top = y + 10;678if (top + hoverHeight > parentHeight) {679top = parentHeight / 2 - hoverHeight / 2;680}681}682} else {683top = parentHeight / 2 - hoverHeight / 2;684}685return this.el.css({686left: left + "px",687top: parseInt(top) + "px"688});689};690691Hover.prototype.show = function() {692return this.el.show();693};694695Hover.prototype.hide = function() {696return this.el.hide();697};698699return Hover;700701})();702703Morris.Line = (function(_super) {704__extends(Line, _super);705706function Line(options) {707this.hilight = __bind(this.hilight, this);708this.onHoverOut = __bind(this.onHoverOut, this);709this.onHoverMove = __bind(this.onHoverMove, this);710this.onGridClick = __bind(this.onGridClick, this);711if (!(this instanceof Morris.Line)) {712return new Morris.Line(options);713}714Line.__super__.constructor.call(this, options);715}716717Line.prototype.init = function() {718if (this.options.hideHover !== 'always') {719this.hover = new Morris.Hover({720parent: this.el721});722this.on('hovermove', this.onHoverMove);723this.on('hoverout', this.onHoverOut);724return this.on('gridclick', this.onGridClick);725}726};727728Line.prototype.defaults = {729lineWidth: 3,730pointSize: 4,731lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'],732pointStrokeWidths: [1],733pointStrokeColors: ['#ffffff'],734pointFillColors: [],735smooth: true,736xLabels: 'auto',737xLabelFormat: null,738xLabelMargin: 24,739continuousLine: true,740hideHover: false741};742743Line.prototype.calc = function() {744this.calcPoints();745return this.generatePaths();746};747748Line.prototype.calcPoints = function() {749var row, y, _i, _len, _ref, _results;750_ref = this.data;751_results = [];752for (_i = 0, _len = _ref.length; _i < _len; _i++) {753row = _ref[_i];754row._x = this.transX(row.x);755row._y = (function() {756var _j, _len1, _ref1, _results1;757_ref1 = row.y;758_results1 = [];759for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {760y = _ref1[_j];761if (y != null) {762_results1.push(this.transY(y));763} else {764_results1.push(y);765}766}767return _results1;768}).call(this);769_results.push(row._ymax = Math.min.apply(Math, [this.bottom].concat((function() {770var _j, _len1, _ref1, _results1;771_ref1 = row._y;772_results1 = [];773for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {774y = _ref1[_j];775if (y != null) {776_results1.push(y);777}778}779return _results1;780})())));781}782return _results;783};784785Line.prototype.hitTest = function(x) {786var index, r, _i, _len, _ref;787if (this.data.length === 0) {788return null;789}790_ref = this.data.slice(1);791for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {792r = _ref[index];793if (x < (r._x + this.data[index]._x) / 2) {794break;795}796}797return index;798};799800Line.prototype.onGridClick = function(x, y) {801var index;802index = this.hitTest(x);803return this.fire('click', index, this.data[index].src, x, y);804};805806Line.prototype.onHoverMove = function(x, y) {807var index;808index = this.hitTest(x);809return this.displayHoverForRow(index);810};811812Line.prototype.onHoverOut = function() {813if (this.options.hideHover !== false) {814return this.displayHoverForRow(null);815}816};817818Line.prototype.displayHoverForRow = function(index) {819var _ref;820if (index != null) {821(_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index));822return this.hilight(index);823} else {824this.hover.hide();825return this.hilight();826}827};828829Line.prototype.hoverContentForRow = function(index) {830var content, j, row, y, _i, _len, _ref;831row = this.data[index];832content = "<div class='morris-hover-row-label'>" + row.label + "</div>";833_ref = row.y;834for (j = _i = 0, _len = _ref.length; _i < _len; j = ++_i) {835y = _ref[j];836content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";837}838if (typeof this.options.hoverCallback === 'function') {839content = this.options.hoverCallback(index, this.options, content, row.src);840}841return [content, row._x, row._ymax];842};843844Line.prototype.generatePaths = function() {845var c, coords, i, r, smooth;846return this.paths = (function() {847var _i, _ref, _ref1, _results;848_results = [];849for (i = _i = 0, _ref = this.options.ykeys.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {850smooth = typeof this.options.smooth === "boolean" ? this.options.smooth : (_ref1 = this.options.ykeys[i], __indexOf.call(this.options.smooth, _ref1) >= 0);851coords = (function() {852var _j, _len, _ref2, _results1;853_ref2 = this.data;854_results1 = [];855for (_j = 0, _len = _ref2.length; _j < _len; _j++) {856r = _ref2[_j];857if (r._y[i] !== void 0) {858_results1.push({859x: r._x,860y: r._y[i]861});862}863}864return _results1;865}).call(this);866if (this.options.continuousLine) {867coords = (function() {868var _j, _len, _results1;869_results1 = [];870for (_j = 0, _len = coords.length; _j < _len; _j++) {871c = coords[_j];872if (c.y !== null) {873_results1.push(c);874}875}876return _results1;877})();878}879if (coords.length > 1) {880_results.push(Morris.Line.createPath(coords, smooth, this.bottom));881} else {882_results.push(null);883}884}885return _results;886}).call(this);887};888889Line.prototype.draw = function() {890var _ref;891if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'x') {892this.drawXAxis();893}894this.drawSeries();895if (this.options.hideHover === false) {896return this.displayHoverForRow(this.data.length - 1);897}898};899900Line.prototype.drawXAxis = function() {901var drawLabel, l, labels, prevAngleMargin, prevLabelMargin, row, ypos, _i, _len, _results,902_this = this;903ypos = this.bottom + this.options.padding / 2;904prevLabelMargin = null;905prevAngleMargin = null;906drawLabel = function(labelText, xpos) {907var label, labelBox, margin, offset, textBox;908label = _this.drawXAxisLabel(_this.transX(xpos), ypos, labelText);909textBox = label.getBBox();910label.transform("r" + (-_this.options.xLabelAngle));911labelBox = label.getBBox();912label.transform("t0," + (labelBox.height / 2) + "...");913if (_this.options.xLabelAngle !== 0) {914offset = -0.5 * textBox.width * Math.cos(_this.options.xLabelAngle * Math.PI / 180.0);915label.transform("t" + offset + ",0...");916}917labelBox = label.getBBox();918if (((prevLabelMargin == null) || prevLabelMargin >= labelBox.x + labelBox.width || (prevAngleMargin != null) && prevAngleMargin >= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {919if (_this.options.xLabelAngle !== 0) {920margin = 1.25 * _this.options.gridTextSize / Math.sin(_this.options.xLabelAngle * Math.PI / 180.0);921prevAngleMargin = labelBox.x - margin;922}923return prevLabelMargin = labelBox.x - _this.options.xLabelMargin;924} else {925return label.remove();926}927};928if (this.options.parseTime) {929if (this.data.length === 1 && this.options.xLabels === 'auto') {930labels = [[this.data[0].label, this.data[0].x]];931} else {932labels = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat);933}934} else {935labels = (function() {936var _i, _len, _ref, _results;937_ref = this.data;938_results = [];939for (_i = 0, _len = _ref.length; _i < _len; _i++) {940row = _ref[_i];941_results.push([row.label, row.x]);942}943return _results;944}).call(this);945}946labels.reverse();947_results = [];948for (_i = 0, _len = labels.length; _i < _len; _i++) {949l = labels[_i];950_results.push(drawLabel(l[0], l[1]));951}952return _results;953};954955Line.prototype.drawSeries = function() {956var i, _i, _j, _ref, _ref1, _results;957this.seriesPoints = [];958for (i = _i = _ref = this.options.ykeys.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) {959this._drawLineFor(i);960}961_results = [];962for (i = _j = _ref1 = this.options.ykeys.length - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {963_results.push(this._drawPointFor(i));964}965return _results;966};967968Line.prototype._drawPointFor = function(index) {969var circle, row, _i, _len, _ref, _results;970this.seriesPoints[index] = [];971_ref = this.data;972_results = [];973for (_i = 0, _len = _ref.length; _i < _len; _i++) {974row = _ref[_i];975circle = null;976if (row._y[index] != null) {977circle = this.drawLinePoint(row._x, row._y[index], this.colorFor(row, index, 'point'), index);978}979_results.push(this.seriesPoints[index].push(circle));980}981return _results;982};983984Line.prototype._drawLineFor = function(index) {985var path;986path = this.paths[index];987if (path !== null) {988return this.drawLinePath(path, this.colorFor(null, index, 'line'), index);989}990};991992Line.createPath = function(coords, smooth, bottom) {993var coord, g, grads, i, ix, lg, path, prevCoord, x1, x2, y1, y2, _i, _len;994path = "";995if (smooth) {996grads = Morris.Line.gradients(coords);997}998prevCoord = {999y: null1000};1001for (i = _i = 0, _len = coords.length; _i < _len; i = ++_i) {1002coord = coords[i];1003if (coord.y != null) {1004if (prevCoord.y != null) {1005if (smooth) {1006g = grads[i];1007lg = grads[i - 1];1008ix = (coord.x - prevCoord.x) / 4;1009x1 = prevCoord.x + ix;1010y1 = Math.min(bottom, prevCoord.y + ix * lg);1011x2 = coord.x - ix;1012y2 = Math.min(bottom, coord.y - ix * g);1013path += "C" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + coord.x + "," + coord.y;1014} else {1015path += "L" + coord.x + "," + coord.y;1016}1017} else {1018if (!smooth || (grads[i] != null)) {1019path += "M" + coord.x + "," + coord.y;1020}1021}1022}1023prevCoord = coord;1024}1025return path;1026};10271028Line.gradients = function(coords) {1029var coord, grad, i, nextCoord, prevCoord, _i, _len, _results;1030grad = function(a, b) {1031return (a.y - b.y) / (a.x - b.x);1032};1033_results = [];1034for (i = _i = 0, _len = coords.length; _i < _len; i = ++_i) {1035coord = coords[i];1036if (coord.y != null) {1037nextCoord = coords[i + 1] || {1038y: null1039};1040prevCoord = coords[i - 1] || {1041y: null1042};1043if ((prevCoord.y != null) && (nextCoord.y != null)) {1044_results.push(grad(prevCoord, nextCoord));1045} else if (prevCoord.y != null) {1046_results.push(grad(prevCoord, coord));1047} else if (nextCoord.y != null) {1048_results.push(grad(coord, nextCoord));1049} else {1050_results.push(null);1051}1052} else {1053_results.push(null);1054}1055}1056return _results;1057};10581059Line.prototype.hilight = function(index) {1060var i, _i, _j, _ref, _ref1;1061if (this.prevHilight !== null && this.prevHilight !== index) {1062for (i = _i = 0, _ref = this.seriesPoints.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {1063if (this.seriesPoints[i][this.prevHilight]) {1064this.seriesPoints[i][this.prevHilight].animate(this.pointShrinkSeries(i));1065}1066}1067}1068if (index !== null && this.prevHilight !== index) {1069for (i = _j = 0, _ref1 = this.seriesPoints.length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) {1070if (this.seriesPoints[i][index]) {1071this.seriesPoints[i][index].animate(this.pointGrowSeries(i));1072}1073}1074}1075return this.prevHilight = index;1076};10771078Line.prototype.colorFor = function(row, sidx, type) {1079if (typeof this.options.lineColors === 'function') {1080return this.options.lineColors.call(this, row, sidx, type);1081} else if (type === 'point') {1082return this.options.pointFillColors[sidx % this.options.pointFillColors.length] || this.options.lineColors[sidx % this.options.lineColors.length];1083} else {1084return this.options.lineColors[sidx % this.options.lineColors.length];1085}1086};10871088Line.prototype.drawXAxisLabel = function(xPos, yPos, text) {1089return 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);1090};10911092Line.prototype.drawLinePath = function(path, lineColor, lineIndex) {1093return this.raphael.path(path).attr('stroke', lineColor).attr('stroke-width', this.lineWidthForSeries(lineIndex));1094};10951096Line.prototype.drawLinePoint = function(xPos, yPos, pointColor, lineIndex) {1097return this.raphael.circle(xPos, yPos, this.pointSizeForSeries(lineIndex)).attr('fill', pointColor).attr('stroke-width', this.pointStrokeWidthForSeries(lineIndex)).attr('stroke', this.pointStrokeColorForSeries(lineIndex));1098};10991100Line.prototype.pointStrokeWidthForSeries = function(index) {1101return this.options.pointStrokeWidths[index % this.options.pointStrokeWidths.length];1102};11031104Line.prototype.pointStrokeColorForSeries = function(index) {1105return this.options.pointStrokeColors[index % this.options.pointStrokeColors.length];1106};11071108Line.prototype.lineWidthForSeries = function(index) {1109if (this.options.lineWidth instanceof Array) {1110return this.options.lineWidth[index % this.options.lineWidth.length];1111} else {1112return this.options.lineWidth;1113}1114};11151116Line.prototype.pointSizeForSeries = function(index) {1117if (this.options.pointSize instanceof Array) {1118return this.options.pointSize[index % this.options.pointSize.length];1119} else {1120return this.options.pointSize;1121}1122};11231124Line.prototype.pointGrowSeries = function(index) {1125return Raphael.animation({1126r: this.pointSizeForSeries(index) + 31127}, 25, 'linear');1128};11291130Line.prototype.pointShrinkSeries = function(index) {1131return Raphael.animation({1132r: this.pointSizeForSeries(index)1133}, 25, 'linear');1134};11351136return Line;11371138})(Morris.Grid);11391140Morris.labelSeries = function(dmin, dmax, pxwidth, specName, xLabelFormat) {1141var d, d0, ddensity, name, ret, s, spec, t, _i, _len, _ref;1142ddensity = 200 * (dmax - dmin) / pxwidth;1143d0 = new Date(dmin);1144spec = Morris.LABEL_SPECS[specName];1145if (spec === void 0) {1146_ref = Morris.AUTO_LABEL_ORDER;1147for (_i = 0, _len = _ref.length; _i < _len; _i++) {1148name = _ref[_i];1149s = Morris.LABEL_SPECS[name];1150if (ddensity >= s.span) {1151spec = s;1152break;1153}1154}1155}1156if (spec === void 0) {1157spec = Morris.LABEL_SPECS["second"];1158}1159if (xLabelFormat) {1160spec = $.extend({}, spec, {1161fmt: xLabelFormat1162});1163}1164d = spec.start(d0);1165ret = [];1166while ((t = d.getTime()) <= dmax) {1167if (t >= dmin) {1168ret.push([spec.fmt(d), t]);1169}1170spec.incr(d);1171}1172return ret;1173};11741175minutesSpecHelper = function(interval) {1176return {1177span: interval * 60 * 1000,1178start: function(d) {1179return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours());1180},1181fmt: function(d) {1182return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes()));1183},1184incr: function(d) {1185return d.setUTCMinutes(d.getUTCMinutes() + interval);1186}1187};1188};11891190secondsSpecHelper = function(interval) {1191return {1192span: interval * 1000,1193start: function(d) {1194return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes());1195},1196fmt: function(d) {1197return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes())) + ":" + (Morris.pad2(d.getSeconds()));1198},1199incr: function(d) {1200return d.setUTCSeconds(d.getUTCSeconds() + interval);1201}1202};1203};12041205Morris.LABEL_SPECS = {1206"decade": {1207span: 172800000000,1208start: function(d) {1209return new Date(d.getFullYear() - d.getFullYear() % 10, 0, 1);1210},1211fmt: function(d) {1212return "" + (d.getFullYear());1213},1214incr: function(d) {1215return d.setFullYear(d.getFullYear() + 10);1216}1217},1218"year": {1219span: 17280000000,1220start: function(d) {1221return new Date(d.getFullYear(), 0, 1);1222},1223fmt: function(d) {1224return "" + (d.getFullYear());1225},1226incr: function(d) {1227return d.setFullYear(d.getFullYear() + 1);1228}1229},1230"month": {1231span: 2419200000,1232start: function(d) {1233return new Date(d.getFullYear(), d.getMonth(), 1);1234},1235fmt: function(d) {1236return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1));1237},1238incr: function(d) {1239return d.setMonth(d.getMonth() + 1);1240}1241},1242"week": {1243span: 604800000,1244start: function(d) {1245return new Date(d.getFullYear(), d.getMonth(), d.getDate());1246},1247fmt: function(d) {1248return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate()));1249},1250incr: function(d) {1251return d.setDate(d.getDate() + 7);1252}1253},1254"day": {1255span: 86400000,1256start: function(d) {1257return new Date(d.getFullYear(), d.getMonth(), d.getDate());1258},1259fmt: function(d) {1260return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate()));1261},1262incr: function(d) {1263return d.setDate(d.getDate() + 1);1264}1265},1266"hour": minutesSpecHelper(60),1267"30min": minutesSpecHelper(30),1268"15min": minutesSpecHelper(15),1269"10min": minutesSpecHelper(10),1270"5min": minutesSpecHelper(5),1271"minute": minutesSpecHelper(1),1272"30sec": secondsSpecHelper(30),1273"15sec": secondsSpecHelper(15),1274"10sec": secondsSpecHelper(10),1275"5sec": secondsSpecHelper(5),1276"second": secondsSpecHelper(1)1277};12781279Morris.AUTO_LABEL_ORDER = ["decade", "year", "month", "week", "day", "hour", "30min", "15min", "10min", "5min", "minute", "30sec", "15sec", "10sec", "5sec", "second"];12801281Morris.Area = (function(_super) {1282var areaDefaults;12831284__extends(Area, _super);12851286areaDefaults = {1287fillOpacity: 'auto',1288behaveLikeLine: false1289};12901291function Area(options) {1292var areaOptions;1293if (!(this instanceof Morris.Area)) {1294return new Morris.Area(options);1295}1296areaOptions = $.extend({}, areaDefaults, options);1297this.cumulative = !areaOptions.behaveLikeLine;1298if (areaOptions.fillOpacity === 'auto') {1299areaOptions.fillOpacity = areaOptions.behaveLikeLine ? .8 : 1;1300}1301Area.__super__.constructor.call(this, areaOptions);1302}13031304Area.prototype.calcPoints = function() {1305var row, total, y, _i, _len, _ref, _results;1306_ref = this.data;1307_results = [];1308for (_i = 0, _len = _ref.length; _i < _len; _i++) {1309row = _ref[_i];1310row._x = this.transX(row.x);1311total = 0;1312row._y = (function() {1313var _j, _len1, _ref1, _results1;1314_ref1 = row.y;1315_results1 = [];1316for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {1317y = _ref1[_j];1318if (this.options.behaveLikeLine) {1319_results1.push(this.transY(y));1320} else {1321total += y || 0;1322_results1.push(this.transY(total));1323}1324}1325return _results1;1326}).call(this);1327_results.push(row._ymax = Math.max.apply(Math, row._y));1328}1329return _results;1330};13311332Area.prototype.drawSeries = function() {1333var i, range, _i, _j, _k, _len, _ref, _ref1, _results, _results1, _results2;1334this.seriesPoints = [];1335if (this.options.behaveLikeLine) {1336range = (function() {1337_results = [];1338for (var _i = 0, _ref = this.options.ykeys.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }1339return _results;1340}).apply(this);1341} else {1342range = (function() {1343_results1 = [];1344for (var _j = _ref1 = this.options.ykeys.length - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; _ref1 <= 0 ? _j++ : _j--){ _results1.push(_j); }1345return _results1;1346}).apply(this);1347}1348_results2 = [];1349for (_k = 0, _len = range.length; _k < _len; _k++) {1350i = range[_k];1351this._drawFillFor(i);1352this._drawLineFor(i);1353_results2.push(this._drawPointFor(i));1354}1355return _results2;1356};13571358Area.prototype._drawFillFor = function(index) {1359var path;1360path = this.paths[index];1361if (path !== null) {1362path = path + ("L" + (this.transX(this.xmax)) + "," + this.bottom + "L" + (this.transX(this.xmin)) + "," + this.bottom + "Z");1363return this.drawFilledPath(path, this.fillForSeries(index));1364}1365};13661367Area.prototype.fillForSeries = function(i) {1368var color;1369color = Raphael.rgb2hsl(this.colorFor(this.data[i], i, 'line'));1370return Raphael.hsl(color.h, this.options.behaveLikeLine ? color.s * 0.9 : color.s * 0.75, Math.min(0.98, this.options.behaveLikeLine ? color.l * 1.2 : color.l * 1.25));1371};13721373Area.prototype.drawFilledPath = function(path, fill) {1374return this.raphael.path(path).attr('fill', fill).attr('fill-opacity', this.options.fillOpacity).attr('stroke', 'none');1375};13761377return Area;13781379})(Morris.Line);13801381Morris.Bar = (function(_super) {1382__extends(Bar, _super);13831384function Bar(options) {1385this.onHoverOut = __bind(this.onHoverOut, this);1386this.onHoverMove = __bind(this.onHoverMove, this);1387this.onGridClick = __bind(this.onGridClick, this);1388if (!(this instanceof Morris.Bar)) {1389return new Morris.Bar(options);1390}1391Bar.__super__.constructor.call(this, $.extend({}, options, {1392parseTime: false1393}));1394}13951396Bar.prototype.init = function() {1397this.cumulative = this.options.stacked;1398if (this.options.hideHover !== 'always') {1399this.hover = new Morris.Hover({1400parent: this.el1401});1402this.on('hovermove', this.onHoverMove);1403this.on('hoverout', this.onHoverOut);1404return this.on('gridclick', this.onGridClick);1405}1406};14071408Bar.prototype.defaults = {1409barSizeRatio: 0.75,1410barGap: 3,1411barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'],1412barOpacity: 1.0,1413barRadius: [0, 0, 0, 0],1414xLabelMargin: 501415};14161417Bar.prototype.calc = function() {1418var _ref;1419this.calcBars();1420if (this.options.hideHover === false) {1421return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(this.data.length - 1));1422}1423};14241425Bar.prototype.calcBars = function() {1426var idx, row, y, _i, _len, _ref, _results;1427_ref = this.data;1428_results = [];1429for (idx = _i = 0, _len = _ref.length; _i < _len; idx = ++_i) {1430row = _ref[idx];1431row._x = this.left + this.width * (idx + 0.5) / this.data.length;1432_results.push(row._y = (function() {1433var _j, _len1, _ref1, _results1;1434_ref1 = row.y;1435_results1 = [];1436for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {1437y = _ref1[_j];1438if (y != null) {1439_results1.push(this.transY(y));1440} else {1441_results1.push(null);1442}1443}1444return _results1;1445}).call(this));1446}1447return _results;1448};14491450Bar.prototype.draw = function() {1451var _ref;1452if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'x') {1453this.drawXAxis();1454}1455return this.drawSeries();1456};14571458Bar.prototype.drawXAxis = function() {1459var i, label, labelBox, margin, offset, prevAngleMargin, prevLabelMargin, row, textBox, ypos, _i, _ref, _results;1460ypos = this.bottom + (this.options.xAxisLabelTopPadding || this.options.padding / 2);1461prevLabelMargin = null;1462prevAngleMargin = null;1463_results = [];1464for (i = _i = 0, _ref = this.data.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {1465row = this.data[this.data.length - 1 - i];1466label = this.drawXAxisLabel(row._x, ypos, row.label);1467textBox = label.getBBox();1468label.transform("r" + (-this.options.xLabelAngle));1469labelBox = label.getBBox();1470label.transform("t0," + (labelBox.height / 2) + "...");1471if (this.options.xLabelAngle !== 0) {1472offset = -0.5 * textBox.width * Math.cos(this.options.xLabelAngle * Math.PI / 180.0);1473label.transform("t" + offset + ",0...");1474}1475if (((prevLabelMargin == null) || prevLabelMargin >= labelBox.x + labelBox.width || (prevAngleMargin != null) && prevAngleMargin >= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < this.el.width()) {1476if (this.options.xLabelAngle !== 0) {1477margin = 1.25 * this.options.gridTextSize / Math.sin(this.options.xLabelAngle * Math.PI / 180.0);1478prevAngleMargin = labelBox.x - margin;1479}1480_results.push(prevLabelMargin = labelBox.x - this.options.xLabelMargin);1481} else {1482_results.push(label.remove());1483}1484}1485return _results;1486};14871488Bar.prototype.drawSeries = function() {1489var barWidth, bottom, groupWidth, idx, lastTop, left, leftPadding, numBars, row, sidx, size, top, ypos, zeroPos;1490groupWidth = this.width / this.options.data.length;1491numBars = this.options.stacked != null ? 1 : this.options.ykeys.length;1492barWidth = (groupWidth * this.options.barSizeRatio - this.options.barGap * (numBars - 1)) / numBars;1493leftPadding = groupWidth * (1 - this.options.barSizeRatio) / 2;1494zeroPos = this.ymin <= 0 && this.ymax >= 0 ? this.transY(0) : null;1495return this.bars = (function() {1496var _i, _len, _ref, _results;1497_ref = this.data;1498_results = [];1499for (idx = _i = 0, _len = _ref.length; _i < _len; idx = ++_i) {1500row = _ref[idx];1501lastTop = 0;1502_results.push((function() {1503var _j, _len1, _ref1, _results1;1504_ref1 = row._y;1505_results1 = [];1506for (sidx = _j = 0, _len1 = _ref1.length; _j < _len1; sidx = ++_j) {1507ypos = _ref1[sidx];1508if (ypos !== null) {1509if (zeroPos) {1510top = Math.min(ypos, zeroPos);1511bottom = Math.max(ypos, zeroPos);1512} else {1513top = ypos;1514bottom = this.bottom;1515}1516left = this.left + idx * groupWidth + leftPadding;1517if (!this.options.stacked) {1518left += sidx * (barWidth + this.options.barGap);1519}1520size = bottom - top;1521if (this.options.stacked) {1522top -= lastTop;1523}1524this.drawBar(left, top, barWidth, size, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius);1525_results1.push(lastTop += size);1526} else {1527_results1.push(null);1528}1529}1530return _results1;1531}).call(this));1532}1533return _results;1534}).call(this);1535};15361537Bar.prototype.colorFor = function(row, sidx, type) {1538var r, s;1539if (typeof this.options.barColors === 'function') {1540r = {1541x: row.x,1542y: row.y[sidx],1543label: row.label1544};1545s = {1546index: sidx,1547key: this.options.ykeys[sidx],1548label: this.options.labels[sidx]1549};1550return this.options.barColors.call(this, r, s, type);1551} else {1552return this.options.barColors[sidx % this.options.barColors.length];1553}1554};15551556Bar.prototype.hitTest = function(x) {1557if (this.data.length === 0) {1558return null;1559}1560x = Math.max(Math.min(x, this.right), this.left);1561return Math.min(this.data.length - 1, Math.floor((x - this.left) / (this.width / this.data.length)));1562};15631564Bar.prototype.onGridClick = function(x, y) {1565var index;1566index = this.hitTest(x);1567return this.fire('click', index, this.data[index].src, x, y);1568};15691570Bar.prototype.onHoverMove = function(x, y) {1571var index, _ref;1572index = this.hitTest(x);1573return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index));1574};15751576Bar.prototype.onHoverOut = function() {1577if (this.options.hideHover !== false) {1578return this.hover.hide();1579}1580};15811582Bar.prototype.hoverContentForRow = function(index) {1583var content, j, row, x, y, _i, _len, _ref;1584row = this.data[index];1585content = "<div class='morris-hover-row-label'>" + row.label + "</div>";1586_ref = row.y;1587for (j = _i = 0, _len = _ref.length; _i < _len; j = ++_i) {1588y = _ref[j];1589content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";1590}1591if (typeof this.options.hoverCallback === 'function') {1592content = this.options.hoverCallback(index, this.options, content, row.src);1593}1594x = this.left + (index + 0.5) * this.width / this.data.length;1595return [content, x];1596};15971598Bar.prototype.drawXAxisLabel = function(xPos, yPos, text) {1599var label;1600return 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);1601};16021603Bar.prototype.drawBar = function(xPos, yPos, width, height, barColor, opacity, radiusArray) {1604var maxRadius, path;1605maxRadius = Math.max.apply(Math, radiusArray);1606if (maxRadius === 0 || maxRadius > height) {1607path = this.raphael.rect(xPos, yPos, width, height);1608} else {1609path = this.raphael.path(this.roundedRect(xPos, yPos, width, height, radiusArray));1610}1611return path.attr('fill', barColor).attr('fill-opacity', opacity).attr('stroke', 'none');1612};16131614Bar.prototype.roundedRect = function(x, y, w, h, r) {1615if (r == null) {1616r = [0, 0, 0, 0];1617}1618return ["M", x, r[0] + y, "Q", x, y, x + r[0], y, "L", x + w - r[1], y, "Q", x + w, y, x + w, y + r[1], "L", x + w, y + h - r[2], "Q", x + w, y + h, x + w - r[2], y + h, "L", x + r[3], y + h, "Q", x, y + h, x, y + h - r[3], "Z"];1619};16201621return Bar;16221623})(Morris.Grid);16241625Morris.Donut = (function(_super) {1626__extends(Donut, _super);16271628Donut.prototype.defaults = {1629colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],1630backgroundColor: '#FFFFFF',1631labelColor: '#000000',1632formatter: Morris.commas,1633resize: false1634};16351636function Donut(options) {1637this.resizeHandler = __bind(this.resizeHandler, this);1638this.select = __bind(this.select, this);1639this.click = __bind(this.click, this);1640var _this = this;1641if (!(this instanceof Morris.Donut)) {1642return new Morris.Donut(options);1643}1644this.options = $.extend({}, this.defaults, options);1645if (typeof options.element === 'string') {1646this.el = $(document.getElementById(options.element));1647} else {1648this.el = $(options.element);1649}1650if (this.el === null || this.el.length === 0) {1651throw new Error("Graph placeholder not found.");1652}1653if (options.data === void 0 || options.data.length === 0) {1654return;1655}1656this.raphael = new Raphael(this.el[0]);1657if (this.options.resize) {1658$(window).bind('resize', function(evt) {1659if (_this.timeoutId != null) {1660window.clearTimeout(_this.timeoutId);1661}1662return _this.timeoutId = window.setTimeout(_this.resizeHandler, 100);1663});1664}1665this.setData(options.data);1666}16671668Donut.prototype.redraw = function() {1669var C, cx, cy, i, idx, last, max_value, min, next, seg, total, value, w, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;1670this.raphael.clear();1671cx = this.el.width() / 2;1672cy = this.el.height() / 2;1673w = (Math.min(cx, cy) - 10) / 3;1674total = 0;1675_ref = this.values;1676for (_i = 0, _len = _ref.length; _i < _len; _i++) {1677value = _ref[_i];1678total += value;1679}1680min = 5 / (2 * w);1681C = 1.9999 * Math.PI - min * this.data.length;1682last = 0;1683idx = 0;1684this.segments = [];1685_ref1 = this.values;1686for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) {1687value = _ref1[i];1688next = last + min + C * (value / total);1689seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.data[i].color || this.options.colors[idx % this.options.colors.length], this.options.backgroundColor, idx, this.raphael);1690seg.render();1691this.segments.push(seg);1692seg.on('hover', this.select);1693seg.on('click', this.click);1694last = next;1695idx += 1;1696}1697this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, this.options.labelColor, 15, 800);1698this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, this.options.labelColor, 14);1699max_value = Math.max.apply(Math, this.values);1700idx = 0;1701_ref2 = this.values;1702_results = [];1703for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {1704value = _ref2[_k];1705if (value === max_value) {1706this.select(idx);1707break;1708}1709_results.push(idx += 1);1710}1711return _results;1712};17131714Donut.prototype.setData = function(data) {1715var row;1716this.data = data;1717this.values = (function() {1718var _i, _len, _ref, _results;1719_ref = this.data;1720_results = [];1721for (_i = 0, _len = _ref.length; _i < _len; _i++) {1722row = _ref[_i];1723_results.push(parseFloat(row.value));1724}1725return _results;1726}).call(this);1727return this.redraw();1728};17291730Donut.prototype.click = function(idx) {1731return this.fire('click', idx, this.data[idx]);1732};17331734Donut.prototype.select = function(idx) {1735var row, s, segment, _i, _len, _ref;1736_ref = this.segments;1737for (_i = 0, _len = _ref.length; _i < _len; _i++) {1738s = _ref[_i];1739s.deselect();1740}1741segment = this.segments[idx];1742segment.select();1743row = this.data[idx];1744return this.setLabels(row.label, this.options.formatter(row.value, row));1745};17461747Donut.prototype.setLabels = function(label1, label2) {1748var inner, maxHeightBottom, maxHeightTop, maxWidth, text1bbox, text1scale, text2bbox, text2scale;1749inner = (Math.min(this.el.width() / 2, this.el.height() / 2) - 10) * 2 / 3;1750maxWidth = 1.8 * inner;1751maxHeightTop = inner / 2;1752maxHeightBottom = inner / 3;1753this.text1.attr({1754text: label1,1755transform: ''1756});1757text1bbox = this.text1.getBBox();1758text1scale = Math.min(maxWidth / text1bbox.width, maxHeightTop / text1bbox.height);1759this.text1.attr({1760transform: "S" + text1scale + "," + text1scale + "," + (text1bbox.x + text1bbox.width / 2) + "," + (text1bbox.y + text1bbox.height)1761});1762this.text2.attr({1763text: label2,1764transform: ''1765});1766text2bbox = this.text2.getBBox();1767text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height);1768return this.text2.attr({1769transform: "S" + text2scale + "," + text2scale + "," + (text2bbox.x + text2bbox.width / 2) + "," + text2bbox.y1770});1771};17721773Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, color, fontSize, fontWeight) {1774var text;1775text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize).attr('fill', color);1776if (fontWeight != null) {1777text.attr('font-weight', fontWeight);1778}1779return text;1780};17811782Donut.prototype.resizeHandler = function() {1783this.timeoutId = null;1784this.raphael.setSize(this.el.width(), this.el.height());1785return this.redraw();1786};17871788return Donut;17891790})(Morris.EventEmitter);17911792Morris.DonutSegment = (function(_super) {1793__extends(DonutSegment, _super);17941795function DonutSegment(cx, cy, inner, outer, p0, p1, color, backgroundColor, index, raphael) {1796this.cx = cx;1797this.cy = cy;1798this.inner = inner;1799this.outer = outer;1800this.color = color;1801this.backgroundColor = backgroundColor;1802this.index = index;1803this.raphael = raphael;1804this.deselect = __bind(this.deselect, this);1805this.select = __bind(this.select, this);1806this.sin_p0 = Math.sin(p0);1807this.cos_p0 = Math.cos(p0);1808this.sin_p1 = Math.sin(p1);1809this.cos_p1 = Math.cos(p1);1810this.is_long = (p1 - p0) > Math.PI ? 1 : 0;1811this.path = this.calcSegment(this.inner + 3, this.inner + this.outer - 5);1812this.selectedPath = this.calcSegment(this.inner + 3, this.inner + this.outer);1813this.hilight = this.calcArc(this.inner);1814}18151816DonutSegment.prototype.calcArcPoints = function(r) {1817return [this.cx + r * this.sin_p0, this.cy + r * this.cos_p0, this.cx + r * this.sin_p1, this.cy + r * this.cos_p1];1818};18191820DonutSegment.prototype.calcSegment = function(r1, r2) {1821var ix0, ix1, iy0, iy1, ox0, ox1, oy0, oy1, _ref, _ref1;1822_ref = this.calcArcPoints(r1), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];1823_ref1 = this.calcArcPoints(r2), ox0 = _ref1[0], oy0 = _ref1[1], ox1 = _ref1[2], oy1 = _ref1[3];1824return ("M" + ix0 + "," + iy0) + ("A" + r1 + "," + r1 + ",0," + this.is_long + ",0," + ix1 + "," + iy1) + ("L" + ox1 + "," + oy1) + ("A" + r2 + "," + r2 + ",0," + this.is_long + ",1," + ox0 + "," + oy0) + "Z";1825};18261827DonutSegment.prototype.calcArc = function(r) {1828var ix0, ix1, iy0, iy1, _ref;1829_ref = this.calcArcPoints(r), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];1830return ("M" + ix0 + "," + iy0) + ("A" + r + "," + r + ",0," + this.is_long + ",0," + ix1 + "," + iy1);1831};18321833DonutSegment.prototype.render = function() {1834var _this = this;1835this.arc = this.drawDonutArc(this.hilight, this.color);1836return this.seg = this.drawDonutSegment(this.path, this.color, this.backgroundColor, function() {1837return _this.fire('hover', _this.index);1838}, function() {1839return _this.fire('click', _this.index);1840});1841};18421843DonutSegment.prototype.drawDonutArc = function(path, color) {1844return this.raphael.path(path).attr({1845stroke: color,1846'stroke-width': 2,1847opacity: 01848});1849};18501851DonutSegment.prototype.drawDonutSegment = function(path, fillColor, strokeColor, hoverFunction, clickFunction) {1852return this.raphael.path(path).attr({1853fill: fillColor,1854stroke: strokeColor,1855'stroke-width': 31856}).hover(hoverFunction).click(clickFunction);1857};18581859DonutSegment.prototype.select = function() {1860if (!this.selected) {1861this.seg.animate({1862path: this.selectedPath1863}, 150, '<>');1864this.arc.animate({1865opacity: 11866}, 150, '<>');1867return this.selected = true;1868}1869};18701871DonutSegment.prototype.deselect = function() {1872if (this.selected) {1873this.seg.animate({1874path: this.path1875}, 150, '<>');1876this.arc.animate({1877opacity: 01878}, 150, '<>');1879return this.selected = false;1880}1881};18821883return DonutSegment;18841885})(Morris.EventEmitter);18861887}).call(this);18881889