def test_bounds_layout(self):
        bounds1 = Bounds((0, 0, 1, 1))
        bounds2 = Bounds((0, 0, 2, 2))
        bounds3 = Bounds((0, 0, 3, 3))
        bounds4 = Bounds((0, 0, 4, 4))

        layout = (bounds1 + bounds2 + bounds3 + bounds4).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], bounds3, xref='x', yref='y')
        self.assert_path_shape_element(shapes[1],
                                       bounds4,
                                       xref='x2',
                                       yref='y2')
        self.assert_path_shape_element(shapes[2],
                                       bounds1,
                                       xref='x3',
                                       yref='y3')
        self.assert_path_shape_element(shapes[3],
                                       bounds2,
                                       xref='x4',
                                       yref='y4')
    def test_bounds_layout(self):
        bounds1 = Bounds((0, 0, 1, 1))
        bounds2 = Bounds((0, 0, 2, 2))
        bounds3 = Bounds((0, 0, 3, 3))
        bounds4 = Bounds((0, 0, 4, 4))

        layout = (Tiles("") * bounds1 + Tiles("") * bounds2 +
                  Tiles("") * bounds3 + Tiles("") * bounds4).cols(2)

        state = self._get_plot_state(layout)
        self.assertEqual(state['data'][1]["subplot"], "mapbox")
        self.assertEqual(state['data'][3]["subplot"], "mapbox2")
        self.assertEqual(state['data'][5]["subplot"], "mapbox3")
        self.assertEqual(state['data'][7]["subplot"], "mapbox4")
        self.assertNotIn("xaxis", state['layout'])
        self.assertNotIn("yaxis", state['layout'])
Exemple #3
0
    def test_single_bounds(self):
        bounds = Bounds((1, 2, 3, 4))

        state = self._get_plot_state(bounds)

        shapes = state['layout']['shapes']
        self.assertEqual(len(shapes), 1)
        self.assert_path_shape_element(shapes[0], bounds)
    def test_single_bounds(self):
        bounds = Tiles("") * Bounds(
            (self.x_range[0], self.y_range[0], self.x_range[1],
             self.y_range[1])).redim.range(x=self.x_range, y=self.y_range)

        state = self._get_plot_state(bounds)
        self.assertEqual(state["data"][1]["type"], "scattermapbox")
        self.assertEqual(state["data"][1]["mode"], "lines")
        self.assertEqual(
            state["data"][1]["lon"],
            np.array([self.lon_range[i] for i in (0, 0, 1, 1, 0)]))
        self.assertEqual(
            state["data"][1]["lat"],
            np.array([self.lat_range[i] for i in (0, 1, 1, 0, 0)]))
        self.assertEqual(state["data"][1]["showlegend"], False)
        self.assertEqual(state["data"][1]["line"]["color"],
                         default_shape_color)
        self.assertEqual(state['layout']['mapbox']['center'], {
            'lat': self.lat_center,
            'lon': self.lon_center
        })
Exemple #5
0
    def test_overlay(self):
        # Base layer is mapbox vector layer
        tiles = Tiles("").opts(mapboxstyle="dark", accesstoken="token-str")

        # Raster tile layer
        stamen_raster = StamenTerrain().opts(alpha=0.7)

        # RGB layer
        rgb_data = np.random.rand(10, 10, 3)
        rgb = RGB(rgb_data,
                  bounds=(self.x_range[0], self.y_range[0], self.x_range[1],
                          self.y_range[1])).opts(opacity=0.5)

        # Points layer
        points = Points([(0, 0), (self.x_range[1], self.y_range[1])
                         ]).opts(show_legend=True)

        # Bounds
        bounds = Bounds((self.x_range[0], self.y_range[0], 0, 0))

        # Overlay
        overlay = (tiles * stamen_raster * rgb * points * bounds).redim.range(
            x=self.x_range, y=self.y_range)

        # Render to plotly figure dictionary
        fig_dict = plotly_renderer.get_plot_state(overlay)

        # Check number of traces and layers
        traces = fig_dict["data"]
        subplot = fig_dict["layout"]["mapbox"]
        layers = subplot["layers"]

        self.assertEqual(len(traces), 5)
        self.assertEqual(len(layers), 2)

        # Check vector layer
        dummy_trace = traces[0]
        self.assertEqual(dummy_trace["type"], "scattermapbox")
        self.assertEqual(dummy_trace["lon"], [])
        self.assertEqual(dummy_trace["lat"], [])
        self.assertFalse(dummy_trace["showlegend"])

        self.assertEqual(subplot["style"], "dark")
        self.assertEqual(subplot["accesstoken"], "token-str")
        self.assertEqual(subplot['center'], {
            'lat': self.lat_center,
            'lon': self.lon_center
        })

        # Check raster layer
        dummy_trace = traces[1]
        raster_layer = layers[0]
        self.assertEqual(dummy_trace["type"], "scattermapbox")
        self.assertEqual(dummy_trace["lon"], [])
        self.assertEqual(dummy_trace["lat"], [])
        self.assertFalse(dummy_trace["showlegend"])

        # Check raster_layer
        self.assertEqual(raster_layer["below"], "traces")
        self.assertEqual(raster_layer["opacity"], 0.7)
        self.assertEqual(raster_layer["sourcetype"], "raster")
        self.assertEqual(raster_layer["source"][0].lower(),
                         stamen_raster.data.lower())

        # Check RGB layer
        dummy_trace = traces[2]
        rgb_layer = layers[1]
        self.assertEqual(dummy_trace["type"], "scattermapbox")
        self.assertEqual(dummy_trace["lon"], [None])
        self.assertEqual(dummy_trace["lat"], [None])
        self.assertFalse(dummy_trace["showlegend"])

        # Check rgb_layer
        self.assertEqual(rgb_layer["below"], "traces")
        self.assertEqual(rgb_layer["opacity"], 0.5)
        self.assertEqual(rgb_layer["sourcetype"], "image")
        self.assertTrue(
            rgb_layer["source"].startswith("data:image/png;base64,iVBOR"))
        self.assertEqual(rgb_layer["coordinates"],
                         [[self.lon_range[0], self.lat_range[1]],
                          [self.lon_range[1], self.lat_range[1]],
                          [self.lon_range[1], self.lat_range[0]],
                          [self.lon_range[0], self.lat_range[0]]])

        # Check Points layer
        points_trace = traces[3]
        self.assertEqual(points_trace["type"], "scattermapbox")
        self.assertEqual(points_trace["lon"], np.array([0, self.lon_range[1]]))
        self.assertEqual(points_trace["lat"], np.array([0, self.lat_range[1]]))
        self.assertEqual(points_trace["mode"], "markers")
        self.assertTrue(points_trace.get("showlegend", True))

        # Check Bounds layer
        bounds_trace = traces[4]
        self.assertEqual(bounds_trace["type"], "scattermapbox")
        self.assertEqual(
            bounds_trace["lon"],
            np.array([
                self.lon_range[0], self.lon_range[0], 0, 0, self.lon_range[0]
            ]))
        self.assertEqual(
            bounds_trace["lat"],
            np.array([
                self.lat_range[0], 0, 0, self.lat_range[0], self.lat_range[0]
            ]))
        self.assertEqual(bounds_trace["mode"], "lines")
        self.assertTrue(points_trace["showlegend"], False)

        # No xaxis/yaxis
        self.assertNotIn("xaxis", fig_dict["layout"])
        self.assertNotIn("yaxis", fig_dict["layout"])
Exemple #6
0
 def test_bounds_styling(self):
     self.assert_shape_element_styling(Bounds((1, 2, 3, 4)))