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

create emit before we use it; make move accept an event. #84

Merged
merged 3 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ The brush also creates the SVG elements necessary to display the brush selection

The overlay rect covers the brushable area defined by [*brush*.extent](#brush_extent). The selection rect covers the area defined by the current [brush selection](#brushSelection). The handle rects cover the edges and corners of the brush selection, allowing the corresponding value in the brush selection to be modified interactively. To modify the brush selection programmatically, use [*brush*.move](#brush_move).

<a href="#brush_move" name="brush_move">#</a> <i>brush</i>.<b>move</b>(<i>group</i>, <i>selection</i>) · [Source](https://github.com/d3/d3-brush/blob/master/src/brush.js), [Examples](https://observablehq.com/d/93b91f86f9ebc9b9)
<a href="#brush_move" name="brush_move">#</a> <i>brush</i>.<b>move</b>(<i>group</i>, <i>selection</i>[, <i>event</i>]) · [Source](https://github.com/d3/d3-brush/blob/master/src/brush.js), [Examples](https://observablehq.com/d/93b91f86f9ebc9b9)

Sets the active *selection* of the brush on the specified *group*, which must be a [selection](https://github.com/d3/d3-selection) or a [transition](https://github.com/d3/d3-transition) of SVG [G elements](https://www.w3.org/TR/SVG/struct.html#Groups). The *selection* must be defined as an array of numbers, or null to clear the brush selection. For a [two-dimensional brush](#brush), it must be defined as [[*x0*, *y0*], [*x1*, *y1*]], where *x0* is the minimum *x*-value, *y0* is the minimum *y*-value, *x1* is the maximum *x*-value, and *y1* is the maximum *y*-value. For an [*x*-brush](#brushX), it must be defined as [*x0*, *x1*]; for a [*y*-brush](#brushY), it must be defined as [*y0*, *y1*]. The selection may also be specified as a function which returns such an array; if a function, it is invoked for each selected element, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element. The returned array defines the brush selection for that element.

<a href="#brush_clear" name="brush_clear">#</a> <i>brush</i>.<b>clear</b>(<i>group</i>) · [Source](https://github.com/d3/d3-brush/blob/master/src/brush.js), [Examples](https://observablehq.com/@d3/double-click-brush-clear)
<a href="#brush_clear" name="brush_clear">#</a> <i>brush</i>.<b>clear</b>(<i>group</i>[, <i>event</i>]) · [Source](https://github.com/d3/d3-brush/blob/master/src/brush.js), [Examples](https://observablehq.com/@d3/double-click-brush-clear)

An alias for [*brush*.move](#brush_move) with the null selection.

Expand Down
26 changes: 13 additions & 13 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 Down Expand Up @@ -244,13 +244,13 @@ 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);
});
}
};

brush.clear = function(group) {
brush.move(group, null);
brush.clear = function(group, event) {
brush.move(group, null, event);
};

function redraw() {
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
32 changes: 16 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
"@babel/highlight" "^7.10.4"

"@babel/code-frame@^7.10.4":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.13.tgz#dcfc826beef65e75c50e21d3837d7d95798dd658"
integrity sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g==
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.14.5.tgz#23b08d740e83f49c5e59945fbf1b43e80bbf4edb"
integrity sha512-9pzDqyc6OLDaqe+zbACgFkb6fKMNG6CObKpnYXChRsvYGyEdc7CA2BaqeOM+vOtCS5ndmJicPJhKAwYRI6UfFw==
dependencies:
"@babel/highlight" "^7.12.13"
"@babel/highlight" "^7.14.5"

"@babel/helper-validator-identifier@^7.14.0":
version "7.14.0"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.0.tgz#d26cad8a47c65286b15df1547319a5d0bcf27288"
integrity sha512-V3ts7zMSu5lfiwWDVWzRDGIN+lnCEUdaXgtVHJgLb1rGaA6jMrtB9EmE7L18foXJIE8Un/A/h6NJfGQp/e1J4A==
"@babel/helper-validator-identifier@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.5.tgz#d0f0e277c512e0c938277faa85a3968c9a44c0e8"
integrity sha512-5lsetuxCLilmVGyiLEfoHBRX8UCFD+1m2x3Rj97WrW3V7H3u4RWRXA4evMjImCsin2J2YT0QaVDGf+z8ondbAg==

"@babel/highlight@^7.10.4", "@babel/highlight@^7.12.13":
version "7.14.0"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.14.0.tgz#3197e375711ef6bf834e67d0daec88e4f46113cf"
integrity sha512-YSCOwxvTYEIMSGaBQb5kDDsCopDdiUGsqpatp3fOlI4+2HQSkTmEVWnVuySdAC5EWCqSWWTv0ib63RjR7dTBdg==
"@babel/highlight@^7.10.4", "@babel/highlight@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.14.5.tgz#6861a52f03966405001f6aa534a01a24d99e8cd9"
integrity sha512-qf9u2WFWVV0MppaL877j2dBtQIDgmidgjGk5VIMw3OadXvYaXn66U1BFlH2t4+t3i+8PhedppRv+i40ABzd+gg==
dependencies:
"@babel/helper-validator-identifier" "^7.14.0"
"@babel/helper-validator-identifier" "^7.14.5"
chalk "^2.0.0"
js-tokens "^4.0.0"

Expand Down Expand Up @@ -309,9 +309,9 @@ d3-selection@3:
integrity sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==

d3-transition@3:
version "3.0.0"
resolved "https://registry.yarnpkg.com/d3-transition/-/d3-transition-3.0.0.tgz#e5ec6612ac057c78780e35686150c0914e3de8ab"
integrity sha512-BKbH4cJkRcSGAb4DtjRCZkYy8I0YJFOg4PnuZaJOVgaQBSEPzLA5sAnMGfYswQ+dIx9+BzHB9sH+QcNt2aICWg==
version "3.0.1"
resolved "https://registry.yarnpkg.com/d3-transition/-/d3-transition-3.0.1.tgz#6869fdde1448868077fdd5989200cb61b2a1645f"
integrity sha512-ApKvfjsSR6tg06xrL434C0WydLr7JewBB3V+/39RMHsaXTOG0zmt/OAXeng5M5LBm0ojmxJrpomQVZ1aPvBL4w==
dependencies:
d3-color "1 - 3"
d3-dispatch "1 - 3"
Expand Down