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

@ -213,12 +213,21 @@ class Morris.Line
if @xvals.length is 1
@left + @width / 2
else
@left + (x - @xmin) * @dx
@left + (x - @xmin) * @dx
# @private
transY: (y) =>
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.
#
# 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]
coords = $.map(@seriesCoords[i], (c) -> c)
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)
.attr('stroke', @colorForSeries(i))
.attr('stroke-width', @options.lineWidth)
@ -307,9 +316,10 @@ class Morris.Line
# create a path for a data series
#
# @private
createPath: (coords, top, left, bottom, right) ->
createPath: (series, coords, top, left, bottom, right) ->
path = ""
if @options.smooth
if @shouldDrawSmooth(series)
grads = @gradients coords
for i in [0..coords.length-1]
c = coords[i]

View File

@ -292,6 +292,8 @@
this.updateHover = __bind(this.updateHover, this);
this.shouldDrawSmooth = __bind(this.shouldDrawSmooth, this);
this.transY = __bind(this.transY, this);
this.transX = __bind(this.transX, this);
@ -554,6 +556,16 @@
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() {
this.r.clear();
this.calc();
@ -616,7 +628,7 @@
return c;
});
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);
}
}
@ -649,10 +661,10 @@
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;
path = "";
if (this.options.smooth) {
if (this.shouldDrawSmooth(series)) {
grads = this.gradients(coords);
for (i = _i = 0, _ref = coords.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
c = coords[i];

2
morris.min.js vendored

File diff suppressed because one or more lines are too long