morrisjs-rails 0.4.0 → 0.4.1

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,5 +1,5 @@
1
1
  module Morrisjs
2
2
  module Rails
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -81,9 +81,6 @@
81
81
  this.el.css('position', 'relative');
82
82
  }
83
83
  this.options = $.extend({}, this.gridDefaults, this.defaults || {}, options);
84
- if (this.options.data === void 0 || this.options.data.length === 0) {
85
- return;
86
- }
87
84
  if (typeof this.options.units === 'string') {
88
85
  this.options.postUnits = options.units;
89
86
  }
@@ -145,6 +142,14 @@
145
142
  if (redraw == null) {
146
143
  redraw = true;
147
144
  }
145
+ if (!(data != null) || data.length === 0) {
146
+ this.data = [];
147
+ this.raphael.clear();
148
+ if (this.hover != null) {
149
+ this.hover.hide();
150
+ }
151
+ return;
152
+ }
148
153
  ymax = this.cumulative ? 0 : null;
149
154
  ymin = this.cumulative ? 0 : null;
150
155
  if (this.options.goals.length > 0) {
@@ -330,26 +335,35 @@
330
335
  }
331
336
  };
332
337
 
333
- Grid.prototype.drawGoals = function() {
334
- var goal, i, _i, _len, _ref, _results;
335
- _ref = this.options.goals;
336
- _results = [];
337
- for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
338
- goal = _ref[i];
339
- _results.push(this.drawGoal("M" + this.left + "," + (this.transY(goal)) + "H" + (this.left + this.width)));
338
+ Grid.prototype.measureText = function(text, fontSize) {
339
+ var ret, tt;
340
+ if (fontSize == null) {
341
+ fontSize = 12;
340
342
  }
341
- return _results;
343
+ tt = this.raphael.text(100, 100, text).attr('font-size', fontSize);
344
+ ret = tt.getBBox();
345
+ tt.remove();
346
+ return ret;
342
347
  };
343
348
 
344
- Grid.prototype.drawEvents = function() {
345
- var event, i, _i, _len, _ref, _results;
346
- _ref = this.events;
347
- _results = [];
348
- for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
349
- event = _ref[i];
350
- _results.push(this.drawEvent("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top));
349
+ Grid.prototype.yAxisFormat = function(label) {
350
+ return this.yLabelFormat(label);
351
+ };
352
+
353
+ Grid.prototype.yLabelFormat = function(label) {
354
+ if (typeof this.options.yLabelFormat === 'function') {
355
+ return this.options.yLabelFormat(label);
356
+ } else {
357
+ return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
358
+ }
359
+ };
360
+
361
+ Grid.prototype.updateHover = function(x, y) {
362
+ var hit, _ref;
363
+ hit = this.hitTest(x, y);
364
+ if (hit != null) {
365
+ return (_ref = this.hover).update.apply(_ref, hit);
351
366
  }
352
- return _results;
353
367
  };
354
368
 
355
369
  Grid.prototype.drawGrid = function() {
@@ -375,43 +389,36 @@
375
389
  return _results;
376
390
  };
377
391
 
378
- Grid.prototype.measureText = function(text, fontSize) {
379
- var ret, tt;
380
- if (fontSize == null) {
381
- fontSize = 12;
382
- }
383
- tt = this.raphael.text(100, 100, text).attr('font-size', fontSize);
384
- ret = tt.getBBox();
385
- tt.remove();
386
- return ret;
387
- };
388
-
389
- Grid.prototype.yAxisFormat = function(label) {
390
- return this.yLabelFormat(label);
391
- };
392
-
393
- Grid.prototype.yLabelFormat = function(label) {
394
- if (typeof this.options.yLabelFormat === 'function') {
395
- return this.options.yLabelFormat(label);
396
- } else {
397
- return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
392
+ Grid.prototype.drawGoals = function() {
393
+ var color, goal, i, _i, _len, _ref, _results;
394
+ _ref = this.options.goals;
395
+ _results = [];
396
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
397
+ goal = _ref[i];
398
+ color = this.options.goalLineColors[i % this.options.goalLineColors.length];
399
+ _results.push(this.drawGoal(goal, color));
398
400
  }
401
+ return _results;
399
402
  };
400
403
 
401
- Grid.prototype.updateHover = function(x, y) {
402
- var hit, _ref;
403
- hit = this.hitTest(x, y);
404
- if (hit != null) {
405
- return (_ref = this.hover).update.apply(_ref, hit);
404
+ Grid.prototype.drawEvents = function() {
405
+ var color, event, i, _i, _len, _ref, _results;
406
+ _ref = this.events;
407
+ _results = [];
408
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
409
+ event = _ref[i];
410
+ color = this.options.eventLineColors[i % this.options.eventLineColors.length];
411
+ _results.push(this.drawEvent(event, color));
406
412
  }
413
+ return _results;
407
414
  };
408
415
 
409
- Grid.prototype.drawGoal = function(path) {
410
- return this.raphael.path(path).attr('stroke', this.options.goalLineColors[i % this.options.goalLineColors.length]).attr('stroke-width', this.options.goalStrokeWidth);
416
+ Grid.prototype.drawGoal = function(goal, color) {
417
+ return this.raphael.path("M" + this.left + "," + (this.transY(goal)) + "H" + this.right).attr('stroke', color).attr('stroke-width', this.options.goalStrokeWidth);
411
418
  };
412
419
 
413
- Grid.prototype.drawEvent = function(path) {
414
- return this.raphael.path(path).attr('stroke', this.options.eventLineColors[i % this.options.eventLineColors.length]).attr('stroke-width', this.options.eventStrokeWidth);
420
+ Grid.prototype.drawEvent = function(event, color) {
421
+ return this.raphael.path("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top).attr('stroke', color).attr('stroke-width', this.options.eventStrokeWidth);
415
422
  };
416
423
 
417
424
  Grid.prototype.drawYAxisLabel = function(xPos, yPos, text) {
@@ -636,6 +643,9 @@
636
643
 
637
644
  Line.prototype.hitTest = function(x, y) {
638
645
  var index, r, _i, _len, _ref;
646
+ if (this.data.length === 0) {
647
+ return null;
648
+ }
639
649
  _ref = this.data.slice(1);
640
650
  for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
641
651
  r = _ref[index];
@@ -1291,6 +1301,9 @@
1291
1301
  };
1292
1302
 
1293
1303
  Bar.prototype.hitTest = function(x, y) {
1304
+ if (this.data.length === 0) {
1305
+ return null;
1306
+ }
1294
1307
  x = Math.max(Math.min(x, this.right), this.left);
1295
1308
  return Math.min(this.data.length - 1, Math.floor((x - this.left) / (this.width / this.data.length)));
1296
1309
  };
@@ -1342,6 +1355,7 @@
1342
1355
  Donut.prototype.defaults = {
1343
1356
  colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],
1344
1357
  backgroundColor: '#FFFFFF',
1358
+ labelColor: '#000000',
1345
1359
  formatter: Morris.commas
1346
1360
  };
1347
1361
 
@@ -1395,8 +1409,8 @@
1395
1409
  last = next;
1396
1410
  idx += 1;
1397
1411
  }
1398
- this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, 15, 800);
1399
- this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, 14);
1412
+ this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, this.options.labelColor, 15, 800);
1413
+ this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, this.options.labelColor, 14);
1400
1414
  max_value = Math.max.apply(null, (function() {
1401
1415
  var _k, _len2, _ref2, _results;
1402
1416
  _ref2 = this.data;
@@ -1463,9 +1477,9 @@
1463
1477
  });
1464
1478
  };
1465
1479
 
1466
- Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, fontSize, fontWeight) {
1480
+ Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, color, fontSize, fontWeight) {
1467
1481
  var text;
1468
- text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize);
1482
+ text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize).attr('fill', color);
1469
1483
  if (fontWeight != null) {
1470
1484
  text.attr('font-weight', fontWeight);
1471
1485
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morrisjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -63,4 +63,3 @@ signing_key:
63
63
  specification_version: 3
64
64
  summary: morris.js for the Rails Asset Pipeline
65
65
  test_files: []
66
- has_rdoc: