Skip to content

Commit

Permalink
Better xrange and title if only schedules are plotted (#67)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nhoening committed Mar 25, 2021
1 parent 48367b8 commit 597153f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -15,6 +15,7 @@ Bugfixes
--------
* Show screenshots in documentation and add some missing content [see `PR #60 <http://www.github.com/SeitaBV/flexmeasures/pull/60>`_]
* Documentation listed 2.0 API endpoints twice [see `PR #59 <http://www.github.com/SeitaBV/flexmeasures/pull/59>`_]
* Better xrange and title if only schedules are plotted [see `PR #67 <http://www.github.com/SeitaBV/flexmeasures/pull/67>`_]
* User page did not list number of assets correctly [see `PR #64 <http://www.github.com/SeitaBV/flexmeasures/pull/64>`_]
* Missing *postPrognosis* endpoint for >1.0 API blueprints [part of `PR #41 <http://www.github.com/SeitaBV/flexmeasures/pull/41>`_]

Expand Down
16 changes: 10 additions & 6 deletions flexmeasures/ui/utils/plotting_utils.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions flexmeasures/ui/views/analytics.py
Expand Up @@ -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,
Expand Down

0 comments on commit 597153f

Please sign in to comment.