character 0.1.0 → 1.0.0

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