Changeset 3bdbfcc in sasview for src/sas/qtgui/Plotter.py


Ignore:
Timestamp:
Feb 2, 2017 6:29:07 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
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
Children:
965fbd8
Parents:
5d89f43
git-author:
Piotr Rozyczko <rozyczko@…> (01/23/17 07:21:03)
git-committer:
Piotr Rozyczko <rozyczko@…> (02/02/17 06:29:07)
Message:

Reimplementation of the slicer functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Plotter.py

    r092a3d9 r3bdbfcc  
    516516        self.plot(data=self.fit_result, marker='-', hide_error=True) 
    517517 
     518    def onMplMouseDown(self, event): 
     519        """ 
     520        Left button down and ready to drag 
     521        """ 
     522        # Check that the LEFT button was pressed 
     523        if event.button == 1: 
     524            self.leftdown = True 
     525            ax = event.inaxes 
     526            for text in self.textList: 
     527                if text.contains(event)[0]: # If user has clicked on text 
     528                    self.selectedText = text 
     529                    return 
     530 
     531            if ax != None: 
     532                self.xInit, self.yInit = event.xdata, event.ydata 
     533                try: 
     534                    self.x_click = float(event.xdata)  # / size_x 
     535                    self.y_click = float(event.ydata)  # / size_y 
     536                except: 
     537                    self.position = None 
     538 
     539    def onMplMouseUp(self, event): 
     540        """ 
     541        Set the data coordinates of the click 
     542        """ 
     543        self.x_click = event.xdata 
     544        self.y_click = event.ydata 
     545 
     546        # Check that the LEFT button was released 
     547        if event.button == 1: 
     548            self.leftdown = False 
     549            #self.leftup = True 
     550            self.selectedText = None 
     551 
     552        #release the legend 
     553        if self.gotLegend == 1: 
     554            self.gotLegend = 0 
     555 
     556    def onMplMouseMotion(self, event): 
     557        """ 
     558        Check if the left button is press and the mouse in moving. 
     559        Compute delta for x and y coordinates and then perform the drag 
     560        """ 
     561        if self.gotLegend == 1 and self.leftdown: 
     562            self.onLegendMotion(event) 
     563            return 
     564 
     565        if self.leftdown and self.selectedText is not None: 
     566            # User has clicked on text and is dragging 
     567            ax = event.inaxes 
     568            if ax != None: 
     569                # Only move text if mouse is within axes 
     570                self.selectedText.set_position((event.xdata, event.ydata)) 
     571                self.canvas.draw_idle() 
     572            else: 
     573                # User has dragged outside of axes 
     574                self.selectedText = None 
     575            return 
     576 
     577    def onMplPick(self, event): 
     578        """ 
     579        On pick legend 
     580        """ 
     581        legend = self.legend 
     582        if event.artist == legend: 
     583            # Get the box of the legend. 
     584            bbox = self.legend.get_window_extent() 
     585            # Get mouse coordinates at time of pick. 
     586            self.mouse_x = event.mouseevent.x 
     587            self.mouse_y = event.mouseevent.y 
     588            # Get legend coordinates at time of pick. 
     589            self.legend_x = bbox.xmin 
     590            self.legend_y = bbox.ymin 
     591            # Indicate we picked up the legend. 
     592            self.gotLegend = 1 
     593 
     594            #self.legend.legendPatch.set_alpha(0.5) 
     595 
     596    def onLegendMotion(self, event): 
     597        """ 
     598        On legend in motion 
     599        """ 
     600        ax = event.inaxes 
     601        if ax == None: 
     602            return 
     603        # Event occurred inside a plotting area 
     604        lo_x, hi_x = ax.get_xlim() 
     605        lo_y, hi_y = ax.get_ylim() 
     606        # How much the mouse moved. 
     607        x = mouse_diff_x = self.mouse_x - event.x 
     608        y = mouse_diff_y = self.mouse_y - event.y 
     609        # Put back inside 
     610        if x < lo_x: 
     611            x = lo_x 
     612        if x > hi_x: 
     613            x = hi_x 
     614        if y < lo_y: 
     615            y = lo_y 
     616        if y > hi_y: 
     617            y = hi_y 
     618        # Move the legend from its previous location by that same amount 
     619        loc_in_canvas = self.legend_x - mouse_diff_x, \ 
     620                        self.legend_y - mouse_diff_y 
     621        # Transform into legend coordinate system 
     622        trans_axes = self.legend.parent.transAxes.inverted() 
     623        loc_in_norm_axes = trans_axes.transform_point(loc_in_canvas) 
     624        self.legend_pos_loc = tuple(loc_in_norm_axes) 
     625        self.legend._loc = self.legend_pos_loc 
     626        # self.canvas.draw() 
     627        self.canvas.draw_idle() 
     628 
     629    def onMplWheel(self, event): 
     630        """ 
     631        Process mouse wheel as zoom events 
     632        """ 
     633        ax = event.inaxes 
     634        step = event.step 
     635 
     636        if ax != None: 
     637            # Event occurred inside a plotting area 
     638            lo, hi = ax.get_xlim() 
     639            lo, hi = PlotUtilities.rescale(lo, hi, step, 
     640                              pt=event.xdata, scale=ax.get_xscale()) 
     641            if not self.xscale == 'log' or lo > 0: 
     642                self._scale_xlo = lo 
     643                self._scale_xhi = hi 
     644                ax.set_xlim((lo, hi)) 
     645 
     646            lo, hi = ax.get_ylim() 
     647            lo, hi = PlotUtilities.rescale(lo, hi, step, pt=event.ydata, 
     648                              scale=ax.get_yscale()) 
     649            if not self.yscale == 'log' or lo > 0: 
     650                self._scale_ylo = lo 
     651                self._scale_yhi = hi 
     652                ax.set_ylim((lo, hi)) 
     653        else: 
     654            # Check if zoom happens in the axes 
     655            xdata, ydata = None, None 
     656            x, y = event.x, event.y 
     657 
     658            for ax in self.axes: 
     659                insidex, _ = ax.xaxis.contains(event) 
     660                if insidex: 
     661                    xdata, _ = ax.transAxes.inverted().transform_point((x, y)) 
     662                insidey, _ = ax.yaxis.contains(event) 
     663                if insidey: 
     664                    _, ydata = ax.transAxes.inverted().transform_point((x, y)) 
     665            if xdata is not None: 
     666                lo, hi = ax.get_xlim() 
     667                lo, hi = PlotUtilities.rescale(lo, hi, step, 
     668                                  bal=xdata, scale=ax.get_xscale()) 
     669                if not self.xscale == 'log' or lo > 0: 
     670                    self._scale_xlo = lo 
     671                    self._scale_xhi = hi 
     672                    ax.set_xlim((lo, hi)) 
     673            if ydata is not None: 
     674                lo, hi = ax.get_ylim() 
     675                lo, hi = PlotUtilities.rescale(lo, hi, step, bal=ydata, 
     676                                  scale=ax.get_yscale()) 
     677                if not self.yscale == 'log' or lo > 0: 
     678                    self._scale_ylo = lo 
     679                    self._scale_yhi = hi 
     680                    ax.set_ylim((lo, hi)) 
     681        self.canvas.draw_idle() 
     682 
    518683 
    519684class Plotter(QtGui.QDialog, PlotterWidget): 
Note: See TracChangeset for help on using the changeset viewer.