@@ -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,81 @@ 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
+ var el = d3 . select ( 'g.legend' ) . node ( ) ;
1052
+ var opts = { element : el } ;
1053
+ mouseEvent ( 'mousedown' , p [ 0 ] , p [ 1 ] , opts ) ;
1054
+ mouseEvent ( 'mouseup' , p [ 0 ] , p [ 1 ] , opts ) ;
1055
+ setTimeout ( resolve , DBLCLICKDELAY + 20 ) ;
1056
+ } ) ;
1057
+ } ;
1058
+ }
1059
+
1060
+ function assertVisible ( expectation ) {
1061
+ return function ( ) {
1062
+ var actual = gd . _fullData . map ( function ( t ) { return t . visible ; } ) ;
1063
+ expect ( actual ) . toEqual ( expectation ) ;
1064
+ } ;
1065
+ }
1066
+
1067
+ var specs = [ {
1068
+ orientation : 'h' ,
1069
+ edits : { legendPosition : true } ,
1070
+ clickPos : [ [ 118 , 469 ] , [ 212 , 469 ] , [ 295 , 469 ] ]
1071
+ } , {
1072
+ orientation : 'h' ,
1073
+ edits : { legendPosition : true , legendText : true } ,
1074
+ clickPos : [ [ 118 , 469 ] , [ 212 , 469 ] , [ 295 , 469 ] ]
1075
+ } , {
1076
+ orientation : 'v' ,
1077
+ edits : { legendPosition : true } ,
1078
+ clickPos : [ [ 430 , 114 ] , [ 430 , 131 ] , [ 430 , 153 ] ]
1079
+ } , {
1080
+ orientation : 'v' ,
1081
+ edits : { legendPosition : true , legendText : true } ,
1082
+ clickPos : [ [ 430 , 114 ] , [ 430 , 131 ] , [ 430 , 153 ] ]
1083
+ } ] ;
1084
+
1085
+ specs . forEach ( function ( s ) {
1086
+ var msg = s . orientation + ' - ' + JSON . stringify ( s . edits ) ;
1087
+
1088
+ it ( 'should find correct bounding box (case ' + msg + ')' , function ( done ) {
1089
+ Plotly . plot ( gd ,
1090
+ Lib . extendDeep ( [ ] , data ) ,
1091
+ { legend : { orientation : s . orientation } , width : 500 , height : 500 } ,
1092
+ { edits : s . edits }
1093
+ )
1094
+ . then ( assertVisible ( [ true , true , true ] ) )
1095
+ . then ( clickAt ( s . clickPos [ 0 ] ) )
1096
+ . then ( assertVisible ( [ 'legendonly' , true , true ] ) )
1097
+ . then ( clickAt ( s . clickPos [ 1 ] ) )
1098
+ . then ( assertVisible ( [ 'legendonly' , 'legendonly' , true ] ) )
1099
+ . then ( clickAt ( s . clickPos [ 2 ] ) )
1100
+ . then ( assertVisible ( [ 'legendonly' , 'legendonly' , 'legendonly' ] ) )
1101
+ . catch ( failTest )
1102
+ . then ( done ) ;
1103
+ } ) ;
1104
+ } ) ;
1105
+ } ) ;
1106
+
1030
1107
describe ( 'legend visibility interactions' , function ( ) {
1031
1108
var gd ;
1032
1109
0 commit comments