Skip to content
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

Stop event propagation for {brush,drag,zoom}. #1322

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions d3.js
Expand Up @@ -535,6 +535,7 @@ d3 = function() {
event_({
type: "dragstart"
});
d3.event.stopPropagation();
function point() {
var p = target.parentNode;
return touchId != null ? d3.touches(p).filter(function(p) {
Expand Down Expand Up @@ -1206,6 +1207,7 @@ d3 = function() {
}
function mousedown() {
var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target)), selectEnable = d3_event_userSelectSuppress("zoom");
d3.event.stopPropagation();
function mousemove() {
moved = 1;
translateTo(d3.mouse(target), l);
Expand Down Expand Up @@ -1249,6 +1251,7 @@ d3 = function() {
}
touchtime = now;
}
d3.event.stopPropagation();
}
function touchmove() {
var touches = d3.touches(this), p0 = touches[0], l0 = translate0[p0.identifier];
Expand Down Expand Up @@ -7928,8 +7931,13 @@ d3 = function() {
g.selectAll(".extent,.e>rect,.w>rect").attr("height", extent[1][1] - extent[0][1]);
}
function brushstart() {
var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), center, origin = mouse(), offset;
var w = d3.select(d3_window).on("mousemove.brush", brushmove).on("mouseup.brush", brushend).on("touchmove.brush", brushmove).on("touchend.brush", brushend).on("keydown.brush", keydown).on("keyup.brush", keyup);
var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), center, origin = mouse(), offset, selectEnable = d3_event_userSelectSuppress("brush");
var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
if (d3.event.changedTouches) {
w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
} else {
w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
}
if (dragging) {
origin[0] = extent[0][0] - origin[0];
origin[1] = extent[0][1] - origin[1];
Expand All @@ -7945,7 +7953,7 @@ d3 = function() {
type: "brushstart"
});
brushmove();
d3_eventCancel();
d3.event.stopPropagation();
function mouse() {
var touches = d3.event.changedTouches;
return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
Expand Down Expand Up @@ -7996,6 +8004,7 @@ d3 = function() {
type: "brush",
mode: dragging ? "move" : "resize"
});
d3_eventCancel();
}
}
function move1(point, scale, i) {
Expand Down Expand Up @@ -8032,6 +8041,7 @@ d3 = function() {
type: "brushend"
});
d3_eventCancel();
selectEnable();
}
}
brush.x = function(z) {
Expand Down
4 changes: 2 additions & 2 deletions d3.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/behavior/drag.js
Expand Up @@ -37,6 +37,7 @@ d3.behavior.drag = function() {
}

event_({type: "dragstart"});
d3.event.stopPropagation();

function point() {
var p = target.parentNode;
Expand Down
4 changes: 4 additions & 0 deletions src/behavior/zoom.js
Expand Up @@ -106,6 +106,8 @@ d3.behavior.zoom = function() {
l = location(d3.mouse(target)),
selectEnable = d3_event_userSelectSuppress("zoom");

d3.event.stopPropagation();

function mousemove() {
moved = 1;
translateTo(d3.mouse(target), l);
Expand Down Expand Up @@ -155,6 +157,8 @@ d3.behavior.zoom = function() {
}
touchtime = now;
}

d3.event.stopPropagation();
}

function touchmove() {
Expand Down
18 changes: 12 additions & 6 deletions src/svg/brush.js
Expand Up @@ -4,6 +4,7 @@ import "../event/dispatch";
import "../event/event";
import "../event/mouse";
import "../event/touches";
import "../event/user-select";
import "../scale/scale";
import "../selection/selection";
import "svg";
Expand Down Expand Up @@ -102,16 +103,19 @@ d3.svg.brush = function() {
dragging = eventTarget.classed("extent"),
center,
origin = mouse(),
offset;
offset,
selectEnable = d3_event_userSelectSuppress("brush");

var w = d3.select(d3_window)
.on("mousemove.brush", brushmove)
.on("mouseup.brush", brushend)
.on("touchmove.brush", brushmove)
.on("touchend.brush", brushend)
.on("keydown.brush", keydown)
.on("keyup.brush", keyup);

if (d3.event.changedTouches) {
w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
} else {
w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
}

// If the extent was clicked on, drag rather than brush;
// store the point between the mouse and extent origin instead.
if (dragging) {
Expand Down Expand Up @@ -139,7 +143,7 @@ d3.svg.brush = function() {
// Notify listeners.
event_({type: "brushstart"});
brushmove();
d3_eventCancel();
d3.event.stopPropagation();

function mouse() {
var touches = d3.event.changedTouches;
Expand Down Expand Up @@ -206,6 +210,7 @@ d3.svg.brush = function() {
if (moved) {
redraw(g);
event_({type: "brush", mode: dragging ? "move" : "resize"});
d3_eventCancel();
}
}

Expand Down Expand Up @@ -269,6 +274,7 @@ d3.svg.brush = function() {

event_({type: "brushend"});
d3_eventCancel();
selectEnable();
}
}

Expand Down