@@ -9,6 +9,7 @@ var Axes = PlotlyInternal.Axes;
99
1010var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1111var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
12+ var fail = require ( '../assets/fail_test' ) ;
1213var customMatchers = require ( '../assets/custom_matchers' ) ;
1314
1415describe ( 'Bar.supplyDefaults' , function ( ) {
@@ -1197,7 +1198,8 @@ describe('bar hover', function() {
11971198
11981199 return {
11991200 style : [ pt . index , pt . color , pt . xLabelVal , pt . yLabelVal ] ,
1200- pos : [ pt . x0 , pt . x1 , pt . y0 , pt . y1 ]
1201+ pos : [ pt . x0 , pt . x1 , pt . y0 , pt . y1 ] ,
1202+ text : pt . text
12011203 } ;
12021204 }
12031205
@@ -1274,6 +1276,41 @@ describe('bar hover', function() {
12741276 } ) ;
12751277 } ) ;
12761278
1279+ describe ( 'text labels' , function ( ) {
1280+
1281+ it ( 'should show \'hovertext\' items when present, \'text\' if not' , function ( done ) {
1282+ gd = createGraphDiv ( ) ;
1283+
1284+ var mock = Lib . extendDeep ( { } , require ( '@mocks/text_chart_arrays' ) ) ;
1285+ mock . data . forEach ( function ( t ) { t . type = 'bar' ; } ) ;
1286+
1287+ Plotly . plot ( gd , mock ) . then ( function ( ) {
1288+ var out = _hover ( gd , - 0.25 , 0.5 , 'closest' ) ;
1289+ expect ( out . text ) . toEqual ( 'Hover text\nA' , 'hover text' ) ;
1290+
1291+ return Plotly . restyle ( gd , 'hovertext' , null ) ;
1292+ } )
1293+ . then ( function ( ) {
1294+ var out = _hover ( gd , - 0.25 , 0.5 , 'closest' ) ;
1295+ expect ( out . text ) . toEqual ( 'Text\nA' , 'hover text' ) ;
1296+
1297+ return Plotly . restyle ( gd , 'text' , [ 'APPLE' , 'BANANA' , 'ORANGE' ] ) ;
1298+ } )
1299+ . then ( function ( ) {
1300+ var out = _hover ( gd , - 0.25 , 0.5 , 'closest' ) ;
1301+ expect ( out . text ) . toEqual ( 'APPLE' , 'hover text' ) ;
1302+
1303+ return Plotly . restyle ( gd , 'hovertext' , [ 'apple' , 'banana' , 'orange' ] ) ;
1304+ } )
1305+ . then ( function ( ) {
1306+ var out = _hover ( gd , - 0.25 , 0.5 , 'closest' ) ;
1307+ expect ( out . text ) . toEqual ( 'apple' , 'hover text' ) ;
1308+ } )
1309+ . catch ( fail )
1310+ . then ( done ) ;
1311+ } ) ;
1312+ } ) ;
1313+
12771314} ) ;
12781315
12791316function mockBarPlot ( dataWithoutTraceType , layout ) {
0 commit comments