Skip to content
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

add support for min/max scale limits #5192

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

mojoaxel
Copy link
Contributor

@mojoaxel mojoaxel commented Oct 5, 2020

Resolves #5191

This is my first contribution to this repository. Please review this contribution thoroughly! I'm especially not sure if I thought of every edge case of all geo-charts and their parameters.

@archmoj archmoj added community community contribution feature something new labels Oct 5, 2020
@mojoaxel mojoaxel force-pushed the 5191-geo-zoom-limit branch from 071e21b to e722947 Compare October 6, 2020 20:17
@mojoaxel
Copy link
Contributor Author

mojoaxel commented Oct 7, 2020

I could use some help on how to tackle the failed tests in the ci. I tried to run the tests locally but got too many errors.

@mojoaxel
Copy link
Contributor Author

@archmoj Thanks for reviewing this!

@@ -533,8 +533,18 @@ function handleGeo(gd, ev) {

if(attr === 'zoom') {
var scale = geoLayout.projection.scale;
var minscale = geoLayout.projection.minscale;
var maxscale = geoLayout.projection.maxscale;
Copy link
Contributor

Choose a reason for hiding this comment

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

Now we need to handle

if(maxscale === null) maxscale = Infinity;

or

if(maxscale === -1) maxscale = Infinity;

if we decide to use -1 instead of null which is not a number.
@alexcjohnson your idea on which one is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With e722947 I changed the default to -1 instead of null. Scales with less than 0 make no sense here so this should be a valid solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose -1 as a default is OK if we really need a "no max" value - it's better than null which behaves oddly in relayout.

But I wonder if we can't pick a decent default that's more zoomed in than is generally ever useful. I have occasionally gotten in a situation by accidentally scroll zooming so far in that everything freezes up because the SVG engine is having trouble drawing all the off-screen elements. If we cover 99% of cases and avoid this pitfall I'd say that's a reasonable tradeoff, and avoids making a coded value. Something like 10,000?

Similarly, is there a default we could use for minscale, to avoid zooming the whole map away to a point? 0.1 perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like 10,000?
Similarly, is there a default we could use for minscale, to avoid zooming the whole map away to a point? 0.1 perhaps?

Makes sense!
(I'll have a look tomorrow. It's getting late her in europe 😴)

minscale: {
valType: 'number',
role: 'info',
min: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't minscale have a max range of 1?

Copy link
Contributor Author

@mojoaxel mojoaxel Oct 26, 2020

Choose a reason for hiding this comment

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

I don't think so. Maybe it also make sense in some circumstances to only allow scaling between e.g. 2..3.

Then of course the initial scale should also set so one value between 2..3. This check is still missing! What would be a good place to check if scale is within the given min/max bounds and reset it otherwise? Is layout_defaults.js the right place?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, layout_defaults is the right place - note that coerce returns the set value. Also we should check that minscale <= maxscale

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also we probably need to check when the scale is automatically determined from the contents of the map whether it's within these bounds, and push it into the range if not. I'm not quite sure where that happens, possibly multiple places in geo.js depending on the situation.

@archmoj
Copy link
Contributor

archmoj commented Oct 27, 2020

Right now if I set minscale and maxscaleto 1, I expect the graph not to be scaled. However, usingwheel` scroll zoom the scale changes once.
To fix that you should likely constrain scales in this function as well:

function handleZoom() {
projection
.scale(d3.event.scale)
.translate(d3.event.translate);
geo.render();
var center = projection.invert(geo.midPt);
geo.graphDiv.emit('plotly_relayouting', {
'geo.projection.scale': projection.scale() / geo.fitScale,
'geo.center.lon': center[0],
'geo.center.lat': center[1]
});
}

@archmoj
Copy link
Contributor

archmoj commented Nov 4, 2020

@mojoaxel we are planning next plotly.js minor (possibly next week) to include new features like this one.
Do you have time to address the remaining comments, so that we could include this feature?

@mojoaxel
Copy link
Contributor Author

mojoaxel commented Nov 4, 2020

Right now if I set minscale and maxscaleto 1, I expect the graph not to be scaled. However, usingwheel` scroll zoom the scale changes once.

I had a look at this a few days ago. That looks like a d3 issue to me. I could not figure it out.

To fix that you should likely constrain scales in this function as well:

I tried that code and it gets not called at all.

@mojoaxel we are planning next plotly.js minor (possibly next week) to include new features like this one.
Do you have time to address the remaining comments, so that we could include this feature?

Cool, I'll try to look into the open issues today, but I'm not sure that I'll manage to fix the open issues (alone).

@archmoj Feel free to take my code, fix it and create your own pull-request. At the moment I don't have the time to dive deep into this complex codebase.

@nicolaskruchten
Copy link
Contributor

A small update on timing: our team is working hard on releasing v2.0 of Plotly.js, which we anticipate will happen in early April. This PR would be a good candidate to land in the library in v2.1 or later, so with apologies for the delay, we will likely not be able to give much feedback on this PR for the next few weeks :)

@gvwilson gvwilson self-assigned this Jun 10, 2024
@gvwilson
Copy link
Contributor

This pull request has been sitting for a while, so I would like to close it as part of our effort to tidy up our public repositories. I've assigned it to myself to keep track of it; I'll wait until 2024-06-17 for someone to say it's still relevant and they'll to take it on, and otherwise I will close it then. Thanks - @gvwilson

@mojoaxel mojoaxel force-pushed the 5191-geo-zoom-limit branch 3 times, most recently from 1dfbb3a to bcc3fab Compare June 10, 2024 21:58
@mojoaxel mojoaxel force-pushed the 5191-geo-zoom-limit branch from bcc3fab to c42cb9d Compare June 10, 2024 21:59
@mojoaxel
Copy link
Contributor Author

I'll wait until 2024-06-17 for someone to say it's still relevant and they'll to take it on, and otherwise I will close it then.

I still would love to see this merged. I rebased on the current master but I could use some help with the test.

At the moment I would consider this still work-in-progress. I'll try to finish this until 2024-06-17.

@gvwilson
Copy link
Contributor

thanks very much @mojoaxel - much appreciated.

@gvwilson gvwilson assigned marthacryan and unassigned gvwilson Jun 26, 2024
@gvwilson gvwilson added P2 considered for next cycle and removed status: has TODOs labels Aug 8, 2024
@camdecoster camdecoster self-assigned this Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution feature something new P2 considered for next cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow user to set zoom/scale limits for choropleth maps
7 participants