@@ -512,6 +512,7 @@ drawing.makeTester = function(gd) {
512512// always returns a copy of the bbox, so the caller can modify it safely
513513var savedBBoxes = [ ] ,
514514 maxSavedBBoxes = 10000 ;
515+
515516drawing . bBox = function ( node ) {
516517 // cache elements we've already measured so we don't have to
517518 // remeasure the same thing many times
@@ -520,32 +521,36 @@ drawing.bBox = function(node) {
520521 return Lib . extendFlat ( { } , savedBBoxes [ saveNum . value ] ) ;
521522 }
522523
523- var test3 = d3 . select ( '#js-plotly-tester' ) ,
524- tester = test3 . node ( ) ;
524+ if ( ! drawing . test3 ) {
525+ drawing . test3 = d3 . select ( '#js-plotly-tester' ) ;
526+ drawing . tester = drawing . test3 . node ( ) ;
527+ }
525528
526529 // copy the node to test into the tester
527530 var testNode = node . cloneNode ( true ) ;
528- tester . appendChild ( testNode ) ;
531+ drawing . tester . appendChild ( testNode ) ;
529532 // standardize its position... do we really want to do this?
530533 d3 . select ( testNode ) . attr ( {
531534 x : 0 ,
532535 y : 0 ,
533536 transform : ''
534537 } ) ;
535538
536- var testRect = testNode . getBoundingClientRect ( ) ,
537- refRect = test3 . select ( '.js-reference-point' )
539+ var testRect = testNode . getBoundingClientRect ( ) ;
540+ if ( ! drawing . refRect ) {
541+ drawing . refRect = drawing . test3 . select ( '.js-reference-point' )
538542 . node ( ) . getBoundingClientRect ( ) ;
543+ }
539544
540- tester . removeChild ( testNode ) ;
545+ drawing . tester . removeChild ( testNode ) ;
541546
542547 var bb = {
543548 height : testRect . height ,
544549 width : testRect . width ,
545- left : testRect . left - refRect . left ,
546- top : testRect . top - refRect . top ,
547- right : testRect . right - refRect . left ,
548- bottom : testRect . bottom - refRect . top
550+ left : testRect . left - drawing . refRect . left ,
551+ top : testRect . top - drawing . refRect . top ,
552+ right : testRect . right - drawing . refRect . left ,
553+ bottom : testRect . bottom - drawing . refRect . top
549554 } ;
550555
551556 // make sure we don't have too many saved boxes,
0 commit comments