1/* @license 2morris.js06 v0.6.9 3https://pierresh.github.io/morris.js/ 4Copyright 2021 Olly Smith All rights reserved. 5Licensed under the BSD-2-Clause License. 6*/ 7 8 9(function() { 10 var Morris, compStyle, minutesSpecHelper, secondsSpecHelper, 11 __slice = [].slice, 12 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 13 __hasProp = {}.hasOwnProperty, 14 __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; }, 15 __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; }; 16 17 Morris = window.Morris = {}; 18 19 compStyle = function(el) { 20 if (getComputedStyle) { 21 return getComputedStyle(el, null); 22 } else if (el.currentStyle) { 23 return el.currentStyle; 24 } else { 25 return el.style; 26 } 27 }; 28 29 Morris.EventEmitter = (function() { 30 function EventEmitter() {} 31 32 EventEmitter.prototype.on = function(name, handler) { 33 if (this.handlers == null) { 34 this.handlers = {}; 35 } 36 if (this.handlers[name] == null) { 37 this.handlers[name] = []; 38 } 39 this.handlers[name].push(handler); 40 return this; 41 }; 42 43 EventEmitter.prototype.fire = function() { 44 var args, handler, name, _i, _len, _ref, _results; 45 name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; 46 if ((this.handlers != null) && (this.handlers[name] != null)) { 47 _ref = this.handlers[name]; 48 _results = []; 49 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 50 handler = _ref[_i]; 51 _results.push(handler.apply(null, args)); 52 } 53 return _results; 54 } 55 }; 56 57 return EventEmitter; 58 59 })(); 60 61 Morris.commas = function(num) { 62 var absnum, intnum, ret, strabsnum; 63 if (num != null) { 64 ret = num < 0 ? "-" : ""; 65 absnum = Math.abs(num); 66 intnum = Math.floor(absnum).toFixed(0); 67 ret += intnum.replace(/(?=(?:\d{3})+$)(?!^)/g, ','); 68 strabsnum = absnum.toString(); 69 if (strabsnum.length > intnum.length) { 70 ret += strabsnum.slice(intnum.length); 71 } 72 return ret; 73 } else { 74 return '-'; 75 } 76 }; 77 78 Morris.pad2 = function(number) { 79 return (number < 10 ? '0' : '') + number; 80 }; 81 82 Morris.extend = function() { 83 var key, object, objects, properties, val, _i, _len; 84 object = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : []; 85 if (object == null) { 86 object = {}; 87 } 88 for (_i = 0, _len = objects.length; _i < _len; _i++) { 89 properties = objects[_i]; 90 if (properties != null) { 91 for (key in properties) { 92 val = properties[key]; 93 if (properties.hasOwnProperty(key)) { 94 object[key] = val; 95 } 96 } 97 } 98 } 99 return object; 100 }; 101 102 Morris.offset = function(el) { 103 var rect; 104 rect = el.getBoundingClientRect(); 105 return { 106 top: rect.top + document.body.scrollTop, 107 left: rect.left + document.body.scrollLeft 108 }; 109 }; 110 111 Morris.css = function(el, prop) { 112 return compStyle(el)[prop]; 113 }; 114 115 Morris.on = function(el, eventName, fn) { 116 if (el.addEventListener) { 117 return el.addEventListener(eventName, fn); 118 } else { 119 return el.attachEvent('on' + eventName, fn); 120 } 121 }; 122 123 Morris.off = function(el, eventName, fn) { 124 if (el.removeEventListener) { 125 return el.removeEventListener(eventName, fn); 126 } else { 127 return el.detachEvent('on' + eventName, fn); 128 } 129 }; 130 131 Morris.dimensions = function(el) { 132 var style; 133 style = compStyle(el); 134 return { 135 width: parseInt(style.width), 136 height: parseInt(style.height) 137 }; 138 }; 139 140 Morris.innerDimensions = function(el) { 141 var style; 142 style = compStyle(el); 143 return { 144 width: parseInt(style.width) + parseInt(style.paddingLeft) + parseInt(style.paddingRight), 145 height: parseInt(style.height) + parseInt(style.paddingTop) + parseInt(style.paddingBottom) 146 }; 147 }; 148 149 Morris.Grid = (function(_super) { 150 __extends(Grid, _super); 151 152 function Grid(options) { 153 this.setLabels = __bind(this.setLabels, this); 154 this.hasToShow = __bind(this.hasToShow, this); 155 this.debouncedResizeHandler = __bind(this.debouncedResizeHandler, this); 156 this.resizeHandler = __bind(this.resizeHandler, this); 157 this.mouseupHandler = __bind(this.mouseupHandler, this); 158 this.mousedownHandler = __bind(this.mousedownHandler, this); 159 this.clickHandler = __bind(this.clickHandler, this); 160 this.touchHandler = __bind(this.touchHandler, this); 161 this.mouseleaveHandler = __bind(this.mouseleaveHandler, this); 162 this.mousemoveHandler = __bind(this.mousemoveHandler, this); 163 if (typeof options.element === 'string') { 164 this.el = document.getElementById(options.element); 165 } else { 166 this.el = options.element[0] || options.element; 167 } 168 if (this.el == null) { 169 throw new Error("Graph container element not found"); 170 } 171 if (Morris.css(this.el, 'position') === 'static') { 172 this.el.style.position = 'relative'; 173 } 174 this.options = Morris.extend({}, this.gridDefaults, this.defaults || {}, options); 175 if (typeof this.options.units === 'string') { 176 this.options.postUnits = options.units; 177 } 178 this.raphael = new Raphael(this.el); 179 this.elementWidth = null; 180 this.elementHeight = null; 181 this.dirty = false;
182 this.selectFrom = null; 183 if (this.init) { 184 this.init(); 185 } 186 this.setData(this.options.data); 187 Morris.on(this.el, 'mousemove', this.mousemoveHandler); 188 Morris.on(this.el, 'mouseleave', this.mouseleaveHandler); 189 Morris.on(this.el, 'touchstart touchmove touchend', this.touchHandler); 190 Morris.on(this.el, 'click', this.clickHandler); 191 if (this.options.rangeSelect) { 192 this.selectionRect = this.raphael.rect(0, 0, 0, Morris.innerDimensions(this.el).height).attr({ 193 fill: this.options.rangeSelectColor, 194 stroke: false 195 }).toBack().hide(); 196 Morris.on(this.el, 'mousedown', this.mousedownHandler); 197 Morris.on(this.el, 'mouseup', this.mouseupHandler); 198 } 199 if (this.options.resize) { 200 Morris.on(window, 'resize', this.resizeHandler); 201 } 202 this.el.style.webkitTapHighlightColor = 'rgba(0,0,0,0)'; 203 if (this.postInit) { 204 this.postInit(); 205 } 206 } 207 208 Grid.prototype.gridDefaults = { 209 dateFormat: null, 210 axes: true, 211 freePosition: false, 212 grid: true, 213 gridIntegers: false, 214 gridLineColor: '#aaa', 215 gridStrokeWidth: 0.5, 216 gridTextColor: '#888', 217 gridTextSize: 12, 218 gridTextFamily: 'sans-serif', 219 gridTextWeight: 'normal', 220 hideHover: 'auto', 221 yLabelFormat: null, 222 yLabelAlign: 'right', 223 yLabelAlign2: 'left', 224 xLabelAngle: 0, 225 numLines: 5, 226 padding: 25, 227 parseTime: true, 228 postUnits: '', 229 postUnits2: '', 230 preUnits: '', 231 preUnits2: '', 232 ymax: 'auto', 233 ymin: 'auto 0', 234 ymax2: 'auto', 235 ymin2: 'auto 0', 236 regions: [], 237 regionsColors: ['#fde4e4'], 238 goals: [], 239 goals2: [], 240 goalStrokeWidth: 1.0, 241 goalStrokeWidth2: 1.0, 242 goalLineColors: ['red'], 243 goalLineColors2: ['red'], 244 events: [], 245 eventStrokeWidth: 1.0, 246 eventLineColors: ['#005a04'], 247 rangeSelect: null, 248 rangeSelectColor: '#eef', 249 resize: true, 250 dataLabels: true, 251 dataLabelsPosition: 'outside', 252 dataLabelsFamily: 'sans-serif', 253 dataLabelsSize: 12, 254 dataLabelsWeight: 'normal', 255 dataLabelsColor: 'auto', 256 animate: true, 257 nbYkeys2: 0, 258 smooth: true 259 }; 260 261 Grid.prototype.destroy = function() { 262 Morris.off(this.el, 'mousemove', this.mousemoveHandler); 263 Morris.off(this.el, 'mouseleave', this.mouseleaveHandler); 264 Morris.off(this.el, 'touchstart touchmove touchend', this.touchHandler); 265 Morris.off(this.el, 'click', this.clickHandler); 266 if (this.options.rangeSelect) { 267 Morris.off(this.el, 'mousedown', this.mousedownHandler); 268 Morris.off(this.el, 'mouseup', this.mouseupHandler); 269 } 270 if (this.options.resize) { 271 window.clearTimeout(this.timeoutId); 272 return Morris.off(window, 'resize', this.resizeHandler); 273 } 274 }; 275 276 Grid.prototype.setData = function(data, redraw) { 277 var e, flatEvents, from, idx, index, maxGoal, minGoal, ret, row, step, step2, to, total, y, ykey, ymax, ymax2, ymin, ymin2, yval, _i, _len, _ref, _ref1; 278 if (redraw == null) { 279 redraw = true; 280 } 281 this.options.data = data; 282 if ((data == null) || data.length === 0) { 283 this.data = []; 284 this.raphael.clear(); 285 if (this.hover != null) { 286 this.hover.hide(); 287 } 288 return; 289 } 290 ymax = this.cumulative ? 0 : null; 291 ymin = this.cumulative ? 0 : null; 292 ymax2 = this.cumulative ? 0 : null; 293 ymin2 = this.cumulative ? 0 : null; 294 if (this.options.goals.length > 0) { 295 minGoal = Math.min.apply(Math, this.options.goals); 296 maxGoal = Math.max.apply(Math, this.options.goals); 297 ymin = ymin != null ? Math.min(ymin, minGoal) : minGoal; 298 ymax = ymax != null ? Math.max(ymax, maxGoal) : maxGoal; 299 } 300 if (this.options.goals2.length > 0) { 301 minGoal = Math.min.apply(Math, this.options.goals2); 302 maxGoal = Math.max.apply(Math, this.options.goals2); 303 ymin2 = ymin2 != null ? Math.min(ymin2, minGoal) : minGoal;
304 ymax2 = ymax2 != null ? Math.max(ymax2, maxGoal) : maxGoal; 305 } 306 if (this.options.nbYkeys2 > this.options.ykeys.length) { 307 this.options.nbYkeys2 = this.options.ykeys.length; 308 } 309 this.data = (function() { 310 var _i, _len, _results; 311 _results = []; 312 for (index = _i = 0, _len = data.length; _i < _len; index = ++_i) { 313 row = data[index]; 314 ret = { 315 src: row 316 }; 317 ret.label = row[this.options.xkey]; 318 if (this.options.parseTime) { 319 ret.x = Morris.parseDate(ret.label); 320 if (this.options.dateFormat) { 321 ret.label = this.options.dateFormat(ret.x); 322 } else if (typeof ret.label === 'number') { 323 ret.label = new Date(ret.label).toString(); 324 } 325 } else if (this.options.freePosition) { 326 ret.x = parseFloat(row[this.options.xkey]); 327 if (this.options.xLabelFormat) { 328 ret.label = this.options.xLabelFormat(ret); 329 } 330 } else { 331 ret.x = index; 332 if (this.options.xLabelFormat) { 333 ret.label = this.options.xLabelFormat(ret); 334 } 335 } 336 total = 0; 337 ret.y = (function() { 338 var _j, _len1, _ref, _results1; 339 _ref = this.options.ykeys; 340 _results1 = []; 341 for (idx = _j = 0, _len1 = _ref.length; _j < _len1; idx = ++_j) { 342 ykey = _ref[idx]; 343 yval = row[ykey]; 344 if (typeof yval === 'string') { 345 yval = parseFloat(yval); 346 } 347 if ((yval != null) && typeof yval !== 'number') { 348 yval = null; 349 } 350 if (idx < this.options.ykeys.length - this.options.nbYkeys2) { 351 if ((yval != null) && this.hasToShow(idx)) { 352 if (this.cumulative) { 353 if (total < 0 && yval > 0) { 354 total = yval; 355 } else { 356 total += yval; 357 } 358 } else { 359 if (ymax != null) { 360 ymax = Math.max(yval, ymax); 361 ymin = Math.min(yval, ymin); 362 } else { 363 ymax = ymin = yval; 364 } 365 } 366 } 367 if (this.cumulative && (total != null)) { 368 ymax = Math.max(total, ymax); 369 ymin = Math.min(total, ymin); 370 } 371 } else { 372 if ((yval != null) && this.hasToShow(idx)) { 373 if (this.cumulative) { 374 total = yval; 375 } else { 376 if (ymax2 != null) { 377 ymax2 = Math.max(yval, ymax2); 378 ymin2 = Math.min(yval, ymin2); 379 } else { 380 ymax2 = ymin2 = yval; 381 } 382 } 383 } 384 if (this.cumulative && (total != null)) { 385 ymax2 = Math.max(total, ymax2); 386 ymin2 = Math.min(total, ymin2); 387 } 388 } 389 _results1.push(yval); 390 } 391 return _results1; 392 }).call(this); 393 _results.push(ret); 394 } 395 return _results; 396 }).call(this); 397 if (this.options.parseTime || this.options.freePosition) { 398 this.data = this.data.sort(function(a, b) { 399 return (a.x > b.x) - (b.x > a.x); 400 }); 401 } 402 this.xmin = this.data[0].x; 403 this.xmax = this.data[this.data.length - 1].x; 404 this.events = []; 405 if (this.options.events.length > 0) { 406 if (this.options.parseTime) { 407 _ref = this.options.events; 408 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 409 e = _ref[_i]; 410 if (e instanceof Array) { 411 from = e[0], to = e[1]; 412 this.events.push([Morris.parseDate(from), Morris.parseDate(to)]); 413 } else { 414 this.events.push(Morris.parseDate(e)); 415 } 416 } 417 } else { 418 this.events = this.options.events; 419 } 420 flatEvents = this.events.map(function(e) { 421 return e; 422 }); 423 this.xmax = Math.max(this.xmax, Math.max.apply(Math, flatEvents)); 424 this.xmin = Math.min(this.xmin, Math.min.apply(Math, flatEvents)); 425 } 426 if (this.xmin === this.xmax) { 427 this.xmin -= 1; 428 this.xmax += 1; 429 } 430 this.ymin = this.yboundary('min', ymin); 431 this.ymax = this.yboundary('max', ymax); 432 this.ymin2 = this.yboundary('min2', ymin2); 433 this.ymax2 = this.yboundary('max2', ymax2); 434 if (this.ymin === this.ymax) { 435 if (ymin) { 436 this.ymin -= 1; 437 } 438 this.ymax += 1; 439 } 440 if (this.ymin2 === this.ymax2) { 441 if (ymin2) { 442 this.ymin2 -= 1; 443 } 444 this.ymax2 += 1; 445 } 446 if (((_ref1 = this.options.axes) === true || _ref1 === 'both' || _ref1 === 'y') || this.options.grid === true) { 447 if (this.options.ymax === this.gridDefaults.ymax && this.options.ymin === this.gridDefaults.ymin) { 448 this.grid = this.autoGridLines(this.ymin, this.ymax, this.options.numLines); 449 this.ymin = Math.min(this.ymin, this.grid[0]); 450 this.ymax = Math.max(this.ymax, this.grid[this.grid.length - 1]); 451 } else { 452 step = (this.ymax - this.ymin) / (this.options.numLines - 1); 453 if (this.options.gridIntegers) { 454 step = Math.max(1, Math.round(step)); 455 } 456 this.grid = (function() { 457 var _j, _ref2, _ref3, _results; 458 _results = []; 459 for (y = _j = _ref2 = this.ymin, _ref3 = this.ymax; step > 0 ? _j <= _ref3 : _j >= _ref3; y = _j += step) { 460 _results.push(parseFloat(y.toFixed(2))); 461 } 462 return _results; 463 }).call(this); 464 } 465 if (this.options.ymax2 === this.gridDefaults.ymax2 && this.options.ymin2 === this.gridDefaults.ymin2 && this.options.nbYkeys2 > 0) { 466 this.grid2 = this.autoGridLines(this.ymin2, this.ymax2, this.options.numLines); 467 this.ymin2 = Math.min(this.ymin2, this.grid2[0]); 468 this.ymax2 = Math.max(this.ymax2, this.grid2[this.grid2.length - 1]); 469 } else { 470 step2 = (this.ymax2 - this.ymin2) / (this.options.numLines - 1); 471 this.grid2 = (function() { 472 var _j, _ref2, _ref3, _results; 473 _results = []; 474 for (y = _j = _ref2 = this.ymin2, _ref3 = this.ymax2; step2 > 0 ? _j <= _ref3 : _j >= _ref3; y = _j += step2) { 475 _results.push(parseFloat(y.toFixed(2))); 476 } 477 return _results; 478 }).call(this); 479 } 480 } 481 this.dirty = true; 482 if (redraw) { 483 return this.redraw(); 484 } 485 }; 486
487 Grid.prototype.yboundary = function(boundaryType, currentValue) { 488 var boundaryOption, suggestedValue; 489 boundaryOption = this.options["y" + boundaryType]; 490 if (typeof boundaryOption === 'string') { 491 if (boundaryOption.slice(0, 4) === 'auto') { 492 if (boundaryOption.length > 5) { 493 suggestedValue = parseInt(boundaryOption.slice(5), 10); 494 if (currentValue == null) { 495 return suggestedValue; 496 } 497 return Math[boundaryType.substring(0, 3)](currentValue, suggestedValue); 498 } else { 499 if (currentValue != null) { 500 return currentValue; 501 } else { 502 return 0; 503 } 504 } 505 } else { 506 return parseInt(boundaryOption, 10); 507 } 508 } else { 509 return boundaryOption; 510 } 511 }; 512 513 Grid.prototype.autoGridLines = function(ymin, ymax, nlines) { 514 var gmax, gmin, grid, smag, span, step, unit, y, ymag; 515 span = ymax - ymin; 516 ymag = Math.floor(Math.log(span) / Math.log(10)); 517 unit = Math.pow(10, ymag); 518 gmin = Math.floor(ymin / unit) * unit; 519 gmax = Math.ceil(ymax / unit) * unit; 520 step = (gmax - gmin) / (nlines - 1); 521 if (unit === 1 && step > 1 && Math.ceil(step) !== step) { 522 step = Math.ceil(step); 523 gmax = gmin + step * (nlines - 1); 524 } 525 if (gmin < 0 && gmax > 0) { 526 gmin = Math.floor(ymin / step) * step; 527 gmax = Math.ceil(ymax / step) * step; 528 } 529 if (step < 1) { 530 smag = Math.floor(Math.log(step) / Math.log(10)); 531 grid = (function() { 532 var _i, _results; 533 _results = []; 534 for (y = _i = gmin; step > 0 ? _i <= gmax : _i >= gmax; y = _i += step) { 535 _results.push(parseFloat(y.toFixed(1 - smag))); 536 } 537 return _results; 538 })(); 539 } else { 540 grid = (function() { 541 var _i, _results; 542 _results = []; 543 for (y = _i = gmin; step > 0 ? _i <= gmax : _i >= gmax; y = _i += step) { 544 _results.push(y); 545 } 546 return _results; 547 })(); 548 } 549 return grid; 550 }; 551 552 Grid.prototype._calc = function() { 553 var angle, bottomOffsets, gridLine, h, i, w, yLabelWidths, yLabelWidths2, _ref, _ref1, _ref2; 554 _ref = Morris.dimensions(this.el), w = _ref.width, h = _ref.height; 555 if (this.elementWidth !== w || this.elementHeight !== h || this.dirty) { 556 this.elementWidth = w; 557 this.elementHeight = h; 558 this.dirty = false; 559 this.left = this.options.padding; 560 this.right = this.elementWidth - this.options.padding; 561 this.top = this.options.padding; 562 this.bottom = this.elementHeight - this.options.padding; 563 if ((_ref1 = this.options.axes) === true || _ref1 === 'both' || _ref1 === 'y') { 564 if (this.grid != null) { 565 yLabelWidths = (function() { 566 var _i, _len, _ref2, _results; 567 _ref2 = this.grid; 568 _results = []; 569 for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 570 gridLine = _ref2[_i]; 571 _results.push(this.measureText(this.yAxisFormat(gridLine)).width); 572 } 573 return _results; 574 }).call(this); 575 } 576 if (this.options.nbYkeys2 > 0) { 577 yLabelWidths2 = (function() { 578 var _i, _len, _ref2, _results; 579 _ref2 = this.grid2; 580 _results = []; 581 for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 582 gridLine = _ref2[_i]; 583 _results.push(this.measureText(this.yAxisFormat2(gridLine)).width); 584 } 585 return _results; 586 }).call(this); 587 } 588 if (!this.options.horizontal) { 589 this.left += Math.max.apply(Math, yLabelWidths); 590 if (this.options.nbYkeys2 > 0) { 591 this.right -= Math.max.apply(Math, yLabelWidths2); 592 } 593 } else { 594 this.bottom -= this.options.padding / 2; 595 } 596 } 597 if ((_ref2 = this.options.axes) === true || _ref2 === 'both' || _ref2 === 'x') { 598 if (!this.options.horizontal) { 599 angle = -this.options.xLabelAngle; 600 } else { 601 angle = -90; 602 } 603 bottomOffsets = (function() { 604 var _i, _ref3, _results; 605 _results = []; 606 for (i = _i = 0, _ref3 = this.data.length; 0 <= _ref3 ? _i < _ref3 : _i > _ref3; i = 0 <= _ref3 ? ++_i : --_i) { 607 _results.push(this.measureText(this.data[i].label, angle).height); 608 } 609 return _results; 610 }).call(this); 611 if (!this.options.horizontal) { 612 this.bottom -= Math.max.apply(Math, bottomOffsets); 613 } else { 614 this.left += Math.max.apply(Math, bottomOffsets); 615 } 616 } 617 this.width = Math.max(1, this.right - this.left); 618 this.height = Math.max(1, this.bottom - this.top); 619 if (!this.options.horizontal) { 620 this.dx = this.width / (this.xmax - this.xmin);
621 this.dy = this.height / (this.ymax - this.ymin); 622 this.dy2 = this.height / (this.ymax2 - this.ymin2); 623 this.yStart = this.bottom; 624 this.yEnd = this.top; 625 this.xStart = this.left; 626 this.xEnd = this.right; 627 this.xSize = this.width; 628 this.ySize = this.height; 629 } else { 630 this.dx = this.height / (this.xmax - this.xmin); 631 this.dy = this.width / (this.ymax - this.ymin); 632 this.dy2 = this.width / (this.ymax2 - this.ymin2); 633 this.yStart = this.left; 634 this.yEnd = this.right; 635 this.xStart = this.top; 636 this.xEnd = this.bottom; 637 this.xSize = this.height; 638 this.ySize = this.width; 639 } 640 if (this.calc) { 641 return this.calc(); 642 } 643 } 644 }; 645 646 Grid.prototype.transY = function(y) { 647 if (!this.options.horizontal) { 648 return this.bottom - (y - this.ymin) * this.dy; 649 } else { 650 return this.left + (y - this.ymin) * this.dy; 651 } 652 }; 653 654 Grid.prototype.transY2 = function(y) { 655 if (!this.options.horizontal) { 656 return this.bottom - (y - this.ymin2) * this.dy2; 657 } else { 658 return this.left + (y - this.ymin2) * this.dy2; 659 } 660 }; 661 662 Grid.prototype.transX = function(x) { 663 if (this.data.length === 1) { 664 return (this.xStart + this.xEnd) / 2; 665 } else { 666 return this.xStart + (x - this.xmin) * this.dx; 667 } 668 }; 669 670 Grid.prototype.redraw = function() { 671 this.raphael.clear(); 672 this._calc(); 673 this.drawGrid(); 674 this.drawRegions(); 675 this.drawEvents(); 676 if (this.draw) { 677 this.draw(); 678 } 679 this.drawGoals(); 680 return this.setLabels(); 681 }; 682 683 Grid.prototype.measureText = function(text, angle) { 684 var ret, tt; 685 if (angle == null) { 686 angle = 0; 687 } 688 tt = 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); 689 ret = tt.getBBox(); 690 tt.remove(); 691 return ret; 692 }; 693 694 Grid.prototype.yAxisFormat = function(label) { 695 return this.yLabelFormat(label, 0); 696 }; 697 698 Grid.prototype.yAxisFormat2 = function(label) { 699 return this.yLabelFormat(label, 1000); 700 }; 701 702 Grid.prototype.yLabelFormat = function(label, i) { 703 if (typeof this.options.yLabelFormat === 'function') { 704 return this.options.yLabelFormat(label, i); 705 } else { 706 if (this.options.nbYkeys2 === 0 || (i <= this.options.ykeys.length - this.options.nbYkeys2 - 1)) { 707 return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits; 708 } else { 709 return "" + this.options.preUnits2 + (Morris.commas(label)) + this.options.postUnits2; 710 } 711 } 712 }; 713 714 Grid.prototype.yLabelFormat_noUnit = function(label, i) { 715 if (typeof this.options.yLabelFormat === 'function') { 716 return this.options.yLabelFormat(label, i); 717 } else { 718 return "" + (Morris.commas(label)); 719 } 720 }; 721 722 Grid.prototype.getYAxisLabelX = function() { 723 if (this.options.yLabelAlign === 'right') { 724 return this.left - this.options.padding / 2; 725 } else { 726 return this.options.padding / 2; 727 } 728 }; 729 730 Grid.prototype.drawGrid = function() { 731 var basePos, basePos2, lineY, pos, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3, _ref4, _results; 732 if (this.options.grid === false && ((_ref = this.options.axes) !== true && _ref !== 'both' && _ref !== 'y')) { 733 return; 734 } 735 if (!this.options.horizontal) { 736 basePos = this.getYAxisLabelX(); 737 basePos2 = this.right + this.options.padding / 2; 738 } else { 739 basePos = this.getXAxisLabelY(); 740 basePos2 = this.top - (this.options.xAxisLabelTopPadding || this.options.padding / 2); 741 } 742 if (this.grid != null) { 743 _ref1 = this.grid; 744 for (_i = 0, _len = _ref1.length; _i < _len; _i++) { 745 lineY = _ref1[_i]; 746 pos = this.transY(lineY); 747 if ((_ref2 = this.options.axes) === true || _ref2 === 'both' || _ref2 === 'y') { 748 if (!this.options.horizontal) { 749 this.drawYAxisLabel(basePos, pos, this.yAxisFormat(lineY), 1); 750 } else { 751 this.drawXAxisLabel(pos, basePos, this.yAxisFormat(lineY)); 752 } 753 } 754 if (this.options.grid) { 755 pos = Math.floor(pos) + 0.5; 756 if (!this.options.horizontal) { 757 if (isNaN(this.xEnd)) { 758 this.xEnd = 20; 759 }
760 this.drawGridLine("M" + this.xStart + "," + pos + "H" + this.xEnd); 761 } else { 762 this.drawGridLine("M" + pos + "," + this.xStart + "V" + this.xEnd); 763 } 764 } 765 } 766 } 767 if (this.options.nbYkeys2 > 0) { 768 _ref3 = this.grid2; 769 _results = []; 770 for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { 771 lineY = _ref3[_j]; 772 pos = this.transY2(lineY); 773 if ((_ref4 = this.options.axes) === true || _ref4 === 'both' || _ref4 === 'y') { 774 if (!this.options.horizontal) { 775 _results.push(this.drawYAxisLabel(basePos2, pos, this.yAxisFormat2(lineY), 2)); 776 } else { 777 _results.push(this.drawXAxisLabel(pos, basePos2, this.yAxisFormat2(lineY))); 778 } 779 } else { 780 _results.push(void 0); 781 } 782 } 783 return _results; 784 } 785 }; 786 787 Grid.prototype.drawRegions = function() { 788 var color, i, region, _i, _len, _ref, _results; 789 _ref = this.options.regions; 790 _results = []; 791 for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { 792 region = _ref[i]; 793 color = this.options.regionsColors[i % this.options.regionsColors.length]; 794 _results.push(this.drawRegion(region, color)); 795 } 796 return _results; 797 }; 798 799 Grid.prototype.drawGoals = function() { 800 var color, goal, i, _i, _j, _len, _len1, _ref, _ref1, _results; 801 _ref = this.options.goals; 802 for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { 803 goal = _ref[i]; 804 color = this.options.goalLineColors[i % this.options.goalLineColors.length]; 805 this.drawGoal(goal, color); 806 } 807 _ref1 = this.options.goals2; 808 _results = []; 809 for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { 810 goal = _ref1[i]; 811 color = this.options.goalLineColors2[i % this.options.goalLineColors2.length]; 812 _results.push(this.drawGoal2(goal, color)); 813 } 814 return _results; 815 }; 816 817 Grid.prototype.drawEvents = function() { 818 var color, event, i, _i, _len, _ref, _results; 819 if (this.events != null) { 820 _ref = this.events; 821 _results = []; 822 for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { 823 event = _ref[i]; 824 color = this.options.eventLineColors[i % this.options.eventLineColors.length]; 825 _results.push(this.drawEvent(event, color)); 826 } 827 return _results; 828 } 829 }; 830 831 Grid.prototype.drawGoal = function(goal, color) { 832 var path, y; 833 y = Math.floor(this.transY(goal)) + 0.5; 834 if (!this.options.horizontal) { 835 path = "M" + this.xStart + "," + y + "H" + this.xEnd; 836 } else { 837 path = "M" + y + "," + this.xStart + "V" + this.xEnd; 838 } 839 return this.raphael.path(path).attr('stroke', color).attr('stroke-width', this.options.goalStrokeWidth); 840 }; 841 842 Grid.prototype.drawGoal2 = function(goal, color) { 843 var path, y; 844 y = Math.floor(this.transY2(goal)) + 0.5; 845 if (!this.options.horizontal) { 846 path = "M" + this.xStart + "," + y + "H" + this.xEnd; 847 } else { 848 path = "M" + y + "," + this.xStart + "V" + this.xEnd; 849 } 850 return this.raphael.path(path).attr('stroke', color).attr('stroke-width', this.options.goalStrokeWidth2); 851 }; 852 853 Grid.prototype.drawRegion = function(region, color) { 854 var from, path, to, y; 855 if (region instanceof Array) { 856 from = Math.min(Math.max.apply(Math, region), this.ymax); 857 to = Math.max(Math.min.apply(Math, region), this.ymin); 858 if (!this.options.horizontal) { 859 from = Math.floor(this.transY(from)); 860 to = Math.floor(this.transY(to)) - from; 861 return this.raphael.rect(this.xStart, from, this.xEnd - this.xStart, to).attr({ 862 fill: color, 863 stroke: false 864 }).toBack(); 865 } else { 866 to = Math.floor(this.transY(to)); 867 from = Math.floor(this.transY(from)) - to; 868 return this.raphael.rect(to, this.xStart, from, this.xEnd - this.xStart).attr({ 869 fill: color, 870 stroke: false 871 }).toBack(); 872 } 873 } else { 874 if (!this.options.horizontal) { 875 y = Math.floor(this.transY(area)) + 1; 876 path = "M" + this.xStart + "," + y + "H" + this.xEnd; 877 return this.raphael.path(path).attr('stroke', color).attr('stroke-width', 2); 878 } else { 879 y = Math.floor(this.transY(area)) + 1; 880 path = "M" + y + "," + this.xStart + "V" + this.xEnd; 881 return this.raphael.path(path).attr('stroke', color).attr('stroke-width', 2); 882 } 883 } 884 }; 885 886 Grid.prototype.drawEvent = function(event, color) { 887 var from, path, to, x; 888 if (event instanceof Array) { 889 from = event[0], to = event[1]; 890 from = Math.floor(this.transX(from)) + 0.5; 891 to = Math.floor(this.transX(to)) + 0.5; 892 if (!this.options.horizontal) { 893 return this.raphael.rect(from, this.yEnd, to - from, this.yStart - this.yEnd).attr({ 894 fill: color, 895 stroke: false 896 }).toBack(); 897 } else { 898 return this.raphael.rect(this.yStart, from, this.yEnd - this.yStart, to - from).attr({ 899 fill: color, 900 stroke: false 901 }).toBack(); 902 } 903 } else { 904 x = Math.floor(this.transX(event)) + 0.5; 905 if (!this.options.horizontal) { 906 path = "M" + x + "," + this.yStart + "V" + this.yEnd; 907 } else { 908 path = "M" + this.yStart + "," + x + "H" + this.yEnd; 909 } 910 return this.raphael.path(path).attr('stroke', color).attr('stroke-width', this.options.eventStrokeWidth); 911 } 912 }; 913 914 Grid.prototype.drawYAxisLabel = function(xPos, yPos, text, yaxis) { 915 var label; 916 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); 917 if (yaxis === 1) { 918 if (this.options.yLabelAlign === 'right') { 919 return label.attr('text-anchor', 'end'); 920 } else { 921 return label.attr('text-anchor', 'start'); 922 } 923 } else { 924 if (this.options.yLabelAlign2 === 'left') { 925 return label.attr('text-anchor', 'start'); 926 } else { 927 return label.attr('text-anchor', 'end'); 928 } 929 } 930 }; 931 932 Grid.prototype.drawXAxisLabel = function(xPos, yPos, text) { 933 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); 934 }; 935 936 Grid.prototype.drawGridLine = function(path) { 937 return this.raphael.path(path).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth); 938 }; 939 940 Grid.prototype.startRange = function(x) { 941 this.hover.hide(); 942 this.selectFrom = x; 943 return this.selectionRect.attr({ 944 x: x, 945 width: 0 946 }).show(); 947 }; 948 949 Grid.prototype.endRange = function(x) { 950 var end, start; 951 if (this.selectFrom) { 952 start = Math.min(this.selectFrom, x); 953 end = Math.max(this.selectFrom, x); 954 this.options.rangeSelect.call(this.el, { 955 start: this.data[this.hitTest(start)].x, 956 end: this.data[this.hitTest(end)].x 957 }); 958 return this.selectFrom = null; 959 } 960 }; 961 962 Grid.prototype.mousemoveHandler = function(evt) { 963 var left, offset, right, width, x; 964 offset = Morris.offset(this.el); 965 x = evt.pageX - offset.left; 966 if (this.selectFrom) { 967 left = this.data[this.hitTest(Math.min(x, this.selectFrom))]._x; 968 right = this.data[this.hitTest(Math.max(x, this.selectFrom))]._x; 969 width = right - left; 970 return this.selectionRect.attr({ 971 x: left, 972 width: width 973 }); 974 } else { 975 return this.fire('hovermove', x, evt.pageY - offset.top); 976 } 977 }; 978 979 Grid.prototype.mouseleaveHandler = function(evt) { 980 if (this.selectFrom) { 981 this.selectionRect.hide(); 982 this.selectFrom = null; 983 } 984 return this.fire('hoverout'); 985 }; 986 987 Grid.prototype.touchHandler = function(evt) { 988 var offset, touch; 989 touch = evt.originalEvent.touches[0] || evt.originalEvent.changedTouches[0]; 990 offset = Morris.offset(this.el); 991 return this.fire('hovermove', touch.pageX - offset.left, touch.pageY - offset.top); 992 }; 993 994 Grid.prototype.clickHandler = function(evt) { 995 var offset; 996 offset = Morris.offset(this.el); 997 return this.fire('gridclick', evt.pageX - offset.left, evt.pageY - offset.top); 998 }; 999 1000 Grid.prototype.mousedownHandler = function(evt) { 1001 var offset; 1002 offset = Morris.offset(this.el); 1003 return this.startRange(evt.pageX - offset.left); 1004 }; 1005 1006 Grid.prototype.mouseupHandler = function(evt) { 1007 var offset; 1008 offset = Morris.offset(this.el); 1009 this.endRange(evt.pageX - offset.left); 1010 return this.fire('hovermove', evt.pageX - offset.left, evt.pageY - offset.top); 1011 }; 1012 1013 Grid.prototype.resizeHandler = function() { 1014 if (this.timeoutId != null) { 1015 window.clearTimeout(this.timeoutId); 1016 } 1017 return this.timeoutId = window.setTimeout(this.debouncedResizeHandler, 100); 1018 }; 1019 1020 Grid.prototype.debouncedResizeHandler = function() { 1021 var height, width, _ref; 1022 this.timeoutId = null; 1023 _ref = Morris.dimensions(this.el), width = _ref.width, height = _ref.height; 1024 this.raphael.setSize(width, height); 1025 this.options.animate = false;
1026 return this.redraw(); 1027 }; 1028 1029 Grid.prototype.hasToShow = function(i) { 1030 return this.options.shown === true || this.options.shown[i] === true; 1031 }; 1032 1033 Grid.prototype.isColorDark = function(hex) { 1034 var b, g, luma, r, rgb; 1035 if (hex != null) { 1036 hex = hex.substring(1); 1037 rgb = parseInt(hex, 16); 1038 r = (rgb >> 16) & 0xff; 1039 g = (rgb >> 8) & 0xff; 1040 b = (rgb >> 0) & 0xff; 1041 luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; 1042 if (luma >= 128) { 1043 return false; 1044 } else { 1045 return true; 1046 } 1047 } else { 1048 return false; 1049 } 1050 }; 1051 1052 Grid.prototype.drawDataLabel = function(xPos, yPos, text, color) { 1053 var label; 1054 return label = this.raphael.text(xPos, yPos, text).attr('text-anchor', 'middle').attr('font-size', this.options.dataLabelsSize).attr('font-family', this.options.dataLabelsFamily).attr('font-weight', this.options.dataLabelsWeight).attr('fill', color); 1055 }; 1056 1057 Grid.prototype.drawDataLabelExt = function(xPos, yPos, text, anchor, color) { 1058 var label; 1059 return label = this.raphael.text(xPos, yPos, text).attr('text-anchor', anchor).attr('font-size', this.options.dataLabelsSize).attr('font-family', this.options.dataLabelsFamily).attr('font-weight', this.options.dataLabelsWeight).attr('fill', color); 1060 }; 1061 1062 Grid.prototype.setLabels = function() { 1063 var color, index, row, ykey, _i, _len, _ref, _results; 1064 if (this.options.dataLabels) { 1065 _ref = this.data; 1066 _results = []; 1067 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1068 row = _ref[_i]; 1069 _results.push((function() { 1070 var _j, _len1, _ref1, _results1; 1071 _ref1 = this.options.ykeys; 1072 _results1 = []; 1073 for (index = _j = 0, _len1 = _ref1.length; _j < _len1; index = ++_j) { 1074 ykey = _ref1[index]; 1075 if (this.options.dataLabelsColor !== 'auto') { 1076 color = this.options.dataLabelsColor; 1077 } else if (this.options.stacked === true && this.isColorDark(this.options.barColors[index % this.options.barColors.length]) === true) { 1078 color = '#fff'; 1079 } else { 1080 color = '#000'; 1081 } 1082 if ((this.options.lineColors != null) && (this.options.lineType != null)) { 1083 if (row.label_y[index] != null) { 1084 this.drawDataLabel(row._x, row.label_y[index], this.yLabelFormat_noUnit(row.y[index], 0), color); 1085 } 1086 if (row._y2 != null) { 1087 if (row._y2[index] != null) { 1088 _results1.push(this.drawDataLabel(row._x, row._y2[index] - 10, this.yLabelFormat_noUnit(row.y[index], 1000), color)); 1089 } else { 1090 _results1.push(void 0); 1091 } 1092 } else { 1093 _results1.push(void 0); 1094 } 1095 } else { 1096 if (row.label_y[index] != null) { 1097 if (this.options.horizontal === !true) { 1098 _results1.push(this.drawDataLabel(row.label_x[index], row.label_y[index], this.yLabelFormat_noUnit(row.y[index], index), color)); 1099 } else { 1100 _results1.push(this.drawDataLabelExt(row.label_x[index], row.label_y[index], this.yLabelFormat_noUnit(row.y[index]), 'start', color)); 1101 } 1102 } else if (row._y2[index] != null) { 1103 if (this.options.horizontal === !true) { 1104 _results1.push(this.drawDataLabel(row._x, row._y2[index] - 10, this.yLabelFormat_noUnit(row.y[index], index), color)); 1105 } else { 1106 _results1.push(this.drawDataLabelExt(row._y2[index], row._x - 10, this.yLabelFormat_noUnit(row.y[index]), 'middle', color)); 1107 } 1108 } else { 1109 _results1.push(void 0); 1110 } 1111 } 1112 } 1113 return _results1; 1114 }).call(this)); 1115 } 1116 return _results; 1117 } 1118 }; 1119 1120 return Grid; 1121 1122 })(Morris.EventEmitter); 1123 1124 Morris.parseDate = function(date) { 1125 var isecs, m, msecs, n, o, offsetmins, p, q, r, ret, secs; 1126 if (typeof date === 'number') { 1127 return date; 1128 } 1129 m = date.match(/^(\d+) Q(\d)$/); 1130 n = date.match(/^(\d+)-(\d+)$/); 1131 o = date.match(/^(\d+)-(\d+)-(\d+)$/); 1132 p = date.match(/^(\d+) W(\d+)$/); 1133 q = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/); 1134 r = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/); 1135 if (m) { 1136 return new Date(parseInt(m[1], 10), parseInt(m[2], 10) * 3 - 1, 1).getTime(); 1137 } else if (n) { 1138 return new Date(parseInt(n[1], 10), parseInt(n[2], 10) - 1, 1).getTime(); 1139 } else if (o) { 1140 return new Date(parseInt(o[1], 10), parseInt(o[2], 10) - 1, parseInt(o[3], 10)).getTime(); 1141 } else if (p) { 1142 ret = new Date(parseInt(p[1], 10), 0, 1); 1143 if (ret.getDay() !== 4) { 1144 ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7); 1145 } 1146 return ret.getTime() + parseInt(p[2], 10) * 604800000; 1147 } else if (q) { 1148 if (!q[6]) { 1149 return new Date(parseInt(q[1], 10), parseInt(q[2], 10) - 1, parseInt(q[3], 10), parseInt(q[4], 10), parseInt(q[5], 10)).getTime(); 1150 } else { 1151 offsetmins = 0; 1152 if (q[6] !== 'Z') { 1153 offsetmins = parseInt(q[8], 10) * 60 + parseInt(q[9], 10); 1154 if (q[7] === '+') { 1155 offsetmins = 0 - offsetmins; 1156 } 1157 } 1158 return Date.UTC(parseInt(q[1], 10), parseInt(q[2], 10) - 1, parseInt(q[3], 10), parseInt(q[4], 10), parseInt(q[5], 10) + offsetmins); 1159 } 1160 } else if (r) { 1161 secs = parseFloat(r[6]); 1162 isecs = Math.floor(secs); 1163 msecs = Math.round((secs - isecs) * 1000); 1164 if (!r[8]) { 1165 return 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(); 1166 } else { 1167 offsetmins = 0; 1168 if (r[8] !== 'Z') { 1169 offsetmins = parseInt(r[10], 10) * 60 + parseInt(r[11], 10);
1170 if (r[9] === '+') { 1171 offsetmins = 0 - offsetmins; 1172 } 1173 } 1174 return 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); 1175 } 1176 } else { 1177 return new Date(parseInt(date, 10), 0, 1).getTime(); 1178 } 1179 }; 1180 1181 Morris.Hover = (function() { 1182 Hover.defaults = { 1183 "class": 'morris-hover morris-default-style' 1184 }; 1185 1186 function Hover(options) { 1187 if (options == null) { 1188 options = {}; 1189 } 1190 this.options = Morris.extend({}, Morris.Hover.defaults, options); 1191 this.el = document.createElement('div'); 1192 this.el.className = this.options["class"]; 1193 this.el.style.display = 'none'; 1194 (this.options.parent = this.options.parent[0] || this.options.parent).appendChild(this.el); 1195 } 1196 1197 Hover.prototype.update = function(html, x, y, centre_y) { 1198 if (!html) { 1199 return this.hide(); 1200 } else { 1201 this.html(html); 1202 this.show(); 1203 return this.moveTo(x, y, centre_y); 1204 } 1205 }; 1206 1207 Hover.prototype.html = function(content) { 1208 return this.el.innerHTML = content; 1209 }; 1210 1211 Hover.prototype.moveTo = function(x, y, centre_y) { 1212 var hoverHeight, hoverWidth, left, parentHeight, parentWidth, top, _ref; 1213 _ref = Morris.innerDimensions(this.options.parent), parentWidth = _ref.width, parentHeight = _ref.height; 1214 hoverWidth = this.el.offsetWidth; 1215 hoverHeight = this.el.offsetHeight; 1216 left = Math.min(Math.max(0, x - hoverWidth / 2), parentWidth - hoverWidth); 1217 if (y != null) { 1218 if (centre_y === true) { 1219 top = y - hoverHeight / 2; 1220 if (top < 0) { 1221 top = 0; 1222 } 1223 } else { 1224 top = y - hoverHeight - 10; 1225 if (top < 0) { 1226 top = y + 10; 1227 if (top + hoverHeight > parentHeight) { 1228 top = parentHeight / 2 - hoverHeight / 2; 1229 } 1230 } 1231 } 1232 } else { 1233 top = parentHeight / 2 - hoverHeight / 2; 1234 } 1235 this.el.style.left = parseInt(left) + "px"; 1236 return this.el.style.top = parseInt(top) + "px"; 1237 }; 1238 1239 Hover.prototype.show = function() { 1240 return this.el.style.display = ''; 1241 }; 1242 1243 Hover.prototype.hide = function() { 1244 return this.el.style.display = 'none'; 1245 }; 1246 1247 return Hover; 1248 1249 })(); 1250 1251 Morris.Line = (function(_super) { 1252 __extends(Line, _super); 1253 1254 function Line(options) { 1255 this.hilight = __bind(this.hilight, this); 1256 this.onHoverOut = __bind(this.onHoverOut, this); 1257 this.onHoverMove = __bind(this.onHoverMove, this); 1258 this.onGridClick = __bind(this.onGridClick, this); 1259 if (!(this instanceof Morris.Line)) { 1260 return new Morris.Line(options); 1261 } 1262 Line.__super__.constructor.call(this, options); 1263 } 1264 1265 Line.prototype.init = function() { 1266 if (this.options.hideHover !== 'always') { 1267 this.hover = new Morris.Hover({ 1268 parent: this.el 1269 }); 1270 this.on('hovermove', this.onHoverMove); 1271 this.on('hoverout', this.onHoverOut); 1272 return this.on('gridclick', this.onGridClick); 1273 } 1274 }; 1275 1276 Line.prototype.defaults = { 1277 lineWidth: 3, 1278 pointSize: 4, 1279 pointSizeGrow: 3, 1280 lineColors: ['#2f7df6', '#53a351', '#f6c244', '#cb444a', '#4aa0b5', '#222529'], 1281 extraClassLine: '', 1282 extraClassCircle: '', 1283 pointStrokeWidths: [1], 1284 pointStrokeColors: ['#ffffff'], 1285 pointFillColors: [], 1286 pointSuperimposed: true, 1287 hoverOrdered: false, 1288 hoverReversed: false, 1289 smooth: true, 1290 lineType: {}, 1291 shown: true, 1292 xLabels: 'auto', 1293 xLabelFormat: null, 1294 xLabelMargin: 0, 1295 verticalGrid: false, 1296 verticalGridHeight: 'full', 1297 verticalGridStartOffset: 0, 1298 verticalGridType: '', 1299 trendLine: false, 1300 trendLineType: 'linear', 1301 trendLineWidth: 2, 1302 trendLineWeight: false, 1303 trendLineColors: ['#689bc3', '#a2b3bf', '#64b764'] 1304 }; 1305 1306 Line.prototype.calc = function() { 1307 this.calcPoints(); 1308 return this.generatePaths(); 1309 }; 1310 1311 Line.prototype.calcPoints = function() { 1312 var count, i, idx, ii, index, point, row, v, y, _i, _j, _k, _l, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _results; 1313 _ref = this.data; 1314 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1315 row = _ref[_i]; 1316 row._x = this.transX(row.x); 1317 row._y = (function() { 1318 var _j, _len1, _ref1, _results; 1319 _ref1 = row.y; 1320 _results = []; 1321 for (ii = _j = 0, _len1 = _ref1.length; _j < _len1; ii = ++_j) { 1322 y = _ref1[ii]; 1323 if (ii < this.options.ykeys.length - this.options.nbYkeys2) { 1324 if (y != null) { 1325 _results.push(this.transY(y)); 1326 } else { 1327 _results.push(y); 1328 } 1329 } else { 1330 _results.push(void 0); 1331 } 1332 } 1333 return _results; 1334 }).call(this); 1335 row._y2 = (function() { 1336 var _j, _len1, _ref1, _results; 1337 _ref1 = row.y; 1338 _results = []; 1339 for (ii = _j = 0, _len1 = _ref1.length; _j < _len1; ii = ++_j) { 1340 y = _ref1[ii]; 1341 if (ii >= this.options.ykeys.length - this.options.nbYkeys2) { 1342 if (y != null) { 1343 _results.push(this.transY2(y)); 1344 } else { 1345 _results.push(y); 1346 } 1347 } else { 1348 _results.push(void 0); 1349 } 1350 } 1351 return _results; 1352 }).call(this); 1353 row._ymax = Math.min.apply(Math, [this.bottom].concat((function() { 1354 var _j, _len1, _ref1, _results; 1355 _ref1 = row._y; 1356 _results = []; 1357 for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { 1358 y = _ref1[i]; 1359 if ((y != null) && this.hasToShow(i)) { 1360 _results.push(y); 1361 } 1362 } 1363 return _results; 1364 }).call(this))); 1365 row._ymax2 = Math.min.apply(Math, [this.bottom].concat((function() { 1366 var _j, _len1, _ref1, _results; 1367 _ref1 = row._y2; 1368 _results = []; 1369 for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { 1370 y = _ref1[i]; 1371 if ((y != null) && this.hasToShow(i)) { 1372 _results.push(y); 1373 } 1374 } 1375 return _results; 1376 }).call(this))); 1377 } 1378 _ref1 = this.data; 1379 for (idx = _j = 0, _len1 = _ref1.length; _j < _len1; idx = ++_j) { 1380 row = _ref1[idx]; 1381 this.data[idx].label_x = []; 1382 this.data[idx].label_y = []; 1383 for (index = _k = _ref2 = this.options.ykeys.length - 1; _ref2 <= 0 ? _k <= 0 : _k >= 0; index = _ref2 <= 0 ? ++_k : --_k) { 1384 if (row._y[index] != null) { 1385 this.data[idx].label_x[index] = row._x; 1386 this.data[idx].label_y[index] = row._y[index] - 10; 1387 } 1388 if (row._y2 != null) { 1389 if (row._y2[index] != null) { 1390 this.data[idx].label_x[index] = row._x; 1391 this.data[idx].label_y[index] = row._y2[index] - 10; 1392 } 1393 } 1394 } 1395 } 1396 if (this.options.pointSuperimposed === !true) { 1397 _ref3 = this.data; 1398 _results = []; 1399 for (_l = 0, _len2 = _ref3.length; _l < _len2; _l++) { 1400 row = _ref3[_l]; 1401 _results.push((function() { 1402 var _len3, _len4, _m, _n, _ref4, _ref5, _results1; 1403 _ref4 = row._y; 1404 _results1 = []; 1405 for (idx = _m = 0, _len3 = _ref4.length; _m < _len3; idx = ++_m) {
1406 point = _ref4[idx]; 1407 count = 0; 1408 _ref5 = row._y; 1409 for (i = _n = 0, _len4 = _ref5.length; _n < _len4; i = ++_n) { 1410 v = _ref5[i]; 1411 if (point === v && typeof point === 'number') { 1412 count++; 1413 } 1414 } 1415 if (count > 1) { 1416 row._y[idx] = row._y[idx] + count * (this.lineWidthForSeries(idx)); 1417 if (this.lineWidthForSeries(idx) > 1) { 1418 _results1.push(row._y[idx] = row._y[idx] - 1); 1419 } else { 1420 _results1.push(void 0); 1421 } 1422 } else { 1423 _results1.push(void 0); 1424 } 1425 } 1426 return _results1; 1427 }).call(this)); 1428 } 1429 return _results; 1430 } 1431 }; 1432 1433 Line.prototype.hitTest = function(x) { 1434 var index, r, _i, _len, _ref; 1435 if (this.data.length === 0) { 1436 return null; 1437 } 1438 _ref = this.data.slice(1); 1439 for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) { 1440 r = _ref[index]; 1441 if (x < (r._x + this.data[index]._x) / 2) { 1442 break; 1443 } 1444 } 1445 return index; 1446 }; 1447 1448 Line.prototype.onGridClick = function(x, y) { 1449 var index; 1450 index = this.hitTest(x); 1451 return this.fire('click', index, this.data[index].src, x, y); 1452 }; 1453 1454 Line.prototype.onHoverMove = function(x, y) { 1455 var index; 1456 index = this.hitTest(x); 1457 return this.displayHoverForRow(index); 1458 }; 1459 1460 Line.prototype.onHoverOut = function() { 1461 if (this.options.hideHover !== false) { 1462 return this.displayHoverForRow(null); 1463 } 1464 }; 1465 1466 Line.prototype.displayHoverForRow = function(index) { 1467 var _ref; 1468 if (index != null) { 1469 (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index)); 1470 return this.hilight(index); 1471 } else { 1472 this.hover.hide(); 1473 return this.hilight(); 1474 } 1475 }; 1476 1477 Line.prototype.escapeHTML = function(string) { 1478 var map, reg; 1479 map = { 1480 '&': '&', 1481 '<': '<', 1482 '>': '>', 1483 '"': '"', 1484 "'": ''', 1485 "/": '/' 1486 }; 1487 reg = /[&<>"'/]/ig; 1488 return string.replace(reg, function(match) { 1489 return map[match]; 1490 }); 1491 }; 1492 1493 Line.prototype.hoverContentForRow = function(index) { 1494 var axis, content, j, jj, max, max_pos, order, row, y, yy, _i, _j, _k, _l, _len, _len1, _ref, _ref1, _ref2; 1495 row = this.data[index]; 1496 content = ""; 1497 order = []; 1498 if (this.options.hoverOrdered === true) { 1499 _ref = row.y; 1500 for (jj = _i = 0, _len = _ref.length; _i < _len; jj = ++_i) { 1501 yy = _ref[jj]; 1502 max = null; 1503 max_pos = -1; 1504 _ref1 = row.y; 1505 for (j = _j = 0, _len1 = _ref1.length; _j < _len1; j = ++_j) { 1506 y = _ref1[j]; 1507 if (__indexOf.call(order, j) < 0) { 1508 if (max <= y || max === null) { 1509 max = y; 1510 max_pos = j; 1511 } 1512 } 1513 } 1514 order.push(max_pos); 1515 } 1516 } else { 1517 _ref2 = row.y; 1518 for (jj = _k = _ref2.length - 1; _k >= 0; jj = _k += -1) { 1519 yy = _ref2[jj]; 1520 order.push(jj); 1521 } 1522 } 1523 if (this.options.hoverReversed === true) { 1524 order = order.reverse(); 1525 } 1526 axis = -1; 1527 for (_l = order.length - 1; _l >= 0; _l += -1) { 1528 j = order[_l]; 1529 if (this.options.labels[j] === false) { 1530 continue; 1531 } 1532 if (row.y[j] !== void 0 && axis === -1) { 1533 axis = j; 1534 } 1535 content = ("<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(row.y[j], j)) + "\n</div>") + content; 1536 } 1537 content = "<div class='morris-hover-row-label'>" + this.escapeHTML(row.label) + "</div>" + content; 1538 if (typeof this.options.hoverCallback === 'function') { 1539 content = this.options.hoverCallback(index, this.options, content, row.src
1539); 1540 } 1541 if (axis > this.options.nbYkeys2) { 1542 return [content, row._x, row._ymax2]; 1543 } else { 1544 return [content, row._x, row._ymax]; 1545 } 1546 }; 1547 1548 Line.prototype.generatePaths = function() { 1549 var coords, i, lineType, nb, r, smooth; 1550 return this.paths = (function() { 1551 var _i, _ref, _ref1, _results; 1552 _results = []; 1553 for (i = _i = 0, _ref = this.options.ykeys.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { 1554 smooth = typeof this.options.smooth === "boolean" ? this.options.smooth : (_ref1 = this.options.ykeys[i], __indexOf.call(this.options.smooth, _ref1) >= 0); 1555 lineType = smooth ? 'smooth' : 'jagged'; 1556 if (typeof this.options.lineType === "string") { 1557 lineType = this.options.lineType; 1558 } else { 1559 1560 } 1561 if (this.options.lineType[this.options.ykeys[i]] !== void 0) { 1562 lineType = this.options.lineType[this.options.ykeys[i]]; 1563 } 1564 nb = this.options.ykeys.length - this.options.nbYkeys2; 1565 if (i < nb) { 1566 coords = (function() { 1567 var _j, _len, _ref2, _results1; 1568 _ref2 = this.data; 1569 _results1 = []; 1570 for (_j = 0, _len = _ref2.length; _j < _len; _j++) { 1571 r = _ref2[_j]; 1572 if (r._y[i] !== void 0) { 1573 _results1.push({ 1574 x: r._x, 1575 y: r._y[i] 1576 }); 1577 } 1578 } 1579 return _results1; 1580 }).call(this); 1581 } else { 1582 coords = (function() { 1583 var _j, _len, _ref2, _results1; 1584 _ref2 = this.data; 1585 _results1 = []; 1586 for (_j = 0, _len = _ref2.length; _j < _len; _j++) { 1587 r = _ref2[_j]; 1588 if (r._y2[i] !== void 0) { 1589 _results1.push({ 1590 x: r._x, 1591 y: r._y2[i] 1592 }); 1593 } 1594 } 1595 return _results1; 1596 }).call(this); 1597 } 1598 if (coords.length > 1) { 1599 _results.push(Morris.Line.createPath(coords, lineType, this.bottom, i, this.options.ykeys.length, this.options.lineWidth)); 1600 } else { 1601 _results.push(null); 1602 } 1603 } 1604 return _results; 1605 }).call(this); 1606 }; 1607 1608 Line.prototype.draw = function() { 1609 var _ref; 1610 if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'x') { 1611 this.drawXAxis(); 1612 } 1613 this.drawSeries(); 1614 if (this.options.hideHover === false) { 1615 return this.displayHoverForRow(this.data.length - 1); 1616 } 1617 }; 1618 1619 Line.prototype.drawXAxis = function() { 1620 var drawLabel, l, labels, lines, prevAngleMargin, prevLabelMargin, row, ypos, _i, _j, _len, _len1, _results, 1621 _this = this; 1622 ypos = this.bottom + this.options.padding / 2; 1623 prevLabelMargin = null; 1624 prevAngleMargin = null; 1625 drawLabel = function(labelText, xpos) { 1626 var label, labelBox, margin, offset, textBox; 1627 label = _this.drawXAxisLabel(_this.transX(xpos), ypos, labelText); 1628 textBox = label.getBBox(); 1629 label.transform("r" + (-_this.options.xLabelAngle)); 1630 labelBox = label.getBBox(); 1631 label.transform("t0," + (labelBox.height / 2) + "..."); 1632 if (_this.options.xLabelAngle !== 0) { 1633 offset = -0.5 * textBox.width * Math.cos(_this.options.xLabelAngle * Math.PI / 180.0); 1634 label.transform("t" + offset + ",0..."); 1635 } 1636 labelBox = label.getBBox(); 1637 if (((prevLabelMargin == null) || prevLabelMargin >= labelBox.x + labelBox.width || (prevAngleMargin != null) && prevAngleMargin >= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < Morris.dimensions(_this.el).width) { 1638 if (_this.options.xLabelAngle !== 0) { 1639 margin = 1.25 * _this.options.gridTextSize / Math.sin(_this.options.xLabelAngle * Math.PI / 180.0); 1640 prevAngleMargin = labelBox.x - margin; 1641 } 1642 prevLabelMargin = labelBox.x - _this.options.xLabelMargin; 1643 if (_this.options.verticalGrid === true) { 1644 return _this.drawVerticalGridLine(xpos); 1645 } 1646 } else { 1647 return label.remove(); 1648 } 1649 }; 1650 if (this.options.parseTime) { 1651 if (this.data.length === 1 && this.options.xLabels === 'auto') { 1652 labels = [[this.data[0].label, this.data[0].x]]; 1653 } else { 1654 labels = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat); 1655 } 1656 } else if (this.options.customLabels) { 1657 labels = (function() { 1658 var _i, _len, _ref, _results; 1659 _ref = this.options.customLabels; 1660 _results = []; 1661 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1662 row = _ref[_i]; 1663 _results.push([row.label, row.x]); 1664 } 1665 return _results; 1666 }).call(this); 1667 } else { 1668 labels = (function() { 1669 var _i, _len, _ref, _results; 1670 _ref = this.data; 1671 _results = []; 1672 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1673 row = _ref[_i]; 1674 _results.push([row.label, row.x]); 1675 } 1676 return _results; 1677 }).call(this); 1678 } 1679 labels.reverse(); 1680 for (_i = 0, _len = labels.length; _i < _len; _i++) { 1681 l = labels[_i]; 1682 drawLabel(l[0], l[1]); 1683 } 1684 if (typeof this.options.verticalGrid === 'string') { 1685 lines = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.verticalGrid); 1686 _results = []; 1687 for (_j = 0, _len1 = lines.length; _j < _len1; _j++) { 1688 l = lines[_j]; 1689 _results.push(this.drawVerticalGridLine(l[1])); 1690 } 1691 return _results; 1692 } 1693 }; 1694 1695 Line.prototype.drawVerticalGridLine = function(xpos) { 1696 var yEnd, yStart; 1697 xpos = Math.floor(this.transX(xpos)) + 0.5; 1698 yStart = this.yStart + this.options.verticalGridStartOffset; 1699 if (this.options.verticalGridHeight === 'full') { 1700 yEnd = this.yEnd; 1701 } else { 1702 yEnd = this.yStart - this.options.verticalGridHeight; 1703 }
1704 return this.drawGridLineVert("M" + xpos + "," + yStart + "V" + yEnd); 1705 }; 1706 1707 Line.prototype.drawGridLineVert = function(path) { 1708 return this.raphael.path(path).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth).attr('stroke-dasharray', this.options.verticalGridType); 1709 }; 1710 1711 Line.prototype.drawSeries = function() { 1712 var i, _i, _j, _ref, _ref1, _results; 1713 this.seriesPoints = []; 1714 for (i = _i = _ref = this.options.ykeys.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) { 1715 if (this.hasToShow(i)) { 1716 if (this.options.trendLine !== false && this.options.trendLine === true || this.options.trendLine[i] === true) { 1717 if (this.data.length > 0) { 1718 this._drawTrendLine(i); 1719 } 1720 } 1721 this._drawLineFor(i); 1722 } 1723 } 1724 _results = []; 1725 for (i = _j = _ref1 = this.options.ykeys.length - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) { 1726 if (this.hasToShow(i)) { 1727 _results.push(this._drawPointFor(i)); 1728 } else { 1729 _results.push(void 0); 1730 } 1731 } 1732 return _results; 1733 }; 1734 1735 Line.prototype._drawPointFor = function(index) { 1736 var circle, idx, row, _i, _len, _ref, _results; 1737 this.seriesPoints[index] = []; 1738 _ref = this.data; 1739 _results = []; 1740 for (idx = _i = 0, _len = _ref.length; _i < _len; idx = ++_i) { 1741 row = _ref[idx]; 1742 circle = null; 1743 if (row._y[index] != null) { 1744 circle = this.drawLinePoint(row._x, row._y[index], this.colorFor(row, index, 'point'), index); 1745 } 1746 if (row._y2 != null) { 1747 if (row._y2[index] != null) { 1748 circle = this.drawLinePoint(row._x, row._y2[index], this.colorFor(row, index, 'point'), index); 1749 } 1750 } 1751 _results.push(this.seriesPoints[index].push(circle)); 1752 } 1753 return _results; 1754 }; 1755 1756 Line.prototype._drawLineFor = function(index) { 1757 var path; 1758 path = this.paths[index]; 1759 if (path !== null) { 1760 return this.drawLinePath(path, this.colorFor(null, index, 'line'), index); 1761 } 1762 }; 1763 1764 Line.prototype._drawTrendLine = function(index) { 1765 var a, b, data, datapoints, i, path, plots, reg, sum_x, sum_xx, sum_xy, sum_y, t_off_x, t_x, t_y, val, weight, x, y, _i, _j, _k, _l, _len, _ref; 1766 sum_x = 0; 1767 sum_y = 0; 1768 sum_xx = 0; 1769 sum_xy = 0; 1770 datapoints = 0; 1771 plots = []; 1772 _ref = this.data; 1773 for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { 1774 val = _ref[i]; 1775 x = val.x; 1776 y = val.y[index]; 1777 if (y != null) { 1778 plots.push([x, y]); 1779 if (this.options.trendLineWeight === false) { 1780 weight = 1; 1781 } else { 1782 weight = this.options.data[i][this.options.trendLineWeight]; 1783 } 1784 datapoints += weight; 1785 sum_x += x * weight; 1786 sum_y += y * weight; 1787 sum_xx += x * x * weight; 1788 sum_xy += x * y * weight; 1789 } 1790 } 1791 a = (datapoints * sum_xy - sum_x * sum_y) / (datapoints * sum_xx - sum_x * sum_x); 1792 b = (sum_y / datapoints) - ((a * sum_x) / datapoints); 1793 data = [{}, {}]; 1794 data[0].x = this.transX(this.data[0].x); 1795 data[0].y = this.transY(this.data[0].x * a + b); 1796 data[1].x = this.transX(this.data[this.data.length - 1].x); 1797 data[1].y = this.transY(this.data[this.data.length - 1].x * a + b); 1798 if (this.options.trendLineType !== 'linear') { 1799 if (typeof regression === 'function') { 1800 t_off_x = (this.xmax - this.xmin) / 30; 1801 data = []; 1802 if (this.options.trendLineType === 'polynomial') { 1803 reg = regression('polynomial', plots, 2); 1804 for (i = _j = 0; _j <= 30; i = ++_j) { 1805 t_x = this.xmin + i * t_off_x; 1806 t_y = reg.equation[2] * t_x * t_x + reg.equation[1] * t_x + reg.equation[0]; 1807 data.push({ 1808 x: this.transX(t_x), 1809 y: this.transY(t_y) 1810 }); 1811 } 1812 } else if (this.options.trendLineType === 'logarithmic') { 1813 reg = regression('logarithmic', plots); 1814 for (i = _k = 0; _k <= 30; i = ++_k) { 1815 t_x = this.xmin + i * t_off_x; 1816 t_y = reg.equation[0] + reg.equation[1] * Math.log(t_x); 1817 data.push({ 1818 x: this.transX(t_x), 1819 y: this.transY(t_y) 1820 }); 1821 } 1822 } else if (this.options.trendLineType === 'exponential') { 1823 reg = regression('exponential', plots); 1824 for (i = _l = 0; _l <= 30; i = ++_l) { 1825 t_x = this.xmin + i * t_off_x; 1826 t_y = reg.equation[0] + Math.exp(reg.equation[1] * t_x); 1827 data.push({ 1828 x: this.transX(t_x), 1829 y: this.transY(t_y) 1830 }); 1831 } 1832 }
1833 console.log('Regression formula is: ' + reg.string + ', r2:' + reg.r2); 1834 } else { 1835 console.log('Warning: regression() is undefined, please ensure that regression.js is loaded'); 1836 } 1837 } 1838 if (!isNaN(a)) { 1839 path = Morris.Line.createPath(data, 'jagged', this.bottom); 1840 return path = this.raphael.path(path).attr('stroke', this.colorFor(null, index, 'trendLine')).attr('stroke-width', this.options.trendLineWidth); 1841 } 1842 }; 1843 1844 Line.createPath = function(coords, lineType, bottom, index, nb, lineWidth) { 1845 var coord, g, grads, i, ix, lg, path, prevCoord, x1, x2, y1, y2, _i, _len; 1846 path = ""; 1847 if (lineType === 'smooth') { 1848 grads = Morris.Line.gradients(coords); 1849 } 1850 prevCoord = { 1851 y: null 1852 }; 1853 for (i = _i = 0, _len = coords.length; _i < _len; i = ++_i) { 1854 coord = coords[i]; 1855 if (coord.y != null) { 1856 if (prevCoord.y != null) { 1857 if (lineType === 'smooth') { 1858 g = grads[i]; 1859 lg = grads[i - 1]; 1860 ix = (coord.x - prevCoord.x) / 4; 1861 x1 = prevCoord.x + ix; 1862 y1 = Math.min(bottom, prevCoord.y + ix * lg); 1863 x2 = coord.x - ix; 1864 y2 = Math.min(bottom, coord.y - ix * g); 1865 path += "C" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + coord.x + "," + coord.y; 1866 } else if (lineType === 'jagged') { 1867 path += "L" + coord.x + "," + coord.y; 1868 } else if (lineType === 'step') { 1869 path += "L" + coord.x + "," + prevCoord.y; 1870 path += "L" + coord.x + "," + coord.y; 1871 } else if (lineType === 'stepNoRiser') { 1872 path += "L" + coord.x + "," + prevCoord.y; 1873 path += "M" + coord.x + "," + coord.y; 1874 } else if (lineType === 'vertical') { 1875 path += "L" + (prevCoord.x - (nb - 1) * (lineWidth /
1875nb) + index * lineWidth) + "," + prevCoord.y; 1876 path += "L" + (prevCoord.x - (nb - 1) * (lineWidth / nb) + index * lineWidth) + "," + bottom; 1877 path += "M" + (coord.x - (nb - 1) * (lineWidth / nb) + index * lineWidth) + "," + bottom; 1878 if (coords.length === (i + 1)) { 1879 path += "L" + (coord.x - (nb - 1) * (lineWidth / nb) + index * lineWidth) + "," + coord.y; 1880 path += "L" + (coord.x - (nb - 1) * (lineWidth / nb) + index * lineWidth) + "," + bottom; 1881 } 1882 } 1883 } else { 1884 if (lineType !== 'smooth' || (grads[i] != null)) { 1885 path += "M" + coord.x + "," + coord.y; 1886 } 1887 } 1888 } 1889 prevCoord = coord; 1890 } 1891 return path; 1892 }; 1893 1894 Line.gradients = function(coords) { 1895 var coord, grad, i, nextCoord, prevCoord, _i, _len, _results; 1896 grad = function(a, b) { 1897 return (a.y - b.y) / (a.x - b.x); 1898 }; 1899 _results = []; 1900 for (i = _i = 0, _len = coords.length; _i < _len; i = ++_i) { 1901 coord = coords[i]; 1902 if (coord.y != null) { 1903 nextCoord = coords[i + 1] || { 1904 y: null 1905 }; 1906 prevCoord = coords[i - 1] || { 1907 y: null 1908 }; 1909 if ((prevCoord.y != null) && (nextCoord.y != null)) { 1910 _results.push(grad(prevCoord, nextCoord)); 1911 } else if (prevCoord.y != null) { 1912 _results.push(grad(prevCoord, coord)); 1913 } else if (nextCoord.y != null) { 1914 _results.push(grad(coord, nextCoord)); 1915 } else { 1916 _results.push(null); 1917 } 1918 } else { 1919 _results.push(null); 1920 } 1921 } 1922 return _results; 1923 }; 1924 1925 Line.prototype.hilight = function(index) { 1926 var i, _i, _j, _ref, _ref1; 1927 if (this.prevHilight !== null && this.prevHilight !== index) { 1928 for (i = _i = 0, _ref = this.seriesPoints.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { 1929 if (this.hasToShow(i) && this.seriesPoints[i][this.prevHilight]) { 1930 this.seriesPoints[i][this.prevHilight].animate(this.pointShrinkSeries(i)); 1931 } 1932 } 1933 } 1934 if (index !== null && this.prevHilight !== index) { 1935 for (i = _j = 0, _ref1 = this.seriesPoints.length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) { 1936 if (this.hasToShow(i) && this.seriesPoints[i][index]) { 1937 this.seriesPoints[i][index].animate(this.pointGrowSeries(i)); 1938 } 1939 } 1940 } 1941 return this.prevHilight = index; 1942 }; 1943 1944 Line.prototype.colorFor = function(row, sidx, type) { 1945 if (typeof this.options.lineColors === 'function') { 1946 return this.options.lineColors.call(this, row, sidx, type); 1947 } else if (type === 'point') { 1948 return this.options.pointFillColors[sidx % this.options.pointFillColors.length] || this.options.lineColors[sidx % this.options.lineColors.length]; 1949 } else if (type === 'trendLine') { 1950 return this.options.trendLineColors[sidx % this.options.trendLineColors.length]; 1951 } else { 1952 return this.options.lineColors[sidx % this.options.lineColors.length]; 1953 } 1954 }; 1955 1956 Line.prototype.drawLinePath = function(path, lineColor, lineIndex) { 1957 var ii, rPath, row, row_x, straightPath, _i, _len, _ref; 1958 if (this.options.animate) { 1959 straightPath = ''; 1960 _ref = this.data; 1961 for (ii = _i = 0, _len = _ref.length; _i < _len; ii = ++_i) { 1962 row = _ref[ii]; 1963 if (straightPath === '') { 1964 if (lineIndex >= this.options.ykeys.length - this.options.nbYkeys2) { 1965 if (row._y2[lineIndex] != null) { 1966 straightPath = 'M' + row._x + ',' + this.transY2(this.ymin2); 1967 } 1968 } else if (row._y[lineIndex] != null) { 1969 if (this.options.lineType !== 'vertical') { 1970 straightPath = 'M' + row._x + ',' + this.transY(this.ymin); 1971 } else { 1972 straightPath = 'M' + row._x + ',' + this.transY(0) + 'L' + row._x + ',' + this.transY(0) + 'L' + row._x + ',' + this.transY(0); 1973 } 1974 } 1975 } else { 1976 if (lineIndex >= this.options.ykeys.length - this.options.nbYkeys2) { 1977 if (row._y2[lineIndex] != null) { 1978 straightPath += ',' + row._x + ',' + this.transY2(this.ymin2); 1979 if (this.options.lineType === 'step') { 1980 straightPath += ',' + row._x + ',' + this.transY2(this.ymin2); 1981 } 1982 } 1983 } else if (row._y[lineIndex] != null) { 1984 if (this.options.lineType !== 'vertical') { 1985 straightPath += ',' + row._x + ',' + this.transY(this.ymin); 1986 } else { 1987 row_x = row._x - (this.options.ykeys.length - 1) * (this.options.lineWidth / this.options.ykeys.length) + lineIndex * this.options.lineWidth; 1988 straightPath += 'M' + row_x + ',' + this.transY(0) + 'L' + row_x + ',' + this.transY(0) + 'L' + row_x + ',' + this.transY(0); 1989 } 1990 if (this.options.lineType === 'step') { 1991 straightPath += ',' + row._x + ',' + this.transY(this.ymin); 1992 } 1993 } 1994 } 1995 } 1996 rPath = this.raphael.path(straightPath).attr('stroke', lineColor).attr('stroke-width', this.lineWidthForSeries(lineIndex)).attr('class', this.options.extraClassLine).attr('class', 'line_' + lineIndex); 1997 if (this.options.cumulative) { 1998 return (function(rPath, path) { 1999 return rPath.animate({ 2000 path: path 2001 }, 600, '<>'); 2002 })(rPath, path); 2003 } else { 2004 return (function(rPath, path) { 2005 return rPath.animate({ 2006 path: path 2007 }, 500, '<>'); 2008 })(rPath, path); 2009 } 2010 } else { 2011 return this.raphael.path(path).attr('stroke', lineColor).attr('stroke-width', this.lineWidthForSeries(lineIndex)).attr('class', this.options.extraClassLine).attr('class', 'line_' + lineIndex); 2012 } 2013 }; 2014 2015 Line.prototype.drawLinePoint = function(xPos, yPos, pointColor, lineIndex) { 2016 return this.raphael.circle(xPos, yPos, this.pointSizeForSeries(lineIndex)).attr('fill', pointColor).attr('stroke-width', this.pointStrokeWidthForSeries(lineIndex)).attr('stroke', this.pointStrokeColorForSeries(lineIndex)).attr('class', this.options.extraClassCircle).attr('class', 'circle_line_' + lineIndex); 2017 }; 2018 2019 Line.prototype.pointStrokeWidthForSeries = function(index) { 2020 return this.options.pointStrokeWidths[index % this.options.pointStrokeWidths.length]; 2021 }; 2022 2023 Line.prototype.pointStrokeColorForSeries = function(index) { 2024 return this.options.pointStrokeColors[index % this.options.pointStrokeColors.length]; 2025 }; 2026 2027 Line.prototype.lineWidthForSeries = function(index) { 2028 if (this.options.lineWidth instanceof Array) { 2029 return this.options.lineWidth[index % this.options.lineWidth.length]; 2030 } else { 2031 return this.options.lineWidth; 2032 } 2033 }; 2034 2035 Line.prototype.pointSizeForSeries = function(index) { 2036 if (this.options.pointSize instanceof Array) { 2037 return this.options.pointSize[index % this.options.pointSize.length]; 2038 } else { 2039 return this.options.pointSize; 2040 } 2041 }; 2042 2043 Line.prototype.pointGrowSeries = function(index) { 2044 if (this.pointSizeForSeries(index) === 0) { 2045 return; 2046 } 2047 return Raphael.animation({ 2048 r: this.pointSizeForSeries(index) + this.options.pointSizeGrow 2049 }, 25, 'linear'); 2050 }; 2051 2052 Line.prototype.pointShrinkSeries = function(index) { 2053 return Raphael.animation({ 2054 r: this.pointSizeForSeries(index) 2055 }, 25, 'linear'); 2056 }; 2057 2058 return Line; 2059 2060 })(Morris.Grid); 2061 2062 Morris.labelSeries = function(dmin, dmax, pxwidth, specName, xLabelFormat) { 2063 var d, d0, ddensity, name, ret, s, spec, t, _i, _len, _ref; 2064 ddensity = 200 * (dmax - dmin) / pxwidth; 2065 d0 = new Date(dmin); 2066 spec = Morris.LABEL_SPECS[specName]; 2067 if (spec === void 0) { 2068 _ref = Morris.AUTO_LABEL_ORDER; 2069 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 2070 name = _ref[_i]; 2071 s = Morris.LABEL_SPECS[name]; 2072 if (ddensity >= s.span) { 2073 spec = s; 2074 break; 2075 } 2076 } 2077 } 2078 if (spec === void 0) { 2079 spec = Morris.LABEL_SPECS["second"]; 2080 } 2081 if (xLabelFormat) { 2082 spec = Morris.extend({}, spec, { 2083 fmt: xLabelFormat 2084 }); 2085 } 2086 d = spec.start(d0); 2087 ret = []; 2088 while ((t = d.getTime()) <= dmax) { 2089 if (t >= dmin) {
2090 ret.push([spec.fmt(d), t]); 2091 } 2092 spec.incr(d); 2093 } 2094 return ret; 2095 }; 2096 2097 minutesSpecHelper = function(interval) { 2098 return { 2099 span: interval * 60 * 1000, 2100 start: function(d) { 2101 return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours()); 2102 }, 2103 fmt: function(d) { 2104 return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes())); 2105 }, 2106 incr: function(d) { 2107 return d.setUTCMinutes(d.getUTCMinutes() + interval); 2108 } 2109 }; 2110 }; 2111 2112 secondsSpecHelper = function(interval) { 2113 return { 2114 span: interval * 1000, 2115 start: function(d) { 2116 return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes()); 2117 }, 2118 fmt: function(d) { 2119 return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes())) + ":" + (Morris.pad2(d.getSeconds())); 2120 }, 2121 incr: function(d) { 2122 return d.setUTCSeconds(d.getUTCSeconds() + interval); 2123 } 2124 }; 2125 }; 2126 2127 Morris.LABEL_SPECS = { 2128 "decade": { 2129 span: 172800000000, 2130 start: function(d) { 2131 return new Date(d.getFullYear() - d.getFullYear() % 10, 0, 1); 2132 }, 2133 fmt: function(d) { 2134 return "" + (d.getFullYear()); 2135 }, 2136 incr: function(d) { 2137 return d.setFullYear(d.getFullYear() + 10); 2138 } 2139 }, 2140 "year": { 2141 span: 17280000000, 2142 start: function(d) { 2143 return new Date(d.getFullYear(), 0, 1); 2144 }, 2145 fmt: function(d) { 2146 return "" + (d.getFullYear()); 2147 }, 2148 incr: function(d) { 2149 return d.setFullYear(d.getFullYear() + 1); 2150 } 2151 }, 2152 "month": { 2153 span: 2419200000, 2154 start: function(d) { 2155 return new Date(d.getFullYear(), d.getMonth(), 1); 2156 }, 2157 fmt: function(d) { 2158 return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)); 2159 }, 2160 incr: function(d) { 2161 return d.setMonth(d.getMonth() + 1); 2162 } 2163 }, 2164 "week": { 2165 span: 604800000, 2166 start: function(d) { 2167 return new Date(d.getFullYear(), d.getMonth(), d.getDate()); 2168 }, 2169 fmt: function(d) { 2170 return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate())); 2171 }, 2172 incr: function(d) { 2173 return d.setDate(d.getDate() + 7); 2174 } 2175 }, 2176 "day": { 2177 span: 86400000, 2178 start: function(d) { 2179 return new Date(d.getFullYear(), d.getMonth(), d.getDate()); 2180 }, 2181 fmt: function(d) { 2182 return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate())); 2183 }, 2184 incr: function(d) { 2185 return d.setDate(d.getDate() + 1); 2186 } 2187 }, 2188 "hour": minutesSpecHelper(60), 2189 "30min": minutesSpecHelper(30), 2190 "15min": minutesSpecHelper(15), 2191 "10min": minutesSpecHelper(10), 2192 "5min": minutesSpecHelper(5), 2193 "minute": minutesSpecHelper(1), 2194 "30sec": secondsSpecHelper(30), 2195 "15sec": secondsSpecHelper(15), 2196 "10sec": secondsSpecHelper(10), 2197 "5sec": secondsSpecHelper(5), 2198 "second": secondsSpecHelper(1) 2199 }; 2200 2201 Morris.AUTO_LABEL_ORDER = ["decade", "year", "month", "week", "day", "hour", "30min", "15min", "10min", "5min", "minute", "30sec", "15sec", "10sec", "5sec", "second"]; 2202 2203 Morris.Area = (function(_super) { 2204 var areaDefaults; 2205 2206 __extends(Area, _super); 2207 2208 areaDefaults = { 2209 fillOpacity: 'auto', 2210 behaveLikeLine: false, 2211 belowArea: true, 2212 areaColors: [] 2213 }; 2214 2215 function Area(options) { 2216 var areaOptions; 2217 if (!(this instanceof Morris.Area)) { 2218 return new Morris.Area(options); 2219 } 2220 areaOptions = Morris.extend({}, areaDefaults, options); 2221 this.cumulative = !areaOptions.behaveLikeLine; 2222 if (areaOptions.fillOpacity === 'auto') { 2223 areaOptions.fillOpacity = areaOptions.behaveLikeLine ? .8 : 1; 2224 } 2225 Area.__super__.constructor.call(this, areaOptions); 2226 } 2227 2228 Area.prototype.calcPoints = function() { 2229 var i, idx, index, row, total, y, _i, _j, _len, _len1, _ref, _ref1, _results; 2230 _ref = this.data; 2231 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 2232 row = _ref[_i]; 2233 row._x = this.transX(row.x); 2234 total = 0; 2235 row._y = (function() { 2236 var _j, _len1, _ref1, _results; 2237 _ref1 = row.y; 2238 _results = []; 2239 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 2240 y = _ref1[_j]; 2241 if (this.options.behaveLikeLine) { 2242 if (y != null) { 2243 _results.push(this.transY(y)); 2244 } else { 2245 _results.push(y); 2246 } 2247 } else { 2248 if (y != null) { 2249 total += y || 0; 2250 _results.push(this.transY(total)); 2251 } else { 2252 _results.push(void 0); 2253 } 2254 } 2255 } 2256 return _results; 2257 }).call(this); 2258 row._ymax = Math.max.apply(Math, [].concat((function() { 2259 var _j, _len1, _ref1, _results; 2260 _ref1 = row._y; 2261 _results = []; 2262 for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { 2263 y = _ref1[i]; 2264 if (y != null) { 2265 _results.push(y); 2266 } 2267 } 2268 return _results; 2269 })())); 2270 } 2271 _ref1 = this.data; 2272 _results = []; 2273 for (idx = _j = 0, _len1 = _ref1.length; _j < _len1; idx = ++_j) { 2274 row = _ref1[idx]; 2275 this.data[idx].label_x = []; 2276 this.data[idx].label_y = []; 2277 _results.push((function() { 2278 var _k, _ref2, _results1; 2279 _results1 = []; 2280 for (index = _k = _ref2 = this.options.ykeys.length - 1; _ref2 <= 0 ? _k <= 0 : _k >= 0; index = _ref2 <= 0 ? ++_k : --_k) { 2281 if (row._y[index] != null) { 2282 this.data[idx].label_x[index] = row._x; 2283 this.data[idx].label_y[index] = row._y[index] - 10; 2284 } 2285 if (row._y2 != null) { 2286 if (row._y2[index] != null) { 2287 this.data[idx].label_x[index] = row._x; 2288 _results1.push(this.data[idx].label_y[index] = row._y2[index] - 10); 2289 } else { 2290 _results1.push(void 0); 2291 } 2292 } else { 2293 _results1.push(void 0); 2294 } 2295 } 2296 return _results1; 2297 }).call(this)); 2298 } 2299 return _results; 2300 }; 2301 2302 Area.prototype.drawSeries = function() { 2303 var i, range, _i, _j, _k, _l, _len, _len1, _ref, _ref1, _results, _results1, _results2; 2304 this.seriesPoints = []; 2305 if (this.options.behaveLikeLine) { 2306 range = (function() { 2307 _results = []; 2308 for (var _i = 0, _ref = this.options.ykeys.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); } 2309 return _results; 2310 }).apply(this); 2311 } else { 2312 range = (function() { 2313 _results1 = []; 2314 for (var _j = _ref1 = this.options.ykeys.length - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; _ref1 <= 0 ? _j++ : _j--){ _results1.push(_j); } 2315 return _results1; 2316 }).apply(this); 2317 } 2318 for (_k = 0, _len = range.length; _k < _len; _k++) { 2319 i = range[_k]; 2320 this._drawFillFor(i); 2321 } 2322 _results2 = []; 2323 for (_l = 0, _len1 = range.length; _l < _len1; _l++) { 2324 i = range[_l]; 2325 this._drawLineFor(i); 2326 _results2.push(this._drawPointFor(i)); 2327 } 2328 return _results2; 2329 }; 2330 2331 Area.prototype._drawFillFor = function(index) { 2332 var coords, path, pathBelow, r; 2333 path = this.paths[index]; 2334 if (path !== null) { 2335 if (this.options.belowArea === true) { 2336 path = path + ("L" + (this.transX(this.xmax)) + "," + this.bottom + "L" + (this.transX(this.xmin)) + "," + this.bottom + "Z"); 2337 return this.drawFilledPath(path, this.fillForSeries(index), index); 2338 } else { 2339 coords = (function() { 2340 var _i, _ref, _results; 2341 _ref = this.data; 2342 _results = []; 2343 for (_i = _ref.length - 1; _i >= 0; _i += -1) { 2344 r = _ref[_i]; 2345 if (r._y[0] !== void 0) { 2346 _results.push({ 2347 x: r._x, 2348 y: r._y[0] 2349 }); 2350 } 2351 } 2352 return _results; 2353 }).call(this); 2354 pathBelow = Morris.Line.createPath(coords, 'smooth', this.bottom); 2355 path = path + "L" + pathBelow.slice(1); 2356 return this.drawFilledPath(path, this.fillForSeries(index), index); 2357 } 2358 } 2359 }; 2360 2361 Area.prototype.fillForSeries = function(i) { 2362 var color; 2363 if (this.options.areaColors.length === 0) { 2364 this.options.areaColors = this.options.lineColors; 2365 } 2366 color = Raphael.rgb2hsl(this.options.areaColors[i % this.options.areaColors.length]); 2367 return 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)); 2368 }; 2369 2370 Area.prototype.drawFilledPath = function(path, fill, areaIndex) { 2371 var coords, pathBelow, r, rPath, straightPath; 2372 if (this.options.animate) { 2373 coords = (function() { 2374 var _i, _len, _ref, _results; 2375 _ref = this.data; 2376 _results = []; 2377 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 2378 r = _ref[_i]; 2379 if (r._y[areaIndex] !== void 0) { 2380 _results.push({ 2381 x: r._x, 2382 y: this.transY(0) 2383 }); 2384 } 2385 } 2386 return _results; 2387 }).call(this);
2388 straightPath = Morris.Line.createPath(coords, 'smooth', this.bottom); 2389 if (this.options.belowArea === true) { 2390 straightPath = straightPath + ("L" + (this.transX(this.xmax)) + "," + this.bottom + "L" + (this.transX(this.xmin)) + "," + this.bottom + "Z"); 2391 } else { 2392 coords = (function() { 2393 var _i, _ref, _results; 2394 _ref = this.data; 2395 _results = []; 2396 for (_i = _ref.length - 1; _i >= 0; _i += -1) { 2397 r = _ref[_i]; 2398 if (r._y[areaIndex] !== void 0) { 2399 _results.push({ 2400 x: r._x, 2401 y: this.transY(0) 2402 }); 2403 } 2404 } 2405 return _results; 2406 }).call(this); 2407 pathBelow = Morris.Line.createPath(coords, 'smooth', this.bottom); 2408 straightPath = straightPath + "L" + pathBelow.slice(1); 2409 } 2410 straightPath += 'Z'; 2411 rPath = this.raphael.path(straightPath).attr('fill', fill).attr('fill-opacity', this.options.fillOpacity).attr('stroke', 'none'); 2412 return (function(rPath, path) { 2413 return rPath.animate({ 2414 path: path 2415 }, 500, '<>'); 2416 })(rPath, path); 2417 } else { 2418 return this.raphael.path(path).attr('fill', fill).attr('fill-opacity', this.options.fillOpacity).attr('stroke', 'none'); 2419 } 2420 }; 2421 2422 return Area; 2423 2424 })(Morris.Line); 2425 2426 Morris.Bar = (function(_super) { 2427 __extends(Bar, _super); 2428 2429 function Bar(options) { 2430 this.onHoverOut = __bind(this.onHoverOut, this); 2431 this.onHoverMove = __bind(this.onHoverMove, this); 2432 this.onGridClick = __bind(this.onGridClick, this); 2433 if (!(this instanceof Morris.Bar)) { 2434 return new Morris.Bar(options); 2435 } 2436 Bar.__super__.constructor.call(this, Morris.extend({}, options, { 2437 parseTime: false 2438 })); 2439 } 2440 2441 Bar.prototype.init = function() { 2442 this.cumulative = this.options.stacked; 2443 if (this.options.hideHover !== 'always') { 2444 this.hover = new Morris.Hover({ 2445 parent: this.el 2446 }); 2447 this.on('hovermove', this.onHoverMove); 2448 this.on('hoverout', this.onHoverOut); 2449 return this.on('gridclick', this.onGridClick); 2450 } 2451 }; 2452 2453 Bar.prototype.defaults = { 2454 barSizeRatio: 0.75, 2455 pointSize: 4, 2456 lineWidth: 3, 2457 barGap: 3, 2458 barColors: ['#2f7df6', '#53a351', '#f6c244', '#cb444a', '#4aa0b5', '#222529'], 2459 barOpacity: 1.0, 2460 barHighlightOpacity: 1.0, 2461 highlightSpeed: 150, 2462 barRadius: [0, 0, 0, 0], 2463 xLabelMargin: 0, 2464 horizontal: false, 2465 stacked: false, 2466 shown: true, 2467 showZero: true, 2468 inBarValue: false, 2469 inBarValueTextColor: 'white', 2470 inBarValueMinTopMargin: 1, 2471 inBarValueRightMargin: 4, 2472 rightAxisBar: false 2473 }; 2474 2475 Bar.prototype.calc = function() { 2476 var _ref; 2477 this.calcBars(); 2478 if (this.options.hideHover === false) { 2479 return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(this.data.length - 1)); 2480 } 2481 }; 2482 2483 Bar.prototype.calcBars = function() { 2484 var idx, ii, row, y, _i, _len, _ref, _results; 2485 _ref = this.data; 2486 _results = []; 2487 for (idx = _i = 0, _len = _ref.length; _i < _len; idx = ++_i) { 2488 row = _ref[idx]; 2489 row._x = this.xStart + this.xSize * (idx + 0.5) / this.data.length; 2490 row._y = (function() { 2491 var _j, _len1, _ref1, _results1; 2492 _ref1 = row.y; 2493 _results1 = []; 2494 for (ii = _j = 0, _len1 = _ref1.length; _j < _len1; ii = ++_j) { 2495 y = _ref1[ii]; 2496 if (ii < this.options.ykeys.length - this.options.nbYkeys2) { 2497 if (y != null) { 2498 _results1.push(this.transY(y)); 2499 } else { 2500 _results1.push(null); 2501 } 2502 } else { 2503 _results1.push(void 0); 2504 } 2505 } 2506 return _results1; 2507 }).call(this); 2508 _results.push(row._y2 = (function() { 2509 var _j, _len1, _ref1, _results1; 2510 _ref1 = row.y; 2511 _results1 = []; 2512 for (ii = _j = 0, _len1 = _ref1.length; _j < _len1; ii = ++_j) { 2513 y = _ref1[ii]; 2514 if (ii >= this.options.ykeys.length - this.options.nbYkeys2) { 2515 if (y != null) { 2516 _results1.push(this.transY2(y)); 2517 } else { 2518 _results1.push(null); 2519 } 2520 } else { 2521 _results1.push(void 0); 2522 } 2523 } 2524 return _results1; 2525 }).call(this)); 2526 } 2527 return _results; 2528 }; 2529 2530 Bar.prototype.draw = function() { 2531 var _ref; 2532 if ((_ref = this.options.axes) === true || _ref === 'both' || _ref === 'x') { 2533 this.drawXAxis(); 2534 } 2535 this.drawSeries(); 2536 if (this.options.rightAxisBar === !true) { 2537 this.drawBarLine(); 2538 return this.drawBarPoints(); 2539 } 2540 }; 2541 2542 Bar.prototype.drawBarLine = function() { 2543 var coord, coords, dim, g, grads, i, ii, ix, lg, nb, path, prevCoord, r, rPath, straightPath, x1, x2, y1, y2, _i, _j, _len, _len1, _ref, _results; 2544 nb = this.options.ykeys.length - this.options.nbYkeys2; 2545 _ref = this.options.ykeys.slice(nb, this.options.ykeys.length); 2546 _results = []; 2547 for (ii = _i = 0, _len = _ref.length; _i < _len; ii = _i += 1) { 2548 dim = _ref[ii]; 2549 path = "";
2550 straightPath = ""; 2551 if (this.options.horizontal === !true) { 2552 coords = (function() { 2553 var _j, _len1, _ref1, _results1; 2554 _ref1 = this.data; 2555 _results1 = []; 2556 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 2557 r = _ref1[_j]; 2558 if (r._y2[nb + ii] !== void 0) { 2559 _results1.push({ 2560 x: r._x, 2561 y: r._y2[nb + ii] 2562 }); 2563 } 2564 } 2565 return _results1; 2566 }).call(this); 2567 } else { 2568 coords = (function() { 2569 var _j, _len1, _ref1, _results1; 2570 _ref1 = this.data; 2571 _results1 = []; 2572 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 2573 r = _ref1[_j]; 2574 if (r._y2[nb + ii] !== void 0) { 2575 _results1.push({ 2576 x: r._y2[nb + ii], 2577 y: r._x 2578 }); 2579 } 2580 } 2581 return _results1; 2582 }).call(this); 2583 } 2584 if (this.options.smooth) { 2585 grads = Morris.Line.gradients(coords); 2586 } 2587 prevCoord = { 2588 y: null 2589 }; 2590 for (i = _j = 0, _len1 = coords.length; _j < _len1; i = ++_j) { 2591 coord = coords[i]; 2592 if (coord.y != null) { 2593 if (prevCoord.y != null) { 2594 if (this.options.smooth && this.options.horizontal === !true) { 2595 g = grads[i]; 2596 lg = grads[i - 1]; 2597 ix = (coord.x - prevCoord.x) / 4; 2598 x1 = prevCoord.x + ix; 2599 y1 = Math.min(this.bottom, prevCoord.y + ix * lg); 2600 x2 = coord.x - ix; 2601 y2 = Math.min(this.bottom, coord.y - ix * g); 2602 path += "C" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + coord.x + "," + coord.y; 2603 } else { 2604 path += "L" + coord.x + "," + coord.y; 2605 } 2606 if (this.options.horizontal === true) { 2607 straightPath += 'L' + this.transY(0) + ',' + coord.y; 2608 } else { 2609 straightPath += 'L' + coord.x + ',' + this.transY(0); 2610 } 2611 } else { 2612 if (!this.options.smooth || (grads[i] != null)) { 2613 path += "M" + coord.x + "," + coord.y; 2614 if (this.options.horizontal === true) { 2615 straightPath += 'M' + this.transY(0) + ',' + coord.y; 2616 } else { 2617 straightPath += 'M' + coord.x + ',' + this.transY(0); 2618 } 2619 } 2620 } 2621 } 2622 prevCoord = coord; 2623 } 2624 if (path !== "") { 2625 if (this.options.animate) { 2626 rPath = this.raphael.path(straightPath).attr('stroke', this.colorFor(coord, nb + ii, 'bar')).attr('stroke-width', this.lineWidthForSeries(ii)); 2627 _results.push((function(rPath, path) { 2628 return rPath.animate({ 2629 path: path 2630 }, 500, '<>'); 2631 })(rPath, path)); 2632 } else { 2633 _results.push(rPath = this.raphael.path(path).attr('stroke', this.colorFor(coord, nb + ii, 'bar')).attr('stroke-width', this.lineWidthForSeries(ii))); 2634 } 2635 } else { 2636 _results.push(void 0); 2637 } 2638 } 2639 return _results; 2640 }; 2641 2642 Bar.prototype.drawBarPoints = function() { 2643 var circle, dim, idx, ii, nb, row, _i, _len, _ref, _results; 2644 nb = this.options.ykeys.length - this.options.nbYkeys2; 2645 this.seriesPoints = []; 2646 _ref = this.options.ykeys.slice(nb, this.options.ykeys.length); 2647 _results = []; 2648 for (ii = _i = 0, _len = _ref.length; _i < _len; ii = _i += 1) { 2649 dim = _ref[ii]; 2650 this.seriesPoints[ii] = []; 2651 _results.push((function() { 2652 var _j, _len1, _ref1, _results1; 2653 _ref1 = this.data; 2654 _results1 = []; 2655 for (idx = _j = 0, _len1 = _ref1.length; _j < _len1; idx = ++_j) { 2656 row = _ref1[idx]; 2657 circle = null; 2658 if (row._y2[nb + ii] != null) { 2659 if (this.options.horizontal === !true) { 2660 circle = this.raphael.circle(row._x, row._y2[nb + ii], this.pointSizeForSeries(ii)).attr('fill', this.colorFor(row, nb + ii, 'bar')).attr('stroke-width', 1).attr('stroke', '#ffffff'); 2661 _results1.push(this.seriesPoints[ii].push(circle)); 2662 } else { 2663 circle = this.raphael.circle(row._y2[nb + ii], row._x, this.pointSizeForSeries(ii)).attr('fill', this.colorFor(row, nb + ii, 'bar')).attr('stroke-width', 1).attr('stroke', '#ffffff'); 2664 _results1.push(this.seriesPoints[ii].push(circle)); 2665 } 2666 } else { 2667 _results1.push(void 0); 2668 } 2669 } 2670 return _results1; 2671 }).call(this)); 2672 } 2673 return _results; 2674 }; 2675 2676 Bar.prototype.lineWidthForSeries = function(index) { 2677 if (this.options.lineWidth instanceof Array) { 2678 return this.options.lineWidth[index % this.options.lineWidth.length]; 2679 } else { 2680 return this.options.lineWidth; 2681 } 2682 }; 2683 2684 Bar.prototype.pointSizeForSeries = function(index) { 2685 if (this.options.pointSize instanceof Array) { 2686 return this.options.pointSize[index % this.options.pointSize.length]; 2687 } else { 2688 return this.options.pointSize; 2689 } 2690 }; 2691 2692 Bar.prototype.drawXAxis = function() { 2693 var angle, basePos, height, i, label, labelBox, margin, maxSize, offset, prevAngleMargin, prevLabelMargin, row, size, startPos, textBox, width, _i, _ref, _ref1, _results; 2694 if (!this.options.horizontal) { 2695 basePos = this.getXAxisLabelY(); 2696 } else { 2697 basePos = this.getYAxisLabelX(); 2698 } 2699 prevLabelMargin = null; 2700 prevAngleMargin = null; 2701 _results = []; 2702 for (i = _i = 0, _ref = this.data.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { 2703 row = this.data[this.data.length - 1 - i]; 2704 if (!this.options.horizontal) { 2705 label = this.drawXAxisLabel(row._x, basePos, row.label); 2706 } else { 2707 label = this.drawYAxisLabel(basePos, row._x - 0.5 * this.options.gridTextSize, row.label, 1); 2708 } 2709 if (!this.options.horizontal) { 2710 angle = this.options.xLabelAngle; 2711 } else { 2712 angle = 0; 2713 } 2714 textBox = label.getBBox(); 2715 label.transform("r" + (-angle)); 2716 labelBox = label.getBBox(); 2717 label.transform("t0," + (labelBox.height / 2) + "..."); 2718 if (angle !== 0) { 2719 offset = -0.5 * textBox.width * Math.cos(angle * Math.PI / 180.0); 2720 label.transform("t" + offset + ",0..."); 2721 } 2722 _ref1 = Morris.dimensions(this.el), width = _ref1.width, height = _ref1.height; 2723 if (!this.options.horizontal) { 2724 startPos = labelBox.x; 2725 size = labelBox.width; 2726 maxSize = width; 2727 } else { 2728 startPos = labelBox.y; 2729 size = labelBox.height; 2730 maxSize = height; 2731 } 2732 if (((prevLabelMargin == null) || prevLabelMargin >= startPos + size || (prevAngleMargin != null) && prevAngleMargin >= startPos) && startPos >= 0 && (startPos + size) < maxSize) { 2733 if (angle !== 0) { 2734 margin = 1.25 * this.options.gridTextSize / Math.sin(angle * Math.PI / 180.0); 2735 prevAngleMargin = startPos - margin; 2736 } 2737 if (!this.options.horizontal) { 2738 _results.push(prevLabelMargin = startPos - this.options.xLabelMargin); 2739 } else { 2740 _results.push(prevLabelMargin = startPos); 2741 } 2742 } else { 2743 _results.push(label.remove()); 2744 } 2745 } 2746 return _results; 2747 }; 2748 2749 Bar.prototype.getXAxisLabelY = function() { 2750 return this.bottom + (this.options.xAxisLabelTopPadding || this.options.padding / 2); 2751 }; 2752 2753 Bar.prototype.drawSeries = function() { 2754 var barMiddle, barWidth, bottom, depth, groupWidth, i, idx, lastBottom, lastTop, left, leftPadding, nb, numBars, row, sidx, size, space
2754Left, top, ypos, zeroPos, _i, _ref; 2755 this.seriesBars = []; 2756 groupWidth = this.xSize / this.options.data.length; 2757 if (this.options.stacked) { 2758 numBars = 1; 2759 } else { 2760 numBars = 0; 2761 for (i = _i = 0, _ref = this.options.ykeys.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { 2762 if (this.hasToShow(i)) { 2763 numBars += 1; 2764 } 2765 } 2766 } 2767 if (this.options.stacked === !true && this.options.rightAxisBar === false) { 2768 numBars = numBars - this.options.nbYkeys2; 2769 } 2770 barWidth = (groupWidth * this.options.barSizeRatio - this.options.barGap * (numBars - 1)) / numBars; 2771 if (this.options.barSize) { 2772 barWidth = Math.min(barWidth, this.options.barSize); 2773 } 2774 spaceLeft = groupWidth - barWidth * numBars - this.options.barGap * (numBars - 1); 2775 leftPadding = spaceLeft / 2; 2776 zeroPos = this.ymin <= 0 && this.ymax >= 0 ? this.transY(0) : null; 2777 return this.bars = (function() { 2778 var _j, _len, _ref1, _results; 2779 _ref1 = this.data; 2780 _results = []; 2781 for (idx = _j = 0, _len = _ref1.length; _j < _len; idx = ++_j) { 2782 row = _ref1[idx]; 2783 this.data[idx].label_x = []; 2784 this.data[idx].label_y = []; 2785 this.seriesBars[idx] = []; 2786 lastTop = null; 2787 lastBottom = null; 2788 if (this.options.rightAxisBar === true) { 2789 nb = row._y.length; 2790 } else { 2791 nb = row._y.length - this.options.nbYkeys2; 2792 } 2793 _results.push((function() { 2794 var _k, _len1, _ref2, _results1; 2795 _ref2 = row._y.slice(0, nb); 2796 _results1 = []; 2797 for (sidx = _k = 0, _len1 = _ref2.length; _k < _len1; sidx = ++_k) { 2798 ypos = _ref2[sidx]; 2799 if (row._y[sidx] != null) { 2800 ypos = row._y[sidx]; 2801 } else if (row._y2[sidx] != null) { 2802 ypos = row._y2[sidx]; 2803 } 2804 if (!this.hasToShow(sidx)) { 2805 continue; 2806 } 2807 if (ypos !== null) { 2808 if (zeroPos) { 2809 top = Math.min(ypos, zeroPos); 2810 bottom = Math.max(ypos, zeroPos); 2811 } else { 2812 top = ypos; 2813 bottom = this.bottom; 2814 } 2815 left = this.xStart + idx * groupWidth + leftPadding; 2816 if (!this.options.stacked) { 2817 left += sidx * (barWidth + this.options.barGap); 2818 } 2819 size = bottom - top; 2820 if (this.options.verticalGridCondition && this.options.verticalGridCondition(row.x)) { 2821 if (!this.options.horizontal) { 2822 this.drawBar(this.xStart + idx * groupWidth, this.yEnd, groupWidth, this.ySize, this.options.verticalGridColor, this.options.verticalGridOpacity, this.options.barRadius); 2823 } else { 2824 this.drawBar(this.yStart, this.xStart + idx * groupWidth, this.ySize, groupWidth, this.options.verticalGridColor, this.options.verticalGridOpacity, this.options.barRadius); 2825 } 2826 } 2827 if (!this.options.horizontal) { 2828 if (this.options.stacked && (lastTop != null)) { 2829 top += lastTop - bottom; 2830 } 2831 lastTop = top; 2832 if (size === 0 && this.options.showZero) { 2833 size = 1; 2834 } 2835 this.seriesBars[idx][sidx] = this.drawBar(left, top, barWidth, size, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius); 2836 if (this.options.dataLabels) { 2837 if (this.options.dataLabelsPosition === 'inside' || (this.options.stacked && this.options.dataLabelsPosition !== 'force_outside')) { 2838 depth = size / 2; 2839 } else { 2840 depth = -7; 2841 } 2842 if (size > this.options.dataLabelsSize || !this.options.stacked || this.options.dataLabelsPosition === 'force_outside') { 2843 this.data[idx].label_x[sidx] = left + barWidth / 2; 2844 _results1.push(this.data[idx].label_y[sidx] = top + depth); 2845 } else { 2846 _results1.push(void 0); 2847 } 2848 } else { 2849 _results1.push(void 0); 2850 } 2851 } else { 2852 lastBottom = bottom; 2853 if (this.options.stacked && (lastTop != null)) { 2854 top = lastTop; 2855 } 2856 lastTop = top + size; 2857 if (size === 0) { 2858 size = 1; 2859 } 2860 this.seriesBars[idx][sidx] = this.drawBar(top, left, size, barWidth, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius); 2861 if (this.options.dataLabels) { 2862 if (this.options.stacked || this.options.dataLabelsPosition === '
2862inside') { 2863 this.data[idx].label_x[sidx] = top + size / 2; 2864 this.data[idx].label_y[sidx] = left + barWidth / 2; 2865 } else { 2866 this.data[idx].label_x[sidx] = top + size + 5; 2867 this.data[idx].label_y[sidx] = left + barWidth / 2; 2868 } 2869 } 2870 if (this.options.inBarValue && barWidth > this.options.gridTextSize + 2 * this.options.inBarValueMinTopMargin) { 2871 barMiddle = left + 0.5 * barWidth; 2872 _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')); 2873 } else { 2874 _results1.push(void 0); 2875 } 2876 } 2877 } else { 2878 _results1.push(null); 2879 } 2880 } 2881 return _results1; 2882 }).call(this)); 2883 } 2884 return _results; 2885 }).call(this); 2886 }; 2887 2888 Bar.prototype.hilight = function(index) { 2889 var i, y, _i, _j, _len, _len1, _ref, _ref1; 2890 if (this.seriesBars && this.seriesBars[this.prevHilight] && this.prevHilight !== null && this.prevHilight !== index) { 2891 _ref = this.seriesBars[this.prevHilight]; 2892 for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { 2893 y = _ref[i]; 2894 if (y) { 2895 y.animate({ 2896 'fill-opacity': this.options.barOpacity 2897 }, this.options.highlightSpeed); 2898 } 2899 } 2900 } 2901 if (this.seriesBars && this.seriesBars[index] && index !== null && this.prevHilight !== index) { 2902 _ref1 = this.seriesBars[index]; 2903 for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { 2904 y = _ref1[i]; 2905 if (y) { 2906 y.animate({ 2907 'fill-opacity': this.options.barHighlightOpacity 2908 }, this.options.highlightSpeed); 2909 } 2910 } 2911 } 2912 return this.prevHilight = index; 2913 }; 2914 2915 Bar.prototype.colorFor = function(row, sidx, type) { 2916 var r, s; 2917 if (typeof this.options.barColors === 'function') { 2918 r = { 2919 x: row.x, 2920 y: row.y[sidx], 2921 label: row.label, 2922 src: row.src 2923 }; 2924 s = { 2925 index: sidx, 2926 key: this.options.ykeys[sidx], 2927 label: this.options.labels[sidx] 2928 }; 2929 return this.options.barColors.call(this, r, s, type); 2930 } else { 2931 return this.options.barColors[sidx % this.options.barColors.length]; 2932 } 2933 }; 2934 2935 Bar.prototype.hitTest = function(x, y) { 2936 var bodyRect, pos; 2937 if (this.data.length === 0) { 2938 return null; 2939 } 2940 if (!this.options.horizontal) { 2941 pos = x; 2942 } else { 2943 bodyRect = document.body.getBoundingClientRect(); 2944 pos = y + bodyRect.top; 2945 } 2946 pos = Math.max(Math.min(pos, this.xEnd), this.xStart); 2947 return Math.min(this.data.length - 1, Math.floor((pos - this.xStart) / (this.xSize / this.data.length))); 2948 }; 2949 2950 Bar.prototype.onGridClick = function(x, y) { 2951 var index; 2952 index = this.hitTest(x, y); 2953 return this.fire('click', index, this.data[index].src, x, y); 2954 }; 2955 2956 Bar.prototype.onHoverMove = function(x, y) { 2957 var index, _ref; 2958 index = this.hitTest(x, y); 2959 this.hilight(index); 2960 if (index != null) { 2961 return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index)); 2962 } else { 2963 return this.hover.hide(); 2964 } 2965 }; 2966 2967 Bar.prototype.onHoverOut = function() { 2968 this.hilight(-1); 2969 if (this.options.hideHover !== false) { 2970 return this.hover.hide(); 2971 } 2972 }; 2973 2974 Bar.prototype.escapeHTML = function(string) { 2975 var map, reg; 2976 map = { 2977 '&': '&', 2978 '<': '<', 2979 '>': '>', 2980 '"': '"', 2981 "'": ''', 2982 "/": '/' 2983 }; 2984 reg = /[&<>"'/]/ig; 2985 return string.replace(reg, function(match) { 2986 return map[match]; 2987 }); 2988 }; 2989 2990 Bar.prototype.hoverContentForRow = function(index) { 2991 var content, inv, j, jj, row, x, y, _i, _j, _len, _len1, _ref; 2992 row = this.data[index]; 2993 content = "<div class='morris-hover-row-label'>" + this.escapeHTML(row.label) + "</div>"; 2994 inv = []; 2995 _ref = row.y; 2996 for (jj = _i = 0, _len = _ref.length; _i < _len; jj = ++_i) { 2997 y = _ref[jj]; 2998 inv.unshift(y); 2999 } 3000 for (jj = _j = 0, _len1 = inv.length; _j < _len1; jj = ++_j) { 3001 y = inv[jj]; 3002 j = row.y.length - 1 - jj; 3003 if (this.options.labels[j] === false) { 3004 continue; 3005 } 3006 content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y, j)) + "\n</div>"; 3007 } 3008 if (typeof this.options.hoverCallback === 'function') { 3009 content = this.options.hoverCallback(index, this.options, content, row.src
3009); 3010 } 3011 if (!this.options.horizontal) { 3012 x = this.left + (index + 0.5) * this.width / this.data.length; 3013 return [content, x]; 3014 } else { 3015 x = this.left + 0.5 * this.width; 3016 y = this.top + (index + 0.5) * this.height / this.data.length; 3017 return [content, x, y, true]; 3018 } 3019 }; 3020 3021 Bar.prototype.drawBar = function(xPos, yPos, width, height, barColor, opacity, radiusArray) { 3022 var maxRadius, path; 3023 maxRadius = Math.max.apply(Math, radiusArray); 3024 if (this.options.animate) { 3025 if (this.options.horizontal) { 3026 if (maxRadius === 0 || maxRadius > height) { 3027 path = this.raphael.rect(this.transY(0), yPos, 0, height).animate({ 3028 x: xPos, 3029 width: width 3030 }, 500); 3031 } else { 3032 path = this.raphael.path(this.roundedRect(this.transY(0), yPos + height, width, 0, radiusArray).animate({ 3033 y: yPos, 3034 height: height 3035 }, 500)); 3036 } 3037 } else { 3038 if (maxRadius === 0 || maxRadius > height) { 3039 path = this.raphael.rect(xPos, this.transY(0), width, 0).animate({ 3040 y: yPos, 3041 height: height 3042 }, 500); 3043 } else { 3044 path = this.raphael.path(this.roundedRect(xPos, this.transY(0), width, 0, radiusArray).animate({ 3045 y: yPos, 3046 height: height 3047 }, 500)); 3048 } 3049 } 3050 } else { 3051 if (maxRadius === 0 || maxRadius > height) { 3052 path = this.raphael.rect(xPos, yPos, width, height); 3053 } else { 3054 path = this.raphael.path(this.roundedRect(xPos, yPos, width, height, radiusArray)); 3055 } 3056 } 3057 return path.attr('fill', barColor).attr('fill-opacity', opacity).attr('stroke', 'none'); 3058 }; 3059 3060 Bar.prototype.roundedRect = function(x, y, w, h, r) { 3061 if (r == null) { 3062 r = [0, 0, 0, 0]; 3063 } 3064 return ["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"]; 3065 }; 3066 3067 return Bar; 3068 3069 })(Morris.Grid); 3070 3071 Morris.Donut = (function(_super) { 3072 __extends(Donut, _super); 3073 3074 Donut.prototype.defaults = { 3075 colors: ['#2f7df6', '#53a351', '#f6c244', '#cb444a', '#4aa0b5', '#222529', '#44a1f8', '#81d453', '#f0bb40', '#eb3f25', '#b45184', '#5f5f5f'], 3076 backgroundColor: '#FFFFFF', 3077 labelColor: '#000000', 3078 padding: 0, 3079 formatter: Morris.commas, 3080 resize: true, 3081 dataLabels: false, 3082 dataLabelsPosition: 'inside', 3083 dataLabelsFamily: 'sans-serif', 3084 dataLabelsSize: 12, 3085 dataLabelsWeight: 'normal', 3086 dataLabelsColor: 'auto', 3087 noDataLabel: 'No data for this chart', 3088 noDataLabelSize: 21, 3089 noDataLabelWeight: 'bold', 3090 donutType: 'donut', 3091 animate: true, 3092 showPercentage: false, 3093 postUnits: '', 3094 preUnits: '' 3095 }; 3096 3097 function Donut(options) { 3098 this.debouncedResizeHandler = __bind(this.debouncedResizeHandler, this); 3099 this.resizeHandler = __bind(this.resizeHandler, this); 3100 this.deselect = __bind(this.deselect, this); 3101 this.select = __bind(this.select, this); 3102 this.click = __bind(this.click, this); 3103 var cx, cy, height, width, _ref; 3104 if (!(this instanceof Morris.Donut)) { 3105 return new Morris.Donut(options); 3106 } 3107 this.options = Morris.extend({}, this.defaults, options); 3108 if (typeof options.element === 'string') { 3109 this.el = document.getElementById(options.element); 3110 } else { 3111 this.el = options.element[0] || options.element; 3112 } 3113 if (this.el === null) { 3114 throw new Error("Graph placeholder not found."); 3115 } 3116 this.raphael = new Raphael(this.el); 3117 if (options.data === void 0 || options.data.length === 0) { 3118 _ref = Morris.dimensions(this.el), width = _ref.width, height = _ref.height; 3119 cx = width / 2; 3120 cy = height / 2; 3121 this.raphael.text(cx, cy, this.options.noDataLabel).attr('text-anchor', 'middle').attr('font-size', this.options.noDataLabelSize).attr('font-family', this.options.dataLabelsFamily).attr('font-weight', this.options.noDataLabelWeight).attr('fill', this.options.dataLabelsColor); 3122 return; 3123 } 3124 if (this.options.resize) { 3125 Morris.on(window, 'resize', this.resizeHandler); 3126 } 3127 this.setData(options.data); 3128 } 3129 3130 Donut.prototype.destroy = function() { 3131 if (this.options.resize) { 3132 window.clearTimeout(this.timeoutId); 3133 return Morris.off(window, 'resize', this.resizeHandler); 3134 } 3135 }; 3136 3137 Donut.prototype.redraw = function() { 3138 var C, color, cx, cy, dist, finalValue, height, i, idx, label_x, label_y, last, max_value, min, next, p_cos_p0, p_sin_p0, seg, total, value, w, width, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _results; 3139 this.raphael.clear(); 3140 _ref = Morris.dimensions(this.el), width = _ref.width, height = _ref.height; 3141 cx = width / 2; 3142 cy = height / 2; 3143 w = (Math.min(cx, cy) - 10) / 3 - this.options.padding; 3144 total = 0; 3145 _ref1 = this.values; 3146 for (_i = 0, _len = _ref1.length; _i < _len; _i++) { 3147 value = _ref1[_i]; 3148 total += value; 3149 } 3150 this.options.total = total; 3151 min = 5 / (2 * w); 3152 C = 1.9999 * Math.PI - min * this.data.length; 3153 last = 0; 3154 idx = 0; 3155 this.segments = []; 3156 if (total === 0) { 3157 total = 1; 3158 } 3159 _ref2 = this.values; 3160 for (i = _j = 0, _len1 = _ref2.length; _j < _len1; i = ++_j) { 3161 value = _ref2[i]; 3162 next = last + min + C * (value / total); 3163 seg = 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, this.options); 3164 seg.render(); 3165 this.segments.push(seg); 3166 seg.on('hover', this.select); 3167 seg.on('click', this.click); 3168 seg.on('mouseout', this.deselect); 3169 if (parseFloat(seg.raphael.height) > parseFloat(height)) { 3170 dist = height * 2 - this.options.padding * 7; 3171 } else { 3172 dist = seg.raphael.height - this.options.padding * 7; 3173 } 3174 if (this.options.data[i].ratio === void 0) { 3175 this.options.data[i].ratio = 1; 3176 } 3177 dist = dist * this.options.data[i].ratio; 3178 if (this.options.dataLabels && this.values.length >= 1) { 3179 p_sin_p0 = Math.sin((last + next) / 2); 3180 p_cos_p0 = Math.cos((last + next) / 2);
3181 if (this.options.dataLabelsPosition === 'inside') { 3182 if (this.options.donutType === 'pie') { 3183 label_x = parseFloat(cx) + parseFloat(dist * 0.30 * p_sin_p0); 3184 label_y = parseFloat(cy) + parseFloat(dist * 0.30 * p_cos_p0); 3185 } else { 3186 label_x = parseFloat(cx) + parseFloat(dist * 0.39 * p_sin_p0); 3187 label_y = parseFloat(cy) + parseFloat(dist * 0.39 * p_cos_p0); 3188 } 3189 } else { 3190 label_x = parseFloat(cx) + parseFloat((dist - 9) * 0.5 * p_sin_p0); 3191 label_y = parseFloat(cy) + parseFloat((dist - 9) * 0.5 * p_cos_p0); 3192 } 3193 if (this.options.dataLabelsColor !== 'auto') { 3194 color = this.options.dataLabelsColor; 3195 } else if (this.options.dataLabelsPosition === 'inside' && this.isColorDark(this.options.colors[i]) === true) { 3196 color = '#fff'; 3197 } else { 3198 color = '#000'; 3199 } 3200 if (this.options.showPercentage) { 3201 finalValue = Math.round(parseFloat(value) / parseFloat(total) * 100) + '%'; 3202 this.drawDataLabelExt(label_x, label_y, finalValue, color); 3203 } else { 3204 this.drawDataLabelExt(label_x, label_y, this.options.preUnits + value + this.options.postUnits, color); 3205 } 3206 } 3207 last = next; 3208 idx += 1; 3209 } 3210 this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, this.options.labelColor, 15, 800); 3211 this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, this.options.labelColor, 14); 3212 max_value = Math.max.apply(Math, this.values); 3213 idx = 0; 3214 if (this.options.donutType === 'donut') { 3215 _ref3 = this.values; 3216 _results = []; 3217 for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { 3218 value = _ref3[_k]; 3219 if (value === max_value) { 3220 this.select(idx); 3221 break; 3222 } 3223 _results.push(idx += 1); 3224 } 3225 return _results; 3226 } 3227 }; 3228 3229 Donut.prototype.setData = function(data) { 3230 var row; 3231 this.data = data; 3232 this.values = (function() { 3233 var _i, _len, _ref, _results; 3234 _ref = this.data; 3235 _results = []; 3236 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 3237 row = _ref[_i]; 3238 _results.push(parseFloat(row.value)); 3239 } 3240 return _results; 3241 }).call(this); 3242 return this.redraw(); 3243 }; 3244 3245 Donut.prototype.drawDataLabel = function(xPos, yPos, text, color) { 3246 var label; 3247 return label = this.raphael.text(xPos, yPos, text).attr('text-anchor', 'middle').attr('font-size', this.options.dataLabelsSize).attr('font-family', this.options.dataLabelsFamily).attr('font-weight', this.options.dataLabelsWeight).attr('fill', this.options.dataLabelsColor); 3248 }; 3249 3250 Donut.prototype.drawDataLabelExt = function(xPos, yPos, text, color) { 3251 var label, labelAnchor; 3252 if (this.values.length >= 1) { 3253 labelAnchor = 'middle'; 3254 } else if (this.options.dataLabelsPosition === 'inside') { 3255 labelAnchor = 'middle'; 3256 } else if (xPos > this.raphael.width / 2) { 3257 labelAnchor = 'start'; 3258 } else if (xPos > this.raphael.width * 0.55 && xPos < this.raphael.width * 0.45) { 3259 labelAnchor = 'middle'; 3260 } else { 3261 labelAnchor = 'end'; 3262 } 3263 return label = this.raphael.text(xPos, yPos, text, color).attr('text-anchor', labelAnchor).attr('font-size', this.options.dataLabelsSize).attr('font-family', this.options.dataLabelsFamily).attr('font-weight', this.options.dataLabelsWeight).attr('fill', color); 3264 }; 3265 3266 Donut.prototype.click = function(idx) { 3267 return this.fire('click', idx, this.data[idx]); 3268 }; 3269 3270 Donut.prototype.select = function(idx) { 3271 var finalValue, row, s, segment, _i, _len, _ref; 3272 _ref = this.segments; 3273 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 3274 s = _ref[_i]; 3275 s.deselect(); 3276 } 3277 segment = this.segments[idx]; 3278 segment.select(); 3279 row = this.data[idx]; 3280 if (this.options.donutType === 'donut') { 3281 if (this.options.showPercentage && !this.options.dataLabels) { 3282 finalValue = Math.round(parseFloat(row.value) / parseFloat(this.options.total) * 100) + '%'; 3283 return this.setLabels(row.label, finalValue); 3284 } else { 3285 return this.setLabels(row.label, this.options.formatter(row.value, row)); 3286 } 3287 } 3288 }; 3289 3290 Donut.prototype.deselect = function(idx) { 3291 var s, _i, _len, _ref, _results; 3292 _ref = this.segments; 3293 _results = []; 3294 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 3295 s = _ref[_i]; 3296 _results.push(s.deselect()); 3297 } 3298 return _results; 3299 }; 3300 3301 Donut.prototype.isColorDark = function(hex) { 3302 var b, g, luma, r, rgb; 3303 if (hex != null) { 3304 hex = hex.substring(1); 3305 rgb = parseInt(hex, 16); 3306 r = (rgb >> 16) & 0xff;
3307 g = (rgb >> 8) & 0xff; 3308 b = (rgb >> 0) & 0xff; 3309 luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; 3310 if (luma >= 128) { 3311 return false; 3312 } else { 3313 return true; 3314 } 3315 } else { 3316 return false; 3317 } 3318 }; 3319 3320 Donut.prototype.setLabels = function(label1, label2) { 3321 var height, inner, maxHeightBottom, maxHeightTop, maxWidth, text1bbox, text1scale, text2bbox, text2scale, width, _ref; 3322 _ref = Morris.dimensions(this.el), width = _ref.width, height = _ref.height; 3323 inner = (Math.min(width / 2, height / 2) - 10) * 2 / 3; 3324 maxWidth = 1.8 * inner; 3325 maxHeightTop = inner / 2; 3326 maxHeightBottom = inner / 3; 3327 this.text1.attr({ 3328 text: label1, 3329 transform: '' 3330 }); 3331 text1bbox = this.text1.getBBox(); 3332 text1scale = Math.min(maxWidth / text1bbox.width, maxHeightTop / text1bbox.height); 3333 this.text1.attr({ 3334 transform: "S" + text1scale + "," + text1scale + "," + (text1bbox.x + text1bbox.width / 2) + "," + (text1bbox.y + text1bbox.height) 3335 }); 3336 this.text2.attr({ 3337 text: label2, 3338 transform: '' 3339 }); 3340 text2bbox = this.text2.getBBox(); 3341 text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height); 3342 return this.text2.attr({ 3343 transform: "S" + text2scale + "," + text2scale + "," + (text2bbox.x + text2bbox.width / 2) + "," + text2bbox.y 3344 }); 3345 }; 3346 3347 Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, color, fontSize, fontWeight) { 3348 var text; 3349 text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize).attr('fill', color); 3350 if (fontWeight != null) { 3351 text.attr('font-weight', fontWeight); 3352 } 3353 return text; 3354 }; 3355 3356 Donut.prototype.resizeHandler = function() { 3357 if (this.timeoutId != null) { 3358 window.clearTimeout(this.timeoutId); 3359 } 3360 return this.timeoutId = window.setTimeout(this.debouncedResizeHandler, 100); 3361 }; 3362 3363 Donut.prototype.debouncedResizeHandler = function() { 3364 var height, width, _ref; 3365 this.timeoutId = null; 3366 _ref = Morris.dimensions(this.el), width = _ref.width, height = _ref.height; 3367 this.raphael.setSize(width, height); 3368 this.options.animate = false; 3369 return this.redraw(); 3370 }; 3371 3372 return Donut; 3373 3374 })(Morris.EventEmitter); 3375 3376 Morris.DonutSegment = (function(_super) { 3377 __extends(DonutSegment, _super); 3378 3379 function DonutSegment(cx, cy, inner, outer, p0, p1, color, backgroundColor, index, raphael, options) { 3380 this.cx = cx; 3381 this.cy = cy; 3382 this.inner = inner; 3383 this.outer = outer; 3384 this.color = color; 3385 this.backgroundColor = backgroundColor; 3386 this.index = index; 3387 this.raphael = raphael; 3388 this.options = options; 3389 this.deselect = __bind(this.deselect, this); 3390 this.select = __bind(this.select, this); 3391 this.sin_p0 = Math.sin(p0); 3392 this.cos_p0 = Math.cos(p0); 3393 this.sin_p1 = Math.sin(p1); 3394 this.cos_p1 = Math.cos(p1); 3395 this.is_long = (p1 - p0) > Math.PI ? 1 : 0; 3396 if (this.options.data[this.index].ratio === void 0) { 3397 this.options.data[this.index].ratio = 1; 3398 } 3399 inner = this.inner * this.options.data[this.index].ratio; 3400 this.path = this.calcSegment(inner + 3, inner + this.outer - 5); 3401 this.selectedPath = this.calcSegment(inner + 3, inner + this.outer); 3402 this.hilight = this.calcArc(inner); 3403 } 3404 3405 DonutSegment.prototype.calcArcPoints = function(r) { 3406 return [this.cx + r * this.sin_p0, this.cy + r * this.cos_p0, this.cx + r * this.sin_p1, this.cy + r * this.cos_p1]; 3407 }; 3408 3409 DonutSegment.prototype.calcSegment = function(r1, r2) { 3410 var ix0, ix1, iy0, iy1, ox0, ox1, oy0, oy1, _ref, _ref1; 3411 _ref = this.calcArcPoints(r1), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3]; 3412 _ref1 = this.calcArcPoints(r2), ox0 = _ref1[0], oy0 = _ref1[1], ox1 = _ref1[2], oy1 = _ref1[3]; 3413 if (this.options.donutType === 'pie') { 3414 return ("M" + ox0 + "," + oy0) + ("A" + r2 + "," + r2 + ",0," + this.is_long + ",0," + ox1 + "," + oy1) + ("L" + this.cx + "," + this.cy) + "Z"; 3415 } else { 3416 return ("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"; 3417 } 3418 }; 3419 3420 DonutSegment.prototype.calcArc = function(r) { 3421 var ix0, ix1, iy0, iy1, _ref; 3422 _ref = this.calcArcPoints(r), ix0 = _ref[0], iy0 = _ref[1], ix1
3422= _ref[2], iy1 = _ref[3]; 3423 return ("M" + ix0 + "," + iy0) + ("A" + r + "," + r + ",0," + this.is_long + ",0," + ix1 + "," + iy1); 3424 }; 3425 3426 DonutSegment.prototype.render = function() { 3427 var _this = this; 3428 if (!/NaN/.test(this.hilight)) { 3429 this.arc = this.drawDonutArc(this.hilight, this.color); 3430 } 3431 if (!/NaN/.test(this.path)) { 3432 return this.seg = this.drawDonutSegment(this.path, this.color, this.backgroundColor, function() { 3433 return _this.fire('hover', _this.index); 3434 }, function() { 3435 return _this.fire('click', _this.index); 3436 }, function() { 3437 return _this.fire('mouseout', _this.index); 3438 }); 3439 } 3440 }; 3441 3442 DonutSegment.prototype.drawDonutArc = function(path, color) { 3443 var rPath; 3444 if (this.options.animate) { 3445 rPath = this.raphael.path("M" + this.cx + "," + this.cy + "Z").attr({ 3446 stroke: color, 3447 'stroke-width': 2, 3448 opacity: 0 3449 }); 3450 return (function(rPath, path) { 3451 return rPath.animate({ 3452 path: path 3453 }, 500, '<>'); 3454 })(rPath, path); 3455 } else { 3456 return this.raphael.path(path).attr({ 3457 stroke: color, 3458 'stroke-width': 2, 3459 opacity: 0 3460 }); 3461 } 3462 }; 3463 3464 DonutSegment.prototype.drawDonutSegment = function(path, fillColor, strokeColor, hoverFunction, clickFunction, leaveFunction) { 3465 var rPath, straightDots, straightPath; 3466 if (this.options.animate && this.options.donutType === 'pie') { 3467 straightPath = path; 3468 straightPath = path.replace('A', ','); 3469 straightPath = straightPath.replace('M', ''); 3470 straightPath = straightPath.replace('C', ','); 3471 straightPath = straightPath.replace('Z', ''); 3472 straightDots = straightPath.split(','); 3473 if (this.options.donutType === 'pie') { 3474 straightPath = 'M' + straightDots[0] + ',' + straightDots[1] + ',' + straightDots[straightDots.length - 2] + ',' + straightDots[straightDots.length - 1] + ',' + straightDots[straightDots.length - 2] + ',' + straightDots[straightDots.length - 1] + 'Z'; 3475 } else { 3476 straightPath = 'M' + straightDots[0] + ',' + straightDots[1] + ',' + straightDots[straightDots.length - 2] + ',' + straightDots[straightDots.length - 1] + 'Z'; 3477 } 3478 rPath = this.raphael.path(straightPath).attr({ 3479 fill: fillColor, 3480 stroke: strokeColor, 3481 'stroke-width': 3 3482 }).hover(hoverFunction).click(clickFunction).mouseout(leaveFunction); 3483 return (function(rPath, path) { 3484 return rPath.animate({ 3485 path: path 3486 }, 500, '<>'); 3487 })(rPath, path); 3488 } else { 3489 if (this.options.donutType === 'pie') { 3490 return this.raphael.path(path).attr({ 3491 fill: fillColor, 3492 stroke: strokeColor, 3493 'stroke-width': 3 3494 }).hover(hoverFunction).click(clickFunction).mouseout(leaveFunction); 3495 } else { 3496 return this.raphael.path(path).attr({ 3497 fill: fillColor, 3498 stroke: strokeColor, 3499 'stroke-width': 3 3500 }).hover(hoverFunction).click(clickFunction); 3501 } 3502 } 3503 }; 3504 3505 DonutSegment.prototype.select = function() { 3506 if (!this.selected) { 3507 if (this.seg != null) { 3508 this.seg.animate({ 3509 path: this.selectedPath 3510 }, 150, '<>'); 3511 this.arc.animate({ 3512 opacity: 1 3513 }, 150, '<>'); 3514 return this.selected = true; 3515 } 3516 } 3517 }; 3518 3519 DonutSegment.prototype.deselect = function() { 3520 if (this.selected) { 3521 this.seg.animate({ 3522 path: this.path 3523 }, 150, '<>'); 3524 this.arc.animate({ 3525 opacity: 0 3526 }, 150, '<>'); 3527 return this.selected = false; 3528 } 3529 }; 3530 3531 return DonutSegment; 3532 3533 })(Morris.EventEmitter); 3534 3535}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.