Exemple #1
0
 def test_box_edit_callback(self):
     boxes = Polygons([Box(0, 0, 1)])
     box_edit = BoxEdit(source=boxes)
     plot = bokeh_server_renderer.get_plot(boxes)
     self.assertIsInstance(plot.callbacks[0], BoxEditCallback)
     callback = plot.callbacks[0]
     source = plot.handles['rect_source']
     self.assertEqual(source.data, {'x': [0], 'y': [0], 'width': [1], 'height': [1]})
     data = {'x': [0, 1], 'y': [0, 1], 'width': [0.5, 2], 'height': [2, 0.5]}
     callback.on_msg({'data': data})
     element = Polygons([Box(0, 0, (0.5, 2)), Box(1, 1, (2, 0.5))])
     self.assertEqual(box_edit.element, element)
Exemple #2
0
 def test_box_edit_callback_initialized_js(self):
     boxes = Polygons([Box(0, 0, 1)])
     BoxEdit(source=boxes)
     plot = bokeh_renderer.get_plot(boxes)
     cb = plot.callbacks[0].callbacks[0]
     self.assertEqual(plot.handles['rect_source'].js_property_callbacks,
                      {'change:data': [cb], 'patching': [cb]})
    def test_single_box(self):
        box = Tiles("") * Box(0, 0,
                              (1000000, 2000000)).redim.range(x=self.x_range,
                                                              y=self.y_range)

        x_box_range = [-500000, 500000]
        y_box_range = [-1000000, 1000000]
        lon_box_range, lat_box_range = Tiles.easting_northing_to_lon_lat(
            x_box_range, y_box_range)

        state = self._get_plot_state(box)
        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([lon_box_range[i] for i in (0, 0, 1, 1, 0)]))
        self.assertEqual(state["data"][1]["lat"],
                         np.array([lat_box_range[i] for i in (0, 1, 1, 0, 0)]))

        self.assertEqual(state['layout']['mapbox']['center'], {
            'lat': self.lat_center,
            'lon': self.lon_center
        })
    def test_bounds_layout(self):
        box1 = Box(0, 0, (1, 1), orientation=0)
        box2 = Box(0, 0, (2, 2), orientation=0.5)
        box3 = Box(0, 0, (3, 3), orientation=1.0)
        box4 = Box(0, 0, (4, 4), orientation=1.5)

        layout = (box1 + box2 + box3 + box4).cols(2)

        state = self._get_plot_state(layout)

        shapes = state['layout']['shapes']
        self.assertEqual(len(shapes), 4)

        # Check shapes
        self.assert_path_shape_element(shapes[0], box3, xref='x', yref='y')
        self.assert_path_shape_element(shapes[1], box4, xref='x2', yref='y2')
        self.assert_path_shape_element(shapes[2], box1, xref='x3', yref='y3')
        self.assert_path_shape_element(shapes[3], box2, xref='x4', yref='y4')
Exemple #5
0
 def test_box_edit_callback_initialized_server(self):
     boxes = Polygons([Box(0, 0, 1)])
     BoxEdit(source=boxes)
     plot = bokeh_server_renderer.get_plot(boxes)
     self.assertEqual(plot.handles['rect_source']._callbacks,
                      {'data': [plot.callbacks[0].on_change]})
Exemple #6
0
 def test_box_styling(self):
     self.assert_shape_element_styling(Box(0, 0, (1, 1)))
Exemple #7
0
 def test_single_box(self):
     box = Box(0, 0, (1, 2), orientation=1)
     state = self._get_plot_state(box)
     shapes = state['layout']['shapes']
     self.assertEqual(len(shapes), 1)
     self.assert_path_shape_element(shapes[0], box)
 def test_box_edit_callback(self):
     boxes = Polygons([Box(0, 0, 1)])
     box_edit = BoxEdit(source=boxes)
     plot = bokeh_renderer.get_plot(boxes)
     self.assertIsInstance(plot.callbacks[0], BoxEditCallback)
     self.assertEqual(box_edit.element, boxes)