@@ -879,45 +879,99 @@ describe('end-to-end scatter tests', function() {
879879 . then ( done ) ;
880880 } ) ;
881881
882- it ( 'should update axis range accordingly on marker.size edits' , function ( done ) {
883- function _assert ( msg , xrng , yrng ) {
884- var fullLayout = gd . _fullLayout ;
885- expect ( fullLayout . xaxis . range ) . toBeCloseToArray ( xrng , 2 , msg + ' xrng' ) ;
886- expect ( fullLayout . yaxis . range ) . toBeCloseToArray ( yrng , 2 , msg + ' yrng' ) ;
887- }
882+ function assertAxisRanges ( msg , xrng , yrng ) {
883+ var fullLayout = gd . _fullLayout ;
884+ expect ( fullLayout . xaxis . range ) . toBeCloseToArray ( xrng , 2 , msg + ' xrng' ) ;
885+ expect ( fullLayout . yaxis . range ) . toBeCloseToArray ( yrng , 2 , msg + ' yrng' ) ;
886+ }
888887
888+ var schema = Plotly . PlotSchema . get ( ) ;
889+
890+ it ( 'should update axis range accordingly on marker.size edits' , function ( done ) {
889891 // edit types are important to this test
890- var schema = Plotly . PlotSchema . get ( ) ;
891892 expect ( schema . traces . scatter . attributes . marker . size . editType )
892893 . toBe ( 'calc' , 'marker.size editType' ) ;
893894 expect ( schema . layout . layoutAttributes . xaxis . autorange . editType )
894895 . toBe ( 'axrange' , 'ax autorange editType' ) ;
895896
896897 Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] )
897898 . then ( function ( ) {
898- _assert ( 'auto rng / base marker.size' , [ - 0.13 , 2.13 ] , [ 0.93 , 2.07 ] ) ;
899+ assertAxisRanges ( 'auto rng / base marker.size' , [ - 0.13 , 2.13 ] , [ 0.93 , 2.07 ] ) ;
899900 return Plotly . relayout ( gd , {
900901 'xaxis.range' : [ 0 , 2 ] ,
901902 'yaxis.range' : [ 0 , 2 ]
902903 } ) ;
903904 } )
904905 . then ( function ( ) {
905- _assert ( 'set rng / base marker.size' , [ 0 , 2 ] , [ 0 , 2 ] ) ;
906+ assertAxisRanges ( 'set rng / base marker.size' , [ 0 , 2 ] , [ 0 , 2 ] ) ;
906907 return Plotly . restyle ( gd , 'marker.size' , 50 ) ;
907908 } )
908909 . then ( function ( ) {
909- _assert ( 'set rng / big marker.size' , [ 0 , 2 ] , [ 0 , 2 ] ) ;
910+ assertAxisRanges ( 'set rng / big marker.size' , [ 0 , 2 ] , [ 0 , 2 ] ) ;
910911 return Plotly . relayout ( gd , {
911912 'xaxis.autorange' : true ,
912913 'yaxis.autorange' : true
913914 } ) ;
914915 } )
915916 . then ( function ( ) {
916- _assert ( 'auto rng / big marker.size' , [ - 0.28 , 2.28 ] , [ 0.75 , 2.25 ] ) ;
917+ assertAxisRanges ( 'auto rng / big marker.size' , [ - 0.28 , 2.28 ] , [ 0.75 , 2.25 ] ) ;
917918 return Plotly . restyle ( gd , 'marker.size' , null ) ;
918919 } )
919920 . then ( function ( ) {
920- _assert ( 'auto rng / base marker.size' , [ - 0.13 , 2.13 ] , [ 0.93 , 2.07 ] ) ;
921+ assertAxisRanges ( 'auto rng / base marker.size' , [ - 0.13 , 2.13 ] , [ 0.93 , 2.07 ] ) ;
922+ } )
923+ . catch ( failTest )
924+ . then ( done ) ;
925+ } ) ;
926+
927+ it ( 'should update axis range according to visible edits' , function ( done ) {
928+ Plotly . plot ( gd , [
929+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 1 ] } ,
930+ { x : [ 4 , 5 , 6 ] , y : [ - 1 , - 2 , - 1 ] }
931+ ] )
932+ . then ( function ( ) {
933+ assertAxisRanges ( 'both visible' , [ 0.676 , 6.323 ] , [ - 2.29 , 2.29 ] ) ;
934+ return Plotly . restyle ( gd , 'visible' , false , [ 1 ] ) ;
935+ } )
936+ . then ( function ( ) {
937+ assertAxisRanges ( 'visible [true,false]' , [ 0.87 , 3.128 ] , [ 0.926 , 2.07 ] ) ;
938+ return Plotly . restyle ( gd , 'visible' , false , [ 0 ] ) ;
939+ } )
940+ . then ( function ( ) {
941+ assertAxisRanges ( 'both invisible' , [ 0.87 , 3.128 ] , [ 0.926 , 2.07 ] ) ;
942+ return Plotly . restyle ( gd , 'visible' , true , [ 1 ] ) ;
943+ } )
944+ . then ( function ( ) {
945+ assertAxisRanges ( 'visible [false,true]' , [ 3.871 , 6.128 ] , [ - 2.07 , - 0.926 ] ) ;
946+ return Plotly . restyle ( gd , 'visible' , true ) ;
947+ } )
948+ . then ( function ( ) {
949+ assertAxisRanges ( 'back to both visible' , [ 0.676 , 6.323 ] , [ - 2.29 , 2.29 ] ) ;
950+ } )
951+ . catch ( failTest )
952+ . then ( done ) ;
953+ } ) ;
954+
955+ it ( 'should be able to start from visible:false' , function ( done ) {
956+ function _assert ( msg , cnt ) {
957+ var layer = d3 . select ( gd ) . select ( 'g.scatterlayer' ) ;
958+ expect ( layer . selectAll ( '.point' ) . size ( ) ) . toBe ( cnt , msg + '- scatter pts cnt' ) ;
959+ }
960+
961+ Plotly . plot ( gd , [ {
962+ visible : false ,
963+ y : [ 1 , 2 , 1 ]
964+ } ] )
965+ . then ( function ( ) {
966+ _assert ( 'visible:false' , 0 ) ;
967+ return Plotly . restyle ( gd , 'visible' , true ) ;
968+ } )
969+ . then ( function ( ) {
970+ _assert ( 'visible:true' , 3 ) ;
971+ return Plotly . restyle ( gd , 'visible' , false ) ;
972+ } )
973+ . then ( function ( ) {
974+ _assert ( 'back to visible:false' , 0 ) ;
921975 } )
922976 . catch ( failTest )
923977 . then ( done ) ;
0 commit comments