lilygraph 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/lilygraph.rb +10 -3
- data/lilygraph.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/lilygraph.rb
CHANGED
@@ -20,7 +20,7 @@ class Lilygraph
|
|
20
20
|
:indent => 2,
|
21
21
|
:padding => 14,
|
22
22
|
:legend => :right,
|
23
|
-
:bar_text =>
|
23
|
+
:bar_text => :number,
|
24
24
|
:type => :bar,
|
25
25
|
:viewbox => {
|
26
26
|
:width => 800,
|
@@ -224,9 +224,11 @@ class Lilygraph
|
|
224
224
|
x = (@options[:margin][:left] + (dx * data_index)).round
|
225
225
|
|
226
226
|
# Text
|
227
|
-
if @options[:bar_text]
|
227
|
+
if @options[:bar_text] != :none
|
228
228
|
last_bar_height = false
|
229
229
|
data.each_with_index do |number, number_index|
|
230
|
+
percent_total = data.inject(0) { |total, percent_number| total + percent_number }
|
231
|
+
|
230
232
|
if number > 0
|
231
233
|
height = ((dy / division) * number).round
|
232
234
|
|
@@ -243,7 +245,12 @@ class Lilygraph
|
|
243
245
|
last_bar_height = height
|
244
246
|
end
|
245
247
|
|
246
|
-
|
248
|
+
label = case @options[:bar_text]
|
249
|
+
when :number then number
|
250
|
+
when :percent then (100.0 * Float(number) / Float(percent_total)).round.to_s + "%"
|
251
|
+
end
|
252
|
+
|
253
|
+
xml.text label, :x => text_x, :y => text_y, 'text-anchor' => 'middle'
|
247
254
|
else
|
248
255
|
last_bar_height = false
|
249
256
|
end
|
data/lilygraph.gemspec
CHANGED