Skip to content

Commit

Permalink
create emit before we use it; make move accept an event.
Browse files Browse the repository at this point in the history
This seems to:
- fix #83
- possibly fix d3/d3-zoom#198
- help with d3/d3-zoom#222
  • Loading branch information
Fil committed Mar 12, 2021
1 parent a9bd39e commit 33f6217
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/brush.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function brush(dim) {
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
}

brush.move = function(group, selection) {
brush.move = function(group, selection, event) {
if (group.tween) {
group
.on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
Expand All @@ -227,7 +227,7 @@ function brush(dim) {
function tween(t) {
state.selection = t === 1 && selection1 === null ? null : i(t);
redraw.call(that);
emit.brush();
emit.brush(event);
}

return selection0 !== null && selection1 !== null ? tween : tween(1);
Expand All @@ -244,7 +244,7 @@ function brush(dim) {
interrupt(that);
state.selection = selection1 === null ? null : selection1;
redraw.call(that);
emit.start().brush().end();
emit.start(event).brush(event).end(event);
});
}
};
Expand Down Expand Up @@ -361,6 +361,9 @@ function brush(dim) {
return t;
});

interrupt(that);
var emit = emitter(that, arguments, true).beforestart();

if (type === "overlay") {
if (selection) moving = true;
const pts = [points[0], points[1] || points[0]];
Expand All @@ -371,7 +374,7 @@ function brush(dim) {
e0 = dim === Y ? E : max(pts[0][0], pts[1][0]),
s0 = dim === X ? S : max(pts[0][1], pts[1][1])
]];
if (points.length > 1) move();
if (points.length > 1) move(event);
} else {
w0 = selection[0][0];
n0 = selection[0][1];
Expand All @@ -390,9 +393,6 @@ function brush(dim) {
var overlay = group.selectAll(".overlay")
.attr("cursor", cursors[type]);

interrupt(that);
var emit = emitter(that, arguments, true).beforestart();

if (event.touches) {
emit.moved = moved;
emit.ended = ended;
Expand Down Expand Up @@ -518,7 +518,7 @@ function brush(dim) {
if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
mode = MODE_CENTER;
move();
move(event);
}
break;
}
Expand All @@ -528,7 +528,7 @@ function brush(dim) {
if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
mode = MODE_SPACE;
overlay.attr("cursor", cursors.selection);
move();
move(event);
}
break;
}
Expand All @@ -542,7 +542,7 @@ function brush(dim) {
case 16: { // SHIFT
if (shifting) {
lockX = lockY = shifting = false;
move();
move(event);
}
break;
}
Expand All @@ -551,7 +551,7 @@ function brush(dim) {
if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
mode = MODE_HANDLE;
move();
move(event);
}
break;
}
Expand All @@ -567,7 +567,7 @@ function brush(dim) {
mode = MODE_HANDLE;
}
overlay.attr("cursor", cursors[type]);
move();
move(event);
}
break;
}
Expand Down

0 comments on commit 33f6217

Please sign in to comment.