@@ -723,6 +723,131 @@ describe('@flaky Test select box and lasso in general:', function() {
723723 . catch ( failTest )
724724 . then ( done ) ;
725725 } ) ;
726+
727+ it ( 'should remember selection polygons from previous select/lasso mode' , function ( done ) {
728+ var gd = createGraphDiv ( ) ;
729+ var path1 = [ [ 150 , 150 ] , [ 170 , 170 ] ] ;
730+ var path2 = [ [ 193 , 193 ] , [ 213 , 193 ] ] ;
731+
732+ var fig = Lib . extendDeep ( { } , mock ) ;
733+ fig . layout . margin = { l : 0 , t : 0 , r : 0 , b : 0 } ;
734+ fig . layout . width = 500 ;
735+ fig . layout . height = 500 ;
736+ fig . layout . dragmode = 'select' ;
737+
738+ // d attr to array of segment [x,y]
739+ function outline2coords ( outline ) {
740+ if ( ! outline . size ( ) ) return [ [ ] ] ;
741+
742+ return outline . attr ( 'd' )
743+ . replace ( / Z / g, '' )
744+ . split ( 'M' )
745+ . filter ( Boolean )
746+ . map ( function ( s ) {
747+ return s . split ( 'L' )
748+ . map ( function ( s ) { return s . split ( ',' ) . map ( Number ) ; } ) ;
749+ } )
750+ . reduce ( function ( a , b ) { return a . concat ( b ) ; } ) ;
751+ }
752+
753+ function _assert ( msg , exp ) {
754+ var outline = d3 . select ( gd ) . select ( '.zoomlayer' ) . select ( '.select-outline-1' ) ;
755+
756+ if ( exp . outline ) {
757+ expect ( outline2coords ( outline ) ) . toBeCloseTo2DArray ( exp . outline , 2 , msg ) ;
758+ } else {
759+ assertSelectionNodes ( 0 , 0 , msg ) ;
760+ }
761+ }
762+
763+ function _drag ( path , opts ) {
764+ return function ( ) {
765+ resetEvents ( gd ) ;
766+ drag ( path , opts ) ;
767+ return selectedPromise ;
768+ } ;
769+ }
770+
771+ Plotly . plot ( gd , fig )
772+ . then ( function ( ) { _assert ( 'base' , { outline : false } ) ; } )
773+ . then ( _drag ( path1 ) )
774+ . then ( function ( ) {
775+ _assert ( 'select path1' , {
776+ outline : [ [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] ]
777+ } ) ;
778+ } )
779+ . then ( _drag ( path2 ) )
780+ . then ( function ( ) {
781+ _assert ( 'select path2' , {
782+ outline : [ [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] ]
783+ } ) ;
784+ } )
785+ . then ( _drag ( path1 ) )
786+ . then ( _drag ( path2 , { shiftKey : true } ) )
787+ . then ( function ( ) {
788+ _assert ( 'select path1+path2' , {
789+ outline : [
790+ [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] ,
791+ [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ]
792+ ]
793+ } ) ;
794+ } )
795+ . then ( function ( ) {
796+ return Plotly . relayout ( gd , 'dragmode' , 'lasso' ) ;
797+ } )
798+ . then ( function ( ) {
799+ // N.B. all relayout calls clear the selection outline at the moment,
800+ // perhaps we could make an exception for select <-> lasso ?
801+ _assert ( 'after relayout -> lasso' , { outline : false } ) ;
802+ } )
803+ . then ( _drag ( lassoPath , { shiftKey : true } ) )
804+ . then ( function ( ) {
805+ // merged with previous 'select' polygon
806+ _assert ( 'after shift lasso' , {
807+ outline : [
808+ [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] ,
809+ [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ] ,
810+ [ 335 , 243 ] , [ 328 , 169 ] , [ 316 , 171 ] , [ 318 , 239 ] , [ 335 , 243 ]
811+ ]
812+ } ) ;
813+ } )
814+ . then ( _drag ( lassoPath ) )
815+ . then ( function ( ) {
816+ _assert ( 'after lasso (no-shift)' , {
817+ outline : [ [ 316 , 171 ] , [ 318 , 239 ] , [ 335 , 243 ] , [ 328 , 169 ] , [ 316 , 171 ] ]
818+ } ) ;
819+ } )
820+ . then ( function ( ) {
821+ return Plotly . relayout ( gd , 'dragmode' , 'pan' ) ;
822+ } )
823+ . then ( function ( ) {
824+ _assert ( 'after relayout -> pan' , { outline : false } ) ;
825+ drag ( path2 ) ;
826+ _assert ( 'after pan' , { outline : false } ) ;
827+ return Plotly . relayout ( gd , 'dragmode' , 'select' ) ;
828+ } )
829+ . then ( function ( ) {
830+ _assert ( 'after relayout back to select' , { outline : false } ) ;
831+ } )
832+ . then ( _drag ( path1 , { shiftKey : true } ) )
833+ . then ( function ( ) {
834+ // this used to merged 'lasso' polygons before (see #2669)
835+ _assert ( 'shift select path1 after pan' , {
836+ outline : [ [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] ]
837+ } ) ;
838+ } )
839+ . then ( _drag ( path2 , { shiftKey : true } ) )
840+ . then ( function ( ) {
841+ _assert ( 'shift select path1+path2 after pan' , {
842+ outline : [
843+ [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] ,
844+ [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ]
845+ ]
846+ } ) ;
847+ } )
848+ . catch ( failTest )
849+ . then ( done ) ;
850+ } ) ;
726851} ) ;
727852
728853describe ( '@flaky Test select box and lasso per trace:' , function ( ) {
0 commit comments