From b80de0a43d53342290530994cdadcfef9f0fc5b4 Mon Sep 17 00:00:00 2001 From: Felix Claessen <30658763+Flix6x@users.noreply.github.com> Date: Sun, 25 Jun 2023 20:47:23 +0200 Subject: [PATCH] feat: sensors with % units get chart including 0-100% in their domain (#739) Having percentages within [0, 100] is such a common use case that we should always include this domain in the scale. This makes it easier to read off individual charts, and also to compare across charts (for example, when showing simulation results of different scenarios). * feat: sensors with % units get chart including 0-100% in their domain Signed-off-by: F.N. Claessen * fix: also implement new feat on sensor page Signed-off-by: F.N. Claessen * docs: changelog entry Signed-off-by: F.N. Claessen * feat: better visibility in case of 100% values Signed-off-by: F.N. Claessen --------- Signed-off-by: F.N. Claessen --- documentation/changelog.rst | 1 + flexmeasures/data/models/charts/belief_charts.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 29d0b8778..eed9fbda7 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -11,6 +11,7 @@ New features * Allow deleting multiple sensors with a single call to ``flexmeasures delete sensor`` by passing the ``--id`` option multiple times [see `PR #734 `_] * Make it a lot easier to read off the color legend on the asset page, especially when showing many sensors, as they will now be ordered from top to bottom in the same order as they appear in the chart (as defined in the ``sensors_to_show`` attribute), rather than alphabetically [see `PR #742 `_] +* Having percentages within the [0, 100] domain is such a common use case that we now always include it in sensor charts with % units, making it easier to read off individual charts and also to compare across charts [see `PR #739 `_] Bugfixes ----------- diff --git a/flexmeasures/data/models/charts/belief_charts.py b/flexmeasures/data/models/charts/belief_charts.py index c6f535a21..5d3f9d7da 100644 --- a/flexmeasures/data/models/charts/belief_charts.py +++ b/flexmeasures/data/models/charts/belief_charts.py @@ -29,6 +29,10 @@ def bar_chart( stack=None, **FIELD_DEFINITIONS["event_value"], ) + if unit == "%": + event_value_field_definition["scale"] = dict( + domain={"unionWith": [0, 105]}, nice=False + ) event_start_field_definition = FIELD_DEFINITIONS["event_start"] event_start_field_definition["timeUnit"] = { "unit": "yearmonthdatehoursminutesseconds", @@ -139,6 +143,10 @@ def chart_for_multiple_sensors( stack=None, **FIELD_DEFINITIONS["event_value"], ) + if unit == "%": + event_value_field_definition["scale"] = dict( + domain={"unionWith": [0, 105]}, nice=False + ) # Set up shared tooltip shared_tooltip = [