@@ -294,43 +294,140 @@ describe('the range slider', function() {
294294
295295 it ( 'should not add the slider to the DOM by default' , function ( done ) {
296296 Plotly . plot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 2 , 3 , 4 ] } ] , { } )
297- . then ( function ( ) {
298- var rangeSlider = getRangeSlider ( ) ;
299- expect ( rangeSlider ) . not . toBeDefined ( ) ;
300- } )
301- . then ( done ) ;
297+ . then ( function ( ) {
298+ var rangeSlider = getRangeSlider ( ) ;
299+ expect ( rangeSlider ) . not . toBeDefined ( ) ;
300+ } )
301+ . then ( done ) ;
302302 } ) ;
303303
304304 it ( 'should add the slider if rangeslider is set to anything' , function ( done ) {
305305 Plotly . plot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 2 , 3 , 4 ] } ] , { } )
306- . then ( function ( ) { Plotly . relayout ( gd , 'xaxis.rangeslider' , 'exists' ) ; } )
307- . then ( function ( ) {
308- var rangeSlider = getRangeSlider ( ) ;
309- expect ( rangeSlider ) . toBeDefined ( ) ;
310- } )
311- . then ( done ) ;
306+ . then ( function ( ) {
307+ return Plotly . relayout ( gd , 'xaxis.rangeslider' , 'exists' ) ;
308+ } )
309+ . then ( function ( ) {
310+ var rangeSlider = getRangeSlider ( ) ;
311+ expect ( rangeSlider ) . toBeDefined ( ) ;
312+ } )
313+ . then ( done ) ;
312314 } ) ;
313315
314316 it ( 'should add the slider if visible changed to `true`' , function ( done ) {
315317 Plotly . plot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 2 , 3 , 4 ] } ] , { } )
316- . then ( function ( ) { Plotly . relayout ( gd , 'xaxis.rangeslider.visible' , true ) ; } )
317- . then ( function ( ) {
318- var rangeSlider = getRangeSlider ( ) ;
319- expect ( rangeSlider ) . toBeDefined ( ) ;
320- expect ( countRangeSliderClipPaths ( ) ) . toEqual ( 1 ) ;
321- } )
322- . then ( done ) ;
318+ . then ( function ( ) {
319+ return Plotly . relayout ( gd , 'xaxis.rangeslider.visible' , true ) ;
320+ } )
321+ . then ( function ( ) {
322+ var rangeSlider = getRangeSlider ( ) ;
323+ expect ( rangeSlider ) . toBeDefined ( ) ;
324+ expect ( countRangeSliderClipPaths ( ) ) . toEqual ( 1 ) ;
325+ } )
326+ . then ( done ) ;
323327 } ) ;
324328
325329 it ( 'should remove the slider if changed to `false` or `undefined`' , function ( done ) {
326- Plotly . plot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 2 , 3 , 4 ] } ] , { xaxis : { rangeslider : { visible : true } } } )
327- . then ( function ( ) { Plotly . relayout ( gd , 'xaxis.rangeslider.visible' , false ) ; } )
328- . then ( function ( ) {
329- var rangeSlider = getRangeSlider ( ) ;
330- expect ( rangeSlider ) . not . toBeDefined ( ) ;
331- expect ( countRangeSliderClipPaths ( ) ) . toEqual ( 0 ) ;
332- } )
333- . then ( done ) ;
330+ Plotly . plot ( gd , [ {
331+ x : [ 1 , 2 , 3 ] ,
332+ y : [ 2 , 3 , 4 ]
333+ } ] , {
334+ xaxis : {
335+ rangeslider : { visible : true }
336+ }
337+ } )
338+ . then ( function ( ) {
339+ return Plotly . relayout ( gd , 'xaxis.rangeslider.visible' , false ) ;
340+ } )
341+ . then ( function ( ) {
342+ var rangeSlider = getRangeSlider ( ) ;
343+ expect ( rangeSlider ) . not . toBeDefined ( ) ;
344+ expect ( countRangeSliderClipPaths ( ) ) . toEqual ( 0 ) ;
345+ } )
346+ . then ( done ) ;
347+ } ) ;
348+
349+ it ( 'should clear traces in range plot when needed' , function ( done ) {
350+
351+ function count ( query ) {
352+ return d3 . select ( getRangeSlider ( ) ) . selectAll ( query ) . size ( ) ;
353+ }
354+
355+ Plotly . plot ( gd , [ {
356+ type : 'scatter' ,
357+ x : [ 1 , 2 , 3 ] ,
358+ y : [ 2 , 1 , 2 ]
359+ } , {
360+ type : 'bar' ,
361+ x : [ 1 , 2 , 3 ] ,
362+ y : [ 2 , 5 , 2 ]
363+ } ] , {
364+ xaxis : {
365+ rangeslider : { visible : true }
366+ }
367+ } )
368+ . then ( function ( ) {
369+ expect ( count ( 'g.scatterlayer > g.trace' ) ) . toEqual ( 1 ) ;
370+ expect ( count ( 'g.barlayer > g.trace' ) ) . toEqual ( 1 ) ;
371+
372+ return Plotly . restyle ( gd , 'visible' , false ) ;
373+ } )
374+ . then ( function ( ) {
375+ expect ( count ( 'g.scatterlayer > g.trace' ) ) . toEqual ( 0 ) ;
376+ expect ( count ( 'g.barlayer > g.trace' ) ) . toEqual ( 0 ) ;
377+
378+ return Plotly . restyle ( gd , 'visible' , true ) ;
379+ } )
380+ . then ( function ( ) {
381+ expect ( count ( 'g.scatterlayer > g.trace' ) ) . toEqual ( 1 ) ;
382+ expect ( count ( 'g.barlayer > g.trace' ) ) . toEqual ( 1 ) ;
383+
384+ return Plotly . deleteTraces ( gd , [ 0 , 1 ] ) ;
385+ } )
386+ . then ( function ( ) {
387+ expect ( count ( 'g.scatterlayer > g.trace' ) ) . toEqual ( 0 ) ;
388+ expect ( count ( 'g.barlayer > g.trace' ) ) . toEqual ( 0 ) ;
389+
390+ return Plotly . addTraces ( gd , [ {
391+ type : 'heatmap' ,
392+ z : [ [ 1 , 2 , 3 ] , [ 2 , 1 , 3 ] ]
393+ } ] ) ;
394+ } )
395+ . then ( function ( ) {
396+ expect ( count ( 'g.imagelayer > g.hm' ) ) . toEqual ( 1 ) ;
397+
398+ return Plotly . restyle ( gd , 'visible' , false ) ;
399+ } )
400+ . then ( function ( ) {
401+ expect ( count ( 'g.imagelayer > g.hm' ) ) . toEqual ( 0 ) ;
402+
403+ return Plotly . restyle ( gd , {
404+ visible : true ,
405+ type : 'contour'
406+ } ) ;
407+ } )
408+ . then ( function ( ) {
409+ expect ( count ( 'g.maplayer > g.contour' ) ) . toEqual ( 1 ) ;
410+
411+ return Plotly . restyle ( gd , 'type' , 'heatmap' ) ;
412+ } )
413+ . then ( function ( ) {
414+ expect ( count ( 'g.imagelayer > g.hm' ) ) . toEqual ( 1 ) ;
415+ expect ( count ( 'g.maplayer > g.contour' ) ) . toEqual ( 0 ) ;
416+
417+ return Plotly . restyle ( gd , 'type' , 'contour' ) ;
418+ } )
419+ . then ( function ( ) {
420+ expect ( count ( 'g.imagelayer > g.hm' ) ) . toEqual ( 0 ) ;
421+ expect ( count ( 'g.maplayer > g.contour' ) ) . toEqual ( 1 ) ;
422+
423+ return Plotly . deleteTraces ( gd , [ 0 ] ) ;
424+ } )
425+ . then ( function ( ) {
426+ expect ( count ( 'g.imagelayer > g.hm' ) ) . toEqual ( 0 ) ;
427+ expect ( count ( 'g.maplayer > g.contour' ) ) . toEqual ( 0 ) ;
428+ } )
429+ . then ( done ) ;
430+
334431 } ) ;
335432 } ) ;
336433
0 commit comments