Kelsin-lilygraph 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/lilygraph.rb +19 -6
- data/lilygraph.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/lib/lilygraph.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
185
|
+
graph_width / Float(number_of_slots)
|
173
186
|
end
|
174
187
|
|
175
188
|
def dy
|
176
|
-
|
189
|
+
(graph_height * 10.0) / Float(max)
|
177
190
|
end
|
178
191
|
end
|
data/lilygraph.gemspec
CHANGED