@@ -45,6 +45,23 @@ function purgeGraphDiv(done) {
45
45
return delay ( 50 ) ( ) . then ( done ) ;
46
46
}
47
47
48
+ function getAvgPixelByChannel ( id ) {
49
+ var canvas = d3 . select ( id ) . node ( ) ;
50
+
51
+ var imgData = readPixel ( canvas , 0 , 0 , canvas . width , canvas . height ) ;
52
+ var n = imgData . length * 0.25 ;
53
+ var r = 0 ;
54
+ var g = 0 ;
55
+ var b = 0 ;
56
+
57
+ for ( var i = 0 ; i < imgData . length ; i ++ ) {
58
+ r += imgData [ i ++ ] ;
59
+ g += imgData [ i ++ ] ;
60
+ b += imgData [ i ++ ] ;
61
+ }
62
+ return [ r / n , g / n , b / n ] ;
63
+ }
64
+
48
65
describe ( 'parcoords initialization tests' , function ( ) {
49
66
50
67
'use strict' ;
@@ -799,22 +816,39 @@ describe('parcoords Lifecycle methods', function() {
799
816
} ) ;
800
817
} ) ;
801
818
802
- it ( '@gl line.color `Plotly.restyle` should work' , function ( done ) {
803
- function getAvgPixelByChannel ( ) {
804
- var canvas = d3 . select ( '.gl-canvas-focus' ) . node ( ) ;
805
- var imgData = readPixel ( canvas , 0 , 0 , canvas . width , canvas . height ) ;
806
- var n = imgData . length / 4 ;
807
- var r = 0 ;
808
- var g = 0 ;
809
- var b = 0 ;
810
-
811
- for ( var i = 0 ; i < imgData . length ; i ++ ) {
812
- r += imgData [ i ++ ] ;
813
- g += imgData [ i ++ ] ;
814
- b += imgData [ i ++ ] ;
815
- }
816
- return [ r / n , g / n , b / n ] ;
817
- }
819
+ it ( '@gl line.color `Plotly.restyle` should change focus layer' , function ( done ) {
820
+ var testLayer = '.gl-canvas-focus' ;
821
+ Plotly . plot ( gd , [ {
822
+ type : 'parcoords' ,
823
+ dimensions : [ {
824
+ values : [ 1 , 2 ]
825
+ } , {
826
+ values : [ 2 , 4 ]
827
+ } ] ,
828
+ line : { color : 'blue' }
829
+ } ] , {
830
+ width : 300 ,
831
+ height : 200
832
+ } )
833
+ . then ( function ( ) {
834
+ var rgb = getAvgPixelByChannel ( testLayer ) ;
835
+ expect ( rgb [ 0 ] ) . toBe ( 0 , 'no red' ) ;
836
+ expect ( rgb [ 2 ] ) . not . toBe ( 0 , 'all blue' ) ;
837
+
838
+ return Plotly . restyle ( gd , 'line.color' , 'red' ) ;
839
+ } )
840
+ . then ( function ( ) {
841
+ var rgb = getAvgPixelByChannel ( testLayer ) ;
842
+ expect ( rgb [ 0 ] ) . not . toBe ( 0 , 'all red' ) ;
843
+ expect ( rgb [ 2 ] ) . toBe ( 0 , 'no blue' ) ;
844
+ } )
845
+ . catch ( failTest )
846
+ . then ( done ) ;
847
+ } ) ;
848
+
849
+ it ( '@gl line.color `Plotly.restyle` should not change context layer' , function ( done ) {
850
+ var testLayer = '.gl-canvas-context' ;
851
+ var old_rgb , new_rgb ;
818
852
819
853
Plotly . plot ( gd , [ {
820
854
type : 'parcoords' ,
@@ -829,16 +863,20 @@ describe('parcoords Lifecycle methods', function() {
829
863
height : 200
830
864
} )
831
865
. then ( function ( ) {
832
- var rbg = getAvgPixelByChannel ( ) ;
833
- expect ( rbg [ 0 ] ) . toBe ( 0 , 'no red' ) ;
834
- expect ( rbg [ 2 ] ) . not . toBe ( 0 , 'all blue' ) ;
866
+ var rgb = getAvgPixelByChannel ( testLayer ) ;
867
+ old_rgb = rgb [ 0 ] + rgb [ 1 ] + rgb [ 2 ] / 3.0 ;
868
+ expect ( old_rgb ) . toBeGreaterThan ( 0 , 'not all black' ) ;
869
+ expect ( old_rgb ) . toBeLessThan ( 255 , 'not all white' ) ;
835
870
836
871
return Plotly . restyle ( gd , 'line.color' , 'red' ) ;
837
872
} )
838
873
. then ( function ( ) {
839
- var rbg = getAvgPixelByChannel ( ) ;
840
- expect ( rbg [ 0 ] ) . not . toBe ( 0 , 'all red' ) ;
841
- expect ( rbg [ 2 ] ) . toBe ( 0 , 'no blue' ) ;
874
+ var rgb = getAvgPixelByChannel ( testLayer ) ;
875
+ new_rgb = rgb [ 0 ] + rgb [ 1 ] + rgb [ 2 ] / 3.0 ;
876
+ expect ( new_rgb ) . toBeGreaterThan ( 0 , 'not all black' ) ;
877
+ expect ( new_rgb ) . toBeLessThan ( 255 , 'not all white' ) ;
878
+
879
+ expect ( new_rgb ) . toBe ( old_rgb , 'no change to context' ) ;
842
880
} )
843
881
. catch ( failTest )
844
882
. then ( done ) ;
0 commit comments