Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decimal #58

Merged
merged 3 commits into from
Jun 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions morris.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ class Morris.Line
calc: ->
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 @@ -203,11 +211,12 @@ class Morris.Line
#
drawGrid: ->
# draw y axis labels, horizontal lines
yInterval = (@options.ymax - @options.ymin) / (@options.numLines - 1)
firstY = Math.ceil(@options.ymin / yInterval) * yInterval
lastY = Math.floor(@options.ymax / yInterval) * yInterval
for lineY in [firstY..lastY] by yInterval
v = Math.floor(lineY)
firstY = @options.ymin
lastY = @options.ymax


for lineY in [firstY..lastY] by @yInterval
v = lineY
y = @transY(v)
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v))
.attr('font-size', @options.gridTextSize)
Expand Down Expand Up @@ -383,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
27 changes: 16 additions & 11 deletions morris.js

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