@@ -9,6 +9,7 @@ var Sankey = require('@src/traces/sankey');
9
9
10
10
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
11
11
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
12
+ var fail = require ( '../assets/fail_test' ) ;
12
13
var mouseEvent = require ( '../assets/mouse_event' ) ;
13
14
14
15
describe ( 'sankey tests' , function ( ) {
@@ -257,15 +258,8 @@ describe('sankey tests', function() {
257
258
} ) ;
258
259
259
260
describe ( 'lifecycle methods' , function ( ) {
260
-
261
261
afterEach ( destroyGraphDiv ) ;
262
262
263
- function wait ( ) {
264
- return new Promise ( function ( resolve ) {
265
- setTimeout ( resolve , 60 ) ;
266
- } ) ;
267
- }
268
-
269
263
it ( 'Plotly.deleteTraces with two traces removes the deleted plot' , function ( done ) {
270
264
271
265
var gd = createGraphDiv ( ) ;
@@ -317,24 +311,102 @@ describe('sankey tests', function() {
317
311
done ( ) ;
318
312
} ) ;
319
313
} ) ;
314
+ } ) ;
315
+
316
+ describe ( 'Test hover/click interactions:' , function ( ) {
317
+ afterEach ( destroyGraphDiv ) ;
318
+
319
+ function assertLabel ( content , style ) {
320
+ var g = d3 . selectAll ( '.hovertext' ) ;
321
+ var lines = g . selectAll ( '.nums .line' ) ;
322
+ var name = g . selectAll ( '.name' ) ;
323
+
324
+ expect ( lines . size ( ) ) . toBe ( content . length - 1 ) ;
325
+
326
+ lines . each ( function ( _ , i ) {
327
+ expect ( d3 . select ( this ) . text ( ) ) . toBe ( content [ i ] ) ;
328
+ } ) ;
329
+
330
+ expect ( name . text ( ) ) . toBe ( content [ content . length - 1 ] ) ;
331
+
332
+ var path = g . select ( 'path' ) ;
333
+ expect ( path . style ( 'fill' ) ) . toEqual ( style [ 0 ] , 'bgcolor' ) ;
334
+ expect ( path . style ( 'stroke' ) ) . toEqual ( style [ 1 ] , 'bordercolor' ) ;
335
+
336
+ var text = g . select ( 'text.nums' ) ;
337
+ expect ( parseInt ( text . style ( 'font-size' ) ) ) . toEqual ( style [ 2 ] , 'font.size' ) ;
338
+ expect ( text . style ( 'font-family' ) . split ( ',' ) [ 0 ] ) . toEqual ( style [ 3 ] , 'font.family' ) ;
339
+ expect ( text . style ( 'fill' ) ) . toEqual ( style [ 4 ] , 'font.color' ) ;
340
+ }
320
341
321
- it ( 'Plotly.plot shows and removes tooltip on node, link ' , function ( done ) {
342
+ it ( 'should shows the correct hover labels ' , function ( done ) {
322
343
var gd = createGraphDiv ( ) ;
323
344
var mockCopy = Lib . extendDeep ( { } , mock ) ;
324
345
346
+ function _hover ( px , py ) {
347
+ mouseEvent ( 'mousemove' , px , py ) ;
348
+ mouseEvent ( 'mouseover' , px , py ) ;
349
+ delete gd . _lastHoverTime ;
350
+ }
351
+
325
352
Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
326
- mouseEvent ( 'mousemove' , 400 , 300 ) ;
327
- mouseEvent ( 'mouseover' , 400 , 300 ) ;
353
+ _hover ( 400 , 300 ) ;
354
+
355
+ assertLabel (
356
+ [ 'Solid' , 'Incoming flow count: 4' , 'Outgoing flow count: 3' , '447TWh' ] ,
357
+ [ 'rgb(148, 103, 189)' , 'rgb(255, 255, 255)' , 13 , 'Arial' , 'rgb(255, 255, 255)' ]
358
+ ) ;
359
+ } )
360
+ . then ( function ( ) {
361
+ _hover ( 450 , 300 ) ;
362
+
363
+ assertLabel (
364
+ [ 'Source: Solid' , 'Target: Industry' , '46TWh' ] ,
365
+ [ 'rgb(0, 0, 96)' , 'rgb(255, 255, 255)' , 13 , 'Arial' , 'rgb(255, 255, 255)' ]
366
+ ) ;
367
+
368
+ return Plotly . relayout ( gd , 'hoverlabel.font.family' , 'Roboto' ) ;
369
+ } )
370
+ . then ( function ( ) {
371
+ _hover ( 400 , 300 ) ;
372
+
373
+ assertLabel (
374
+ [ 'Solid' , 'Incoming flow count: 4' , 'Outgoing flow count: 3' , '447TWh' ] ,
375
+ [ 'rgb(148, 103, 189)' , 'rgb(255, 255, 255)' , 13 , 'Roboto' , 'rgb(255, 255, 255)' ]
376
+ ) ;
328
377
} )
329
- . then ( wait )
330
378
. then ( function ( ) {
331
- expect ( d3 . select ( '.hoverlayer>.hovertext>text' ) . node ( ) . innerHTML )
332
- . toEqual ( '447TWh' , 'tooltip present' ) ;
379
+ _hover ( 450 , 300 ) ;
380
+
381
+ assertLabel (
382
+ [ 'Source: Solid' , 'Target: Industry' , '46TWh' ] ,
383
+ [ 'rgb(0, 0, 96)' , 'rgb(255, 255, 255)' , 13 , 'Roboto' , 'rgb(255, 255, 255)' ]
384
+ ) ;
385
+
386
+ return Plotly . restyle ( gd , {
387
+ 'hoverlabel.bgcolor' : 'red' ,
388
+ 'hoverlabel.bordercolor' : 'blue' ,
389
+ 'hoverlabel.font.size' : 20 ,
390
+ 'hoverlabel.font.color' : 'black'
391
+ } ) ;
333
392
} )
334
393
. then ( function ( ) {
335
- mouseEvent ( 'mousemove' , 450 , 300 ) ;
336
- mouseEvent ( 'mouseover' , 450 , 300 ) ;
394
+ _hover ( 400 , 300 ) ;
395
+
396
+ assertLabel (
397
+ [ 'Solid' , 'Incoming flow count: 4' , 'Outgoing flow count: 3' , '447TWh' ] ,
398
+ [ 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' , 20 , 'Roboto' , 'rgb(0, 0, 0)' ]
399
+ ) ;
400
+ } )
401
+ . then ( function ( ) {
402
+ _hover ( 450 , 300 ) ;
403
+
404
+ assertLabel (
405
+ [ 'Source: Solid' , 'Target: Industry' , '46TWh' ] ,
406
+ [ 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' , 20 , 'Roboto' , 'rgb(0, 0, 0)' ]
407
+ ) ;
337
408
} )
409
+ . catch ( fail )
338
410
. then ( done ) ;
339
411
} ) ;
340
412
} ) ;
0 commit comments