1 # Copyright (C) 2008-2010 Alberto Gomez-Casado
3 # Massimo Sandal <devicerandom@gmail.com>
4 # W. Trevor King <wking@drexel.edu>
6 # This file is part of Hooke.
8 # Hooke is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation, either
11 # version 3 of the License, or (at your option) any later version.
13 # Hooke is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with Hooke. If not, see
20 # <http://www.gnu.org/licenses/>.
22 class ClickedPoint(object):
24 this class defines what a clicked point on the curve plot is
28 self.is_marker=None #boolean ; decides if it is a marker
29 self.is_line_edge=None #boolean ; decides if it is the edge of a line (unused)
30 self.absolute_coords=(None,None) #(float,float) ; the absolute coordinates of the clicked point on the graph
31 self.graph_coords=(None,None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point
32 self.index=None #integer ; the index of the clicked point with respect to the vector selected
33 self.dest=None #0 or 1 ; 0=top plot 1=bottom plot
36 def find_graph_coords_old(self, xvector, yvector):
38 Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
39 corresponds to the clicked point.
40 OLD & DEPRECATED - to be removed
43 #FIXME: a general algorithm using min() is needed!
45 best_dist=10**9 #should be more than enough given the scale
47 for index in scipy.arange(1,len(xvector),1):
48 dist=((self.absolute_coords[0]-xvector[index])**2)+(100*((self.absolute_coords[1]-yvector[index])))**2
49 #TODO, generalize? y coordinate is multiplied by 100 due to scale differences in the plot
55 self.graph_coords=(xvector[best_index],yvector[best_index])
58 def find_graph_coords(self,xvector,yvector):
60 Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
61 corresponds to the clicked point.
64 for index in scipy.arange(1,len(xvector),1):
65 dists.append(((self.absolute_coords[0]-xvector[index])**2)+((self.absolute_coords[1]-yvector[index])**2))
67 self.index=dists.index(min(dists))
68 self.graph_coords=(xvector[self.index],yvector[self.index])