Skip to content

Commit 9af534a

Browse files
committed
add drawing bb test
- to simulate report #1678
1 parent 83b3d64 commit 9af534a

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

test/jasmine/tests/drawing_test.js

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
var Drawing = require('@src/components/drawing');
2-
31
var d3 = require('d3');
4-
52
var Plotly = require('@lib/index');
6-
3+
var Drawing = require('@src/components/drawing');
74
var createGraphDiv = require('../assets/create_graph_div');
85
var destroyGraphDiv = require('../assets/destroy_graph_div');
96
var fail = require('../assets/fail_test');
@@ -348,6 +345,54 @@ describe('Drawing', function() {
348345
expect(g.attr('transform')).toEqual('translate(8,9) scale(4,5) translate(-8,-9) translate(1, 2)');
349346
});
350347
});
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+
});
351396
});
352397

353398
describe('gradients', function() {

0 commit comments

Comments
 (0)