mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-14 07:41:11 +01:00
Added some null checks to the animation code - code now works with the examples
This commit is contained in:
parent
4924a5476b
commit
3631659ee5
2 changed files with 13 additions and 7 deletions
|
@ -258,7 +258,7 @@ class Morris.Line
|
|||
path = @createPath coords, @options.marginTop, @left, @options.marginTop + @height, @left + @width
|
||||
if @options.animate
|
||||
averages[i] = average = Morris.seriesAverage(coords)
|
||||
straightCoords = ({x:c.x, y:average} for c in coords)
|
||||
straightCoords = ({x:c.x, y:average} for c in coords when c?)
|
||||
straightPath = @createPath straightCoords, @options.marginTop, @left, @options.marginTop + @height, @left + @width
|
||||
rPath = @r.path(straightPath)
|
||||
.attr('stroke', @options.lineColors[i])
|
||||
|
@ -538,9 +538,10 @@ Morris.labelSeries = (dmin, dmax, pxwidth, specName, xLabelFormat) ->
|
|||
return ret
|
||||
|
||||
Morris.seriesAverage = (series) ->
|
||||
console.log series
|
||||
total = 0
|
||||
for point in series
|
||||
total += point.y ? 0
|
||||
total += point.y ? 0 if point?
|
||||
(total / series.length) / 2
|
||||
|
||||
minutesSpecHelper = (interval) ->
|
||||
|
|
15
morris.js
15
morris.js
|
@ -303,10 +303,12 @@
|
|||
_results = [];
|
||||
for (_j = 0, _len = coords.length; _j < _len; _j++) {
|
||||
c = coords[_j];
|
||||
_results.push({
|
||||
x: c.x,
|
||||
y: average
|
||||
});
|
||||
if (c != null) {
|
||||
_results.push({
|
||||
x: c.x,
|
||||
y: average
|
||||
});
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
|
@ -627,10 +629,13 @@
|
|||
|
||||
Morris.seriesAverage = function(series) {
|
||||
var point, total, _i, _len, _ref;
|
||||
console.log(series);
|
||||
total = 0;
|
||||
for (_i = 0, _len = series.length; _i < _len; _i++) {
|
||||
point = series[_i];
|
||||
total += (_ref = point.y) != null ? _ref : 0;
|
||||
if (point != null) {
|
||||
total += (_ref = point.y) != null ? _ref : 0;
|
||||
}
|
||||
}
|
||||
return (total / series.length) / 2;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue