diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 0a833676e..7f4a48b9d 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 `_] * User page did not list number of assets correctly [see `PR #64 `_] Infrastructure/Support 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 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,