@@ -1476,6 +1476,14 @@ describe('hover info', function() {
14761476 msgPrefixFmt + 'Top edges of primary and secondary boxes aligned' ) ;
14771477 }
14781478
1479+ function calcLineOverlap ( minA , maxA , minB , maxB ) {
1480+ expect ( minA ) . toBeLessThan ( maxA ) ;
1481+ expect ( minB ) . toBeLessThan ( maxB ) ;
1482+
1483+ var overlap = Math . min ( maxA , maxB ) - Math . max ( minA , minB ) ;
1484+ return Math . max ( 0 , overlap ) ;
1485+ }
1486+
14791487 it ( 'centered-aligned, should render labels inside boxes' , function ( done ) {
14801488 var trace1 = {
14811489 x : [ 'giraffes' ] ,
@@ -1506,14 +1514,6 @@ describe('hover info', function() {
15061514 } ) ;
15071515
15081516 it ( 'centered-aligned, should stack nicely upon each other' , function ( done ) {
1509- function calcLineOverlap ( minA , maxA , minB , maxB ) {
1510- expect ( minA ) . toBeLessThan ( maxA ) ;
1511- expect ( minB ) . toBeLessThan ( maxB ) ;
1512-
1513- var overlap = Math . min ( maxA , maxB ) - Math . max ( minA , minB ) ;
1514- return Math . max ( 0 , overlap ) ;
1515- }
1516-
15171517 var trace1 = {
15181518 x : [ 'giraffes' ] ,
15191519 y : [ 5 ] ,
@@ -1561,6 +1561,50 @@ describe('hover info', function() {
15611561 . catch ( failTest )
15621562 . then ( done ) ;
15631563 } ) ;
1564+
1565+ it ( 'should stack multi-line trace-name labels nicely' , function ( done ) {
1566+ var name = 'Multi<br>line<br>trace<br>name' ;
1567+ var name2 = 'Multi<br>line<br>trace<br>name2' ;
1568+
1569+ Plotly . plot ( gd , [ {
1570+ y : [ 1 , 2 , 1 ] ,
1571+ name : name ,
1572+ hoverlabel : { namelength : - 1 } ,
1573+ hoverinfo : 'x+y+name'
1574+ } , {
1575+ y : [ 1 , 2 , 1 ] ,
1576+ name : name2 ,
1577+ hoverinfo : 'x+y+name' ,
1578+ hoverlabel : { namelength : - 1 }
1579+ } ] , {
1580+ width : 600 ,
1581+ height : 300
1582+ } )
1583+ . then ( function ( ) { _hoverNatural ( gd , 209 , 12 ) ; } )
1584+ . then ( function ( ) {
1585+ var nodes = hoverInfoNodes ( name ) ;
1586+ var nodes2 = hoverInfoNodes ( name2 ) ;
1587+
1588+ assertLabelsInsideBoxes ( nodes , 'trace 0' ) ;
1589+ assertLabelsInsideBoxes ( nodes2 , 'trace 2' ) ;
1590+ assertSecondaryRightToPrimaryBox ( nodes , 'trace 0' ) ;
1591+ assertSecondaryRightToPrimaryBox ( nodes2 , 'trace 2' ) ;
1592+
1593+ var primaryBB = nodes . primaryBox . getBoundingClientRect ( ) ;
1594+ var primaryBB2 = nodes2 . primaryBox . getBoundingClientRect ( ) ;
1595+ expect ( calcLineOverlap ( primaryBB . top , primaryBB . bottom , primaryBB2 . top , primaryBB2 . bottom ) )
1596+ . toBeWithin ( 0 , 1 ) ;
1597+
1598+ // there's a bit of a gap in the secondary as they do have
1599+ // a border (for now)
1600+ var secondaryBB = nodes . secondaryBox . getBoundingClientRect ( ) ;
1601+ var secondaryBB2 = nodes2 . secondaryBox . getBoundingClientRect ( ) ;
1602+ expect ( calcLineOverlap ( secondaryBB . top , secondaryBB . bottom , secondaryBB2 . top , secondaryBB2 . bottom ) )
1603+ . toBeWithin ( 2 , 1 ) ;
1604+ } )
1605+ . catch ( failTest )
1606+ . then ( done ) ;
1607+ } ) ;
15641608 } ) ;
15651609
15661610 describe ( 'hovertemplate' , function ( ) {
0 commit comments