Changeset 6ed101a in sasview for guitools/PlotPanel.py


Ignore:
Timestamp:
Apr 29, 2008 5:40:18 PM (16 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
47f695c9
Parents:
f193585
Message:

more modification ..zoom is still bugging for logx logy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/PlotPanel.py

    rf193585 r6ed101a  
    6767        # keep track if the previous transformation of x and y in Property dialog 
    6868        self.prevXtrans =" " 
    69          
    7069        self.prevYtrans =" " 
    71          
     70        self.canvas.mpl_connect('scroll_event',self.onWheel) 
     71    def _rescale(lo,hi,step,pt=None,bal=None,scale='linear'): 
     72        """ 
     73        Rescale (lo,hi) by step, returning the new (lo,hi) 
     74        The scaling is centered on pt, with positive values of step 
     75        driving lo/hi away from pt and negative values pulling them in. 
     76        If bal is given instead of point, it is already in [0,1] coordinates. 
     77     
     78        This is a helper function for step-based zooming. 
     79        """ 
     80        # Convert values into the correct scale for a linear transformation 
     81        # TODO: use proper scale transformers 
     82        if scale=='log': 
     83            lo,hi = log10(lo),log10(hi) 
     84            if pt is not None: pt = log10(pt) 
     85     
     86        # Compute delta from axis range * %, or 1-% if persent is negative 
     87        if step > 0: 
     88            delta = float(hi-lo)*step/100 
     89        else: 
     90            delta = float(hi-lo)*step/(100-step) 
     91     
     92        # Add scale factor proportionally to the lo and hi values, preserving the 
     93        # point under the mouse 
     94        if bal is None: 
     95            bal = float(pt-lo)/(hi-lo) 
     96        lo = lo - bal*delta 
     97        hi = hi + (1-bal)*delta 
     98     
     99        # Convert transformed values back to the original scale 
     100        if scale=='log': 
     101            lo,hi = pow(10.,lo),pow(10.,hi) 
     102     
     103        return (lo,hi) 
     104 
     105    def onWheel(self, event): 
     106        """ 
     107        Process mouse wheel as zoom events 
     108        """ 
     109        ax = event.inaxes 
     110        step = event.step 
     111 
     112        if ax != None: 
     113            # Event occurred inside a plotting area 
     114            lo,hi = ax.get_xlim() 
     115            lo,hi = _rescale(lo,hi,step,pt=event.xdata) 
     116            ax.set_xlim((lo,hi)) 
     117 
     118            lo,hi = ax.get_ylim() 
     119            lo,hi = _rescale(lo,hi,step,pt=event.ydata) 
     120            ax.set_ylim((lo,hi)) 
     121        else: 
     122            # Check if zoom happens in the axes 
     123            xdata,ydata = None,None 
     124            x,y = event.x,event.y 
     125            for ax in self.axes: 
     126                insidex,_ = ax.xaxis.contains(event) 
     127                if insidex: 
     128                    xdata,_ = ax.transAxes.inverse_xy_tup((x,y)) 
     129                    #print "xaxis",x,"->",xdata 
     130                insidey,_ = ax.yaxis.contains(event) 
     131                if insidey: 
     132                    _,ydata = ax.transAxes.inverse_xy_tup((x,y)) 
     133                    #print "yaxis",y,"->",ydata 
     134            if xdata is not None: 
     135                lo,hi = ax.get_xlim() 
     136                lo,hi = _rescale(lo,hi,step,bal=xdata) 
     137                ax.set_xlim((lo,hi)) 
     138            if ydata is not None: 
     139                lo,hi = ax.get_ylim() 
     140                lo,hi = _rescale(lo,hi,step,bal=ydata) 
     141                ax.set_ylim((lo,hi)) 
     142 
     143        self.canvas.draw_idle() 
     144 
     145 
    72146    def returnTrans(self): 
    73147        return self.xscales,self.yscales 
     
    265339        self.subplot.clear() 
    266340        self.subplot.hold(True) 
    267          
     341     
    268342    def render(self): 
    269343        """Commit the plot after all objects are drawn""" 
Note: See TracChangeset for help on using the changeset viewer.