6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
8
9
-
10
9
'use strict' ;
11
10
12
11
var mouseOffset = require ( 'mouse-event-offset' ) ;
13
12
var hasHover = require ( 'has-hover' ) ;
14
13
var supportsPassive = require ( 'has-passive-events' ) ;
15
14
16
- var Registry = require ( '../../registry' ) ;
17
- var Lib = require ( '../../lib' ) ;
18
-
15
+ var removeElement = require ( '../../lib' ) . removeElement ;
19
16
var constants = require ( '../../plots/cartesian/constants' ) ;
20
17
var interactConstants = require ( '../../constants/interactions' ) ;
21
18
@@ -28,7 +25,6 @@ var unhover = require('./unhover');
28
25
dragElement . unhover = unhover . wrapped ;
29
26
dragElement . unhoverRaw = unhover . raw ;
30
27
31
-
32
28
/**
33
29
* Abstracts click & drag interactions
34
30
*
@@ -106,8 +102,7 @@ dragElement.init = function init(options) {
106
102
107
103
if ( ! supportsPassive ) {
108
104
element . ontouchstart = onStart ;
109
- }
110
- else {
105
+ } else {
111
106
if ( element . _ontouchstart ) {
112
107
element . removeEventListener ( 'touchstart' , element . _ontouchstart ) ;
113
108
}
@@ -145,8 +140,7 @@ dragElement.init = function init(options) {
145
140
if ( newMouseDownTime - gd . _mouseDownTime < DBLCLICKDELAY ) {
146
141
// in a click train
147
142
numClicks += 1 ;
148
- }
149
- else {
143
+ } else {
150
144
// new click train
151
145
numClicks = 1 ;
152
146
gd . _mouseDownTime = newMouseDownTime ;
@@ -157,8 +151,7 @@ dragElement.init = function init(options) {
157
151
if ( hasHover && ! rightClick ) {
158
152
dragCover = coverSlip ( ) ;
159
153
dragCover . style . cursor = window . getComputedStyle ( element ) . cursor ;
160
- }
161
- else if ( ! hasHover ) {
154
+ } else if ( ! hasHover ) {
162
155
// document acts as a dragcover for mobile, bc we can't create dragcover dynamically
163
156
dragCover = document ;
164
157
cursor = window . getComputedStyle ( document . documentElement ) . cursor ;
@@ -191,12 +184,21 @@ dragElement.init = function init(options) {
191
184
dragElement . unhover ( gd ) ;
192
185
}
193
186
194
- if ( gd . _dragged && options . moveFn && ! rightClick ) options . moveFn ( dx , dy ) ;
187
+ if ( gd . _dragged && options . moveFn && ! rightClick ) {
188
+ gd . _dragdata = {
189
+ element : element ,
190
+ dx : dx ,
191
+ dy : dy
192
+ } ;
193
+ options . moveFn ( dx , dy ) ;
194
+ }
195
195
196
196
return ;
197
197
}
198
198
199
199
function onDone ( e ) {
200
+ delete gd . _dragdata ;
201
+
200
202
if ( options . dragmode !== false ) {
201
203
e . preventDefault ( ) ;
202
204
document . removeEventListener ( 'mousemove' , onMove ) ;
@@ -207,9 +209,8 @@ dragElement.init = function init(options) {
207
209
document . removeEventListener ( 'touchend' , onDone ) ;
208
210
209
211
if ( hasHover ) {
210
- Lib . removeElement ( dragCover ) ;
211
- }
212
- else if ( cursor ) {
212
+ removeElement ( dragCover ) ;
213
+ } else if ( cursor ) {
213
214
dragCover . documentElement . style . cursor = cursor ;
214
215
cursor = null ;
215
216
}
@@ -228,8 +229,7 @@ dragElement.init = function init(options) {
228
229
229
230
if ( gd . _dragged ) {
230
231
if ( options . doneFn ) options . doneFn ( ) ;
231
- }
232
- else {
232
+ } else {
233
233
if ( options . clickFn ) options . clickFn ( numClicks , initialEvent ) ;
234
234
235
235
// If we haven't dragged, this should be a click. But because of the
@@ -258,10 +258,8 @@ dragElement.init = function init(options) {
258
258
}
259
259
}
260
260
261
- finishDrag ( gd ) ;
262
-
261
+ gd . _dragging = false ;
263
262
gd . _dragged = false ;
264
-
265
263
return ;
266
264
}
267
265
} ;
@@ -286,11 +284,6 @@ function coverSlip() {
286
284
287
285
dragElement . coverSlip = coverSlip ;
288
286
289
- function finishDrag ( gd ) {
290
- gd . _dragging = false ;
291
- if ( gd . _replotPending ) Registry . call ( 'plot' , gd ) ;
292
- }
293
-
294
287
function pointerOffset ( e ) {
295
288
return mouseOffset (
296
289
e . changedTouches ? e . changedTouches [ 0 ] : e ,
0 commit comments