3 require File.dirname(__FILE__) + "/gruff_test_case"
5 class TestGruffSpider < GruffTestCase
11 [:Constitution, [12]],
12 [:Intelligence, [12]],
29 g = Gruff::Spider.new(20)
30 g.title = "Spider Graph Test"
31 @datasets.each do |data|
32 g.data(data[0], data[1])
36 g.write("test/output/spider_keynote.png")
39 def test_pie_graph_small
40 g = Gruff::Spider.new(20, 400)
41 g.title = "Visual Spider Graph Test Small"
42 @datasets.each do |data|
43 g.data(data[0], data[1])
47 g.write("test/output/spider_small.png")
50 def test_spider_graph_nearly_equal
51 g = Gruff::Spider.new(50)
52 g.title = "Spider Graph Nearly Equal"
57 # g.data(:Snuffleupagus, [43])
59 g.write("test/output/spider_nearly_equal.png")
62 def test_pie_graph_equal
63 g = Gruff::Spider.new(50)
64 g.title = "Spider Graph Equal"
70 g.write("test/output/spider_equal.png")
73 def test_pie_graph_zero
74 g = Gruff::Spider.new(2)
75 g.title = "Pie Graph Two One Zero"
81 g.write("test/output/spider_zero.png")
85 g = setup_basic_graph('800x400')
86 g.title = "Wide spider"
87 g.write("test/output/spider_wide.png")
91 g = setup_basic_graph()
92 g.title = "Spider With Small Legend"
93 g.legend_font_size = 10
94 g.write("test/output/spider_legend.png")
96 g = setup_basic_graph(400)
97 g.title = "Small spider With Small Legend"
98 g.legend_font_size = 10
99 g.write("test/output/spider_legend_small.png")
102 def test_theme_37signals
103 g = Gruff::Spider.new(20)
104 g.title = "Spider Graph Test"
105 @datasets.each do |data|
106 g.data(data[0], data[1])
112 g.write("test/output/spider_37signals.png")
116 g = Gruff::Spider.new(20)
117 g.title = "Look ma, no axes"
119 @datasets.each do |data|
120 g.data(data[0], data[1])
122 g.write("test/output/spider_no_axes.png")
127 g = Gruff::Spider.new(20)
128 g.title = "Should not print"
130 @datasets.each do |data|
131 g.data(data[0], data[1])
133 g.write("test/output/spider_no_print.png")
136 def test_transparency
137 g = Gruff::Spider.new(20)
138 g.title = "Transparent background"
140 g.transparent_background = true
142 @datasets.each do |data|
143 g.data(data[0], data[1])
145 g.write("test/output/spider_no_background.png")
149 g = Gruff::Spider.new(20)
150 g.title = "George (blue) vs Sarah (white)"
151 @datasets.each do |data|
152 g.data(data[0], data[1])
154 g.write("test/output/spider_overlay_1.png")
156 g = Gruff::Spider.new(20)
157 g.title = "Transparent background"
160 g.transparent_background = true
164 [:Constitution, [18]],
165 [:Intelligence, [8]],
169 @datasets.each do |data|
170 g.data(data[0], data[1])
172 g.marker_color = "#4F6EFF"
173 g.write("test/output/spider_overlay_2.png")
176 def test_lots_of_data
177 g = Gruff::Spider.new(10)
178 @datasets = [[:a, [1]], [:b, [5]], [:c, [3]], [:d, [9]], [:e, [4]],
179 [:f, [7]], [:g, [0]], [:h, [4]], [:i, [6]], [:j, [0]],
180 [:k, [4]], [:l, [8]]]
182 @datasets.each do |data|
183 g.data(data[0], data[1])
186 g.title = "Sample Data"
187 g.write("test/output/spider_lots_of_data.png")
190 def test_lots_of_data_with_large_names
191 g = Gruff::Spider.new(10)
192 @datasets = [[:anteaters, [1]], [:bulls, [5]], [:cats, [3]], [:dogs, [9]], [:elephants, [4]],
193 [:frogs, [7]], [:giraffes, [0]], [:hamsters, [4]], [:iguanas, [6]],
194 [:jaguar, [0]], [:kangaroo, [4]], [:locust, [8]]]
196 @datasets.each do |data|
197 g.data(data[0], data[1])
200 g.title = "Zoo Inventory"
201 g.write("test/output/spider_lots_of_data_normal_names.png")
207 def setup_basic_graph(size=800, max = 20)
208 g = Gruff::Spider.new(max, size)
209 g.title = "My Graph Title"
210 @datasets.each do |data|
211 g.data(data[0], data[1])