@@ -507,6 +507,8 @@ describe('Test plot api', function() {
507507 'doCamera'
508508 ] ;
509509
510+ var gd ;
511+
510512 beforeAll ( function ( ) {
511513 mockedMethods . forEach ( function ( m ) {
512514 spyOn ( subroutines , m ) ;
@@ -523,8 +525,20 @@ describe('Test plot api', function() {
523525 return gd ;
524526 }
525527
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+
526540 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 ( {
528542 data : [ {
529543 type : 'scattergl' ,
530544 x : [ 1 , 2 , 3 ] ,
@@ -535,35 +549,69 @@ describe('Test plot api', function() {
535549 }
536550 } ) ;
537551
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-
550552 Plotly . relayout ( gd , 'dragmode' , 'pan' ) ;
551- expectModeBarOnly ( ) ;
553+ expectModeBarOnly ( 'pan' ) ;
552554
553555 Plotly . relayout ( mock ( gd ) , 'dragmode' , 'lasso' ) ;
554- expectReplot ( ) ;
556+ expectReplot ( 'lasso 1' ) ;
555557
556558 Plotly . relayout ( mock ( gd ) , 'dragmode' , 'select' ) ;
557- expectModeBarOnly ( ) ;
559+ expectModeBarOnly ( 'select 1' ) ;
558560
559561 Plotly . relayout ( mock ( gd ) , 'dragmode' , 'lasso' ) ;
560- expectModeBarOnly ( ) ;
562+ expectModeBarOnly ( 'lasso 2' ) ;
561563
562564 Plotly . relayout ( mock ( gd ) , 'dragmode' , 'zoom' ) ;
563- expectModeBarOnly ( ) ;
565+ expectModeBarOnly ( 'zoom' ) ;
564566
565567 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+ }
567615 } ) ;
568616 } ) ;
569617
0 commit comments