|
55 | 55 | end
|
56 | 56 | end
|
57 | 57 |
|
58 |
| - context 'handling plots as container' do |
| 58 | + context 'safe plot array update' do |
59 | 59 | before :each do
|
60 | 60 | @sinx = Plot.new('sin(x)')
|
61 | 61 | @plot3d = Splot.new('sin(x)*cos(y)')
|
|
122 | 122 | expect(mp[0..-1]).to be_eql(mp.plots)
|
123 | 123 | end
|
124 | 124 | end
|
| 125 | + |
| 126 | + context 'destructive plot array update' do |
| 127 | + before :each do |
| 128 | + plots = [ |
| 129 | + Plot.new('sin(x)'), |
| 130 | + Splot.new('sin(x)*cos(y)'), |
| 131 | + Plot.new('exp(x)') |
| 132 | + ] |
| 133 | + @mp = Multiplot.new(*plots, layout: [1, 3]) |
| 134 | + end |
| 135 | + |
| 136 | + it 'should update plots in the existing Plot' do |
| 137 | + @mp.update!(0) do |plot| |
| 138 | + plot.options!(title: 'Updated plot') |
| 139 | + plot.replace_dataset!('exp(x)') |
| 140 | + plot[0].lw!(3) |
| 141 | + end |
| 142 | + expect(@mp[0].title).to eql('Updated plot') |
| 143 | + expect(@mp[0][0].data).to eql('exp(x)') |
| 144 | + expect(@mp[0][0].lw).to eql(3) |
| 145 | + end |
| 146 | + |
| 147 | + it 'should replace plot in the existing Multiplot' do |
| 148 | + plot = Plot.new('cos(x)', title: 'Second plot') |
| 149 | + expect(@mp.replace!(1, plot)).to equal(@mp) |
| 150 | + expect(@mp[1].title).to eql('Second plot') |
| 151 | + @mp[0] = Plot.new('cos(x)', title: 'First plot') |
| 152 | + expect(@mp[0].title).to eql('First plot') |
| 153 | + end |
| 154 | + |
| 155 | + it 'should add plots to the existing Multiplot' do |
| 156 | + plot = Plot.new('cos(x)', title: 'First plot') |
| 157 | + expect(@mp.add!(plot)).to equal(@mp) |
| 158 | + expect(@mp[0].title).to eql('First plot') |
| 159 | + expect(@mp.plots.size).to eql(4) |
| 160 | + end |
| 161 | + |
| 162 | + it 'should remove plot from the existing Multiplot' do |
| 163 | + plot = Plot.new('cos(x)', title: 'Last plot') |
| 164 | + expect(@mp.add!(-1, plot)).to equal(@mp) |
| 165 | + expect(@mp.plots.size).to eql(4) |
| 166 | + expect(@mp.remove!).to equal(@mp) |
| 167 | + expect(@mp.plots.size).to eql(3) |
| 168 | + expect(@mp.plots.last.title).to eql('Last plot') |
| 169 | + end |
| 170 | + end |
125 | 171 | end
|
0 commit comments