-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Move pixel ratio handling into FigureCanvasBase #19126
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,10 +138,6 @@ def __init__(self, *args, **kwargs): | |
# to the connected clients. | ||
self._current_image_mode = 'full' | ||
|
||
# Store the DPI ratio of the browser. This is the scaling that | ||
# occurs automatically for all images on a HiDPI display. | ||
self._dpi_ratio = 1 | ||
|
||
def show(self): | ||
# show the figure window | ||
from matplotlib.pyplot import show | ||
|
@@ -311,8 +307,8 @@ def handle_refresh(self, event): | |
self.draw_idle() | ||
|
||
def handle_resize(self, event): | ||
x, y = event.get('width', 800), event.get('height', 800) | ||
x, y = int(x) * self._dpi_ratio, int(y) * self._dpi_ratio | ||
x = int(event.get('width', 800)) * self.device_pixel_ratio | ||
y = int(event.get('height', 800)) * self.device_pixel_ratio | ||
fig = self.figure | ||
# An attempt at approximating the figure size in pixels. | ||
fig.set_size_inches(x / fig.dpi, y / fig.dpi, forward=False) | ||
|
@@ -327,14 +323,15 @@ def handle_send_image_mode(self, event): | |
# The client requests notification of what the current image mode is. | ||
self.send_event('image_mode', mode=self._current_image_mode) | ||
|
||
def handle_set_device_pixel_ratio(self, event): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess these handlers are effectively private and we reserve the right to change them as we see fit with no deprecation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, but I would say so. They're tied directly with the JavaScript side of the implementation, and I don't think we've ever guaranteed anything there. In this case, it's only a rename for consistency's sake, so I could revert it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will likely require a change in ipympl, but I think we should make the changes to keep the function names consistent (in this case). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I restored the handler for |
||
self._handle_set_device_pixel_ratio(event.get('device_pixel_ratio', 1)) | ||
|
||
def handle_set_dpi_ratio(self, event): | ||
dpi_ratio = event.get('dpi_ratio', 1) | ||
if dpi_ratio != self._dpi_ratio: | ||
# We don't want to scale up the figure dpi more than once. | ||
if not hasattr(self.figure, '_original_dpi'): | ||
self.figure._original_dpi = self.figure.dpi | ||
self.figure.dpi = dpi_ratio * self.figure._original_dpi | ||
self._dpi_ratio = dpi_ratio | ||
# This handler is for backwards-compatibility with older ipympl. | ||
self._handle_set_device_pixel_ratio(event.get('dpi_ratio', 1)) | ||
|
||
def _handle_set_device_pixel_ratio(self, device_pixel_ratio): | ||
if self._set_device_pixel_ratio(device_pixel_ratio): | ||
self._force_full = True | ||
self.draw_idle() | ||
|
||
|
@@ -426,7 +423,8 @@ def _get_toolbar(self, canvas): | |
def resize(self, w, h, forward=True): | ||
self._send_event( | ||
'resize', | ||
size=(w / self.canvas._dpi_ratio, h / self.canvas._dpi_ratio), | ||
size=(w / self.canvas.device_pixel_ratio, | ||
h / self.canvas.device_pixel_ratio), | ||
forward=forward) | ||
|
||
def set_window_title(self, title): | ||
|
Uh oh!
There was an error while loading. Please reload this page.