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

Zoom: Why two ways to do the same thing? #144

Closed
pllim opened this issue Jul 6, 2021 · 6 comments
Closed

Zoom: Why two ways to do the same thing? #144

pllim opened this issue Jul 6, 2021 · 6 comments
Labels
question Further information is requested

Comments

@pllim
Copy link
Member

pllim commented Jul 6, 2021

There can be only one.

@zoom_level.setter
def zoom_level(self, val):
if val == 'fit':
self._viewer.zoom_fit()
else:
self._viewer.scale_to(val, val)
def zoom(self, val):
"""
Zoom in or out by the given factor.
Parameters
----------
val : int
The zoom level to zoom the image.
See `zoom_level`.
"""
self.zoom_level = self.zoom_level * val

@pllim pllim added the question Further information is requested label Jul 6, 2021
@mwcraig
Copy link
Member

mwcraig commented Jul 6, 2021

I think these are two different operations, though arguably the names could be better.

zoom_level: a specific zoom relative to the scale (1 screen pixel) = (1 image pixel)

zoom: a factor by which to change the current zoom_level, e.g. "I want to zoom in another factor 1.5" . A better name might be zoom_by.

@pllim
Copy link
Member Author

pllim commented Jul 7, 2021

But do we need both? 🤔

@mwcraig
Copy link
Member

mwcraig commented Jul 7, 2021

I think we do in the context of user interactions. Imagine you have been doing some zoom in/zoom out by mouse or scroll wheel or whatever. You probably have no idea what your current zoom_level is but might know that you want to zoom by additional factor in or out.

One could calculate the new zoom_level manually but that seems cumbersome.

The other difference I see between them is that zoom_level is part of the state of the view/a property and zoom is an action/method.

@pllim
Copy link
Member Author

pllim commented Jul 7, 2021

So, should we remove the zoom_level setter and make it read-only?

@mwcraig
Copy link
Member

mwcraig commented Jul 7, 2021

I'm inclined not to because I see setting a specific level and zooming by a particular factor as different things. In a widget implementation, allowing zoom_level to be settable in the API means it is fine to make it a traitlet, which makes it easy to link the zoom level of two browsers.

@pllim
Copy link
Member Author

pllim commented Jul 7, 2021

Ah, gotcha...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants