|
13 | 13 | ] |
14 | 14 | end |
15 | 15 |
|
16 | | - context "#dot!", focus: true do |
| 16 | + context "#stacked_bar!" do |
| 17 | + before do |
| 18 | + @temp_dir = SPEC_ROOT + "temp/stacked_bar" |
| 19 | + @fix_dir = SPEC_ROOT + "fixtures/stacked_bar" |
| 20 | + FileUtils.mkdir_p @temp_dir |
| 21 | + end |
| 22 | + |
| 23 | + it "plots a single stacked bar graph with default colors" do |
| 24 | + fig = Rubyplot::Figure.new |
| 25 | + axes = fig.add_subplot 0,0 |
| 26 | + axes.stacked_bar! do |p| |
| 27 | + p.data [25, 36, 86, 39] |
| 28 | + p.label = "moon" |
| 29 | + end |
| 30 | + axes.title = "net earnings in different months." |
| 31 | + axes.x_ticks = { |
| 32 | + 0 => 'Jan', |
| 33 | + 1 => 'Feb', |
| 34 | + 2 => 'March', |
| 35 | + 3 => 'April', |
| 36 | + 4 => 'May', |
| 37 | + 5 => 'June', |
| 38 | + 6 => 'July', |
| 39 | + 7 => 'August', |
| 40 | + 8 => 'September', |
| 41 | + 9 => 'October', |
| 42 | + 10 => 'November', |
| 43 | + 11 => 'December' |
| 44 | + } |
| 45 | + |
| 46 | + file = "/#{Rubyplot.backend}_simple_stacked_bar.png" |
| 47 | + fig.write(@temp_dir + file) |
| 48 | + |
| 49 | + #expect("temp/stacked_bar" + file).to eq_image("fixtures/stacked_bar" + file) |
| 50 | + end |
| 51 | + |
| 52 | + it "plots multiple stacked bar graphs with default colors" do |
| 53 | + fig = Rubyplot::Figure.new |
| 54 | + axes = fig.add_subplot 0,0 |
| 55 | + [ |
| 56 | + ["Charles", [20, 10, 5, 12, 11, 6, 10, 7]], |
| 57 | + ["Adam", [5, 10, 20, 6, 9, 12, 14, 8]], |
| 58 | + ["Daniel", [19, 9, 6, 11, 12, 7, 15, 8]] |
| 59 | + ].each do |label, data| |
| 60 | + axes.stacked_bar! do |p| |
| 61 | + p.data data |
| 62 | + p.label = label |
| 63 | + end |
| 64 | + end |
| 65 | + axes.title = "net earnings in different months." |
| 66 | + axes.x_ticks = { |
| 67 | + 0 => 'Jan', |
| 68 | + 1 => 'Feb', |
| 69 | + 2 => 'March', |
| 70 | + 3 => 'April', |
| 71 | + 4 => 'May', |
| 72 | + 5 => 'June', |
| 73 | + 6 => 'July', |
| 74 | + 7 => 'August', |
| 75 | + 8 => 'September', |
| 76 | + 9 => 'October', |
| 77 | + 10 => 'November', |
| 78 | + 11 => 'December' |
| 79 | + } |
| 80 | + |
| 81 | + file = "/#{Rubyplot.backend}_multiple_stacked_bar.png" |
| 82 | + fig.write(@temp_dir + file) |
| 83 | + |
| 84 | + #expect("temp/stacked_bar" + file).to eq_image("fixtures/stacked_bar" + file) |
| 85 | + end |
| 86 | + |
| 87 | + it "plots stacked bar in a small size" do |
| 88 | + fig = Rubyplot::Figure.new |
| 89 | + axes = fig.add_subplot 0,0 |
| 90 | + [ |
| 91 | + ["Car", [25, 36, 86, 39]], |
| 92 | + ["Bus", [80, 54, 67, 54]], |
| 93 | + ["Train", [22, 29, 35, 38]] |
| 94 | + ].each do |label, data| |
| 95 | + axes.stacked_bar!(400) do |p| |
| 96 | + p.data data |
| 97 | + p.label = label |
| 98 | + end |
| 99 | + end |
| 100 | + axes.title = "stacked bar." |
| 101 | + |
| 102 | + file = "/#{Rubyplot.backend}_small_stacked_bar.png" |
| 103 | + fig.write(@temp_dir + file) |
| 104 | + |
| 105 | + #expect("temp/stacked_bar" + file).to eq_image("fixtures/stacked_bar" + file) |
| 106 | + end |
| 107 | + end |
| 108 | + |
| 109 | + context "#dot!" do |
17 | 110 | before do |
18 | 111 | @temp_dir = SPEC_ROOT + "temp/dot" |
19 | 112 | @fix_dir = SPEC_ROOT + "fixtures/dot" |
|
64 | 157 | 3 => '5/30' |
65 | 158 | } |
66 | 159 |
|
67 | | - file = "/#{Rubyplot.backend}_simple_dot.png" |
| 160 | + file = "/#{Rubyplot.backend}_multiple_dot.png" |
68 | 161 | fig.write(@temp_dir + file) |
69 | 162 |
|
70 | 163 | #expect("temp/dot" + file).to eq_image("fixtures/dot" + file) |
|
0 commit comments