3 require File.dirname(__FILE__) + "/gruff_test_case"
5 class TestGruffBar < GruffTestCase
7 # TODO Delete old output files once when starting tests
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]],
22 g.title = "Bar Graph Test"
23 g.write("test/output/bar_keynote.png")
26 g.title = "Visual Multi-Line Bar Graph Test"
28 g.write("test/output/bar_rails_keynote.png")
31 g.title = "Visual Multi-Line Bar Graph Test"
33 g.write("test/output/bar_odeo.png")
36 def test_bar_graph_set_colors
38 g.title = "Bar Graph With Manual Colors"
45 g.data(:Art, [0, 5, 8, 15], '#990000')
46 g.data(:Philosophy, [10, 3, 2, 8], '#009900')
47 g.data(:Science, [2, 15, 8, 11], '#990099')
51 g.write("test/output/bar_manual_colors.png")
54 def test_bar_graph_small
55 g = Gruff::Bar.new(400)
56 g.title = "Visual Multi-Line Bar Graph Test"
63 @datasets.each do |data|
64 g.data(data[0], data[1])
67 g.write("test/output/bar_keynote_small.png")
70 # Somewhat worthless test. Should an error be thrown?
72 # g = setup_basic_graph 400
73 # g.title = "Nil Font"
75 # g.write "test/output/bar_nil_font.png"
79 def test_no_line_markers
80 g = setup_basic_graph(400)
81 g.title = "No Line Markers"
82 g.hide_line_markers = true
83 g.write("test/output/bar_no_line_markers.png")
87 g = setup_basic_graph(400)
90 g.write("test/output/bar_no_legend.png")
94 g = setup_basic_graph(400)
97 g.write("test/output/bar_no_title.png")
100 def test_no_title_or_legend
101 g = setup_basic_graph(400)
102 g.title = "No Title or Legend"
105 g.write("test/output/bar_no_title_or_legend.png")
108 def test_set_marker_count
109 g = setup_basic_graph(400)
110 g.title = "Set marker"
112 g.write("test/output/bar_set_marker.png")
115 def test_set_legend_box_size
116 g = setup_basic_graph(400)
117 g.title = "Set Legend Box Size"
118 g.legend_box_size = 10.0
119 g.write("test/output/bar_set_legend_box_size_sm.png")
121 g = setup_basic_graph(400)
122 g.title = "Set Legend Box Size"
123 g.legend_box_size = 50.0
124 g.write("test/output/bar_set_legend_box_size_lg.png")
128 g = setup_basic_graph(400)
129 g.title = "X Y Labels"
130 g.x_axis_label = 'Score (%)'
131 g.y_axis_label = "Students"
132 g.write("test/output/bar_x_y_labels.png")
136 g = setup_basic_graph('800x400')
137 g.title = "Wide Graph"
138 g.write("test/output/bar_wide_graph.png")
140 g = setup_basic_graph('400x200')
141 g.title = "Wide Graph Small"
142 g.write("test/output/bar_wide_graph_small.png")
147 g = setup_basic_graph('400x600')
148 g.title = "Tall Graph"
149 g.write("test/output/bar_tall_graph.png")
151 g = setup_basic_graph('200x400')
152 g.title = "Tall Graph Small"
153 g.write("test/output/bar_tall_graph_small.png")
159 g.title = "One Value Graph Test"
166 g.write("test/output/bar_one_value.png")
172 g.title = "Pos/Neg Bar Graph Test"
179 g.data(:apples, [-1, 0, 4, -4])
180 g.data(:peaches, [10, 8, 6, 3])
182 g.write("test/output/bar_pos_neg.png")
188 g.title = "Nearly Zero Graph"
195 g.data(:apples, [1, 2, 3, 4])
196 g.data(:peaches, [4, 3, 2, 1])
199 g.write("test/output/bar_nearly_zero_max_10.png")
202 def test_y_axis_increment
203 generate_with_y_axis_increment 2.0
204 generate_with_y_axis_increment 1
205 generate_with_y_axis_increment 5
206 generate_with_y_axis_increment 20
209 def generate_with_y_axis_increment(increment)
211 g.title = "Y Axis Set to #{increment}"
218 g.y_axis_increment = increment
219 g.data(:apples, [1, 0.2, 0.5, 0.7])
220 g.data(:peaches, [2.5, 2.3, 2, 6.1])
221 g.write("test/output/bar_y_increment_#{increment}.png")
225 def test_custom_theme
227 g.title = "Custom Theme"
228 g.font = File.expand_path('CREABBRG.TTF', ENV['MAGICK_FONT_PATH'])
229 g.title_font_size = 60
230 g.legend_font_size = 32
231 g.marker_font_size = 32
233 :colors => %w(#efd250 #666699 #e5573f #9595e2),
234 :marker_color => 'white',
235 :font_color => 'blue',
236 :background_image => "assets/pc306715.jpg"
244 g.data(:vancouver, [1, 2, 3, 4])
245 g.data(:seattle, [2, 4, 6, 8])
246 g.data(:portland, [3, 1, 7, 3])
247 g.data(:victoria, [4, 3, 5, 7])
249 g.write("test/output/bar_themed.png")
252 def test_july_enhancements
253 g = Gruff::Bar.new(600)
255 g.title = "Full speed ahead"
256 g.labels = (0..10).inject({}) { |memo, i| memo.merge({ i => (i*10).to_s}) }
257 g.data(:apples, (0..9).map { rand(20)/10.0 })
258 g.y_axis_increment = 1.0
259 g.x_axis_label = 'Score (%)'
260 g.y_axis_label = 'Students'
261 write_test_file g, 'enhancements.png'
267 def setup_basic_graph(size=800)
268 g = Gruff::Bar.new(size)
269 g.title = "My Bar Graph"
276 @datasets.each do |data|
277 g.data(data[0], data[1])