gruff 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +5 -0
- data/.travis.yml +8 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/README.txt +3 -0
- data/Rakefile +17 -34
- data/gruff.gemspec +33 -0
- data/lib/gruff.rb +3 -0
- data/lib/gruff/base.rb +17 -14
- data/lib/gruff/line.rb +104 -11
- data/lib/gruff/mini/legend.rb +50 -23
- data/lib/gruff/pie.rb +8 -6
- data/lib/gruff/scatter.rb +268 -0
- data/lib/gruff/scene.rb +1 -1
- data/lib/gruff/side_bar.rb +13 -7
- data/lib/gruff/side_stacked_bar.rb +9 -6
- data/lib/gruff/stacked_bar.rb +3 -0
- data/lib/gruff/version.rb +3 -0
- data/test/gruff_test_case.rb +2 -0
- data/test/test_bar.rb +16 -1
- data/test/test_line.rb +102 -64
- data/test/test_mini_bar.rb +1 -1
- data/test/test_mini_pie.rb +7 -2
- data/test/test_mini_side_bar.rb +1 -2
- data/test/test_scatter.rb +233 -0
- data/test/test_scene.rb +1 -1
- data/test/test_side_bar.rb +31 -0
- metadata +41 -27
@@ -11,13 +11,18 @@ require File.dirname(__FILE__) + '/stacked_mixin'
|
|
11
11
|
class Gruff::SideStackedBar < Gruff::SideBar
|
12
12
|
include StackedMixin
|
13
13
|
|
14
|
+
# Spacing factor applied between bars
|
15
|
+
attr_accessor :bar_spacing
|
16
|
+
|
14
17
|
def draw
|
15
18
|
@has_left_labels = true
|
16
19
|
get_maximum_by_stack
|
17
20
|
super
|
21
|
+
end
|
18
22
|
|
19
|
-
|
23
|
+
protected
|
20
24
|
|
25
|
+
def draw_bars
|
21
26
|
# Setup spacing.
|
22
27
|
#
|
23
28
|
# Columns sit stacked.
|
@@ -30,8 +35,6 @@ class Gruff::SideStackedBar < Gruff::SideBar
|
|
30
35
|
padding = (@bar_width * (1 - @bar_spacing)) / 2
|
31
36
|
|
32
37
|
@norm_data.each_with_index do |data_row, row_index|
|
33
|
-
@d = @d.fill data_row[DATA_COLOR_INDEX]
|
34
|
-
|
35
38
|
data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
|
36
39
|
|
37
40
|
## using the original calcs from the stacked bar chart to get the difference between
|
@@ -42,7 +45,9 @@ class Gruff::SideStackedBar < Gruff::SideBar
|
|
42
45
|
temp2 = @graph_left + @graph_width - height[point_index] - 1
|
43
46
|
difference = temp2 - temp1
|
44
47
|
|
45
|
-
|
48
|
+
@d = @d.fill data_row[DATA_COLOR_INDEX]
|
49
|
+
|
50
|
+
left_x = length[point_index] #+ 1
|
46
51
|
left_y = @graph_top + (@bar_width * point_index) + padding
|
47
52
|
right_x = left_x + difference
|
48
53
|
right_y = left_y + @bar_width * @bar_spacing
|
@@ -61,8 +66,6 @@ class Gruff::SideStackedBar < Gruff::SideBar
|
|
61
66
|
@d.draw(@base_image)
|
62
67
|
end
|
63
68
|
|
64
|
-
protected
|
65
|
-
|
66
69
|
def larger_than_max?(data_point, index=0)
|
67
70
|
max(data_point, index) > @maximum_value
|
68
71
|
end
|
data/lib/gruff/stacked_bar.rb
CHANGED
@@ -5,6 +5,9 @@ require File.dirname(__FILE__) + '/stacked_mixin'
|
|
5
5
|
class Gruff::StackedBar < Gruff::Base
|
6
6
|
include StackedMixin
|
7
7
|
|
8
|
+
# Spacing factor applied between bars
|
9
|
+
attr_accessor :bar_spacing
|
10
|
+
|
8
11
|
# Draws a bar graph, but multiple sets are stacked on top of each other.
|
9
12
|
def draw
|
10
13
|
get_maximum_by_stack
|
data/test/gruff_test_case.rb
CHANGED
data/test/test_bar.rb
CHANGED
@@ -37,7 +37,6 @@ class TestGruffBar < GruffTestCase
|
|
37
37
|
def test_thousand_separators
|
38
38
|
g = Gruff::Bar.new(600)
|
39
39
|
g.title = "Formatted numbers"
|
40
|
-
g.bar_spacing = 0.2
|
41
40
|
g.marker_count = 8
|
42
41
|
g.data("data", [4025, 1024, 50257, 703672, 1580456])
|
43
42
|
g.write("test/output/bar_formatted_numbers.png")
|
@@ -284,6 +283,22 @@ class TestGruffBar < GruffTestCase
|
|
284
283
|
write_test_file g, 'enhancements.png'
|
285
284
|
end
|
286
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
|
287
302
|
|
288
303
|
protected
|
289
304
|
|
data/test/test_line.rb
CHANGED
@@ -15,28 +15,28 @@ class TestGruffLine < GruffTestCase
|
|
15
15
|
:font_color => 'black',
|
16
16
|
:background_colors => 'transparent'
|
17
17
|
}
|
18
|
-
|
18
|
+
|
19
19
|
g.labels = {
|
20
|
-
0 => '5/6',
|
21
|
-
1 => '5/15',
|
22
|
-
2 => '5/24',
|
23
|
-
3 => '5/30',
|
20
|
+
0 => '5/6',
|
21
|
+
1 => '5/15',
|
22
|
+
2 => '5/24',
|
23
|
+
3 => '5/30',
|
24
24
|
}
|
25
25
|
g.data(:apples, [-1, 0, 4, -4])
|
26
26
|
g.data(:peaches, [10, 8, 6, 3])
|
27
27
|
g.write("test/output/line_transparent.png")
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def test_line_graph_with_themes
|
31
31
|
line_graph_with_themes()
|
32
32
|
line_graph_with_themes(400)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_one_value
|
36
36
|
g = Gruff::Line.new
|
37
37
|
g.title = "One Value"
|
38
38
|
g.labels = {
|
39
|
-
0 => '1',
|
39
|
+
0 => '1',
|
40
40
|
1 => '2'
|
41
41
|
}
|
42
42
|
g.data('one', 1)
|
@@ -48,7 +48,7 @@ class TestGruffLine < GruffTestCase
|
|
48
48
|
g = Gruff::Line.new
|
49
49
|
g.title = "One Value in an Array"
|
50
50
|
g.labels = {
|
51
|
-
0 => '1',
|
51
|
+
0 => '1',
|
52
52
|
1 => '2'
|
53
53
|
}
|
54
54
|
g.data('one', [1])
|
@@ -76,8 +76,8 @@ class TestGruffLine < GruffTestCase
|
|
76
76
|
# g.write("test/output/line_crash_fix_test.png")
|
77
77
|
# end
|
78
78
|
|
79
|
-
|
80
|
-
def test_line_small_values
|
79
|
+
|
80
|
+
def test_line_small_values
|
81
81
|
@datasets = [
|
82
82
|
[:small, [0.1, 0.14356, 0.0, 0.5674839, 0.456]],
|
83
83
|
[:small2, [0.2, 0.3, 0.1, 0.05, 0.9]]
|
@@ -119,8 +119,8 @@ class TestGruffLine < GruffTestCase
|
|
119
119
|
g.write("test/output/line_small_small_zero.png")
|
120
120
|
end
|
121
121
|
|
122
|
-
|
123
|
-
def test_line_large_values
|
122
|
+
|
123
|
+
def test_line_large_values
|
124
124
|
@datasets = [
|
125
125
|
[:large, [100_005, 35_000, 28_000, 27_000]],
|
126
126
|
[:large2, [35_000, 28_000, 27_000, 100_005]],
|
@@ -140,15 +140,15 @@ class TestGruffLine < GruffTestCase
|
|
140
140
|
|
141
141
|
g.write("test/output/line_large.png")
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
# def test_long_title
|
145
|
-
#
|
145
|
+
#
|
146
146
|
# end
|
147
|
-
#
|
147
|
+
#
|
148
148
|
# def test_add_colors
|
149
|
-
#
|
149
|
+
#
|
150
150
|
# end
|
151
|
-
#
|
151
|
+
#
|
152
152
|
|
153
153
|
def test_request_too_many_colors
|
154
154
|
g = Gruff::Line.new
|
@@ -160,22 +160,22 @@ class TestGruffLine < GruffTestCase
|
|
160
160
|
@datasets.each do |data|
|
161
161
|
g.data("#{data[0]}-B", data[1].map {|d| d + 20})
|
162
162
|
end
|
163
|
-
g.write("test/output/line_more_sets_than_colors.png")
|
163
|
+
g.write("test/output/line_more_sets_than_colors.png")
|
164
164
|
end
|
165
|
-
|
166
|
-
#
|
165
|
+
|
166
|
+
#
|
167
167
|
# def test_add_data
|
168
|
-
#
|
168
|
+
#
|
169
169
|
# end
|
170
170
|
|
171
171
|
def test_many_datapoints
|
172
172
|
g = Gruff::Line.new
|
173
173
|
g.title = "Many Multi-Line Graph Test"
|
174
174
|
g.labels = {
|
175
|
-
0 => 'June',
|
176
|
-
10 => 'July',
|
177
|
-
30 => 'August',
|
178
|
-
50 => 'September',
|
175
|
+
0 => 'June',
|
176
|
+
10 => 'July',
|
177
|
+
30 => 'August',
|
178
|
+
50 => 'September',
|
179
179
|
}
|
180
180
|
g.data('many points', (0..50).collect {|i| rand(100) })
|
181
181
|
g.x_axis_label = "Months"
|
@@ -192,7 +192,7 @@ class TestGruffLine < GruffTestCase
|
|
192
192
|
g.title = "Similar High End Values Test"
|
193
193
|
g.data('similar points', @dataset )
|
194
194
|
g.write("test/output/line_similar_high_end_values.png")
|
195
|
-
|
195
|
+
|
196
196
|
g = Gruff::Line.new
|
197
197
|
g.title = "Similar High End Values With Floor"
|
198
198
|
g.data('similar points', @dataset )
|
@@ -205,11 +205,11 @@ class TestGruffLine < GruffTestCase
|
|
205
205
|
g = Gruff::Line.new(400)
|
206
206
|
g.title = "Many Values Line Test 400px"
|
207
207
|
g.labels = {
|
208
|
-
0 => '5/6',
|
209
|
-
10 => '5/15',
|
210
|
-
20 => '5/24',
|
211
|
-
30 => '5/30',
|
212
|
-
40 => '6/4',
|
208
|
+
0 => '5/6',
|
209
|
+
10 => '5/15',
|
210
|
+
20 => '5/24',
|
211
|
+
30 => '5/30',
|
212
|
+
40 => '6/4',
|
213
213
|
50 => '6/16'
|
214
214
|
}
|
215
215
|
%w{jimmy jane philip arthur julie bert}.each do |student_name|
|
@@ -224,11 +224,11 @@ class TestGruffLine < GruffTestCase
|
|
224
224
|
g = Gruff::Line.new(300)
|
225
225
|
g.title = "Tiny Test 300px"
|
226
226
|
g.labels = {
|
227
|
-
0 => '5/6',
|
228
|
-
10 => '5/15',
|
229
|
-
20 => '5/24',
|
230
|
-
30 => '5/30',
|
231
|
-
40 => '6/4',
|
227
|
+
0 => '5/6',
|
228
|
+
10 => '5/15',
|
229
|
+
20 => '5/24',
|
230
|
+
30 => '5/30',
|
231
|
+
40 => '6/4',
|
232
232
|
50 => '6/16'
|
233
233
|
}
|
234
234
|
%w{jimmy jane philip arthur julie bert}.each do |student_name|
|
@@ -244,7 +244,7 @@ class TestGruffLine < GruffTestCase
|
|
244
244
|
g.title = "No Data"
|
245
245
|
# Default theme
|
246
246
|
g.write("test/output/line_no_data.png")
|
247
|
-
|
247
|
+
|
248
248
|
g = Gruff::Line.new(400)
|
249
249
|
g.title = "No Data Title"
|
250
250
|
g.no_data_message = 'There is no data'
|
@@ -259,7 +259,7 @@ class TestGruffLine < GruffTestCase
|
|
259
259
|
g.data(:gus, [0,0,0,0])
|
260
260
|
|
261
261
|
# Default theme
|
262
|
-
g.write("test/output/line_no_data_other.png")
|
262
|
+
g.write("test/output/line_no_data_other.png")
|
263
263
|
end
|
264
264
|
|
265
265
|
|
@@ -279,7 +279,7 @@ class TestGruffLine < GruffTestCase
|
|
279
279
|
end
|
280
280
|
|
281
281
|
# Default theme
|
282
|
-
g.write("test/output/line_some_nil_points.png")
|
282
|
+
g.write("test/output/line_some_nil_points.png")
|
283
283
|
end
|
284
284
|
|
285
285
|
def test_no_title
|
@@ -296,7 +296,7 @@ class TestGruffLine < GruffTestCase
|
|
296
296
|
g = setup_basic_graph(400)
|
297
297
|
g.title = "No Line Markers"
|
298
298
|
g.hide_line_markers = true
|
299
|
-
g.write("test/output/line_no_line_markers.png")
|
299
|
+
g.write("test/output/line_no_line_markers.png")
|
300
300
|
end
|
301
301
|
|
302
302
|
def test_no_legend
|
@@ -312,14 +312,14 @@ class TestGruffLine < GruffTestCase
|
|
312
312
|
g.hide_line_markers = true
|
313
313
|
g.hide_legend = true
|
314
314
|
g.hide_title = true
|
315
|
-
g.write("test/output/line_nothing_but_the_graph.png")
|
315
|
+
g.write("test/output/line_nothing_but_the_graph.png")
|
316
316
|
end
|
317
317
|
|
318
318
|
def test_baseline_larger_than_data
|
319
319
|
g = setup_basic_graph(400)
|
320
320
|
g.title = "Baseline Larger Than Data"
|
321
321
|
g.baseline_value = 150
|
322
|
-
g.write("test/output/line_large_baseline.png")
|
322
|
+
g.write("test/output/line_large_baseline.png")
|
323
323
|
end
|
324
324
|
|
325
325
|
|
@@ -327,20 +327,20 @@ class TestGruffLine < GruffTestCase
|
|
327
327
|
g = setup_basic_graph(400)
|
328
328
|
g.title = "Hide Dots"
|
329
329
|
g.hide_dots = true
|
330
|
-
g.write("test/output/line_hide_dots.png")
|
330
|
+
g.write("test/output/line_hide_dots.png")
|
331
331
|
end
|
332
332
|
|
333
333
|
def test_hide_lines
|
334
334
|
g = setup_basic_graph(400)
|
335
335
|
g.title = "Hide Lines"
|
336
336
|
g.hide_lines = true
|
337
|
-
g.write("test/output/line_hide_lines.png")
|
337
|
+
g.write("test/output/line_hide_lines.png")
|
338
338
|
end
|
339
339
|
|
340
340
|
def test_wide_graph
|
341
341
|
g = setup_basic_graph('800x400')
|
342
342
|
g.title = "Wide Graph"
|
343
|
-
g.write("test/output/line_wide_graph.png")
|
343
|
+
g.write("test/output/line_wide_graph.png")
|
344
344
|
|
345
345
|
g = setup_basic_graph('400x200')
|
346
346
|
g.title = "Wide Graph Small"
|
@@ -350,7 +350,7 @@ class TestGruffLine < GruffTestCase
|
|
350
350
|
def test_negative
|
351
351
|
g = setup_pos_neg(800)
|
352
352
|
g.write("test/output/line_pos_neg.png")
|
353
|
-
|
353
|
+
|
354
354
|
g = setup_pos_neg(400)
|
355
355
|
g.title = 'Pos/Neg Line Test Small'
|
356
356
|
g.write("test/output/line_pos_neg_400.png")
|
@@ -359,13 +359,13 @@ class TestGruffLine < GruffTestCase
|
|
359
359
|
def test_all_negative
|
360
360
|
g = setup_all_neg(800)
|
361
361
|
g.write("test/output/line_all_neg.png")
|
362
|
-
|
362
|
+
|
363
363
|
g = setup_all_neg(400)
|
364
364
|
g.title = 'All Neg Line Test Small'
|
365
365
|
g.write("test/output/line_all_neg_400.png")
|
366
366
|
end
|
367
367
|
|
368
|
-
def test_many_numbers
|
368
|
+
def test_many_numbers
|
369
369
|
g = Gruff::Line.new('400x170')
|
370
370
|
g.title = "Line Test, Many Numbers"
|
371
371
|
|
@@ -419,7 +419,7 @@ class TestGruffLine < GruffTestCase
|
|
419
419
|
{ :date => '23'},
|
420
420
|
{ :date => '24'},
|
421
421
|
{ :date => '25'},
|
422
|
-
{ :date => '26'},
|
422
|
+
{ :date => '26'},
|
423
423
|
{ :date => '27',
|
424
424
|
:wpm => 37,
|
425
425
|
:errors => 3,
|
@@ -448,7 +448,28 @@ class TestGruffLine < GruffTestCase
|
|
448
448
|
g.hide_line_markers = false
|
449
449
|
g.write('test/output/line_no_hide.png')
|
450
450
|
end
|
451
|
-
|
451
|
+
|
452
|
+
def test_xy_data
|
453
|
+
g = Gruff::Line.new
|
454
|
+
g.title = "X/Y Dataset"
|
455
|
+
g.dataxy("Apples", [1,3,4,5,6,10], [1, 2, 3, 4, 4, 3])
|
456
|
+
g.dataxy("Bapples", [1,3,4,5,7,9], [1, 1, 2, 2, 3, 3])
|
457
|
+
g.data("Capples", [1, 1, 2, 2, 3, 3])
|
458
|
+
g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
|
459
|
+
g.write('test/output/data_xy.png')
|
460
|
+
end
|
461
|
+
|
462
|
+
def test_xy_data_pairs
|
463
|
+
g = Gruff::Line.new
|
464
|
+
g.title = "X/Y Dataset"
|
465
|
+
g.dataxy("Apples", [[1,1], [3,2],[4,3],[5,4],[6,4],[10,3]])
|
466
|
+
g.dataxy("Bapples", [[1,1],[3,1],[4,2],[5,2],[7,3],[9,3]])
|
467
|
+
g.data("Capples", [1, 1, 2, 2, 3, 3])
|
468
|
+
g.dataxy("Dapples", [[1,1],[2,3],[5,8],[13,21]])
|
469
|
+
g.dataxy("Eapples", [[1,1],[2,3],[5,8],[13,21],[13,8],[5,3],[2,1],[1,1]])
|
470
|
+
g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
|
471
|
+
g.write('test/output/data_xy_pairs.png')
|
472
|
+
end
|
452
473
|
|
453
474
|
def test_jruby_error
|
454
475
|
g = Gruff::Line.new
|
@@ -462,13 +483,30 @@ class TestGruffLine < GruffTestCase
|
|
462
483
|
g.legend_font_size = 12
|
463
484
|
g.marker_font_size = 16
|
464
485
|
g.hide_dots = false
|
465
|
-
g.label_max_decimals = 1
|
466
486
|
|
467
487
|
g.write('test/output/line_jruby_error.png')
|
468
488
|
end
|
469
489
|
|
490
|
+
def test_marker_label_accuracy
|
491
|
+
g = Gruff::Line.new
|
492
|
+
g.title = "Marker label accuracy"
|
493
|
+
g.labels = {
|
494
|
+
0 => '1',
|
495
|
+
1 => '2',
|
496
|
+
2 => '3',
|
497
|
+
3 => '4',
|
498
|
+
4 => '5'
|
499
|
+
}
|
500
|
+
g.data('first', [0.5, 0.51, 0.52, 0.53, 0.54])
|
501
|
+
g.data('second', [0.6, 0.61, 0.62, 0.63, 0.64])
|
502
|
+
g.data('third', [0.7, 0.71, 0.72, 0.73, 0.74])
|
503
|
+
|
504
|
+
g.write("test/output/line_marker_label_accuracy.png")
|
505
|
+
end
|
506
|
+
|
507
|
+
|
470
508
|
private
|
471
|
-
|
509
|
+
|
472
510
|
def bmi(params={})
|
473
511
|
g = basic_graph()
|
474
512
|
|
@@ -492,7 +530,7 @@ private
|
|
492
530
|
end
|
493
531
|
# Default theme
|
494
532
|
g.write("test/output/line_theme_keynote_#{size}.png")
|
495
|
-
|
533
|
+
|
496
534
|
g = Gruff::Line.new(size)
|
497
535
|
g.title = "Multi-Line Graph Test #{size}"
|
498
536
|
g.labels = @labels
|
@@ -502,7 +540,7 @@ private
|
|
502
540
|
g.data(data[0], data[1])
|
503
541
|
end
|
504
542
|
g.write("test/output/line_theme_37signals_#{size}.png")
|
505
|
-
|
543
|
+
|
506
544
|
g = Gruff::Line.new(size)
|
507
545
|
g.title = "Multi-Line Graph Test #{size}"
|
508
546
|
g.labels = @labels
|
@@ -512,7 +550,7 @@ private
|
|
512
550
|
g.data(data[0], data[1])
|
513
551
|
end
|
514
552
|
g.write("test/output/line_theme_rails_keynote_#{size}.png")
|
515
|
-
|
553
|
+
|
516
554
|
g = Gruff::Line.new(size)
|
517
555
|
g.title = "Multi-Line Graph Test #{size}"
|
518
556
|
g.labels = @labels
|
@@ -528,10 +566,10 @@ private
|
|
528
566
|
g = Gruff::Line.new(size)
|
529
567
|
g.title = "Pos/Neg Line Graph Test"
|
530
568
|
g.labels = {
|
531
|
-
0 => '5/6',
|
532
|
-
1 => '5/15',
|
533
|
-
2 => '5/24',
|
534
|
-
3 => '5/30',
|
569
|
+
0 => '5/6',
|
570
|
+
1 => '5/15',
|
571
|
+
2 => '5/24',
|
572
|
+
3 => '5/30',
|
535
573
|
}
|
536
574
|
g.data(:apples, [-1, 0, 4, -4])
|
537
575
|
g.data(:peaches, [10, 8, 6, 3])
|
@@ -543,10 +581,10 @@ private
|
|
543
581
|
g = Gruff::Line.new(size)
|
544
582
|
g.title = "All Neg Line Graph Test"
|
545
583
|
g.labels = {
|
546
|
-
0 => '5/6',
|
547
|
-
1 => '5/15',
|
548
|
-
2 => '5/24',
|
549
|
-
3 => '5/30',
|
584
|
+
0 => '5/6',
|
585
|
+
1 => '5/15',
|
586
|
+
2 => '5/24',
|
587
|
+
3 => '5/30',
|
550
588
|
}
|
551
589
|
g.data(:apples, [-1, -5, -20, -4])
|
552
590
|
g.data(:peaches, [-10, -8, -6, -3])
|