@@ -10,6 +10,7 @@ var anchorUtils = require('@src/components/legend/anchor_utils');
1010
1111var d3 = require ( 'd3' ) ;
1212var failTest = require ( '../assets/fail_test' ) ;
13+ var mouseEvent = require ( '../assets/mouse_event' ) ;
1314var delay = require ( '../assets/delay' ) ;
1415var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1516var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -929,6 +930,7 @@ describe('legend interaction', function() {
929930
930931 describe ( 'editable mode interactions' , function ( ) {
931932 var gd ;
933+
932934 var mock = {
933935 data : [ {
934936 x : [ 1 , 2 , 3 ] ,
@@ -1027,6 +1029,79 @@ describe('legend interaction', function() {
10271029 } ) ;
10281030 } ) ;
10291031
1032+ describe ( 'visible toggle' , function ( ) {
1033+ var gd ;
1034+
1035+ beforeEach ( function ( ) {
1036+ gd = createGraphDiv ( ) ;
1037+ } ) ;
1038+
1039+ afterEach ( destroyGraphDiv ) ;
1040+
1041+ var data = [
1042+ { y : [ 1 , 2 , 1 ] } ,
1043+ { y : [ 2 , 1 , 2 ] } ,
1044+ { y : [ 2 , 3 , 4 ] }
1045+ ] ;
1046+
1047+ // we need to click on the drag cover to truly test this,
1048+ function clickAt ( p ) {
1049+ return function ( ) {
1050+ return new Promise ( function ( resolve ) {
1051+ mouseEvent ( 'mousedown' , p [ 0 ] , p [ 1 ] ) ;
1052+ mouseEvent ( 'mouseup' , p [ 0 ] , p [ 1 ] ) ;
1053+ setTimeout ( resolve , DBLCLICKDELAY + 20 ) ;
1054+ } ) ;
1055+ } ;
1056+ }
1057+
1058+ function assertVisible ( expectation ) {
1059+ return function ( ) {
1060+ var actual = gd . _fullData . map ( function ( t ) { return t . visible ; } ) ;
1061+ expect ( actual ) . toEqual ( expectation ) ;
1062+ } ;
1063+ }
1064+
1065+ var specs = [ {
1066+ orientation : 'h' ,
1067+ edits : { legendPosition : true } ,
1068+ clickPos : [ [ 118 , 469 ] , [ 212 , 469 ] , [ 295 , 469 ] ]
1069+ } , {
1070+ orientation : 'h' ,
1071+ edits : { legendPosition : true , legendText : true } ,
1072+ clickPos : [ [ 118 , 469 ] , [ 212 , 469 ] , [ 295 , 469 ] ]
1073+ } , {
1074+ orientation : 'v' ,
1075+ edits : { legendPosition : true } ,
1076+ clickPos : [ [ 430 , 114 ] , [ 430 , 131 ] , [ 430 , 153 ] ]
1077+ } , {
1078+ orientation : 'v' ,
1079+ edits : { legendPosition : true , legendText : true } ,
1080+ clickPos : [ [ 430 , 114 ] , [ 430 , 131 ] , [ 430 , 153 ] ]
1081+ } ] ;
1082+
1083+ specs . forEach ( function ( s ) {
1084+ var msg = s . orientation + ' - ' + JSON . stringify ( s . edits ) ;
1085+
1086+ it ( 'should find correct bounding box (case ' + msg + ')' , function ( done ) {
1087+ Plotly . plot ( gd ,
1088+ Lib . extendDeep ( [ ] , data ) ,
1089+ { legend : { orientation : s . orientation } , width : 500 , height : 500 } ,
1090+ { edits : s . edits }
1091+ )
1092+ . then ( assertVisible ( [ true , true , true ] ) )
1093+ . then ( clickAt ( s . clickPos [ 0 ] ) )
1094+ . then ( assertVisible ( [ 'legendonly' , true , true ] ) )
1095+ . then ( clickAt ( s . clickPos [ 1 ] ) )
1096+ . then ( assertVisible ( [ 'legendonly' , 'legendonly' , true ] ) )
1097+ . then ( clickAt ( s . clickPos [ 2 ] ) )
1098+ . then ( assertVisible ( [ 'legendonly' , 'legendonly' , 'legendonly' ] ) )
1099+ . catch ( failTest )
1100+ . then ( done ) ;
1101+ } ) ;
1102+ } ) ;
1103+ } ) ;
1104+
10301105 describe ( 'legend visibility interactions' , function ( ) {
10311106 var gd ;
10321107
0 commit comments