Skip to content

Commit 3370d55

Browse files
committed
fix wheel zoom
1 parent 8394fc0 commit 3370d55

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

plotpy/events.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -915,18 +915,23 @@ def get_zoom_param(
915915
Returns two tuples of four floats each, representing the parameters used
916916
by BasePlot.do_zoom_view.
917917
"""
918-
rect_width = plot.contentsRect().width()
918+
919+
x, y = pos.x(), pos.y()
920+
rect = plot.contentsRect()
921+
w, h = rect.width(), rect.height()
922+
print(f"x: {x} -> {x + w * factor}")
923+
print(f"y: {y} -> {y + w * factor}")
919924
dx = (
920-
pos.x() * factor,
921-
pos.x(),
922-
pos.x(),
923-
rect_width,
925+
x + (w * factor),
926+
x,
927+
x,
928+
w,
924929
)
925930
dy = (
926-
pos.y() * factor,
927-
pos.y(),
928-
pos.y(),
929-
rect_width,
931+
y + (h * factor),
932+
y,
933+
y,
934+
h,
930935
)
931936
return dx, dy
932937

@@ -941,15 +946,16 @@ def wheel(self, filter: StatefulEventFilter, event: QG.QWheelEvent):
941946
"""
942947
plot = filter.plot
943948
zoom_step = event.angleDelta().y() / 120
944-
zoom_factor = np.log10(10 + abs(zoom_step * 8))
949+
zoom_factor = np.log10(10 + abs(zoom_step * 2))
945950
if zoom_step < 0:
946951
zoom_factor = 1 / zoom_factor
952+
zoom_factor -= 1
947953

948954
center_point = event.globalPos()
949955
center_point = filter.plot.canvas().mapFromGlobal(center_point) # type: ignore
950956

951957
dx, dy = self.get_zoom_param(plot, center_point, zoom_factor)
952-
plot.do_zoom_view(dx, dy)
958+
plot.do_zoom_view(dx, dy, lock_aspect_ratio=True)
953959

954960

955961
class QtDragHandler(DragHandler):

0 commit comments

Comments
 (0)