From c3d3fdb7abb550999b03db0e557ddb1498c55a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Sat, 20 Mar 2021 22:57:43 +0100 Subject: [PATCH 1/3] If only prognosed data is given, the title of the plot can reflect that --- flexmeasures/ui/views/analytics.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flexmeasures/ui/views/analytics.py b/flexmeasures/ui/views/analytics.py index 85f27e880..989348716 100644 --- a/flexmeasures/ui/views/analytics.py +++ b/flexmeasures/ui/views/analytics.py @@ -535,6 +535,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, From 8478fad347829e36a61eecf21e0bc50867bb8bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Sat, 20 Mar 2021 22:59:26 +0100 Subject: [PATCH 2/3] the xrange is not dependent on the the main data dataframe being non-empty --- flexmeasures/ui/utils/plotting_utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 From 5a0b0a06c249919d501358c2fda952b08f710072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Sun, 21 Mar 2021 20:36:31 +0100 Subject: [PATCH 3/3] changelog entry --- documentation/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index de4358410..6039e16f7 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -10,6 +10,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 `_]