mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Add ymax 'auto $min' support.
This commit is contained in:
parent
846c4677c9
commit
8d6cb3ee8e
@ -73,10 +73,13 @@ class Morris.Line
|
||||
@xmax += 1
|
||||
|
||||
# Compute the vertical range of the graph if desired
|
||||
if @options.ymax == 'auto'
|
||||
# use $.map to flatten arrays and find the max y value
|
||||
all_y_vals = $.map @series, (x) -> Math.max.apply null, x
|
||||
@options.ymax = Math.max(20, Math.max.apply(null, all_y_vals))
|
||||
if typeof @options.ymax is 'string' and @options.ymax[0..3] is 'auto'
|
||||
# use Array.concat to flatten arrays and find the max y value
|
||||
ymax = Math.max.apply null, Array.prototype.concat.apply([], @series)
|
||||
if @options.ymax.length > 5
|
||||
@options.ymax = Math.max parseInt(@options.ymax[5..], 10), ymax
|
||||
else
|
||||
@options.ymax = ymax
|
||||
|
||||
# Clear and redraw the graph
|
||||
#
|
||||
|
14
morris.js
14
morris.js
@ -41,7 +41,7 @@
|
||||
};
|
||||
|
||||
Line.prototype.precalc = function() {
|
||||
var all_y_vals, ykey, _i, _len, _ref,
|
||||
var ykey, ymax, _i, _len, _ref,
|
||||
_this = this;
|
||||
this.columnLabels = $.map(this.options.data, function(d) {
|
||||
return d[_this.options.xkey];
|
||||
@ -64,11 +64,13 @@
|
||||
this.xmin -= 1;
|
||||
this.xmax += 1;
|
||||
}
|
||||
if (this.options.ymax === 'auto') {
|
||||
all_y_vals = $.map(this.series, function(x) {
|
||||
return Math.max.apply(null, x);
|
||||
});
|
||||
return this.options.ymax = Math.max(20, Math.max.apply(null, all_y_vals));
|
||||
if (typeof this.options.ymax === 'string' && this.options.ymax.slice(0, 4) === 'auto') {
|
||||
ymax = Math.max.apply(null, Array.prototype.concat.apply([], this.series));
|
||||
if (this.options.ymax.length > 5) {
|
||||
return this.options.ymax = Math.max(parseInt(this.options.ymax.slice(5), 10), ymax);
|
||||
} else {
|
||||
return this.options.ymax = ymax;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
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