lilygraph 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/lilygraph.rb +10 -3
  3. data/lilygraph.gemspec +1 -1
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
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 => true,
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
- xml.text number, :x => text_x, :y => text_y, 'text-anchor' => 'middle'
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lilygraph}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christopher Giroir"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lilygraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Giroir