Skip to content

Commit

Permalink
Hardcode chorpleth legend for energy shares
Browse files Browse the repository at this point in the history
  • Loading branch information
henhuy committed Oct 15, 2024
1 parent 365b655 commit 5926c9f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ 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_capita_statusquo",
Expand Down
38 changes: 37 additions & 1 deletion digiplan/map/choropleths.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,49 @@ def get_values_per_feature(self) -> dict[int, float]: # noqa: D102

def get_fill_color(self, values: dict[int, float]) -> dict: # noqa: ARG002
"""Fix choropleth legend and colors to max value of 100%."""
return settings.MAP_ENGINE_CHOROPLETH_STYLES.get_fill_color(self.lookup, [0.0, 99.0])
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

0 comments on commit 5926c9f

Please sign in to comment.