Skip to content

Loading…

Upgrade morris to 0.4.1. #1

Merged
merged 1 commit into from

2 participants

@linjunpop

No description provided.

@beanieboi
Owner

Thanks. I will merge this when I'm back home.

@beanieboi beanieboi merged commit 3c4930f into beanieboi:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2013
  1. @linjunpop

    Upgrade morris to 0.4.1.

    linjunpop committed
Showing with 67 additions and 53 deletions.
  1. +1 −1 lib/morrisjs-rails/version.rb
  2. +66 −52 vendor/assets/javascripts/morris.js
View
2 lib/morrisjs-rails/version.rb
@@ -1,5 +1,5 @@
module Morrisjs
module Rails
- VERSION = "0.4.0"
+ VERSION = "0.4.1"
end
end
View
118 vendor/assets/javascripts/morris.js
@@ -81,9 +81,6 @@
this.el.css('position', 'relative');
}
this.options = $.extend({}, this.gridDefaults, this.defaults || {}, options);
- if (this.options.data === void 0 || this.options.data.length === 0) {
- return;
- }
if (typeof this.options.units === 'string') {
this.options.postUnits = options.units;
}
@@ -145,6 +142,14 @@
if (redraw == null) {
redraw = true;
}
+ if (!(data != null) || data.length === 0) {
+ this.data = [];
+ this.raphael.clear();
+ if (this.hover != null) {
+ this.hover.hide();
+ }
+ return;
+ }
ymax = this.cumulative ? 0 : null;
ymin = this.cumulative ? 0 : null;
if (this.options.goals.length > 0) {
@@ -330,26 +335,35 @@
}
};
- Grid.prototype.drawGoals = function() {
- var goal, i, _i, _len, _ref, _results;
- _ref = this.options.goals;
- _results = [];
- for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
- goal = _ref[i];
- _results.push(this.drawGoal("M" + this.left + "," + (this.transY(goal)) + "H" + (this.left + this.width)));
+ Grid.prototype.measureText = function(text, fontSize) {
+ var ret, tt;
+ if (fontSize == null) {
+ fontSize = 12;
}
- return _results;
+ tt = this.raphael.text(100, 100, text).attr('font-size', fontSize);
+ ret = tt.getBBox();
+ tt.remove();
+ return ret;
};
- Grid.prototype.drawEvents = function() {
- var event, i, _i, _len, _ref, _results;
- _ref = this.events;
- _results = [];
- for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
- event = _ref[i];
- _results.push(this.drawEvent("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top));
+ Grid.prototype.yAxisFormat = function(label) {
+ return this.yLabelFormat(label);
+ };
+
+ Grid.prototype.yLabelFormat = function(label) {
+ if (typeof this.options.yLabelFormat === 'function') {
+ return this.options.yLabelFormat(label);
+ } else {
+ return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
+ }
+ };
+
+ Grid.prototype.updateHover = function(x, y) {
+ var hit, _ref;
+ hit = this.hitTest(x, y);
+ if (hit != null) {
+ return (_ref = this.hover).update.apply(_ref, hit);
}
- return _results;
};
Grid.prototype.drawGrid = function() {
@@ -375,43 +389,36 @@
return _results;
};
- Grid.prototype.measureText = function(text, fontSize) {
- var ret, tt;
- if (fontSize == null) {
- fontSize = 12;
- }
- tt = this.raphael.text(100, 100, text).attr('font-size', fontSize);
- ret = tt.getBBox();
- tt.remove();
- return ret;
- };
-
- Grid.prototype.yAxisFormat = function(label) {
- return this.yLabelFormat(label);
- };
-
- Grid.prototype.yLabelFormat = function(label) {
- if (typeof this.options.yLabelFormat === 'function') {
- return this.options.yLabelFormat(label);
- } else {
- return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
+ Grid.prototype.drawGoals = function() {
+ var color, goal, i, _i, _len, _ref, _results;
+ _ref = this.options.goals;
+ _results = [];
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
+ goal = _ref[i];
+ color = this.options.goalLineColors[i % this.options.goalLineColors.length];
+ _results.push(this.drawGoal(goal, color));
}
+ return _results;
};
- Grid.prototype.updateHover = function(x, y) {
- var hit, _ref;
- hit = this.hitTest(x, y);
- if (hit != null) {
- return (_ref = this.hover).update.apply(_ref, hit);
+ Grid.prototype.drawEvents = function() {
+ var color, event, i, _i, _len, _ref, _results;
+ _ref = this.events;
+ _results = [];
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
+ event = _ref[i];
+ color = this.options.eventLineColors[i % this.options.eventLineColors.length];
+ _results.push(this.drawEvent(event, color));
}
+ return _results;
};
- Grid.prototype.drawGoal = function(path) {
- return this.raphael.path(path).attr('stroke', this.options.goalLineColors[i % this.options.goalLineColors.length]).attr('stroke-width', this.options.goalStrokeWidth);
+ Grid.prototype.drawGoal = function(goal, color) {
+ return this.raphael.path("M" + this.left + "," + (this.transY(goal)) + "H" + this.right).attr('stroke', color).attr('stroke-width', this.options.goalStrokeWidth);
};
- Grid.prototype.drawEvent = function(path) {
- return this.raphael.path(path).attr('stroke', this.options.eventLineColors[i % this.options.eventLineColors.length]).attr('stroke-width', this.options.eventStrokeWidth);
+ Grid.prototype.drawEvent = function(event, color) {
+ return this.raphael.path("M" + (this.transX(event)) + "," + this.bottom + "V" + this.top).attr('stroke', color).attr('stroke-width', this.options.eventStrokeWidth);
};
Grid.prototype.drawYAxisLabel = function(xPos, yPos, text) {
@@ -636,6 +643,9 @@
Line.prototype.hitTest = function(x, y) {
var index, r, _i, _len, _ref;
+ if (this.data.length === 0) {
+ return null;
+ }
_ref = this.data.slice(1);
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
r = _ref[index];
@@ -1291,6 +1301,9 @@
};
Bar.prototype.hitTest = function(x, y) {
+ if (this.data.length === 0) {
+ return null;
+ }
x = Math.max(Math.min(x, this.right), this.left);
return Math.min(this.data.length - 1, Math.floor((x - this.left) / (this.width / this.data.length)));
};
@@ -1342,6 +1355,7 @@
Donut.prototype.defaults = {
colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],
backgroundColor: '#FFFFFF',
+ labelColor: '#000000',
formatter: Morris.commas
};
@@ -1395,8 +1409,8 @@
last = next;
idx += 1;
}
- this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, 15, 800);
- this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, 14);
+ this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, this.options.labelColor, 15, 800);
+ this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, this.options.labelColor, 14);
max_value = Math.max.apply(null, (function() {
var _k, _len2, _ref2, _results;
_ref2 = this.data;
@@ -1463,9 +1477,9 @@
});
};
- Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, fontSize, fontWeight) {
+ Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, color, fontSize, fontWeight) {
var text;
- text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize);
+ text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize).attr('fill', color);
if (fontWeight != null) {
text.attr('font-weight', fontWeight);
}
Something went wrong with that request. Please try again.