@@ -552,13 +552,16 @@ describe('annotations log/linear axis changes', function() {
552
552
describe ( 'annotations autorange' , function ( ) {
553
553
'use strict' ;
554
554
555
- var mock = Lib . extendDeep ( { } , require ( '@mocks/annotations-autorange.json' ) ) ;
555
+ var mock ;
556
556
var gd ;
557
557
558
558
beforeAll ( function ( ) {
559
559
jasmine . addMatchers ( customMatchers ) ;
560
+ } ) ;
560
561
562
+ beforeEach ( function ( ) {
561
563
gd = createGraphDiv ( ) ;
564
+ mock = Lib . extendDeep ( { } , require ( '@mocks/annotations-autorange.json' ) ) ;
562
565
} ) ;
563
566
564
567
afterEach ( destroyGraphDiv ) ;
@@ -588,13 +591,30 @@ describe('annotations autorange', function() {
588
591
expect ( fullLayout . yaxis3 . range ) . toBeCloseToArray ( y3 , PREC , 'yaxis3' ) ;
589
592
}
590
593
594
+ function assertVisible ( indices ) {
595
+ // right now we keep the annotation groups around when they're invisible,
596
+ // they just don't have any graphical elements in them. Might be better
597
+ // to get rid of the groups even, but this test will produce the right
598
+ // results either way, showing that the annotation is or isn't drawn.
599
+ for ( var i = 0 ; i < gd . layout . annotations . length ; i ++ ) {
600
+ var selectorBase = '.annotation[data-index="' + i + '"]' ;
601
+ var annotationGraphicalItems = d3 . selectAll (
602
+ selectorBase + ' text,' +
603
+ selectorBase + ' rect,' +
604
+ selectorBase + ' path' ) ;
605
+ expect ( annotationGraphicalItems . size ( ) > 0 )
606
+ . toBe ( indices . indexOf ( i ) !== - 1 , selectorBase ) ;
607
+ }
608
+ }
609
+
591
610
it ( 'should adapt to relayout calls' , function ( done ) {
592
611
Plotly . plot ( gd , mock ) . then ( function ( ) {
593
612
assertRanges (
594
613
[ 0.91 , 2.09 ] , [ 0.91 , 2.09 ] ,
595
614
[ '2000-11-13' , '2001-04-21' ] , [ - 0.069 , 3.917 ] ,
596
615
[ 0.88 , 2.05 ] , [ 0.92 , 2.08 ]
597
616
) ;
617
+ assertVisible ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] ) ;
598
618
599
619
return Plotly . relayout ( gd , {
600
620
'annotations[0].visible' : false ,
@@ -608,6 +628,7 @@ describe('annotations autorange', function() {
608
628
[ '2001-01-18' , '2001-03-27' ] , [ - 0.069 , 3.917 ] ,
609
629
[ 1.44 , 2.1 ] , [ 0.92 , 2.08 ]
610
630
) ;
631
+ assertVisible ( [ 1 , 2 , 3 , 5 , 6 , 7 , 9 , 10 , 11 , 12 , 13 ] ) ;
611
632
612
633
return Plotly . relayout ( gd , {
613
634
'annotations[2].visible' : false ,
@@ -621,6 +642,7 @@ describe('annotations autorange', function() {
621
642
[ '2001-01-31 23:59:59.999' , '2001-02-01 00:00:00.001' ] , [ - 0.069 , 3.917 ] ,
622
643
[ 0.5 , 2.5 ] , [ 0.92 , 2.08 ]
623
644
) ;
645
+ assertVisible ( [ 1 , 3 , 6 , 7 , 10 , 11 , 12 , 13 ] ) ;
624
646
625
647
return Plotly . relayout ( gd , {
626
648
'annotations[0].visible' : true ,
@@ -637,6 +659,27 @@ describe('annotations autorange', function() {
637
659
[ '2000-11-13' , '2001-04-21' ] , [ - 0.069 , 3.917 ] ,
638
660
[ 0.88 , 2.05 ] , [ 0.92 , 2.08 ]
639
661
) ;
662
+ assertVisible ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] ) ;
663
+
664
+ // check that off-plot annotations are hidden - zoom in to
665
+ // only one of the four on each subplot
666
+ return Plotly . relayout ( gd , {
667
+ 'xaxis.range' : [ 1.4 , 1.6 ] ,
668
+ 'yaxis.range' : [ 0.9 , 1.1 ] ,
669
+ 'xaxis2.range' : [ '2001-01-15' , '2001-02-15' ] ,
670
+ 'yaxis2.range' : [ 0.9 , 1.1 ] ,
671
+ 'xaxis3.range' : [ 1.9 , 2.1 ] ,
672
+ 'yaxis3.range' : [ 1.4 , 1.6 ]
673
+ } ) ;
674
+ } )
675
+ . then ( function ( ) {
676
+ assertRanges ( [ 1.4 , 1.6 ] , [ 0.9 , 1.1 ] ,
677
+ [ '2001-01-15' , '2001-02-15' ] , [ 0.9 , 1.1 ] ,
678
+ [ 1.9 , 2.1 ] , [ 1.4 , 1.6 ]
679
+ ) ;
680
+ // only one annotation on each subplot, plus the two paper-referenced
681
+ // are visible after zooming in
682
+ assertVisible ( [ 3 , 7 , 9 , 12 , 13 ] ) ;
640
683
} )
641
684
. catch ( failTest )
642
685
. then ( done ) ;
0 commit comments