Skip to content

Commit 81d38cd

Browse files
committed
d3@v6 compatible brush/zoom event handlers
1 parent 006f8f4 commit 81d38cd

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/base/coordinate-grid-mixin.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class CoordinateGridMixin extends ColorMixin(MarginMixin) {
7878
this._zoomScale = [1, Infinity];
7979
this._zoomOutRestrict = true;
8080

81-
this._zoom = zoom().on('zoom', () => this._onZoom());
81+
this._zoom = zoom().on('zoom', evt => this._onZoom(evt));
8282
this._nullZoom = zoom().on('zoom', null);
8383
this._hasBeenMouseZoomable = false;
8484
this._ignoreZoomEvents = false; // ignore when carrying out programmatic zoom operations
@@ -934,7 +934,7 @@ export class CoordinateGridMixin extends ColorMixin(MarginMixin) {
934934

935935
renderBrush (g, doTransition) {
936936
if (this._brushOn) {
937-
this._brush.on('start brush end', () => this._brushing());
937+
this._brush.on('start brush end', evt => this._brushing(evt));
938938

939939
// To retrieve selection we need self._gBrush
940940
this._gBrush = g.append('g')
@@ -974,12 +974,17 @@ export class CoordinateGridMixin extends ColorMixin(MarginMixin) {
974974
return !brushSelection || brushSelection[1] <= brushSelection[0];
975975
}
976976

977-
_brushing () {
977+
_brushing (evt) {
978978
if (this._ignoreBrushEvents) {
979979
return;
980980
}
981981

982-
let brushSelection = event.selection;
982+
// d3@v5 compatibility
983+
if (event) {
984+
evt = event;
985+
}
986+
987+
let brushSelection = evt.selection;
983988
if (brushSelection) {
984989
brushSelection = brushSelection.map(this.x().invert);
985990
}
@@ -1261,13 +1266,18 @@ export class CoordinateGridMixin extends ColorMixin(MarginMixin) {
12611266
}
12621267
}
12631268

1264-
_onZoom () {
1269+
_onZoom (evt) {
12651270
// ignore zoom events if it was caused by a programmatic change
12661271
if (this._ignoreZoomEvents) {
12671272
return;
12681273
}
12691274

1270-
const newDomain = event.transform.rescaleX(this._origX).domain();
1275+
// d3@v5 compatibility
1276+
if (event) {
1277+
evt = event;
1278+
}
1279+
1280+
const newDomain = evt.transform.rescaleX(this._origX).domain();
12711281
this.focus(newDomain, false);
12721282
}
12731283

src/charts/scatter-plot.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,17 @@ export class ScatterPlot extends CoordinateGridMixin {
584584
return !brushSelection || brushSelection[0][0] >= brushSelection[1][0] || brushSelection[0][1] >= brushSelection[1][1];
585585
}
586586

587-
_brushing () {
587+
_brushing (evt) {
588588
if (this._ignoreBrushEvents) {
589589
return;
590590
}
591591

592-
let brushSelection = event.selection;
592+
// d3@v5 compatibility
593+
if (event) {
594+
evt = event;
595+
}
596+
597+
let brushSelection = evt.selection;
593598

594599
// Testing with pixels is more reliable
595600
let brushIsEmpty = this.brushIsEmpty(brushSelection);

0 commit comments

Comments
 (0)