@@ -1265,7 +1265,10 @@ describe('waterfall hover', function() {
12651265 return {
12661266 style : [ pt . index , pt . color , pt . xLabelVal , pt . yLabelVal ] ,
12671267 pos : [ pt . x0 , pt . x1 , pt . y0 , pt . y1 ] ,
1268- text : pt . text
1268+ text : pt . text ,
1269+ extraText : pt . extraText ,
1270+ xLabelVal : pt . xLabelVal ,
1271+ yLabelVal : pt . yLabelVal
12691272 } ;
12701273 }
12711274
@@ -1371,32 +1374,88 @@ describe('waterfall hover', function() {
13711374 . then ( done ) ;
13721375 } ) ;
13731376
1374- describe ( 'round hover precision' , function ( ) {
1375- it ( 'should format numbers' , function ( done ) {
1376- gd = createGraphDiv ( ) ;
1377-
1378- Plotly . plot ( gd , {
1379- data : [ {
1380- x : [ 'A' , 'B' , 'C' , 'D' , 'E' ] ,
1381- y : [ 0 , - 1.1 , 2.2 , - 3.3 , 4.4 ] ,
1382- type : 'waterfall'
1383- } ] ,
1384- layout : { width : 400 , height : 400 }
1385- } )
1386- . then ( function ( ) {
1387- var evt = { xpx : 200 , ypx : 350 } ;
1388- Fx . hover ( 'graph' , evt , 'xy' ) ;
1389- } )
1390- . then ( function ( ) {
1391- assertHoverLabelContent ( {
1392- nums : '2.2\n4.4 ▲\nInitial: −2.2' ,
1393- name : '' ,
1394- axis : 'E'
1395- } ) ;
1396- } )
1397- . catch ( failTest )
1398- . then ( done ) ;
1399- } ) ;
1377+ it ( 'should format numbers - round hover precision' , function ( done ) {
1378+ gd = createGraphDiv ( ) ;
1379+
1380+ Plotly . plot ( gd , {
1381+ data : [ {
1382+ x : [ 'A' , 'B' , 'C' , 'D' , 'E' ] ,
1383+ y : [ 0 , - 1.1 , 2.2 , - 3.3 , 4.4 ] ,
1384+ type : 'waterfall'
1385+ } ] ,
1386+ layout : { width : 400 , height : 400 }
1387+ } )
1388+ . then ( function ( ) {
1389+ var evt = { xpx : 200 , ypx : 350 } ;
1390+ Fx . hover ( 'graph' , evt , 'xy' ) ;
1391+ } )
1392+ . then ( function ( ) {
1393+ assertHoverLabelContent ( {
1394+ nums : '2.2\n4.4 ▲\nInitial: −2.2' ,
1395+ name : '' ,
1396+ axis : 'E'
1397+ } ) ;
1398+ } )
1399+ . catch ( failTest )
1400+ . then ( done ) ;
1401+ } ) ;
1402+
1403+ it ( 'hover measure categories with axis prefix and suffix' , function ( done ) {
1404+ gd = createGraphDiv ( ) ;
1405+
1406+ Plotly . plot ( gd , {
1407+ data : [ {
1408+ x : [ 'A' , 'B' , 'C' , 'D' , 'E' ] ,
1409+ y : [ 2.2 , - 1.1 , null , 3.3 , null ] ,
1410+ measure : [ 'a' , 'r' , 't' , 'r' , 't' ] ,
1411+ base : 1000.001 ,
1412+ type : 'waterfall'
1413+ } ] ,
1414+ layout : {
1415+ xaxis : {
1416+ tickprefix : '[' ,
1417+ ticksuffix : ']'
1418+ } ,
1419+ yaxis : {
1420+ tickprefix : '$' ,
1421+ ticksuffix : 'm'
1422+ } ,
1423+ width : 400 ,
1424+ height : 400
1425+ }
1426+ } )
1427+ . then ( function ( ) {
1428+ var out = _hover ( gd , 0 , 1000.5 , 'closest' ) ;
1429+ expect ( out . yLabelVal ) . toEqual ( 1002.201 ) ;
1430+ expect ( out . extraText ) . toEqual ( undefined ) ;
1431+ expect ( out . style ) . toEqual ( [ 0 , '#4499FF' , 0 , 1002.201 ] ) ;
1432+ } )
1433+ . then ( function ( ) {
1434+ var out = _hover ( gd , 1 , 1000.5 , 'closest' ) ;
1435+ expect ( out . yLabelVal ) . toEqual ( 1001.101 ) ;
1436+ expect ( out . extraText ) . toEqual ( '($1.1m) ▼<br>Initial: $1,002.201m' ) ;
1437+ expect ( out . style ) . toEqual ( [ 1 , '#FF4136' , 1 , 1001.101 ] ) ;
1438+ } )
1439+ . then ( function ( ) {
1440+ var out = _hover ( gd , 2 , 1000.5 , 'closest' ) ;
1441+ expect ( out . yLabelVal ) . toEqual ( 1001.101 ) ;
1442+ expect ( out . extraText ) . toEqual ( undefined ) ;
1443+ expect ( out . style ) . toEqual ( [ 2 , '#4499FF' , 2 , 1001.101 ] ) ;
1444+ } )
1445+ . then ( function ( ) {
1446+ var out = _hover ( gd , 3 , 1000.5 , 'closest' ) ;
1447+ expect ( out . yLabelVal ) . toEqual ( 1004.401 ) ;
1448+ expect ( out . extraText ) . toEqual ( '$3.3m ▲<br>Initial: $1,001.101m' ) ;
1449+ expect ( out . style ) . toEqual ( [ 3 , '#3D9970' , 3 , 1004.401 ] ) ;
1450+ } )
1451+ . then ( function ( ) {
1452+ var out = _hover ( gd , 4 , 1000.5 , 'closest' ) ;
1453+ expect ( out . yLabelVal ) . toEqual ( 1004.401 ) ;
1454+ expect ( out . extraText ) . toEqual ( undefined ) ;
1455+ expect ( out . style ) . toEqual ( [ 4 , '#4499FF' , 4 , 1004.401 ] ) ;
1456+ } )
1457+ . catch ( failTest )
1458+ . then ( done ) ;
14001459 } ) ;
14011460 } ) ;
14021461
0 commit comments