Index: guitools/PropertyDialog.py
===================================================================
--- guitools/PropertyDialog.py	(revision e2914b14919b7507085cdb12782a84ad78e53105)
+++ guitools/PropertyDialog.py	(revision 57896544f08828746f936a04451449e4a91450e1)
@@ -26,8 +26,8 @@
         iy += 1
         ix = 1
-        self.xvalue = wx.ComboBox(panel, -1, size=(60, -1))
+        self.xvalue = wx.ComboBox(panel, -1)
         sizer.Add(self.xvalue,(iy,ix))
         ix +=2
-        self.yvalue = wx.ComboBox(panel, -1, size=(60, -1))
+        self.yvalue = wx.ComboBox(panel, -1)
         sizer.Add( self.yvalue,(iy, ix))
         ix +=2
@@ -53,4 +53,8 @@
         self.yvalue.Insert("Log(y)",1)
         self.yvalue.Insert("y^(2)",2)
+        self.yvalue.Insert("1/y",3)
+        self.yvalue.Insert("1/sqrt(y)",4)
+        self.yvalue.Insert("Log(y*x)",5)
+        self.yvalue.Insert("Log(y*x^(2))",6)
         
         panel.SetSizer(sizer)
Index: guitools/fitDialog.py
===================================================================
--- guitools/fitDialog.py	(revision 1bde57aff2ddf3ac43c0e3c981900f34dbae9cc0)
+++ guitools/fitDialog.py	(revision 57896544f08828746f936a04451449e4a91450e1)
@@ -89,5 +89,5 @@
         # new data for the fit 
         self.file_data1 = Theory1D(x=[], y=[], dy=None)
-        self.file_data1.name = "y= exp(A + bx**2)"
+        self.file_data1.name = "Fit"
         
     def _onFit(self ,event):
@@ -95,11 +95,10 @@
         print "we are on fit"
         temp =[]
-        tempdx =[]
-        tempdy =[]
         xmin = self._checkVal(self.tcXmin.GetValue())
         xmax = self._checkVal(self.tcXmax.GetValue())
-        #x= self.plottable.view.x
-        x=self.plottable.returnXvalueOfView()
-        print "x value :" ,x
+        
+        #store the values of View in x,y, dx,dy
+        x,y,dx,dy=self.plottable.returnValuesOfView()
+       
         if x != []:
             if xmin !=None  and xmax != None:
@@ -107,5 +106,5 @@
                     if x[j]>xmin and x[j]<xmax:
                         temp.append(self.model.run(x[j]))
-                        #tempdx.append(math.sqrt(x[j]))
+                    
                         for y_i in temp:
                             tempdy.append(math.sqrt(y_i)) 
@@ -114,7 +113,5 @@
                 for x_i in x:
                     temp.append(self.model.run(x_i))
-                    tempdx.append(math.sqrt(x_i))
-                for y_i in temp:
-                    tempdy.append(math.sqrt(y_i))
+        
                     self.tcXmin.SetValue(str(min(x)))
                     self.tcXmax.SetValue(str(max(x)))
@@ -124,9 +121,8 @@
             self.file_data1.x =x
             self.file_data1.y =temp
-            #self.file_data1.dx=tempdx
+          
             self.file_data1.dx=None
-            #self.file_data1.dy=tempdy
             self.file_data1.dy=None
-            
+            self.file_data1.reset_view()
         
             # Display the fittings values
@@ -136,14 +132,8 @@
             cstB  = fittings.Parameter(self.model, 'B', default_B)        
             chisqr, out, cov = fittings.sansfit(self.model, 
-                [cstA, cstB], self.plottable.view.x, 
-                self.plottable.view.y, self.plottable.view.dy,xmin,xmax)
-            # Create new data plottable with result
+               [cstA, cstB],x, y,dy,min(x),max(x))
             
-            self.file_data1.y = []
-            #for x_i in self.file_data1.x:
-            for x_i in self.file_data1.x:
-                self.file_data1.y.append(self.model.run(x_i))
-                
-            self.push_data(self.file_data1)
+           
+            #Check that cov and out are iterable before displaying them
             if cov ==None:
                 errA =str(0.0)
@@ -158,4 +148,16 @@
                 cstA=str(out[0])
                 cstB=str(out[1])
+           
+            self.model.setParam('A', float(cstA))
+            self.model.setParam('B', float(cstB))
+             # Create new data plottable with result
+            self.file_data1.y = []
+           
+            for x_i in x:
+                self.file_data1.y.append(self.model.run(x_i))
+            #Send the data to display to the PlotPanel
+            self.file_data1.reset_view()
+            self.push_data(self.file_data1)
+            # Display the fitting value on the Fit Dialog
             self._onsetValues(cstA, cstB, errA,errB,str(chisqr))
        
Index: guitools/fittings.py
===================================================================
--- guitools/fittings.py	(revision 57896544f08828746f936a04451449e4a91450e1)
+++ guitools/fittings.py	(revision 57896544f08828746f936a04451449e4a91450e1)
@@ -0,0 +1,98 @@
+from scipy import optimize
+#from numpy import *
+
+
+
+class Parameter:
+    """
+        Class to handle model parameters
+    """
+    def __init__(self, model, name, value=None):
+            self.model = model
+            self.name = name
+            if not value==None:
+                self.model.setParam(self.name, value)
+           
+    def set(self, value):
+        """
+            Set the value of the parameter
+        """
+        self.model.setParam(self.name, value)
+
+    def __call__(self):
+        """ 
+            Return the current value of the parameter
+        """
+        return self.model.getParam(self.name)
+    
+def sansfit(model, pars, x, y, err_y ,qmin=None, qmax=None):
+    """
+        Fit function
+        @param model: sans model object
+        @param pars: list of parameters
+        @param x: vector of x data
+        @param y: vector of y data
+        @param err_y: vector of y errors 
+    """
+    def f(params):
+        """
+            Calculates the vector of residuals for each point 
+            in y for a given set of input parameters.
+            @param params: list of parameter values
+            @return: vector of residuals
+        """
+        i = 0
+        for p in pars:
+            p.set(params[i])
+            i += 1
+        
+        residuals = []
+        for j in range(len(x)):
+            if x[j]>qmin and x[j]<qmax:
+                residuals.append( ( y[j] - model.runXY(x[j]) ) / err_y[j] )
+       
+        return residuals
+        
+    def chi2(params):
+        """
+            Calculates chi^2
+            @param params: list of parameter values
+            @return: chi^2
+        """
+        sum = 0
+        res = f(params)
+        for item in res:
+            sum += item*item
+        return sum
+        
+    p = [param() for param in pars]
+    out, cov_x, info, mesg, success = optimize.leastsq(f, p, full_output=1, warning=True)
+    print info, mesg, success
+    # Calculate chi squared
+    if len(pars)>1:
+        chisqr = chi2(out)
+    elif len(pars)==1:
+        chisqr = chi2([out])
+        
+    return chisqr, out, cov_x    
+
+
+def calcCommandline(self,event):
+    """
+        Testing implementation
+    """
+  
+    # Fit a Line model
+    from LineModel import Line
+    line    = Line()
+    cstA = Parameter(line, 'A', event.cstA)
+    cstB  = Parameter(line, 'B', event.cstB)        
+    y = line.run()
+    chisqr, out, cov = sansfit(line, [cstA, cstB],  event.x, y, 0) 
+    # print "Output parameters:", out
+    print "The right answer is [70.0, 1.0]"
+    print chisqr, out, cov
+
+if __name__ == "__main__": 
+    
+    calcCommandline()
Index: guitools/plottables.py
===================================================================
--- guitools/plottables.py	(revision f63f5ff80aa312a54707cd78d73cfbadc72cceb4)
+++ guitools/plottables.py	(revision 57896544f08828746f936a04451449e4a91450e1)
@@ -174,4 +174,8 @@
         if plottable in self.plottables:
             del self.plottables[plottable]
+        if self.color > 0:
+            self.color =  self.color -1
+        else:
+            self.color =0 
 
     def reset(self):
@@ -312,4 +316,8 @@
         self._yaxis = name
         self._yunit = units
+    def get_xaxis(self):
+        return self._xaxis, self._xunit
+    def get_yaxis(self):
+        return self._yaxis, self._yunit
 
     @classmethod
@@ -336,4 +344,9 @@
     def __init__(self):
         self.view = View()
+        self._xaxis = ""
+        self._xunit = ""
+        self._yaxis = ""
+        self._yunit = "" 
+        
     def set_View(self,x,y):
         """ Load View  """
@@ -345,6 +358,5 @@
         """ Reload view with new value to plot"""
         self.view = self.View(self.x, self.y, self.dx, self.dy)
-        print "the value of view x",self.view.x
-        print "the value of view y",self.view.y
+       
        
     
@@ -379,5 +391,5 @@
         self.view.transform_y(func, errfunc, self.y, self.dy)
         
-    def returnXvalueOfView(self):
+    def returnValuesOfView(self):
         return self.view.returnXview()
         
@@ -449,5 +461,6 @@
                      
         def returnXview(self):
-            return self.x
+            return self.x,self.y,self.dx,self.dy
+           
      
 class Data1D(Plottable):
@@ -468,5 +481,6 @@
         self.dx = dx
         self.dy = dy
-        
+        self.xaxis( 'q', 'A')
+        self.yaxis( 'intensity', 'cm')
         self.view = self.View(self.x, self.y, self.dx, self.dy)
         
@@ -497,8 +511,9 @@
         The title is the name that will show up on the legend.
         """
+        self.name= "theo"
         self.x = x
         self.y = y
         self.dy = dy
-        #Alina:added
+       
         self.view = self.View(self.x, self.y, None, self.dy)
     def render(self,plot,**kw):
@@ -508,5 +523,13 @@
     def changed(self):
         return False
-
+    @classmethod
+    def labels(cls, collection):
+        """Build a label mostly unique within a collection"""
+        map = {}
+        for item in collection:
+            #map[item] = label(item, collection)
+            map[item] = r"$\rm{%s}$" % item.name
+        return map
+   
 
 
Index: guitools/requirements.txt
===================================================================
--- guitools/requirements.txt	(revision fcaada5e84073108f347572b77d68a82b1e2728d)
+++ guitools/requirements.txt	(revision 57896544f08828746f936a04451449e4a91450e1)
@@ -3,5 +3,5 @@
   1- [DONE] After fitting, the fit panel is not updated with the output values of the fit. 
   
-  2- Do this:
+  2- [DONE] Do this:
       a) load the file line_in_x2_y.txt
       b) fit a straight line, close the Fit Dialog
@@ -9,10 +9,10 @@
       You will see an exception that should be fixed.
 
-  3- [DONE] Load the file line_in_x2_y.txt in miniView. Select x^2 and y for the scales. Fit it. 
+  3-  [DONE] Load the file line_in_x2_y.txt in miniView. Select x^2 and y for the scales. Fit it. 
       a) The fit range is wrong, it's not update for the X^2 view.
       b) the fit result is wrong
       c) Even if you update the range, the fit and the plots are wrong.
       
-  4- At the python command prompt, try:
+  4- [DONE]At the python command prompt, try:
        from sans.guitools.PlotPanel import PlotPanel
        
@@ -21,11 +21,14 @@
      Guitools should not depend on your miniView code.
      
-  5- Each time you open and close the Fit Dialog, a new label "Theory1D" is created in the
+  5- [QUESTION] Each time you open and close the Fit Dialog, a new label "Theory1D" is created in the
      legend. There should always be only one, for the _last_ fit, and the name should be "Fit".
+     [alina] is it fine if I delete the fit line from the graph
+      and remove  it when I close the Fit Dialog window?
      
-  6- Do this:
+  6-[QUESTION ] Do this:
   		a) Load the file 'line_in_logy_x.txt'
   		b) Fit a straight line
   		c) The fit shown does not start from the first point and it's not a straight line. 
+  	[ALINA] then for transformation to log Do I have to transform x to log and set x linear?
       
 - NOTES that might help for bugs
@@ -34,8 +37,8 @@
   		the axis is in log will NOT be a straight line
   3- Make sure that you are filling the View of the fit result correctly.
-  
+  [ALINA] not using the log of matplotlib anymore but the axis are never in the log scale by the value are in log10 x
 
 - NEEDED IMPROVEMENTS
-  1- After loading a new file or changing the scale using the "Properties" menu, remove any previously displayed fit from the graph.
+  1-[DONE] After loading a new file or changing the scale using the "Properties" menu, remove any previously displayed fit from the graph.
   
   2- There are additional y scales we need: y, y^2, log(y), 1/y, 1/sqrt(y), log(y * x), log(y * x^2)
