Fix Y label sizing.

This commit is contained in:
Olly Smith 2013-04-14 09:12:41 +01:00
parent 347533c8dd
commit 96530d7576
4 changed files with 18 additions and 10 deletions

View File

@ -17,7 +17,7 @@ var decimal_data = [];
for (var x = 0; x <= 360; x += 10) {
decimal_data.push({
x: x,
y: Math.sin(Math.PI * x / 180).toFixed(4)
y: 1.5 + 1.5 * Math.sin(Math.PI * x / 180).toFixed(4)
});
}
window.m = Morris.Line({
@ -29,7 +29,7 @@ window.m = Morris.Line({
parseTime: false,
hoverCallback: function (index, options) {
var row = options.data[index];
return "sin(" + row.x + ") = " + row.y;
return "1.5 + 1.5 sin(" + row.x + ") = " + row.y;
},
xLabelMargin: 10
});

View File

@ -234,10 +234,9 @@ class Morris.Grid extends Morris.EventEmitter
@top = @options.padding
@bottom = @elementHeight - @options.padding
if @options.axes
maxYLabelWidth = Math.max(
@measureText(@yAxisFormat(@ymin), @options.gridTextSize).width,
@measureText(@yAxisFormat(@ymax), @options.gridTextSize).width)
@left += maxYLabelWidth
yLabelWidths = for gridLine in @grid
@measureText(@yAxisFormat(gridLine), @options.gridTextSize).width
@left += Math.max(yLabelWidths...)
@bottom -= 1.5 * @options.gridTextSize
@width = Math.max(1, @right - @left)
@height = Math.max(1, @bottom - @top)

View File

@ -341,7 +341,7 @@
};
Grid.prototype._calc = function() {
var h, maxYLabelWidth, w;
var gridLine, h, w, yLabelWidths;
w = this.el.width();
h = this.el.height();
if (this.elementWidth !== w || this.elementHeight !== h || this.dirty) {
@ -353,8 +353,17 @@
this.top = this.options.padding;
this.bottom = this.elementHeight - this.options.padding;
if (this.options.axes) {
maxYLabelWidth = Math.max(this.measureText(this.yAxisFormat(this.ymin), this.options.gridTextSize).width, this.measureText(this.yAxisFormat(this.ymax), this.options.gridTextSize).width);
this.left += maxYLabelWidth;
yLabelWidths = (function() {
var _i, _len, _ref, _results;
_ref = this.grid;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
gridLine = _ref[_i];
_results.push(this.measureText(this.yAxisFormat(gridLine), this.options.gridTextSize).width);
}
return _results;
}).call(this);
this.left += Math.max.apply(Math, yLabelWidths);
this.bottom -= 1.5 * this.options.gridTextSize;
}
this.width = Math.max(1, this.right - this.left);

2
morris.min.js vendored

File diff suppressed because one or more lines are too long