mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Fix #66.
This commit is contained in:
parent
5f0e65c279
commit
eacbc01149
@ -51,6 +51,7 @@ class Morris.Line
|
||||
@el.bind 'touchmove', touchHandler
|
||||
@el.bind 'touchend', touchHandler
|
||||
|
||||
@seriesLabels = @options.labels
|
||||
@setData(@options.data)
|
||||
|
||||
# Default configuration
|
||||
@ -104,7 +105,6 @@ class Morris.Line
|
||||
@options.data.sort (a, b) => (a[@options.xkey] < b[@options.xkey]) - (b[@options.xkey] < a[@options.xkey])
|
||||
# extract labels
|
||||
@columnLabels = $.map @options.data, (d) => d[@options.xkey]
|
||||
@seriesLabels = @options.labels
|
||||
|
||||
# extract series data
|
||||
@series = []
|
||||
@ -141,17 +141,20 @@ class Morris.Line
|
||||
# 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
|
||||
@ymax = Math.max parseInt(@options.ymax[5..], 10), ymax
|
||||
else
|
||||
@options.ymax = ymax
|
||||
@ymax = ymax
|
||||
if typeof @options.ymin is 'string' and @options.ymin[0..3] is 'auto'
|
||||
ymin = Math.min.apply null, Array.prototype.concat.apply([], @series)
|
||||
if @options.ymin.length > 5
|
||||
@options.ymin = Math.min parseInt(@options.ymin[5..], 10), ymin
|
||||
@ymin = Math.min parseInt(@options.ymin[5..], 10), ymin
|
||||
else
|
||||
@options.ymin = ymin
|
||||
@ymin = ymin
|
||||
if @ymin is @ymax
|
||||
@ymin -= 1
|
||||
@ymax += 1
|
||||
|
||||
@yInterval = (@options.ymax - @options.ymin) / (@options.numLines - 1)
|
||||
@yInterval = (@ymax - @ymin) / (@options.numLines - 1)
|
||||
if @yInterval > 0 and @yInterval < 1
|
||||
@precision = -Math.floor(Math.log(@yInterval) / Math.log(10))
|
||||
else
|
||||
@ -172,13 +175,13 @@ class Morris.Line
|
||||
@dirty = false
|
||||
# calculate grid dimensions
|
||||
@maxYLabelWidth = Math.max(
|
||||
@measureText(@yLabelFormat(@options.ymin), @options.gridTextSize).width,
|
||||
@measureText(@yLabelFormat(@options.ymax), @options.gridTextSize).width)
|
||||
@measureText(@yLabelFormat(@ymin), @options.gridTextSize).width,
|
||||
@measureText(@yLabelFormat(@ymax), @options.gridTextSize).width)
|
||||
@left = @maxYLabelWidth + @options.marginLeft
|
||||
@width = @el.width() - @left - @options.marginRight
|
||||
@height = @el.height() - @options.marginTop - @options.marginBottom
|
||||
@dx = @width / (@xmax - @xmin)
|
||||
@dy = @height / (@options.ymax - @options.ymin)
|
||||
@dy = @height / (@ymax - @ymin)
|
||||
# calculate series data point coordinates
|
||||
@columns = (@transX(x) for x in @xvals)
|
||||
@seriesCoords = []
|
||||
@ -202,7 +205,7 @@ class Morris.Line
|
||||
@left + (x - @xmin) * @dx
|
||||
|
||||
transY: (y) =>
|
||||
return @options.marginTop + @height - (y - @options.ymin) * @dy
|
||||
return @options.marginTop + @height - (y - @ymin) * @dy
|
||||
|
||||
# Clear and redraw the graph
|
||||
#
|
||||
@ -218,8 +221,8 @@ class Morris.Line
|
||||
#
|
||||
drawGrid: ->
|
||||
# draw y axis labels, horizontal lines
|
||||
firstY = @options.ymin
|
||||
lastY = @options.ymax
|
||||
firstY = @ymin
|
||||
lastY = @ymax
|
||||
|
||||
|
||||
for lineY in [firstY..lastY] by @yInterval
|
||||
|
26
morris.js
26
morris.js
@ -68,6 +68,7 @@
|
||||
this.el.bind('touchstart', touchHandler);
|
||||
this.el.bind('touchmove', touchHandler);
|
||||
this.el.bind('touchend', touchHandler);
|
||||
this.seriesLabels = this.options.labels;
|
||||
this.setData(this.options.data);
|
||||
}
|
||||
|
||||
@ -120,7 +121,6 @@
|
||||
this.columnLabels = $.map(this.options.data, function(d) {
|
||||
return d[_this.options.xkey];
|
||||
});
|
||||
this.seriesLabels = this.options.labels;
|
||||
this.series = [];
|
||||
_ref = this.options.ykeys;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
@ -171,20 +171,24 @@
|
||||
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) {
|
||||
this.options.ymax = Math.max(parseInt(this.options.ymax.slice(5), 10), ymax);
|
||||
this.ymax = Math.max(parseInt(this.options.ymax.slice(5), 10), ymax);
|
||||
} else {
|
||||
this.options.ymax = ymax;
|
||||
this.ymax = ymax;
|
||||
}
|
||||
}
|
||||
if (typeof this.options.ymin === 'string' && this.options.ymin.slice(0, 4) === 'auto') {
|
||||
ymin = Math.min.apply(null, Array.prototype.concat.apply([], this.series));
|
||||
if (this.options.ymin.length > 5) {
|
||||
this.options.ymin = Math.min(parseInt(this.options.ymin.slice(5), 10), ymin);
|
||||
this.ymin = Math.min(parseInt(this.options.ymin.slice(5), 10), ymin);
|
||||
} else {
|
||||
this.options.ymin = ymin;
|
||||
this.ymin = ymin;
|
||||
}
|
||||
}
|
||||
this.yInterval = (this.options.ymax - this.options.ymin) / (this.options.numLines - 1);
|
||||
if (this.ymin === this.ymax) {
|
||||
this.ymin -= 1;
|
||||
this.ymax += 1;
|
||||
}
|
||||
this.yInterval = (this.ymax - this.ymin) / (this.options.numLines - 1);
|
||||
if (this.yInterval > 0 && this.yInterval < 1) {
|
||||
this.precision = -Math.floor(Math.log(this.yInterval) / Math.log(10));
|
||||
} else {
|
||||
@ -205,12 +209,12 @@
|
||||
this.elementWidth = w;
|
||||
this.elementHeight = h;
|
||||
this.dirty = false;
|
||||
this.maxYLabelWidth = Math.max(this.measureText(this.yLabelFormat(this.options.ymin), this.options.gridTextSize).width, this.measureText(this.yLabelFormat(this.options.ymax), this.options.gridTextSize).width);
|
||||
this.maxYLabelWidth = Math.max(this.measureText(this.yLabelFormat(this.ymin), this.options.gridTextSize).width, this.measureText(this.yLabelFormat(this.ymax), this.options.gridTextSize).width);
|
||||
this.left = this.maxYLabelWidth + this.options.marginLeft;
|
||||
this.width = this.el.width() - this.left - this.options.marginRight;
|
||||
this.height = this.el.height() - this.options.marginTop - this.options.marginBottom;
|
||||
this.dx = this.width / (this.xmax - this.xmin);
|
||||
this.dy = this.height / (this.options.ymax - this.options.ymin);
|
||||
this.dy = this.height / (this.ymax - this.ymin);
|
||||
this.columns = (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = this.xvals;
|
||||
@ -253,7 +257,7 @@
|
||||
};
|
||||
|
||||
Line.prototype.transY = function(y) {
|
||||
return this.options.marginTop + this.height - (y - this.options.ymin) * this.dy;
|
||||
return this.options.marginTop + this.height - (y - this.ymin) * this.dy;
|
||||
};
|
||||
|
||||
Line.prototype.redraw = function() {
|
||||
@ -268,8 +272,8 @@
|
||||
Line.prototype.drawGrid = function() {
|
||||
var drawLabel, firstY, i, l, labelText, lastY, lineY, prevLabelMargin, v, xLabelMargin, y, ypos, _i, _j, _k, _len, _ref, _ref1, _ref2, _results, _results1,
|
||||
_this = this;
|
||||
firstY = this.options.ymin;
|
||||
lastY = this.options.ymax;
|
||||
firstY = this.ymin;
|
||||
lastY = this.ymax;
|
||||
for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) {
|
||||
v = parseFloat(lineY.toFixed(this.precision));
|
||||
y = this.transY(v);
|
||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
@ -243,8 +243,3 @@ describe 'Morris.line', ->
|
||||
["1/5/2012", new Date(2012, 0, 5).getTime()],
|
||||
["1/6/2012", new Date(2012, 0, 6).getTime()]
|
||||
])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user