added ability to set smooth parameter per series

This commit is contained in:
tiraeth 2012-10-15 22:58:35 +02:00
parent 60eae6a697
commit 9773a697b3
3 changed files with 30 additions and 8 deletions

View File

@ -219,6 +219,15 @@ 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(@seriesLabels[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
@ -288,7 +297,7 @@ class Morris.Line
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)
if coords.length > 1 if coords.length > 1
path = @createPath coords, @options.marginTop, @left, @options.marginTop + @height, @left + @width path = @createPath i, coords, @options.marginTop, @left, @options.marginTop + @height, @left + @width
@r.path(path) @r.path(path)
.attr('stroke', @colorForSeries(i)) .attr('stroke', @colorForSeries(i))
.attr('stroke-width', @options.lineWidth) .attr('stroke-width', @options.lineWidth)
@ -307,9 +316,10 @@ class Morris.Line
# create a path for a data series # create a path for a data series
# #
# @private # @private
createPath: (coords, top, left, bottom, right) -> createPath: (series, coords, top, left, bottom, right) ->
path = "" path = ""
if @options.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,6 +292,8 @@
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);
@ -554,6 +556,16 @@
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.seriesLabels[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();
@ -616,7 +628,7 @@
return c; return c;
}); });
if (coords.length > 1) { if (coords.length > 1) {
path = this.createPath(coords, this.options.marginTop, this.left, this.options.marginTop + this.height, this.left + this.width); path = this.createPath(i, coords, this.options.marginTop, this.left, this.options.marginTop + this.height, this.left + this.width);
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);
} }
} }
@ -649,10 +661,10 @@
return _results; return _results;
}; };
Line.prototype.createPath = function(coords, top, left, bottom, right) { Line.prototype.createPath = function(series, coords, top, left, bottom, right) {
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.options.smooth) { if (this.shouldDrawSmooth(series)) {
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