@@ -352,6 +352,51 @@ describe('Visible rangesliders', function() {
352352 . catch ( failTest )
353353 . then ( done ) ;
354354 } ) ;
355+
356+ it ( 'should automargin correctly with a top or bottom x axis' , function ( done ) {
357+ var topMock = require ( '@mocks/range_slider_top_axis' ) ;
358+
359+ function assertTop ( hasExtra ) {
360+ var op = hasExtra ? 'toBeGreaterThan' : 'toBeLessThan' ;
361+ expect ( gd . _fullLayout . _size . t ) [ op ] ( 102 ) ;
362+ expect ( gd . _fullLayout . _size . b ) . toBeWithin ( 128 , 5 ) ;
363+ }
364+
365+ function assertBottom ( val ) {
366+ expect ( gd . _fullLayout . _size . t ) . toBe ( 100 ) ;
367+ expect ( gd . _fullLayout . _size . b ) . toBeWithin ( val , 10 ) ;
368+ }
369+
370+ Plotly . plot ( gd , topMock )
371+ . then ( function ( ) {
372+ assertTop ( true ) ;
373+ return Plotly . relayout ( gd , 'xaxis.range' , [ - 0.5 , 1.5 ] ) ;
374+ } )
375+ . then ( function ( ) {
376+ assertTop ( false ) ;
377+ return Plotly . relayout ( gd , 'xaxis.range' , [ - 0.5 , 6.5 ] ) ;
378+ } )
379+ . then ( function ( ) {
380+ assertTop ( true ) ;
381+ // rangeslider automargins even without automargin turned on
382+ // axis.automargin only affects automargin directly from labels,
383+ // not when the rangeslider is pushed down by labels.
384+ return Plotly . relayout ( gd , { 'xaxis.side' : 'bottom' , 'xaxis.automargin' : false } ) ;
385+ } )
386+ . then ( function ( ) {
387+ assertBottom ( 210 ) ;
388+ return Plotly . relayout ( gd , 'xaxis.range' , [ - 0.5 , 1.5 ] ) ;
389+ } )
390+ . then ( function ( ) {
391+ assertBottom ( 145 ) ;
392+ return Plotly . relayout ( gd , 'xaxis.range' , [ - 0.5 , 6.5 ] ) ;
393+ } )
394+ . then ( function ( ) {
395+ assertBottom ( 210 ) ;
396+ } )
397+ . catch ( failTest )
398+ . then ( done ) ;
399+ } ) ;
355400} ) ;
356401
357402describe ( 'Rangeslider visibility property' , function ( ) {
0 commit comments