Skip to content

Commit 930b23a

Browse files
committed
Update gui_bivariate_utils.py
1 parent c876061 commit 930b23a

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

tools/code/gui_bivariate_utils.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -899,28 +899,32 @@ def highlight_function(feature):
899899
<p><b>Exposure quantile:</b> {hazard_q}</p>
900900
</div>
901901
"""
902-
902+
903903
def popup_function(feature):
904904
feature_id = feature['properties'][id_field]
905905
feature_data = gdf[gdf[id_field] == feature_id]
906906

907907
if not feature_data.empty:
908908
row = feature_data.iloc[0]
909-
return folium.Popup(
910-
html.format(
911-
name=row[name_field],
912-
pop=row[population_field_selector.value],
913-
area=row['area_km2'],
914-
pop_dens=row['pop_density'],
915-
rwi=row[wealth_field_selector.value],
916-
w_rwi=row['w_RWIxPOP_scaled'],
917-
hazard=row[hazard_field_selector.value],
918-
rel_exposure=row['relative_exposure'],
919-
wealth_q=int(row['wealth_quantile']) + 1,
920-
hazard_q=int(row['hazard_quantile']) + 1
921-
),
922-
max_width=350
923-
)
909+
try:
910+
return folium.Popup(
911+
html.format(
912+
name=row[name_field],
913+
pop=row[population_field_selector.value],
914+
area=row['area_km2'],
915+
pop_dens=row['pop_density'],
916+
rwi=row[wealth_field_selector.value],
917+
w_rwi=row['w_RWIxPOP_scaled'],
918+
hazard=row[hazard_field_selector.value],
919+
rel_exposure=row['relative_exposure'],
920+
wealth_q=int(row['wealth_quantile']) + 1,
921+
hazard_q=int(row['hazard_quantile']) + 1
922+
),
923+
max_width=350
924+
)
925+
except Exception as e:
926+
print(f"Error creating popup: {str(e)}")
927+
return folium.Popup(f"Error displaying data for {row[name_field]}", max_width=350)
924928
else:
925929
return folium.Popup("No data available", max_width=350)
926930

0 commit comments

Comments
 (0)