@@ -2465,7 +2465,7 @@ describe('Test axes', function() {
2465
2465
'short label 5' , 'loooooong label 5'
2466
2466
]
2467
2467
} ] ,
2468
- gd ;
2468
+ gd , initialSize , previousSize , savedBottom ;
2469
2469
2470
2470
beforeEach ( function ( ) {
2471
2471
gd = createGraphDiv ( ) ;
@@ -2477,87 +2477,98 @@ describe('Test axes', function() {
2477
2477
2478
2478
Plotly . plot ( gd , data )
2479
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 ) ;
2480
+ initialSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2486
2481
expect ( gd . _fullLayout . xaxis . _lastangle ) . toBe ( 30 ) ;
2487
2482
} )
2488
2483
. then ( function ( ) {
2484
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2489
2485
return Plotly . relayout ( gd , { 'yaxis.automargin' : true } ) ;
2490
2486
} )
2491
2487
. then ( function ( ) {
2492
2488
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 ) ;
2489
+ expect ( size . l ) . toBeGreaterThan ( previousSize . l ) ;
2490
+ expect ( size . r ) . toBe ( previousSize . r ) ;
2491
+ expect ( size . b ) . toBe ( previousSize . b ) ;
2492
+ expect ( size . t ) . toBe ( previousSize . t ) ;
2497
2493
} )
2498
2494
. then ( function ( ) {
2495
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2499
2496
return Plotly . relayout ( gd , { 'xaxis.automargin' : true } ) ;
2500
2497
} )
2501
2498
. then ( function ( ) {
2502
2499
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 ) ;
2500
+ expect ( size . l ) . toBe ( previousSize . l ) ;
2501
+ expect ( size . r ) . toBe ( previousSize . r ) ;
2502
+ expect ( size . b ) . toBeGreaterThan ( previousSize . b ) ;
2503
+ expect ( size . t ) . toBe ( previousSize . t ) ;
2507
2504
} )
2508
2505
. then ( function ( ) {
2506
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2507
+ savedBottom = previousSize . b ;
2509
2508
return Plotly . relayout ( gd , { 'xaxis.tickangle' : 45 } ) ;
2510
2509
} )
2511
2510
. then ( function ( ) {
2512
2511
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 ) ;
2512
+ expect ( size . l ) . toBe ( previousSize . l ) ;
2513
+ expect ( size . r ) . toBe ( previousSize . r ) ;
2514
+ expect ( size . b ) . toBeGreaterThan ( previousSize . b ) ;
2515
+ expect ( size . t ) . toBe ( previousSize . t ) ;
2517
2516
} )
2518
2517
. then ( function ( ) {
2518
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2519
2519
return Plotly . relayout ( gd , { 'xaxis.tickangle' : 30 } ) ;
2520
2520
} )
2521
2521
. then ( function ( ) {
2522
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 ) ;
2523
+ expect ( size . l ) . toBe ( previousSize . l ) ;
2524
+ expect ( size . r ) . toBe ( previousSize . r ) ;
2525
+ expect ( size . b ) . toBe ( savedBottom ) ;
2526
+ expect ( size . t ) . toBe ( previousSize . t ) ;
2527
2527
} )
2528
2528
. then ( function ( ) {
2529
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2529
2530
return Plotly . relayout ( gd , { 'yaxis.ticklen' : 30 } ) ;
2530
2531
} )
2531
2532
. then ( function ( ) {
2532
2533
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 ) ;
2534
+ expect ( size . l ) . toBeGreaterThan ( previousSize . l ) ;
2535
+ expect ( size . r ) . toBe ( previousSize . r ) ;
2536
+ expect ( size . b ) . toBe ( previousSize . b ) ;
2537
+ expect ( size . t ) . toBe ( previousSize . t ) ;
2537
2538
} )
2538
2539
. then ( function ( ) {
2540
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2539
2541
return Plotly . relayout ( gd , { 'yaxis.titlefont.size' : 30 } ) ;
2540
2542
} )
2541
2543
. then ( function ( ) {
2542
2544
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 ) ;
2545
+ expect ( size ) . toEqual ( previousSize ) ;
2546
+ } )
2547
+ . then ( function ( ) {
2548
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2549
+ return Plotly . relayout ( gd , { 'yaxis.title' : 'hello' } ) ;
2550
+ } )
2551
+ . then ( function ( ) {
2552
+ var size = gd . _fullLayout . _size ;
2553
+ expect ( size . l ) . toBeGreaterThan ( previousSize . l ) ;
2554
+ expect ( size . r ) . toBe ( previousSize . r ) ;
2555
+ expect ( size . b ) . toBe ( previousSize . b ) ;
2556
+ expect ( size . t ) . toBe ( previousSize . t ) ;
2547
2557
} )
2548
2558
. then ( function ( ) {
2559
+ previousSize = Lib . extendDeep ( { } , gd . _fullLayout . _size ) ;
2549
2560
return Plotly . relayout ( gd , {
2550
2561
'yaxis.side' : 'right' ,
2551
2562
'xaxis.side' : 'top'
2552
2563
} ) ;
2553
2564
} )
2554
2565
. then ( function ( ) {
2555
2566
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 ) ;
2567
+ // left to right and bottom to top
2568
+ expect ( size . l ) . toBe ( initialSize . r ) ;
2569
+ expect ( size . r ) . toBe ( previousSize . l ) ;
2570
+ expect ( size . b ) . toBe ( initialSize . b ) ;
2571
+ expect ( size . t ) . toBe ( previousSize . b ) ;
2561
2572
} )
2562
2573
. then ( function ( ) {
2563
2574
return Plotly . relayout ( gd , {
@@ -2568,10 +2579,7 @@ describe('Test axes', function() {
2568
2579
. then ( function ( ) {
2569
2580
var size = gd . _fullLayout . _size ;
2570
2581
// 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 ) ;
2582
+ expect ( size ) . toEqual ( initialSize ) ;
2575
2583
} )
2576
2584
. catch ( failTest )
2577
2585
. then ( done ) ;
0 commit comments