@@ -1476,6 +1476,14 @@ describe('hover info', function() {
1476
1476
msgPrefixFmt + 'Top edges of primary and secondary boxes aligned' ) ;
1477
1477
}
1478
1478
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
+
1479
1487
it ( 'centered-aligned, should render labels inside boxes' , function ( done ) {
1480
1488
var trace1 = {
1481
1489
x : [ 'giraffes' ] ,
@@ -1506,14 +1514,6 @@ describe('hover info', function() {
1506
1514
} ) ;
1507
1515
1508
1516
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
-
1517
1517
var trace1 = {
1518
1518
x : [ 'giraffes' ] ,
1519
1519
y : [ 5 ] ,
@@ -1561,6 +1561,50 @@ describe('hover info', function() {
1561
1561
. catch ( failTest )
1562
1562
. then ( done ) ;
1563
1563
} ) ;
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
+ } ) ;
1564
1608
} ) ;
1565
1609
1566
1610
describe ( 'hovertemplate' , function ( ) {
0 commit comments