@@ -0,0 +1,2059 @@
+%22%22%22%0ATest cases for the LinePlot's hittest() function%0A%22%22%22%0A%0Aimport unittest%0Afrom numpy import arange, array, linalg%0Afrom chaco.api import ArrayDataSource, ArrayPlotData, Plot, LinearMapper, DataRange1D%0A%0Aclass HittestTestCase(unittest.TestCase):%0A    def make_plot(self, orientation):%0A        # make some data points%0A        x = arange(3)%0A        x = ArrayDataSource(x, sort_order=%22ascending%22)%0A        y = array(%5B2,0,1%5D)%0A%0A        # Plot the data%0A        pd = ArrayPlotData(x=x, y=y)%0A%0A        plot = Plot(pd, orientation=orientation)%0A        line_plot = plot.plot((%22x%22, %22y%22))%5B0%5D%0A%0A        # Construct a fake screen space for the plots%0A        # otherwise would need to actually display the plots to get this%0A        index_mapper = LinearMapper(data_range=DataRange1D(low=0,high=2),%0A                                    high_pos=380, low_pos=20)%0A        value_mapper = LinearMapper(data_range=DataRange1D(low=0,high=2),%0A                                    high_pos=380, low_pos=20)%0A        plot.index_mapper = index_mapper%0A        plot.value_mapper = value_mapper%0A        line_plot.index_mapper = index_mapper%0A        line_plot.value_mapper = value_mapper%0A%0A        return  plot, line_plot%0A%0A    def test_horizontal(self):%0A        plot, line_plot = self.make_plot(%22h%22)%0A%0A        self._test_plot(plot, line_plot, point=%5B0.5,1%5D)%0A        self._test_plot(plot, line_plot, point=%5B1,0%5D)%0A%0A    def test_vertical(self):%0A        plot, line_plot = self.make_plot(%22v%22)%0A        self._test_plot(plot, line_plot, point=%5B0.5,1%5D)%0A        self._test_plot(plot, line_plot, point=%5B1,0%5D)%0A%0A%0A    def _test_plot(self, plot, line_plot, point):%0A%0A        threshold = 2 # In pixels%0A%0A        screen_pt = plot.map_screen(point).flatten()%0A        result = line_plot.hittest(screen_pt, threshold=threshold)%0A%0A        self.assert_(result is not None)%0A%0A        # Check that the result is close by threshold in screenspace%0A        screen_result = plot.map_screen(result)%0A%0A        self.assert_( linalg.norm(screen_pt - screen_result) %3C threshold )%0A%0Aif __name__ == '__main__':%0A    import nose%0A    nose.run()%0A

add a test case for LinePlot's hittest function