gruff 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_dot.rb ADDED
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/gruff_test_case"
4
+
5
+ class TestGruffDot < GruffTestCase
6
+
7
+ # TODO Delete old output files once when starting tests
8
+
9
+ def setup
10
+ @datasets = [
11
+ [:Jimmy, [25, 36, 86, 39]],
12
+ [:Charles, [80, 54, 67, 54]],
13
+ [:Julie, [22, 29, 35, 38]],
14
+ #[:Jane, [95, 95, 95, 90, 85, 80, 88, 100]],
15
+ #[:Philip, [90, 34, 23, 12, 78, 89, 98, 88]],
16
+ #["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]],
17
+ ]
18
+ end
19
+
20
+ def test_dot_graph
21
+ g = setup_basic_graph
22
+ g.title = "Dot Graph Test"
23
+ g.write("test/output/dot_keynote.png")
24
+ end
25
+
26
+ def test_dot_graph_set_colors
27
+ g = Gruff::Dot.new
28
+ g.title = "Dot Graph With Manual Colors"
29
+ g.labels = {
30
+ 0 => '5/6',
31
+ 1 => '5/15',
32
+ 2 => '5/24',
33
+ 3 => '5/30',
34
+ }
35
+ g.data(:Art, [0, 5, 8, 15], '#990000')
36
+ g.data(:Philosophy, [10, 3, 2, 8], '#009900')
37
+ g.data(:Science, [2, 15, 8, 11], '#990099')
38
+
39
+ g.minimum_value = 0
40
+
41
+ g.write("test/output/dot_manual_colors.png")
42
+ end
43
+
44
+ def test_dot_graph_small
45
+ g = Gruff::Dot.new(400)
46
+ g.title = "Visual Multi-Line Dot Graph Test"
47
+ g.labels = {
48
+ 0 => '5/6',
49
+ 1 => '5/15',
50
+ 2 => '5/24',
51
+ 3 => '5/30',
52
+ }
53
+ @datasets.each do |data|
54
+ g.data(data[0], data[1])
55
+ end
56
+
57
+ g.write("test/output/dot_keynote_small.png")
58
+ end
59
+
60
+ # Somewhat worthless test. Should an error be thrown?
61
+ # def test_nil_font
62
+ # g = setup_basic_graph 400
63
+ # g.title = "Nil Font"
64
+ # g.font = nil
65
+ # g.write "test/output/dot_nil_font.png"
66
+ # end
67
+
68
+
69
+ def test_no_line_markers
70
+ g = setup_basic_graph(400)
71
+ g.title = "No Line Markers"
72
+ g.hide_line_markers = true
73
+ g.write("test/output/dot_no_line_markers.png")
74
+ end
75
+
76
+ def test_no_legend
77
+ g = setup_basic_graph(400)
78
+ g.title = "No Legend"
79
+ g.hide_legend = true
80
+ g.write("test/output/dot_no_legend.png")
81
+ end
82
+
83
+ def test_no_title
84
+ g = setup_basic_graph(400)
85
+ g.title = "No Title"
86
+ g.hide_title = true
87
+ g.write("test/output/dot_no_title.png")
88
+ end
89
+
90
+ def test_no_title_or_legend
91
+ g = setup_basic_graph(400)
92
+ g.title = "No Title or Legend"
93
+ g.hide_legend = true
94
+ g.hide_title = true
95
+ g.write("test/output/dot_no_title_or_legend.png")
96
+ end
97
+
98
+ def test_set_marker_count
99
+ g = setup_basic_graph(400)
100
+ g.title = "Set marker"
101
+ g.marker_count = 10
102
+ g.write("test/output/dot_set_marker.png")
103
+ end
104
+
105
+ def test_set_legend_box_size
106
+ g = setup_basic_graph(400)
107
+ g.title = "Set Small Legend Box Size"
108
+ g.legend_box_size = 10.0
109
+ g.write("test/output/dot_set_legend_box_size_sm.png")
110
+
111
+ g = setup_basic_graph(400)
112
+ g.title = "Set Large Legend Box Size"
113
+ g.legend_box_size = 50.0
114
+ g.write("test/output/dot_set_legend_box_size_lg.png")
115
+ end
116
+
117
+ def test_x_y_labels
118
+ g = setup_basic_graph(400)
119
+ g.title = "X Y Labels"
120
+ g.x_axis_label = 'Score (%)'
121
+ g.y_axis_label = "Students"
122
+ g.write("test/output/dot_x_y_labels.png")
123
+ end
124
+
125
+ def test_wide_graph
126
+ g = setup_basic_graph('800x400')
127
+ g.title = "Wide Graph"
128
+ g.write("test/output/dot_wide_graph.png")
129
+
130
+ g = setup_basic_graph('400x200')
131
+ g.title = "Wide Graph Small"
132
+ g.write("test/output/dot_wide_graph_small.png")
133
+ end
134
+
135
+
136
+ def test_tall_graph
137
+ g = setup_basic_graph('400x600')
138
+ g.title = "Tall Graph"
139
+ g.write("test/output/dot_tall_graph.png")
140
+
141
+ g = setup_basic_graph('200x400')
142
+ g.title = "Tall Graph Small"
143
+ g.write("test/output/dot_tall_graph_small.png")
144
+ end
145
+
146
+
147
+ def test_one_value
148
+ g = Gruff::Dot.new
149
+ g.title = "One Value Graph Test"
150
+ g.labels = {
151
+ 0 => '1',
152
+ 1 => '2'
153
+ }
154
+ g.data('one', [1,1])
155
+
156
+ g.write("test/output/dot_one_value.png")
157
+ end
158
+
159
+
160
+ def test_negative
161
+ g = Gruff::Dot.new
162
+ g.title = "Pos/Neg Dot Graph Test"
163
+ g.labels = {
164
+ 0 => '5/6',
165
+ 1 => '5/15',
166
+ 2 => '5/24',
167
+ 3 => '5/30',
168
+ }
169
+ g.data(:apples, [-1, 0, 4, -4])
170
+ g.data(:peaches, [10, 8, 6, 3])
171
+
172
+ g.write("test/output/dot_pos_neg.png")
173
+ end
174
+
175
+
176
+ def test_nearly_zero
177
+ g = Gruff::Dot.new
178
+ g.title = "Nearly Zero Graph"
179
+ g.labels = {
180
+ 0 => '5/6',
181
+ 1 => '5/15',
182
+ 2 => '5/24',
183
+ 3 => '5/30',
184
+ }
185
+ g.data(:apples, [1, 2, 3, 4])
186
+ g.data(:peaches, [4, 3, 2, 1])
187
+ g.minimum_value = 0
188
+ g.maximum_value = 10
189
+ g.write("test/output/dot_nearly_zero_max_10.png")
190
+ end
191
+
192
+ def test_y_axis_increment
193
+ generate_with_y_axis_increment 2.0
194
+ generate_with_y_axis_increment 1
195
+ generate_with_y_axis_increment 5
196
+ generate_with_y_axis_increment 20
197
+ end
198
+
199
+ def generate_with_y_axis_increment(increment)
200
+ g = Gruff::Dot.new
201
+ g.title = "Y Axis Set to #{increment}"
202
+ g.labels = {
203
+ 0 => '5/6',
204
+ 1 => '5/15',
205
+ 2 => '5/24',
206
+ 3 => '5/30',
207
+ }
208
+ g.y_axis_increment = increment
209
+ g.data(:apples, [1, 0.2, 0.5, 0.7])
210
+ g.data(:peaches, [2.5, 2.3, 2, 6.1])
211
+ g.write("test/output/dot_y_increment_#{increment}.png")
212
+ end
213
+
214
+
215
+ def test_custom_theme
216
+ g = Gruff::Dot.new
217
+ g.title = "Custom Theme"
218
+ g.font = File.expand_path('CREABBRG.TTF', ENV['MAGICK_FONT_PATH'])
219
+ g.title_font_size = 60
220
+ g.legend_font_size = 32
221
+ g.marker_font_size = 32
222
+ g.theme = {
223
+ :colors => %w(#efd250 #666699 #e5573f #9595e2),
224
+ :marker_color => 'white',
225
+ :font_color => 'blue',
226
+ :background_image => "assets/pc306715.jpg"
227
+ }
228
+ g.labels = {
229
+ 0 => '5/6',
230
+ 1 => '5/15',
231
+ 2 => '5/24',
232
+ 3 => '5/30',
233
+ }
234
+ g.data(:vancouver, [1, 2, 3, 4])
235
+ g.data(:seattle, [2, 4, 6, 8])
236
+ g.data(:portland, [3, 1, 7, 3])
237
+ g.data(:victoria, [4, 3, 5, 7])
238
+ g.minimum_value = 0
239
+ g.write("test/output/dot_themed.png")
240
+ end
241
+
242
+ def test_july_enhancements
243
+ g = Gruff::Dot.new(600)
244
+ g.hide_legend = true
245
+ g.title = "Full speed ahead"
246
+ g.labels = (0..10).inject({}) { |memo, i| memo.merge({ i => (i*10).to_s}) }
247
+ g.data(:apples, (0..9).map { rand(20)/10.0 })
248
+ g.y_axis_increment = 1.0
249
+ g.x_axis_label = 'Score (%)'
250
+ g.y_axis_label = 'Students'
251
+ write_test_file g, 'enhancements.png'
252
+ end
253
+
254
+
255
+ protected
256
+
257
+ def setup_basic_graph(size=800)
258
+ g = Gruff::Dot.new(size)
259
+ g.title = "My Dot Graph"
260
+ g.labels = {
261
+ 0 => '5/6',
262
+ 1 => '5/15',
263
+ 2 => '5/24',
264
+ 3 => '5/30',
265
+ }
266
+ @datasets.each do |data|
267
+ g.data(data[0], data[1])
268
+ end
269
+ g
270
+ end
271
+
272
+ end
273
+
data/test/test_line.rb CHANGED
@@ -132,6 +132,8 @@ class TestGruffLine < GruffTestCase
132
132
  g.title = "Very Large Values Line Graph Test"
133
133
  g.baseline_value = 50_000
134
134
  g.baseline_color = 'green'
135
+ g.dot_radius = 15
136
+ g.line_width = 3
135
137
  @datasets.each do |data|
136
138
  g.data(data[0], data[1])
137
139
  end
@@ -147,9 +149,20 @@ class TestGruffLine < GruffTestCase
147
149
  #
148
150
  # end
149
151
  #
150
- # def test_request_too_many_colors
151
- #
152
- # end
152
+
153
+ def test_request_too_many_colors
154
+ g = Gruff::Line.new
155
+ g.title = "More Sets Than in Color Array"
156
+ # g.theme = {} # Sets theme with only black and white
157
+ @datasets.each do |data|
158
+ g.data(data[0], data[1])
159
+ end
160
+ @datasets.each do |data|
161
+ g.data("#{data[0]}-B", data[1].map {|d| d + 20})
162
+ end
163
+ g.write("test/output/line_more_sets_than_colors.png")
164
+ end
165
+
153
166
  #
154
167
  # def test_add_data
155
168
  #
@@ -435,8 +448,38 @@ class TestGruffLine < GruffTestCase
435
448
  g.hide_line_markers = false
436
449
  g.write('test/output/line_no_hide.png')
437
450
  end
451
+
438
452
 
439
- protected
453
+ def test_jruby_error
454
+ g = Gruff::Line.new
455
+ g.theme = {
456
+ :colors => ['#7F0099', '#2F85ED', '#2FED09','#EC962F'],
457
+ :marker_color => '#aaa',
458
+ :background_colors => ['#E8E8E8','#B9FD6C']
459
+ }
460
+ g.hide_title = true
461
+
462
+ g.legend_font_size = 12
463
+ g.marker_font_size = 16
464
+ g.hide_dots = false
465
+ g.label_max_decimals = 1
466
+
467
+ g.write('test/output/line_jruby_error.png')
468
+ end
469
+
470
+ private
471
+
472
+ def bmi(params={})
473
+ g = basic_graph()
474
+
475
+ g.y_axis_label = 'BMI'
476
+
477
+ bmis = [24.3, 23.9, 23.7, 23.7, 23.6, 23.9, 23.6, 23.7, 23.4, 23.4, 23.4, 22.9]
478
+
479
+ g.data( 'BMI', bmis )
480
+ g.hide_legend = true
481
+ return g
482
+ end
440
483
 
441
484
  # TODO Reset data after each theme
442
485
  def line_graph_with_themes(size=nil)
@@ -6,6 +6,7 @@ class TestMiniBar < GruffTestCase
6
6
  def test_simple_bar
7
7
  setup_single_dataset
8
8
  g = setup_basic_graph(Gruff::Mini::Bar, 200)
9
+ g.hide_mini_legend = true
9
10
  write_test_file g, 'mini_bar.png'
10
11
  end
11
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoffrey Grosenbach
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-18 00:00:00 -07:00
12
+ date: 2009-08-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.7.0
23
+ version: 1.12.1
24
24
  version:
25
25
  description: Beautiful graphs for one or multiple datasets. Can be used on websites or in documents.
26
26
  email: boss@topfunky.com
@@ -74,6 +74,7 @@ files:
74
74
  - lib/gruff/base.rb
75
75
  - lib/gruff/bullet.rb
76
76
  - lib/gruff/deprecated.rb
77
+ - lib/gruff/dot.rb
77
78
  - lib/gruff/line.rb
78
79
  - lib/gruff/mini/bar.rb
79
80
  - lib/gruff/mini/legend.rb
@@ -98,6 +99,7 @@ files:
98
99
  - test/test_bar.rb
99
100
  - test/test_base.rb
100
101
  - test/test_bullet.rb
102
+ - test/test_dot.rb
101
103
  - test/test_legend.rb
102
104
  - test/test_line.rb
103
105
  - test/test_mini_bar.rb
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  requirements: []
136
138
 
137
139
  rubyforge_project: gruff
138
- rubygems_version: 1.2.0
140
+ rubygems_version: 1.3.1
139
141
  signing_key:
140
142
  specification_version: 2
141
143
  summary: Beautiful graphs for one or multiple datasets.
@@ -145,6 +147,7 @@ test_files:
145
147
  - test/test_bar.rb
146
148
  - test/test_base.rb
147
149
  - test/test_bullet.rb
150
+ - test/test_dot.rb
148
151
  - test/test_legend.rb
149
152
  - test/test_line.rb
150
153
  - test/test_mini_bar.rb