@@ -12,6 +12,7 @@ var failTest = require('../assets/fail_test');
12
12
var mouseEvent = require ( '../assets/mouse_event' ) ;
13
13
var click = require ( '../assets/click' ) ;
14
14
var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
15
+ var readPixel = require ( '../assets/read_pixel' ) ;
15
16
16
17
// mock with two dimensions (one panel); special case, e.g. left and right panel is obv. the same
17
18
var mock2 = require ( '@mocks/gl2d_parcoords_2.json' ) ;
@@ -579,11 +580,12 @@ describe('parcoords edge cases', function() {
579
580
} ) ;
580
581
581
582
describe ( 'parcoords Lifecycle methods' , function ( ) {
583
+ var gd ;
584
+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
582
585
afterEach ( purgeGraphDiv ) ;
583
586
584
587
it ( 'Plotly.deleteTraces with one trace removes the plot' , function ( done ) {
585
588
586
- var gd = createGraphDiv ( ) ;
587
589
var mockCopy = Lib . extendDeep ( { } , mock ) ;
588
590
589
591
mockCopy . data [ 0 ] . line . showscale = false ;
@@ -603,7 +605,6 @@ describe('parcoords Lifecycle methods', function() {
603
605
604
606
it ( '@gl Plotly.deleteTraces with two traces removes the deleted plot' , function ( done ) {
605
607
606
- var gd = createGraphDiv ( ) ;
607
608
var mockCopy = Lib . extendDeep ( { } , mock ) ;
608
609
var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
609
610
mockCopy2 . data [ 0 ] . dimensions . splice ( 3 , 4 ) ;
@@ -635,11 +636,25 @@ describe('parcoords Lifecycle methods', function() {
635
636
. then ( done ) ;
636
637
} ) ;
637
638
639
+ function _assertVisibleData ( visible , msg ) {
640
+ return function ( ) {
641
+ var canvases = d3 . selectAll ( '.gl-canvas' ) ;
642
+ expect ( canvases . size ( ) ) . toBe ( 3 , msg ) ;
643
+ canvases . each ( function ( ) {
644
+ var imageArray = readPixel ( this , 0 , 0 , this . width , this . height ) ;
645
+ var foundPixel = false ;
646
+ var i = 0 ;
647
+ do {
648
+ foundPixel = foundPixel || imageArray [ i ++ ] !== 0 ;
649
+ } while ( ! foundPixel && i < imageArray . length ) ;
650
+ expect ( foundPixel ) . toBe ( visible , msg + ' - ' + this . className ) ;
651
+ } ) ;
652
+ } ;
653
+ }
654
+
638
655
it ( '@gl Calling `Plotly.restyle` with zero panels left should erase lines' , function ( done ) {
639
656
640
657
var mockCopy = Lib . extendDeep ( { } , mock2 ) ;
641
- var gd = createGraphDiv ( ) ;
642
- Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) ;
643
658
644
659
function restyleDimension ( key , dimIndex , setterValue ) {
645
660
var value = Array . isArray ( setterValue ) ? setterValue [ 0 ] : setterValue ;
@@ -650,27 +665,31 @@ describe('parcoords Lifecycle methods', function() {
650
665
} ;
651
666
}
652
667
653
- restyleDimension ( 'values' , 1 , [ [ ] ] ) ( )
654
- . then ( function ( ) {
655
- d3 . selectAll ( '.parcoords-lines' ) . each ( function ( d ) {
656
- var imageArray = d . lineLayer . readPixels ( 0 , 0 , d . model . canvasWidth , d . model . canvasHeight ) ;
657
- var foundPixel = false ;
658
- var i = 0 ;
659
- do {
660
- foundPixel = foundPixel || imageArray [ i ++ ] !== 0 ;
661
- } while ( ! foundPixel && i < imageArray . length ) ;
662
- expect ( foundPixel ) . toEqual ( false ) ;
663
- } ) ;
664
- } )
665
- . catch ( failTest )
666
- . then ( done ) ;
668
+ Plotly . plot ( gd , mockCopy )
669
+ . then ( _assertVisibleData ( true , 'initial' ) )
670
+ . then ( restyleDimension ( 'values' , 1 , [ [ ] ] ) )
671
+ . then ( _assertVisibleData ( false , 'no panels' ) )
672
+ . catch ( failTest )
673
+ . then ( done ) ;
674
+ } ) ;
675
+
676
+ it ( '@gl displays focused and context data after relayout' , function ( done ) {
677
+ var mockCopy = Lib . extendDeep ( { } , mock2 ) ;
678
+
679
+ Plotly . plot ( gd , mockCopy )
680
+ . then ( _assertVisibleData ( true , 'initial' ) )
681
+ . then ( function ( ) {
682
+ return Plotly . relayout ( gd , 'paper_bgcolor' , '#eef' ) ;
683
+ } )
684
+ . then ( _assertVisibleData ( true , 'after relayout' ) )
685
+ . catch ( failTest )
686
+ . then ( done ) ;
667
687
} ) ;
668
688
669
689
describe ( 'Having two datasets' , function ( ) {
670
690
671
691
it ( '@gl Two subsequent calls to Plotly.plot should create two parcoords rows' , function ( done ) {
672
692
673
- var gd = createGraphDiv ( ) ;
674
693
var mockCopy = Lib . extendDeep ( { } , mock ) ;
675
694
var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
676
695
mockCopy . data [ 0 ] . domain = { x : [ 0 , 0.45 ] } ;
@@ -700,7 +719,6 @@ describe('parcoords Lifecycle methods', function() {
700
719
701
720
it ( '@gl Plotly.addTraces should add a new parcoords row' , function ( done ) {
702
721
703
- var gd = createGraphDiv ( ) ;
704
722
var mockCopy = Lib . extendDeep ( { } , mock ) ;
705
723
var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
706
724
mockCopy . data [ 0 ] . domain = { y : [ 0 , 0.35 ] } ;
@@ -727,7 +745,6 @@ describe('parcoords Lifecycle methods', function() {
727
745
728
746
it ( '@gl Plotly.restyle should update the existing parcoords row' , function ( done ) {
729
747
730
- var gd = createGraphDiv ( ) ;
731
748
var mockCopy = Lib . extendDeep ( { } , mock ) ;
732
749
var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
733
750
0 commit comments