@@ -10,6 +10,7 @@ var anchorUtils = require('@src/components/legend/anchor_utils');
10
10
11
11
var d3 = require ( 'd3' ) ;
12
12
var failTest = require ( '../assets/fail_test' ) ;
13
+ var mouseEvent = require ( '../assets/mouse_event' ) ;
13
14
var delay = require ( '../assets/delay' ) ;
14
15
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
15
16
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -929,6 +930,7 @@ describe('legend interaction', function() {
929
930
930
931
describe ( 'editable mode interactions' , function ( ) {
931
932
var gd ;
933
+
932
934
var mock = {
933
935
data : [ {
934
936
x : [ 1 , 2 , 3 ] ,
@@ -1027,6 +1029,79 @@ describe('legend interaction', function() {
1027
1029
} ) ;
1028
1030
} ) ;
1029
1031
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
+
1030
1105
describe ( 'legend visibility interactions' , function ( ) {
1031
1106
var gd ;
1032
1107
0 commit comments