mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Simplify!
This commit is contained in:
parent
66461001b7
commit
67fbc481aa
@ -223,15 +223,6 @@ class Morris.Line
|
||||
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(@options.ykeys[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
|
||||
@ -300,8 +291,10 @@ class Morris.Line
|
||||
drawSeries: ->
|
||||
for i in [@seriesCoords.length-1..0]
|
||||
coords = $.map(@seriesCoords[i], (c) -> c)
|
||||
smooth = @options.smooth is true or
|
||||
$.inArray(@options.ykeys[i], @options.smooth) > -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)
|
||||
.attr('stroke', @colorForSeries(i))
|
||||
.attr('stroke-width', @options.lineWidth)
|
||||
@ -320,10 +313,9 @@ class Morris.Line
|
||||
# create a path for a data series
|
||||
#
|
||||
# @private
|
||||
createPath: (series, coords, top, left, bottom, right) ->
|
||||
createPath: (coords, bottom, smooth) ->
|
||||
path = ""
|
||||
|
||||
if @shouldDrawSmooth(series)
|
||||
if smooth
|
||||
grads = @gradients coords
|
||||
for i in [0..coords.length-1]
|
||||
c = coords[i]
|
||||
|
21
morris.js
21
morris.js
@ -292,8 +292,6 @@
|
||||
|
||||
this.updateHover = __bind(this.updateHover, this);
|
||||
|
||||
this.shouldDrawSmooth = __bind(this.shouldDrawSmooth, this);
|
||||
|
||||
this.transY = __bind(this.transY, this);
|
||||
|
||||
this.transX = __bind(this.transX, this);
|
||||
@ -560,16 +558,6 @@
|
||||
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() {
|
||||
this.r.clear();
|
||||
this.calc();
|
||||
@ -626,13 +614,14 @@
|
||||
};
|
||||
|
||||
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) {
|
||||
coords = $.map(this.seriesCoords[i], function(c) {
|
||||
return c;
|
||||
});
|
||||
smooth = this.options.smooth === true || $.inArray(this.options.ykeys[i], this.options.smooth) > -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);
|
||||
}
|
||||
}
|
||||
@ -665,10 +654,10 @@
|
||||
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;
|
||||
path = "";
|
||||
if (this.shouldDrawSmooth(series)) {
|
||||
if (smooth) {
|
||||
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
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user