Skip to content

Commit

Permalink
Merge pull request #156 from empowerplan/fix/choropleth_legend
Browse files Browse the repository at this point in the history
Fix choropleth legend and RE share choropleth
  • Loading branch information
nesnoj authored Nov 20, 2024
2 parents 7a61cd3 + 4153803 commit 1a9ba4a
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 98 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
- 404 errors for missing MVTs
- truncated tooltips
- choropleth is reactivated when revisiting status quo
- choropleth legend
- choropleth for RE share

### Changed
- improve accessibility
Expand Down
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,14 @@ def __getitem__(self, item): # noqa: D105, ANN001, ANN204
layers=["municipality"],
title=_("Anteil Erneuerbare Energien am Strombedarf"),
unit="%",
labels=["0 - 20", "20 - 40", "40 - 60", "60 - 80", "80 - 100", " > 100"],
),
setup.Choropleth(
"energy_share_2045",
layers=["municipality"],
title=_("Anteil Erneuerbare Energien am Strombedarf"),
unit="%",
labels=["0 - 20", "20 - 40", "40 - 60", "60 - 80", "80 - 100", " > 100"],
),
setup.Choropleth(
"energy_capita_statusquo",
Expand Down
6 changes: 5 additions & 1 deletion digiplan/map/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def render(self) -> dict:
self.chart_options["series"][0]["data"] = data
elif series_length > 1:
for i in range(0, series_length):
values = self.chart_data[i]
values = (
self.chart_data.iloc[i]
if isinstance(self.chart_data, (pd.DataFrame, pd.Series))
else self.chart_data[i]
)
if not isinstance(values, (list, tuple)):
values = [values]
self.chart_options["series"][i]["data"] = values
Expand Down
40 changes: 40 additions & 0 deletions digiplan/map/choropleths.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,51 @@ class EnergyShareChoropleth(Choropleth): # noqa: D101
def get_values_per_feature(self) -> dict[int, float]: # noqa: D102
return calculations.energy_shares_per_municipality().sum(axis=1).round().to_dict()

def get_fill_color(self, values: dict[int, float]) -> dict: # noqa: ARG002
"""Fix choropleth legend and colors to max value of 100%."""
return [
"interpolate",
["linear"],
["feature-state", "energy_share_statusquo"],
0.0,
"rgb(255, 255, 204)",
20.0,
"rgb(199, 233, 180)",
40.0,
"rgb(127, 205, 187)",
60.0,
"rgb(65, 182, 196)",
80.0,
"rgb(44, 127, 184)",
100.0,
"rgb(37, 52, 148)",
]


class EnergyShare2045Choropleth(Choropleth): # noqa: D101
def get_values_per_feature(self) -> dict[int, float]: # noqa: D102
return calculations.energy_shares_2045_per_municipality(self.map_state).sum(axis=1).to_dict()

def get_fill_color(self, values: dict[int, float]) -> dict: # noqa: ARG002
"""Fix choropleth legend and colors to max value of 100%."""
return [
"interpolate",
["linear"],
["feature-state", "energy_share_statusquo"],
0.0,
"rgb(255, 255, 204)",
20.0,
"rgb(199, 233, 180)",
40.0,
"rgb(127, 205, 187)",
60.0,
"rgb(65, 182, 196)",
80.0,
"rgb(44, 127, 184)",
100.0,
"rgb(37, 52, 148)",
]


class EnergyChoropleth(Choropleth): # noqa: D101
def get_values_per_feature(self) -> dict[int, float]: # noqa: D102
Expand Down
8 changes: 8 additions & 0 deletions digiplan/static/config/choropleths.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
"color_palette": "YlGnBu",
"num_colors": 6
},
"energy_share_statusquo": {
"color_palette": "YlGnBu",
"num_colors": 6
},
"energy_share_2045": {
"color_palette": "YlGnBu",
"num_colors": 6
},
"re_power_percentage": {
"color_palette": "GnBu",
"values": [
Expand Down
Loading

0 comments on commit 1a9ba4a

Please sign in to comment.