tienda 2.0.1 → 2.0.2

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