@@ -254,6 +254,76 @@ describe('Test plot api', function() {
254254 } ) ;
255255 } ) ;
256256
257+ describe ( 'Plotly.relayout subroutines switchboard' , function ( ) {
258+ var mockedMethods = [
259+ 'layoutReplot' ,
260+ 'doLegend' ,
261+ 'layoutStyles' ,
262+ 'doTicksRelayout' ,
263+ 'doModeBar' ,
264+ 'doCamera'
265+ ] ;
266+
267+ beforeAll ( function ( ) {
268+ mockedMethods . forEach ( function ( m ) {
269+ spyOn ( subroutines , m ) ;
270+ } ) ;
271+ } ) ;
272+
273+ function mock ( gd ) {
274+ mockedMethods . forEach ( function ( m ) {
275+ subroutines [ m ] . calls . reset ( ) ;
276+ } ) ;
277+
278+ Plots . supplyDefaults ( gd ) ;
279+ Plots . doCalcdata ( gd ) ;
280+ return gd ;
281+ }
282+
283+ it ( 'should trigger recalc when switching into select or lasso dragmode' , function ( ) {
284+ var gd = mock ( {
285+ data : [ {
286+ type : 'scattergl' ,
287+ x : [ 1 , 2 , 3 ] ,
288+ y : [ 1 , 2 , 3 ]
289+ } ] ,
290+ layout : {
291+ dragmode : 'zoom'
292+ }
293+ } ) ;
294+
295+ function expectModeBarOnly ( ) {
296+ expect ( gd . calcdata ) . toBeDefined ( ) ;
297+ expect ( subroutines . doModeBar ) . toHaveBeenCalled ( ) ;
298+ expect ( subroutines . layoutReplot ) . not . toHaveBeenCalled ( ) ;
299+ }
300+
301+ function expectRecalc ( ) {
302+ expect ( gd . calcdata ) . toBeUndefined ( ) ;
303+ expect ( subroutines . doModeBar ) . not . toHaveBeenCalled ( ) ;
304+ expect ( subroutines . layoutReplot ) . toHaveBeenCalled ( ) ;
305+ }
306+
307+ Plotly . relayout ( gd , 'dragmode' , 'pan' ) ;
308+ expectModeBarOnly ( ) ;
309+
310+ Plotly . relayout ( mock ( gd ) , 'dragmode' , 'lasso' ) ;
311+ expectRecalc ( ) ;
312+
313+ Plotly . relayout ( mock ( gd ) , 'dragmode' , 'select' ) ;
314+ expectModeBarOnly ( ) ;
315+
316+ Plotly . relayout ( mock ( gd ) , 'dragmode' , 'lasso' ) ;
317+ expectModeBarOnly ( ) ;
318+
319+ Plotly . relayout ( mock ( gd ) , 'dragmode' , 'zoom' ) ;
320+ expectModeBarOnly ( ) ;
321+
322+ Plotly . relayout ( mock ( gd ) , 'dragmode' , 'select' ) ;
323+ expectRecalc ( ) ;
324+ } ) ;
325+ } ) ;
326+
257327 describe ( 'Plotly.restyle subroutines switchboard' , function ( ) {
258328 beforeEach ( function ( ) {
259329 spyOn ( PlotlyInternal , 'plot' ) ;
0 commit comments