Skip to content

Commit

Permalink
Move the formatting into yLabelFormat.
Browse files Browse the repository at this point in the history
In order to let the user to get rid of the precision, she can provide a custom
yLabelFormat funciton.
  • Loading branch information
pelletier committed May 14, 2012
1 parent 7def73f commit e329928
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions morris.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class Morris.Line
if @elementWidth != w or @elementHeight != h
# calculate grid dimensions
@maxYLabelWidth = Math.max(
@measureText(@yLabelFormat(@options.ymin.toFixed(@precision)), @options.gridTextSize).width,
@measureText(@yLabelFormat(@options.ymax.toFixed(@precision)), @options.gridTextSize).width)
@measureText(@yLabelFormat(@options.ymin), @options.gridTextSize).width,
@measureText(@yLabelFormat(@options.ymax), @options.gridTextSize).width)
@left = @maxYLabelWidth + @options.marginLeft
@width = @el.width() - @left - @options.marginRight
@height = @el.height() - @options.marginTop - @options.marginBottom
Expand Down Expand Up @@ -218,7 +218,7 @@ class Morris.Line
for lineY in [firstY..lastY] by @yInterval
v = lineY
y = @transY(v)
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v.toFixed(@precision)))
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v))
.attr('font-size', @options.gridTextSize)
.attr('fill', @options.gridTextColor)
.attr('text-anchor', 'end')
Expand Down Expand Up @@ -392,7 +392,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
#
Expand Down
6 changes: 3 additions & 3 deletions morris.js

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

Loading

0 comments on commit e329928

Please sign in to comment.