8000 Trigger initial zoom event to set minscale · plotly/plotly.js@29b4316 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29b4316

Browse files
committed
Trigger initial zoom event to set minscale
1 parent 8ed949f commit 29b4316

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 8000 ).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)
0