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,33 @@
1
+
2
+ require File.dirname(__FILE__) + "/gruff_test_case"
3
+
4
+ class TestMiniBar < GruffTestCase
5
+
6
+ def test_simple_bar
7
+ setup_single_dataset
8
+ g = setup_basic_graph(Gruff::Mini::Bar, 200)
9
+ g.hide_mini_legend = true
10
+ write_test_file g, 'mini_bar.png'
11
+ end
12
+
13
+ # def test_simple_bar_wide_dataset
14
+ # setup_wide_dataset
15
+ # g = setup_basic_graph(Gruff::Mini::Bar, 200)
16
+ # write_test_file g, 'mini_bar_wide_data.png'
17
+ # end
18
+ #
19
+ # def test_code_sample
20
+ # g = Gruff::Mini::Bar.new(200)
21
+ # g.data "Jim", [200, 500, 400]
22
+ # g.labels = { 0 => 'This Month', 1 => 'Average', 2 => 'Overall'}
23
+ # g.write "mini_bar_one_color.png"
24
+ #
25
+ # g = Gruff::Mini::Bar.new(200)
26
+ # g.data "Car", 200
27
+ # g.data "Food", 500
28
+ # g.data "Art", 1000
29
+ # g.data "Music", 16
30
+ # g.write "mini_bar_many_colors.png"
31
+ # end
32
+
33
+ end
@@ -0,0 +1,26 @@
1
+
2
+ require File.dirname(__FILE__) + "/gruff_test_case"
3
+
4
+ class TestMiniPie < GruffTestCase
5
+
6
+ def test_simple_pie
7
+ g = setup_basic_graph(Gruff::Mini::Pie, 200)
8
+ write_test_file g, 'mini_pie.png'
9
+ end
10
+
11
+ def test_pie_with_legend_right
12
+ g = setup_basic_graph(Gruff::Mini::Pie, 200)
13
+ g.legend_position = :right
14
+ write_test_file g, 'mini_pie_right_legend.png'
15
+ end
16
+
17
+ # def test_code_sample
18
+ # g = Gruff::Mini::Pie.new(200)
19
+ # g.data "Car", 200
20
+ # g.data "Food", 500
21
+ # g.data "Art", 1000
22
+ # g.data "Music", 16
23
+ # g.write "mini_pie.png"
24
+ # end
25
+
26
+ end
@@ -0,0 +1,37 @@
1
+
2
+ require File.dirname(__FILE__) + "/gruff_test_case"
3
+
4
+ class TestMiniSideBar < GruffTestCase
5
+
6
+ def test_one_color
7
+ # Use a single data set
8
+ @datasets = [
9
+ [:Jimmy, [25, 36, 86, 39]]
10
+ ]
11
+ @labels = {
12
+ 0 => 'Auto',
13
+ 1 => 'Entertainment',
14
+ 2 => 'Food',
15
+ 3 => 'Bus'
16
+ }
17
+
18
+ g = setup_basic_graph(Gruff::Mini::SideBar, 200)
19
+ write_test_file g, 'mini_side_bar.png'
20
+ end
21
+
22
+ def test_multi_color
23
+ # @datasets = [
24
+ # [:Jimmy, [25, 36, 86, 39]]
25
+ # ]
26
+ # @labels = {
27
+ # 0 => 'Auto',
28
+ # 1 => 'Entertainment',
29
+ # 2 => 'Food',
30
+ # 3 => 'Bus'
31
+ # }
32
+
33
+ g = setup_basic_graph(Gruff::Mini::SideBar, 200)
34
+ write_test_file g, 'mini_side_bar_multi_color.png'
35
+ end
36
+
37
+ end
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/gruff_test_case"
4
+
5
+ class TestGruffNet < GruffTestCase
6
+
7
+ def setup
8
+ @datasets = [
9
+ [:Jimmy, [25, 36, 86, 39, 25, 31, 79, 88]],
10
+ [:Charles, [80, 54, 67, 54, 68, 70, 90, 95]],
11
+ [:Julie, [22, 29, 35, 38, 36, 40, 46, 57]],
12
+ [:Jane, [95, 95, 95, 90, 85, 80, 88, 100]],
13
+ [:Philip, [90, 34, 23, 12, 78, 89, 98, 88]],
14
+ ["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]],
15
+ ]
16
+
17
+ @sample_labels = {
18
+ 0 => '5/6',
19
+ 1 => '5/15',
20
+ 2 => '5/24',
21
+ 3 => '5/30',
22
+ 4 => '6/4',
23
+ 5 => '6/12',
24
+ 6 => '6/21',
25
+ 7 => '6/28',
26
+ }
27
+ end
28
+
29
+ def test_net_small_values
30
+ @datasets = [
31
+ [:small, [0.1, 0.14356, 0.0, 0.5674839, 0.456]],
32
+ [:small2, [0.2, 0.3, 0.1, 0.05, 0.9]]
33
+ ]
34
+
35
+ g = Gruff::Net.new
36
+ g.title = "Small Values Net Graph Test"
37
+ @datasets.each do |data|
38
+ g.data(data[0], data[1])
39
+ end
40
+ g.write("test/output/net_small.png")
41
+
42
+ g = Gruff::Net.new(400)
43
+ g.title = "Small Values Net Graph Test 400px"
44
+ @datasets.each do |data|
45
+ g.data(data[0], data[1])
46
+ end
47
+ g.write("test/output/net_small_small.png")
48
+ end
49
+
50
+ def test_net_starts_with_zero
51
+ @datasets = [
52
+ [:first0, [0, 5, 10, 8, 18]],
53
+ [:normal, [1, 2, 3, 4, 5]]
54
+ ]
55
+
56
+ g = Gruff::Net.new
57
+ g.title = "Small Values Net Graph Test"
58
+ @datasets.each do |data|
59
+ g.data(data[0], data[1])
60
+ end
61
+ g.write("test/output/net_small_zero.png")
62
+
63
+ g = Gruff::Net.new(400)
64
+ g.title = "Small Values Net Graph Test 400px"
65
+ @datasets.each do |data|
66
+ g.data(data[0], data[1])
67
+ end
68
+ g.write("test/output/net_small_small_zero.png")
69
+ end
70
+
71
+
72
+ def test_net_large_values
73
+ @datasets = [
74
+ [:large, [100_005, 35_000, 28_000, 27_000]],
75
+ [:large2, [35_000, 28_000, 27_000, 100_005]],
76
+ [:large3, [28_000, 27_000, 100_005, 35_000]],
77
+ [:large4, [1_238, 39_092, 27_938, 48_876]]
78
+ ]
79
+
80
+ g = Gruff::Net.new
81
+ g.title = "Very Large Values Net Graph Test"
82
+ @datasets.each do |data|
83
+ g.data(data[0], data[1])
84
+ end
85
+
86
+ g.write("test/output/net_large.png")
87
+ end
88
+
89
+ def test_many_datapoints
90
+ g = Gruff::Net.new
91
+ g.title = "Many Multi-Net Graph Test"
92
+ g.labels = {
93
+ 0 => 'June',
94
+ 10 => 'July',
95
+ 30 => 'August',
96
+ 50 => 'September',
97
+ }
98
+ g.data('many points', (0..50).collect {|i| rand(100) })
99
+
100
+ # Default theme
101
+ g.write("test/output/net_many.png")
102
+ end
103
+
104
+
105
+ def test_similar_high_end_values
106
+ g = Gruff::Net.new
107
+ g.title = "Similar High End Values Test"
108
+ g.data('similar points', %w(29.43 29.459 29.498 29.53 29.548 29.589 29.619 29.66 29.689 29.849 29.878 29.74 29.769 29.79 29.808 29.828).collect {|i| i.to_f} )
109
+
110
+ # Default theme
111
+ g.write("test/output/net_similar_high_end_values.png")
112
+ end
113
+
114
+ def test_many_nets_graph_small
115
+ g = Gruff::Net.new(400)
116
+ g.title = "Many Values Net Test 400px"
117
+ g.labels = {
118
+ 0 => '5/6',
119
+ 10 => '5/15',
120
+ 20 => '5/24',
121
+ 30 => '5/30',
122
+ 40 => '6/4',
123
+ 50 => '6/16'
124
+ }
125
+ %w{jimmy jane philip arthur julie bert}.each do |student_name|
126
+ g.data(student_name, (0..50).collect { |i| rand 100 })
127
+ end
128
+
129
+ # Default theme
130
+ g.write("test/output/net_many_nets_small.png")
131
+ end
132
+
133
+ def test_dots_graph_tiny
134
+ g = Gruff::Net.new(300)
135
+ g.title = "Dots Test 300px"
136
+ g.labels = {
137
+ 0 => '5/6',
138
+ 10 => '5/15',
139
+ 20 => '5/24',
140
+ 30 => '5/30',
141
+ 40 => '6/4',
142
+ 50 => '6/16'
143
+ }
144
+ %w{jimmy jane philip arthur julie bert}.each do |student_name|
145
+ g.data(student_name, (0..50).collect { |i| rand 100 })
146
+ end
147
+
148
+ # Default theme
149
+ g.write("test/output/net_dots_tiny.png")
150
+ end
151
+
152
+ def test_no_data
153
+ g = Gruff::Net.new(400)
154
+ g.title = "No Data"
155
+ # Default theme
156
+ g.write("test/output/net_no_data.png")
157
+
158
+ g = Gruff::Net.new(400)
159
+ g.title = "No Data Title"
160
+ g.no_data_message = 'There is no data'
161
+ g.write("test/output/net_no_data_msg.png")
162
+ end
163
+
164
+
165
+ def test_all_zeros
166
+ g = Gruff::Net.new(400)
167
+ g.title = "All Zeros"
168
+
169
+ g.data(:gus, [0,0,0,0])
170
+
171
+ # Default theme
172
+ g.write("test/output/net_no_data_other.png")
173
+ end
174
+
175
+ def test_no_title
176
+ g = Gruff::Net.new(400)
177
+ g.labels = @sample_labels
178
+ @datasets.each do |data|
179
+ g.data(data[0], data[1])
180
+ end
181
+
182
+ g.write("test/output/net_no_title.png")
183
+ end
184
+
185
+ def test_no_net_markers
186
+ g = setup_basic_graph(400)
187
+ g.title = "No Net Markers"
188
+ g.hide_line_markers = true
189
+ g.write("test/output/net_no_net_markers.png")
190
+ end
191
+
192
+ def test_no_legend
193
+ g = setup_basic_graph(400)
194
+ g.title = "No Legend"
195
+ g.hide_legend = true
196
+ g.write("test/output/net_no_legend.png")
197
+ end
198
+
199
+ def test_nothing_but_the_graph
200
+ g = setup_basic_graph(400)
201
+ g.title = "THIS TITLE SHOULD NOT DISPLAY!!!"
202
+ g.hide_line_markers = true
203
+ g.hide_legend = true
204
+ g.hide_title = true
205
+ g.write("test/output/net_nothing_but_the_graph.png")
206
+ end
207
+
208
+ def test_wide_graph
209
+ g = setup_basic_graph('800x400')
210
+ g.title = "Wide Graph"
211
+ g.write("test/output/net_wide_graph.png")
212
+
213
+ g = setup_basic_graph('400x200')
214
+ g.title = "Wide Graph Small"
215
+ g.write("test/output/net_wide_graph_small.png")
216
+ end
217
+
218
+ protected
219
+
220
+ def setup_basic_graph(size=800)
221
+ g = Gruff::Net.new(size)
222
+ g.title = "My Graph Title"
223
+ g.labels = @sample_labels
224
+ @datasets.each do |data|
225
+ g.data(data[0], data[1])
226
+ end
227
+ return g
228
+ end
229
+
230
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/gruff_test_case"
4
+
5
+ class TestGruffPhotoBar < GruffTestCase
6
+
7
+ # def setup
8
+ # @datasets = [
9
+ # [:Jimmy, [25, 36, 86, 39]],
10
+ # [:Charles, [80, 54, 67, 54]],
11
+ # # [:Charity, [0, nil, 100, 90]],
12
+ # ]
13
+ # end
14
+ #
15
+ # def test_bar_graph
16
+ # bar_graph_sized
17
+ # bar_graph_sized(400)
18
+ # end
19
+ #
20
+ #
21
+ # protected
22
+ #
23
+ # def bar_graph_sized(size=800)
24
+ # g = Gruff::PhotoBar.new(size)
25
+ # g.title = "Photo Bar Graph Test #{size}px"
26
+ # g.labels = {
27
+ # 0 => '5/6',
28
+ # 1 => '5/15',
29
+ # 2 => '5/24',
30
+ # 3 => '5/30',
31
+ # }
32
+ # @datasets.each do |data|
33
+ # g.data(*data)
34
+ # end
35
+ #
36
+ # g.theme = 'plastik'
37
+ #
38
+ # g.write("test/output/photo_plastik_#{size}.png")
39
+ # end
40
+
41
+ end
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/gruff_test_case"
4
+
5
+ class TestGruffPie < GruffTestCase
6
+
7
+ def setup
8
+ @datasets = [
9
+ [:Darren, [25]],
10
+ [:Chris, [80]],
11
+ [:Egbert, [22]],
12
+ [:Adam, [95]],
13
+ [:Bill, [90]],
14
+ ["Frank", [5]],
15
+ ["Zero", [0]],
16
+ ]
17
+ end
18
+
19
+ def test_pie_graph
20
+ g = Gruff::Pie.new
21
+ g.title = "Visual Pie Graph Test"
22
+ @datasets.each do |data|
23
+ g.data(data[0], data[1])
24
+ end
25
+
26
+ # Default theme
27
+ g.write("test/output/pie_keynote.png")
28
+ end
29
+
30
+ def test_pie_graph_greyscale
31
+ g = Gruff::Pie.new
32
+ g.title = "Greyscale Pie Graph Test"
33
+ g.theme_greyscale
34
+ @datasets.each do |data|
35
+ g.data(data[0], data[1])
36
+ end
37
+
38
+ # Default theme
39
+ g.write("test/output/pie_grey.png")
40
+ end
41
+
42
+ def test_pie_graph_pastel
43
+ g = Gruff::Pie.new
44
+ g.theme_pastel
45
+ g.title = "Pastel Pie Graph Test"
46
+ @datasets.each do |data|
47
+ g.data(data[0], data[1])
48
+ end
49
+
50
+ # Default theme
51
+ g.write("test/output/pie_pastel.png")
52
+ end
53
+
54
+
55
+ def test_pie_graph_small
56
+ g = Gruff::Pie.new(400)
57
+ g.title = "Visual Pie Graph Test Small"
58
+ @datasets.each do |data|
59
+ g.data(data[0], data[1])
60
+ end
61
+
62
+ # Default theme
63
+ g.write("test/output/pie_keynote_small.png")
64
+ end
65
+
66
+ def test_pie_graph_nearly_equal
67
+ g = Gruff::Pie.new
68
+ g.title = "Pie Graph Nearly Equal"
69
+
70
+ g.data(:Blake, [41])
71
+ g.data(:Aaron, [42])
72
+ # g.data(:Grouch, [40])
73
+ # g.data(:Snuffleupagus, [43])
74
+
75
+ g.write("test/output/pie_nearly_equal.png")
76
+ end
77
+
78
+ def test_pie_graph_equal
79
+ g = Gruff::Pie.new
80
+ g.title = "Pie Graph Equal"
81
+
82
+ g.data(:Bert, [41])
83
+ g.data(:Adam, [41])
84
+
85
+ g.write("test/output/pie_equal.png")
86
+ end
87
+
88
+ def test_pie_graph_zero
89
+ g = Gruff::Pie.new
90
+ g.title = "Pie Graph One Zero"
91
+
92
+ g.data(:Bert, [0])
93
+ g.data(:Adam, [1])
94
+
95
+ g.write("test/output/pie_zero.png")
96
+ end
97
+
98
+
99
+ def test_pie_graph_one_val
100
+ g = Gruff::Pie.new
101
+ g.title = "Pie Graph One Val"
102
+
103
+ g.data(:Bert, 53)
104
+ g.data(:Adam, 29)
105
+
106
+ g.write("test/output/pie_one_val.png")
107
+ end
108
+
109
+
110
+ def test_wide
111
+ g = setup_basic_graph('800x400')
112
+ g.title = "Wide Pie"
113
+ g.write("test/output/pie_wide.png")
114
+ end
115
+
116
+ def test_label_size
117
+ g = setup_basic_graph()
118
+ g.title = "Pie With Small Legend"
119
+ g.legend_font_size = 10
120
+ g.write("test/output/pie_legend.png")
121
+
122
+ g = setup_basic_graph(400)
123
+ g.title = "Small Pie With Small Legend"
124
+ g.legend_font_size = 10
125
+ g.write("test/output/pie_legend_small.png")
126
+ end
127
+
128
+
129
+ def test_tiny_simple_pie
130
+ @datasets = (1..5).map {|n| ['Auto', [rand(100)]]}
131
+
132
+ g = setup_basic_graph 200
133
+ g.hide_legend = true
134
+ g.hide_title = true
135
+ g.hide_line_numbers = true
136
+
137
+ g.marker_font_size = 40.0
138
+ g.minimum_value = 0.0
139
+
140
+ write_test_file g, "pie_simple.png"
141
+ end
142
+
143
+ protected
144
+
145
+ def setup_basic_graph(size=800)
146
+ g = Gruff::Pie.new(size)
147
+ g.title = "My Graph Title"
148
+ @datasets.each do |data|
149
+ g.data(data[0], data[1])
150
+ end
151
+ return g
152
+ end
153
+
154
+ end