Ejemplo n.º 1
0
 def test_side_histogram_no_cmapper(self):
     points = Points(np.random.rand(100, 2))
     plot = bokeh_renderer.get_plot(points.hist())
     plot.initialize_plot()
     adjoint_plot = list(plot.subplots.values())[0]
     main_plot = adjoint_plot.subplots['main']
     right_plot = adjoint_plot.subplots['right']
     self.assertTrue('color_mapper' not in main_plot.handles)
     self.assertTrue('color_mapper' not in right_plot.handles)
Ejemplo n.º 2
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)

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

        # No selection region
        region_hist = current_obj[1][()].NdOverlay.I.last
        self.assertEqual(region_hist.data, [None, None])

        # (1) Perform selection on points of points [1, 2]
        points_boundsxy = lnk_sel._selection_expr_streams[0].input_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)

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

        points_unsel, points_sel, points_region, points_region_poly = 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.last),
                             hist_region_color)
        if not len(hist_region2) and lnk_sel.selection_mode != 'inverse':
            self.assertEqual(len(region_hist), 1)
        else:
            self.assertEqual(region_hist.last.data, [0, 2.5])

        # 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].input_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.II
        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][()].NdOverlay.I.last
        if not len(hist_region3) and lnk_sel.selection_mode != 'inverse':
            self.assertEqual(len(region_hist), 1)
        else:
            self.assertEqual(region_hist.data, [0, 2.5])

        # (4) Perform selection of bars [1, 2]
        hist_boundsxy = lnk_sel._selection_expr_streams[1].input_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][()].NdOverlay.I.last
        if show_regions:
            self.assertEqual(self.element_color(region_hist),
                             hist_region_color)
        if not len(hist_region4) and lnk_sel.selection_mode != 'inverse':
            self.assertEqual(len(region_hist), 1)
        elif (lnk_sel.cross_filter_mode != 'overwrite'
              and not (lnk_sel.cross_filter_mode == 'intersect'
                       and lnk_sel.selection_mode == 'overwrite')):
            self.assertEqual(region_hist.data, [0, 3.5])
        else:
            self.assertEqual(region_hist.data, [1.5, 3.5])

        # Check bar selection overlay
        selection_hist = current_obj[1][()].Histogram.II
        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)