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