@@ -159,6 +159,58 @@ describe('restyle', function() {
159159 . then ( done ) ;
160160
161161 } ) ;
162+
163+ it ( 'can legend-hide the second and only scatter trace' , function ( done ) {
164+ Plotly . plot ( gd , [
165+ { y : [ 1 , 2 , 3 ] , type : 'bar' } ,
166+ { y : [ 1 , 2 , 3 ] , xaxis : 'x2' , yaxis : 'y2' , type : 'scatter' }
167+ ] , {
168+ xaxis : { domain : [ 0 , 0.4 ] } ,
169+ xaxis2 : { domain : [ 0.6 , 1 ] } ,
170+ yaxis2 : { anchor : 'x2' } ,
171+ width : 600 ,
172+ height : 400
173+ } )
174+ . then ( function ( ) {
175+ expect ( d3 . select ( '.scatter' ) . size ( ) ) . toBe ( 1 ) ;
176+ return Plotly . restyle ( gd , { visible : 'legendonly' } , 1 ) ;
177+ } )
178+ . then ( function ( ) {
179+ expect ( d3 . select ( '.scatter' ) . size ( ) ) . toBe ( 0 ) ;
180+ return Plotly . restyle ( gd , { visible : true } , 1 ) ;
181+ } )
182+ . then ( function ( ) {
183+ expect ( d3 . select ( '.scatter' ) . size ( ) ) . toBe ( 1 ) ;
184+ } )
185+ . catch ( failTest )
186+ . then ( done ) ;
187+ } ) ;
188+
189+ it ( 'can legend-hide the second and only scattergl trace' , function ( done ) {
190+ Plotly . plot ( gd , [
191+ { y : [ 1 , 2 , 3 ] , type : 'bar' } ,
192+ { y : [ 1 , 2 , 3 ] , xaxis : 'x2' , yaxis : 'y2' , type : 'scattergl' }
193+ ] , {
194+ xaxis : { domain : [ 0 , 0.4 ] } ,
195+ xaxis2 : { domain : [ 0.6 , 1 ] } ,
196+ yaxis2 : { anchor : 'x2' } ,
197+ width : 600 ,
198+ height : 400
199+ } )
200+ . then ( function ( ) {
201+ expect ( ! ! gd . _fullLayout . _plots . x2y2 . _scene ) . toBe ( true ) ;
202+ return Plotly . restyle ( gd , { visible : 'legendonly' } , 1 ) ;
203+ } )
204+ . then ( function ( ) {
205+ expect ( ! ! gd . _fullLayout . _plots . x2y2 . _scene ) . toBe ( false ) ;
206+ return Plotly . restyle ( gd , { visible : true } , 1 ) ;
207+ } )
208+ . then ( function ( ) {
209+ expect ( ! ! gd . _fullLayout . _plots . x2y2 . _scene ) . toBe ( true ) ;
210+ } )
211+ . catch ( failTest )
212+ . then ( done ) ;
213+ } ) ;
162214 } ) ;
163215} ) ;
164216
0 commit comments