def test_segments_overlay_categorical_yaxis(self): segments = Segments(([1, 2, 3], ['A', 'B', 'C'], [4, 5, 6], ['A', 'B', 'C'])) segments2 = Segments(([1, 2, 3], ['B', 'C', 'D'], [4, 5, 6], ['B', 'C', 'D'])) plot = bokeh_renderer.get_plot(segments * segments2) y_range = plot.handles['y_range'] self.assertIsInstance(y_range, FactorRange) self.assertEqual(y_range.factors, ['A', 'B', 'C', 'D'])
def test_segs_geom_selection_inverted(self): rect = Segments([(0, 1, 2, 3), (1, 3, 1.5, 4), (2.5, 4.2, 3.5, 4.8)]).opts(invert_axes=True) geom = np.array([(-0.4, -0.1), (3.2, -0.1), (3.2, 4.1), (-0.1, 4.2)]) expr, bbox, region = rect._get_selection_expr_for_stream_value(geometry=geom) self.assertEqual(bbox, {'y0': np.array([-0.4, 3.2, 3.2, -0.1]), 'x0': np.array([-0.1, -0.1, 4.1, 4.2]), 'y1': np.array([-0.4, 3.2, 3.2, -0.1]), 'x1': np.array([-0.1, -0.1, 4.1, 4.2])}) self.assertEqual(expr.apply(rect), np.array([True, False, False])) self.assertEqual(region, Rectangles([]) * Path([list(geom)+[(-0.4, -0.1)]]))
def test_segs_selection_numeric_inverted(self): segs = Segments([(0, 1, 2, 3), (1, 3, 1.5, 4), (2.5, 4.2, 3.5, 4.8)]).opts(invert_axes=True) expr, bbox, region = segs._get_selection_expr_for_stream_value(bounds=(0.9, 0.5, 4.9, 3.4)) self.assertEqual(bbox, {'x0': (0.5, 3.4), 'y0': (0.9, 4.9), 'x1': (0.5, 3.4), 'y1': (0.9, 4.9)}) self.assertEqual(expr.apply(segs), np.array([False, True, False])) self.assertEqual(region, Rectangles([(0.9, 0.5, 4.9, 3.4)]) * Path([])) expr, bbox, region = segs._get_selection_expr_for_stream_value(bounds=(0.9, 0, 4.9, 3.5)) self.assertEqual(bbox, {'x0': (0, 3.5), 'y0': (0.9, 4.9), 'x1': (0, 3.5), 'y1': (0.9, 4.9)}) self.assertEqual(expr.apply(segs), np.array([True, True, True])) self.assertEqual(region, Rectangles([(0.9, 0, 4.9, 3.5)]) * Path([]))
def test_segments_categorical_xaxis(self): segments = Segments((['A', 'B', 'C'], [1, 2, 3], ['A', 'B', 'C'], [4, 5, 6])) plot = bokeh_renderer.get_plot(segments) x_range = plot.handles['x_range'] self.assertIsInstance(x_range, FactorRange) self.assertEqual(x_range.factors, ['A', 'B', 'C'])
def test_segments_simple(self): rectangles = Tiles("") * Segments([ (0, 0, self.x_range[1], self.y_range[1]), (self.x_range[0], self.y_range[0], 0, 0), ]).redim.range(x=self.x_range, y=self.y_range) state = self._get_plot_state(rectangles) self.assertEqual(state["data"][1]["type"], "scattermapbox") self.assertEqual(state["data"][1]["mode"], "lines") self.assertEqual(state["data"][1]["showlegend"], False) self.assertEqual(state["data"][1]["line"]["color"], default_shape_color) self.assertEqual( state["data"][1]["lon"], np.array( [0, self.lon_range[1], np.nan, self.lon_range[0], 0, np.nan])) self.assertEqual( state["data"][1]["lat"], np.array( [0, self.lat_range[1], np.nan, self.lat_range[0], 0, np.nan])) self.assertEqual(state['layout']['mapbox']['center'], { 'lat': self.lat_center, 'lon': self.lon_center })
def test_segments_simple(self): boxes = Segments([(0, 0, 1, 1), (2, 2, 4, 3)]) state = self._get_plot_state(boxes) shapes = state['layout']['shapes'] self.assertEqual(len(shapes), 2) self.assertEqual( shapes[0], { 'type': 'line', 'x0': 0, 'y0': 0, 'x1': 1, 'y1': 1, 'xref': 'x', 'yref': 'y', 'name': '', 'line': { 'color': default_shape_color } }) self.assertEqual( shapes[1], { 'type': 'line', 'x0': 2, 'y0': 2, 'x1': 4, 'y1': 3, 'xref': 'x', 'yref': 'y', 'name': '', 'line': { 'color': default_shape_color } }) self.assertEqual(state['layout']['xaxis']['range'], [0, 4]) self.assertEqual(state['layout']['yaxis']['range'], [0, 3])
def test_segments_alpha_selection_nonselection(self): opts = dict(alpha=0.8, selection_alpha=1.0, nonselection_alpha=0.2) segments = Segments([(i, i * 2, i * 3, i * 4, i * 5, chr(65 + i)) for i in range(10)], vdims=['a', 'b']).opts(**opts) plot = bokeh_renderer.get_plot(segments) glyph_renderer = plot.handles['glyph_renderer'] self.assertEqual(glyph_renderer.glyph.line_alpha, 0.8) self.assertEqual(glyph_renderer.selection_glyph.line_alpha, 1) self.assertEqual(glyph_renderer.nonselection_glyph.line_alpha, 0.2)
def test_segments_overlay_hover(self): obj = NdOverlay( { i: Segments((range(31), range(31), range(1, 32), range(31))) for i in range(5) }, kdims=['Test']).opts({'Segments': { 'tools': ['hover'] }}) tooltips = [('Test', '@{Test}'), ('x0', '@{x0}'), ('y0', '@{y0}'), ('x1', '@{x1}'), ('y1', '@{y1}')] self._test_hover_info(obj, tooltips)
def test_segments_color_selection_nonselection(self): opts = dict(color='green', selection_color='red', nonselection_color='blue') segments = Segments([(i, i * 2, i * 3, i * 4, i * 5, chr(65 + i)) for i in range(10)], vdims=['a', 'b']).opts(**opts) plot = bokeh_renderer.get_plot(segments) glyph_renderer = plot.handles['glyph_renderer'] self.assertEqual(glyph_renderer.glyph.line_color, 'green') self.assertEqual(glyph_renderer.selection_glyph.line_color, 'red') self.assertEqual(glyph_renderer.nonselection_glyph.line_color, 'blue')
def test_segments_overlay_datetime_hover(self): if pd is None: raise SkipTest("Test requires pandas") obj = NdOverlay( { i: Segments( (list(pd.date_range('2016-01-01', '2016-01-31')), range(31), pd.date_range('2016-01-02', '2016-02-01'), range(31))) for i in range(5) }, kdims=['Test']).opts({'Segments': { 'tools': ['hover'] }}) tooltips = [('Test', '@{Test}'), ('x0', '@{x0}{%F %T}'), ('y0', '@{y0}'), ('x1', '@{x1}{%F %T}'), ('y1', '@{y1}')] formatters = {'@{x0}': "datetime", '@{x1}': "datetime"} self._test_hover_info(obj, tooltips, formatters=formatters)