gruff 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +14 -0
  3. data/.rubocop.yml +16 -0
  4. data/.rubocop_todo.yml +923 -0
  5. data/.travis.yml +21 -14
  6. data/{History.txt → CHANGELOG.md} +32 -25
  7. data/README.md +3 -2
  8. data/Rakefile +27 -18
  9. data/assets/bubble.png +0 -0
  10. data/assets/city_scene/background/0000.png +0 -0
  11. data/assets/city_scene/background/0600.png +0 -0
  12. data/assets/city_scene/background/2000.png +0 -0
  13. data/assets/city_scene/clouds/cloudy.png +0 -0
  14. data/assets/city_scene/clouds/partly_cloudy.png +0 -0
  15. data/assets/city_scene/clouds/stormy.png +0 -0
  16. data/assets/city_scene/grass/default.png +0 -0
  17. data/assets/city_scene/haze/true.png +0 -0
  18. data/assets/city_scene/number_sample/1.png +0 -0
  19. data/assets/city_scene/number_sample/2.png +0 -0
  20. data/assets/city_scene/number_sample/default.png +0 -0
  21. data/assets/city_scene/sky/0000.png +0 -0
  22. data/assets/city_scene/sky/0200.png +0 -0
  23. data/assets/city_scene/sky/0400.png +0 -0
  24. data/assets/city_scene/sky/0600.png +0 -0
  25. data/assets/city_scene/sky/0800.png +0 -0
  26. data/assets/city_scene/sky/1000.png +0 -0
  27. data/assets/city_scene/sky/1200.png +0 -0
  28. data/assets/city_scene/sky/1400.png +0 -0
  29. data/assets/city_scene/sky/1500.png +0 -0
  30. data/assets/city_scene/sky/1700.png +0 -0
  31. data/assets/city_scene/sky/2000.png +0 -0
  32. data/assets/pc306715.jpg +0 -0
  33. data/assets/plastik/blue.png +0 -0
  34. data/assets/plastik/green.png +0 -0
  35. data/assets/plastik/red.png +0 -0
  36. data/gruff.gemspec +12 -10
  37. data/lib/gruff.rb +2 -2
  38. data/lib/gruff/accumulator_bar.rb +2 -2
  39. data/lib/gruff/area.rb +1 -4
  40. data/lib/gruff/bar.rb +12 -13
  41. data/lib/gruff/bar_conversion.rb +11 -11
  42. data/lib/gruff/base.rb +36 -36
  43. data/lib/gruff/bezier.rb +1 -2
  44. data/lib/gruff/bullet.rb +7 -10
  45. data/lib/gruff/deprecated.rb +10 -11
  46. data/lib/gruff/dot.rb +3 -4
  47. data/lib/gruff/line.rb +13 -14
  48. data/lib/gruff/mini/bar.rb +3 -3
  49. data/lib/gruff/mini/legend.rb +7 -8
  50. data/lib/gruff/mini/pie.rb +6 -6
  51. data/lib/gruff/mini/side_bar.rb +7 -7
  52. data/lib/gruff/net.rb +2 -8
  53. data/lib/gruff/photo_bar.rb +9 -12
  54. data/lib/gruff/pie.rb +6 -6
  55. data/lib/gruff/scatter.rb +47 -51
  56. data/lib/gruff/scene.rb +17 -19
  57. data/lib/gruff/side_bar.rb +5 -8
  58. data/lib/gruff/side_stacked_bar.rb +24 -26
  59. data/lib/gruff/spider.rb +14 -15
  60. data/lib/gruff/stacked_area.rb +12 -16
  61. data/lib/gruff/stacked_bar.rb +50 -52
  62. data/lib/gruff/stacked_mixin.rb +2 -3
  63. data/lib/gruff/themes.rb +32 -33
  64. data/lib/gruff/version.rb +1 -1
  65. metadata +23 -67
  66. data/RELEASE.md +0 -30
  67. data/test/gruff_test_case.rb +0 -152
  68. data/test/image_compare.rb +0 -58
  69. data/test/test_accumulator_bar.rb +0 -51
  70. data/test/test_area.rb +0 -134
  71. data/test/test_bar.rb +0 -505
  72. data/test/test_base.rb +0 -33
  73. data/test/test_bezier.rb +0 -33
  74. data/test/test_bullet.rb +0 -26
  75. data/test/test_dot.rb +0 -263
  76. data/test/test_labels_for_null_data.rb +0 -27
  77. data/test/test_legend.rb +0 -68
  78. data/test/test_line.rb +0 -674
  79. data/test/test_mini_bar.rb +0 -33
  80. data/test/test_mini_pie.rb +0 -25
  81. data/test/test_mini_side_bar.rb +0 -36
  82. data/test/test_net.rb +0 -231
  83. data/test/test_photo.rb +0 -41
  84. data/test/test_pie.rb +0 -194
  85. data/test/test_scatter.rb +0 -270
  86. data/test/test_scene.rb +0 -100
  87. data/test/test_side_bar.rb +0 -56
  88. data/test/test_sidestacked_bar.rb +0 -105
  89. data/test/test_spider.rb +0 -226
  90. data/test/test_stacked_area.rb +0 -52
  91. data/test/test_stacked_bar.rb +0 -68
@@ -1,674 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require File.dirname(__FILE__) + '/gruff_test_case'
4
-
5
- class TestGruffLine < GruffTestCase
6
- def test_should_render_with_transparent_theme
7
- g = Gruff::Line.new(400)
8
- g.title = 'Transparent Background'
9
- g.theme = {
10
- :colors => %w(black grey),
11
- :marker_color => 'grey',
12
- :font_color => 'black',
13
- :background_colors => 'transparent'
14
- }
15
-
16
- g.labels = {
17
- 0 => '5/6',
18
- 1 => '5/15',
19
- 2 => '5/24',
20
- 3 => '5/30',
21
- }
22
- g.data(:apples, [-1, 0, 4, -4])
23
- g.data(:peaches, [10, 8, 6, 3])
24
- g.write('test/output/line_transparent.png')
25
- end
26
-
27
- def test_very_small
28
- g = Gruff::Line.new(200)
29
- g.title = 'Very Small Line Chart 200px'
30
- g.labels = @labels
31
- @datasets.each do |data|
32
- g.data(data[0], data[1])
33
- end
34
- g.write('test/output/line_very_small.png')
35
- end
36
-
37
- def test_line_graph_with_themes
38
- line_graph_with_themes()
39
- line_graph_with_themes(400)
40
- end
41
-
42
- def test_one_value
43
- g = Gruff::Line.new
44
- g.title = 'One Value'
45
- g.labels = {
46
- 0 => '1',
47
- 1 => '2'
48
- }
49
- g.data('one', 1)
50
-
51
- g.write('test/output/line_one_value.png')
52
- end
53
-
54
- def test_one_value_array
55
- g = Gruff::Line.new
56
- g.title = 'One Value in an Array'
57
- g.labels = {
58
- 0 => '1',
59
- 1 => '2'
60
- }
61
- g.data('one', [1])
62
-
63
- g.write('test/output/line_one_value_array.png')
64
- end
65
-
66
-
67
- def test_should_not_hang_with_0_0_100
68
- g = Gruff::Line.new(320)
69
- g.title = 'Hang Value Graph Test'
70
- g.data('test', [0, 0, 100])
71
-
72
- g.write('test/output/line_hang_value.png')
73
- end
74
-
75
- # TODO
76
- # def test_fix_crash
77
- # g = Gruff::Line.new(370)
78
- # g.title = "Crash Test"
79
- # g.data "ichi", [5]
80
- # g.data "ni", [0]
81
- # g.data "san", [0]
82
- # g.data "shi", [0]
83
- # g.write("test/output/line_crash_fix_test.png")
84
- # end
85
-
86
-
87
- def test_line_small_values
88
- @datasets = [
89
- [:small, [0.1, 0.14356, 0.0, 0.5674839, 0.456]],
90
- [:small2, [0.2, 0.3, 0.1, 0.05, 0.9]]
91
- ]
92
-
93
- g = Gruff::Line.new
94
- g.title = 'Small Values Line Graph Test'
95
- @datasets.each do |data|
96
- g.data(data[0], data[1])
97
- end
98
- g.write('test/output/line_small_values.png')
99
-
100
- g = Gruff::Line.new(400)
101
- g.title = 'Small Values Line Graph Test 400px'
102
- @datasets.each do |data|
103
- g.data(data[0], data[1])
104
- end
105
- g.write('test/output/line_small_values_small.png')
106
- end
107
-
108
- def test_line_starts_with_zero
109
- @datasets = [
110
- [:first0, [0, 5, 10, 8, 18]],
111
- [:normal, [1, 2, 3, 4, 5]]
112
- ]
113
-
114
- g = Gruff::Line.new
115
- g.title = 'Small Values Line Graph Test'
116
- @datasets.each do |data|
117
- g.data(data[0], data[1])
118
- end
119
- g.write('test/output/line_small_zero.png')
120
-
121
- g = Gruff::Line.new(400)
122
- g.title = 'Small Values Line Graph Test 400px'
123
- @datasets.each do |data|
124
- g.data(data[0], data[1])
125
- end
126
- g.write('test/output/line_small_small_zero.png')
127
- end
128
-
129
-
130
- def test_line_large_values
131
- @datasets = [
132
- [:large, [100_005, 35_000, 28_000, 27_000]],
133
- [:large2, [35_000, 28_000, 27_000, 100_005]],
134
- [:large3, [28_000, 27_000, 100_005, 35_000]],
135
- [:large4, [1_238, 39_092, 27_938, 48_876]]
136
- ]
137
-
138
- g = Gruff::Line.new
139
- g.title = 'Very Large Values Line Graph Test'
140
- g.baseline_value = 50_000
141
- g.baseline_color = 'green'
142
- g.dot_radius = 15
143
- g.line_width = 3
144
- @datasets.each do |data|
145
- g.data(data[0], data[1])
146
- end
147
-
148
- g.write('test/output/line_large.png')
149
- end
150
-
151
- # def test_long_title
152
- #
153
- # end
154
- #
155
- # def test_add_colors
156
- #
157
- # end
158
- #
159
-
160
- def test_request_too_many_colors
161
- g = Gruff::Line.new
162
- g.title = 'More Sets Than in Color Array'
163
- # g.theme = {} # Sets theme with only black and white
164
- @datasets.each do |data|
165
- g.data(data[0], data[1])
166
- end
167
- @datasets.each do |data|
168
- g.data("#{data[0]}-B", data[1].map { |d| d + 20 })
169
- end
170
- g.write('test/output/line_more_sets_than_colors.png')
171
- end
172
-
173
- #
174
- # def test_add_data
175
- #
176
- # end
177
-
178
- def test_many_datapoints
179
- g = Gruff::Line.new
180
- g.title = 'Many Multi-Line Graph Test'
181
- g.labels = {
182
- 0 => 'June',
183
- 10 => 'July',
184
- 30 => 'August',
185
- 50 => 'September',
186
- }
187
- g.data('many points', (0..50).collect { |i| rand(100) })
188
- g.x_axis_label = 'Months'
189
-
190
- # Default theme
191
- g.write('test/output/line_many.png')
192
- end
193
-
194
-
195
- def test_dot_style_square
196
- g = Gruff::Line.new
197
- g.title = 'Square points'
198
- g.labels = {
199
- 0 => 'June',
200
- 10 => 'July',
201
- 30 => 'August',
202
- 50 => 'September',
203
- }
204
- g.dot_style = :square
205
- g.data('many points', (0..50).collect { |i| rand(100) })
206
- g.x_axis_label = 'Months'
207
-
208
- # Default theme
209
- g.write('test/output/line_dot_style_square.png')
210
- end
211
-
212
- def test_similar_high_end_values
213
- @dataset = %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 }
214
-
215
- g = Gruff::Line.new
216
- g.title = 'Similar High End Values Test'
217
- g.data('similar points', @dataset)
218
- g.write('test/output/line_similar_high_end_values.png')
219
-
220
- g = Gruff::Line.new
221
- g.title = 'Similar High End Values With Floor'
222
- g.data('similar points', @dataset)
223
- g.minimum_value = 0
224
- g.y_axis_label = 'Barometric Pressure'
225
- g.write('test/output/line_similar_high_end_values_with_floor.png')
226
- end
227
-
228
- def test_many_lines_graph_small
229
- g = Gruff::Line.new(400)
230
- g.title = 'Many Values Line Test 400px'
231
- g.labels = {
232
- 0 => '5/6',
233
- 10 => '5/15',
234
- 20 => '5/24',
235
- 30 => '5/30',
236
- 40 => '6/4',
237
- 50 => '6/16'
238
- }
239
- %w{jimmy jane philip arthur julie bert}.each do |student_name|
240
- g.data(student_name, (0..50).collect { |i| rand 100 })
241
- end
242
-
243
- # Default theme
244
- g.write('test/output/line_many_lines_small.png')
245
- end
246
-
247
- def test_graph_tiny
248
- g = Gruff::Line.new(300)
249
- g.title = 'Tiny Test 300px'
250
- g.labels = {
251
- 0 => '5/6',
252
- 10 => '5/15',
253
- 20 => '5/24',
254
- 30 => '5/30',
255
- 40 => '6/4',
256
- 50 => '6/16'
257
- }
258
- %w{jimmy jane philip arthur julie bert}.each do |student_name|
259
- g.data(student_name, (0..50).collect { |i| rand 100 })
260
- end
261
-
262
- # Default theme
263
- g.write('test/output/line_tiny.png')
264
- end
265
-
266
- def test_no_data
267
- g = Gruff::Line.new(400)
268
- g.title = 'No Data'
269
- # Default theme
270
- g.write('test/output/line_no_data.png')
271
-
272
- g = Gruff::Line.new(400)
273
- g.title = 'No Data Title'
274
- g.no_data_message = 'There is no data'
275
- g.write('test/output/line_no_data_msg.png')
276
- end
277
-
278
-
279
- def test_all_zeros
280
- g = Gruff::Line.new(400)
281
- g.title = 'All Zeros'
282
-
283
- g.data(:gus, [0, 0, 0, 0])
284
-
285
- # Default theme
286
- g.write('test/output/line_no_data_other.png')
287
- end
288
-
289
-
290
- def test_some_nil_points
291
- g = Gruff::Line.new
292
- g.title = 'Some Nil Points'
293
-
294
- @datasets = [
295
- [:data1, [1, 2, 3, nil, 3, 5, 6]],
296
- [:data2, [5, nil, nil, 5, nil, nil, 5]],
297
- [:data3, [4, nil, 2, 1, 0]],
298
- [:data4, [nil, nil, 3, 1, 2]]
299
- ]
300
-
301
- @datasets.each do |data|
302
- g.data(*data)
303
- end
304
-
305
- # Default theme
306
- g.write('test/output/line_some_nil_points.png')
307
- end
308
-
309
- def test_no_title
310
- g = Gruff::Line.new(400)
311
- g.labels = @labels
312
- @datasets.each do |data|
313
- g.data(data[0], data[1])
314
- end
315
-
316
- g.write('test/output/line_no_title.png')
317
- end
318
-
319
- def test_no_line_markers
320
- g = setup_basic_graph(400)
321
- g.title = 'No Line Markers'
322
- g.hide_line_markers = true
323
- g.write('test/output/line_no_line_markers.png')
324
- end
325
-
326
- def test_no_legend
327
- g = setup_basic_graph(400)
328
- g.title = 'No Legend'
329
- g.hide_legend = true
330
- g.write('test/output/line_no_legend.png')
331
- end
332
-
333
- def test_nothing_but_the_graph
334
- g = setup_basic_graph(400)
335
- g.title = 'THIS TITLE SHOULD NOT DISPLAY!!!'
336
- g.hide_line_markers = true
337
- g.hide_legend = true
338
- g.hide_title = true
339
- g.write('test/output/line_nothing_but_the_graph.png')
340
- end
341
-
342
- def test_legend_below_the_chart
343
- g = setup_basic_graph(400)
344
- g.title = 'Legend below the chart'
345
- g.legend_at_bottom = true
346
- g.write('test/output/line_legend_at_bottom.png')
347
- end
348
-
349
- def test_baseline_larger_than_data
350
- g = setup_basic_graph(400)
351
- g.title = 'Baseline Larger Than Data'
352
- g.baseline_value = 150
353
- g.write('test/output/line_large_baseline.png')
354
- end
355
-
356
- def test_hide_dots
357
- g = setup_basic_graph(400)
358
- g.title = 'Hide Dots'
359
- g.hide_dots = true
360
- g.write('test/output/line_hide_dots.png')
361
- end
362
-
363
- def test_hide_lines
364
- g = setup_basic_graph(400)
365
- g.title = 'Hide Lines'
366
- g.hide_lines = true
367
- g.write('test/output/line_hide_lines.png')
368
- end
369
-
370
- def test_wide_graph
371
- g = setup_basic_graph('800x400')
372
- g.title = 'Wide Graph'
373
- g.write('test/output/line_wide_graph.png')
374
-
375
- g = setup_basic_graph('400x200')
376
- g.title = 'Wide Graph Small'
377
- g.write('test/output/line_wide_graph_small.png')
378
- end
379
-
380
- def test_negative
381
- g = setup_pos_neg(800)
382
- g.write('test/output/line_pos_neg.png')
383
-
384
- g = setup_pos_neg(400)
385
- g.title = 'Pos/Neg Line Test Small'
386
- g.write('test/output/line_pos_neg_400.png')
387
- end
388
-
389
- def test_all_negative
390
- g = setup_all_neg(800)
391
- g.maximum_value = 0
392
- g.write('test/output/line_all_neg.png')
393
- end
394
-
395
- def test_all_negative_no_max_value
396
- g = setup_all_neg(800)
397
- g.write('test/output/line_all_neg_no_max.png')
398
- end
399
-
400
- def test_all_negative_400
401
- g = setup_all_neg(400)
402
- g.maximum_value = 0
403
- g.title = 'All Neg Line Test Small'
404
- g.write('test/output/line_all_neg_400.png')
405
- end
406
-
407
- def test_many_numbers
408
- g = Gruff::Line.new('400x170')
409
- g.title = 'Line Test, Many Numbers'
410
-
411
- data = [
412
- {:date => '01',
413
- :wpm => 0,
414
- :errors => 0,
415
- :accuracy => 0},
416
- {:date => '02',
417
- :wpm => 10,
418
- :errors => 2,
419
- :accuracy => 80},
420
- {:date => '03',
421
- :wpm => 15,
422
- :errors => 0,
423
- :accuracy => 100},
424
- {:date => '04',
425
- :wpm => 16,
426
- :errors => 2,
427
- :accuracy => 87},
428
- {:date => '05'},
429
- {:date => '06',
430
- :wpm => 18,
431
- :errors => 1,
432
- :accuracy => 94},
433
- {:date => '07'},
434
- {:date => '08'},
435
- {:date => '09',
436
- :wpm => 21,
437
- :errors => 1,
438
- :accuracy => 95},
439
- {:date => '10'},
440
- {:date => '11'},
441
- {:date => '12'},
442
- {:date => '13'},
443
- {:date => '14'},
444
- {:date => '15'},
445
- {:date => '16'},
446
- {:date => '17'},
447
- {:date => '18'},
448
- {:date => '19',
449
- :wpm => 28,
450
- :errors => 5,
451
- :accuracy => 82},
452
- {:date => '20'},
453
- {:date => '21'},
454
- {:date => '22'},
455
- {:date => '23'},
456
- {:date => '24'},
457
- {:date => '25'},
458
- {:date => '26'},
459
- {:date => '27',
460
- :wpm => 37,
461
- :errors => 3,
462
- :accuracy => 92},
463
- ]
464
-
465
- [:wpm, :errors, :accuracy].each do |field|
466
- g.dataxy(field, data.each_with_index.map { |d, i| [i + 1, d[field]] if d[field] }.compact)
467
- end
468
-
469
- labels = Hash.new
470
- data.each_with_index do |d, i|
471
- labels[i + 1] = d[:date] if d.size > 1
472
- end
473
- g.labels = labels
474
-
475
- g.write('test/output/line_many_numbers.png')
476
- end
477
-
478
- def test_no_hide_line_no_labels
479
- g = Gruff::Line.new
480
- g.title = 'No Hide Line No Labels'
481
- @datasets.each do |data|
482
- g.data(data[0], data[1])
483
- end
484
- g.hide_line_markers = false
485
- g.write('test/output/line_no_hide.png')
486
- end
487
-
488
- def test_xy_data
489
- g = Gruff::Line.new
490
- g.title = 'X/Y Dataset'
491
- g.dataxy('Apples', [1, 3, 4, 5, 6, 10], [1, 2, 3, 4, 4, 3])
492
- g.dataxy('Bapples', [1, 3, 4, 5, 7, 9], [1, 1, 2, 2, 3, 3])
493
- g.data('Capples', [1, 1, 2, 2, 3, 3])
494
- g.labels = {0 => '2003', 2 => '2004', 4 => '2005', 6 => '2006', 8 => '2007', 10 => '2008'}
495
- g.write('test/output/line_xy.png')
496
- end
497
-
498
- def test_xy_data_pairs
499
- g = Gruff::Line.new
500
- g.title = 'X/Y Dataset Pairs'
501
- g.dataxy('Apples', [[1, 1], [3, 2], [4, 3], [5, 4], [6, 4], [10, 3]])
502
- g.dataxy('Bapples', [[1, 1], [3, 1], [4, 2], [5, 2], [7, 3], [9, 3]])
503
- g.data('Capples', [1, 1, 2, 2, 3, 3])
504
- g.dataxy('Dapples', [[1, 1], [2, 2], [5, 6], [13, 13], [15, nil], [2, 17], [3, nil], [3, 17], [13, nil], [3, 18], [5, nil], [2, 18]])
505
- g.dataxy('Eapples', [[1, 1], [2, 3], [5, 8], [13, 21], [13, 8], [5, 3], [2, 1], [1, 1]])
506
- g.labels = {0 => '2003', 2 => '2004', 4 => '2005', 6 => '2006', 8 => '2007', 10 => '2008', 12 => '2009'}
507
- g.write('test/output/line_xy_pairs.png')
508
- end
509
-
510
- def test_jruby_error
511
- g = Gruff::Line.new
512
- g.theme = {
513
- :colors => %w(#7F0099 #2F85ED #2FED09 #EC962F),
514
- :marker_color => '#aaa',
515
- :background_colors => %w(#E8E8E8 #B9FD6C)
516
- }
517
- g.hide_title = true
518
-
519
- g.legend_font_size = 12
520
- g.marker_font_size = 16
521
- g.hide_dots = false
522
-
523
- g.write('test/output/line_jruby_error.png')
524
- end
525
-
526
- def test_marker_label_accuracy
527
- g = Gruff::Line.new
528
- g.title = 'Marker label accuracy'
529
- g.labels = {
530
- 0 => '1',
531
- 1 => '2',
532
- 2 => '3',
533
- 3 => '4',
534
- 4 => '5'
535
- }
536
- g.data('first', [0.5, 0.51, 0.52, 0.53, 0.54])
537
- g.data('second', [0.6, 0.61, 0.62, 0.63, 0.64])
538
- g.data('third', [0.7, 0.71, 0.72, 0.73, 0.74])
539
-
540
- g.write('test/output/line_marker_label_accuracy.png')
541
- end
542
-
543
- def test_y_axis_increment
544
- g = Gruff::Line.new
545
- g.title = 'y axis increment'
546
-
547
- g.data('data', [1, 2, 3])
548
-
549
- g.y_axis_increment = 1
550
-
551
- g.write('test/output/line_y_axis_increment.png')
552
- end
553
-
554
- def test_multiple_reference_lines
555
-
556
- g = Gruff::Line.new
557
- g.title = 'Line Chart with Multiple Reference Lines'
558
-
559
- g.data('Apples', [3, 2, 3, 4, 4, 3])
560
- g.data('Oranges', [4, 8, 7, 9, 8, 9])
561
- g.data('Watermelon', [2, 3, 4, 5, 6, 8])
562
- g.data('Peaches', [9, 9, 10, 8, 7, 9])
563
-
564
- g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
565
-
566
- g.reference_line_default_width = 1
567
-
568
- g.reference_lines[:baseline] = { :value => 5 }
569
- g.reference_lines[:lots] = { :value => 9 }
570
- g.reference_lines[:little] = { :value => 3 }
571
- g.reference_lines[:horiz_one] = { :index => 1, :color => 'green' }
572
- g.reference_lines[:horiz_two] = { :index => 3, :color => 'green' }
573
-
574
- g.write('line_reference_lines.png')
575
- end
576
-
577
- def test_baseline
578
- g = Gruff::Line.new
579
- g.title = 'Line Chart with Baseline = 5'
580
-
581
- g.data('Apples', [3, 2, 3, 4, 4, 3])
582
- g.data('Oranges', [4, 8, 7, 9, 8, 9])
583
- g.data('Watermelon', [2, 3, 4, 5, 6, 8])
584
- g.data('Peaches', [9, 9, 10, 8, 7, 9])
585
-
586
- g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
587
- g.baseline_value = 5
588
-
589
- g.write('line_baseline.png')
590
- end
591
-
592
- def test_webp
593
- g = setup_basic_graph('800x400')
594
- g.title = 'Line Chart WEBP'
595
- g.write('line_webp.webp')
596
- rescue Magick::ImageMagickError
597
- assert_match(/no encode delegate for this image format .*\.webp/, $!.message)
598
- end
599
-
600
- private
601
-
602
- # TODO Reset data after each theme
603
- def line_graph_with_themes(size=nil)
604
- g = Gruff::Line.new(size)
605
- g.title = "Multi-Line Graph Test #{size}"
606
- g.labels = @labels
607
- g.baseline_value = 90
608
- @datasets.each do |data|
609
- g.data(data[0], data[1])
610
- end
611
- # Default theme
612
- g.write("test/output/line_theme_keynote_#{size}.png")
613
-
614
- g = Gruff::Line.new(size)
615
- g.title = "Multi-Line Graph Test #{size}"
616
- g.labels = @labels
617
- g.baseline_value = 90
618
- g.theme = Gruff::Themes::THIRTYSEVEN_SIGNALS
619
- @datasets.each do |data|
620
- g.data(data[0], data[1])
621
- end
622
- g.write("test/output/line_theme_37signals_#{size}.png")
623
-
624
- g = Gruff::Line.new(size)
625
- g.title = "Multi-Line Graph Test #{size}"
626
- g.labels = @labels
627
- g.baseline_value = 90
628
- g.theme = Gruff::Themes::RAILS_KEYNOTE
629
- @datasets.each do |data|
630
- g.data(data[0], data[1])
631
- end
632
- g.write("test/output/line_theme_rails_keynote_#{size}.png")
633
-
634
- g = Gruff::Line.new(size)
635
- g.title = "Multi-Line Graph Test #{size}"
636
- g.labels = @labels
637
- g.baseline_value = 90
638
- g.theme = Gruff::Themes::ODEO
639
- @datasets.each do |data|
640
- g.data(data[0], data[1])
641
- end
642
- g.write("test/output/line_theme_odeo_#{size}.png")
643
- end
644
-
645
- def setup_pos_neg(size=800)
646
- g = Gruff::Line.new(size)
647
- g.title = 'Pos/Neg Line Graph Test'
648
- g.labels = {
649
- 0 => '5/6',
650
- 1 => '5/15',
651
- 2 => '5/24',
652
- 3 => '5/30',
653
- }
654
- g.data(:apples, [-1, 0, 4, -4])
655
- g.data(:peaches, [10, 8, 6, 3])
656
- g
657
- end
658
-
659
-
660
- def setup_all_neg(size=800)
661
- g = Gruff::Line.new(size)
662
- g.title = 'All Neg Line Graph Test'
663
- g.labels = {
664
- 0 => '5/6',
665
- 1 => '5/15',
666
- 2 => '5/24',
667
- 3 => '5/30',
668
- }
669
- g.data(:apples, [-1, -5, -20, -4])
670
- g.data(:peaches, [-10, -8, -6, -3])
671
- g
672
- end
673
-
674
- end