Skip to content

Doubleclick - Drag bug [Fixes #333] #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 29, 2016
2 changes: 1 addition & 1 deletion src/plots/cartesian/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {

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

// pixels to move mouse before you stop clamping to starting point
MINDRAG: 8,
Expand Down
22 changes: 0 additions & 22 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,6 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
function zoomDone(dragged, numClicks) {
if(Math.min(box.h, box.w) < MINDRAG * 2) {
if(numClicks === 2) doubleClick();
else pauseForDrag(gd);

return removeZoombox(gd);
}
Expand Down Expand Up @@ -1629,7 +1628,6 @@ function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
}
});
}
else pauseForDrag(gd);
}

// scroll zoom, on all draggers except corners
Expand Down Expand Up @@ -1932,21 +1930,6 @@ function getEndText(ax, end) {
}
}

function pauseForDrag(gd) {
// prevent more redraws until we know if a doubleclick
// has occurred
gd._dragging = true;
var deferredReplot = gd._replotPending;
gd._replotPending = false;

setTimeout(function() {
gd._replotPending = deferredReplot;
finishDrag(gd);
},
constants.DBLCLICKDELAY
);
}

function finishDrag(gd) {
gd._dragging = false;
if(gd._replotPending) Plotly.plot(gd);
Expand Down Expand Up @@ -2032,11 +2015,6 @@ fx.dragElement = function(options) {
if(!gd._mouseDownTime) gd._mouseDownTime = 0;

function onStart(e) {
// because we cancel event bubbling,
// explicitly trigger input blur event.
var inputBox = document.querySelector('.plugin-editable');
if(inputBox) d3.select(inputBox).on('blur').call(inputBox);

// make dragging and dragged into properties of gd
// so that others can look at and modify them
gd._dragged = false;
Expand Down
48 changes: 48 additions & 0 deletions test/jasmine/assets/get_rect_center.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';


/**
* Get the screen coordinates of the center of
* an SVG rectangle node.
*
* @param {rect} rect svg <rect> node
*/
module.exports = function getRectCenter(rect) {
var corners = getRectScreenCoords(rect);

return [
corners.nw.x + (corners.ne.x - corners.nw.x) / 2,
corners.ne.y + (corners.se.y - corners.ne.y) / 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @mdtusz

];
};

// Taken from: http://stackoverflow.com/a/5835212/4068492
function getRectScreenCoords(rect) {
var svg = findParentSVG(rect);
var pt = svg.createSVGPoint();
var corners = {};
var matrix = rect.getScreenCTM();

pt.x = rect.x.animVal.value;
pt.y = rect.y.animVal.value;
corners.nw = pt.matrixTransform(matrix);
pt.x += rect.width.animVal.value;
corners.ne = pt.matrixTransform(matrix);
pt.y += rect.height.animVal.value;
corners.se = pt.matrixTransform(matrix);
pt.x -= rect.width.animVal.value;
corners.sw = pt.matrixTransform(matrix);

return corners;
}

function findParentSVG(node) {
var parentNode = node.parentNode;

if(parentNode.tagName === 'svg') {
return parentNode;
}
else {
return findParentSVG(parentNode);
}
}
Loading