|
1 |
| -var Drawing = require('@src/components/drawing'); |
2 |
| - |
3 | 1 | var d3 = require('d3');
|
4 |
| - |
5 | 2 | var Plotly = require('@lib/index');
|
6 |
| - |
| 3 | +var Drawing = require('@src/components/drawing'); |
7 | 4 | var createGraphDiv = require('../assets/create_graph_div');
|
8 | 5 | var destroyGraphDiv = require('../assets/destroy_graph_div');
|
9 | 6 | var fail = require('../assets/fail_test');
|
@@ -348,6 +345,54 @@ describe('Drawing', function() {
|
348 | 345 | expect(g.attr('transform')).toEqual('translate(8,9) scale(4,5) translate(-8,-9) translate(1, 2)');
|
349 | 346 | });
|
350 | 347 | });
|
| 348 | + |
| 349 | + describe('bBox', function() { |
| 350 | + afterEach(destroyGraphDiv); |
| 351 | + |
| 352 | + it('should update bounding box dimension on window scroll', function(done) { |
| 353 | + var gd = createGraphDiv(); |
| 354 | + |
| 355 | + // allow page to scroll |
| 356 | + gd.style.position = 'static'; |
| 357 | + |
| 358 | + Plotly.plot(gd, [{ |
| 359 | + y: [1, 2, 1] |
| 360 | + }], { |
| 361 | + annotations: [{ |
| 362 | + text: 'hello' |
| 363 | + }], |
| 364 | + height: window.innerHeight * 2, |
| 365 | + width: 500 |
| 366 | + }) |
| 367 | + .then(function() { |
| 368 | + var node = d3.select('text.annotation').node(); |
| 369 | + expect(Drawing.bBox(node)).toEqual({ |
| 370 | + height: 14, |
| 371 | + width: 27.671875, |
| 372 | + left: -13.671875, |
| 373 | + top: -11, |
| 374 | + right: 14, |
| 375 | + bottom: 3 |
| 376 | + }); |
| 377 | + |
| 378 | + window.scroll(0, 200); |
| 379 | + return Plotly.relayout(gd, 'annotations[0].text', 'HELLO'); |
| 380 | + }) |
| 381 | + .then(function() { |
| 382 | + var node = d3.select('text.annotation').node(); |
| 383 | + expect(Drawing.bBox(node)).toEqual({ |
| 384 | + height: 14, |
| 385 | + width: 41.015625, |
| 386 | + left: -20.671875, |
| 387 | + top: -11, |
| 388 | + right: 20.34375, |
| 389 | + bottom: 3 |
| 390 | + }); |
| 391 | + }) |
| 392 | + .catch(fail) |
| 393 | + .then(done); |
| 394 | + }); |
| 395 | + }); |
351 | 396 | });
|
352 | 397 |
|
353 | 398 | describe('gradients', function() {
|
|
0 commit comments