@@ -1108,6 +1108,43 @@ describe('hover info on stacked subplots', function() {
1108
1108
} ) ;
1109
1109
1110
1110
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
+
1111
1148
describe ( 'hover info on overlaid subplots' , function ( ) {
1112
1149
'use strict' ;
1113
1150
@@ -1274,7 +1311,7 @@ describe('hover updates', function() {
1274
1311
1275
1312
afterEach ( destroyGraphDiv ) ;
1276
1313
1277
- function assertLabelsCorrect ( mousePos , labelPos , labelText ) {
1314
+ function assertLabelsCorrect ( mousePos , labelPos , labelText , msg ) {
1278
1315
return new Promise ( function ( resolve ) {
1279
1316
if ( mousePos ) {
1280
1317
mouseEvent ( 'mousemove' , mousePos [ 0 ] , mousePos [ 1 ] ) ;
@@ -1283,14 +1320,14 @@ describe('hover updates', function() {
1283
1320
setTimeout ( function ( ) {
1284
1321
var hoverText = d3 . selectAll ( 'g.hovertext' ) ;
1285
1322
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 ) ;
1288
1325
1289
1326
var transformParts = hoverText . attr ( 'transform' ) . split ( '(' ) ;
1290
- expect ( transformParts [ 0 ] ) . toEqual ( 'translate' ) ;
1327
+ expect ( transformParts [ 0 ] ) . toBe ( 'translate' , msg ) ;
1291
1328
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 ) ;
1294
1331
} else {
1295
1332
expect ( hoverText . size ( ) ) . toEqual ( 0 ) ;
1296
1333
}
@@ -1318,7 +1355,7 @@ describe('hover updates', function() {
1318
1355
var gd = createGraphDiv ( ) ;
1319
1356
Plotly . plot ( gd , mock ) . then ( function ( ) {
1320
1357
// 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' ) ;
1322
1359
} ) . then ( function ( ) {
1323
1360
return Plotly . animate ( gd , [ {
1324
1361
data : [ { x : [ 0 ] , y : [ 0 ] } , { x : [ 0.5 ] , y : [ 0.5 ] } ] ,
@@ -1327,25 +1364,25 @@ describe('hover updates', function() {
1327
1364
} ) . then ( function ( ) {
1328
1365
// No mouse event this time. Just change the data and check the label.
1329
1366
// 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' ) ;
1331
1368
} ) . then ( function ( ) {
1332
1369
// Restyle to move the point out of the window:
1333
1370
return Plotly . relayout ( gd , { 'xaxis.range' : [ 2 , 3 ] } ) ;
1334
1371
} ) . then ( function ( ) {
1335
1372
// Assert label removed:
1336
- return assertLabelsCorrect ( null , null ) ;
1373
+ return assertLabelsCorrect ( null , null , null , 'animation/update 2' ) ;
1337
1374
} ) . then ( function ( ) {
1338
1375
// Move back to the original xaxis range:
1339
1376
return Plotly . relayout ( gd , { 'xaxis.range' : [ 0 , 1 ] } ) ;
1340
1377
} ) . then ( function ( ) {
1341
1378
// Assert label restored:
1342
- return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' ) ;
1379
+ return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' , 'animation/update 3' ) ;
1343
1380
} ) . catch ( fail ) . then ( done ) ;
1344
1381
} ) ;
1345
1382
1346
1383
it ( 'should not trigger infinite loop of plotly_unhover events' , function ( done ) {
1347
1384
var gd = createGraphDiv ( ) ;
1348
- var colors0 = [ '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' , '#00000 ' ] ;
1385
+ var colors0 = [ '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' , '#000000 ' ] ;
1349
1386
1350
1387
function unhover ( ) {
1351
1388
return new Promise ( function ( resolve ) {
@@ -1365,7 +1402,7 @@ describe('hover updates', function() {
1365
1402
y : [ 1 , 2 , 3 , 2 , 3 , 4 , 3 ] ,
1366
1403
marker : {
1367
1404
size : 16 ,
1368
- colors : colors0 . slice ( )
1405
+ color : colors0 . slice ( )
1369
1406
}
1370
1407
} ] )
1371
1408
. then ( function ( ) {
@@ -1383,14 +1420,14 @@ describe('hover updates', function() {
1383
1420
Plotly . restyle ( gd , 'marker.color' , [ colors0 . slice ( ) ] ) ;
1384
1421
} ) ;
1385
1422
1386
- return assertLabelsCorrect ( [ 351 , 251 ] , [ 358 , 272 ] , '2' ) ;
1423
+ return assertLabelsCorrect ( [ 351 , 251 ] , [ 358 , 272 ] , '2' , 'events 0' ) ;
1387
1424
} )
1388
1425
. then ( unhover )
1389
1426
. then ( function ( ) {
1390
1427
expect ( hoverCnt ) . toEqual ( 1 ) ;
1391
1428
expect ( unHoverCnt ) . toEqual ( 1 ) ;
1392
1429
1393
- return assertLabelsCorrect ( [ 400 , 200 ] , [ 435 , 198 ] , '3' ) ;
1430
+ return assertLabelsCorrect ( [ 420 , 100 ] , [ 435 , 198 ] , '3' , 'events 1 ') ;
1394
1431
} )
1395
1432
. then ( unhover )
1396
1433
. then ( function ( ) {
0 commit comments