Skip to content

Commit c7b5ec3

Browse files
committed
Trigger initial zoom event to set minscale
1 parent c5dfcf3 commit c7b5ec3

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/plots/geo/geo.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,11 @@ proto.updateFx = function(fullLayout, geoLayout) {
484484

485485
if(dragMode === 'pan') {
486486
bgRect.node().onmousedown = null;
487-
bgRect.call(createGeoZoom(_this, geoLayout));
487+
const zoom = createGeoZoom(_this, geoLayout)
488+
bgRect.call(zoom);
489+
// TODO: Figure out how to restrict when this transition occurs. Or is it a no-op if nothing has changed?
490+
// Trigger transition to handle if minscale attribute isn't 0
491+
zoom.event(bgRect.transition())
488492
bgRect.on('dblclick.zoom', zoomReset);
489493
if(!gd._context._scrollZoom.geo) {
490494
bgRect.on('wheel.zoom', null);
@@ -709,14 +713,15 @@ function getProjection(geoLayout) {
709713

710714
projection.precision(constants.precision);
711715

712-
// https://github.com/d3/d3-zoom/blob/master/README.md#zoom_scaleExtent
713-
projection.scaleExtent = function() {
714-
var minscale = projLayout.minscale;
715-
var maxscale = projLayout.maxscale;
716-
if(maxscale === -1) maxscale = Infinity;
717-
return [100 * minscale, 100 * maxscale];
716+
// https://d3js.org/d3-zoom#zoom_scaleExtent
717+
projection.scaleExtent = () => {
718+
let { minscale, maxscale } = projLayout;
719+
maxscale = maxscale === -1 ? Infinity : maxscale;
720+
const max = Math.max(minscale, maxscale);
721+
const min = Math.min(minscale, maxscale);
722+
return [100 * min, 100 * max];
718723
};
719-
724+
720725
if(geoLayout._isSatellite) {
721726
projection.tilt(projLayout.tilt).distance(projLayout.distance);
722727
}

src/plots/geo/zoom.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,21 @@ function zoomNonClipped(geo, projection) {
133133
function handleZoomstart() {
134134
d3.select(this).style(zoomstartStyle);
135135

136-
mouse0 = d3.mouse(this);
136+
const { bottom, left, right, top } = this.getBoundingClientRect()
137+
mouse0 = d3.event.sourceEvent
138+
? d3.mouse(this)
139+
: [(left + right) / 2, (bottom + top) / 2];
137140
rotate0 = projection.rotate();
138141
translate0 = projection.translate();
139142
lastRotate = rotate0;
140143
zoomPoint = position(mouse0);
141144
}
142145

143146
function handleZoom() {
144-
mouse1 = d3.mouse(this);
145-
147+
const { bottom, left, right, top } = this.getBoundingClientRect()
148+
mouse1 = d3.event.sourceEvent
149+
? d3.mouse(this)
150+
: [(left + right) / 2, (bottom + top) / 2];
146151
if(outside(mouse0)) {
147152
zoom.scale(projection.scale());
148153
zoom.translate(projection.translate());
@@ -211,7 +216,10 @@ function zoomClipped(geo, projection) {
211216
zoom.on('zoomstart', function() {
212217
d3.select(this).style(zoomstartStyle);
213218

214-
var mouse0 = d3.mouse(this);
219+
const { bottom, left, right, top } = this.getBoundingClientRect()
220+
let mouse0 = d3.event.sourceEvent
221+
? d3.mouse(this)
222+
: [(left + right) / 2, (bottom + top) / 2];
215223
var rotate0 = projection.rotate();
216224
var lastRotate = rotate0;
217225
var translate0 = projection.translate();
@@ -220,7 +228,10 @@ function zoomClipped(geo, projection) {
220228
zoomPoint = position(projection, mouse0);
221229

222230
zoomOn.call(zoom, 'zoom', function() {
223-
var mouse1 = d3.mouse(this);
231+
const { bottom, left, right, top } = this.getBoundingClientRect()
232+
let mouse1 = d3.event.sourceEvent
233+
? d3.mouse(this)
234+
: [(left + right) / 2, (bottom + top) / 2];
224235

225236
projection.scale(view.k = d3.event.scale);
226237

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy