Skip to content

Commit d2bd951

Browse files
committed
first cut Plots.redrag
- setup in a similar way to Plots.rehover - stash drag dx/dy values on gd._dragdata, call drag handler `moveFn` after redraw - 🔪 gd._replotPending logic ! - 🔪 gd._dragging Promise.reject !
1 parent 869a42f commit d2bd951

File tree

6 files changed

+40
-58
lines changed

6 files changed

+40
-58
lines changed

src/components/dragelement/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var mouseOffset = require('mouse-event-offset');
1313
var hasHover = require('has-hover');
1414
var supportsPassive = require('has-passive-events');
1515

16-
var Registry = require('../../registry');
1716
var Lib = require('../../lib');
1817

1918
var constants = require('../../plots/cartesian/constants');
@@ -191,12 +190,21 @@ dragElement.init = function init(options) {
191190
dragElement.unhover(gd);
192191
}
193192

194-
if(gd._dragged && options.moveFn && !rightClick) options.moveFn(dx, dy);
193+
if(gd._dragged && options.moveFn && !rightClick) {
194+
gd._dragdata = {
195+
element: element,
196+
dx: dx,
197+
dy: dy
198+
};
199+
options.moveFn(dx, dy);
200+
}
195201

196202
return;
197203
}
198204

199205
function onDone(e) {
206+
delete gd._dragdata;
207+
200208
if(options.dragmode !== false) {
201209
e.preventDefault();
202210
document.removeEventListener('mousemove', onMove);
@@ -258,10 +266,8 @@ dragElement.init = function init(options) {
258266
}
259267
}
260268

261-
finishDrag(gd);
262-
269+
gd._dragging = false;
263270
gd._dragged = false;
264-
265271
return;
266272
}
267273
};
@@ -286,11 +292,6 @@ function coverSlip() {
286292

287293
dragElement.coverSlip = coverSlip;
288294

289-
function finishDrag(gd) {
290-
gd._dragging = false;
291-
if(gd._replotPending) Registry.call('plot', gd);
292-
}
293-
294295
function pointerOffset(e) {
295296
return mouseOffset(
296297
e.changedTouches ? e.changedTouches[0] : e,

src/plot_api/plot_api.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,6 @@ exports.plot = function(gd, data, layout, config) {
139139
gd.layout = helpers.cleanLayout(layout);
140140
}
141141

142-
// if the user is trying to drag the axes, allow new data and layout
143-
// to come in but don't allow a replot.
144-
if(gd._dragging && !gd._transitioning) {
145-
// signal to drag handler that after everything else is done
146-
// we need to replot, because something has changed
147-
gd._replotPending = true;
148-
return Promise.reject();
149-
} else {
150-
// we're going ahead with a replot now
151-
gd._replotPending = false;
152-
}
153-
154142
Plots.supplyDefaults(gd);
155143

156144
var fullLayout = gd._fullLayout;
@@ -386,6 +374,7 @@ exports.plot = function(gd, data, layout, config) {
386374
initInteractions,
387375
Plots.addLinks,
388376
Plots.rehover,
377+
Plots.redrag,
389378
// TODO: doAutoMargin is only needed here for axis automargin, which
390379
// happens outside of marginPushers where all the other automargins are
391380
// calculated. Would be much better to separate margin calculations from
@@ -1404,7 +1393,7 @@ function restyle(gd, astr, val, _traces) {
14041393
seq.push(emitAfterPlot);
14051394
}
14061395

1407-
seq.push(Plots.rehover);
1396+
seq.push(Plots.rehover, Plots.redrag);
14081397

14091398
Queue.add(gd,
14101399
restyle, [gd, specs.undoit, specs.traces],
@@ -1913,7 +1902,7 @@ function relayout(gd, astr, val) {
19131902
seq.push(emitAfterPlot);
19141903
}
19151904

1916-
seq.push(Plots.rehover);
1905+
seq.push(Plots.rehover, Plots.redrag);
19171906

19181907
Queue.add(gd,
19191908
relayout, [gd, specs.undoit],
@@ -2446,7 +2435,7 @@ function update(gd, traceUpdate, layoutUpdate, _traces) {
24462435
seq.push(emitAfterPlot);
24472436
}
24482437

2449-
seq.push(Plots.rehover);
2438+
seq.push(Plots.rehover, Plots.redrag);
24502439

24512440
Queue.add(gd,
24522441
update, [gd, restyleSpecs.undoit, relayoutSpecs.undoit, restyleSpecs.traces],
@@ -2849,7 +2838,7 @@ exports.react = function(gd, data, layout, config) {
28492838
seq.push(emitAfterPlot);
28502839
}
28512840

2852-
seq.push(Plots.rehover);
2841+
seq.push(Plots.rehover, Plots.redrag);
28532842

28542843
plotDone = Lib.syncOrAsync(seq, gd);
28552844
if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);

src/plots/cartesian/dragbox.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var d3 = require('d3');
@@ -38,7 +37,6 @@ var constants = require('./constants');
3837
var MINDRAG = constants.MINDRAG;
3938
var MINZOOM = constants.MINZOOM;
4039

41-
4240
// flag for showing "doubleclick to zoom out" only at the beginning
4341
var SHOWZOOMOUTTIP = true;
4442

@@ -216,6 +214,20 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
216214
}
217215
}
218216
}
217+
218+
gd._fullLayout._redrag = function() {
219+
var dragDataNow = gd._dragdata;
220+
221+
if(dragDataNow && dragDataNow.element === dragger) {
222+
var dragModeNow = gd._fullLayout.dragmode;
223+
224+
if(!isSelectOrLasso(dragModeNow)) {
225+
recomputeAxisLists();
226+
updateSubplots([0, 0, pw, ph]);
227+
dragOptions.moveFn(dragDataNow.dx, dragDataNow.dy);
228+
}
229+
}
230+
};
219231
};
220232

221233
function clearAndResetSelect() {

src/plots/plots.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1679,10 +1679,10 @@ plots.purge = function(gd) {
16791679
// themselves, but may not if there was an error
16801680
delete gd._dragging;
16811681
delete gd._dragged;
1682+
delete gd._dragdata;
16821683
delete gd._hoverdata;
16831684
delete gd._snapshotInProgress;
16841685
delete gd._editing;
1685-
delete gd._replotPending;
16861686
delete gd._mouseDownTime;
16871687
delete gd._legendMouseDownTime;
16881688

@@ -2907,6 +2907,12 @@ plots.rehover = function(gd) {
29072907
}
29082908
};
29092909

2910+
plots.redrag = function(gd) {
2911+
if(gd._fullLayout._redrag) {
2912+
gd._fullLayout._redrag();
2913+
}
2914+
};
2915+
29102916
plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subplotLayout) {
29112917
var traceHashOld = subplot.traceHash;
29122918
var traceHash = {};

test/jasmine/tests/plot_promise_test.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,6 @@ describe('Plotly.___ methods', function() {
6262
});
6363
});
6464

65-
describe('Plotly.plot promise', function() {
66-
var gd;
67-
var promise;
68-
var promiseRejected = false;
69-
70-
beforeEach(function(done) {
71-
var data = [{ x: [1, 2, 3], y: [4, 5, 6] }];
72-
73-
gd = createGraphDiv();
74-
75-
gd._dragging = true;
76-
77-
promise = Plotly.plot(gd, data, {});
78-
79-
promise.then(null, function() {
80-
promiseRejected = true;
81-
done();
82-
});
83-
});
84-
85-
86-
it('should reject the promise when graph is being dragged', function() {
87-
expect(promiseRejected).toBe(true);
88-
});
89-
});
90-
9165
describe('Plotly.redraw promise', function() {
9266
var promise;
9367
var promiseGd;

test/jasmine/tests/plots_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ describe('Test Plots', function() {
405405
// because _dragging and _dragged were not cleared by purge.
406406
gd._dragging = true;
407407
gd._dragged = true;
408+
gd._dragdata = true;
408409
gd._hoverdata = true;
409410
gd._snapshotInProgress = true;
410411
gd._editing = true;
411-
gd._replotPending = true;
412412
gd._mouseDownTime = true;
413413
gd._legendMouseDownTime = true;
414414
});
@@ -427,8 +427,8 @@ describe('Test Plots', function() {
427427
'empty', 'fid', 'undoqueue', 'undonum', 'autoplay', 'changed',
428428
'_promises', '_redrawTimer', 'firstscatter',
429429
'_transitionData', '_transitioning', '_hmpixcount', '_hmlumcount',
430-
'_dragging', '_dragged', '_hoverdata', '_snapshotInProgress', '_editing',
431-
'_replotPending', '_mouseDownTime', '_legendMouseDownTime'
430+
'_dragging', '_dragged', '_dragdata', '_hoverdata', '_snapshotInProgress', '_editing',
431+
'_mouseDownTime', '_legendMouseDownTime'
432432
];
433433

434434
Plots.purge(gd);

0 commit comments

Comments
 (0)