|
1 | 1 | var Plotly = require('@lib/index');
|
2 | 2 | var Plots = require('@src/plots/plots');
|
3 | 3 | var Images = require('@src/components/images');
|
| 4 | + |
| 5 | +var d3 = require('d3'); |
4 | 6 | var createGraphDiv = require('../assets/create_graph_div');
|
5 | 7 | var destroyGraphDiv = require('../assets/destroy_graph_div');
|
6 | 8 | var mouseEvent = require('../assets/mouse_event');
|
@@ -290,4 +292,60 @@ describe('Layout images', function() {
|
290 | 292 | });
|
291 | 293 | });
|
292 | 294 |
|
| 295 | + describe('when adding/removing images', function() { |
| 296 | + |
| 297 | + afterEach(destroyGraphDiv); |
| 298 | + |
| 299 | + it('should properly add and removing image', function(done) { |
| 300 | + var gd = createGraphDiv(), |
| 301 | + data = [{ x: [1, 2, 3], y: [1, 2, 3] }], |
| 302 | + layout = { width: 500, height: 400 }; |
| 303 | + |
| 304 | + function makeImage(source, x, y) { |
| 305 | + return { |
| 306 | + source: source, |
| 307 | + x: x, |
| 308 | + y: y, |
| 309 | + sizex: 1, |
| 310 | + sizey: 1 |
| 311 | + }; |
| 312 | + } |
| 313 | + |
| 314 | + function assertImages(cnt) { |
| 315 | + expect(d3.selectAll('image').size()).toEqual(cnt); |
| 316 | + } |
| 317 | + |
| 318 | + Plotly.plot(gd, data, layout).then(function() { |
| 319 | + assertImages(0); |
| 320 | + |
| 321 | + return Plotly.relayout(gd, 'images[0]', makeImage(jsLogo, 0.1, 0.1)); |
| 322 | + }).then(function() { |
| 323 | + assertImages(1); |
| 324 | + |
| 325 | + return Plotly.relayout(gd, 'images[1]', makeImage(pythonLogo, 0.9, 0.9)); |
| 326 | + }).then(function() { |
| 327 | + assertImages(2); |
| 328 | + |
| 329 | + return Plotly.relayout(gd, 'images[2]', makeImage(pythonLogo, 0.2, 0.5)); |
| 330 | + }).then(function() { |
| 331 | + assertImages(3); |
| 332 | + |
| 333 | + return Plotly.relayout(gd, 'images[2]', 'remove'); |
| 334 | + }).then(function() { |
| 335 | + assertImages(2); |
| 336 | + |
| 337 | + return Plotly.relayout(gd, 'images[1]', 'remove'); |
| 338 | + }).then(function() { |
| 339 | + assertImages(1); |
| 340 | + |
| 341 | + return Plotly.relayout(gd, 'images[0]', 'remove'); |
| 342 | + }).then(function() { |
| 343 | + assertImages(0); |
| 344 | + |
| 345 | + done(); |
| 346 | + }); |
| 347 | + }); |
| 348 | + |
| 349 | + }); |
| 350 | + |
293 | 351 | });
|
0 commit comments