Kelsin-lilygraph 0.2.2 → 0.2.4

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 +19 -6
  3. data/lilygraph.gemspec +1 -1
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.4
@@ -11,6 +11,7 @@ class Lilygraph
11
11
  :width => '100%',
12
12
  :indent => 2,
13
13
  :padding => 14,
14
+ :bar_text => true,
14
15
  :viewbox => {
15
16
  :width => 800,
16
17
  :height => 600
@@ -122,18 +123,30 @@ class Lilygraph
122
123
 
123
124
  x = (@options[:margin][:left] + (dx * data_index)).round
124
125
 
126
+ # Rectangles
125
127
  data.each_with_index do |number, number_index|
126
128
  color = Color::HSL.from_fraction(data_index * (1.0 / @data.size),1.0, 0.4 + (number_index * 0.2)).to_rgb
127
129
  height = ((dy / 10.0) * number).round
128
130
 
129
131
  bar_x = (x + ((dx - width) / 2.0) + (number_index * bar_width)).round
130
- text_x = (bar_x + (bar_width / 2.0)).round
131
-
132
132
  bar_y = @options[:viewbox][:height] - @options[:margin][:bottom] - height
133
- text_y = bar_y - 3
134
133
 
135
134
  xml.rect :fill => color.html, :stroke => color.html, 'stroke-width' => 0, :x => bar_x, :width => bar_width, :y => bar_y, :height => height - 1
136
- xml.text number, :x => text_x, :y => text_y, 'text-anchor' => 'middle'
135
+ end
136
+
137
+ # Text
138
+ if @options[:bar_text]
139
+ data.each_with_index do |number, number_index|
140
+ height = ((dy / 10.0) * number).round
141
+
142
+ bar_x = (x + ((dx - width) / 2.0) + (number_index * bar_width)).round
143
+ text_x = (bar_x + (bar_width / 2.0)).round
144
+
145
+ bar_y = @options[:viewbox][:height] - @options[:margin][:bottom] - height
146
+ text_y = bar_y - 3
147
+
148
+ xml.text number, :x => text_x, :y => text_y, 'text-anchor' => 'middle'
149
+ end
137
150
  end
138
151
  end
139
152
  end
@@ -169,10 +182,10 @@ class Lilygraph
169
182
  end
170
183
 
171
184
  def dx
172
- 700.0 / Float(number_of_slots)
185
+ graph_width / Float(number_of_slots)
173
186
  end
174
187
 
175
188
  def dy
176
- 4500.0 / Float(max)
189
+ (graph_height * 10.0) / Float(max)
177
190
  end
178
191
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lilygraph}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.4"
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: Kelsin-lilygraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Giroir