mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-13 07:11:12 +01:00
Tidy up decimal grids intervals a little.
This commit is contained in:
parent
380cc5217a
commit
0015b28ef2
3 changed files with 17 additions and 18 deletions
|
@ -127,6 +127,12 @@ class Morris.Line
|
||||||
else
|
else
|
||||||
@options.ymin = ymin
|
@options.ymin = ymin
|
||||||
|
|
||||||
|
@yInterval = (@options.ymax - @options.ymin) / (@options.numLines - 1)
|
||||||
|
if @yInterval > 0 and @yInterval < 1
|
||||||
|
@precision = -Math.floor(Math.log(@yInterval) / Math.log(10))
|
||||||
|
else
|
||||||
|
@precision = 0
|
||||||
|
|
||||||
# Some instance variables for later
|
# Some instance variables for later
|
||||||
@pointGrow = Raphael.animation r: @options.pointSize + 3, 25, 'linear'
|
@pointGrow = Raphael.animation r: @options.pointSize + 3, 25, 'linear'
|
||||||
@pointShrink = Raphael.animation r: @options.pointSize, 25, 'linear'
|
@pointShrink = Raphael.animation r: @options.pointSize, 25, 'linear'
|
||||||
|
@ -153,13 +159,6 @@ class Morris.Line
|
||||||
w = @el.width()
|
w = @el.width()
|
||||||
h = @el.height()
|
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
|
if @elementWidth != w or @elementHeight != h
|
||||||
# calculate grid dimensions
|
# calculate grid dimensions
|
||||||
@maxYLabelWidth = Math.max(
|
@maxYLabelWidth = Math.max(
|
||||||
|
@ -219,7 +218,7 @@ class Morris.Line
|
||||||
|
|
||||||
|
|
||||||
for lineY in [firstY..lastY] by @yInterval
|
for lineY in [firstY..lastY] by @yInterval
|
||||||
v = lineY
|
v = parseFloat(lineY.toFixed(@precision))
|
||||||
y = @transY(v)
|
y = @transY(v)
|
||||||
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v))
|
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v))
|
||||||
.attr('font-size', @options.gridTextSize)
|
.attr('font-size', @options.gridTextSize)
|
||||||
|
@ -395,7 +394,7 @@ class Morris.Line
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
yLabelFormat: (label) ->
|
yLabelFormat: (label) ->
|
||||||
"#{@options.preUnits}#{Morris.commas(label.toFixed(@precision || 0))}#{@options.postUnits}"
|
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"
|
||||||
|
|
||||||
# parse a date into a javascript timestamp
|
# parse a date into a javascript timestamp
|
||||||
#
|
#
|
||||||
|
|
16
morris.js
16
morris.js
|
@ -152,6 +152,12 @@
|
||||||
this.options.ymin = ymin;
|
this.options.ymin = ymin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.yInterval = (this.options.ymax - this.options.ymin) / (this.options.numLines - 1);
|
||||||
|
if (this.yInterval > 0 && this.yInterval < 1) {
|
||||||
|
this.precision = -Math.floor(Math.log(this.yInterval) / Math.log(10));
|
||||||
|
} else {
|
||||||
|
this.precision = 0;
|
||||||
|
}
|
||||||
this.pointGrow = Raphael.animation({
|
this.pointGrow = Raphael.animation({
|
||||||
r: this.options.pointSize + 3
|
r: this.options.pointSize + 3
|
||||||
}, 25, 'linear');
|
}, 25, 'linear');
|
||||||
|
@ -185,12 +191,6 @@
|
||||||
_this = this;
|
_this = this;
|
||||||
w = this.el.width();
|
w = this.el.width();
|
||||||
h = this.el.height();
|
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) {
|
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.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;
|
this.left = this.maxYLabelWidth + this.options.marginLeft;
|
||||||
|
@ -259,7 +259,7 @@
|
||||||
firstY = this.options.ymin;
|
firstY = this.options.ymin;
|
||||||
lastY = this.options.ymax;
|
lastY = this.options.ymax;
|
||||||
for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) {
|
for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) {
|
||||||
v = lineY;
|
v = parseFloat(lineY.toFixed(this.precision));
|
||||||
y = this.transY(v);
|
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.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);
|
this.r.path("M" + this.left + "," + y + "H" + (this.left + this.width)).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth);
|
||||||
|
@ -482,7 +482,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Line.prototype.yLabelFormat = function(label) {
|
Line.prototype.yLabelFormat = function(label) {
|
||||||
return "" + this.options.preUnits + (Morris.commas(label.toFixed(this.precision || 0))) + this.options.postUnits;
|
return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
|
||||||
};
|
};
|
||||||
|
|
||||||
return Line;
|
return Line;
|
||||||
|
|
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