@@ -345,6 +345,90 @@ describe('the range slider', function() {
345345 } )
346346 . then ( done ) ;
347347 } ) ;
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+
431+ } ) ;
348432 } ) ;
349433
350434 describe ( 'handleDefaults function' , function ( ) {
0 commit comments