gruff 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
1
  CHANGELOG
2
2
 
3
+ == 0.0.6
4
+
5
+ * Fixed hang when no data is passed.
6
+
3
7
  == 0.0.4
4
8
 
5
9
  * Added bar graphs
@@ -1,7 +1,9 @@
1
1
 
2
- require 'gruff/base'
2
+ # Extra full path added to fix some require errors on some installations.
3
3
 
4
- require 'gruff/area'
5
- require 'gruff/bar'
6
- require 'gruff/line'
7
- require 'gruff/pie'
4
+ require File.dirname(__FILE__) + '/gruff/base'
5
+
6
+ require File.dirname(__FILE__) + '/gruff/area'
7
+ require File.dirname(__FILE__) + '/gruff/bar'
8
+ require File.dirname(__FILE__) + '/gruff/line'
9
+ require File.dirname(__FILE__) + '/gruff/pie'
@@ -1,11 +1,13 @@
1
1
 
2
- require 'gruff/base'
2
+ require File.dirname(__FILE__) + '/base'
3
3
 
4
4
  class Gruff::Area < Gruff::Base
5
5
 
6
6
  def draw
7
7
  super
8
8
 
9
+ return unless @has_data
10
+
9
11
  @x_increment = @graph_width / (@column_count - 1).to_f
10
12
  @d = @d.stroke 'transparent'
11
13
 
@@ -1,11 +1,13 @@
1
1
 
2
- require 'gruff/base'
2
+ require File.dirname(__FILE__) + '/base'
3
3
 
4
4
  class Gruff::Bar < Gruff::Base
5
5
 
6
6
  def draw
7
7
  super
8
8
 
9
+ return unless @has_data
10
+
9
11
  # Setup spacing.
10
12
  #
11
13
  # Columns sit side-by-side.
@@ -17,7 +17,7 @@ require 'yaml'
17
17
 
18
18
  module Gruff
19
19
 
20
- VERSION = '0.0.5'
20
+ VERSION = '0.0.6'
21
21
 
22
22
  class Base
23
23
 
@@ -53,6 +53,7 @@ module Gruff
53
53
  @graph_width = 590.0
54
54
  @column_count = 0
55
55
  @maximum_value = 0
56
+ @has_data = false
56
57
  @data = Array.new
57
58
  @labels = Hash.new
58
59
  @labels_seen = Hash.new
@@ -171,6 +172,9 @@ module Gruff
171
172
  # Pre-normalize
172
173
  data_points.each do |data_point|
173
174
  @maximum_value = (data_point > @maximum_value) ? data_point : @maximum_value
175
+ if @maximum_value > 0
176
+ @has_data = true
177
+ end
174
178
  end
175
179
  end
176
180
 
@@ -207,6 +211,8 @@ protected
207
211
  # - legend
208
212
  # - title
209
213
  def setup_drawing
214
+ return unless @has_data # Maybe should be done in one of the following functions for more granularity.
215
+
210
216
  normalize()
211
217
  setup_graph_measurements()
212
218
 
@@ -219,6 +225,8 @@ protected
219
225
  def normalize
220
226
  if @norm_data.nil?
221
227
  @norm_data = Array.new
228
+ return unless @has_data
229
+
222
230
  @data.each do |data_row|
223
231
  norm_data_points = Array.new
224
232
  data_row[1].each do |data_point|
@@ -1,5 +1,5 @@
1
1
 
2
- require 'gruff/base'
2
+ require File.dirname(__FILE__) + '/base'
3
3
 
4
4
  class Gruff::Line < Gruff::Base
5
5
 
@@ -24,6 +24,8 @@ class Gruff::Line < Gruff::Base
24
24
  def draw
25
25
  super
26
26
 
27
+ return unless @has_data
28
+
27
29
  @x_increment = @graph_width / (@column_count - 1).to_f
28
30
  circle_radius = clip_value_if_greater_than(@columns / (@norm_data.first[1].size * 2.5), 5.0)
29
31
 
@@ -1,5 +1,5 @@
1
1
 
2
- require 'gruff/base'
2
+ require File.dirname(__FILE__) + '/base'
3
3
 
4
4
  class Gruff::Pie < Gruff::Base
5
5
 
@@ -8,6 +8,8 @@ class Gruff::Pie < Gruff::Base
8
8
 
9
9
  super
10
10
 
11
+ return unless @has_data
12
+
11
13
  diameter = @graph_height
12
14
  radius = @graph_height / 2.0
13
15
  top_x = @graph_left + (@graph_width - diameter) / 2.0
@@ -251,84 +251,24 @@ class TestGruffLine < Test::Unit::TestCase
251
251
  g.write("test/output/line_dots_tiny.png")
252
252
  end
253
253
 
254
- =begin
255
- def test_very_small_graphs
256
- [300, 200, 100].each do |size|
257
- g = Gruff::Line.new(size)
258
- g.title = "#{size}px Graph Test"
259
- g.labels = {
260
- 0 => '5/6',
261
- 2 => '5/15',
262
- 4 => '5/24',
263
- 6 => '5/30',
264
- }
265
- @datasets.each do |data|
266
- g.data(data[0], data[1])
267
- end
268
-
269
- # Default theme
270
- g.write("test/output/line_#{size}.png")
271
- end
272
- end
273
- =end
274
-
275
- =begin
276
- def test_for_blog
277
- g = Gruff::Line.new
278
- g.labels = {
279
- 0 => '2002',
280
- 2 => '2003',
281
- 4 => '2004',
282
- 6 => '2005',
283
- }
284
- @datasets.each do |data|
285
- g.data(data[0], data[1])
286
- end
254
+ def test_no_data
255
+ g = Gruff::Line.new(400)
256
+ g.title = "No Data"
287
257
 
288
258
  # Default theme
289
- g.title = "Gruff...graphs"
290
- g.write("test/output/1.png")
291
-
292
- g.theme_odeo
293
- g.title = "Themes, Colors, and Fonts!"
294
- g.font = File.expand_path('CREABBRG.TTF', ENV['MAGICK_FONT_PATH'])
295
- g.write("test/output/2.png")
296
-
297
- g.theme_rails_keynote
298
- g.title = "Source Coming Soon..."
299
- g.font = File.expand_path('Vera.ttf', ENV['MAGICK_FONT_PATH'])
300
- g.write("test/output/3.png")
301
-
259
+ g.write("test/output/line_no_data.png")
302
260
  end
303
261
 
304
- def test_for_blog_small
262
+
263
+ def test_no_data_other
305
264
  g = Gruff::Line.new(400)
306
- g.labels = {
307
- 0 => '2002',
308
- 2 => '2003',
309
- 4 => '2004',
310
- 6 => '2005',
311
- }
312
- @datasets.each do |data|
313
- g.data(data[0], data[1])
314
- end
265
+ g.title = "No Data Other"
315
266
 
316
- # Default theme
317
- g.title = "Gruff...graphs"
318
- g.write("test/output/1_small.png")
267
+ g.data(:gus, [0,0,0,0])
319
268
 
320
- g.theme_odeo
321
- g.title = "Themes, Colors, and Fonts!"
322
- g.font = File.expand_path('CREABBRG.TTF', ENV['MAGICK_FONT_PATH'])
323
- g.write("test/output/2_small.png")
324
-
325
- g.theme_rails_keynote
326
- g.title = "Source Coming Soon..."
327
- g.font = File.expand_path('Vera.ttf', ENV['MAGICK_FONT_PATH'])
328
- g.write("test/output/3_small.png")
329
-
269
+ # Default theme
270
+ g.write("test/output/line_no_data_other.png")
330
271
  end
331
- =end
332
272
 
333
273
 
334
274
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: gruff
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.5
7
- date: 2005-11-17 00:00:00 -08:00
6
+ version: 0.0.6
7
+ date: 2005-11-22 00:00:00 -08:00
8
8
  summary: Beautiful graphs for one or multiple datasets.
9
9
  require_paths:
10
10
  - lib
@@ -41,7 +41,7 @@ files:
41
41
  - lib/gruff/line.rb
42
42
  - lib/gruff/pie.rb
43
43
  - assets/bubble.png
44
- - assets/plastik-yellow.png
44
+ - assets/plastik
45
45
  - test/area_test.rb
46
46
  - test/bar_test.rb
47
47
  - test/line_test.rb
Binary file