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