def __init__(self, image, fg_data=[], bg_data=[], **params): self.image = image super(GrabCutDashboard, self).__init__(transient=True, **params) self.bg_paths = gv.project(self.path_type(bg_data, crs=self.crs), projection=image.crs) self.fg_paths = gv.project(self.path_type(fg_data, crs=self.crs), projection=image.crs) self.draw_bg = PolyDraw(source=self.bg_paths) self.draw_fg = PolyDraw(source=self.fg_paths) self._initialized = False
def test_poly_draw_callback_initialized_js(self): polys = Polygons([[(0, 0), (2, 2), (4, 0)]]) PolyDraw(source=polys) plot = bokeh_renderer.get_plot(polys) cb = plot.callbacks[0].callbacks[0] self.assertEqual(plot.handles['source'].js_property_callbacks, {'change:data': [cb], 'patching': [cb]})
def test_poly_draw_callback_with_vdims_no_color_index(self): polys = Polygons([{ 'x': [0, 2, 4], 'y': [0, 2, 0], 'A': 1 }], vdims=['A']).options(color_index=None) poly_draw = PolyDraw(source=polys) plot = bokeh_server_renderer.get_plot(polys) self.assertIsInstance(plot.callbacks[0], PolyDrawCallback) callback = plot.callbacks[0] data = { 'x': [[1, 2, 3], [3, 4, 5]], 'y': [[1, 2, 3], [3, 4, 5]], 'A': [1, 2] } callback.on_msg({'data': data}) element = Polygons([{ 'x': [1, 2, 3], 'y': [1, 2, 3], 'A': 1 }, { 'x': [3, 4, 5], 'y': [3, 4, 5], 'A': 2 }], vdims=['A']) self.assertEqual(poly_draw.element, element)
def test_polygons_no_holes_with_draw_tool(self): if bokeh_version < '1.0': raise SkipTest( 'Plotting Polygons with holes requires bokeh >= 1.0') from bokeh.models import Patches xs = [1, 2, 3, np.nan, 6, 7, 3] ys = [2, 0, 7, np.nan, 7, 5, 2] holes = [[[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]], []] poly = HoloMap({ 0: Polygons([{ 'x': xs, 'y': ys, 'holes': holes }]), 1: Polygons([{ 'x': xs, 'y': ys }]) }) PolyDraw(source=poly) plot = bokeh_renderer.get_plot(poly) glyph = plot.handles['glyph'] self.assertFalse(plot._has_holes) self.assertIsInstance(glyph, Patches)
def __init__(self, polys=None, points=None, crs=None, **params): super(GeoAnnotator, self).__init__(**params) plot_opts = dict(height=self.height, width=self.width) self.tiles = WMTS(self.tile_url, extents=self.extent, crs=ccrs.PlateCarree()).opts(plot=plot_opts) polys = [] if polys is None else polys points = [] if points is None else points crs = ccrs.GOOGLE_MERCATOR if crs is None else crs tools = [CheckpointTool(), RestoreTool(), ClearTool()] opts = dict(tools=tools, finalize_hooks=[initialize_tools], color_index=None) if not isinstance(polys, Path): polys = self.path_type(polys, crs=crs).options(**opts) self.polys = polys.options(**opts) self.poly_stream = PolyDraw(source=self.polys, data={}, show_vertices=True) self.vertex_stream = PolyEdit(source=self.polys) if isinstance(points, Points): self.points = points else: self.points = Points(points, self.polys.kdims, crs=crs).options(**opts) self.point_stream = PointDraw(source=self.points, data={})
def test_poly_draw_callback(self): polys = Polygons([[(0, 0), (2, 2), (4, 0)]]) poly_draw = PolyDraw(source=polys) plot = bokeh_server_renderer.get_plot(polys) self.assertIsInstance(plot.callbacks[0], PolyDrawCallback) callback = plot.callbacks[0] data = {'x': [[1, 2, 3], [3, 4, 5]], 'y': [[1, 2, 3], [3, 4, 5]]} callback.on_msg({'data': data}) element = Polygons([[(1, 1), (2, 2), (3, 3)], [(3, 3), (4, 4), (5, 5)]]) self.assertEqual(poly_draw.element, element)
def __init__(self, obj, paths=None, **params): super(LineCrossSection, self).__init__(**params) self.obj = obj paths = [] if paths is None else paths self.path = Path(paths, crs=ccrs.GOOGLE_MERCATOR) self.path_stream = PolyDraw(source=self.path) PolyEdit(source=self.path) self.sections = Dynamic(self.obj, operation=self._sample, streams=[self.path_stream]) self.tiles = WMTS(self.tile_url)
def _init_polys(self, polys=None): opts = dict(tools=self._tools, finalize_hooks=[initialize_tools], color_index=None) polys = self.polys if polys is None else polys self.polys = polys.options(**opts) self.poly_stream = PolyDraw(source=self.polys, data={}, show_vertices=True, num_objects=self.num_polys) self.vertex_stream = PolyEdit(source=self.polys, vertex_style={'nonselection_alpha': 0.5})
def __init__(self, polys=None, points=None, crs=None, **params): super(GeoAnnotator, self).__init__(**params) plot_opts = dict(height=self.height, width=self.width) self.tiles = WMTS(self.tile_url, extents=self.extent, crs=ccrs.PlateCarree()).opts(plot=plot_opts) polys = [] if polys is None else polys points = [] if points is None else points crs = ccrs.GOOGLE_MERCATOR if crs is None else crs self.polys = self.path_type(polys, crs=crs) self.poly_stream = PolyDraw(source=self.polys, data={}) self.vertex_stream = PolyEdit(source=self.polys) self.points = Points(points, self.polys.kdims, crs=crs) self.point_stream = PointDraw(source=self.points, data={})
def test_poly_draw_callback_initialized_server(self): polys = Polygons([[(0, 0), (2, 2), (4, 0)]]) PolyDraw(source=polys) plot = bokeh_server_renderer.get_plot(polys) self.assertEqual(plot.handles['source']._callbacks, {'data': [plot.callbacks[0].on_change]})