6
6
from enthought.traits.api import Bool, Enum, Float, Tuple
9
from base_zoom_tool import BaseZoomTool
12
class DragZoom(DragTool, BaseZoomTool):
9
from better_zoom import BetterZoom
12
class DragZoom(DragTool, BetterZoom):
13
13
""" A zoom tool that zooms continuously with a mouse drag movement, instead
14
14
of using a zoom box or range.
48
48
# Whether to restrict zoom to the domain of the mappers
49
49
restrict_domain = Bool(False)
51
zoom_to_mouse = Bool(False)
51
53
#------------------------------------------------------------------------------
53
55
#------------------------------------------------------------------------------
79
81
# Compute the zoom amount based on the pixel difference between
80
82
# the previous mouse event and the current one.
81
84
if self.maintain_aspect_ratio:
82
85
zoom_x = zoom_y = self._calc_zoom(self._prev_y, event.y)
84
87
zoom_x = self._calc_zoom(self._prev_x, event.x)
85
88
zoom_y = self._calc_zoom(self._prev_y, event.y)
88
low_pt, high_pt = self._map_coordinate_box((c.x, c.y), (c.x2, c.y2))
90
# The original screen bounds are used to test if we've reached max_zoom
91
orig_low, orig_high = self._orig_screen_bounds
93
datarange_list = [(0, c.x_mapper, zoom_x), (1, c.y_mapper, zoom_y)]
94
for ndx, mapper, zoom in datarange_list:
95
datarange = mapper.range
96
if self.single_axis and ndx != self._determine_axis():
98
mouse_val = self._original_data[ndx]
99
newlow = mouse_val - zoom * (mouse_val - low_pt[ndx])
100
newhigh = mouse_val + zoom * (high_pt[ndx] - mouse_val)
102
ol, oh = orig_low[ndx], orig_high[ndx]
103
if self._zoom_limit_reached(ol, oh, newlow, newhigh):
107
# prohibit zooming outside the domain of the axis
108
if self.restrict_domain:
110
# This happens when the orientation of the axis is reversed.
111
newlow, newhigh = newhigh, newlow
112
domain_min, domain_max = getattr(mapper, "domain_limits", (None,None))
113
if domain_min is not None and newlow < domain_min:
115
if domain_max is not None and newhigh > domain_max:
118
datarange.set_bounds(newlow, newhigh)
120
self._prev_y = event.y
121
self._prev_x = event.x
123
self.component.request_redraw()
90
# invert the zoom so scrolling up zooms in
94
self.zoom_in_x(zoom_x)
95
self.zoom_in_y(zoom_y)
126
99
def drag_start(self, event, capture_mouse=True):