lib/lilygraph.rb in lilygraph-0.4.2 vs lib/lilygraph.rb in lilygraph-0.4.3
- old
+ new
@@ -165,11 +165,11 @@
xml.text label, :x => x, :y => y, :transform => "rotate(-45 #{x} #{y})"
end
end
# Bars
- xml.g 'font-size' => '8px', 'stroke-width' => 0.3 do |xml|
+ xml.g 'font-size' => '10px', 'stroke-width' => 0.3 do |xml|
@data.each_with_index do |data, data_index|
data = Array(data)
width = dx - @options[:padding]
bar_width = (width / Float(data.size)).round
@@ -199,18 +199,27 @@
xml.rect :fill => color, :stroke => color, 'stroke-width' => 0, :x => bar_x, :width => bar_width, :y => bar_y, :height => height - 1
end
# Text
if @options[:bar_text]
+ last_bar_height = false
data.each_with_index do |number, number_index|
height = ((dy / 10.0) * number).round
bar_x = (x + ((dx - width) / 2.0) + (number_index * bar_width)).round
text_x = (bar_x + (bar_width / 2.0)).round
bar_y = @options[:viewbox][:height] - @options[:margin][:bottom] - height
text_y = bar_y - 3
+ if last_bar_height && (last_bar_height < (number + 5) && last_bar_height > (number - 5))
+ text_y -= (14 - ((number - last_bar_height) * (dy / 10.0)))
+ last_bar_height = false
+ else
+ last_bar_height = number
+ end
+
+ # xml.text number, :x => text_x, :y => text_y + 1, 'text-anchor' => 'middle', 'font-size' => '13px', 'stroke-width' => 1.0, :fill => '#ffffff', :stroke => '#ffffff'
xml.text number, :x => text_x, :y => text_y, 'text-anchor' => 'middle'
end
end
end
end