def _plot_default(self):
        container = DataView()

        xds = FunctionDataSource(func = self.xfunc)
        yds = FunctionDataSource(func = self.yfunc)

        xmapper = container.x_mapper
        ymapper = container.y_mapper

        xds.data_range = xmapper.range
        yds.data_range = xmapper.range

        xmapper.range.set_bounds(-5, 10)
        ymapper.range.set_bounds(-1, 1.2)
        
        #FIXME: change color, marker, marker_size to see the difference
        plot = ScatterPlot(index = xds, value = yds, index_mapper = xmapper,
                           value_mapper = ymapper,
                           color = "green",
                           marker = "circle",
                           marker_size = 3,
                           line_width = 0)

        plot2 = LinePlot(index = xds, value = yds, index_mapper = xmapper,
                        value_mapper = ymapper,
                        color = "lightgray")

        container.add(plot2, plot)
        #FIXME: uncomment following two lines to see the difference
        #plot.tools.append(PanTool(plot, constrain_direction="x", constrain=True))
        #plot.tools.append(ZoomTool(plot, axis="index", tool_mode="range"))

        return container
Exemple #2
0
    def _plot_default(self):
        container = DataView()

        xds = FunctionDataSource(func=self.xfunc)
        yds = FunctionDataSource(func=self.yfunc)

        xmapper = container.x_mapper
        ymapper = container.y_mapper

        xds.data_range = xmapper.range
        yds.data_range = xmapper.range

        xmapper.range.set_bounds(-5, 10)
        ymapper.range.set_bounds(-1, 1.2)

        plot = ScatterPlot(index=xds,
                           value=yds,
                           index_mapper=xmapper,
                           value_mapper=ymapper,
                           color="green",
                           marker="circle",
                           marker_size=3,
                           line_width=0)

        plot2 = LinePlot(index=xds,
                         value=yds,
                         index_mapper=xmapper,
                         value_mapper=ymapper,
                         color="lightgray")

        container.add(plot2, plot)
        plot.tools.append(
            PanTool(plot, constrain_direction="x", constrain=True))
        plot.tools.append(ZoomTool(plot, axis="index", tool_mode="range"))

        return container
Exemple #3
0
    def test_get_data_no_data(self):
        self.data_source = FunctionDataSource()

        assert_array_equal(self.data_source.get_data(), array([], dtype=float))
Exemple #4
0
 def test_init_defaults(self):
     data_source = FunctionDataSource()
     assert_array_equal(data_source._data, [])
     self.assertEqual(data_source.value_dimension, "scalar")
     self.assertEqual(data_source.sort_order, "ascending")
     self.assertFalse(data_source.is_masked())
Exemple #5
0
 def setUp(self):
     self.myfunc = lambda low, high: linspace(low, high, 101)**2
     self.data_source = FunctionDataSource(func=self.myfunc)
Exemple #6
0
class FunctionDataSourceTestCase(UnittestTools, unittest.TestCase):
    def setUp(self):
        self.myfunc = lambda low, high: linspace(low, high, 101)**2
        self.data_source = FunctionDataSource(func=self.myfunc)

    def test_init_defaults(self):
        data_source = FunctionDataSource()
        assert_array_equal(data_source._data, [])
        self.assertEqual(data_source.value_dimension, "scalar")
        self.assertEqual(data_source.sort_order, "ascending")
        self.assertFalse(data_source.is_masked())

    def test_basic_setup(self):
        assert_array_equal(self.myfunc, self.data_source.func)
        self.assertEqual(self.data_source.value_dimension, "scalar")
        self.assertEqual(self.data_source.sort_order, "ascending")
        self.assertFalse(self.data_source.is_masked())

    def test_set_data(self):
        with self.assertRaises(RuntimeError):
            self.data_source.set_data(
                lambda low, high: linspace(low, high, 101))

    def test_range_high_changed(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.data_range.high_setting = 2.0

        assert_array_equal(
            linspace(0.0, 2.0, 101)**2, self.data_source.get_data())

    def test_range_low_changed(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.data_range.low_setting = -1.0

        assert_array_equal(
            linspace(-1.0, 1.0, 101)**2, self.data_source.get_data())

    def test_range_data_range_changed(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.data_range = DataRange1D(low_setting=-2.0,
                                                      high_setting=2.0)

        assert_array_equal(
            linspace(-2.0, 2.0, 101)**2, self.data_source.get_data())

    def test_set_mask(self):
        mymask = array([i % 2 for i in xrange(101)], dtype=bool)

        with self.assertRaises(NotImplementedError):
            self.data_source.set_mask(mymask)

    def test_remove_mask(self):
        with self.assertRaises(NotImplementedError):
            self.data_source.remove_mask()

    def test_get_data(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        assert_array_equal(
            linspace(0.0, 1.0, 101)**2, self.data_source.get_data())

    def test_get_data_no_data(self):
        self.data_source = FunctionDataSource()

        assert_array_equal(self.data_source.get_data(), array([], dtype=float))

    def test_get_data_mask(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        data, mask = self.data_source.get_data_mask()
        assert_array_equal(data, linspace(0.0, 1.0, 101)**2)
        assert_array_equal(mask, ones(shape=101, dtype=bool))

    def test_bounds(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=2.0)

        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0.0, 4.0))

    @unittest.skip("default sort_order is ascending, which isn't right")
    def test_bounds_non_monotone(self):
        self.data_source.data_range = DataRange1D(low_setting=-2.0,
                                                  high_setting=2.0)

        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0.0, 4.0))

    def test_data_size(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=2.0)

        self.assertEqual(101, self.data_source.get_size())
    def test_get_data_no_data(self):
        self.data_source = FunctionDataSource()

        assert_array_equal(self.data_source.get_data(), array([], dtype=float))
 def test_init_defaults(self):
     data_source = FunctionDataSource()
     assert_array_equal(data_source._data, [])
     self.assertEqual(data_source.value_dimension, "scalar")
     self.assertEqual(data_source.sort_order, "ascending")
     self.assertFalse(data_source.is_masked())
 def setUp(self):
     self.myfunc = lambda low, high: linspace(low, high, 101)**2
     self.data_source = FunctionDataSource(func=self.myfunc)
class FunctionDataSourceTestCase(UnittestTools, unittest.TestCase):

    def setUp(self):
        self.myfunc = lambda low, high: linspace(low, high, 101)**2
        self.data_source = FunctionDataSource(func=self.myfunc)


    def test_init_defaults(self):
        data_source = FunctionDataSource()
        assert_array_equal(data_source._data, [])
        self.assertEqual(data_source.value_dimension, "scalar")
        self.assertEqual(data_source.sort_order, "ascending")
        self.assertFalse(data_source.is_masked())

    def test_basic_setup(self):
        assert_array_equal(self.myfunc, self.data_source.func)
        self.assertEqual(self.data_source.value_dimension, "scalar")
        self.assertEqual(self.data_source.sort_order, "ascending")
        self.assertFalse(self.data_source.is_masked())

    def test_set_data(self):
        with self.assertRaises(RuntimeError):
            self.data_source.set_data(
                lambda low, high: linspace(low, high, 101))

    def test_range_high_changed(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        with self.assertTraitChanges(self.data_source, 'data_changed', count=1):
            self.data_source.data_range.high_setting = 2.0

        assert_array_equal(linspace(0.0, 2.0, 101)**2,
                           self.data_source.get_data())

    def test_range_low_changed(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        with self.assertTraitChanges(self.data_source, 'data_changed', count=1):
            self.data_source.data_range.low_setting = -1.0

        assert_array_equal(linspace(-1.0, 1.0, 101)**2,
                           self.data_source.get_data())

    def test_range_data_range_changed(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        with self.assertTraitChanges(self.data_source, 'data_changed', count=1):
            self.data_source.data_range = DataRange1D(low_setting=-2.0,
                                                      high_setting=2.0)

        assert_array_equal(linspace(-2.0, 2.0, 101)**2,
                           self.data_source.get_data())

    def test_set_mask(self):
        mymask = array([i % 2 for i in xrange(101)], dtype=bool)

        with self.assertRaises(NotImplementedError):
            self.data_source.set_mask(mymask)

    def test_remove_mask(self):
        with self.assertRaises(NotImplementedError):
            self.data_source.remove_mask()

    def test_get_data(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        assert_array_equal(linspace(0.0, 1.0, 101)**2,
                           self.data_source.get_data())

    def test_get_data_no_data(self):
        self.data_source = FunctionDataSource()

        assert_array_equal(self.data_source.get_data(), array([], dtype=float))

    def test_get_data_mask(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=1.0)

        data, mask = self.data_source.get_data_mask()
        assert_array_equal(data, linspace(0.0, 1.0, 101)**2)
        assert_array_equal(mask, ones(shape=101, dtype=bool))

    def test_bounds(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=2.0)

        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0.0, 4.0))

    @unittest.skip("default sort_order is ascending, which isn't right")
    def test_bounds_non_monotone(self):
        self.data_source.data_range = DataRange1D(low_setting=-2.0,
                                                  high_setting=2.0)

        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0.0, 4.0))

    def test_data_size(self):
        self.data_source.data_range = DataRange1D(low_setting=0.0,
                                                  high_setting=2.0)

        self.assertEqual(101, self.data_source.get_size())