From 597153f83b4f99b93f6c15c3a3a4fe306d1b4e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Thu, 25 Mar 2021 17:22:49 +0100 Subject: [PATCH] Better xrange and title if only schedules are plotted (#67) * If only prognosed data is given, the title of the plot can reflect that * the xrange is not dependent on the the main data dataframe being non-empty --- documentation/changelog.rst | 1 + flexmeasures/ui/utils/plotting_utils.py | 16 ++++++++++------ flexmeasures/ui/views/analytics.py | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 4d004192f..aaf1a520b 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -15,6 +15,7 @@ Bugfixes -------- * Show screenshots in documentation and add some missing content [see `PR #60 `_] * Documentation listed 2.0 API endpoints twice [see `PR #59 `_] +* Better xrange and title if only schedules are plotted [see `PR #67 `_] * User page did not list number of assets correctly [see `PR #64 `_] * Missing *postPrognosis* endpoint for >1.0 API blueprints [part of `PR #41 `_] diff --git a/flexmeasures/ui/utils/plotting_utils.py b/flexmeasures/ui/utils/plotting_utils.py index a05759c0f..9c407e01b 100644 --- a/flexmeasures/ui/utils/plotting_utils.py +++ b/flexmeasures/ui/utils/plotting_utils.py @@ -161,7 +161,7 @@ def naturaltime(delta): def make_range( index: pd.DatetimeIndex, other_index: pd.DatetimeIndex = None -) -> Union[None, Range1d]: +) -> Optional[Range1d]: """Make a 1D range of values from a datetime index or two. Useful to share axis among Bokeh Figures.""" index = tz_index_naively(index) other_index = tz_index_naively(other_index) @@ -245,13 +245,13 @@ def create_graph( # noqa: C901 "Forecast", "Schedules", ), - x_range: Range1d = None, - forecasts: pd.DataFrame = None, - schedules: pd.DataFrame = None, + x_range: Optional[Range1d] = None, + forecasts: Optional[pd.DataFrame] = None, + schedules: Optional[pd.DataFrame] = None, show_y_floats: bool = False, non_negative_only: bool = False, - tools: List[str] = None, - sizing_mode="scale_width", + tools: Optional[List[str]] = None, + sizing_mode: str = "scale_width", ) -> Figure: """ Create a Bokeh graph. As of now, assumes x data is datetimes and y data is numeric. The former is not set in stone. @@ -282,6 +282,10 @@ def create_graph( # noqa: C901 # Set x range if x_range is None: x_range = make_range(data.index) + if x_range is None and schedules is not None: + x_range = make_range(schedules.index) + if x_range is None and forecasts is not None: + x_range = make_range(forecasts.index) data = tz_index_naively(data) # Set default y range in case there is no data from which to derive a range diff --git a/flexmeasures/ui/views/analytics.py b/flexmeasures/ui/views/analytics.py index f1176b839..08d048586 100644 --- a/flexmeasures/ui/views/analytics.py +++ b/flexmeasures/ui/views/analytics.py @@ -550,6 +550,8 @@ def make_power_figure( title = "Electricity consumption of %s" % resource_display_name else: title = "Electricity production from %s" % resource_display_name + if data.empty: + title = title.replace("Electricity", "Prognosed") return create_graph( data,