@@ -1108,6 +1108,43 @@ describe('hover info on stacked subplots', function() {
11081108} ) ;
11091109
11101110
1111+ describe ( 'hover on many lines+bars' , function ( ) {
1112+ 'use strict' ;
1113+
1114+ afterEach ( destroyGraphDiv ) ;
1115+
1116+ it ( 'shows hover info for both traces' , function ( done ) {
1117+ // see https://github.com/plotly/plotly.js/issues/780
1118+ var values = new Array ( 1000 ) ;
1119+ var values2 = new Array ( values . length ) ;
1120+ for ( var i = 0 ; i < values . length ; i ++ ) {
1121+ values [ i ] = i ;
1122+ values2 [ i ] = i * 2 ;
1123+ }
1124+
1125+ var gd = createGraphDiv ( ) ;
1126+ Plotly . newPlot ( gd , [
1127+ { y : values2 } ,
1128+ { y : values , type : 'bar' }
1129+ ] , {
1130+ width : 400 ,
1131+ height : 400 ,
1132+ margin : { l : 100 , r : 100 , t : 100 , b : 100 }
1133+ } )
1134+ . then ( function ( ) {
1135+ Lib . clearThrottle ( ) ;
1136+ mouseEvent ( 'mousemove' , 200 , 100 ) ;
1137+ Lib . clearThrottle ( ) ;
1138+
1139+ expect ( d3 . select ( gd ) . selectAll ( 'g.hovertext' ) . size ( ) ) . toBe ( 2 ) ;
1140+ expect ( d3 . select ( gd ) . selectAll ( 'g.axistext' ) . size ( ) ) . toBe ( 1 ) ;
1141+ } )
1142+ . catch ( fail )
1143+ . then ( done ) ;
1144+ } ) ;
1145+ } ) ;
1146+
1147+
11111148describe ( 'hover info on overlaid subplots' , function ( ) {
11121149 'use strict' ;
11131150
@@ -1274,7 +1311,7 @@ describe('hover updates', function() {
12741311
12751312 afterEach ( destroyGraphDiv ) ;
12761313
1277- function assertLabelsCorrect ( mousePos , labelPos , labelText ) {
1314+ function assertLabelsCorrect ( mousePos , labelPos , labelText , msg ) {
12781315 return new Promise ( function ( resolve ) {
12791316 if ( mousePos ) {
12801317 mouseEvent ( 'mousemove' , mousePos [ 0 ] , mousePos [ 1 ] ) ;
@@ -1283,14 +1320,14 @@ describe('hover updates', function() {
12831320 setTimeout ( function ( ) {
12841321 var hoverText = d3 . selectAll ( 'g.hovertext' ) ;
12851322 if ( labelPos ) {
1286- expect ( hoverText . size ( ) ) . toEqual ( 1 ) ;
1287- expect ( hoverText . text ( ) ) . toEqual ( labelText ) ;
1323+ expect ( hoverText . size ( ) ) . toBe ( 1 , msg ) ;
1324+ expect ( hoverText . text ( ) ) . toBe ( labelText , msg ) ;
12881325
12891326 var transformParts = hoverText . attr ( 'transform' ) . split ( '(' ) ;
1290- expect ( transformParts [ 0 ] ) . toEqual ( 'translate' ) ;
1327+ expect ( transformParts [ 0 ] ) . toBe ( 'translate' , msg ) ;
12911328 var transformCoords = transformParts [ 1 ] . split ( ')' ) [ 0 ] . split ( ',' ) ;
1292- expect ( + transformCoords [ 0 ] ) . toBeCloseTo ( labelPos [ 0 ] , - 1 , labelText + ':x' ) ;
1293- expect ( + transformCoords [ 1 ] ) . toBeCloseTo ( labelPos [ 1 ] , - 1 , labelText + ':y' ) ;
1329+ expect ( + transformCoords [ 0 ] ) . toBeCloseTo ( labelPos [ 0 ] , - 1 , labelText + ':x ' + msg ) ;
1330+ expect ( + transformCoords [ 1 ] ) . toBeCloseTo ( labelPos [ 1 ] , - 1 , labelText + ':y ' + msg ) ;
12941331 } else {
12951332 expect ( hoverText . size ( ) ) . toEqual ( 0 ) ;
12961333 }
@@ -1318,7 +1355,7 @@ describe('hover updates', function() {
13181355 var gd = createGraphDiv ( ) ;
13191356 Plotly . plot ( gd , mock ) . then ( function ( ) {
13201357 // The label text gets concatenated together when queried. Such is life.
1321- return assertLabelsCorrect ( [ 100 , 100 ] , [ 103 , 100 ] , 'trace 00.5' ) ;
1358+ return assertLabelsCorrect ( [ 100 , 100 ] , [ 103 , 100 ] , 'trace 00.5' , 'animation/update 0' ) ;
13221359 } ) . then ( function ( ) {
13231360 return Plotly . animate ( gd , [ {
13241361 data : [ { x : [ 0 ] , y : [ 0 ] } , { x : [ 0.5 ] , y : [ 0.5 ] } ] ,
@@ -1327,25 +1364,25 @@ describe('hover updates', function() {
13271364 } ) . then ( function ( ) {
13281365 // No mouse event this time. Just change the data and check the label.
13291366 // Ditto on concatenation. This is "trace 1" + "0.5"
1330- return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' ) ;
1367+ return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' , 'animation/update 1' ) ;
13311368 } ) . then ( function ( ) {
13321369 // Restyle to move the point out of the window:
13331370 return Plotly . relayout ( gd , { 'xaxis.range' : [ 2 , 3 ] } ) ;
13341371 } ) . then ( function ( ) {
13351372 // Assert label removed:
1336- return assertLabelsCorrect ( null , null ) ;
1373+ return assertLabelsCorrect ( null , null , null , 'animation/update 2' ) ;
13371374 } ) . then ( function ( ) {
13381375 // Move back to the original xaxis range:
13391376 return Plotly . relayout ( gd , { 'xaxis.range' : [ 0 , 1 ] } ) ;
13401377 } ) . then ( function ( ) {
13411378 // Assert label restored:
1342- return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' ) ;
1379+ return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' , 'animation/update 3' ) ;
13431380 } ) . catch ( fail ) . then ( done ) ;
13441381 } ) ;
13451382
13461383 it ( 'should not trigger infinite loop of plotly_unhover events' , function ( done ) {
13471384 var gd = createGraphDiv ( ) ;
1348- var colors0 = [ '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' ] ;
1385+ var colors0 = [ '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' ] ;
13491386
13501387 function unhover ( ) {
13511388 return new Promise ( function ( resolve ) {
@@ -1365,7 +1402,7 @@ describe('hover updates', function() {
13651402 y : [ 1 , 2 , 3 , 2 , 3 , 4 , 3 ] ,
13661403 marker : {
13671404 size : 16 ,
1368- colors : colors0 . slice ( )
1405+ color : colors0 . slice ( )
13691406 }
13701407 } ] )
13711408 . then ( function ( ) {
@@ -1383,14 +1420,14 @@ describe('hover updates', function() {
13831420 Plotly . restyle ( gd , 'marker.color' , [ colors0 . slice ( ) ] ) ;
13841421 } ) ;
13851422
1386- return assertLabelsCorrect ( [ 351 , 251 ] , [ 358 , 272 ] , '2' ) ;
1423+ return assertLabelsCorrect ( [ 351 , 251 ] , [ 358 , 272 ] , '2' , 'events 0' ) ;
13871424 } )
13881425 . then ( unhover )
13891426 . then ( function ( ) {
13901427 expect ( hoverCnt ) . toEqual ( 1 ) ;
13911428 expect ( unHoverCnt ) . toEqual ( 1 ) ;
13921429
1393- return assertLabelsCorrect ( [ 400 , 200 ] , [ 435 , 198 ] , '3' ) ;
1430+ return assertLabelsCorrect ( [ 420 , 100 ] , [ 435 , 198 ] , '3' , 'events 1 ') ;
13941431 } )
13951432 . then ( unhover )
13961433 . then ( function ( ) {
0 commit comments