-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pydeck: Update for new @deck.gl/json API and add additional tes… (#4020)
- Loading branch information
1 parent
6d0a7d0
commit 851909b
Showing
16 changed files
with
657 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
bindings/python/pydeck/tests/bindings/pydeck_examples/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .minimal import create_minimal_test_object # noqa | ||
from .hexagon_layer_function import create_heatmap_test_object # noqa | ||
from .geojson_layer import create_geojson_layer_test_object # noqa | ||
from .multilayers import create_multi_layer_test_object # noqa | ||
from .scatterplot import create_scatterplot_test_object # noqa | ||
from .stacked import create_stacked_test_object # noqa |
43 changes: 43 additions & 0 deletions
43
bindings/python/pydeck/tests/bindings/pydeck_examples/geojson_layer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pydeck import Deck, Layer, ViewState | ||
|
||
features = { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[-122.42923736572264, 37.80544394934271], | ||
[0, 37.80544394934271], | ||
[-122.42923736572264, 0], | ||
[-122.42923736572264, 37.80544394934271], | ||
] | ||
], | ||
}, | ||
} | ||
], | ||
} | ||
|
||
|
||
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) |
81 changes: 81 additions & 0 deletions
81
bindings/python/pydeck/tests/bindings/pydeck_examples/hexagon_layer_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from pydeck import Deck, Layer, View, ViewState | ||
|
||
color_range = [ | ||
[1, 152, 189], | ||
[73, 227, 206], | ||
[216, 254, 181], | ||
[254, 237, 177], | ||
[254, 173, 84], | ||
[209, 55, 78], | ||
] | ||
|
||
data = [ | ||
{"lat": 0, "lon": 0}, | ||
{"lat": 0, "lon": 0}, | ||
{"lat": 0, "lon": 0}, | ||
{"lat": 0, "lon": 1}, | ||
{"lat": 0.1, "lon": 1}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 0.2, "lon": 1.2}, | ||
{"lat": 0.2, "lon": 1.2}, | ||
{"lat": 0.2, "lon": 1.2}, | ||
{"lat": 0.2, "lon": 1.2}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 0.1, "lon": 0.1}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
{"lat": 1.2, "lon": 1.2}, | ||
] | ||
|
||
|
||
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, | ||
) |
29 changes: 29 additions & 0 deletions
29
bindings/python/pydeck/tests/bindings/pydeck_examples/minimal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pydeck import Deck, Layer, LightSettings, View, ViewState | ||
|
||
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/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) | ||
return Deck(layers=[layer], initial_view_state=view_state, views=[view]) |
46 changes: 46 additions & 0 deletions
46
bindings/python/pydeck/tests/bindings/pydeck_examples/multilayers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pydeck import Deck, Layer, ViewState | ||
|
||
|
||
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, | ||
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 | ||
) |
16 changes: 16 additions & 0 deletions
16
bindings/python/pydeck/tests/bindings/pydeck_examples/scatterplot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pydeck import Deck, Layer, ViewState | ||
|
||
|
||
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) |
Oops, something went wrong.