66* LICENSE file in the root directory of this source tree.
77*/
88
9-
109'use strict' ;
1110
1211var mouseOffset = require ( 'mouse-event-offset' ) ;
1312var hasHover = require ( 'has-hover' ) ;
1413var supportsPassive = require ( 'has-passive-events' ) ;
1514
16- var Registry = require ( '../../registry' ) ;
17- var Lib = require ( '../../lib' ) ;
18-
15+ var removeElement = require ( '../../lib' ) . removeElement ;
1916var constants = require ( '../../plots/cartesian/constants' ) ;
2017var interactConstants = require ( '../../constants/interactions' ) ;
2118
@@ -28,7 +25,6 @@ var unhover = require('./unhover');
2825dragElement . unhover = unhover . wrapped ;
2926dragElement . unhoverRaw = unhover . raw ;
3027
31-
3228/**
3329 * Abstracts click & drag interactions
3430 *
@@ -106,8 +102,7 @@ dragElement.init = function init(options) {
106102
107103 if ( ! supportsPassive ) {
108104 element . ontouchstart = onStart ;
109- }
110- else {
105+ } else {
111106 if ( element . _ontouchstart ) {
112107 element . removeEventListener ( 'touchstart' , element . _ontouchstart ) ;
113108 }
@@ -145,8 +140,7 @@ dragElement.init = function init(options) {
145140 if ( newMouseDownTime - gd . _mouseDownTime < DBLCLICKDELAY ) {
146141 // in a click train
147142 numClicks += 1 ;
148- }
149- else {
143+ } else {
150144 // new click train
151145 numClicks = 1 ;
152146 gd . _mouseDownTime = newMouseDownTime ;
@@ -157,8 +151,7 @@ dragElement.init = function init(options) {
157151 if ( hasHover && ! rightClick ) {
158152 dragCover = coverSlip ( ) ;
159153 dragCover . style . cursor = window . getComputedStyle ( element ) . cursor ;
160- }
161- else if ( ! hasHover ) {
154+ } else if ( ! hasHover ) {
162155 // document acts as a dragcover for mobile, bc we can't create dragcover dynamically
163156 dragCover = document ;
164157 cursor = window . getComputedStyle ( document . documentElement ) . cursor ;
@@ -191,12 +184,21 @@ dragElement.init = function init(options) {
191184 dragElement . unhover ( gd ) ;
192185 }
193186
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+ }
195195
196196 return ;
197197 }
198198
199199 function onDone ( e ) {
200+ delete gd . _dragdata ;
201+
200202 if ( options . dragmode !== false ) {
201203 e . preventDefault ( ) ;
202204 document . removeEventListener ( 'mousemove' , onMove ) ;
@@ -207,9 +209,8 @@ dragElement.init = function init(options) {
207209 document . removeEventListener ( 'touchend' , onDone ) ;
208210
209211 if ( hasHover ) {
210- Lib . removeElement ( dragCover ) ;
211- }
212- else if ( cursor ) {
212+ removeElement ( dragCover ) ;
213+ } else if ( cursor ) {
213214 dragCover . documentElement . style . cursor = cursor ;
214215 cursor = null ;
215216 }
@@ -228,8 +229,7 @@ dragElement.init = function init(options) {
228229
229230 if ( gd . _dragged ) {
230231 if ( options . doneFn ) options . doneFn ( ) ;
231- }
232- else {
232+ } else {
233233 if ( options . clickFn ) options . clickFn ( numClicks , initialEvent ) ;
234234
235235 // If we haven't dragged, this should be a click. But because of the
@@ -258,10 +258,8 @@ dragElement.init = function init(options) {
258258 }
259259 }
260260
261- finishDrag ( gd ) ;
262-
261+ gd . _dragging = false ;
263262 gd . _dragged = false ;
264-
265263 return ;
266264 }
267265} ;
@@ -286,11 +284,6 @@ function coverSlip() {
286284
287285dragElement . coverSlip = coverSlip ;
288286
289- function finishDrag ( gd ) {
290- gd . _dragging = false ;
291- if ( gd . _replotPending ) Registry . call ( 'plot' , gd ) ;
292- }
293-
294287function pointerOffset ( e ) {
295288 return mouseOffset (
296289 e . changedTouches ? e . changedTouches [ 0 ] : e ,
0 commit comments