pfsc-gruff 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/History.txt +117 -0
  2. data/MIT-LICENSE +21 -0
  3. data/Manifest.txt +81 -0
  4. data/README.txt +40 -0
  5. data/Rakefile +55 -0
  6. data/assets/bubble.png +0 -0
  7. data/assets/city_scene/background/0000.png +0 -0
  8. data/assets/city_scene/background/0600.png +0 -0
  9. data/assets/city_scene/background/2000.png +0 -0
  10. data/assets/city_scene/clouds/cloudy.png +0 -0
  11. data/assets/city_scene/clouds/partly_cloudy.png +0 -0
  12. data/assets/city_scene/clouds/stormy.png +0 -0
  13. data/assets/city_scene/grass/default.png +0 -0
  14. data/assets/city_scene/haze/true.png +0 -0
  15. data/assets/city_scene/number_sample/1.png +0 -0
  16. data/assets/city_scene/number_sample/2.png +0 -0
  17. data/assets/city_scene/number_sample/default.png +0 -0
  18. data/assets/city_scene/sky/0000.png +0 -0
  19. data/assets/city_scene/sky/0200.png +0 -0
  20. data/assets/city_scene/sky/0400.png +0 -0
  21. data/assets/city_scene/sky/0600.png +0 -0
  22. data/assets/city_scene/sky/0800.png +0 -0
  23. data/assets/city_scene/sky/1000.png +0 -0
  24. data/assets/city_scene/sky/1200.png +0 -0
  25. data/assets/city_scene/sky/1400.png +0 -0
  26. data/assets/city_scene/sky/1500.png +0 -0
  27. data/assets/city_scene/sky/1700.png +0 -0
  28. data/assets/city_scene/sky/2000.png +0 -0
  29. data/assets/pc306715.jpg +0 -0
  30. data/assets/plastik/blue.png +0 -0
  31. data/assets/plastik/green.png +0 -0
  32. data/assets/plastik/red.png +0 -0
  33. data/init.rb +2 -0
  34. data/lib/gruff.rb +28 -0
  35. data/lib/gruff/accumulator_bar.rb +27 -0
  36. data/lib/gruff/area.rb +58 -0
  37. data/lib/gruff/bar.rb +87 -0
  38. data/lib/gruff/bar_conversion.rb +46 -0
  39. data/lib/gruff/base.rb +1123 -0
  40. data/lib/gruff/bullet.rb +109 -0
  41. data/lib/gruff/deprecated.rb +39 -0
  42. data/lib/gruff/dot.rb +113 -0
  43. data/lib/gruff/line.rb +135 -0
  44. data/lib/gruff/mini/bar.rb +37 -0
  45. data/lib/gruff/mini/legend.rb +109 -0
  46. data/lib/gruff/mini/pie.rb +36 -0
  47. data/lib/gruff/mini/side_bar.rb +35 -0
  48. data/lib/gruff/net.rb +140 -0
  49. data/lib/gruff/photo_bar.rb +100 -0
  50. data/lib/gruff/pie.rb +126 -0
  51. data/lib/gruff/scene.rb +209 -0
  52. data/lib/gruff/side_bar.rb +118 -0
  53. data/lib/gruff/side_stacked_bar.rb +77 -0
  54. data/lib/gruff/spider.rb +130 -0
  55. data/lib/gruff/stacked_area.rb +67 -0
  56. data/lib/gruff/stacked_bar.rb +57 -0
  57. data/lib/gruff/stacked_mixin.rb +23 -0
  58. data/rails_generators/gruff/gruff_generator.rb +63 -0
  59. data/rails_generators/gruff/templates/controller.rb +32 -0
  60. data/rails_generators/gruff/templates/functional_test.rb +24 -0
  61. data/test/gruff_test_case.rb +123 -0
  62. data/test/test_accumulator_bar.rb +50 -0
  63. data/test/test_area.rb +134 -0
  64. data/test/test_bar.rb +321 -0
  65. data/test/test_base.rb +8 -0
  66. data/test/test_bullet.rb +26 -0
  67. data/test/test_dot.rb +273 -0
  68. data/test/test_legend.rb +68 -0
  69. data/test/test_line.rb +556 -0
  70. data/test/test_mini_bar.rb +33 -0
  71. data/test/test_mini_pie.rb +26 -0
  72. data/test/test_mini_side_bar.rb +37 -0
  73. data/test/test_net.rb +230 -0
  74. data/test/test_photo.rb +41 -0
  75. data/test/test_pie.rb +154 -0
  76. data/test/test_scene.rb +100 -0
  77. data/test/test_side_bar.rb +29 -0
  78. data/test/test_sidestacked_bar.rb +89 -0
  79. data/test/test_spider.rb +216 -0
  80. data/test/test_stacked_area.rb +52 -0
  81. data/test/test_stacked_bar.rb +52 -0
  82. metadata +186 -0
@@ -0,0 +1,321 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/gruff_test_case"
4
+
5
+ class TestGruffBar < 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_bar_graph
21
+ g = setup_basic_graph
22
+ g.title = "Bar Graph Test"
23
+ g.title_margin = 100
24
+ g.write("test/output/bar_keynote.png")
25
+
26
+ g = setup_basic_graph
27
+ g.title = "Visual Multi-Line Bar Graph Test"
28
+ g.theme_rails_keynote
29
+ g.write("test/output/bar_rails_keynote.png")
30
+
31
+ g = setup_basic_graph
32
+ g.title = "Visual Multi-Line Bar Graph Test"
33
+ g.theme_odeo
34
+ g.write("test/output/bar_odeo.png")
35
+ end
36
+
37
+ def test_thousand_separators
38
+ g = Gruff::Bar.new(600)
39
+ g.title = "Formatted numbers"
40
+ g.marker_count = 8
41
+ g.data("data", [4025, 1024, 50257, 703672, 1580456])
42
+ g.write("test/output/bar_formatted_numbers.png")
43
+ end
44
+
45
+ def test_bar_graph_set_colors
46
+ g = Gruff::Bar.new
47
+ g.title = "Bar Graph With Manual Colors"
48
+ g.legend_margin = 50
49
+ g.labels = {
50
+ 0 => '5/6',
51
+ 1 => '5/15',
52
+ 2 => '5/24',
53
+ 3 => '5/30',
54
+ }
55
+ g.data(:Art, [0, 5, 8, 15], '#990000')
56
+ g.data(:Philosophy, [10, 3, 2, 8], '#009900')
57
+ g.data(:Science, [2, 15, 8, 11], '#990099')
58
+
59
+ g.minimum_value = 0
60
+
61
+ g.write("test/output/bar_manual_colors.png")
62
+ end
63
+
64
+ def test_bar_graph_small
65
+ g = Gruff::Bar.new(400)
66
+ g.title = "Visual Multi-Line Bar Graph Test"
67
+ g.labels = {
68
+ 0 => '5/6',
69
+ 1 => '5/15',
70
+ 2 => '5/24',
71
+ 3 => '5/30',
72
+ }
73
+ @datasets.each do |data|
74
+ g.data(data[0], data[1])
75
+ end
76
+
77
+ g.write("test/output/bar_keynote_small.png")
78
+ end
79
+
80
+ # Somewhat worthless test. Should an error be thrown?
81
+ # def test_nil_font
82
+ # g = setup_basic_graph 400
83
+ # g.title = "Nil Font"
84
+ # g.font = nil
85
+ # g.write "test/output/bar_nil_font.png"
86
+ # end
87
+
88
+
89
+ def test_no_line_markers
90
+ g = setup_basic_graph(400)
91
+ g.title = "No Line Markers"
92
+ g.hide_line_markers = true
93
+ g.write("test/output/bar_no_line_markers.png")
94
+ end
95
+
96
+ def test_no_legend
97
+ g = setup_basic_graph(400)
98
+ g.title = "No Legend"
99
+ g.hide_legend = true
100
+ g.write("test/output/bar_no_legend.png")
101
+ end
102
+
103
+ def test_no_title
104
+ g = setup_basic_graph(400)
105
+ g.title = "No Title"
106
+ g.hide_title = true
107
+ g.write("test/output/bar_no_title.png")
108
+ end
109
+
110
+ def test_no_title_or_legend
111
+ g = setup_basic_graph(400)
112
+ g.title = "No Title or Legend"
113
+ g.hide_legend = true
114
+ g.hide_title = true
115
+ g.write("test/output/bar_no_title_or_legend.png")
116
+ end
117
+
118
+ def test_set_marker_count
119
+ g = setup_basic_graph(400)
120
+ g.title = "Set marker"
121
+ g.marker_count = 10
122
+ g.write("test/output/bar_set_marker.png")
123
+ end
124
+
125
+ def test_set_legend_box_size
126
+ g = setup_basic_graph(400)
127
+ g.title = "Set Small Legend Box Size"
128
+ g.legend_box_size = 10.0
129
+ g.write("test/output/bar_set_legend_box_size_sm.png")
130
+
131
+ g = setup_basic_graph(400)
132
+ g.title = "Set Large Legend Box Size"
133
+ g.legend_box_size = 50.0
134
+ g.write("test/output/bar_set_legend_box_size_lg.png")
135
+ end
136
+
137
+ def test_x_y_labels
138
+ g = setup_basic_graph(400)
139
+ g.title = "X Y Labels"
140
+ g.x_axis_label = 'Score (%)'
141
+ g.y_axis_label = "Students"
142
+ g.write("test/output/bar_x_y_labels.png")
143
+ end
144
+
145
+ def test_wide_graph
146
+ g = setup_basic_graph('800x400')
147
+ g.title = "Wide Graph"
148
+ g.write("test/output/bar_wide_graph.png")
149
+
150
+ g = setup_basic_graph('400x200')
151
+ g.title = "Wide Graph Small"
152
+ g.write("test/output/bar_wide_graph_small.png")
153
+ end
154
+
155
+
156
+ def test_tall_graph
157
+ g = setup_basic_graph('400x600')
158
+ g.title = "Tall Graph"
159
+ g.write("test/output/bar_tall_graph.png")
160
+
161
+ g = setup_basic_graph('200x400')
162
+ g.title = "Tall Graph Small"
163
+ g.write("test/output/bar_tall_graph_small.png")
164
+ end
165
+
166
+
167
+ def test_one_value
168
+ g = Gruff::Bar.new
169
+ g.title = "One Value Graph Test"
170
+ g.labels = {
171
+ 0 => '1',
172
+ 1 => '2'
173
+ }
174
+ g.data('one', [1,1])
175
+
176
+ g.write("test/output/bar_one_value.png")
177
+ end
178
+
179
+
180
+ def test_negative
181
+ g = Gruff::Bar.new
182
+ g.title = "Pos/Neg Bar Graph Test"
183
+ g.labels = {
184
+ 0 => '5/6',
185
+ 1 => '5/15',
186
+ 2 => '5/24',
187
+ 3 => '5/30',
188
+ }
189
+ g.data(:apples, [-1, 0, 4, -4])
190
+ g.data(:peaches, [10, 8, 6, 3])
191
+
192
+ g.write("test/output/bar_pos_neg.png")
193
+ end
194
+
195
+
196
+ def test_nearly_zero
197
+ g = Gruff::Bar.new
198
+ g.title = "Nearly Zero Graph"
199
+ g.labels = {
200
+ 0 => '5/6',
201
+ 1 => '5/15',
202
+ 2 => '5/24',
203
+ 3 => '5/30',
204
+ }
205
+ g.data(:apples, [1, 2, 3, 4])
206
+ g.data(:peaches, [4, 3, 2, 1])
207
+ g.minimum_value = 0
208
+ g.maximum_value = 10
209
+ g.write("test/output/bar_nearly_zero_max_10.png")
210
+ end
211
+
212
+ def test_y_axis_increment
213
+ generate_with_y_axis_increment 2.0
214
+ generate_with_y_axis_increment 1
215
+ generate_with_y_axis_increment 5
216
+ generate_with_y_axis_increment 20
217
+ end
218
+
219
+ def generate_with_y_axis_increment(increment)
220
+ g = Gruff::Bar.new
221
+ g.title = "Y Axis Set to #{increment}"
222
+ g.labels = {
223
+ 0 => '5/6',
224
+ 1 => '5/15',
225
+ 2 => '5/24',
226
+ 3 => '5/30',
227
+ }
228
+ g.y_axis_increment = increment
229
+ g.data(:apples, [1, 0.2, 0.5, 0.7])
230
+ g.data(:peaches, [2.5, 2.3, 2, 6.1])
231
+ g.write("test/output/bar_y_increment_#{increment}.png")
232
+ end
233
+
234
+
235
+ def test_custom_theme
236
+ g = Gruff::Bar.new
237
+ g.title = "Custom Theme"
238
+ g.font = File.expand_path('CREABBRG.TTF', ENV['MAGICK_FONT_PATH'])
239
+ g.title_font_size = 60
240
+ g.legend_font_size = 32
241
+ g.marker_font_size = 32
242
+ g.theme = {
243
+ :colors => %w(#efd250 #666699 #e5573f #9595e2),
244
+ :marker_color => 'white',
245
+ :font_color => 'blue',
246
+ :background_image => "assets/pc306715.jpg"
247
+ }
248
+ g.labels = {
249
+ 0 => '5/6',
250
+ 1 => '5/15',
251
+ 2 => '5/24',
252
+ 3 => '5/30',
253
+ }
254
+ g.data(:vancouver, [1, 2, 3, 4])
255
+ g.data(:seattle, [2, 4, 6, 8])
256
+ g.data(:portland, [3, 1, 7, 3])
257
+ g.data(:victoria, [4, 3, 5, 7])
258
+ g.minimum_value = 0
259
+ g.write("test/output/bar_themed.png")
260
+ end
261
+
262
+ def test_legend_should_not_overlap
263
+ g = Gruff::Bar.new(400)
264
+ g.theme_37signals()
265
+ g.title = 'My Graph'
266
+ g.data("Apples Oranges Watermelon Apples Oranges", [1, 2, 3, 4, 4, 3])
267
+ g.data('Oranges', [4, 8, 7, 9, 8, 9])
268
+ g.data('Watermelon', [2, 3, 1, 5, 6, 8])
269
+ g.data('Peaches', [9, 9, 10, 8, 7, 9])
270
+ g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
271
+ g.write("test/output/bar_long_legend_text.png")
272
+ end
273
+
274
+ def test_july_enhancements
275
+ g = Gruff::Bar.new(600)
276
+ g.hide_legend = true
277
+ g.title = "Full speed ahead"
278
+ g.labels = (0..10).inject({}) { |memo, i| memo.merge({ i => (i*10).to_s}) }
279
+ g.data(:apples, (0..9).map { rand(20)/10.0 })
280
+ g.y_axis_increment = 1.0
281
+ g.x_axis_label = 'Score (%)'
282
+ g.y_axis_label = 'Students'
283
+ write_test_file g, 'enhancements.png'
284
+ end
285
+
286
+ def test_bar_spacing
287
+ g = setup_basic_graph
288
+ g.bar_spacing = 0
289
+ g.title = "100% spacing between bars"
290
+ g.write("test/output/bar_spacing_full.png")
291
+
292
+ g = setup_basic_graph
293
+ g.bar_spacing = 0.5
294
+ g.title = "50% spacing between bars"
295
+ g.write("test/output/bar_spacing_half.png")
296
+
297
+ g = setup_basic_graph
298
+ g.bar_spacing = 1
299
+ g.title = "0% spacing between bars"
300
+ g.write("test/output/bar_spacing_none.png")
301
+ end
302
+
303
+ protected
304
+
305
+ def setup_basic_graph(size=800)
306
+ g = Gruff::Bar.new(size)
307
+ g.title = "My Bar Graph"
308
+ g.labels = {
309
+ 0 => '5/6',
310
+ 1 => '5/15',
311
+ 2 => '5/24',
312
+ 3 => '5/30',
313
+ }
314
+ @datasets.each do |data|
315
+ g.data(data[0], data[1])
316
+ end
317
+ g
318
+ end
319
+
320
+ end
321
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/gruff_test_case"
4
+
5
+ class TestGruffBase < GruffTestCase
6
+
7
+
8
+ end
@@ -0,0 +1,26 @@
1
+ # require File.dirname(__FILE__) + "/gruff_test_case"
2
+ #
3
+ # class TestGruffBullet < GruffTestCase
4
+ #
5
+ # def setup
6
+ # @data_args = [75, 100, {
7
+ # :target => 80,
8
+ # :low => 50,
9
+ # :high => 90
10
+ # }]
11
+ # end
12
+ #
13
+ # def test_bullet_graph
14
+ # g = Gruff::Bullet.new
15
+ # g.title = "Monthly Revenue"
16
+ # g.data *@data_args
17
+ # g.write("test/output/bullet_greyscale.png")
18
+ # end
19
+ #
20
+ # def test_no_options
21
+ # g = Gruff::Bullet.new
22
+ # g.data 127, 150
23
+ # g.write("test/output/bullet_no_options.png")
24
+ # end
25
+ #
26
+ # end
@@ -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
+