FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: Add min/max scale limits for geo plots by camdecoster · Pull Request #7371 · plotly/plotly.js · GitHub

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

Merged
camdecoster merged 32 commits into
v4.0from
cam/5192/add-min-max-scale-limits
Jun 26, 2026
Merged

feat: Add min/max scale limits for geo plots#7371
camdecoster merged 32 commits into
v4.0from
cam/5192/add-min-max-scale-limits

Conversation

camdecoster commented Feb 18, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

Description

Add minscale and maxscale attributes to geo plots. These set the min and max scale extents for a plot (how far a user can zoom out/in). This PR supersedes #5192 which will be closed after this is merged.

Changes

  • Adds minscale and maxscale attributes to geo plots. Defaults are 0 and -1, respectively.
  • Enforces scale extents on zoom mouse events, mode bar button clicks
  • Manually creates zoom event to enforce scale extents on first render (treating the middle of the plot as the zoom point)

Demo Video or Screenshot(s):

Before:

Screencast.From.2025-02-22.11-25-20.mp4

After:

Screencast.From.2025-02-22.11-29-21.mp4

Testing

  • Start the dev dashboard with npm start
  • Search for a geo mock and load it (I used geo_legendonly)
  • Zoom in and out and note how you can go as far as you want in either direction
  • Edit the mock file and add the following attributes under the "geo" key
    • "minscale": 2
    • "maxscale": 4
  • Reload the mock in the dashboard
  • Note that the mock appears zoomed in upon first load
  • Zoom in and out and note how you're now limited in how far you can go

camdecoster force-pushed the cam/5192/add-min-max-scale-limits branch from c7b5ec3 to 29b4316 Compare February 18, 2025 14:15
gvwilson added P1 needed for current cycle fix fixes something broken labels Feb 18, 2025

Copy link
Copy Markdown
Contributor Author

I believe that some tests are failing because there's now an extra zoom event on every call to updateFx (for dragMode === 'pan'). I think I need to restrict that call to only happen upon first load. I'll keep looking into it.

Copy link
Copy Markdown
Contributor Author

@archmoj this PR should now be good to review. We don't need both this and #7482. I'd like to argue that we should use the approach of using scaleExtent (the native D3 mechanism) rather than limiting the scale on our side.

archmoj commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

geo_canadian-cities

Thanks @camdecoster. My local test branch was not up-to-date. I confirm now it renders with no error.

archmoj commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

If you add

"projection": { "minscale": 0.5, "maxscale": 2 },

to geo_canadian-cities under "geo" object, the map renders smaller with gd._fullLayout.geo.projection.scale: 0.3013880580354019.

@camdecoster Could you please investigate that?

archmoj commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

If you add

"projection": { "minscale": 0.5, "maxscale": 2 },

to geo_canadian-cities under "geo" object, the map renders smaller with gd._fullLayout.geo.projection.scale: 0.3013880580354019.

@camdecoster Could you please investigate that?

Here is a codepen displaying the bug.

archmoj added feature something new and removed fix fixes something broken labels Jul 28, 2025

camdecoster commented Jun 8, 2026
edited
Loading

Copy link
Copy Markdown
Contributor Author

@archmoj would you be able to test your Codepen with the latest build?

archmoj commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@archmoj would you be able to test your Codepen with the latest build?

Hi @camdecoster,
Here is the updated codepen.
So the problem mentioned here is fixed.
Thank you! 💪

camdecoster removed their assignment Jun 9, 2026
camdecoster added this to the v4.0.0 milestone Jun 9, 2026
camdecoster changed the base branch from master to v4.0 June 23, 2026 20:17
Comment thread src/plots/geo/layout_attributes.js Outdated
Comment on lines +169 to +172
'Sets the minimum zoom level of the map view, relative to',
'`projection.scale`. A `minscale` of *0.5* (50%) prevents the',
'user from zooming out beyond half the base zoom level.',
'The default of *0* imposes no lower bound.'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could you edit these docstrings to make it clear what the min and max allowed values are? I suppose minscale can be a value between 0-1 (exclusive) and maxscale can be 1-infinity, but it would be helpful to state that explicitly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I updated these descriptions to include those values.

camdecoster merged commit 9901777 into v4.0 Jun 26, 2026
83 checks passed
camdecoster deleted the cam/5192/add-min-max-scale-limits branch June 26, 2026 19:38

Copy link
Copy Markdown
Contributor

Cool that this got merged! Thanks for picking up my commits 🎉

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature something new P1 needed for current cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow user to set zoom/scale limits for choropleth maps

5 participants


Back | FazBrowse Home | New Git URL