f0813c751a447db769542dea29729de8e5e68ead
[hooke.git] / hooke / ui / gui / point_request.py
1 class ClickedPoint(object):
2     '''
3     this class defines what a clicked point on the curve plot is
4     '''
5     def __init__(self):
6
7         self.is_marker=None #boolean ; decides if it is a marker
8         self.is_line_edge=None #boolean ; decides if it is the edge of a line (unused)
9         self.absolute_coords=(None,None) #(float,float) ; the absolute coordinates of the clicked point on the graph
10         self.graph_coords=(None,None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point
11         self.index=None #integer ; the index of the clicked point with respect to the vector selected
12         self.dest=None #0 or 1 ; 0=top plot 1=bottom plot
13
14
15     def find_graph_coords_old(self, xvector, yvector):
16         '''
17         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
18         corresponds to the clicked point.
19         OLD & DEPRECATED - to be removed
20         '''
21
22         #FIXME: a general algorithm using min() is needed!
23         best_index=0
24         best_dist=10**9 #should be more than enough given the scale
25
26         for index in scipy.arange(1,len(xvector),1):
27             dist=((self.absolute_coords[0]-xvector[index])**2)+(100*((self.absolute_coords[1]-yvector[index])))**2
28                 #TODO, generalize? y coordinate is multiplied by 100 due to scale differences in the plot
29             if dist<best_dist:
30                 best_index=index
31                 best_dist=dist
32
33         self.index=best_index
34         self.graph_coords=(xvector[best_index],yvector[best_index])
35         return
36
37     def find_graph_coords(self,xvector,yvector):
38         '''
39         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
40         corresponds to the clicked point.
41         '''
42         dists=[]
43         for index in scipy.arange(1,len(xvector),1):
44             dists.append(((self.absolute_coords[0]-xvector[index])**2)+((self.absolute_coords[1]-yvector[index])**2))
45
46         self.index=dists.index(min(dists))
47         self.graph_coords=(xvector[self.index],yvector[self.index])