@@ -7,6 +7,7 @@ var Lib = require('@src/lib');
7
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
8
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9
9
var TRANSITION_DELAY = 100 ;
10
+ var fail = require ( '../assets/fail_test' ) ;
10
11
11
12
describe ( 'update menus defaults' , function ( ) {
12
13
'use strict' ;
@@ -446,6 +447,60 @@ describe('update menus interactions', function() {
446
447
} ) ;
447
448
} ) ;
448
449
450
+ it ( 'applies padding on all sides' , function ( done ) {
451
+ var xy1 , xy2 ;
452
+ var firstMenu = d3 . select ( '.' + constants . headerGroupClassName ) ;
453
+ var xpad = 80 ;
454
+ var ypad = 60 ;
455
+
456
+ // Position it center-anchored and in the middle of the plot:
457
+ Plotly . relayout ( gd , {
458
+ 'updatemenus[0].x' : 0.2 ,
459
+ 'updatemenus[0].y' : 0.5 ,
460
+ 'updatemenus[0].xanchor' : 'center' ,
461
+ 'updatemenus[0].yanchor' : 'middle' ,
462
+ } ) . then ( function ( ) {
463
+ // Convert to xy:
464
+ xy1 = firstMenu . attr ( 'transform' ) . match ( / t r a n s l a t e \( ( [ ^ , ] * ) , \s * ( [ ^ \) ] * ) \) / ) . slice ( 1 ) . map ( parseFloat ) ;
465
+
466
+ // Set three of four paddings. This should move it.
467
+ return Plotly . relayout ( gd , {
468
+ 'updatemenus[0].pad.t' : ypad ,
469
+ 'updatemenus[0].pad.r' : xpad ,
470
+ 'updatemenus[0].pad.b' : ypad ,
471
+ 'updatemenus[0].pad.l' : xpad ,
472
+ } ) ;
473
+ } ) . then ( function ( ) {
474
+ xy2 = firstMenu . attr ( 'transform' ) . match ( / t r a n s l a t e \( ( [ ^ , ] * ) , \s * ( [ ^ \) ] * ) \) / ) . slice ( 1 ) . map ( parseFloat ) ;
475
+
476
+ expect ( xy1 [ 0 ] - xy2 [ 0 ] ) . toEqual ( xpad ) ;
477
+ expect ( xy1 [ 1 ] - xy2 [ 1 ] ) . toEqual ( ypad ) ;
478
+ } ) . catch ( fail ) . then ( done ) ;
479
+ } ) ;
480
+
481
+ it ( 'appliesy padding on relayout' , function ( done ) {
482
+ var x1 , x2 ;
483
+ var firstMenu = d3 . select ( '.' + constants . headerGroupClassName ) ;
484
+ var padShift = 40 ;
485
+
486
+ // Position the menu in the center of the plot horizontal so that
487
+ // we can test padding updates without worrying about margin pushing.
488
+ Plotly . relayout ( gd , {
489
+ 'updatemenus[0].x' : 0.5 ,
490
+ 'updatemenus[0].pad.r' : 0 ,
491
+ } ) . then ( function ( ) {
492
+ // Extract the x-component of the translation:
493
+ x1 = parseInt ( firstMenu . attr ( 'transform' ) . match ( / t r a n s l a t e \( ( [ ^ , ] * ) .* / ) [ 1 ] ) ;
494
+
495
+ return Plotly . relayout ( gd , 'updatemenus[0].pad.r' , 40 ) ;
496
+ } ) . then ( function ( ) {
497
+ // Extract the x-component of the translation:
498
+ x2 = parseInt ( firstMenu . attr ( 'transform' ) . match ( / t r a n s l a t e \( ( [ ^ , ] * ) .* / ) [ 1 ] ) ;
499
+
500
+ expect ( x1 - x2 ) . toBeCloseTo ( padShift , 1 ) ;
501
+ } ) . catch ( fail ) . then ( done ) ;
502
+ } ) ;
503
+
449
504
function assertNodeCount ( query , cnt ) {
450
505
expect ( d3 . selectAll ( query ) . size ( ) ) . toEqual ( cnt ) ;
451
506
}
0 commit comments