@@ -7,6 +7,7 @@ var d3 = require('d3');
77var createGraph = require ( '../assets/create_graph_div' ) ;
88var destroyGraph = require ( '../assets/destroy_graph_div' ) ;
99var getBBox = require ( '../assets/get_bbox' ) ;
10+ var mouseEvent = require ( '../assets/mouse_event' ) ;
1011var mock = require ( '../../image/mocks/legend_scroll.json' ) ;
1112
1213describe ( 'The legend' , function ( ) {
@@ -76,18 +77,18 @@ describe('The legend', function() {
7677 } ) ;
7778
7879 it ( 'should scroll when there\'s a wheel event' , function ( ) {
79- var legend = getLegend ( ) ,
80- scrollBox = getScrollBox ( ) ,
81- legendHeight = getLegendHeight ( gd ) ,
82- scrollBoxYMax = gd . _fullLayout . legend . _height - legendHeight ,
83- scrollBarYMax = legendHeight -
84- constants . scrollBarHeight -
85- 2 * constants . scrollBarMargin ,
86- initialDataScroll = scrollBox . getAttribute ( 'data-scroll' ) ,
87- wheelDeltaY = 100 ,
88- finalDataScroll = '' + Lib . constrain ( initialDataScroll -
89- wheelDeltaY / scrollBarYMax * scrollBoxYMax ,
90- - scrollBoxYMax , 0 ) ;
80+ var legend = getLegend ( ) ;
81+ var scrollBox = getScrollBox ( ) ;
82+ var legendHeight = getLegendHeight ( gd ) ;
83+ var scrollBoxYMax = gd . _fullLayout . legend . _height - legendHeight ;
84+ var scrollBarYMax = legendHeight -
85+ constants . scrollBarHeight -
86+ 2 * constants . scrollBarMargin ;
87+ var initialDataScroll = scrollBox . getAttribute ( 'data-scroll' ) ;
88+ var wheelDeltaY = 100 ;
89+ var finalDataScroll = '' + Lib . constrain ( initialDataScroll -
90+ wheelDeltaY / scrollBarYMax * scrollBoxYMax ,
91+ - scrollBoxYMax , 0 ) ;
9192
9293 legend . dispatchEvent ( scrollTo ( wheelDeltaY ) ) ;
9394
@@ -96,6 +97,69 @@ describe('The legend', function() {
9697 'translate(0, ' + finalDataScroll + ')' ) ;
9798 } ) ;
9899
100+ function dragScroll ( element , rightClick ) {
101+ var scrollBox = getScrollBox ( ) ;
102+ var scrollBar = getScrollBar ( ) ;
103+ var legendHeight = getLegendHeight ( gd ) ;
104+ var scrollBoxYMax = gd . _fullLayout . legend . _height - legendHeight ;
105+ var scrollBarYMax = legendHeight -
106+ constants . scrollBarHeight -
107+ 2 * constants . scrollBarMargin ;
108+ var initialDataScroll = scrollBox . getAttribute ( 'data-scroll' ) ;
109+ var dy = 50 ;
110+ var finalDataScroll = '' + Lib . constrain ( initialDataScroll -
111+ dy / scrollBarYMax * scrollBoxYMax ,
112+ - scrollBoxYMax , 0 ) ;
113+
114+ var scrollBarBB = scrollBar . getBoundingClientRect ( ) ;
115+ var y0 = scrollBarBB . top + scrollBarBB . height / 2 ;
116+ var y1 = y0 + dy ;
117+
118+ var elBB = element . getBoundingClientRect ( ) ;
119+ var x = elBB . left + elBB . width / 2 ;
120+
121+ var opts = { element : element } ;
122+ if ( rightClick ) {
123+ opts . button = 2 ;
124+ opts . buttons = 2 ;
125+ }
126+
127+ mouseEvent ( 'mousedown' , x , y0 , opts ) ;
128+ mouseEvent ( 'mousemove' , x , y1 , opts ) ;
129+ mouseEvent ( 'mouseup' , x , y1 , opts ) ;
130+
131+ expect ( finalDataScroll ) . not . toBe ( initialDataScroll ) ;
132+
133+ return finalDataScroll ;
134+ }
135+
136+ it ( 'should scroll on dragging the scrollbar' , function ( ) {
137+ var finalDataScroll = dragScroll ( getScrollBar ( ) ) ;
138+ var scrollBox = getScrollBox ( ) ;
139+
140+ expect ( scrollBox . getAttribute ( 'data-scroll' ) ) . toBe ( finalDataScroll ) ;
141+ expect ( scrollBox . getAttribute ( 'transform' ) ) . toBe (
142+ 'translate(0, ' + finalDataScroll + ')' ) ;
143+ } ) ;
144+
145+ it ( 'should not scroll on dragging the scrollbox' , function ( ) {
146+ var scrollBox = getScrollBox ( ) ;
147+ var finalDataScroll = dragScroll ( scrollBox ) ;
148+
149+ expect ( scrollBox . getAttribute ( 'data-scroll' ) ) . not . toBe ( finalDataScroll ) ;
150+ expect ( scrollBox . getAttribute ( 'transform' ) ) . not . toBe (
151+ 'translate(0, ' + finalDataScroll + ')' ) ;
152+ } ) ;
153+
154+ it ( 'should not scroll on dragging the scrollbar with a right click' , function ( ) {
155+ var finalDataScroll = dragScroll ( getScrollBar ( ) , true ) ;
156+ var scrollBox = getScrollBox ( ) ;
157+
158+ expect ( scrollBox . getAttribute ( 'data-scroll' ) ) . not . toBe ( finalDataScroll ) ;
159+ expect ( scrollBox . getAttribute ( 'transform' ) ) . not . toBe (
160+ 'translate(0, ' + finalDataScroll + ')' ) ;
161+ } ) ;
162+
99163 it ( 'should keep the scrollbar position after a toggle event' , function ( done ) {
100164 var legend = getLegend ( ) ,
101165 scrollBox = getScrollBox ( ) ,
0 commit comments