@@ -504,6 +504,7 @@ drawing.makeTester = function(gd) {
504504// always returns a copy of the bbox, so the caller can modify it safely
505505var savedBBoxes = [ ] ,
506506 maxSavedBBoxes = 10000 ;
507+
507508drawing . bBox = function ( node ) {
508509 // cache elements we've already measured so we don't have to
509510 // remeasure the same thing many times
@@ -512,32 +513,36 @@ drawing.bBox = function(node) {
512513 return Lib . extendFlat ( { } , savedBBoxes [ saveNum . value ] ) ;
513514 }
514515
515- var test3 = d3 . select ( '#js-plotly-tester' ) ,
516- tester = test3 . node ( ) ;
516+ if ( ! drawing . test3 ) {
517+ drawing . test3 = d3 . select ( '#js-plotly-tester' ) ;
518+ drawing . tester = drawing . test3 . node ( ) ;
519+ }
517520
518521 // copy the node to test into the tester
519522 var testNode = node . cloneNode ( true ) ;
520- tester . appendChild ( testNode ) ;
523+ drawing . tester . appendChild ( testNode ) ;
521524 // standardize its position... do we really want to do this?
522525 d3 . select ( testNode ) . attr ( {
523526 x : 0 ,
524527 y : 0 ,
525528 transform : ''
526529 } ) ;
527530
528- var testRect = testNode . getBoundingClientRect ( ) ,
529- refRect = test3 . select ( '.js-reference-point' )
531+ var testRect = testNode . getBoundingClientRect ( ) ;
532+ if ( ! drawing . refRect ) {
533+ drawing . refRect = drawing . test3 . select ( '.js-reference-point' )
530534 . node ( ) . getBoundingClientRect ( ) ;
535+ }
531536
532- tester . removeChild ( testNode ) ;
537+ drawing . tester . removeChild ( testNode ) ;
533538
534539 var bb = {
535540 height : testRect . height ,
536541 width : testRect . width ,
537- left : testRect . left - refRect . left ,
538- top : testRect . top - refRect . top ,
539- right : testRect . right - refRect . left ,
540- bottom : testRect . bottom - refRect . top
542+ left : testRect . left - drawing . refRect . left ,
543+ top : testRect . top - drawing . refRect . top ,
544+ right : testRect . right - drawing . refRect . left ,
545+ bottom : testRect . bottom - drawing . refRect . top
541546 } ;
542547
543548 // make sure we don't have too many saved boxes,
0 commit comments