~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to enthought/chaco/tools/drag_zoom.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-06 19:03:54 UTC
  • mfrom: (7.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110406190354-rwd55l2ezjecfo41
Tags: 3.4.0-2
d/rules: fix pyshared directory path (Closes: #621116)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from enthought.traits.api import Bool, Enum, Float, Tuple
7
7
 
8
8
# Chaco imports
9
 
from base_zoom_tool import BaseZoomTool
10
 
 
11
 
 
12
 
class DragZoom(DragTool, BaseZoomTool):
 
9
from better_zoom import BetterZoom
 
10
 
 
11
 
 
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.
15
15
 
48
48
    # Whether to restrict zoom to the domain of the mappers
49
49
    restrict_domain = Bool(False)
50
50
 
 
51
    zoom_to_mouse = Bool(False)
 
52
    
51
53
    #------------------------------------------------------------------------------
52
54
    # Private traits
53
55
    #------------------------------------------------------------------------------
78
80
 
79
81
        # Compute the zoom amount based on the pixel difference between
80
82
        # the previous mouse event and the current one.
 
83
                
81
84
        if self.maintain_aspect_ratio:
82
85
            zoom_x = zoom_y = self._calc_zoom(self._prev_y, event.y)
83
86
        else:
84
87
            zoom_x = self._calc_zoom(self._prev_x, event.x)
85
88
            zoom_y = self._calc_zoom(self._prev_y, event.y)
86
 
 
87
 
        c = self.component
88
 
        low_pt, high_pt = self._map_coordinate_box((c.x, c.y), (c.x2, c.y2))
89
 
 
90
 
        # The original screen bounds are used to test if we've reached max_zoom
91
 
        orig_low, orig_high = self._orig_screen_bounds
92
 
 
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():
97
 
                continue
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)
101
 
            
102
 
            ol, oh = orig_low[ndx], orig_high[ndx]
103
 
            if self._zoom_limit_reached(ol, oh, newlow, newhigh):
104
 
                event.handled = True
105
 
                return
106
 
 
107
 
            # prohibit zooming outside the domain of the axis
108
 
            if self.restrict_domain:
109
 
                if newlow > newhigh:
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:
114
 
                    newlow = domain_min
115
 
                if domain_max is not None and newhigh > domain_max:
116
 
                    newhigh = domain_max
117
 
            
118
 
            datarange.set_bounds(newlow, newhigh)
119
 
       
120
 
        self._prev_y = event.y
121
 
        self._prev_x = event.x
122
 
        event.handled = True
123
 
        self.component.request_redraw()
 
89
            
 
90
        # invert the zoom so scrolling up zooms in
 
91
        zoom_x = 1.0/zoom_x
 
92
        zoom_y = 1.0/zoom_y
 
93
            
 
94
        self.zoom_in_x(zoom_x)
 
95
        self.zoom_in_y(zoom_y)
 
96
        
124
97
        return
125
98
 
126
99
    def drag_start(self, event, capture_mouse=True):
150
123
        # We express the built-in zoom scaling as 0.05/10 to indicate a scaling
151
124
        # of 5% every 10 pixels, per the docstring for the 'speed' trait.
152
125
        return 1.0 - self.speed * (clicked - original) * (0.05/10)
153