diff --git a/CHANGELOG.md b/CHANGELOG.md index 87c66bb..a22d405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and the versioning aim to respect [Semantic Versioning](http://semver.org/spec/v Here is a template for new release sections +## [Unreleased] +### Added +- title and unit for choropleths in legend + ## [0.8.0] - 2023-05-02 ### Added - default choropleth config diff --git a/django_mapengine/setup.py b/django_mapengine/setup.py index 24237ad..614eeca 100644 --- a/django_mapengine/setup.py +++ b/django_mapengine/setup.py @@ -104,6 +104,8 @@ class Choropleth: """Choropleth class used to set up choropleths in project settings""" name: str + title: str + unit: str layers: List[str] use_feature_state: bool = True @@ -116,7 +118,12 @@ def as_dict(self) -> dict: dict holding choropleth values needed in map setups """ - return {"layers": self.layers, "useFeatureState": self.use_feature_state} + return { + "title": self.title, + "unit": self.unit, + "layers": self.layers, + "useFeatureState": self.use_feature_state, + } @dataclass diff --git a/django_mapengine/static/django_mapengine/js/legend.js b/django_mapengine/static/django_mapengine/js/legend.js index 090ee1d..762772b 100644 --- a/django_mapengine/static/django_mapengine/js/legend.js +++ b/django_mapengine/static/django_mapengine/js/legend.js @@ -38,7 +38,8 @@ const createLegend = (title, unit, colors, valueRanges, nextColumnStartIndex = 3 function loadLegend(msg, choroplethName){ - const unit = "unit"; //need value! + const title = map_store.cold.choropleths[choroplethName]["title"]; + const unit = map_store.cold.choropleths[choroplethName]["unit"]; const paintPropertiesPerLayer = map_store.cold.storedChoroplethPaintProperties[choroplethName]; /* Find active layer */ @@ -75,6 +76,6 @@ function loadLegend(msg, choroplethName){ } } const entriesPerColumn = Math.floor(values.length / 2); - legendElement.innerHTML = createLegend(choroplethName, unit, colors, values, entriesPerColumn); + legendElement.innerHTML = createLegend(title, unit, colors, values, entriesPerColumn); return logMessage(msg); } diff --git a/tests/django_test_settings.py b/tests/django_test_settings.py index a2f28eb..799fe09 100644 --- a/tests/django_test_settings.py +++ b/tests/django_test_settings.py @@ -4,6 +4,8 @@ INSTALLED_APPS = ["django_mapengine", "tests.test_app.apps.TestConf"] +ROOT_URLCONF = "django_mapengine.urls" + MAP_ENGINE_CENTER_AT_STARTUP = [1, 2] MAP_ENGINE_ZOOM_AT_STARTUP = 8