Skip to content

Commit

Permalink
Add gridTextFamily and gridTextWeight options.
Browse files Browse the repository at this point in the history
  • Loading branch information
oesmith committed May 12, 2013
1 parent feca1ec commit 6220c40
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/morris.bar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
16 changes: 12 additions & 4 deletions lib/morris.grid.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand Down
2 changes: 2 additions & 0 deletions lib/morris.line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
19 changes: 9 additions & 10 deletions morris.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion morris.min.js

Large diffs are not rendered by default.

0 comments on commit 6220c40

Please sign in to comment.