@@ -3102,33 +3102,35 @@ describe('Test axes', function() {
31023102
31033103    describe ( '*tickson*:' ,  function ( )  { 
31043104        var  gd ; 
3105+ 
31053106        beforeEach ( function ( )  { 
31063107            gd  =  createGraphDiv ( ) ; 
31073108        } ) ; 
3109+ 
31083110        afterEach ( destroyGraphDiv ) ; 
31093111
3110-         function  getPositions ( query )  { 
3111-             var  pos  =  [ ] ; 
3112-             d3 . selectAll ( query ) . each ( function ( )  { 
3113-                 pos . push ( this . getBoundingClientRect ( ) . x ) ; 
3114-             } ) ; 
3115-             return  pos ; 
3116-         } 
3112+         it ( 'should respond to relayout' ,  function ( done )  { 
3113+             function  getPositions ( query )  { 
3114+                 var  pos  =  [ ] ; 
3115+                 d3 . selectAll ( query ) . each ( function ( )  { 
3116+                     pos . push ( this . getBoundingClientRect ( ) . x ) ; 
3117+                 } ) ; 
3118+                 return  pos ; 
3119+             } 
31173120
3118-         function  _assert ( msg ,  exp )  { 
3119-             var  ticks  =  getPositions ( 'path.xtick' ) ; 
3120-             var  gridLines  =  getPositions ( 'path.xgrid' ) ; 
3121-             var  tickLabels  =  getPositions ( '.xtick > text' ) ; 
3121+              function  _assert ( msg ,  exp )  { 
3122+                  var  ticks  =  getPositions ( 'path.xtick' ) ; 
3123+                  var  gridLines  =  getPositions ( 'path.xgrid' ) ; 
3124+                  var  tickLabels  =  getPositions ( '.xtick > text' ) ; 
31223125
3123-             expect ( ticks ) . toBeCloseToArray ( exp . ticks ,  1 ,  msg  +  '- ticks' ) ; 
3124-             expect ( gridLines ) . toBeCloseToArray ( exp . gridLines ,  1 ,  msg  +  '- grid lines' ) ; 
3125-             expect ( tickLabels . length ) . toBe ( exp . tickLabels . length ,  msg  +  '- # of tick labels' ) ; 
3126-             tickLabels . forEach ( function ( tl ,  i )  { 
3127-                 expect ( tl ) . toBeWithin ( exp . tickLabels [ i ] ,  2 ,  msg  +  '- tick label '  +  i ) ; 
3128-             } ) ; 
3129-         } 
3126+                  expect ( ticks ) . toBeCloseToArray ( exp . ticks ,  1 ,  msg  +  '- ticks' ) ; 
3127+                  expect ( gridLines ) . toBeCloseToArray ( exp . gridLines ,  1 ,  msg  +  '- grid lines' ) ; 
3128+                  expect ( tickLabels . length ) . toBe ( exp . tickLabels . length ,  msg  +  '- # of tick labels' ) ; 
3129+                  tickLabels . forEach ( function ( tl ,  i )  { 
3130+                      expect ( tl ) . toBeWithin ( exp . tickLabels [ i ] ,  2 ,  msg  +  '- tick label '  +  i ) ; 
3131+                  } ) ; 
3132+              } 
31303133
3131-         it ( 'should respond to relayout' ,  function ( done )  { 
31323134            Plotly . plot ( gd ,  [ { 
31333135                x : [ 'a' ,  'b' ,  'c' ] , 
31343136                y : [ 1 ,  2 ,  1 ] 
@@ -3172,6 +3174,55 @@ describe('Test axes', function() {
31723174            . catch ( failTest ) 
31733175            . then ( done ) ; 
31743176        } ) ; 
3177+ 
3178+         it ( 'should rotate labels to avoid overlaps' ,  function ( done )  { 
3179+             function  _assert ( msg ,  exp )  { 
3180+                 var  tickLabels  =  d3 . selectAll ( '.xtick > text' ) ; 
3181+ 
3182+                 expect ( tickLabels . size ( ) ) . toBe ( exp . angle . length ,  msg  +  ' - # of tick labels' ) ; 
3183+ 
3184+                 tickLabels . each ( function ( _ ,  i )  { 
3185+                     var  t  =  d3 . select ( this ) . attr ( 'transform' ) ; 
3186+                     var  rotate  =  ( t . split ( 'rotate(' ) [ 1 ]  ||  '' ) . split ( ')' ) [ 0 ] ; 
3187+                     var  angle  =  rotate . split ( ',' ) [ 0 ] ; 
3188+                     expect ( Number ( angle ) ) . toBe ( exp . angle [ i ] ,  msg  +  ' - node '  +  i ) ; 
3189+                 } ) ; 
3190+             } 
3191+ 
3192+             Plotly . plot ( gd ,  [ { 
3193+                 x : [ 'A very long title' ,  'short' ,  'Another very long title' ] , 
3194+                 y : [ 1 ,  4 ,  2 ] 
3195+             } ] ,  { 
3196+                 xaxis : { 
3197+                     domain : [ 0.22 ,  0.78 ] , 
3198+                     tickson : 'boundaries' , 
3199+                     ticks : 'outside' 
3200+                 } , 
3201+                 width : 500 , 
3202+                 height : 500 
3203+             } ) 
3204+             . then ( function ( )  { 
3205+                 _assert ( 'base - rotated' ,  { 
3206+                     angle : [ 90 ,  90 ,  90 ] 
3207+                 } ) ; 
3208+ 
3209+                 return  Plotly . relayout ( gd ,  'xaxis.range' ,  [ - 0.5 ,  1.5 ] ) ; 
3210+             } ) 
3211+             . then ( function ( )  { 
3212+                 _assert ( 'narrower range - unrotated' ,  { 
3213+                     angle : [ 0 ,  0 ] 
3214+                 } ) ; 
3215+ 
3216+                 return  Plotly . relayout ( gd ,  'xaxis.tickwidth' ,  10 ) ; 
3217+             } ) 
3218+             . then ( function ( )  { 
3219+                 _assert ( 'narrow range / wide ticks - rotated' ,  { 
3220+                     angle : [ 90 ,  90 ] 
3221+                 } ) ; 
3222+             } ) 
3223+             . catch ( failTest ) 
3224+             . then ( done ) ; 
3225+         } ) ; 
31753226    } ) ; 
31763227} ) ; 
31773228
0 commit comments