def test_stream_callback_on_clone(self):
     points = Points([])
     stream = PointerXY(source=points)
     plot = bokeh_server_renderer.get_plot(points.clone())
     bokeh_server_renderer(plot)
     plot.callbacks[0].on_msg({"x": 0.8, "y": 0.3})
     self.assertEqual(stream.x, 0.8)
     self.assertEqual(stream.y, 0.3)
 def test_cds_resolves(self):
     points = Points([1, 2, 3])
     CDSStream(source=points)
     plot = bokeh_server_renderer.get_plot(points)
     cds = plot.handles['cds']
     callback = plot.callbacks[0]
     data_spec = callback.attributes['data']
     resolved = callback.resolve_attr_spec(data_spec, cds, model=cds)
     self.assertEqual(resolved, {'id': cds.ref['id'],
                                 'value': points.columns()})
 def test_points_selected(self):
     points = Points([(0, 0), (1, 1), (2, 2)]).opts(selected=[0, 2])
     plot = bokeh_renderer.get_plot(points)
     cds = plot.handles['cds']
     self.assertEqual(cds.selected.indices, [0, 2])
Exemple #4
0
 def test_bivariate_from_points(self):
     points = Points(np.array([[0, 1], [1, 2], [2, 3]]))
     dist = Bivariate(points)
     self.assertEqual(dist.kdims, points.kdims)
 def test_points_no_single_item_legend(self):
     points = Points([('A', 1), ('B', 2)], label='A')
     plot = bokeh_renderer.get_plot(points)
     plot.initialize_plot()
     fig = plot.state
     self.assertEqual(len(fig.legend), 0)
 def test_points_colormapping(self):
     points = Points(np.random.rand(10, 4),
                     vdims=['a', 'b']).opts(plot=dict(color_index=3))
     self._test_colormapping(points, 3)
Exemple #7
0
 def test_source_empty_element(self):
     points = Points([])
     stream = PointerX(source=points)
     self.assertIs(stream.source, points)
Exemple #8
0
 def test_source_registry(self):
     points = Points([(0, 0)])
     PointerX(source=points)
     self.assertIn(points, Stream.registry)
Exemple #9
0
 def method(self):
     self.count += 1
     return Points([])
Exemple #10
0
 def test(x):
     return Points([x])
Exemple #11
0
 def test_stream_callback_on_unlinked_clone(self):
     points = Points([])
     PointerXY(source=points)
     plot = bokeh_server_renderer.get_plot(points.clone(link=False))
     bokeh_server_renderer(plot)
     self.assertTrue(len(plot.callbacks) == 0)
Exemple #12
0
 def test_points_categorical_xaxis_invert_axes(self):
     points = Points((['A', 'B', 'C'], (1,2,3))).opts(plot=dict(invert_axes=True))
     plot = bokeh_renderer.get_plot(points)
     y_range = plot.handles['y_range']
     self.assertIsInstance(y_range, FactorRange)
     self.assertEqual(y_range.factors, ['A', 'B', 'C'])
Exemple #13
0
 def test_point_draw_callback_with_vdims_initialization(self):
     points = Points([(0, 1, 'A')], vdims=['A'])
     stream = PointDraw(source=points)
     bokeh_server_renderer.get_plot(points)
     self.assertEqual(stream.element.dimension_values('A'), np.array(['A']))
Exemple #14
0
 def test_point_draw_callback_initialized_server(self):
     points = Points([(0, 1)])
     PointDraw(source=points)
     plot = bokeh_server_renderer.get_plot(points)
     self.assertEqual(plot.handles['source']._callbacks,
                      {'data': [plot.callbacks[0].on_change]})
Exemple #15
0
 def test_selection1d_syncs_to_selected(self):
     points = Points([(0, 0), (1, 1), (2, 2)]).opts(selected=[0, 2])
     stream = Selection1D(source=points)
     bokeh_renderer.get_plot(points)
     self.assertEqual(stream.index, [0, 2])
 def test_layout_disable_toolbar(self):
     layout = (Curve([]) + Points([])).options(toolbar=None)
     plot = bokeh_renderer.get_plot(layout)
     self.assertIsInstance(plot.state, GridBox)
     self.assertEqual(len(plot.state.children), 2)
Exemple #17
0
 def test_stream_callback_on_unlinked_clone(self):
     points = Points([])
     PointerXY(source=points)
     plot = bokeh_server_renderer.get_plot(points.clone(link=False))
     bokeh_server_renderer(plot)
     self.assertTrue(len(plot.callbacks) == 0)
Exemple #18
0
 def test_overlay_empty_element_extent(self):
     overlay = Curve([]).redim.range(x=(-10, 10)) * Points([]).redim.range(y=(-20, 20))
     plot = bokeh_renderer.get_plot(overlay)
     extents = plot.get_extents(overlay, {})
     self.assertEqual(extents, (-10, -20, 10, 20))
Exemple #19
0
 def history_callback(x, y, history=deque(maxlen=10)):
     history.append((x, y))
     return Points(list(history))
Exemple #20
0
 def action_number_method(self):
     self.count += 1
     return Points([])
Exemple #21
0
 def test_source_registry(self):
     points = Points([(0, 0)])
     positionX = PointerX(source=points)
     self.assertIn(id(points), Stream.registry)
Exemple #22
0
 def points(data):
     subscriber.call_count += 1
     return Points([(0, data)])
Exemple #23
0
 def test_source_registry_empty_element(self):
     points = Points([])
     positionX = PointerX(source=points)
     self.assertIn(id(points), Stream.registry)
Exemple #24
0
 def test_source_empty_dmap(self):
     points_dmap = DynamicMap(lambda x: Points([]), kdims=['X'])
     stream = PointerX(source=points_dmap)
     self.assertIs(stream.source, points_dmap)
Exemple #25
0
 def test_compute_overlayable_zorders_holomap(self):
     hmap = HoloMap({0: Points([])})
     sources = compute_overlayable_zorders(hmap)
     self.assertEqual(sources[0], [hmap, hmap.last])
Exemple #26
0
 def test_source_registry_empty_element(self):
     points = Points([])
     PointerX(source=points)
     self.assertIn(points, Stream.registry)
Exemple #27
0
 def test_get_min_distance_float32_type(self):
     xs, ys = (np.arange(0, 2., .2, dtype='float32'),
               np.arange(0, 2., .2, dtype='float32'))
     X, Y = np.meshgrid(xs, ys)
     dist = get_min_distance(Points((X.flatten(), Y.flatten())))
     self.assertEqual(round(dist, 5), 0.2)
 def test_points_categorical_xaxis(self):
     points = Points((['A', 'B', 'C'], (1, 2, 3)))
     plot = bokeh_renderer.get_plot(points)
     x_range = plot.handles['x_range']
     self.assertIsInstance(x_range, FactorRange)
     self.assertEqual(x_range.factors, ['A', 'B', 'C'])
Exemple #29
0
 def test_get_min_distance_int32_type_no_scipy(self):
     xs, ys = (np.arange(0, 10, dtype='int32'),
               np.arange(0, 10, dtype='int32'))
     X, Y = np.meshgrid(xs, ys)
     dist = _get_min_distance_numpy(Points((X.flatten(), Y.flatten())))
     self.assertEqual(dist, 1.0)
 def test_points_colormapping_with_nonselection(self):
     opts = dict(plot=dict(color_index=3),
                 style=dict(nonselection_color='red'))
     points = Points(np.random.rand(10, 4), vdims=['a', 'b']).opts(**opts)
     self._test_colormapping(points, 3)
 def test_point_draw_callback_initialize(self):
     points = Points([(0, 1)])
     point_draw = PointDraw(source=points)
     plot = bokeh_renderer.get_plot(points)
     self.assertIsInstance(plot.callbacks[0], PointDrawCallback)
     self.assertEqual(point_draw.element, points)
 def test_batched_points(self):
     overlay = NdOverlay({i: Points(np.arange(i)) for i in range(1, 100)})
     plot = bokeh_renderer.get_plot(overlay)
     extents = plot.get_extents(overlay, {})
     self.assertEqual(extents, (0, 0, 98, 98))
Exemple #33
0
    def do_crossfilter_points_histogram(self,
                                        selection_mode,
                                        cross_filter_mode,
                                        selected1,
                                        selected2,
                                        selected3,
                                        selected4,
                                        points_region1,
                                        points_region2,
                                        points_region3,
                                        points_region4,
                                        hist_region2,
                                        hist_region3,
                                        hist_region4,
                                        show_regions=True,
                                        dynamic=False):
        points = Points(self.data)
        hist = points.hist('x', adjoin=False, normed=False, num_bins=5)

        if dynamic:
            # Convert points to DynamicMap that returns the element
            hist_orig = hist
            points = hv.util.Dynamic(points)
        else:
            hist_orig = hist

        lnk_sel = link_selections.instance(selection_mode=selection_mode,
                                           cross_filter_mode=cross_filter_mode,
                                           show_regions=show_regions,
                                           selected_color='#00ff00',
                                           unselected_color='#ff0000')
        linked = lnk_sel(points + hist)
        current_obj = linked[()]

        # Check initial base points
        self.check_base_points_like(current_obj[0][()].Points.I, lnk_sel)

        # Check initial selection overlay points
        self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
                                       self.data)

        # Initial region bounds all None
        self.assertEqual(len(current_obj[0][()].Curve.I), 0)

        # Check initial base histogram
        base_hist = current_obj[1][()].Histogram.I
        self.assertEqual(self.element_color(base_hist),
                         lnk_sel.unselected_color)
        self.assertEqual(base_hist.data, hist_orig.data)

        # No selection region
        region_hist = current_obj[1][()].Histogram.II
        self.assertEqual(region_hist.data,
                         hist_orig.pipeline(hist_orig.dataset.iloc[:0]).data)

        # Check initial selection overlay Histogram
        selection_hist = current_obj[1][()].Histogram.III
        self.assertEqual(
            self.element_color(selection_hist),
            self.expected_selection_color(selection_hist, lnk_sel))
        self.assertEqual(selection_hist.data, hist_orig.data)

        # (1) Perform selection on points of points [1, 2]
        points_boundsxy = lnk_sel._selection_expr_streams[0]._source_streams[0]
        self.assertIsInstance(points_boundsxy, SelectionXY)
        points_boundsxy.event(bounds=(1, 1, 4, 4))

        # Get current object
        current_obj = linked[()]

        # Check base points unchanged
        self.check_base_points_like(current_obj[0][()].Points.I, lnk_sel)

        # Check points selection overlay
        self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
                                       self.data.iloc[selected1])

        # Check points region bounds
        region_bounds = current_obj[0][()].Rectangles.I
        self.assertEqual(region_bounds, Rectangles(points_region1))

        if show_regions:
            self.assertEqual(self.element_color(region_bounds),
                             box_region_color)

        # Check histogram bars selected
        selection_hist = current_obj[1][()].Histogram.III
        self.assertEqual(
            selection_hist.data,
            hist_orig.pipeline(hist_orig.dataset.iloc[selected1]).data)

        # (2) Perform selection on histogram bars [0, 1]
        hist_boundsxy = lnk_sel._selection_expr_streams[1]._source_streams[0]
        self.assertIsInstance(hist_boundsxy, SelectionXY)
        hist_boundsxy.event(bounds=(0, 0, 2.5, 2))

        points_unsel, points_sel, points_region = current_obj[0][()].values()

        # Check points selection overlay
        self.check_overlay_points_like(points_sel, lnk_sel,
                                       self.data.iloc[selected2])

        self.assertEqual(points_region, Rectangles(points_region2))

        # Check base histogram unchanged
        base_hist, region_hist, sel_hist = current_obj[1][()].values()
        self.assertEqual(self.element_color(base_hist),
                         lnk_sel.unselected_color)
        self.assertEqual(base_hist.data, hist_orig.data)

        # Check selection region covers first and second bar
        if show_regions:
            self.assertEqual(self.element_color(region_hist),
                             hist_region_color)
        self.assertEqual(
            region_hist.data,
            hist_orig.pipeline(hist_orig.dataset.iloc[hist_region2]).data)

        # Check histogram selection overlay
        self.assertEqual(self.element_color(sel_hist),
                         self.expected_selection_color(sel_hist, lnk_sel))
        self.assertEqual(
            sel_hist.data,
            hist_orig.pipeline(hist_orig.dataset.iloc[selected2]).data)

        # (3) Perform selection on points points [0, 2]
        points_boundsxy = lnk_sel._selection_expr_streams[0]._source_streams[0]
        self.assertIsInstance(points_boundsxy, SelectionXY)
        points_boundsxy.event(bounds=(0, 0, 4, 2.5))

        # Check selection overlay points contains only second point
        self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
                                       self.data.iloc[selected3])

        # Check points region bounds
        region_bounds = current_obj[0][()].Rectangles.I
        self.assertEqual(region_bounds, Rectangles(points_region3))

        # Check second and third histogram bars selected
        selection_hist = current_obj[1][()].Histogram.III
        self.assertEqual(
            selection_hist.data,
            hist_orig.pipeline(hist_orig.dataset.iloc[selected3]).data)

        # Check selection region covers first and second bar
        region_hist = current_obj[1][()].Histogram.II
        self.assertEqual(
            region_hist.data,
            hist_orig.pipeline(hist_orig.dataset.iloc[hist_region3]).data)

        # (4) Perform selection of bars [1, 2]
        hist_boundsxy = lnk_sel._selection_expr_streams[1]._source_streams[0]
        self.assertIsInstance(hist_boundsxy, SelectionXY)
        hist_boundsxy.event(bounds=(1.5, 0, 3.5, 2))

        # Check points selection overlay
        self.check_overlay_points_like(current_obj[0][()].Points.II, lnk_sel,
                                       self.data.iloc[selected4])

        # Check points region bounds
        region_bounds = current_obj[0][()].Rectangles.I
        self.assertEqual(region_bounds, Rectangles(points_region4))

        # Check bar selection region
        region_hist = current_obj[1][()].Histogram.II
        if show_regions:
            self.assertEqual(self.element_color(region_hist),
                             hist_region_color)
        self.assertEqual(
            region_hist.data,
            hist_orig.pipeline(hist_orig.dataset.iloc[hist_region4]).data)

        # Check bar selection overlay
        selection_hist = current_obj[1][()].Histogram.III
        self.assertEqual(
            self.element_color(selection_hist),
            self.expected_selection_color(selection_hist, lnk_sel))
        self.assertEqual(
            selection_hist.data,
            hist_orig.pipeline(hist_orig.dataset.iloc[selected4]).data)