Skip to content

Commit 9fb1cdb

Browse files
committed
Update syntax
1 parent f938f4b commit 9fb1cdb

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/plots/geo/zoom.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,20 @@ function zoomNonClipped(geo, projection) {
127127
function handleZoomstart() {
128128
d3.select(this).style(zoomstartStyle);
129129

130-
var rect = this.getBBox();
131-
mouse0 = d3.event.sourceEvent ? d3.mouse(this) : [rect.x + rect.width / 2, rect.y + rect.height / 2];
130+
// Fallback to bbox center when there's no source event
131+
// (e.g. synthetic zoom.event dispatched on initial render
132+
// to enforce minscale/maxscale).
133+
const { x, y, width, height } = this.getBBox();
134+
mouse0 = d3.event.sourceEvent ? d3.mouse(this) : [x + width / 2, y + height / 2];
132135
rotate0 = projection.rotate();
133136
translate0 = projection.translate();
134137
lastRotate = rotate0;
135138
zoomPoint = position(mouse0);
136139
}
137140

138141
function handleZoom() {
139-
var rect = this.getBBox();
140-
mouse1 = d3.event.sourceEvent ? d3.mouse(this) : [rect.x + rect.width / 2, rect.y + rect.height / 2];
142+
const { x, y, width, height } = this.getBBox();
143+
mouse1 = d3.event.sourceEvent ? d3.mouse(this) : [x + width / 2, y + height / 2];
141144
if (outside(mouse0)) {
142145
zoom.scale(projection.scale());
143146
zoom.translate(projection.translate());
@@ -203,18 +206,21 @@ function zoomClipped(geo, projection) {
203206
zoom.on('zoomstart', function () {
204207
d3.select(this).style(zoomstartStyle);
205208

206-
var rect = this.getBBox();
207-
var mouse0 = d3.event.sourceEvent ? d3.mouse(this) : [rect.x + rect.width / 2, rect.y + rect.height / 2];
208-
var rotate0 = projection.rotate();
209-
var lastRotate = rotate0;
210-
var translate0 = projection.translate();
211-
var q = quaternionFromEuler(rotate0);
209+
// Fallback to bbox center when there's no source event
210+
// (e.g. synthetic zoom.event dispatched on initial render
211+
// to enforce minscale/maxscale).
212+
const { x, y, width, height } = this.getBBox();
213+
let mouse0 = d3.event.sourceEvent ? d3.mouse(this) : [x + width / 2, y + height / 2];
214+
const rotate0 = projection.rotate();
215+
let lastRotate = rotate0;
216+
const translate0 = projection.translate();
217+
const q = quaternionFromEuler(rotate0);
212218

213219
zoomPoint = position(projection, mouse0);
214220

215221
zoomOn.call(zoom, 'zoom', function () {
216-
var rect = this.getBBox();
217-
var mouse1 = d3.event.sourceEvent ? d3.mouse(this) : [rect.x + rect.width / 2, rect.y + rect.height / 2];
222+
const { x, y, width, height } = this.getBBox();
223+
const mouse1 = d3.event.sourceEvent ? d3.mouse(this) : [x + width / 2, y + height / 2];
218224

219225
projection.scale((view.k = d3.event.scale));
220226

0 commit comments

Comments
 (0)