8000 feat: Add min/max scale limits for geo plots by camdecoster · Pull Request #7371 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

feat: Add min/max scale limits for geo plots #7371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
Switch to getBBox and fix zoom.event call
  • Loading branch information
camdecoster committed Feb 22, 2025
commit 84cd037acf7138f9a6fa684626dc2acf6c57ec9c
2 changes: 1 addition & 1 deletion src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ proto.updateFx = function(fullLayout, geoLayout) {
bgRect.call(zoom);
// TODO: Figure out how to restrict when this transition occurs. Or is it a no-op if nothing has changed?
// Trigger transition to handle if minscale attribute isn't 0
zoom.event(bgRect.transition())
zoom.event(bgRect)
bgRect.on('dblclick.zoom', zoomReset);
if(!gd._context._scrollZoom.geo) {
bgRect.on('wheel.zoom', null);
Expand Down
16 changes: 8 additions & 8 deletions src/plots/geo/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ function zoomNonClipped(geo, projection) {
function handleZoomstart() {
d3.select(this).style(zoomstartStyle);

var rect = this.getBoundingClientRect()
var rect = this.getBBox()
mouse0 = d3.event.sourceEvent
? d3.mouse(this)
: [(rect.left + rect.right) / 2, (rect.bottom + rect.top) / 2];
: [rect.x + rect.width / 2, rect.y + rect.height / 2];
rotate0 = projection.rotate();
translate0 = projection.translate();
lastRotate = rotate0;
zoomPoint = position(mouse0);
}

function handleZoom() {
var rect = this.getBoundingClientRect()
var rect = this.getBBox()
mouse1 = d3.event.sourceEvent
? d3.mouse(this)
: [(rect.left + rect.right) / 2, (rect.bottom + rect.top) / 2];
: [rect.x + rect.width / 2, rect.y + rect.height / 2];
if(outside(mouse0)) {
zoom.scale(projection.scale());
zoom.translate(projection.translate());
Expand Down Expand Up @@ -216,10 +216,10 @@ function zoomClipped(geo, projection) {
zoom.on('zoomstart', function() {
d3.select(this).style(zoomstartStyle);

var rect = this.getBoundingClientRect()
var rect = this.getBBox()
var mouse0 = d3.event.sourceEvent
? d3.mouse(this)
: [(rect.left + rect.right) / 2, (rect.bottom + rect.top) / 2];
: [rect.x + rect.width / 2, rect.y + rect.height / 2];
var rotate0 = projection.rotate();
var lastRotate = rotate0;
var translate0 = projection.translate();
Expand All @@ -228,10 +228,10 @@ function zoomClipped(geo, projection) {
zoomPoint = position(projection, mouse0);

zoomOn.call(zoom, 'zoom', function() {
var rect = this.getBoundingClientRect()
var rect = this.getBBox()
var mouse1 = d3.event.sourceEvent
? d3.mouse(this)
: [(rect.left + rect.right) / 2, (rect.bottom + rect.top) / 2];
: [rect.x + rect.width / 2, rect.y + rect.height / 2];

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

Expand Down
0