1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#!/usr/bin/ruby
require File.dirname(__FILE__) + "/gruff_test_case"
class TestGruffArea < GruffTestCase
def setup
super
@datasets = [
[:Jimmy, [25, 36, 86, 39, 25, 31, 79, 88]],
[:Charles, [80, 54, 67, 54, 68, 70, 90, 95]],
[:Julie, [22, 29, 35, 38, 36, 40, 46, 57]],
[:Jane, [95, 95, 95, 90, 85, 80, 88, 100]],
[:Philip, [90, 34, 23, 12, 78, 89, 98, 88]],
["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]],
]
@sample_labels = {
0 => '5/6',
1 => '5/15',
2 => '5/24',
3 => '5/30',
4 => '6/4',
5 => '6/12',
6 => '6/21',
7 => '6/28',
}
end
def test_area_graph
g = Gruff::Area.new
g.title = "Visual Multi-Area Graph Test"
g.labels = {
0 => '5/6',
2 => '5/15',
4 => '5/24',
6 => '5/30',
}
@datasets.each do |data|
g.data(data[0], data[1])
end
# Default theme
g.write("test/output/area_keynote.png")
end
def test_resize
g = Gruff::Area.new(400)
g.title = "Small Size Multi-Area Graph Test"
g.labels = {
0 => '5/6',
2 => '5/15',
4 => '5/24',
6 => '5/30',
}
@datasets.each do |data|
g.data(data[0], data[1])
end
# Default theme
g.write("test/output/area_keynote_small.png")
end
def test_many_datapoints
g = Gruff::Area.new
g.title = "Many Multi-Area Graph Test"
g.labels = {
0 => 'June',
10 => 'July',
30 => 'August',
50 => 'September',
}
g.data('many points', (0..50).collect {|i| rand(100) })
# Default theme
g.write("test/output/area_many.png")
end
def test_many_areas_graph_small
g = Gruff::Area.new(400)
g.title = "Many Values Area Test 400px"
g.labels = {
0 => '5/6',
10 => '5/15',
20 => '5/24',
30 => '5/30',
40 => '6/4',
50 => '6/16'
}
%w{jimmy jane philip arthur julie bert}.each do |student_name|
g.data(student_name, (0..50).collect { |i| rand 100 })
end
# Default theme
g.write("test/output/area_many_areas_small.png")
end
def test_area_graph_tiny
g = Gruff::Area.new(300)
g.title = "Area Test 300px"
g.labels = {
0 => '5/6',
10 => '5/15',
20 => '5/24',
30 => '5/30',
40 => '6/4',
50 => '6/16'
}
%w{jimmy jane philip arthur julie bert}.each do |student_name|
g.data(student_name, (0..50).collect { |i| rand 100 })
end
# Default theme
g.write("test/output/area_tiny.png")
end
def test_wide
g = setup_basic_graph('800x400')
g.title = "Area Wide"
g.write("test/output/area_wide.png")
end
protected
def setup_basic_graph(size=800)
g = Gruff::Area.new(size)
g.title = "My Graph Title"
g.labels = @sample_labels
@datasets.each do |data|
g.data(data[0], data[1])
end
return g
end
end
|