Skip to content

Commit

Permalink
Tidy up decimal grids intervals a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
oesmith committed Jun 8, 2012
1 parent 380cc52 commit 0015b28
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
17 changes: 8 additions & 9 deletions morris.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ class Morris.Line
else
@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
@pointGrow = Raphael.animation r: @options.pointSize + 3, 25, 'linear'
@pointShrink = Raphael.animation r: @options.pointSize, 25, 'linear'
Expand All @@ -153,13 +159,6 @@ class Morris.Line
w = @el.width()
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
# calculate grid dimensions
@maxYLabelWidth = Math.max(
Expand Down Expand Up @@ -219,7 +218,7 @@ class Morris.Line


for lineY in [firstY..lastY] by @yInterval
v = lineY
v = parseFloat(lineY.toFixed(@precision))
y = @transY(v)
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v))
.attr('font-size', @options.gridTextSize)
Expand Down Expand Up @@ -395,7 +394,7 @@ class Morris.Line
return ret

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
#
Expand Down
16 changes: 8 additions & 8 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 0015b28

Please sign in to comment.