Simplify!

This commit is contained in:
Olly Smith 2012-10-21 00:29:40 +01:00
parent 66461001b7
commit 67fbc481aa
3 changed files with 11 additions and 30 deletions

View File

@ -223,15 +223,6 @@ class Morris.Line
transY: (y) => transY: (y) =>
return @options.marginTop + @height - (y - @ymin) * @dy return @options.marginTop + @height - (y - @ymin) * @dy
# @private
shouldDrawSmooth: (series) =>
if typeof @options.smooth is 'boolean' && @options.smooth
true
else if typeof @options.smooth is 'object' and $.inArray(@options.ykeys[series], @options.smooth) > -1
true
else
false
# Clear and redraw the chart. # Clear and redraw the chart.
# #
# If you need to re-size your charts, call this method after changing the # If you need to re-size your charts, call this method after changing the
@ -300,8 +291,10 @@ class Morris.Line
drawSeries: -> drawSeries: ->
for i in [@seriesCoords.length-1..0] for i in [@seriesCoords.length-1..0]
coords = $.map(@seriesCoords[i], (c) -> c) coords = $.map(@seriesCoords[i], (c) -> c)
smooth = @options.smooth is true or
$.inArray(@options.ykeys[i], @options.smooth) > -1
if coords.length > 1 if coords.length > 1
path = @createPath i, coords, @options.marginTop, @left, @options.marginTop + @height, @left + @width path = @createPath coords, @options.marginTop + @height, smooth
@r.path(path) @r.path(path)
.attr('stroke', @colorForSeries(i)) .attr('stroke', @colorForSeries(i))
.attr('stroke-width', @options.lineWidth) .attr('stroke-width', @options.lineWidth)
@ -320,10 +313,9 @@ class Morris.Line
# create a path for a data series # create a path for a data series
# #
# @private # @private
createPath: (series, coords, top, left, bottom, right) -> createPath: (coords, bottom, smooth) ->
path = "" path = ""
if smooth
if @shouldDrawSmooth(series)
grads = @gradients coords grads = @gradients coords
for i in [0..coords.length-1] for i in [0..coords.length-1]
c = coords[i] c = coords[i]

View File

@ -292,8 +292,6 @@
this.updateHover = __bind(this.updateHover, this); this.updateHover = __bind(this.updateHover, this);
this.shouldDrawSmooth = __bind(this.shouldDrawSmooth, this);
this.transY = __bind(this.transY, this); this.transY = __bind(this.transY, this);
this.transX = __bind(this.transX, this); this.transX = __bind(this.transX, this);
@ -560,16 +558,6 @@
return this.options.marginTop + this.height - (y - this.ymin) * this.dy; return this.options.marginTop + this.height - (y - this.ymin) * this.dy;
}; };
Line.prototype.shouldDrawSmooth = function(series) {
if (typeof this.options.smooth === 'boolean' && this.options.smooth) {
return true;
} else if (typeof this.options.smooth === 'object' && $.inArray(this.options.ykeys[series], this.options.smooth) > -1) {
return true;
} else {
return false;
}
};
Line.prototype.redraw = function() { Line.prototype.redraw = function() {
this.r.clear(); this.r.clear();
this.calc(); this.calc();
@ -626,13 +614,14 @@
}; };
Line.prototype.drawSeries = function() { Line.prototype.drawSeries = function() {
var c, circle, coords, i, path, _i, _j, _ref, _ref1, _results; var c, circle, coords, i, path, smooth, _i, _j, _ref, _ref1, _results;
for (i = _i = _ref = this.seriesCoords.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) { for (i = _i = _ref = this.seriesCoords.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) {
coords = $.map(this.seriesCoords[i], function(c) { coords = $.map(this.seriesCoords[i], function(c) {
return c; return c;
}); });
smooth = this.options.smooth === true || $.inArray(this.options.ykeys[i], this.options.smooth) > -1;
if (coords.length > 1) { if (coords.length > 1) {
path = this.createPath(i, coords, this.options.marginTop, this.left, this.options.marginTop + this.height, this.left + this.width); path = this.createPath(coords, this.options.marginTop + this.height, smooth);
this.r.path(path).attr('stroke', this.colorForSeries(i)).attr('stroke-width', this.options.lineWidth); this.r.path(path).attr('stroke', this.colorForSeries(i)).attr('stroke-width', this.options.lineWidth);
} }
} }
@ -665,10 +654,10 @@
return _results; return _results;
}; };
Line.prototype.createPath = function(series, coords, top, left, bottom, right) { Line.prototype.createPath = function(coords, bottom, smooth) {
var c, g, grads, i, ix, lc, lg, path, x1, x2, y1, y2, _i, _ref; var c, g, grads, i, ix, lc, lg, path, x1, x2, y1, y2, _i, _ref;
path = ""; path = "";
if (this.shouldDrawSmooth(series)) { if (smooth) {
grads = this.gradients(coords); grads = this.gradients(coords);
for (i = _i = 0, _ref = coords.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { for (i = _i = 0, _ref = coords.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
c = coords[i]; c = coords[i];

2
morris.min.js vendored

File diff suppressed because one or more lines are too long