File: test_sidestacked_bar.rb

package info (click to toggle)
ruby-gruff 0.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 852 kB
  • sloc: ruby: 4,929; makefile: 3
file content (105 lines) | stat: -rw-r--r-- 2,334 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/ruby

require File.dirname(__FILE__) + "/gruff_test_case"

class TestGruffSideStackedBar < GruffTestCase

  def setup
    @datasets = [
      [:Jimmy, [25, 36, 86, 39]],
      [:Charles, [80, 54, 67, 54]],
      [:Julie, [22, 29, 35, 38]],
      #[: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'
      }      

  end

  def test_bar_graph
    g = Gruff::SideStackedBar.new
    g.title = "Visual Stacked Bar Graph Test"
    g.labels = {
      0 => '5/6', 
      1 => '5/15', 
      2 => '5/24', 
      3 => '5/30', 
    }
    @datasets.each do |data|
      g.data(data[0], data[1])
    end
    g.write "test/output/side_stacked_bar_keynote.png"
  end


  def test_bar_graph_small
    g = Gruff::SideStackedBar.new(400)
    g.title = "Visual Stacked Bar Graph Test"
    g.labels = {
      0 => '5/6', 
      1 => '5/15', 
      2 => '5/24', 
      3 => '5/30', 
    }
    @datasets.each do |data|
      g.data(data[0], data[1])
    end
    g.write "test/output/side_stacked_bar_keynote_small.png"
  end

  def test_wide
    g = setup_basic_graph('800x400')
    g.title = "Wide SSBar"
    g.write "test/output/side_stacked_bar_wide.png"
  end

  def test_should_space_long_left_labels_appropriately
    g = Gruff::SideStackedBar.new
    g.title = "Stacked Bar Long Label"
    g.labels = {
      0 => 'September', 
      1 => 'Oct', 
      2 => 'Nov', 
      3 => 'Dec', 
    }
    @datasets.each do |data|
      g.data(data[0], data[1])
    end
    g.write "test/output/side_stacked_bar_long_label.png"
  end
  
  def test_bar_labels
     g = Gruff::SideStackedBar.new
     g.title = "Stacked Bar Long Label"
     g.labels = {
       0 => 'September', 
       1 => 'Oct', 
       2 => 'Nov', 
       3 => 'Dec', 
     }
     @datasets.each do |data|
       g.data(data[0], data[1])
     end
     g.show_labels_for_bar_values = true
     g.write "test/output/side_stacked_bar_labels.png"
   end

protected

  def setup_basic_graph(size=800)
    g = Gruff::SideStackedBar.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