Skip to content

Commit 9f98681

Browse files
authored
Merge pull request #3170 from jonfunkhouser/dragmode_false
Add dragmode: false
2 parents 889087d + 174d2b2 commit 9f98681

File tree

4 files changed

+66
-9
lines changed

4 files changed

+66
-9
lines changed

Diff for: src/components/dragelement/index.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ dragElement.init = function init(options) {
124124
var clampFn = options.clampFn || _clampFn;
125125

126126
function onStart(e) {
127-
e.preventDefault();
128-
129127
// make dragging and dragged into properties of gd
130128
// so that others can look at and modify them
131129
gd._dragged = false;
@@ -167,11 +165,15 @@ dragElement.init = function init(options) {
167165
document.documentElement.style.cursor = window.getComputedStyle(element).cursor;
168166
}
169167

170-
document.addEventListener('mousemove', onMove);
171168
document.addEventListener('mouseup', onDone);
172-
document.addEventListener('touchmove', onMove);
173169
document.addEventListener('touchend', onDone);
174170

171+
if(options.dragmode !== false) {
172+
e.preventDefault();
173+
document.addEventListener('mousemove', onMove);
174+
document.addEventListener('touchmove', onMove);
175+
}
176+
175177
return;
176178
}
177179

@@ -195,13 +197,15 @@ dragElement.init = function init(options) {
195197
}
196198

197199
function onDone(e) {
198-
document.removeEventListener('mousemove', onMove);
200+
if(options.dragmode !== false) {
201+
e.preventDefault();
202+
document.removeEventListener('mousemove', onMove);
203+
document.removeEventListener('touchmove', onMove);
204+
}
205+
199206
document.removeEventListener('mouseup', onDone);
200-
document.removeEventListener('touchmove', onMove);
201207
document.removeEventListener('touchend', onDone);
202208

203-
e.preventDefault();
204-
205209
if(hasHover) {
206210
Lib.removeElement(dragCover);
207211
}

Diff for: src/components/fx/layout_attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
dragmode: {
4545
valType: 'enumerated',
4646
role: 'info',
47-
values: ['zoom', 'pan', 'select', 'lasso', 'orbit', 'turntable'],
47+
values: ['zoom', 'pan', 'select', 'lasso', 'orbit', 'turntable', false],
4848
dflt: 'zoom',
4949
editType: 'modebar',
5050
description: [

Diff for: test/jasmine/tests/dragelement_test.js

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var d3 = require('d3');
44
var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66
var mouseEvent = require('../assets/mouse_event');
7+
var touchEvent = require('../assets/touch_event');
78

89

910
describe('dragElement', function() {
@@ -205,6 +206,30 @@ describe('dragElement', function() {
205206

206207
expect(mockObj.dummy).not.toHaveBeenCalled();
207208
});
209+
210+
it('should not register move event handler when dragmode is false', function() {
211+
var moveCalls = 0;
212+
var options = {
213+
element: this.element,
214+
gd: this.gd,
215+
dragmode: false,
216+
moveFn: function() {
217+
moveCalls++;
218+
}
219+
};
220+
dragElement.init(options);
221+
mouseEvent('mousedown', this.x, this.y);
222+
mouseEvent('mousemove', this.x + 10, this.y + 10);
223+
mouseEvent('mouseup', this.x, this.y);
224+
225+
expect(moveCalls).toBe(0);
226+
227+
touchEvent('touchstart', this.x, this.y);
228+
touchEvent('touchmove', this.x + 10, this.y + 10);
229+
touchEvent('touchend', this.x, this.y);
230+
231+
expect(moveCalls).toBe(0);
232+
});
208233
});
209234

210235
describe('dragElement.getCursor', function() {

Diff for: test/jasmine/tests/hover_label_test.js

+28
Original file line numberDiff line numberDiff line change
@@ -2785,3 +2785,31 @@ describe('touch devices', function() {
27852785
});
27862786
});
27872787
});
2788+
2789+
describe('dragmode: false', function() {
2790+
var data = [{x: [1, 2, 3], y: [1, 3, 2], type: 'bar'}];
2791+
var layout = {width: 600, height: 400, dragmode: false};
2792+
var gd;
2793+
2794+
beforeEach(function(done) {
2795+
gd = createGraphDiv();
2796+
Plotly.plot(gd, data, layout).then(done);
2797+
});
2798+
afterEach(destroyGraphDiv);
2799+
2800+
it('should emit hover events on mousemove', function(done) {
2801+
var hoverHandler = jasmine.createSpy('hover');
2802+
gd.on('plotly_hover', hoverHandler);
2803+
Promise.resolve()
2804+
.then(function() {
2805+
mouseEvent('mousemove', 105, 300);
2806+
mouseEvent('mousemove', 108, 303);
2807+
})
2808+
.then(delay(HOVERMINTIME * 1.1))
2809+
.then(function() {
2810+
expect(hoverHandler).toHaveBeenCalled();
2811+
})
2812+
.catch(failTest)
2813+
.then(done);
2814+
});
2815+
});

0 commit comments

Comments
 (0)