@@ -507,6 +507,8 @@ describe('Test plot api', function() {
507
507
'doCamera'
508
508
] ;
509
509
510
+ var gd ;
511
+
510
512
beforeAll ( function ( ) {
511
513
mockedMethods . forEach ( function ( m ) {
512
514
spyOn ( subroutines , m ) ;
@@ -523,8 +525,20 @@ describe('Test plot api', function() {
523
525
return gd ;
524
526
}
525
527
528
+ function expectModeBarOnly ( msg ) {
529
+ expect ( gd . calcdata ) . toBeDefined ( msg ) ;
530
+ expect ( subroutines . doModeBar . calls . count ( ) ) . toBeGreaterThan ( 0 , msg ) ;
531
+ expect ( subroutines . layoutReplot . calls . count ( ) ) . toBe ( 0 , msg ) ;
532
+ }
533
+
534
+ function expectReplot ( msg ) {
535
+ expect ( gd . calcdata ) . toBeDefined ( msg ) ;
536
+ expect ( subroutines . doModeBar . calls . count ( ) ) . toBe ( 0 , msg ) ;
537
+ expect ( subroutines . layoutReplot . calls . count ( ) ) . toBeGreaterThan ( 0 , msg ) ;
538
+ }
539
+
526
540
it ( 'should trigger replot (but not recalc) when switching into select or lasso dragmode for scattergl traces' , function ( ) {
527
- var gd = mock ( {
541
+ gd = mock ( {
528
542
data : [ {
529
543
type : 'scattergl' ,
530
544
x : [ 1 , 2 , 3 ] ,
@@ -535,35 +549,69 @@ describe('Test plot api', function() {
535
549
}
536
550
} ) ;
537
551
538
- function expectModeBarOnly ( ) {
539
- expect ( gd . calcdata ) . toBeDefined ( ) ;
540
- expect ( subroutines . doModeBar ) . toHaveBeenCalled ( ) ;
541
- expect ( subroutines . layoutReplot ) . not . toHaveBeenCalled ( ) ;
542
- }
543
-
544
- function expectReplot ( ) {
545
- expect ( gd . calcdata ) . toBeDefined ( ) ;
546
- expect ( subroutines . doModeBar ) . not . toHaveBeenCalled ( ) ;
547
- expect ( subroutines . layoutReplot ) . toHaveBeenCalled ( ) ;
548
- }
549
-
550
552
Plotly . relayout ( gd , 'dragmode' , 'pan' ) ;
551
- expectModeBarOnly ( ) ;
553
+ expectModeBarOnly ( 'pan' ) ;
552
554
553
555
Plotly . relayout ( mock ( gd ) , 'dragmode' , 'lasso' ) ;
554
- expectReplot ( ) ;
556
+ expectReplot ( 'lasso 1' ) ;
555
557
556
558
Plotly . relayout ( mock ( gd ) , 'dragmode' , 'select' ) ;
557
- expectModeBarOnly ( ) ;
559
+ expectModeBarOnly ( 'select 1' ) ;
558
560
559
561
Plotly . relayout ( mock ( gd ) , 'dragmode' , 'lasso' ) ;
560
- expectModeBarOnly ( ) ;
562
+ expectModeBarOnly ( 'lasso 2' ) ;
561
563
562
564
Plotly . relayout ( mock ( gd ) , 'dragmode' , 'zoom' ) ;
563
- expectModeBarOnly ( ) ;
565
+ expectModeBarOnly ( 'zoom' ) ;
564
566
565
567
Plotly . relayout ( mock ( gd ) , 'dragmode' , 'select' ) ;
566
- expectReplot ( ) ;
568
+ expectReplot ( 'select 2' ) ;
569
+ } ) ;
570
+
571
+ it ( 'should trigger replot (but not recalc) when changing attributes that affect axis length/range' , function ( ) {
572
+ // but axis.autorange itself is NOT here, because setting it from false to true requires an
573
+ // autorange so that we calculate _min and _max, which we ignore if autorange is off.
574
+ var axLayoutEdits = {
575
+ 'xaxis.rangemode' : 'tozero' ,
576
+ 'xaxis.domain' : [ 0.2 , 0.8 ] ,
577
+ 'xaxis.domain[1]' : 0.7 ,
578
+ 'yaxis.domain' : [ 0.1 , 0.9 ] ,
579
+ 'yaxis.domain[0]' : 0.3 ,
580
+ 'yaxis.overlaying' : 'y2' ,
581
+ 'margin.l' : 50 ,
582
+ 'margin.r' : 20 ,
583
+ 'margin.t' : 1 ,
584
+ 'margin.b' : 5 ,
585
+ 'margin.autoexpand' : false ,
586
+ height : 567 ,
587
+ width : 432 ,
588
+ 'grid.rows' : 2 ,
589
+ 'grid.columns' : 3 ,
590
+ 'grid.xgap' : 0.5 ,
591
+ 'grid.ygap' : 0 ,
592
+ 'grid.roworder' : 'bottom to top' ,
593
+ 'grid.pattern' : 'independent' ,
594
+ 'grid.yaxes' : [ 'y2' , 'y' ] ,
595
+ 'grid.xaxes[0]' : 'x2' ,
596
+ 'grid.domain' : { x : [ 0 , 0.4 ] , y : [ 0.6 , 1 ] } ,
597
+ 'grid.domain.x' : [ 0.01 , 0.99 ] ,
598
+ 'grid.domain.y[0]' : 0.33 ,
599
+ 'grid.subplots' : [ [ '' , 'xy' ] , [ 'x2y2' , '' ] ] ,
600
+ 'grid.subplots[1][1]' : 'xy'
601
+ } ;
602
+
603
+ for ( var attr in axLayoutEdits ) {
604
+ gd = mock ( {
605
+ data : [ { y : [ 1 , 2 ] } , { y : [ 4 , 3 ] , xaxis : 'x2' , yaxis : 'y2' } ] ,
606
+ layout : {
607
+ xaxis2 : { domain : [ 0.6 , 0.9 ] } ,
608
+ yaxis2 : { domain : [ 0.6 , 0.9 ] }
609
+ }
610
+ } ) ;
611
+
612
+ Plotly . relayout ( gd , attr , axLayoutEdits [ attr ] ) ;
613
+ expectReplot ( attr ) ;
614
+ }
567
615
} ) ;
568
616
} ) ;
569
617
0 commit comments