Add gridTextFamily and gridTextWeight options.

This commit is contained in:
Olly Smith 2013-05-12 16:25:06 +01:00
parent feca1ecaeb
commit 6220c40217
5 changed files with 26 additions and 15 deletions

View File

@ -177,6 +177,8 @@ class Morris.Bar extends Morris.Grid
drawXAxisLabel: (xPos, yPos, text) ->
label = @raphael.text(xPos, yPos, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
drawBar: (xPos, yPos, width, height, barColor) ->

View File

@ -65,6 +65,8 @@ class Morris.Grid extends Morris.EventEmitter
gridStrokeWidth: 0.5
gridTextColor: '#888'
gridTextSize: 12
gridTextFamily: 'sans-serif'
gridTextWeight: 'normal'
hideHover: false
yLabelFormat: null
xLabelAngle: 0
@ -239,10 +241,10 @@ class Morris.Grid extends Morris.EventEmitter
@bottom = @elementHeight - @options.padding
if @options.axes
yLabelWidths = for gridLine in @grid
@measureText(@yAxisFormat(gridLine), @options.gridTextSize).width
@measureText(@yAxisFormat(gridLine)).width
@left += Math.max(yLabelWidths...)
bottomOffsets = for i in [0...@data.length]
@measureText(@data[i].text, @options.gridTextSize, -@options.xLabelAngle).height
@measureText(@data[i].text, -@options.xLabelAngle).height
@bottom -= Math.max(bottomOffsets...)
@width = Math.max(1, @right - @left)
@height = Math.max(1, @bottom - @top)
@ -273,8 +275,12 @@ class Morris.Grid extends Morris.EventEmitter
# @private
#
measureText: (text, fontSize = 12, angle = 0) ->
tt = @raphael.text(100, 100, text).attr('font-size', fontSize).rotate(angle)
measureText: (text, angle = 0) ->
tt = @raphael.text(100, 100, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.rotate(angle)
ret = tt.getBBox()
tt.remove()
ret
@ -333,6 +339,8 @@ class Morris.Grid extends Morris.EventEmitter
drawYAxisLabel: (xPos, yPos, text) ->
@raphael.text(xPos, yPos, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
.attr('text-anchor', 'end')

View File

@ -277,6 +277,8 @@ class Morris.Line extends Morris.Grid
drawXAxisLabel: (xPos, yPos, text) ->
@raphael.text(xPos, yPos, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
drawLinePath: (path, lineColor) ->

View File

@ -126,6 +126,8 @@
gridStrokeWidth: 0.5,
gridTextColor: '#888',
gridTextSize: 12,
gridTextFamily: 'sans-serif',
gridTextWeight: 'normal',
hideHover: false,
yLabelFormat: null,
xLabelAngle: 0,
@ -364,7 +366,7 @@
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
gridLine = _ref[_i];
_results.push(this.measureText(this.yAxisFormat(gridLine), this.options.gridTextSize).width);
_results.push(this.measureText(this.yAxisFormat(gridLine)).width);
}
return _results;
}).call(this);
@ -373,7 +375,7 @@
var _i, _ref, _results;
_results = [];
for (i = _i = 0, _ref = this.data.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
_results.push(this.measureText(this.data[i].text, this.options.gridTextSize, -this.options.xLabelAngle).height);
_results.push(this.measureText(this.data[i].text, -this.options.xLabelAngle).height);
}
return _results;
}).call(this);
@ -412,15 +414,12 @@
}
};
Grid.prototype.measureText = function(text, fontSize, angle) {
Grid.prototype.measureText = function(text, angle) {
var ret, tt;
if (fontSize == null) {
fontSize = 12;
}
if (angle == null) {
angle = 0;
}
tt = this.raphael.text(100, 100, text).attr('font-size', fontSize).rotate(angle);
tt = this.raphael.text(100, 100, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).rotate(angle);
ret = tt.getBBox();
tt.remove();
return ret;
@ -501,7 +500,7 @@
};
Grid.prototype.drawYAxisLabel = function(xPos, yPos, text) {
return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end');
return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end');
};
Grid.prototype.drawGridLine = function(path) {
@ -1026,7 +1025,7 @@
};
Line.prototype.drawXAxisLabel = function(xPos, yPos, text) {
return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor);
return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor);
};
Line.prototype.drawLinePath = function(path, lineColor) {
@ -1497,7 +1496,7 @@
Bar.prototype.drawXAxisLabel = function(xPos, yPos, text) {
var label;
return label = this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor);
return label = this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor);
};
Bar.prototype.drawBar = function(xPos, yPos, width, height, barColor) {

2
morris.min.js vendored

File diff suppressed because one or more lines are too long