@@ -17,6 +17,7 @@ var click = require('../assets/timed_click');
17
17
var hover = require ( '../assets/hover' ) ;
18
18
var delay = require ( '../assets/delay' ) ;
19
19
var mouseEvent = require ( '../assets/mouse_event' ) ;
20
+ var readPixel = require ( '../assets/read_pixel' ) ;
20
21
21
22
// contourgl is not part of the dist plotly.js bundle initially
22
23
Plotly . register ( [
@@ -901,4 +902,63 @@ describe('@noCI @gl Test gl2d lasso/select:', function() {
901
902
. catch ( failTest )
902
903
. then ( done ) ;
903
904
} ) ;
905
+
906
+ it ( 'should work after a width/height relayout' , function ( done ) {
907
+ gd = createGraphDiv ( ) ;
908
+
909
+ var w = 500 ;
910
+ var h = 500 ;
911
+ var w2 = 800 ;
912
+ var h2 = 600 ;
913
+ var pad = 20 ;
914
+
915
+ function _read ( query ) {
916
+ var canvas = gd . querySelector ( query ) ;
917
+ return readPixel ( canvas , 0 , 0 , gd . layout . width , gd . layout . height )
918
+ . reduce ( function ( acc , v ) { return acc + v ; } , 0 ) ;
919
+ }
920
+
921
+ function readContext ( ) { return _read ( '.gl-canvas-context' ) ; }
922
+
923
+ function readFocus ( ) { return _read ( '.gl-canvas-focus' ) ; }
924
+
925
+ Plotly . plot ( gd , [ {
926
+ type : 'scattergl' ,
927
+ mode : 'markers' ,
928
+ y : [ 2 , 1 , 2 ]
929
+ } ] , {
930
+ dragmode : 'select' ,
931
+ margin : { t : 0 , b : 0 , l : 0 , r : 0 } ,
932
+ width : w , height : h
933
+ } )
934
+ . then ( delay ( 100 ) )
935
+ . then ( function ( ) {
936
+ expect ( readContext ( ) ) . toBeGreaterThan ( 1e4 , 'base context' ) ;
937
+ expect ( readFocus ( ) ) . toBe ( 0 , 'base focus' ) ;
938
+ } )
939
+ . then ( function ( ) { return select ( [ [ pad , pad ] , [ w - pad , h - pad ] ] ) ; } )
940
+ . then ( function ( ) {
941
+ expect ( readContext ( ) ) . toBe ( 0 , 'select context' ) ;
942
+ expect ( readFocus ( ) ) . toBeGreaterThan ( 1e4 , 'select focus' ) ;
943
+ } )
944
+ . then ( function ( ) {
945
+ return Plotly . update ( gd ,
946
+ { selectedpoints : null } ,
947
+ { width : w2 , height : h2 }
948
+ ) ;
949
+ } )
950
+ . then ( function ( ) {
951
+ expect ( readContext ( ) ) . toBeGreaterThan ( 1e4 , 'update context' ) ;
952
+ expect ( readFocus ( ) ) . toBe ( 0 , 'update focus' ) ;
953
+ } )
954
+ . then ( function ( ) { return select ( [ [ pad , pad ] , [ w2 - pad , h2 - pad ] ] ) ; } )
955
+ . then ( function ( ) {
956
+ // make sure full w2/h2 context canvas is cleared!
957
+ // from https://github.com/plotly/plotly.js/issues/2731<Paste>
958
+ expect ( readContext ( ) ) . toBe ( 0 , 'update+select context' ) ;
959
+ expect ( readFocus ( ) ) . toBeGreaterThan ( 1e4 , 'update+select focus' ) ;
960
+ } )
961
+ . catch ( failTest )
962
+ . then ( done ) ;
963
+ } ) ;
904
964
} ) ;
0 commit comments