@@ -12,6 +12,7 @@ var failTest = require('../assets/fail_test');
1212var mouseEvent = require ( '../assets/mouse_event' ) ;
1313var click = require ( '../assets/click' ) ;
1414var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
15+ var readPixel = require ( '../assets/read_pixel' ) ;
1516
1617// mock with two dimensions (one panel); special case, e.g. left and right panel is obv. the same
1718var mock2 = require ( '@mocks/gl2d_parcoords_2.json' ) ;
@@ -579,11 +580,12 @@ describe('parcoords edge cases', function() {
579580} ) ;
580581
581582describe ( 'parcoords Lifecycle methods' , function ( ) {
583+ var gd ;
584+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
582585 afterEach ( purgeGraphDiv ) ;
583586
584587 it ( 'Plotly.deleteTraces with one trace removes the plot' , function ( done ) {
585588
586- var gd = createGraphDiv ( ) ;
587589 var mockCopy = Lib . extendDeep ( { } , mock ) ;
588590
589591 mockCopy . data [ 0 ] . line . showscale = false ;
@@ -603,7 +605,6 @@ describe('parcoords Lifecycle methods', function() {
603605
604606 it ( '@gl Plotly.deleteTraces with two traces removes the deleted plot' , function ( done ) {
605607
606- var gd = createGraphDiv ( ) ;
607608 var mockCopy = Lib . extendDeep ( { } , mock ) ;
608609 var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
609610 mockCopy2 . data [ 0 ] . dimensions . splice ( 3 , 4 ) ;
@@ -635,11 +636,25 @@ describe('parcoords Lifecycle methods', function() {
635636 . then ( done ) ;
636637 } ) ;
637638
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+
638655 it ( '@gl Calling `Plotly.restyle` with zero panels left should erase lines' , function ( done ) {
639656
640657 var mockCopy = Lib . extendDeep ( { } , mock2 ) ;
641- var gd = createGraphDiv ( ) ;
642- Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) ;
643658
644659 function restyleDimension ( key , dimIndex , setterValue ) {
645660 var value = Array . isArray ( setterValue ) ? setterValue [ 0 ] : setterValue ;
@@ -650,27 +665,31 @@ describe('parcoords Lifecycle methods', function() {
650665 } ;
651666 }
652667
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 ) ;
667687 } ) ;
668688
669689 describe ( 'Having two datasets' , function ( ) {
670690
671691 it ( '@gl Two subsequent calls to Plotly.plot should create two parcoords rows' , function ( done ) {
672692
673- var gd = createGraphDiv ( ) ;
674693 var mockCopy = Lib . extendDeep ( { } , mock ) ;
675694 var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
676695 mockCopy . data [ 0 ] . domain = { x : [ 0 , 0.45 ] } ;
@@ -700,7 +719,6 @@ describe('parcoords Lifecycle methods', function() {
700719
701720 it ( '@gl Plotly.addTraces should add a new parcoords row' , function ( done ) {
702721
703- var gd = createGraphDiv ( ) ;
704722 var mockCopy = Lib . extendDeep ( { } , mock ) ;
705723 var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
706724 mockCopy . data [ 0 ] . domain = { y : [ 0 , 0.35 ] } ;
@@ -727,7 +745,6 @@ describe('parcoords Lifecycle methods', function() {
727745
728746 it ( '@gl Plotly.restyle should update the existing parcoords row' , function ( done ) {
729747
730- var gd = createGraphDiv ( ) ;
731748 var mockCopy = Lib . extendDeep ( { } , mock ) ;
732749 var mockCopy2 = Lib . extendDeep ( { } , mock ) ;
733750
0 commit comments