morris.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. (function () {
  2. var $, Morris, minutesSpecHelper, secondsSpecHelper,
  3. __slice = [].slice,
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function (child, parent) {
  6. for (var key in parent) {
  7. if (__hasProp.call(parent, key)) child[key] = parent[key];
  8. }
  9. function ctor() {
  10. this.constructor = child;
  11. }
  12. ctor.prototype = parent.prototype;
  13. child.prototype = new ctor();
  14. child.__super__ = parent.prototype;
  15. return child;
  16. },
  17. __bind = function (fn, me) {
  18. return function () {
  19. return fn.apply(me, arguments);
  20. };
  21. },
  22. __indexOf = [].indexOf || function (item) {
  23. for (var i = 0, l = this.length; i < l; i++) {
  24. if (i in this && this[i] === item) return i;
  25. }
  26. return -1;
  27. };
  28. Morris = window.Morris = {};
  29. $ = jQuery;
  30. Morris.EventEmitter = (function () {
  31. function EventEmitter() {
  32. }
  33. EventEmitter.prototype.on = function (name, handler) {
  34. if (this.handlers == null) {
  35. this.handlers = {};
  36. }
  37. if (this.handlers[name] == null) {
  38. this.handlers[name] = [];
  39. }
  40. this.handlers[name].push(handler);
  41. return this;
  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. return EventEmitter;
  57. })();
  58. Morris.commas = function (num) {
  59. var absnum, intnum, ret, strabsnum;
  60. if (num != null) {
  61. ret = num < 0 ? "-" : "";
  62. absnum = Math.abs(num);
  63. intnum = Math.floor(absnum).toFixed(0);
  64. ret += intnum.replace(/(?=(?:\d{3})+$)(?!^)/g, ',');
  65. strabsnum = absnum.toString();
  66. if (strabsnum.length > intnum.length) {
  67. ret += strabsnum.slice(intnum.length);
  68. }
  69. return ret;
  70. } else {
  71. return '-';
  72. }
  73. };
  74. Morris.pad2 = function (number) {
  75. return (number < 10 ? '0' : '') + number;
  76. };
  77. Morris.Grid = (function (_super) {
  78. __extends(Grid, _super);
  79. function Grid(options) {
  80. var _this = this;
  81. if (typeof options.element === 'string') {
  82. this.el = $(document.getElementById(options.element));
  83. } else {
  84. this.el = $(options.element);
  85. }
  86. if (!(this.el != null) || this.el.length === 0) {
  87. throw new Error("Graph container element not found");
  88. }
  89. if (this.el.css('position') === 'static') {
  90. this.el.css('position', 'relative');
  91. }
  92. this.options = $.extend({}, this.gridDefaults, this.defaults || {}, options);
  93. if (typeof this.options.units === 'string') {
  94. this.options.postUnits = options.units;
  95. }
  96. this.raphael = new Raphael(this.el[0]);
  97. this.elementWidth = null;
  98. this.elementHeight = null;
  99. this.dirty = false;
  100. if (this.init) {
  101. this.init();
  102. }
  103. this.setData(this.options.data);
  104. this.el.bind('mousemove', function (evt) {
  105. var offset;
  106. offset = _this.el.offset();
  107. return _this.fire('hovermove', evt.pageX - offset.left, evt.pageY - offset.top);
  108. });
  109. this.el.bind('mouseout', function (evt) {
  110. return _this.fire('hoverout');
  111. });
  112. this.el.bind('touchstart touchmove touchend', function (evt) {
  113. var offset, touch;
  114. touch = evt.originalEvent.touches[0] || evt.originalEvent.changedTouches[0];
  115. offset = _this.el.offset();
  116. _this.fire('hover', touch.pageX - offset.left, touch.pageY - offset.top);
  117. return touch;
  118. });
  119. this.el.bind('click', function (evt) {
  120. var offset;
  121. offset = _this.el.offset();
  122. return _this.fire('gridclick', evt.pageX - offset.left, evt.pageY - offset.top);
  123. });
  124. if (this.postInit) {
  125. this.postInit();
  126. }
  127. }
  128. Grid.prototype.gridDefaults = {
  129. dateFormat: null,
  130. axes: true,
  131. grid: true,
  132. gridLineColor: '#aaa',
  133. gridStrokeWidth: 0.5,
  134. gridTextColor: '#888',
  135. gridTextSize: 12,
  136. gridTextFamily: 'sans-serif',
  137. gridTextWeight: 'normal',
  138. hideHover: false,
  139. yLabelFormat: null,
  140. xLabelAngle: 0,
  141. numLines: 5,
  142. padding: 25,
  143. parseTime: true,
  144. postUnits: '',
  145. preUnits: '',
  146. ymax: 'auto',
  147. ymin: 'auto 0',
  148. goals: [],
  149. goalStrokeWidth: 1.0,
  150. goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'],
  151. events: [],
  152. eventStrokeWidth: 1.0,
  153. eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502']
  154. };
  155. Grid.prototype.setData = function (data, redraw) {
  156. var e, idx, index, maxGoal, minGoal, ret, row, step, total, y, ykey, ymax, ymin, yval;
  157. if (redraw == null) {
  158. redraw = true;
  159. }
  160. this.options.data = data;
  161. if (!(data != null) || data.length === 0) {
  162. this.data = [];
  163. this.raphael.clear();
  164. if (this.hover != null) {
  165. this.hover.hide();
  166. }
  167. return;
  168. }
  169. ymax = this.cumulative ? 0 : null;
  170. ymin = this.cumulative ? 0 : null;
  171. if (this.options.goals.length > 0) {
  172. minGoal = Math.min.apply(null, this.options.goals);
  173. maxGoal = Math.max.apply(null, this.options.goals);
  174. ymin = ymin != null ? Math.min(ymin, minGoal) : minGoal;
  175. ymax = ymax != null ? Math.max(ymax, maxGoal) : maxGoal;
  176. }
  177. this.data = (function () {
  178. var _i, _len, _results;
  179. _results = [];
  180. for (index = _i = 0, _len = data.length; _i < _len; index = ++_i) {
  181. row = data[index];
  182. ret = {};
  183. ret.label = row[this.options.xkey];
  184. if (this.options.parseTime) {
  185. ret.x = Morris.parseDate(ret.label);
  186. if (this.options.dateFormat) {
  187. ret.label = this.options.dateFormat(ret.x);
  188. } else if (typeof ret.label === 'number') {
  189. ret.label = new Date(ret.label).toString();
  190. }
  191. } else {
  192. ret.x = index;
  193. if (this.options.xLabelFormat) {
  194. ret.label = this.options.xLabelFormat(ret);
  195. }
  196. }
  197. total = 0;
  198. ret.y = (function () {
  199. var _j, _len1, _ref, _results1;
  200. _ref = this.options.ykeys;
  201. _results1 = [];
  202. for (idx = _j = 0, _len1 = _ref.length; _j < _len1; idx = ++_j) {
  203. ykey = _ref[idx];
  204. yval = row[ykey];
  205. if (typeof yval === 'string') {
  206. yval = parseFloat(yval);
  207. }
  208. if ((yval != null) && typeof yval !== 'number') {
  209. yval = null;
  210. }
  211. if (yval != null) {
  212. if (this.cumulative) {
  213. total += yval;
  214. } else {
  215. if (ymax != null) {
  216. ymax = Math.max(yval, ymax);
  217. ymin = Math.min(yval, ymin);
  218. } else {
  219. ymax = ymin = yval;
  220. }
  221. }
  222. }
  223. if (this.cumulative && (total != null)) {
  224. ymax = Math.max(total, ymax);
  225. ymin = Math.min(total, ymin);
  226. }
  227. _results1.push(yval);
  228. }
  229. return _results1;
  230. }).call(this);
  231. _results.push(ret);
  232. }
  233. return _results;
  234. }).call(this);
  235. if (this.options.parseTime) {
  236. this.data = this.data.sort(function (a, b) {
  237. return (a.x > b.x) - (b.x > a.x);
  238. });
  239. }
  240. this.xmin = this.data[0].x;
  241. this.xmax = this.data[this.data.length - 1].x;
  242. this.events = [];
  243. if (this.options.parseTime && this.options.events.length > 0) {
  244. this.events = (function () {
  245. var _i, _len, _ref, _results;
  246. _ref = this.options.events;
  247. _results = [];
  248. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  249. e = _ref[_i];
  250. _results.push(Morris.parseDate(e));
  251. }
  252. return _results;
  253. }).call(this);
  254. this.xmax = Math.max(this.xmax, Math.max.apply(null, this.events));
  255. this.xmin = Math.min(this.xmin, Math.min.apply(null, this.events));
  256. }
  257. if (this.xmin === this.xmax) {
  258. this.xmin -= 1;
  259. this.xmax += 1;
  260. }
  261. this.ymin = this.yboundary('min', ymin);
  262. this.ymax = this.yboundary('max', ymax);
  263. if (this.ymin === this.ymax) {
  264. if (ymin) {
  265. this.ymin -= 1;
  266. }
  267. this.ymax += 1;
  268. }
  269. if (this.options.axes === true || this.options.grid === true) {
  270. if (this.options.ymax === this.gridDefaults.ymax && this.options.ymin === this.gridDefaults.ymin) {
  271. this.grid = this.autoGridLines(this.ymin, this.ymax, this.options.numLines);
  272. this.ymin = Math.min(this.ymin, this.grid[0]);
  273. this.ymax = Math.max(this.ymax, this.grid[this.grid.length - 1]);
  274. } else {
  275. step = (this.ymax - this.ymin) / (this.options.numLines - 1);
  276. this.grid = (function () {
  277. var _i, _ref, _ref1, _results;
  278. _results = [];
  279. for (y = _i = _ref = this.ymin, _ref1 = this.ymax; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; y = _i += step) {
  280. _results.push(y);
  281. }
  282. return _results;
  283. }).call(this);
  284. }
  285. }
  286. this.dirty = true;
  287. if (redraw) {
  288. return this.redraw();
  289. }
  290. };
  291. Grid.prototype.yboundary = function (boundaryType, currentValue) {
  292. var boundaryOption, suggestedValue;
  293. boundaryOption = this.options["y" + boundaryType];
  294. if (typeof boundaryOption === 'string') {
  295. if (boundaryOption.slice(0, 4) === 'auto') {
  296. if (boundaryOption.length > 5) {
  297. suggestedValue = parseInt(boundaryOption.slice(5), 10);
  298. if (currentValue == null) {
  299. return suggestedValue;
  300. }
  301. return Math[boundaryType](currentValue, suggestedValue);
  302. } else {
  303. if (currentValue != null) {
  304. return currentValue;
  305. } else {
  306. return 0;
  307. }
  308. }
  309. } else {
  310. return parseInt(boundaryOption, 10);
  311. }
  312. } else {
  313. return boundaryOption;
  314. }
  315. };
  316. Grid.prototype.autoGridLines = function (ymin, ymax, nlines) {
  317. var gmax, gmin, grid, smag, span, step, unit, y, ymag;
  318. span = ymax - ymin;
  319. ymag = Math.floor(Math.log(span) / Math.log(10));
  320. unit = Math.pow(10, ymag);
  321. gmin = Math.floor(ymin / unit) * unit;
  322. gmax = Math.ceil(ymax / unit) * unit;
  323. step = (gmax - gmin) / (nlines - 1);
  324. if (unit === 1 && step > 1 && Math.ceil(step) !== step) {
  325. step = Math.ceil(step);
  326. gmax = gmin + step * (nlines - 1);
  327. }
  328. if (gmin < 0 && gmax > 0) {
  329. gmin = Math.floor(ymin / step) * step;
  330. gmax = Math.ceil(ymax / step) * step;
  331. }
  332. if (step < 1) {
  333. smag = Math.floor(Math.log(step) / Math.log(10));
  334. grid = (function () {
  335. var _i, _results;
  336. _results = [];
  337. for (y = _i = gmin; gmin <= gmax ? _i <= gmax : _i >= gmax; y = _i += step) {
  338. _results.push(parseFloat(y.toFixed(1 - smag)));
  339. }
  340. return _results;
  341. })();
  342. } else {
  343. grid = (function () {
  344. var _i, _results;
  345. _results = [];
  346. for (y = _i = gmin; gmin <= gmax ? _i <= gmax : _i >= gmax; y = _i += step) {
  347. _results.push(y);
  348. }
  349. return _results;
  350. })();
  351. }
  352. return grid;
  353. };
  354. Grid.prototype._calc = function () {
  355. var bottomOffsets, gridLine, h, i, w, yLabelWidths;
  356. w = this.el.width();
  357. h = this.el.height();
  358. if (this.elementWidth !== w || this.elementHeight !== h || this.dirty) {
  359. this.elementWidth = w;
  360. this.elementHeight = h;
  361. this.dirty = false;
  362. this.left = this.options.padding;
  363. this.right = this.elementWidth - this.options.padding;
  364. this.top = this.options.padding;
  365. this.bottom = this.elementHeight - this.options.padding;
  366. if (this.options.axes) {
  367. yLabelWidths = (function () {
  368. var _i, _len, _ref, _results;
  369. _ref = this.grid;
  370. _results = [];
  371. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  372. gridLine = _ref[_i];
  373. _results.push(this.measureText(this.yAxisFormat(gridLine)).width);
  374. }
  375. return _results;
  376. }).call(this);
  377. this.left += Math.max.apply(Math, yLabelWidths);
  378. bottomOffsets = (function () {
  379. var _i, _ref, _results;
  380. _results = [];
  381. for (i = _i = 0, _ref = this.data.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
  382. _results.push(this.measureText(this.data[i].text, -this.options.xLabelAngle).height);
  383. }
  384. return _results;
  385. }).call(this);
  386. this.bottom -= Math.max.apply(Math, bottomOffsets);
  387. }
  388. this.width = Math.max(1, this.right - this.left);
  389. this.height = Math.max(1, this.bottom - this.top);
  390. this.dx = this.width / (this.xmax - this.xmin);
  391. this.dy = this.height / (this.ymax - this.ymin);
  392. if (this.calc) {
  393. return this.calc();
  394. }
  395. }
  396. };
  397. Grid.prototype.transY = function (y) {
  398. return this.bottom - (y - this.ymin) * this.dy;
  399. };
  400. Grid.prototype.transX = function (x) {
  401. if (this.data.length === 1) {
  402. return (this.left + this.right) / 2;
  403. } else {
  404. return this.left + (x - this.xmin) * this.dx;
  405. }
  406. };
  407. Grid.prototype.redraw = function () {
  408. this.raphael.clear();
  409. this._calc();
  410. this.drawGrid();
  411. this.drawGoals();
  412. this.drawEvents();
  413. if (this.draw) {
  414. return this.draw();
  415. }
  416. };
  417. Grid.prototype.measureText = function (text, angle) {
  418. var ret, tt;
  419. if (angle == null) {
  420. angle = 0;
  421. }
  422. 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);
  423. ret = tt.getBBox();
  424. tt.remove();
  425. return ret;
  426. };
  427. Grid.prototype.yAxisFormat = function (label) {
  428. return this.yLabelFormat(label);
  429. };
  430. Grid.prototype.yLabelFormat = function (label) {
  431. if (typeof this.options.yLabelFormat === 'function') {
  432. return this.options.yLabelFormat(label);
  433. } else {
  434. return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
  435. }
  436. };
  437. Grid.prototype.updateHover = function (x, y) {
  438. var hit, _ref;
  439. hit = this.hitTest(x, y);
  440. if (hit != null) {
  441. return (_ref = this.hover).update.apply(_ref, hit);
  442. }
  443. };
  444. Grid.prototype.drawGrid = function () {
  445. var lineY, y, _i, _len, _ref, _results;
  446. if (this.options.grid === false && this.options.axes === false) {
  447. return;
  448. }
  449. _ref = this.grid;
  450. _results = [];
  451. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  452. lineY = _ref[_i];
  453. y = this.transY(lineY);
  454. if (this.options.axes) {
  455. this.drawYAxisLabel(this.left - this.options.padding / 2, y, this.yAxisFormat(lineY));
  456. }
  457. if (this.options.grid) {
  458. _results.push(this.drawGridLine("M" + this.left + "," + y + "H" + (this.left + this.width)));
  459. } else {
  460. _results.push(void 0);
  461. }
  462. }
  463. return _results;
  464. };
  465. Grid.prototype.drawGoals = function () {
  466. var color, goal, i, _i, _len, _ref, _results;
  467. _ref = this.options.goals;
  468. _results = [];
  469. for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
  470. goal = _ref[i];
  471. color = this.options.goalLineColors[i % this.options.goalLineColors.length];
  472. _results.push(this.drawGoal(goal, color));
  473. }
  474. return _results;
  475. };
  476. Grid.prototype.drawEvents = function () {
  477. var color, event, i, _i, _len, _ref, _results;
  478. _ref = this.events;
  479. _results = [];
  480. for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
  481. event = _ref[i];
  482. color = this.options.eventLineColors[i % this.options.eventLineColors.length];
  483. _results.push(this.drawEvent(event, color));
  484. }
  485. return _results;
  486. };
  487. Grid.prototype.drawGoal = function (goal, color) {
  488. return this.raphael.path("M" + this.left + "," + (this.transY(goal)) + "H" + this.right).attr('stroke', color).attr('stroke-width', this.options.goalStrokeWidth);
  489. };
  490. Grid.prototype.drawEvent = function (event, color) {
  491. return this.raphael.path("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top).attr('stroke', color).attr('stroke-width', this.options.eventStrokeWidth);
  492. };
  493. Grid.prototype.drawYAxisLabel = function (xPos, yPos, text) {
  494. return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end');
  495. };
  496. Grid.prototype.drawGridLine = function (path) {
  497. return this.raphael.path(path).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth);
  498. };
  499. return Grid;
  500. })(Morris.EventEmitter);
  501. Morris.parseDate = function (date) {
  502. var isecs, m, msecs, n, o, offsetmins, p, q, r, ret, secs;
  503. if (typeof date === 'number') {
  504. return date;
  505. }
  506. m = date.match(/^(\d+) Q(\d)$/);
  507. n = date.match(/^(\d+)-(\d+)$/);
  508. o = date.match(/^(\d+)-(\d+)-(\d+)$/);
  509. p = date.match(/^(\d+) W(\d+)$/);
  510. q = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/);
  511. r = date.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/);
  512. if (m) {
  513. return new Date(parseInt(m[1], 10), parseInt(m[2], 10) * 3 - 1, 1).getTime();
  514. } else if (n) {
  515. return new Date(parseInt(n[1], 10), parseInt(n[2], 10) - 1, 1).getTime();
  516. } else if (o) {
  517. return new Date(parseInt(o[1], 10), parseInt(o[2], 10) - 1, parseInt(o[3], 10)).getTime();
  518. } else if (p) {
  519. ret = new Date(parseInt(p[1], 10), 0, 1);
  520. if (ret.getDay() !== 4) {
  521. ret.setMonth(0, 1 + ((4 - ret.getDay()) + 7) % 7);
  522. }
  523. return ret.getTime() + parseInt(p[2], 10) * 604800000;
  524. } else if (q) {
  525. if (!q[6]) {
  526. 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();
  527. } else {
  528. offsetmins = 0;
  529. if (q[6] !== 'Z') {
  530. offsetmins = parseInt(q[8], 10) * 60 + parseInt(q[9], 10);
  531. if (q[7] === '+') {
  532. offsetmins = 0 - offsetmins;
  533. }
  534. }
  535. 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);
  536. }
  537. } else if (r) {
  538. secs = parseFloat(r[6]);
  539. isecs = Math.floor(secs);
  540. msecs = Math.round((secs - isecs) * 1000);
  541. if (!r[8]) {
  542. 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();
  543. } else {
  544. offsetmins = 0;
  545. if (r[8] !== 'Z') {
  546. offsetmins = parseInt(r[10], 10) * 60 + parseInt(r[11], 10);
  547. if (r[9] === '+') {
  548. offsetmins = 0 - offsetmins;
  549. }
  550. }
  551. 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);
  552. }
  553. } else {
  554. return new Date(parseInt(date, 10), 0, 1).getTime();
  555. }
  556. };
  557. Morris.Hover = (function () {
  558. Hover.defaults = {
  559. "class": 'morris-hover morris-default-style'
  560. };
  561. function Hover(options) {
  562. if (options == null) {
  563. options = {};
  564. }
  565. this.options = $.extend({}, Morris.Hover.defaults, options);
  566. this.el = $("<div class='" + this.options["class"] + "'></div>");
  567. this.el.hide();
  568. this.options.parent.append(this.el);
  569. }
  570. Hover.prototype.update = function (html, x, y) {
  571. this.html(html);
  572. this.show();
  573. return this.moveTo(x, y);
  574. };
  575. Hover.prototype.html = function (content) {
  576. return this.el.html(content);
  577. };
  578. Hover.prototype.moveTo = function (x, y) {
  579. var hoverHeight, hoverWidth, left, parentHeight, parentWidth, top;
  580. parentWidth = this.options.parent.innerWidth();
  581. parentHeight = this.options.parent.innerHeight();
  582. hoverWidth = this.el.outerWidth();
  583. hoverHeight = this.el.outerHeight();
  584. left = Math.min(Math.max(0, x - hoverWidth / 2), parentWidth - hoverWidth);
  585. if (y != null) {
  586. top = y - hoverHeight - 10;
  587. if (top < 0) {
  588. top = y + 10;
  589. if (top + hoverHeight > parentHeight) {
  590. top = parentHeight / 2 - hoverHeight / 2;
  591. }
  592. }
  593. } else {
  594. top = parentHeight / 2 - hoverHeight / 2;
  595. }
  596. return this.el.css({
  597. left: left + "px",
  598. top: parseInt(top) + "px"
  599. });
  600. };
  601. Hover.prototype.show = function () {
  602. return this.el.show();
  603. };
  604. Hover.prototype.hide = function () {
  605. return this.el.hide();
  606. };
  607. return Hover;
  608. })();
  609. Morris.Line = (function (_super) {
  610. __extends(Line, _super);
  611. function Line(options) {
  612. this.hilight = __bind(this.hilight, this);
  613. this.onHoverOut = __bind(this.onHoverOut, this);
  614. this.onHoverMove = __bind(this.onHoverMove, this);
  615. this.onGridClick = __bind(this.onGridClick, this);
  616. if (!(this instanceof Morris.Line)) {
  617. return new Morris.Line(options);
  618. }
  619. Line.__super__.constructor.call(this, options);
  620. }
  621. Line.prototype.init = function () {
  622. this.pointGrow = Raphael.animation({
  623. r: this.options.pointSize + 3
  624. }, 25, 'linear');
  625. this.pointShrink = Raphael.animation({
  626. r: this.options.pointSize
  627. }, 25, 'linear');
  628. if (this.options.hideHover !== 'always') {
  629. this.hover = new Morris.Hover({
  630. parent: this.el
  631. });
  632. this.on('hovermove', this.onHoverMove);
  633. this.on('hoverout', this.onHoverOut);
  634. return this.on('gridclick', this.onGridClick);
  635. }
  636. };
  637. Line.prototype.defaults = {
  638. lineWidth: 3,
  639. pointSize: 4,
  640. lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'],
  641. pointWidths: [1],
  642. pointStrokeColors: ['#ffffff'],
  643. pointFillColors: [],
  644. smooth: true,
  645. xLabels: 'auto',
  646. xLabelFormat: null,
  647. xLabelMargin: 24,
  648. continuousLine: true,
  649. hideHover: false
  650. };
  651. Line.prototype.calc = function () {
  652. this.calcPoints();
  653. return this.generatePaths();
  654. };
  655. Line.prototype.calcPoints = function () {
  656. var row, y, _i, _len, _ref, _results;
  657. _ref = this.data;
  658. _results = [];
  659. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  660. row = _ref[_i];
  661. row._x = this.transX(row.x);
  662. row._y = (function () {
  663. var _j, _len1, _ref1, _results1;
  664. _ref1 = row.y;
  665. _results1 = [];
  666. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  667. y = _ref1[_j];
  668. if (y != null) {
  669. _results1.push(this.transY(y));
  670. } else {
  671. _results1.push(y);
  672. }
  673. }
  674. return _results1;
  675. }).call(this);
  676. _results.push(row._ymax = Math.min.apply(null, [this.bottom].concat((function () {
  677. var _j, _len1, _ref1, _results1;
  678. _ref1 = row._y;
  679. _results1 = [];
  680. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  681. y = _ref1[_j];
  682. if (y != null) {
  683. _results1.push(y);
  684. }
  685. }
  686. return _results1;
  687. })())));
  688. }
  689. return _results;
  690. };
  691. Line.prototype.hitTest = function (x, y) {
  692. var index, r, _i, _len, _ref;
  693. if (this.data.length === 0) {
  694. return null;
  695. }
  696. _ref = this.data.slice(1);
  697. for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
  698. r = _ref[index];
  699. if (x < (r._x + this.data[index]._x) / 2) {
  700. break;
  701. }
  702. }
  703. return index;
  704. };
  705. Line.prototype.onGridClick = function (x, y) {
  706. var index;
  707. index = this.hitTest(x, y);
  708. return this.fire('click', index, this.options.data[index], x, y);
  709. };
  710. Line.prototype.onHoverMove = function (x, y) {
  711. var index;
  712. index = this.hitTest(x, y);
  713. return this.displayHoverForRow(index);
  714. };
  715. Line.prototype.onHoverOut = function () {
  716. if (this.options.hideHover !== false) {
  717. return this.displayHoverForRow(null);
  718. }
  719. };
  720. Line.prototype.displayHoverForRow = function (index) {
  721. var _ref;
  722. if (index != null) {
  723. (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index));
  724. return this.hilight(index);
  725. } else {
  726. this.hover.hide();
  727. return this.hilight();
  728. }
  729. };
  730. Line.prototype.hoverContentForRow = function (index) {
  731. var content, j, row, y, _i, _len, _ref;
  732. row = this.data[index];
  733. content = "<div class='morris-hover-row-label'>" + row.label + "</div>";
  734. _ref = row.y;
  735. for (j = _i = 0, _len = _ref.length; _i < _len; j = ++_i) {
  736. y = _ref[j];
  737. content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";
  738. }
  739. if (typeof this.options.hoverCallback === 'function') {
  740. content = this.options.hoverCallback(index, this.options, content);
  741. }
  742. return [content, row._x, row._ymax];
  743. };
  744. Line.prototype.generatePaths = function () {
  745. var c, coords, i, r, smooth;
  746. return this.paths = (function () {
  747. var _i, _ref, _ref1, _results;
  748. _results = [];
  749. for (i = _i = 0, _ref = this.options.ykeys.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
  750. smooth = this.options.smooth === true || (_ref1 = this.options.ykeys[i], __indexOf.call(this.options.smooth, _ref1) >= 0);
  751. coords = (function () {
  752. var _j, _len, _ref2, _results1;
  753. _ref2 = this.data;
  754. _results1 = [];
  755. for (_j = 0, _len = _ref2.length; _j < _len; _j++) {
  756. r = _ref2[_j];
  757. if (r._y[i] !== void 0) {
  758. _results1.push({
  759. x: r._x,
  760. y: r._y[i]
  761. });
  762. }
  763. }
  764. return _results1;
  765. }).call(this);
  766. if (this.options.continuousLine) {
  767. coords = (function () {
  768. var _j, _len, _results1;
  769. _results1 = [];
  770. for (_j = 0, _len = coords.length; _j < _len; _j++) {
  771. c = coords[_j];
  772. if (c.y !== null) {
  773. _results1.push(c);
  774. }
  775. }
  776. return _results1;
  777. })();
  778. }
  779. if (coords.length > 1) {
  780. _results.push(Morris.Line.createPath(coords, smooth, this.bottom));
  781. } else {
  782. _results.push(null);
  783. }
  784. }
  785. return _results;
  786. }).call(this);
  787. };
  788. Line.prototype.draw = function () {
  789. if (this.options.axes) {
  790. this.drawXAxis();
  791. }
  792. this.drawSeries();
  793. if (this.options.hideHover === false) {
  794. return this.displayHoverForRow(this.data.length - 1);
  795. }
  796. };
  797. Line.prototype.drawXAxis = function () {
  798. var drawLabel, l, labels, prevAngleMargin, prevLabelMargin, row, ypos, _i, _len, _results,
  799. _this = this;
  800. ypos = this.bottom + this.options.padding / 2;
  801. prevLabelMargin = null;
  802. prevAngleMargin = null;
  803. drawLabel = function (labelText, xpos) {
  804. var label, labelBox, margin, offset, textBox;
  805. label = _this.drawXAxisLabel(_this.transX(xpos), ypos, labelText);
  806. textBox = label.getBBox();
  807. label.transform("r" + (-_this.options.xLabelAngle));
  808. labelBox = label.getBBox();
  809. label.transform("t0," + (labelBox.height / 2) + "...");
  810. if (_this.options.xLabelAngle !== 0) {
  811. offset = -0.5 * textBox.width * Math.cos(_this.options.xLabelAngle * Math.PI / 180.0);
  812. label.transform("t" + offset + ",0...");
  813. }
  814. labelBox = label.getBBox();
  815. if ((!(prevLabelMargin != null) || prevLabelMargin >= labelBox.x + labelBox.width || (prevAngleMargin != null) && prevAngleMargin >= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {
  816. if (_this.options.xLabelAngle !== 0) {
  817. margin = 1.25 * _this.options.gridTextSize / Math.sin(_this.options.xLabelAngle * Math.PI / 180.0);
  818. prevAngleMargin = labelBox.x - margin;
  819. }
  820. return prevLabelMargin = labelBox.x - _this.options.xLabelMargin;
  821. } else {
  822. return label.remove();
  823. }
  824. };
  825. if (this.options.parseTime) {
  826. if (this.data.length === 1 && this.options.xLabels === 'auto') {
  827. labels = [[this.data[0].label, this.data[0].x]];
  828. } else {
  829. labels = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat);
  830. }
  831. } else {
  832. labels = (function () {
  833. var _i, _len, _ref, _results;
  834. _ref = this.data;
  835. _results = [];
  836. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  837. row = _ref[_i];
  838. _results.push([row.label, row.x]);
  839. }
  840. return _results;
  841. }).call(this);
  842. }
  843. labels.reverse();
  844. _results = [];
  845. for (_i = 0, _len = labels.length; _i < _len; _i++) {
  846. l = labels[_i];
  847. _results.push(drawLabel(l[0], l[1]));
  848. }
  849. return _results;
  850. };
  851. Line.prototype.drawSeries = function () {
  852. var i, _i, _j, _ref, _ref1, _results;
  853. this.seriesPoints = [];
  854. for (i = _i = _ref = this.options.ykeys.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) {
  855. this._drawLineFor(i);
  856. }
  857. _results = [];
  858. for (i = _j = _ref1 = this.options.ykeys.length - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {
  859. _results.push(this._drawPointFor(i));
  860. }
  861. return _results;
  862. };
  863. Line.prototype._drawPointFor = function (index) {
  864. var circle, row, _i, _len, _ref, _results;
  865. this.seriesPoints[index] = [];
  866. _ref = this.data;
  867. _results = [];
  868. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  869. row = _ref[_i];
  870. circle = null;
  871. if (row._y[index] != null) {
  872. circle = this.drawLinePoint(row._x, row._y[index], this.options.pointSize, this.colorFor(row, index, 'point'), index);
  873. }
  874. _results.push(this.seriesPoints[index].push(circle));
  875. }
  876. return _results;
  877. };
  878. Line.prototype._drawLineFor = function (index) {
  879. var path;
  880. path = this.paths[index];
  881. if (path !== null) {
  882. return this.drawLinePath(path, this.colorFor(null, index, 'line'));
  883. }
  884. };
  885. Line.createPath = function (coords, smooth, bottom) {
  886. var coord, g, grads, i, ix, lg, path, prevCoord, x1, x2, y1, y2, _i, _len;
  887. path = "";
  888. if (smooth) {
  889. grads = Morris.Line.gradients(coords);
  890. }
  891. prevCoord = {
  892. y: null
  893. };
  894. for (i = _i = 0, _len = coords.length; _i < _len; i = ++_i) {
  895. coord = coords[i];
  896. if (coord.y != null) {
  897. if (prevCoord.y != null) {
  898. if (smooth) {
  899. g = grads[i];
  900. lg = grads[i - 1];
  901. ix = (coord.x - prevCoord.x) / 4;
  902. x1 = prevCoord.x + ix;
  903. y1 = Math.min(bottom, prevCoord.y + ix * lg);
  904. x2 = coord.x - ix;
  905. y2 = Math.min(bottom, coord.y - ix * g);
  906. path += "C" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + coord.x + "," + coord.y;
  907. } else {
  908. path += "L" + coord.x + "," + coord.y;
  909. }
  910. } else {
  911. if (!smooth || (grads[i] != null)) {
  912. path += "M" + coord.x + "," + coord.y;
  913. }
  914. }
  915. }
  916. prevCoord = coord;
  917. }
  918. return path;
  919. };
  920. Line.gradients = function (coords) {
  921. var coord, grad, i, nextCoord, prevCoord, _i, _len, _results;
  922. grad = function (a, b) {
  923. return (a.y - b.y) / (a.x - b.x);
  924. };
  925. _results = [];
  926. for (i = _i = 0, _len = coords.length; _i < _len; i = ++_i) {
  927. coord = coords[i];
  928. if (coord.y != null) {
  929. nextCoord = coords[i + 1] || {
  930. y: null
  931. };
  932. prevCoord = coords[i - 1] || {
  933. y: null
  934. };
  935. if ((prevCoord.y != null) && (nextCoord.y != null)) {
  936. _results.push(grad(prevCoord, nextCoord));
  937. } else if (prevCoord.y != null) {
  938. _results.push(grad(prevCoord, coord));
  939. } else if (nextCoord.y != null) {
  940. _results.push(grad(coord, nextCoord));
  941. } else {
  942. _results.push(null);
  943. }
  944. } else {
  945. _results.push(null);
  946. }
  947. }
  948. return _results;
  949. };
  950. Line.prototype.hilight = function (index) {
  951. var i, _i, _j, _ref, _ref1;
  952. if (this.prevHilight !== null && this.prevHilight !== index) {
  953. for (i = _i = 0, _ref = this.seriesPoints.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
  954. if (this.seriesPoints[i][this.prevHilight]) {
  955. this.seriesPoints[i][this.prevHilight].animate(this.pointShrink);
  956. }
  957. }
  958. }
  959. if (index !== null && this.prevHilight !== index) {
  960. for (i = _j = 0, _ref1 = this.seriesPoints.length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
  961. if (this.seriesPoints[i][index]) {
  962. this.seriesPoints[i][index].animate(this.pointGrow);
  963. }
  964. }
  965. }
  966. return this.prevHilight = index;
  967. };
  968. Line.prototype.colorFor = function (row, sidx, type) {
  969. if (typeof this.options.lineColors === 'function') {
  970. return this.options.lineColors.call(this, row, sidx, type);
  971. } else if (type === 'point') {
  972. return this.options.pointFillColors[sidx % this.options.pointFillColors.length] || this.options.lineColors[sidx % this.options.lineColors.length];
  973. } else {
  974. return this.options.lineColors[sidx % this.options.lineColors.length];
  975. }
  976. };
  977. Line.prototype.drawXAxisLabel = function (xPos, yPos, text) {
  978. 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);
  979. };
  980. Line.prototype.drawLinePath = function (path, lineColor) {
  981. return this.raphael.path(path).attr('stroke', lineColor).attr('stroke-width', this.options.lineWidth);
  982. };
  983. Line.prototype.drawLinePoint = function (xPos, yPos, size, pointColor, lineIndex) {
  984. return this.raphael.circle(xPos, yPos, size).attr('fill', pointColor).attr('stroke-width', this.strokeWidthForSeries(lineIndex)).attr('stroke', this.strokeForSeries(lineIndex));
  985. };
  986. Line.prototype.strokeWidthForSeries = function (index) {
  987. return this.options.pointWidths[index % this.options.pointWidths.length];
  988. };
  989. Line.prototype.strokeForSeries = function (index) {
  990. return this.options.pointStrokeColors[index % this.options.pointStrokeColors.length];
  991. };
  992. return Line;
  993. })(Morris.Grid);
  994. Morris.labelSeries = function (dmin, dmax, pxwidth, specName, xLabelFormat) {
  995. var d, d0, ddensity, name, ret, s, spec, t, _i, _len, _ref;
  996. ddensity = 200 * (dmax - dmin) / pxwidth;
  997. d0 = new Date(dmin);
  998. spec = Morris.LABEL_SPECS[specName];
  999. if (spec === void 0) {
  1000. _ref = Morris.AUTO_LABEL_ORDER;
  1001. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1002. name = _ref[_i];
  1003. s = Morris.LABEL_SPECS[name];
  1004. if (ddensity >= s.span) {
  1005. spec = s;
  1006. break;
  1007. }
  1008. }
  1009. }
  1010. if (spec === void 0) {
  1011. spec = Morris.LABEL_SPECS["second"];
  1012. }
  1013. if (xLabelFormat) {
  1014. spec = $.extend({}, spec, {
  1015. fmt: xLabelFormat
  1016. });
  1017. }
  1018. d = spec.start(d0);
  1019. ret = [];
  1020. while ((t = d.getTime()) <= dmax) {
  1021. if (t >= dmin) {
  1022. ret.push([spec.fmt(d), t]);
  1023. }
  1024. spec.incr(d);
  1025. }
  1026. return ret;
  1027. };
  1028. minutesSpecHelper = function (interval) {
  1029. return {
  1030. span: interval * 60 * 1000,
  1031. start: function (d) {
  1032. return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours());
  1033. },
  1034. fmt: function (d) {
  1035. return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes()));
  1036. },
  1037. incr: function (d) {
  1038. return d.setUTCMinutes(d.getUTCMinutes() + interval);
  1039. }
  1040. };
  1041. };
  1042. secondsSpecHelper = function (interval) {
  1043. return {
  1044. span: interval * 1000,
  1045. start: function (d) {
  1046. return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes());
  1047. },
  1048. fmt: function (d) {
  1049. return "" + (Morris.pad2(d.getHours())) + ":" + (Morris.pad2(d.getMinutes())) + ":" + (Morris.pad2(d.getSeconds()));
  1050. },
  1051. incr: function (d) {
  1052. return d.setUTCSeconds(d.getUTCSeconds() + interval);
  1053. }
  1054. };
  1055. };
  1056. Morris.LABEL_SPECS = {
  1057. "decade": {
  1058. span: 172800000000,
  1059. start: function (d) {
  1060. return new Date(d.getFullYear() - d.getFullYear() % 10, 0, 1);
  1061. },
  1062. fmt: function (d) {
  1063. return "" + (d.getFullYear());
  1064. },
  1065. incr: function (d) {
  1066. return d.setFullYear(d.getFullYear() + 10);
  1067. }
  1068. },
  1069. "year": {
  1070. span: 17280000000,
  1071. start: function (d) {
  1072. return new Date(d.getFullYear(), 0, 1);
  1073. },
  1074. fmt: function (d) {
  1075. return "" + (d.getFullYear());
  1076. },
  1077. incr: function (d) {
  1078. return d.setFullYear(d.getFullYear() + 1);
  1079. }
  1080. },
  1081. "month": {
  1082. span: 2419200000,
  1083. start: function (d) {
  1084. return new Date(d.getFullYear(), d.getMonth(), 1);
  1085. },
  1086. fmt: function (d) {
  1087. return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1));
  1088. },
  1089. incr: function (d) {
  1090. return d.setMonth(d.getMonth() + 1);
  1091. }
  1092. },
  1093. "day": {
  1094. span: 86400000,
  1095. start: function (d) {
  1096. return new Date(d.getFullYear(), d.getMonth(), d.getDate());
  1097. },
  1098. fmt: function (d) {
  1099. return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate()));
  1100. },
  1101. incr: function (d) {
  1102. return d.setDate(d.getDate() + 1);
  1103. }
  1104. },
  1105. "hour": minutesSpecHelper(60),
  1106. "30min": minutesSpecHelper(30),
  1107. "15min": minutesSpecHelper(15),
  1108. "10min": minutesSpecHelper(10),
  1109. "5min": minutesSpecHelper(5),
  1110. "minute": minutesSpecHelper(1),
  1111. "30sec": secondsSpecHelper(30),
  1112. "15sec": secondsSpecHelper(15),
  1113. "10sec": secondsSpecHelper(10),
  1114. "5sec": secondsSpecHelper(5),
  1115. "second": secondsSpecHelper(1)
  1116. };
  1117. Morris.AUTO_LABEL_ORDER = ["decade", "year", "month", "day", "hour", "30min", "15min", "10min", "5min", "minute", "30sec", "15sec", "10sec", "5sec", "second"];
  1118. Morris.Area = (function (_super) {
  1119. var areaDefaults;
  1120. __extends(Area, _super);
  1121. areaDefaults = {
  1122. fillOpacity: 'auto',
  1123. behaveLikeLine: false
  1124. };
  1125. function Area(options) {
  1126. var areaOptions;
  1127. if (!(this instanceof Morris.Area)) {
  1128. return new Morris.Area(options);
  1129. }
  1130. areaOptions = $.extend({}, areaDefaults, options);
  1131. this.cumulative = !areaOptions.behaveLikeLine;
  1132. if (areaOptions.fillOpacity === 'auto') {
  1133. areaOptions.fillOpacity = areaOptions.behaveLikeLine ? .8 : 1;
  1134. }
  1135. Area.__super__.constructor.call(this, areaOptions);
  1136. }
  1137. Area.prototype.calcPoints = function () {
  1138. var row, total, y, _i, _len, _ref, _results;
  1139. _ref = this.data;
  1140. _results = [];
  1141. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1142. row = _ref[_i];
  1143. row._x = this.transX(row.x);
  1144. total = 0;
  1145. row._y = (function () {
  1146. var _j, _len1, _ref1, _results1;
  1147. _ref1 = row.y;
  1148. _results1 = [];
  1149. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  1150. y = _ref1[_j];
  1151. if (this.options.behaveLikeLine) {
  1152. _results1.push(this.transY(y));
  1153. } else {
  1154. total += y || 0;
  1155. _results1.push(this.transY(total));
  1156. }
  1157. }
  1158. return _results1;
  1159. }).call(this);
  1160. _results.push(row._ymax = Math.max.apply(Math, row._y));
  1161. }
  1162. return _results;
  1163. };
  1164. Area.prototype.drawSeries = function () {
  1165. var i, range, _i, _j, _k, _len, _ref, _ref1, _results, _results1, _results2;
  1166. this.seriesPoints = [];
  1167. if (this.options.behaveLikeLine) {
  1168. range = (function () {
  1169. _results = [];
  1170. for (var _i = 0, _ref = this.options.ykeys.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--) {
  1171. _results.push(_i);
  1172. }
  1173. return _results;
  1174. }).apply(this);
  1175. } else {
  1176. range = (function () {
  1177. _results1 = [];
  1178. for (var _j = _ref1 = this.options.ykeys.length - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; _ref1 <= 0 ? _j++ : _j--) {
  1179. _results1.push(_j);
  1180. }
  1181. return _results1;
  1182. }).apply(this);
  1183. }
  1184. _results2 = [];
  1185. for (_k = 0, _len = range.length; _k < _len; _k++) {
  1186. i = range[_k];
  1187. this._drawFillFor(i);
  1188. this._drawLineFor(i);
  1189. _results2.push(this._drawPointFor(i));
  1190. }
  1191. return _results2;
  1192. };
  1193. Area.prototype._drawFillFor = function (index) {
  1194. var path;
  1195. path = this.paths[index];
  1196. if (path !== null) {
  1197. path = path + ("L" + (this.transX(this.xmax)) + "," + this.bottom + "L" + (this.transX(this.xmin)) + "," + this.bottom + "Z");
  1198. return this.drawFilledPath(path, this.fillForSeries(index));
  1199. }
  1200. };
  1201. Area.prototype.fillForSeries = function (i) {
  1202. var color;
  1203. color = Raphael.rgb2hsl(this.colorFor(this.data[i], i, 'line'));
  1204. 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));
  1205. };
  1206. Area.prototype.drawFilledPath = function (path, fill) {
  1207. return this.raphael.path(path).attr('fill', fill).attr('fill-opacity', this.options.fillOpacity).attr('stroke-width', 0);
  1208. };
  1209. return Area;
  1210. })(Morris.Line);
  1211. Morris.Bar = (function (_super) {
  1212. __extends(Bar, _super);
  1213. function Bar(options) {
  1214. this.onHoverOut = __bind(this.onHoverOut, this);
  1215. this.onHoverMove = __bind(this.onHoverMove, this);
  1216. this.onGridClick = __bind(this.onGridClick, this);
  1217. if (!(this instanceof Morris.Bar)) {
  1218. return new Morris.Bar(options);
  1219. }
  1220. Bar.__super__.constructor.call(this, $.extend({}, options, {
  1221. parseTime: false
  1222. }));
  1223. }
  1224. Bar.prototype.init = function () {
  1225. this.cumulative = this.options.stacked;
  1226. if (this.options.hideHover !== 'always') {
  1227. this.hover = new Morris.Hover({
  1228. parent: this.el
  1229. });
  1230. this.on('hovermove', this.onHoverMove);
  1231. this.on('hoverout', this.onHoverOut);
  1232. return this.on('gridclick', this.onGridClick);
  1233. }
  1234. };
  1235. Bar.prototype.defaults = {
  1236. barSizeRatio: 0.75,
  1237. barGap: 3,
  1238. barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'],
  1239. xLabelMargin: 50
  1240. };
  1241. Bar.prototype.calc = function () {
  1242. var _ref;
  1243. this.calcBars();
  1244. if (this.options.hideHover === false) {
  1245. return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(this.data.length - 1));
  1246. }
  1247. };
  1248. Bar.prototype.calcBars = function () {
  1249. var idx, row, y, _i, _len, _ref, _results;
  1250. _ref = this.data;
  1251. _results = [];
  1252. for (idx = _i = 0, _len = _ref.length; _i < _len; idx = ++_i) {
  1253. row = _ref[idx];
  1254. row._x = this.left + this.width * (idx + 0.5) / this.data.length;
  1255. _results.push(row._y = (function () {
  1256. var _j, _len1, _ref1, _results1;
  1257. _ref1 = row.y;
  1258. _results1 = [];
  1259. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  1260. y = _ref1[_j];
  1261. if (y != null) {
  1262. _results1.push(this.transY(y));
  1263. } else {
  1264. _results1.push(null);
  1265. }
  1266. }
  1267. return _results1;
  1268. }).call(this));
  1269. }
  1270. return _results;
  1271. };
  1272. Bar.prototype.draw = function () {
  1273. if (this.options.axes) {
  1274. this.drawXAxis();
  1275. }
  1276. return this.drawSeries();
  1277. };
  1278. Bar.prototype.drawXAxis = function () {
  1279. var i, label, labelBox, margin, offset, prevAngleMargin, prevLabelMargin, row, textBox, ypos, _i, _ref, _results;
  1280. ypos = this.bottom + this.options.padding / 2;
  1281. prevLabelMargin = null;
  1282. prevAngleMargin = null;
  1283. _results = [];
  1284. for (i = _i = 0, _ref = this.data.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
  1285. row = this.data[this.data.length - 1 - i];
  1286. label = this.drawXAxisLabel(row._x, ypos, row.label);
  1287. textBox = label.getBBox();
  1288. label.transform("r" + (-this.options.xLabelAngle));
  1289. labelBox = label.getBBox();
  1290. label.transform("t0," + (labelBox.height / 2) + "...");
  1291. if (this.options.xLabelAngle !== 0) {
  1292. offset = -0.5 * textBox.width * Math.cos(this.options.xLabelAngle * Math.PI / 180.0);
  1293. label.transform("t" + offset + ",0...");
  1294. }
  1295. if ((!(prevLabelMargin != null) || prevLabelMargin >= labelBox.x + labelBox.width || (prevAngleMargin != null) && prevAngleMargin >= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < this.el.width()) {
  1296. if (this.options.xLabelAngle !== 0) {
  1297. margin = 1.25 * this.options.gridTextSize / Math.sin(this.options.xLabelAngle * Math.PI / 180.0);
  1298. prevAngleMargin = labelBox.x - margin;
  1299. }
  1300. _results.push(prevLabelMargin = labelBox.x - this.options.xLabelMargin);
  1301. } else {
  1302. _results.push(label.remove());
  1303. }
  1304. }
  1305. return _results;
  1306. };
  1307. Bar.prototype.drawSeries = function () {
  1308. var barWidth, bottom, groupWidth, idx, lastTop, left, leftPadding, numBars, row, sidx, size, top, ypos, zeroPos;
  1309. groupWidth = this.width / this.options.data.length;
  1310. numBars = this.options.stacked != null ? 1 : this.options.ykeys.length;
  1311. barWidth = (groupWidth * this.options.barSizeRatio - this.options.barGap * (numBars - 1)) / numBars;
  1312. leftPadding = groupWidth * (1 - this.options.barSizeRatio) / 2;
  1313. zeroPos = this.ymin <= 0 && this.ymax >= 0 ? this.transY(0) : null;
  1314. return this.bars = (function () {
  1315. var _i, _len, _ref, _results;
  1316. _ref = this.data;
  1317. _results = [];
  1318. for (idx = _i = 0, _len = _ref.length; _i < _len; idx = ++_i) {
  1319. row = _ref[idx];
  1320. lastTop = 0;
  1321. _results.push((function () {
  1322. var _j, _len1, _ref1, _results1;
  1323. _ref1 = row._y;
  1324. _results1 = [];
  1325. for (sidx = _j = 0, _len1 = _ref1.length; _j < _len1; sidx = ++_j) {
  1326. ypos = _ref1[sidx];
  1327. if (ypos !== null) {
  1328. if (zeroPos) {
  1329. top = Math.min(ypos, zeroPos);
  1330. bottom = Math.max(ypos, zeroPos);
  1331. } else {
  1332. top = ypos;
  1333. bottom = this.bottom;
  1334. }
  1335. left = this.left + idx * groupWidth + leftPadding;
  1336. if (!this.options.stacked) {
  1337. left += sidx * (barWidth + this.options.barGap);
  1338. }
  1339. size = bottom - top;
  1340. if (this.options.stacked) {
  1341. top -= lastTop;
  1342. }
  1343. this.drawBar(left, top, barWidth, size, this.colorFor(row, sidx, 'bar'));
  1344. _results1.push(lastTop += size);
  1345. } else {
  1346. _results1.push(null);
  1347. }
  1348. }
  1349. return _results1;
  1350. }).call(this));
  1351. }
  1352. return _results;
  1353. }).call(this);
  1354. };
  1355. Bar.prototype.colorFor = function (row, sidx, type) {
  1356. var r, s;
  1357. if (typeof this.options.barColors === 'function') {
  1358. r = {
  1359. x: row.x,
  1360. y: row.y[sidx],
  1361. label: row.label
  1362. };
  1363. s = {
  1364. index: sidx,
  1365. key: this.options.ykeys[sidx],
  1366. label: this.options.labels[sidx]
  1367. };
  1368. return this.options.barColors.call(this, r, s, type);
  1369. } else {
  1370. return this.options.barColors[sidx % this.options.barColors.length];
  1371. }
  1372. };
  1373. Bar.prototype.hitTest = function (x, y) {
  1374. if (this.data.length === 0) {
  1375. return null;
  1376. }
  1377. x = Math.max(Math.min(x, this.right), this.left);
  1378. return Math.min(this.data.length - 1, Math.floor((x - this.left) / (this.width / this.data.length)));
  1379. };
  1380. Bar.prototype.onGridClick = function (x, y) {
  1381. var index;
  1382. index = this.hitTest(x, y);
  1383. return this.fire('click', index, this.options.data[index], x, y);
  1384. };
  1385. Bar.prototype.onHoverMove = function (x, y) {
  1386. var index, _ref;
  1387. index = this.hitTest(x, y);
  1388. return (_ref = this.hover).update.apply(_ref, this.hoverContentForRow(index));
  1389. };
  1390. Bar.prototype.onHoverOut = function () {
  1391. if (this.options.hideHover !== false) {
  1392. return this.hover.hide();
  1393. }
  1394. };
  1395. Bar.prototype.hoverContentForRow = function (index) {
  1396. var content, j, row, x, y, _i, _len, _ref;
  1397. row = this.data[index];
  1398. content = "<div class='morris-hover-row-label'>" + row.label + "</div>";
  1399. _ref = row.y;
  1400. for (j = _i = 0, _len = _ref.length; _i < _len; j = ++_i) {
  1401. y = _ref[j];
  1402. content += "<div class='morris-hover-point' style='color: " + (this.colorFor(row, j, 'label')) + "'>\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y)) + "\n</div>";
  1403. }
  1404. if (typeof this.options.hoverCallback === 'function') {
  1405. content = this.options.hoverCallback(index, this.options, content);
  1406. }
  1407. x = this.left + (index + 0.5) * this.width / this.data.length;
  1408. return [content, x];
  1409. };
  1410. Bar.prototype.drawXAxisLabel = function (xPos, yPos, text) {
  1411. var label;
  1412. return label = this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor);
  1413. };
  1414. Bar.prototype.drawBar = function (xPos, yPos, width, height, barColor) {
  1415. return this.raphael.rect(xPos, yPos, width, height).attr('fill', barColor).attr('stroke-width', 0);
  1416. };
  1417. return Bar;
  1418. })(Morris.Grid);
  1419. Morris.Donut = (function (_super) {
  1420. __extends(Donut, _super);
  1421. Donut.prototype.defaults = {
  1422. colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],
  1423. backgroundColor: '#FFFFFF',
  1424. labelColor: '#000000',
  1425. formatter: Morris.commas
  1426. };
  1427. function Donut(options) {
  1428. this.select = __bind(this.select, this);
  1429. this.click = __bind(this.click, this);
  1430. var row;
  1431. if (!(this instanceof Morris.Donut)) {
  1432. return new Morris.Donut(options);
  1433. }
  1434. if (typeof options.element === 'string') {
  1435. this.el = $(document.getElementById(options.element));
  1436. } else {
  1437. this.el = $(options.element);
  1438. }
  1439. this.options = $.extend({}, this.defaults, options);
  1440. if (this.el === null || this.el.length === 0) {
  1441. throw new Error("Graph placeholder not found.");
  1442. }
  1443. if (options.data === void 0 || options.data.length === 0) {
  1444. return;
  1445. }
  1446. this.data = options.data;
  1447. this.values = (function () {
  1448. var _i, _len, _ref, _results;
  1449. _ref = this.data;
  1450. _results = [];
  1451. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1452. row = _ref[_i];
  1453. _results.push(parseFloat(row.value));
  1454. }
  1455. return _results;
  1456. }).call(this);
  1457. this.redraw();
  1458. }
  1459. Donut.prototype.redraw = function () {
  1460. var C, cx, cy, i, idx, last, max_value, min, next, seg, total, value, w, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;
  1461. this.el.empty();
  1462. this.raphael = new Raphael(this.el[0]);
  1463. cx = this.el.width() / 2;
  1464. cy = this.el.height() / 2;
  1465. w = (Math.min(cx, cy) - 10) / 3;
  1466. total = 0;
  1467. _ref = this.values;
  1468. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1469. value = _ref[_i];
  1470. total += value;
  1471. }
  1472. min = 5 / (2 * w);
  1473. C = 1.9999 * Math.PI - min * this.data.length;
  1474. last = 0;
  1475. idx = 0;
  1476. this.segments = [];
  1477. _ref1 = this.values;
  1478. for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) {
  1479. value = _ref1[i];
  1480. next = last + min + C * (value / total);
  1481. seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.options.colors[idx % this.options.colors.length], this.options.backgroundColor, idx, this.raphael);
  1482. seg.render();
  1483. this.segments.push(seg);
  1484. seg.on('hover', this.select);
  1485. seg.on('click', this.click);
  1486. last = next;
  1487. idx += 1;
  1488. }
  1489. this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, this.options.labelColor, 15, 800);
  1490. this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, this.options.labelColor, 14);
  1491. max_value = Math.max.apply(null, (function () {
  1492. var _k, _len2, _ref2, _results;
  1493. _ref2 = this.values;
  1494. _results = [];
  1495. for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
  1496. value = _ref2[_k];
  1497. _results.push(value);
  1498. }
  1499. return _results;
  1500. }).call(this));
  1501. idx = 0;
  1502. _ref2 = this.values;
  1503. _results = [];
  1504. for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
  1505. value = _ref2[_k];
  1506. if (value === max_value) {
  1507. this.select(idx);
  1508. break;
  1509. }
  1510. _results.push(idx += 1);
  1511. }
  1512. return _results;
  1513. };
  1514. Donut.prototype.click = function (idx) {
  1515. return this.fire('click', idx, this.data[idx]);
  1516. };
  1517. Donut.prototype.select = function (idx) {
  1518. var row, s, segment, _i, _len, _ref;
  1519. _ref = this.segments;
  1520. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1521. s = _ref[_i];
  1522. s.deselect();
  1523. }
  1524. segment = this.segments[idx];
  1525. segment.select();
  1526. row = this.data[idx];
  1527. return this.setLabels(row.label, this.options.formatter(row.value, row));
  1528. };
  1529. Donut.prototype.setLabels = function (label1, label2) {
  1530. var inner, maxHeightBottom, maxHeightTop, maxWidth, text1bbox, text1scale, text2bbox, text2scale;
  1531. inner = (Math.min(this.el.width() / 2, this.el.height() / 2) - 10) * 2 / 3;
  1532. maxWidth = 1.8 * inner;
  1533. maxHeightTop = inner / 2;
  1534. maxHeightBottom = inner / 3;
  1535. this.text1.attr({
  1536. text: label1,
  1537. transform: ''
  1538. });
  1539. text1bbox = this.text1.getBBox();
  1540. text1scale = Math.min(maxWidth / text1bbox.width, maxHeightTop / text1bbox.height);
  1541. this.text1.attr({
  1542. transform: "S" + text1scale + "," + text1scale + "," + (text1bbox.x + text1bbox.width / 2) + "," + (text1bbox.y + text1bbox.height)
  1543. });
  1544. this.text2.attr({
  1545. text: label2,
  1546. transform: ''
  1547. });
  1548. text2bbox = this.text2.getBBox();
  1549. text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height);
  1550. return this.text2.attr({
  1551. transform: "S" + text2scale + "," + text2scale + "," + (text2bbox.x + text2bbox.width / 2) + "," + text2bbox.y
  1552. });
  1553. };
  1554. Donut.prototype.drawEmptyDonutLabel = function (xPos, yPos, color, fontSize, fontWeight) {
  1555. var text;
  1556. text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize).attr('fill', color);
  1557. if (fontWeight != null) {
  1558. text.attr('font-weight', fontWeight);
  1559. }
  1560. return text;
  1561. };
  1562. return Donut;
  1563. })(Morris.EventEmitter);
  1564. Morris.DonutSegment = (function (_super) {
  1565. __extends(DonutSegment, _super);
  1566. function DonutSegment(cx, cy, inner, outer, p0, p1, color, backgroundColor, index, raphael) {
  1567. this.cx = cx;
  1568. this.cy = cy;
  1569. this.inner = inner;
  1570. this.outer = outer;
  1571. this.color = color;
  1572. this.backgroundColor = backgroundColor;
  1573. this.index = index;
  1574. this.raphael = raphael;
  1575. this.deselect = __bind(this.deselect, this);
  1576. this.select = __bind(this.select, this);
  1577. this.sin_p0 = Math.sin(p0);
  1578. this.cos_p0 = Math.cos(p0);
  1579. this.sin_p1 = Math.sin(p1);
  1580. this.cos_p1 = Math.cos(p1);
  1581. this.is_long = (p1 - p0) > Math.PI ? 1 : 0;
  1582. this.path = this.calcSegment(this.inner + 3, this.inner + this.outer - 5);
  1583. this.selectedPath = this.calcSegment(this.inner + 3, this.inner + this.outer);
  1584. this.hilight = this.calcArc(this.inner);
  1585. }
  1586. DonutSegment.prototype.calcArcPoints = function (r) {
  1587. 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];
  1588. };
  1589. DonutSegment.prototype.calcSegment = function (r1, r2) {
  1590. var ix0, ix1, iy0, iy1, ox0, ox1, oy0, oy1, _ref, _ref1;
  1591. _ref = this.calcArcPoints(r1), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
  1592. _ref1 = this.calcArcPoints(r2), ox0 = _ref1[0], oy0 = _ref1[1], ox1 = _ref1[2], oy1 = _ref1[3];
  1593. 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";
  1594. };
  1595. DonutSegment.prototype.calcArc = function (r) {
  1596. var ix0, ix1, iy0, iy1, _ref;
  1597. _ref = this.calcArcPoints(r), ix0 = _ref[0], iy0 = _ref[1], ix1 = _ref[2], iy1 = _ref[3];
  1598. return ("M" + ix0 + "," + iy0) + ("A" + r + "," + r + ",0," + this.is_long + ",0," + ix1 + "," + iy1);
  1599. };
  1600. DonutSegment.prototype.render = function () {
  1601. var _this = this;
  1602. this.arc = this.drawDonutArc(this.hilight, this.color);
  1603. return this.seg = this.drawDonutSegment(this.path, this.color, this.backgroundColor, function () {
  1604. return _this.fire('hover', _this.index);
  1605. }, function () {
  1606. return _this.fire('click', _this.index);
  1607. });
  1608. };
  1609. DonutSegment.prototype.drawDonutArc = function (path, color) {
  1610. return this.raphael.path(path).attr({
  1611. stroke: color,
  1612. 'stroke-width': 2,
  1613. opacity: 0
  1614. });
  1615. };
  1616. DonutSegment.prototype.drawDonutSegment = function (path, fillColor, strokeColor, hoverFunction, clickFunction) {
  1617. return this.raphael.path(path).attr({
  1618. fill: fillColor,
  1619. stroke: strokeColor,
  1620. 'stroke-width': 3
  1621. }).hover(hoverFunction).click(clickFunction);
  1622. };
  1623. DonutSegment.prototype.select = function () {
  1624. if (!this.selected) {
  1625. this.seg.animate({
  1626. path: this.selectedPath
  1627. }, 150, '<>');
  1628. this.arc.animate({
  1629. opacity: 1
  1630. }, 150, '<>');
  1631. return this.selected = true;
  1632. }
  1633. };
  1634. DonutSegment.prototype.deselect = function () {
  1635. if (this.selected) {
  1636. this.seg.animate({
  1637. path: this.path
  1638. }, 150, '<>');
  1639. this.arc.animate({
  1640. opacity: 0
  1641. }, 150, '<>');
  1642. return this.selected = false;
  1643. }
  1644. };
  1645. return DonutSegment;
  1646. })(Morris.EventEmitter);
  1647. }).call(this);