Skip to content

Commit

Permalink
Evolution as map (#14)
Browse files Browse the repository at this point in the history
* remove old files

* move evolution map to map section

* return evolution map as html

* update docstring

* suggestions for no autoplay on evolution map

---------

Co-authored-by: Sarah Rieubland <[email protected]>
  • Loading branch information
gmguarino and sarahrieubland authored Jun 4, 2024
1 parent 70e54b6 commit 13d78a9
Show file tree
Hide file tree
Showing 34 changed files with 5,634 additions and 5,773 deletions.
33 changes: 0 additions & 33 deletions Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions main.py

This file was deleted.

4 changes: 2 additions & 2 deletions pinkbombs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .graphs.viz import make_area_chart, make_area_single_chart, make_area_chart_options
from .graphs.viz import make_area_order_chart, make_bar_chart, make_area_order_chart_grouped
from .graphs.viz import make_color_bar_chart, make_color_bar_chart2
from .graphs.viz import make_animated_bubble_map, make_treemap_chart
from .graphs.viz import make_treemap_chart
from .graphs.viz import make_simple_bar_chart, make_simple_pie_chart
from .graphs.viz import make_simple_box_chart, make_matrix_alternatives
from .graphs.maps_viz import make_ras_bubble_map
from .graphs.maps_viz import make_ras_bubble_map, make_animated_bubble_map


# from .router import api
Expand Down
15 changes: 0 additions & 15 deletions pinkbombs/auth/authenicate.py

This file was deleted.

6 changes: 0 additions & 6 deletions pinkbombs/auth/cors.py

This file was deleted.

72 changes: 36 additions & 36 deletions pinkbombs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,6 @@
True,
],
},
"evolution-map": {
"filename": "evolution_salmon_farming_country_iso_1.4.csv",
"function": pb.make_animated_bubble_map,
"parser": pd.read_csv,
"arguments": [
"alpha-3",
"Country",
"Year",
"Tonnes - live weight",
"Evolution of salmon farming by country",
1980,
50,
True,
[
'#151c97',
],
],
},
"top-comp": {
"filename": "top_10_companies_producing_2.1.csv",
"function": pb.make_simple_bar_chart,
Expand Down Expand Up @@ -174,6 +156,24 @@
False,
],
},
"evolution-map": {
"filename": "evolution_salmon_farming_country_iso_1.4.csv",
"function": pb.make_animated_bubble_map,
"parser": pd.read_csv,
"arguments": [
"alpha-3",
"Country",
"Year",
"Tonnes - live weight",
"Evolution of salmon farming by country",
1980,
50,
True,
[
'#151c97',
],
],
},
}

MAPPINGFR = {
Expand Down Expand Up @@ -238,24 +238,6 @@
True,
],
},
"evolution-map": {
"filename": "evolution_salmon_farming_country_iso_1.4_fr.csv",
"function": pb.make_animated_bubble_map,
"parser": pd.read_csv,
"arguments": [
"alpha-3",
"Pays",
"Année",
"Tonnes de saumon",
"Evolution de l'élevage de saumons par pays",
1980,
50,
True,
[
'#151c97',
],
],
},
"top-comp": {
"filename": "top_10_companies_producing_2.1_fr.csv",
"function": pb.make_simple_bar_chart,
Expand Down Expand Up @@ -348,4 +330,22 @@
True
],
},
"evolution-map": {
"filename": "evolution_salmon_farming_country_iso_1.4_fr.csv",
"function": pb.make_animated_bubble_map,
"parser": pd.read_csv,
"arguments": [
"alpha-3",
"Pays",
"Année",
"Tonnes de saumon",
"Evolution de l'élevage de saumons par pays",
1980,
50,
True,
[
'#151c97',
],
],
},
}
4 changes: 2 additions & 2 deletions pinkbombs/graphs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .viz import make_area_chart, make_area_single_chart, make_area_chart_options
from .viz import make_area_order_chart, make_bar_chart, make_area_order_chart_grouped
from .viz import make_color_bar_chart, make_color_bar_chart2
from .viz import make_animated_bubble_map, make_treemap_chart
from .viz import make_treemap_chart
from .viz import make_simple_bar_chart, make_simple_pie_chart
from .viz import make_simple_box_chart, make_matrix_alternatives
from .maps_viz import make_ras_bubble_map
from .maps_viz import make_ras_bubble_map, make_animated_bubble_map
65 changes: 65 additions & 0 deletions pinkbombs/graphs/maps_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,71 @@
import folium
from folium.plugins import GroupedLayerControl
from branca.element import Template, MacroElement
import plotly.express as px
from plotly.graph_objects import Figure


def make_animated_bubble_map(
input_df,
input_loc,
input_hover,
input_time,
input_size,
title,
min_year=1950,
size_max=50,
last_frame=True,
palette=px.colors.qualitative.Prism,
theme="simple_white",
reverse=False,
) -> str:
"""Returns plotly express object as Bubbles map with animation
Parameters:
input_df (pd.DataFrame): dataframe with data to be visualised
input_loc (str): name of the field with the iso alpha3 codes
input_hover (str): name of the field to show on hover
input_time (str): name of the time field for the animation
input_size (str): name of the field for the size of the bubbles
min_year (int): year to start the animation, default=1950
title (str): chart title
size_max (int): size of the maximum bubble radius, default=50
palette (px.object): plotly discrete palette, default is Prism
theme (str): plotly chart theme, default is 'simple_white'
last_frame (boolean): to add last frame as first
Returns:
area (html): output chart object as html string.
"""
# if reverse:
# input_df = input_df.sort_values(by=input_time, ascending=False)
if min_year > 1950:
input_df = input_df.loc[input_df[input_time] >= min_year,]

map = px.scatter_geo(
input_df,
locations=input_loc,
size=input_size,
animation_frame=input_time,
projection="natural earth",
size_max=size_max,
hover_name=input_hover,
hover_data={input_size: ":,.0f", input_time: True, input_hover: False, input_loc: False},
color_discrete_sequence=palette,
title=title,
)
map.update_geos(showcountries=True)

if last_frame:
map2 = Figure()
for tr in map.frames[-1].data:
map2.add_trace(tr)
map2.layout = map.layout
map2.frames = map.frames
map2.layout["sliders"][0]["active"] = len(map.frames) - 1

# Remove lasso and select
map2.update_layout(modebar_remove=["lasso2d", "select2d"])

return map2.to_html(auto_play=False)


def get_transfo_param(df, col, min_rad=2.5, max_rad=60):
Expand Down
10 changes: 6 additions & 4 deletions pinkbombs/graphs/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@
palette=['#151c97'],
)

g1_4.write_html("pinkbombs/graphs/test_html/" + data1_4_name + ".html",
auto_play=False)
func1_4 = open("pinkbombs/graphs/test_html/" + data1_4_name + ".html","w")
func1_4.write(g1_4)
func1_4.close()

# Graph 1.4 - Evolution of salmon farming by country - FRENCH
data1_4_file = "data/" + data1_4_name + "_fr.csv"
Expand All @@ -175,8 +176,9 @@
palette=['#151c97'],
)

g1_4.write_html("pinkbombs/graphs/test_html/" + data1_4_name + "_fr.html",
auto_play=False)
func1_4 = open("pinkbombs/graphs/test_html/" + data1_4_name + "_fr.html","w")
func1_4.write(g1_4)
func1_4.close()

# Graph 2.1 - Top 10 companies producing salmon
data2_1_name = "top_10_companies_producing_2.1"
Expand Down
2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/alternatives_7.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/alternatives_7_fr.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/carbon_bombs_pie_chart_5.1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/discrease_wild_salmon_1.1.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/escapes_marine_cages_3.5.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/mortality_rates_4.4.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/mortality_rates_4.4_fr.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pinkbombs/graphs/test_html/numbers_salmons_farmed_1.0.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 13d78a9

Please sign in to comment.