From 82ab6593f797c39e704399bf42f00e8e681d16fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 12 Apr 2024 18:20:57 +0200 Subject: [PATCH] Change default behavior to not exceed interval --- holoviews/plotting/bokeh/links.py | 33 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/holoviews/plotting/bokeh/links.py b/holoviews/plotting/bokeh/links.py index fe4698d447..bb8e9a9057 100644 --- a/holoviews/plotting/bokeh/links.py +++ b/holoviews/plotting/bokeh/links.py @@ -142,6 +142,15 @@ def __init__(self, root_model, link, source_plot, target_plot): continue axes[f'{axis}_range'] = target_plot.handles[f'{axis}_range'] + interval = getattr(link, f'intervals{axis}', None) + if interval is not None and bokeh34: + min, max = interval + if min is not None: + axes[f'{axis}_range'].min_interval = min + if max is not None: + axes[f'{axis}_range'].max_interval = max + self._set_range_for_interval(axes[f'{axis}_range'], max) + bounds = getattr(link, f'bounds{axis}', None) if bounds is not None: start, end = bounds @@ -152,19 +161,27 @@ def __init__(self, root_model, link, source_plot, target_plot): axes[f'{axis}_range'].end = end axes[f'{axis}_range'].reset_end = end - interval = getattr(link, f'intervals{axis}', None) - if interval is not None and bokeh34: - min, max = interval - if min is not None: - axes[f'{axis}_range'].min_interval = min - if max is not None: - axes[f'{axis}_range'].max_interval = max - tool = RangeTool(**axes) source_plot.state.add_tools(tool) if toolbars: toolbars[0].tools.append(tool) + def _set_range_for_interval(self, axis, max): + # Changes the existing Range1d axis range to be in the interval + for n in ("", "reset_"): + start = getattr(axis, f"{n}start") + try: + end = start + max + except Exception as e: + # Handle combinations of datetime axis and timedelta interval + # Likely a better way to do this + try: + import pandas as pd + end = (pd.array([start]) + pd.array([max]))[0] + except Exception: + raise e from None + setattr(axis, f"{n}end", end) + class DataLinkCallback(LinkCallback): """