Skip to content

Commit 0129d5a

Browse files
committed
simplify dragElement cursor handling & remove redundant initInteractions
The only reason we needed two initInteractions during Plotly.plot is so the second one could pick up the `onmousemove` from the first to cache as `initialMouseMove`, but it works fine now to remove that junk entirely.
1 parent dc4fc32 commit 0129d5a

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

src/components/dragelement/index.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ dragElement.unhoverRaw = unhover.raw;
2626

2727
/**
2828
* Abstracts click & drag interactions
29+
*
30+
* During the interaction, a "coverSlip" element - a transparent
31+
* div covering the whole page - is created, which has two key effects:
32+
* - Lets you drag beyond the boundaries of the plot itself without
33+
* dropping (but if you drag all the way out of the browser window the
34+
* interaction will end)
35+
* - Freezes the cursor: whatever mouse cursor the drag element had when the
36+
* interaction started gets copied to the coverSlip for use until mouseup
37+
*
2938
* @param {object} options with keys:
3039
* element (required) the DOM element to drag
3140
* prepFn (optional) function(event, startX, startY)
@@ -44,10 +53,6 @@ dragElement.unhoverRaw = unhover.raw;
4453
* numClicks is how many clicks we've registered within
4554
* a doubleclick time
4655
* e is the original event
47-
* setCursor (optional) function(event)
48-
* executed on mousemove before mousedown
49-
* the purpose of this callback is to update the mouse cursor before
50-
* the click & drag interaction has been initiated
5156
*/
5257
dragElement.init = function init(options) {
5358
var gd = options.gd,
@@ -57,15 +62,11 @@ dragElement.init = function init(options) {
5762
startY,
5863
newMouseDownTime,
5964
dragCover,
60-
initialTarget,
61-
initialOnMouseMove;
65+
initialTarget;
6266

6367
if(!gd._mouseDownTime) gd._mouseDownTime = 0;
6468

6569
function onStart(e) {
66-
// disable call to options.setCursor(evt)
67-
options.element.onmousemove = initialOnMouseMove;
68-
6970
// make dragging and dragged into properties of gd
7071
// so that others can look at and modify them
7172
gd._dragged = false;
@@ -116,10 +117,6 @@ dragElement.init = function init(options) {
116117
}
117118

118119
function onDone(e) {
119-
// re-enable call to options.setCursor(evt)
120-
initialOnMouseMove = options.element.onmousemove;
121-
if(options.setCursor) options.element.onmousemove = options.setCursor;
122-
123120
dragCover.onmousemove = null;
124121
dragCover.onmouseup = null;
125122
dragCover.onmouseout = null;
@@ -166,10 +163,6 @@ dragElement.init = function init(options) {
166163
return Lib.pauseEvent(e);
167164
}
168165

169-
// enable call to options.setCursor(evt)
170-
initialOnMouseMove = options.element.onmousemove;
171-
if(options.setCursor) options.element.onmousemove = options.setCursor;
172-
173166
options.element.onmousedown = onStart;
174167
options.element.style.pointerEvents = 'all';
175168
};

src/components/shapes/draw.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {
130130
var xa, ya, x2p, y2p, p2x, p2y;
131131

132132
var dragOptions = {
133-
setCursor: updateDragMode,
134133
element: shapePath.node(),
135134
gd: gd,
136135
prepFn: startDrag,
@@ -141,6 +140,8 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {
141140

142141
dragElement.init(dragOptions);
143142

143+
shapePath.node().onmousemove = updateDragMode;
144+
144145
function updateDragMode(evt) {
145146
// choose 'move' or 'resize'
146147
// based on initial position of cursor within the drag element

src/plot_api/plot_api.js

-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ Plotly.plot = function(gd, data, layout, config) {
368368
drawFramework,
369369
marginPushers,
370370
marginPushersAgain,
371-
initInteractions,
372371
positionAndAutorange,
373372
subroutines.layoutStyles,
374373
drawAxes,

0 commit comments

Comments
 (0)