Skip to content

Commit

Permalink
Merge pull request #15 from vicvega/master
Browse files Browse the repository at this point in the history
Marker labels accuracy
  • Loading branch information
topfunky committed Nov 10, 2011
2 parents 6e1a2b0 + a250f1e commit 508a80d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 71 deletions.
14 changes: 8 additions & 6 deletions lib/gruff/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'RMagick'
require 'bigdecimal'

require File.dirname(__FILE__) + '/deprecated'

Expand Down Expand Up @@ -41,7 +42,7 @@ class Base
DEFAULT_MARGIN = 20.0

DEFAULT_TARGET_WIDTH = 800

THOUSAND_SEPARATOR = ','

# Blank space above the graph
Expand All @@ -55,10 +56,10 @@ class Base

# Blank space to the left of the graph
attr_accessor :left_margin

# Blank space below the title
attr_accessor :title_margin

# Blank space below the legend
attr_accessor :legend_margin

Expand Down Expand Up @@ -223,7 +224,7 @@ def initialize_ivars
@marker_font_size = 21.0
@legend_font_size = 20.0
@title_font_size = 36.0

@top_margin = @bottom_margin = @left_margin = @right_margin = DEFAULT_MARGIN
@legend_margin = LEGEND_MARGIN
@title_margin = TITLE_MARGIN
Expand Down Expand Up @@ -698,7 +699,8 @@ def draw_line_markers
@d = @d.fill(@marker_color)
@d = @d.line(@graph_left, y, @graph_right, y)

marker_label = index * @increment + @minimum_value.to_f
marker_label = (BigDecimal(index.to_s) * BigDecimal(@increment.to_s) +
BigDecimal(@minimum_value.to_s)).to_f

unless @hide_line_numbers
@d.fill = @font_color
Expand Down Expand Up @@ -1072,7 +1074,7 @@ def label(value)
else
value.to_s
end

parts = label.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{THOUSAND_SEPARATOR}")
parts.join('.')
Expand Down
Loading

0 comments on commit 508a80d

Please sign in to comment.