Skip to content

Commit c47c550

Browse files
committed
Updated base map in mapping to render more geographic features with ArcGIS World Imagery and reduced margins to increase size of graph components, updated tests to look for scattermapbox instead of scattergeo.
1 parent 8fca070 commit c47c550

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

components/divs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Fixed styles and sorting options
44
H1_STYLE = {'textAlign': 'center', 'color': 'MidnightBlue'}
55
H4_STYLE = {'color': 'MidnightBlue', 'margin-bottom' : 10}
6-
HALF_DIV_STYLE = {'width': '48%', 'display': 'inline-block'}
6+
HALF_DIV_STYLE = {'height': '48%', 'width': '48%', 'display': 'inline-block'}
77
QUARTER_DIV_STYLE = {'width': '24%', 'display': 'inline-block'}
88
BUTTON_STYLE = {'color': 'MidnightBlue',
99
'background-color': 'BlanchedAlmond',
@@ -267,7 +267,10 @@ def get_main_div(hist_div, img_div):
267267

268268
# Graphs - Distribution (histogram or map), then pie chart
269269
html.Div([
270-
dcc.Graph(id = 'dist-plot')], style = HALF_DIV_STYLE),
270+
dcc.Loading(id = 'dist-plot-loading',
271+
type = "circle",
272+
color = 'DarkMagenta',
273+
children = dcc.Graph(id = 'dist-plot'))], style = HALF_DIV_STYLE),
271274
html.Div([
272275
dcc.Graph(id = 'pie-plot')], style = HALF_DIV_STYLE),
273276

components/graphs.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ def make_hist_plot(df, x_var, color_by, sort_by):
2626
color = color_by,
2727
color_discrete_sequence = px.colors.qualitative.Bold).update_xaxes(categoryorder = sort_by)
2828

29-
fig.update_layout(title = {'text': f'Distribution of {x_var} Colored by {color_by}'})
29+
fig.update_layout(title = {'text': f'Distribution of {x_var} Colored by {color_by}'},
30+
font = {'size': 16},
31+
margin = {
32+
'l': 30,
33+
'r': 20,
34+
't': 35,
35+
'b': 20
36+
})
3037

3138
return fig
3239

@@ -46,23 +53,16 @@ def make_map(df, color_by):
4653
df = df.copy()
4754
# only use entries that have valid lat & lon for mapping
4855
df = df.loc[df['lat-lon'].str.contains('unknown') == False]
49-
fig = px.scatter_geo(df,
50-
lat = df.lat,
51-
lon = df.lon,
52-
projection = "natural earth",
56+
fig = px.scatter_mapbox(df,
57+
lat = "lat",
58+
lon = "lon",
59+
#projection = "natural earth",
5360
custom_data = ["Samples_at_locality", "Species_at_locality", "Subspecies_at_locality"],
54-
size = df.Samples_at_locality,
61+
size = "Samples_at_locality",
5562
color = color_by,
5663
color_discrete_sequence = px.colors.qualitative.Bold,
5764
title = "Distribution of Samples")
5865

59-
fig.update_geos(fitbounds = "locations",
60-
showcountries = True, countrycolor = "Grey",
61-
showrivers = True,
62-
showlakes = True,
63-
showland = True, landcolor = "wheat",
64-
showocean = True, oceancolor = "LightBlue")
65-
6666
fig.update_traces(hovertemplate =
6767
"Latitude: %{lat}<br>"+
6868
"Longitude: %{lon}<br>" +
@@ -71,6 +71,25 @@ def make_map(df, color_by):
7171
"Subspecies at lat/lon: %{customdata[2]}<br>"
7272
)
7373

74+
fig.update_layout(
75+
font = {'size': 16},
76+
margin = {
77+
'l': 20,
78+
'r': 20,
79+
't': 35,
80+
'b': 20
81+
},
82+
mapbox_style = "white-bg",
83+
mapbox_layers = [{
84+
"below": "traces",
85+
"sourcetype": "raster",
86+
"sourceattribution": "Esri, Maxar, Earthstar Geographics, and the GIS User Community",
87+
"source": ["https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"]
88+
# Usage and Licensing (ArcGIS World Imagery): https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer
89+
# Style: https://roblabs.com/xyz-raster-sources/styles/arcgis-world-imagery.json
90+
}]
91+
)
92+
7493
return fig
7594

7695
def make_pie_plot(df, var):
@@ -97,6 +116,13 @@ def make_pie_plot(df, var):
97116
color_discrete_sequence = px.colors.qualitative.Bold)
98117
pie_fig.update_traces(textposition = 'inside', textinfo = 'percent+label')
99118

100-
pie_fig.update_layout(title = {'text': f'Percentage Breakdown of {var}'})
119+
pie_fig.update_layout(title = {'text': f'Percentage Breakdown of {var}'},
120+
font = {'size': 16},
121+
margin = {
122+
'l': 20,
123+
'r': 20,
124+
't': 35,
125+
'b': 20
126+
})
101127

102128
return pie_fig

tests/components/test_graphs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_make_map():
2525
# Map plot output
2626
output = make_map(processed_df, "Species")
2727
output_data = output['data', 0]
28-
assert output_data.type == "scattergeo"
28+
assert output_data.type == "scattermapbox"
2929
#test for uknowns in data and check it's proper type
3030
assert 'unknown' not in output_data['customdata']
3131

tests/test_app_callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_update_dist_plot_call():
3434

3535
# Map plot output
3636
output2 = update_dist_plot('Species', 'Subspecies', 'alpha', "Show Histogram", jsonified_data)
37-
assert output2['data', 0].type == "scattergeo"
37+
assert output2['data', 0].type == "scattermapbox"
3838

3939

4040
def test_update_pie_plot():

0 commit comments

Comments
 (0)