Skip to content

Commit e03e9e0

Browse files
committed
Merge pull request #355 from plotly/zoom-click-bug
Doubleclick - Drag bug [Fixes #333]
2 parents 31c3b36 + 5881c4b commit e03e9e0

File tree

4 files changed

+404
-57
lines changed

4 files changed

+404
-57
lines changed

src/plots/cartesian/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828

2929
// ms between first mousedown and 2nd mouseup to constitute dblclick...
3030
// we don't seem to have access to the system setting
31-
DBLCLICKDELAY: 600,
31+
DBLCLICKDELAY: 300,
3232

3333
// pixels to move mouse before you stop clamping to starting point
3434
MINDRAG: 8,

src/plots/cartesian/graph_interact.js

-22
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,6 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
15761576
function zoomDone(dragged, numClicks) {
15771577
if(Math.min(box.h, box.w) < MINDRAG * 2) {
15781578
if(numClicks === 2) doubleClick();
1579-
else pauseForDrag(gd);
15801579

15811580
return removeZoombox(gd);
15821581
}
@@ -1629,7 +1628,6 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
16291628
}
16301629
});
16311630
}
1632-
else pauseForDrag(gd);
16331631
}
16341632

16351633
// scroll zoom, on all draggers except corners
@@ -1932,21 +1930,6 @@ function getEndText(ax, end) {
19321930
}
19331931
}
19341932

1935-
function pauseForDrag(gd) {
1936-
// prevent more redraws until we know if a doubleclick
1937-
// has occurred
1938-
gd._dragging = true;
1939-
var deferredReplot = gd._replotPending;
1940-
gd._replotPending = false;
1941-
1942-
setTimeout(function() {
1943-
gd._replotPending = deferredReplot;
1944-
finishDrag(gd);
1945-
},
1946-
constants.DBLCLICKDELAY
1947-
);
1948-
}
1949-
19501933
function finishDrag(gd) {
19511934
gd._dragging = false;
19521935
if(gd._replotPending) Plotly.plot(gd);
@@ -2032,11 +2015,6 @@ fx.dragElement = function(options) {
20322015
if(!gd._mouseDownTime) gd._mouseDownTime = 0;
20332016

20342017
function onStart(e) {
2035-
// because we cancel event bubbling,
2036-
// explicitly trigger input blur event.
2037-
var inputBox = document.querySelector('.plugin-editable');
2038-
if(inputBox) d3.select(inputBox).on('blur').call(inputBox);
2039-
20402018
// make dragging and dragged into properties of gd
20412019
// so that others can look at and modify them
20422020
gd._dragged = false;
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
4+
/**
5+
* Get the screen coordinates of the center of
6+
* an SVG rectangle node.
7+
*
8+
* @param {rect} rect svg <rect> node
9+
*/
10+
module.exports = function getRectCenter(rect) {
11+
var corners = getRectScreenCoords(rect);
12+
13+
return [
14+
corners.nw.x + (corners.ne.x - corners.nw.x) / 2,
15+
corners.ne.y + (corners.se.y - corners.ne.y) / 2
16+
];
17+
};
18+
19+
// Taken from: http://stackoverflow.com/a/5835212/4068492
20+
function getRectScreenCoords(rect) {
21+
var svg = findParentSVG(rect);
22+
var pt = svg.createSVGPoint();
23+
var corners = {};
24+
var matrix = rect.getScreenCTM();
25+
26+
pt.x = rect.x.animVal.value;
27+
pt.y = rect.y.animVal.value;
28+
corners.nw = pt.matrixTransform(matrix);
29+
pt.x += rect.width.animVal.value;
30+
corners.ne = pt.matrixTransform(matrix);
31+
pt.y += rect.height.animVal.value;
32+
corners.se = pt.matrixTransform(matrix);
33+
pt.x -= rect.width.animVal.value;
34+
corners.sw = pt.matrixTransform(matrix);
35+
36+
return corners;
37+
}
38+
39+
function findParentSVG(node) {
40+
var parentNode = node.parentNode;
41+
42+
if(parentNode.tagName === 'svg') {
43+
return parentNode;
44+
}
45+
else {
46+
return findParentSVG(parentNode);
47+
}
48+
}

0 commit comments

Comments
 (0)