def test_json_output(): lights = LightSettings( lights_position=[ -0.144528, 49.739968, 8000, -3.807751, 54.104682, 8000], ambient_ratio=0.4, diffuse_ratio=0.6) layer = Layer( 'HexagonLayer', 'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv', id='heatmap', elevation_scale=50, elevation_range=[0, 3000], extruded=True, coverage=1, light_settings=lights) view_state = ViewState( longitude=-1.4157267858730052, latitude=52.232395363869415, zoom=6.6, min_zoom=5, max_zoom=15, pitch=40.5, bearing=-27.396674584323023) view = View(type='MapView', controller=True) deck = Deck(layers=[layer], initial_view_state=view_state, views=[view]) assert str(deck) == json.dumps(json.loads(FIXTURE_STRING), sort_keys=True)
def create_minimal_test_object(): lights = LightSettings( lights_position=[ -0.144528, 49.739968, 8000, -3.807751, 54.104682, 8000 ], ambient_ratio=0.4, diffuse_ratio=0.6, ) layer = Layer( "HexagonLayer", "https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv", id="heatmap", elevation_scale=50, elevation_range=[0, 3000], extruded=True, coverage=1, light_settings=lights, ) view_state = ViewState( longitude=-1.4157267858730052, latitude=52.232395363869415, zoom=6.6, min_zoom=5, max_zoom=15, pitch=40.5, bearing=-27.396674584323023, ) view = View(type="MapView", controller=True) return Deck(layers=[layer], initial_view_state=view_state, views=[view])
def create_heatmap_test_object(): DESCRIPTION = "HexagonLayer without a function string should fail but HeatmapLayer should succeed" # This actually shouldn't render # Tries to detect if strings are being interpreted by the # expression parser in @deck.gl/json failed_hexagon_layer = Layer( type="HexagonLayer", id="failed-heatmap", data=data, elevation_range=[0, 15], elevation_scale=1800, get_position="'[lon, lat]'", radius=10000, upper_percentile=100, color_range=color_range, ) # This will render successful_heatmap_layer = Layer( type="HeatmapLayer", id="successful-heatmap", data=data, get_position=["lon", "lat"], color_range=color_range, ) return Deck( description=DESCRIPTION, initial_view_state=ViewState( **{"longitude": 0, "latitude": 0, "zoom": 5, "pitch": 40.5, "bearing": -27.396674584323023} ), views=[View(type="MapView", controller=True)], layers=[failed_hexagon_layer, successful_heatmap_layer], map_style=None, )
def create_stacked_test_object(): view_state = ViewState(max_zoom=20, zoom=15) scatterplot = Layer( "ScatterplotLayer", data=data, get_position="position", get_radius=100, id="first", getColor="rgb", ) text_layer = Layer( "TextLayer", data=df, id="second", font_size=144, get_color=[0, 0, 255], get_position="position", get_text_anchor="`start`", font_family="`Times, Times New Roman, Georgia, serif`", ) return Deck( description="Test of plotting multiple layers at once", layers=[scatterplot, text_layer], initial_view_state=view_state, views=None, map_style=None, )
def create_scatterplot_test_object(): view_state = ViewState(latitude=0, longitude=0, zoom=12) layers = [ Layer( "ScatterplotLayer", id="scatterplot", data=[[0, 0], [0.01, 0.01]], get_position="-", get_radius=500, get_fill_color=[255, 0, 0], ) ] return Deck(layers=layers, initial_view_state=view_state, map_style=None, views=None)
def create_multi_layer_test_object(): view_state = ViewState(latitude=-122.45, longitude=37.8, zoom=12) scatterplot = Layer( "ScatterplotLayer", id='scatterplot', data=[{ "position": [-122.45, 37.8] }], get_position='position', get_fill_color=[255, 0, 0, 255], get_radius=1000, ) text_layer = Layer( "TextLayer", id='textlayer', data=[{ "position": [-122.45, 37.8], "text": "Hello World" }], get_position='position', get_text_anchor="end", ) geojson_layer = Layer( "GeoJsonLayer", id='geojsonlayer', data={ "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-122.42923736572264, 37.80544394934271], }, }], }, stroked=True, filled=True, get_position='features.geometry.coordinates', line_width_min_pixels=2, opacity=0.4, get_line_color=[255, 100, 100], get_fill_color=[200, 160, 0, 180], ) return Deck(layers=[scatterplot, text_layer, geojson_layer], initial_view_state=view_state)
def create_geojson_layer_test_object(): return Deck(description="Test of GeoJsonLayer", map_style=None, initial_view_state=ViewState(longitude=-122.45, latitude=37.8, zoom=0), layers=[ Layer( "GeoJsonLayer", id='geojson-layer', data=features, stroked=True, filled=True, line_width_min_pixels=2, opacity=0.4, get_line_color=[255, 100, 100], get_fill_color=[200, 160, 0, 180], ) ], views=None)
def create_geojson_layer_with_gmaps_test_object(): return Deck( description="Test of GeoJsonLayer, with Google Maps basemap", map_style="satellite", map_provider="google_maps", initial_view_state=ViewState(longitude=-122.45, latitude=37.8, zoom=0), layers=[ Layer( "GeoJsonLayer", id="geojson-layer", data=features, stroked=True, filled=True, line_width_min_pixels=2, opacity=0.4, get_line_color=[255, 100, 100], get_fill_color=[200, 160, 0, 180], ) ], views=None, )
picking_radius=5, pickable=True, get_color="rgb", get_position="position", ), Layer( "TextLayer", data=text_data, picking_radius=5, get_color=[255, 255, 255], pickable=True, font_size=72, get_position="position", ), ]) v = ViewState(latitude=0, longitude=0, zoom=15) d.initial_view_state = v def has_pyppeteer(): try: import pyppeteer # noqa return True except ImportError: return False @pytest.mark.skipif(os.environ.get("TRAVIS") == "true" or not has_pyppeteer(), reason="Skipping Python screenshot tests") @pytest.mark.asyncio
8000], ambient_ratio=0.4, diffuse_ratio=0.6) layer = Layer( 'HexagonLayer', 'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv', id='heatmap', elevation_scale=50, elevation_range=[0, 3000], extruded=True, coverage=1, light_settings=lights) view_state = ViewState( longitude=-1.4157267858730052, latitude=52.232395363869415, zoom=6.6, min_zoom=5, max_zoom=15, pitch=40.5, bearing=-27.396674584323023) view = View(type='MapView', controller=True) deck = Deck(layers=[layer], initial_view_state=view_state, views=[view]) def test_json_output(): """Verify that the JSON rendering produces an @deck.gl/json library-compliant JSON object""" assert str(deck) == json.dumps(json.loads(FIXTURE_STRING), sort_keys=True) def test_update(): """Verify that calling `update` changes the Deck object""" view_state.latitude, view_state.longitude = 0, 0