@@ -1381,6 +1381,58 @@ describe('legend relayout update', function() {
13811381 } )
13821382 . then ( done , done . fail ) ;
13831383 } ) ;
1384+
1385+ it ( 'should constrain legend height when yref is container' , function ( done ) {
1386+ var fig = {
1387+ data : Array . from ( { length : 20 } , ( ) => ( {
1388+ x : [ 1 , 2 , 3 ] ,
1389+ y : [ 1 , 2 , 3 ]
1390+ } ) ) ,
1391+ layout : {
1392+ legend : {
1393+ xref : 'container' ,
1394+ yref : 'container' ,
1395+ x :0.9
1396+ }
1397+ }
1398+ }
1399+
1400+ function _assert ( msg , xy , wh ) {
1401+ return function ( ) {
1402+ var fullLayout = gd . _fullLayout ;
1403+ var legend3 = d3Select ( 'g.legend' ) ;
1404+ var bg3 = legend3 . select ( 'rect.bg' ) ;
1405+ var translate = Drawing . getTranslate ( legend3 ) ;
1406+ var x = translate . x ;
1407+ var y = translate . y ;
1408+ var w = + bg3 . attr ( 'width' ) ;
1409+ var h = + bg3 . attr ( 'height' ) ;
1410+
1411+ console . log ( ) ;
1412+ console . log ( "msg: " , msg ) ;
1413+ console . log ( "x: " , x , " y: " , y ) ;
1414+ console . log ( "w: " , w , " h: " , h ) ;
1415+ console . log ( "xy: " , xy ) ;
1416+ console . log ( "wh: " , wh ) ;
1417+ console . log ( "fullLayout.width:" , fullLayout . width , "fullLayout.height:" , fullLayout . height ) ;
1418+
1419+ expect ( [ x , y ] ) . toBeWithinArray ( xy , 25 , msg + '| legend x,y' ) ;
1420+ expect ( [ w , h ] ) . toBeWithinArray ( wh , 25 , msg + '| legend w,h' ) ;
1421+ expect ( x + w <= fullLayout . width ) . toBe ( true , msg + '| fits in x' ) ;
1422+ expect ( y + h <= fullLayout . height ) . toBe ( true , msg + '| fits in y' ) ;
1423+ } ;
1424+ }
1425+
1426+ Plotly . newPlot ( gd , fig )
1427+ . then ( _assert ( 'base' , [ 539 , 0 ] , [ 91 , 390 ] ) )
1428+ . then ( function ( ) { return Plotly . relayout ( gd , 'legend.y' , 0.6 ) ; } )
1429+ . then ( function ( ) { return Plotly . relayout ( gd , 'legend.yanchor' , 'bottom' ) ; } )
1430+ . then ( _assert ( 'after moving legend towards the top edge' , [ 539 , 0 ] , [ 101 , 180 ] ) )
1431+ . then ( function ( ) { return Plotly . relayout ( gd , 'legend.y' , 0.4 ) ; } )
1432+ . then ( function ( ) { return Plotly . relayout ( gd , 'legend.yanchor' , 'top' ) ; } )
1433+ . then ( _assert ( 'after moving legend towards the bottom edge' , [ 539 , 270 ] , [ 101 , 180 ] ) )
1434+ . then ( done , done . fail ) ;
1435+ } ) ;
13841436} ) ;
13851437
13861438describe ( 'legend orientation change:' , function ( ) {
0 commit comments