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

Fix ImagePlot subpixel cases when zoomed and panned to an edge #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions chaco/image_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,17 @@ def _calc_zoom_coords(self, px, py, plot_width, plot_height,
yparams = (1, 3)
for pos_index, size_index in (xparams, yparams):
if subimage_index[pos_index] == subimage_index[pos_index+2]-1:
# xcoords lie inside the same pixel, so set the subimage
# coords to be the width of the image
subimage_coords[pos_index] = plot_dimensions[pos_index]
subimage_coords[size_index] = plot_dimensions[size_index]
# coords lie inside the same pixel, so can clamp subimage_coords
# to the plot bounds
clamped_min = max(subimage_coords[pos_index],
plot_dimensions[pos_index])

si_max = subimage_coords[pos_index] + subimage_coords[size_index]
plot_max = plot_dimensions[pos_index] + plot_dimensions[size_index]
clamped_max = min(si_max, plot_max)

subimage_coords[pos_index] = clamped_min
subimage_coords[size_index] = clamped_max - clamped_min
elif subimage_index[pos_index] == subimage_index[pos_index+2]-2:
# coords span across a pixel boundary. Find the scaling
# factor of the virtual (and potentially large) subimage
Expand All @@ -300,12 +307,17 @@ def _calc_zoom_coords(self, px, py, plot_width, plot_height,
# entire screen, since we are only straddling one pixel boundary.
# The formula for calculating the new origin can be worked out
# on paper.
#
# Panning to near an edge so only one transition is visible
# causes an attempt to scale up the subimage_coords, so we
# guard against that case too.
extent = subimage_coords[size_index]
pixel_extent = extent/2 # we are indexed into two pixels
origin = subimage_coords[pos_index]
scale = float(2 * plot_dimensions[size_index] / extent)
subimage_coords[size_index] *= scale
subimage_coords[pos_index] = origin + (1-scale)*pixel_extent
if scale < 1:
subimage_coords[size_index] *= scale
subimage_coords[pos_index] = origin + (1-scale)*pixel_extent

subimage_index = map(int, subimage_index)

Expand Down