Skip to content

Commit a7b4524

Browse files
authored
Merge pull request #75 from woutervh-/pass-mode-to-event-listeners
Pass along mode to BrushEvent
2 parents 13642ce + 9b28a8b commit a7b4524

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,4 @@ When a [brush event listener](#brush_on) is invoked, it receives the current bru
169169
* `type` - the string “start”, “brush” or “end”; see [*brush*.on](#brush_on).
170170
* `selection` - the current [brush selection](#brushSelection).
171171
* `sourceEvent` - the underlying input event, such as mousemove or touchmove.
172+
* `mode` - the string “drag”, “space”, “handle” or “center”; the mode of the brush.

src/brush.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,20 @@ function brush(dim) {
301301
if (++this.active === 1) this.state.emitter = this, this.starting = true;
302302
return this;
303303
},
304-
start: function(event) {
305-
if (this.starting) this.starting = false, this.emit("start", event);
304+
start: function(event, mode) {
305+
if (this.starting) this.starting = false, this.emit("start", event, mode);
306306
else this.emit("brush", event);
307307
return this;
308308
},
309-
brush: function(event) {
310-
this.emit("brush", event);
309+
brush: function(event, mode) {
310+
this.emit("brush", event, mode);
311311
return this;
312312
},
313-
end: function(event) {
314-
if (--this.active === 0) delete this.state.emitter, this.emit("end", event);
313+
end: function(event, mode) {
314+
if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
315315
return this;
316316
},
317-
emit: function(type, event) {
317+
emit: function(type, event, mode) {
318318
var d = select(this.that).datum();
319319
listeners.call(
320320
type,
@@ -323,6 +323,7 @@ function brush(dim) {
323323
sourceEvent: event,
324324
target: brush,
325325
selection: dim.output(this.state.selection),
326+
mode,
326327
dispatch: listeners
327328
}),
328329
d
@@ -407,7 +408,7 @@ function brush(dim) {
407408
}
408409

409410
redraw.call(that);
410-
emit.start(event);
411+
emit.start(event, mode.name);
411412

412413
function moved(event) {
413414
for (const p of event.changedTouches || [event]) {
@@ -485,7 +486,7 @@ function brush(dim) {
485486
|| selection[1][1] !== s1) {
486487
state.selection = [[w1, n1], [e1, s1]];
487488
redraw.call(that);
488-
emit.brush(event);
489+
emit.brush(event, mode.name);
489490
}
490491
}
491492

@@ -503,7 +504,7 @@ function brush(dim) {
503504
overlay.attr("cursor", cursors.overlay);
504505
if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
505506
if (empty(selection)) state.selection = null, redraw.call(that);
506-
emit.end(event);
507+
emit.end(event, mode.name);
507508
}
508509

509510
function keydowned(event) {

src/event.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ export default function BrushEvent(type, {
22
sourceEvent,
33
target,
44
selection,
5+
mode,
56
dispatch
67
}) {
78
Object.defineProperties(this, {
89
type: {value: type, enumerable: true, configurable: true},
910
sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
1011
target: {value: target, enumerable: true, configurable: true},
1112
selection: {value: selection, enumerable: true, configurable: true},
13+
mode: {value: mode, enumerable: true, configurable: true},
1214
_: {value: dispatch}
1315
});
1416
}

0 commit comments

Comments
 (0)