Changeset 057210c in sasview for guitools


Ignore:
Timestamp:
Mar 17, 2008 8:10:20 AM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
4e290cd
Parents:
2bf92f2
Message:

Added a View class and an example

Location:
guitools
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • guitools/PlotPanel.py

    r2bf92f2 r057210c  
    1010from canvas import FigureCanvas 
    1111#TODO: make the plottables interactive 
     12from plottables import Graph 
    1213 
    1314def show_tree(obj,d=0): 
     
    4647        self.SetSizer(sizer) 
    4748 
    48  
     49        # Graph object to manage the plottables 
     50        self.graph = Graph() 
    4951         
    5052        self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 
  • guitools/plottables.py

    r2bf92f2 r057210c  
    123123        """Properties of the y axis. 
    124124        """ 
    125         if self.prop["xunit"] and units != self.prop["xunit"]: 
     125        if self.prop["yunit"] and units != self.prop["yunit"]: 
    126126            pass 
    127127            #print "Plottable: how do we handle non-commensurate units" 
    128128        self.prop["ylabel"] = "%s (%s)"%(name,units) 
    129         self.prop["xunit"] = units 
     129        self.prop["yunit"] = units 
    130130         
    131131    def title(self,name): 
     
    348348        """Return the number of colors need to render the object""" 
    349349        return 1 
    350  
     350     
     351    class View: 
     352        """ 
     353            Representation of the data that might include a transformation 
     354        """ 
     355        x = None 
     356        y = None 
     357        dx = None 
     358        dy = None 
     359         
     360        def __init__(self, x=None, y=None, dx=None, dy=None): 
     361            self.x = x 
     362            self.y = y 
     363            self.dx = dx 
     364            self.dy = dy 
     365             
     366        def transform_x(self, func, errfunc, x, dx): 
     367            """ 
     368                Transforms the x and dx vectors and stores the output. 
     369                 
     370                @param func: function to apply to the data 
     371                @param x: array of x values 
     372                @param dx: array of error values 
     373                @param errfunc: function to apply to errors 
     374            """ 
     375            import copy 
     376            # Sanity check 
     377            if dx and not len(x)==len(dx): 
     378                raise ValueError, "Plottable.View: Given x and dx are not of the same length" 
     379             
     380            self.x  = deepcopy(x) 
     381            self.dx = deepcopy(dx) 
     382             
     383            for i in range(len(x)): 
     384                 self.x[i] = func(x[i]) 
     385                 self.dx[i] = errfunc(dx[i]) 
     386                       
     387        def transform_y(self, func, errfunc, y, dy): 
     388            """ 
     389                Transforms the x and dx vectors and stores the output. 
     390                 
     391                @param func: function to apply to the data 
     392                @param y: array of y values 
     393                @param dy: array of error values 
     394                @param errfunc: function to apply to errors 
     395            """ 
     396            import copy 
     397            # Sanity check 
     398            if dy and not len(y)==len(dy): 
     399                raise ValueError, "Plottable.View: Given y and dy are not of the same length" 
     400             
     401            self.y  = deepcopy(y) 
     402            self.dy = deepcopy(dy) 
     403             
     404            for i in range(len(y)): 
     405                 self.y[i] = func(y[i]) 
     406                 self.dy[i] = errfunc(dy[i]) 
     407                       
     408         
    351409 
    352410class Data1D(Plottable): 
     
    362420        The label, if it is different, appears on the status bar. 
    363421        """ 
     422        self.name = "data" 
    364423        self.x = x 
    365424        self.y = y 
    366425        self.dx = dx 
    367426        self.dy = dy 
     427         
     428        self.view = self.View(self.x, self.y, self.dx, self.dy) 
    368429 
    369430    def render(self,plot,**kw): 
    370         Plottable.render(self,plot) 
    371         plot.points(self.x,self.y,dx=self.dx,dy=self.dy,**kw) 
     431        plot.points(self.view.x,self.view.y,dx=self.view.dx,dy=self.view.dy,**kw) 
    372432 
    373433    def changed(self): 
    374434        return False 
    375435 
     436    @classmethod 
     437    def labels(cls, collection): 
     438        """Build a label mostly unique within a collection""" 
     439        map = {} 
     440        for item in collection: 
     441            #map[item] = label(item, collection) 
     442            map[item] = r"$\rm{%s}$" % item.name 
     443        return map 
    376444     
    377445class Theory1D(Plottable): 
Note: See TracChangeset for help on using the changeset viewer.