Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better xrange and title if only schedules are plotted #67

Merged
merged 4 commits into from Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -10,6 +10,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>`_]

Infrastructure/Support
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 @@ -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,
Expand Down