@@ -2447,6 +2447,137 @@ describe('Test axes', function() {
24472447 } ) ;
24482448 } ) ;
24492449 } ) ;
2450+
2451+ describe ( 'automargin' , function ( ) {
2452+ var data = [ {
2453+ x : [
2454+ 'short label 1' , 'loooooong label 1' ,
2455+ 'short label 2' , 'loooooong label 2' ,
2456+ 'short label 3' , 'loooooong label 3' ,
2457+ 'short label 4' , 'loooooongloooooongloooooong label 4' ,
2458+ 'short label 5' , 'loooooong label 5'
2459+ ] ,
2460+ y : [
2461+ 'short label 1' , 'loooooong label 1' ,
2462+ 'short label 2' , 'loooooong label 2' ,
2463+ 'short label 3' , 'loooooong label 3' ,
2464+ 'short label 4' , 'loooooong label 4' ,
2465+ 'short label 5' , 'loooooong label 5'
2466+ ]
2467+ } ] ,
2468+ gd ;
2469+
2470+ beforeEach ( function ( ) {
2471+ gd = createGraphDiv ( ) ;
2472+ } ) ;
2473+
2474+ afterEach ( destroyGraphDiv ) ;
2475+
2476+ it ( 'should grow and shrink margins' , function ( done ) {
2477+
2478+ Plotly . plot ( gd , data )
2479+ . then ( function ( ) {
2480+ var size = gd . _fullLayout . _size ;
2481+ // these are the defaults
2482+ expect ( size . l ) . toBe ( 80 ) ;
2483+ expect ( size . r ) . toBe ( 80 ) ;
2484+ expect ( size . b ) . toBe ( 80 ) ;
2485+ expect ( size . t ) . toBe ( 100 ) ;
2486+ expect ( gd . _fullLayout . xaxis . _lastangle ) . toBe ( 30 ) ;
2487+ } )
2488+ . then ( function ( ) {
2489+ return Plotly . relayout ( gd , { 'yaxis.automargin' : true } ) ;
2490+ } )
2491+ . then ( function ( ) {
2492+ var size = gd . _fullLayout . _size ;
2493+ expect ( size . l ) . toBe ( 133 ) ; // left side grows
2494+ expect ( size . r ) . toBe ( 80 ) ;
2495+ expect ( size . b ) . toBe ( 80 ) ;
2496+ expect ( size . t ) . toBe ( 100 ) ;
2497+ } )
2498+ . then ( function ( ) {
2499+ return Plotly . relayout ( gd , { 'xaxis.automargin' : true } ) ;
2500+ } )
2501+ . then ( function ( ) {
2502+ var size = gd . _fullLayout . _size ;
2503+ expect ( size . l ) . toBe ( 133 ) ;
2504+ expect ( size . r ) . toBe ( 80 ) ;
2505+ expect ( size . b ) . toBe ( 154 ) ; // bottom grows
2506+ expect ( size . t ) . toBe ( 100 ) ;
2507+ } )
2508+ . then ( function ( ) {
2509+ return Plotly . relayout ( gd , { 'xaxis.tickangle' : 45 } ) ;
2510+ } )
2511+ . then ( function ( ) {
2512+ var size = gd . _fullLayout . _size ;
2513+ expect ( size . l ) . toBe ( 133 ) ;
2514+ expect ( size . r ) . toBe ( 80 ) ;
2515+ expect ( size . b ) . toBe ( 200 ) ; // bottom grows more
2516+ expect ( size . t ) . toBe ( 100 ) ;
2517+ } )
2518+ . then ( function ( ) {
2519+ return Plotly . relayout ( gd , { 'xaxis.tickangle' : 30 } ) ;
2520+ } )
2521+ . then ( function ( ) {
2522+ var size = gd . _fullLayout . _size ;
2523+ expect ( size . l ) . toBe ( 133 ) ;
2524+ expect ( size . r ) . toBe ( 80 ) ;
2525+ expect ( size . b ) . toBe ( 154 ) ; // bottom shrinks back
2526+ expect ( size . t ) . toBe ( 100 ) ;
2527+ } )
2528+ . then ( function ( ) {
2529+ return Plotly . relayout ( gd , { 'yaxis.ticklen' : 30 } ) ;
2530+ } )
2531+ . then ( function ( ) {
2532+ var size = gd . _fullLayout . _size ;
2533+ expect ( size . l ) . toBe ( 165 ) ; // left grows for tick length
2534+ expect ( size . r ) . toBe ( 80 ) ;
2535+ expect ( size . b ) . toBe ( 154 ) ;
2536+ expect ( size . t ) . toBe ( 100 ) ;
2537+ } )
2538+ . then ( function ( ) {
2539+ return Plotly . relayout ( gd , { 'yaxis.titlefont.size' : 30 } ) ;
2540+ } )
2541+ . then ( function ( ) {
2542+ var size = gd . _fullLayout . _size ;
2543+ expect ( size . l ) . toBe ( 181 ) ; // left grows for axis title font size
2544+ expect ( size . r ) . toBe ( 80 ) ;
2545+ expect ( size . b ) . toBe ( 154 ) ;
2546+ expect ( size . t ) . toBe ( 100 ) ;
2547+ } )
2548+ . then ( function ( ) {
2549+ return Plotly . relayout ( gd , {
2550+ 'yaxis.side' : 'right' ,
2551+ 'xaxis.side' : 'top'
2552+ } ) ;
2553+ } )
2554+ . then ( function ( ) {
2555+ var size = gd . _fullLayout . _size ;
2556+ // left-right and top-bottom swap
2557+ expect ( size . l ) . toBe ( 80 ) ;
2558+ expect ( size . r ) . toBe ( 181 ) ;
2559+ expect ( size . b ) . toBe ( 80 ) ;
2560+ expect ( size . t ) . toBe ( 154 ) ;
2561+ } )
2562+ . then ( function ( ) {
2563+ return Plotly . relayout ( gd , {
2564+ 'xaxis.automargin' : false ,
2565+ 'yaxis.automargin' : false
2566+ } ) ;
2567+ } )
2568+ . then ( function ( ) {
2569+ var size = gd . _fullLayout . _size ;
2570+ // back to the defaults
2571+ expect ( size . l ) . toBe ( 80 ) ;
2572+ expect ( size . r ) . toBe ( 80 ) ;
2573+ expect ( size . b ) . toBe ( 80 ) ;
2574+ expect ( size . t ) . toBe ( 100 ) ;
2575+ } )
2576+ . catch ( failTest )
2577+ . then ( done ) ;
2578+
2579+ } ) ;
2580+ } ) ;
24502581} ) ;
24512582
24522583function getZoomInButton ( gd ) {
0 commit comments