@@ -512,6 +512,7 @@ drawing.makeTester = function(gd) {
512
512
// always returns a copy of the bbox, so the caller can modify it safely
513
513
var savedBBoxes = [ ] ,
514
514
maxSavedBBoxes = 10000 ;
515
+
515
516
drawing . bBox = function ( node ) {
516
517
// cache elements we've already measured so we don't have to
517
518
// remeasure the same thing many times
@@ -520,32 +521,36 @@ drawing.bBox = function(node) {
520
521
return Lib . extendFlat ( { } , savedBBoxes [ saveNum . value ] ) ;
521
522
}
522
523
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
+ }
525
528
526
529
// copy the node to test into the tester
527
530
var testNode = node . cloneNode ( true ) ;
528
- tester . appendChild ( testNode ) ;
531
+ drawing . tester . appendChild ( testNode ) ;
529
532
// standardize its position... do we really want to do this?
530
533
d3 . select ( testNode ) . attr ( {
531
534
x : 0 ,
532
535
y : 0 ,
533
536
transform : ''
534
537
} ) ;
535
538
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' )
538
542
. node ( ) . getBoundingClientRect ( ) ;
543
+ }
539
544
540
- tester . removeChild ( testNode ) ;
545
+ drawing . tester . removeChild ( testNode ) ;
541
546
542
547
var bb = {
543
548
height : testRect . height ,
544
549
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
549
554
} ;
550
555
551
556
// make sure we don't have too many saved boxes,
0 commit comments