Skip to content

Commit 6f6100f

Browse files
authored
elyra-ai#2298 Drag interactions are too sensitive (elyra-ai#2299)
Signed-off-by: CTomlyn <tomlyn@us.ibm.com>
1 parent b93d750 commit 6f6100f

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

canvas_modules/common-canvas/src/common-canvas/common-canvas-utils.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,18 @@ export default class CanvasUtils {
506506
return null;
507507
}
508508

509-
// Returns true if point 1 is inside a circle of the specified radius whose
510-
// center is point 2.
511-
static isInside(point1, point2, radius) {
512-
return Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2)) < radius;
509+
// Returns true if the distance between the two positions is smaller than
510+
// 3px which is considered to be a tiny movement. This can be used to define
511+
// whether a mouse pointer gesture is considered to be a click on an object or, if
512+
// outside the 3px distance, a drag.
513+
static isTinyMovement(startPos, endPos) {
514+
return CanvasUtils.isInside(startPos, endPos, 3);
515+
}
516+
517+
// Returns true if the distance from point 1 to point 2 is less than the
518+
// distance passed in.
519+
static isInside(point1, point2, distance) {
520+
return Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2)) < distance;
513521
}
514522

515523
// Returns the distance from the start point to finish point of the link line.

canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-drag-new-link.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export default class SVGCanvasUtilsDragNewLink {
354354

355355
// If the user has not dragged the mouse far enough to create a new link, we
356356
// treat it as a click on the port.
357-
if (this.isClicked(drawingNewLinkData.mousePos, d3Event)) {
357+
if (CanvasUtils.isTinyMovement(drawingNewLinkData.mousePos, { x: d3Event.x, y: d3Event.y })) {
358358
this.removeNewLink();
359359
this.ren.canvasController.clickActionHandler({
360360
clickType: SINGLE_CLICK,
@@ -386,12 +386,6 @@ export default class SVGCanvasUtilsDragNewLink {
386386
}
387387
}
388388

389-
// Returns true if the mouse position is inside a circle with a radius of
390-
// 3px centred at the d3Event x and y.
391-
isClicked(mousePos, d3Event) {
392-
return CanvasUtils.isInside(mousePos, { x: d3Event.x, y: d3Event.y }, 3);
393-
}
394-
395389
// Handles the creation of a link when the end of a new link
396390
// being drawn from a source node is dropped on a target node.
397391
createNewLinkFromDragData(d3Event, trgNode, drawingNewLinkData) {

canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-drag-objects.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,13 @@ export default class SVGCanvasUtilsDragObjects {
725725
}
726726
}
727727

728+
// If enableDragWithoutSelect is enabled and the mouse pointer
729+
// hasn't moved very much, we don't move the objects.
730+
if (this.ren.config.enableDragWithoutSelect &&
731+
CanvasUtils.isTinyMovement({ x: 0, y: 0 }, { x: this.draggingObjectData.dragOffsetX, y: this.draggingObjectData.dragOffsetY })) {
732+
return;
733+
}
734+
728735
this.ren.displayMovedComments();
729736
this.ren.displayMovedNodes();
730737
this.ren.displayMovedLinks();
@@ -784,11 +791,10 @@ export default class SVGCanvasUtilsDragObjects {
784791
// Remove the 'd3-is-moving' class from the objects being dragged.
785792
this.switchIsMovingClass(draggingObjectData.dragObjects, false);
786793

787-
// If the pointer hasn't moved and enableDragWithoutSelect is enabled we interpret
788-
// that as a select on the object.
789-
if (draggingObjectData.dragOffsetX === 0 &&
790-
draggingObjectData.dragOffsetY === 0 &&
791-
this.ren.config.enableDragWithoutSelect) {
794+
// If enableDragWithoutSelect is enabled and the pointer hasn't moved
795+
// very much, we interpret that as a select on the object.
796+
if (this.ren.config.enableDragWithoutSelect &&
797+
CanvasUtils.isTinyMovement({ x: 0, y: 0 }, { x: draggingObjectData.dragOffsetX, y: draggingObjectData.dragOffsetY })) {
792798
const objType = this.ren.activePipeline.getObjectTypeName(d);
793799
this.ren.selectObject(eventType, d, objType, range, augment);
794800

0 commit comments

Comments
 (0)