@@ -330,11 +330,14 @@ describe('sankey tests', function() {
330
330
} ) ;
331
331
332
332
describe ( 'lifecycle methods' , function ( ) {
333
+ var gd ;
334
+ beforeEach ( function ( ) {
335
+ gd = createGraphDiv ( ) ;
336
+ } ) ;
333
337
afterEach ( destroyGraphDiv ) ;
334
338
335
339
it ( 'Plotly.deleteTraces with two traces removes the deleted plot' , function ( done ) {
336
340
337
- var gd = createGraphDiv ( ) ;
338
341
var mockCopy = Lib . extendDeep ( { } , mock ) ;
339
342
var mockCopy2 = Lib . extendDeep ( { } , mockDark ) ;
340
343
@@ -363,7 +366,6 @@ describe('sankey tests', function() {
363
366
364
367
it ( 'Plotly.plot does not show Sankey if \'visible\' is false' , function ( done ) {
365
368
366
- var gd = createGraphDiv ( ) ;
367
369
var mockCopy = Lib . extendDeep ( { } , mock ) ;
368
370
369
371
Plotly . plot ( gd , mockCopy )
@@ -386,7 +388,6 @@ describe('sankey tests', function() {
386
388
387
389
it ( '\'node\' remains visible even if \'value\' is very low' , function ( done ) {
388
390
389
- var gd = createGraphDiv ( ) ;
390
391
var minimock = [ {
391
392
type : 'sankey' ,
392
393
node : {
@@ -408,7 +409,6 @@ describe('sankey tests', function() {
408
409
} ) ;
409
410
410
411
it ( 'switch from normal to circular Sankey on react' , function ( done ) {
411
- var gd = createGraphDiv ( ) ;
412
412
var mockCopy = Lib . extendDeep ( { } , mock ) ;
413
413
var mockCircularCopy = Lib . extendDeep ( { } , mockCircular ) ;
414
414
@@ -424,7 +424,6 @@ describe('sankey tests', function() {
424
424
} ) ;
425
425
426
426
it ( 'switch from circular to normal Sankey on react' , function ( done ) {
427
- var gd = createGraphDiv ( ) ;
428
427
var mockCircularCopy = Lib . extendDeep ( { } , mockCircular ) ;
429
428
430
429
Plotly . plot ( gd , mockCircularCopy )
@@ -448,20 +447,43 @@ describe('sankey tests', function() {
448
447
} ) ;
449
448
} ) ;
450
449
451
- it ( 'can create groups' , function ( done ) {
452
- var gd = createGraphDiv ( ) ;
450
+ it ( 'can create groups, restyle groups and properly update DOM' , function ( done ) {
453
451
var mockCircularCopy = Lib . extendDeep ( { } , mockCircular ) ;
454
- mockCircularCopy . data [ 0 ] . node . groups = [ [ 2 , 3 ] , [ 0 , 1 ] ] ;
452
+ var firstGroup = [ [ 2 , 3 ] , [ 0 , 1 ] ] ;
453
+ var newGroup = [ [ 2 , 3 ] ] ;
454
+ mockCircularCopy . data [ 0 ] . node . groups = firstGroup ;
455
+
455
456
Plotly . plot ( gd , mockCircularCopy )
456
457
. then ( function ( ) {
457
- expect ( gd . _fullData [ 0 ] . node . groups ) . toEqual ( [ [ 2 , 3 ] , [ 0 , 1 ] ] ) ;
458
- return Plotly . restyle ( gd , { 'node.groups' : [ [ [ 3 , 4 ] ] ] } ) ;
458
+ expect ( gd . _fullData [ 0 ] . node . groups ) . toEqual ( firstGroup ) ;
459
+ return Plotly . restyle ( gd , { 'node.groups' : [ newGroup ] } ) ;
459
460
} )
460
461
. then ( function ( ) {
461
- expect ( gd . _fullData [ 0 ] . node . groups ) . toEqual ( [ [ 3 , 4 ] ] ) ;
462
- destroyGraphDiv ( ) ;
463
- done ( ) ;
464
- } ) ;
462
+ expect ( gd . _fullData [ 0 ] . node . groups ) . toEqual ( newGroup ) ;
463
+
464
+ // Check that all links have updated their links
465
+ d3 . selectAll ( '.sankey .sankey-link' ) . each ( function ( d , i ) {
466
+ var path = this . getAttribute ( 'd' ) ;
467
+ expect ( path ) . toBe ( d . linkPath ( ) ( d ) , 'link ' + i + ' has wrong `d` attribute' ) ;
468
+ } ) ;
469
+
470
+ // Check that ghost nodes used for animations:
471
+ // 1) are drawn first so they apear behind
472
+ var seeRealNode = false ;
473
+ var sankeyNodes = d3 . selectAll ( '.sankey .sankey-node' ) ;
474
+ sankeyNodes . each ( function ( d , i ) {
475
+ if ( d . partOfGroup ) {
476
+ if ( seeRealNode ) fail ( 'node ' + i + ' is a ghost node and should be behind' ) ;
477
+ } else {
478
+ seeRealNode = true ;
479
+ }
480
+ } ) ;
481
+ // 2) have an element for each grouped node
482
+ var L = sankeyNodes . filter ( function ( d ) { return d . partOfGroup ; } ) . size ( ) ;
483
+ expect ( L ) . toBe ( newGroup . flat ( ) . length , 'does not have the right number of ghost nodes' ) ;
484
+ } )
485
+ . catch ( failTest )
486
+ . then ( done ) ;
465
487
} ) ;
466
488
} ) ;
467
489
0 commit comments