Merge branch 'decimal' of https://github.com/pelletier/morris.js into pelletier-decimal

Conflicts:
	morris.min.js
This commit is contained in:
Olly Smith 2012-06-08 21:42:10 +01:00
commit 380cc5217a
3 changed files with 32 additions and 18 deletions

View File

@ -152,6 +152,14 @@ class Morris.Line
calc: ->
w = @el.width()
h = @el.height()
@yInterval = (@options.ymax - @options.ymin) / (@options.numLines - 1)
if (@yInterval < 1)
@precision = -parseInt(@yInterval.toExponential().split('e')[1])
else
@precision = 0
if @elementWidth != w or @elementHeight != h
# calculate grid dimensions
@maxYLabelWidth = Math.max(
@ -206,11 +214,12 @@ class Morris.Line
#
drawGrid: ->
# draw y axis labels, horizontal lines
yInterval = (@options.ymax - @options.ymin) / (@options.numLines - 1)
firstY = Math.ceil(@options.ymin / yInterval) * yInterval
lastY = Math.floor(@options.ymax / yInterval) * yInterval
for lineY in [firstY..lastY] by yInterval
v = Math.floor(lineY)
firstY = @options.ymin
lastY = @options.ymax
for lineY in [firstY..lastY] by @yInterval
v = lineY
y = @transY(v)
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v))
.attr('font-size', @options.gridTextSize)
@ -386,7 +395,7 @@ class Morris.Line
return ret
yLabelFormat: (label) ->
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"
"#{@options.preUnits}#{Morris.commas(label.toFixed(@precision || 0))}#{@options.postUnits}"
# parse a date into a javascript timestamp
#

View File

@ -185,6 +185,12 @@
_this = this;
w = this.el.width();
h = this.el.height();
this.yInterval = (this.options.ymax - this.options.ymin) / (this.options.numLines - 1);
if (this.yInterval < 1) {
this.precision = -parseInt(this.yInterval.toExponential().split('e')[1]);
} else {
this.precision = 0;
}
if (this.elementWidth !== w || this.elementHeight !== h) {
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.left = this.maxYLabelWidth + this.options.marginLeft;
@ -248,13 +254,12 @@
};
Line.prototype.drawGrid = function() {
var drawLabel, firstY, i, l, labelText, lastY, lineY, prevLabelMargin, v, xLabelMargin, y, yInterval, ypos, _i, _j, _k, _len, _ref, _ref1, _results, _results1,
var drawLabel, firstY, i, l, labelText, lastY, lineY, prevLabelMargin, v, xLabelMargin, y, ypos, _i, _j, _k, _len, _ref, _ref1, _ref2, _results, _results1,
_this = this;
yInterval = (this.options.ymax - this.options.ymin) / (this.options.numLines - 1);
firstY = Math.ceil(this.options.ymin / yInterval) * yInterval;
lastY = Math.floor(this.options.ymax / yInterval) * yInterval;
for (lineY = _i = firstY; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += yInterval) {
v = Math.floor(lineY);
firstY = this.options.ymin;
lastY = this.options.ymax;
for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) {
v = lineY;
y = this.transY(v);
this.r.text(this.left - this.options.marginLeft / 2, y, this.yLabelFormat(v)).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end');
this.r.path("M" + this.left + "," + y + "H" + (this.left + this.width)).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth);
@ -276,17 +281,17 @@
if (this.columnLabels.length === 1 && this.options.xLabels === 'auto') {
return drawLabel(this.columnLabels[0], this.xvals[0]);
} else {
_ref = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat);
_ref1 = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat);
_results = [];
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
l = _ref[_j];
for (_j = 0, _len = _ref1.length; _j < _len; _j++) {
l = _ref1[_j];
_results.push(drawLabel(l[0], l[1]));
}
return _results;
}
} else {
_results1 = [];
for (i = _k = 0, _ref1 = this.columnLabels.length; 0 <= _ref1 ? _k <= _ref1 : _k >= _ref1; i = 0 <= _ref1 ? ++_k : --_k) {
for (i = _k = 0, _ref2 = this.columnLabels.length; 0 <= _ref2 ? _k <= _ref2 : _k >= _ref2; i = 0 <= _ref2 ? ++_k : --_k) {
labelText = this.columnLabels[this.columnLabels.length - i - 1];
_results1.push(drawLabel(labelText, i));
}
@ -477,7 +482,7 @@
};
Line.prototype.yLabelFormat = function(label) {
return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
return "" + this.options.preUnits + (Morris.commas(label.toFixed(this.precision || 0))) + this.options.postUnits;
};
return Line;

2
morris.min.js vendored

File diff suppressed because one or more lines are too long