diff --git a/CHANGELOG.md b/CHANGELOG.md index d02f0609..b95523e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Latest +# v0.10.1 +## What's Changed +After resampling the figure, the line goes beyond figure frontier indicating presence of data. https://github.com/predict-idlab/plotly-resampler/pull/308 # v0.10.0 ## New Features diff --git a/plotly_resampler/aggregation/plotly_aggregator_parser.py b/plotly_resampler/aggregation/plotly_aggregator_parser.py index c359aa29..d9049363 100644 --- a/plotly_resampler/aggregation/plotly_aggregator_parser.py +++ b/plotly_resampler/aggregation/plotly_aggregator_parser.py @@ -70,6 +70,8 @@ def get_start_end_indices(hf_trace_data, axis_type, start, end) -> Tuple[int, in x_step = hf_trace_data["x"].step start_idx = int(max((start - x_start) // x_step, 0)) end_idx = int((end - x_start) // x_step) + start_idx = max(0, start_idx - 1) + end_idx = min(end_idx + 1, len(hf_trace_data["x"])) return start_idx, end_idx # TODO: this can be performed as-well for a fixed frequency range-index w/ freq @@ -85,6 +87,8 @@ def get_start_end_indices(hf_trace_data, axis_type, start, end) -> Tuple[int, in # Search the index-positions start_idx = bisect.bisect_left(hf_trace_data["x"], start) end_idx = bisect.bisect_right(hf_trace_data["x"], end) + start_idx = max(0, start_idx - 1) + end_idx = min(end_idx + 1, len(hf_trace_data["x"])) return start_idx, end_idx @staticmethod diff --git a/pyproject.toml b/pyproject.toml index 115523ad..0b251bf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "plotly-resampler" # Do not forget to update the __init__.py __version__ variable -version = "0.10.0" +version = "0.10.1" description = "Visualizing large time series with plotly" authors = ["Jonas Van Der Donckt", "Jeroen Van Der Donckt", "Emiel Deprost"] readme = "README.md" diff --git a/tests/test_figure_resampler.py b/tests/test_figure_resampler.py index 640914ec..dab9795f 100644 --- a/tests/test_figure_resampler.py +++ b/tests/test_figure_resampler.py @@ -296,8 +296,8 @@ def test_log_axis(): assert len(out) == 2 assert (x1 - x0) < 10 assert len(out[1]["x"]) == 1000 - assert out[-1]["x"][0] >= 100 - assert out[-1]["x"][-1] <= 50_000 + assert out[-1]["x"][0] >= 99 + assert out[-1]["x"][-1] <= 50_001 def test_add_traces_from_other_figure(): @@ -997,8 +997,8 @@ def test_time_tz_slicing(): start_idx, end_idx = PlotlyAggregatorParser.get_start_end_indices( hf_data_dict, hf_data_dict["axis_type"], t_start, t_stop ) - assert (s.index[start_idx] - t_start) <= pd.Timedelta(seconds=1) - assert (s.index[min(end_idx, n - 1)] - t_stop) <= pd.Timedelta(seconds=1) + assert (s.index[start_idx] - t_start) <= pd.Timedelta(seconds=2) + assert (s.index[min(end_idx, n - 1)] - t_stop) <= pd.Timedelta(seconds=2) def test_time_tz_slicing_different_timestamp(): @@ -1064,10 +1064,10 @@ def test_different_tz_no_tz_series_slicing(): ) assert ( s.tz_localize(None).index[start_idx].tz_localize(t_start.tz) - t_start - ) <= pd.Timedelta(seconds=1) + ) <= pd.Timedelta(seconds=2) assert ( s.tz_localize(None).index[end_idx].tz_localize(t_stop.tz) - t_stop - ) <= pd.Timedelta(seconds=1) + ) <= pd.Timedelta(seconds=2) def test_multiple_tz_no_tz_series_slicing(): diff --git a/tests/test_figurewidget_resampler.py b/tests/test_figurewidget_resampler.py index 03f73bd4..06fb61d2 100644 --- a/tests/test_figurewidget_resampler.py +++ b/tests/test_figurewidget_resampler.py @@ -794,7 +794,7 @@ def test_hf_data_property_reload_data(): assert np.all(fwr.hf_data[0]["y"] == new_y) fwr.reload_data() - assert (fwr.data[0]["x"][0] >= 10_000) & (fwr.data[0]["x"][-1] <= 20_000) + assert (fwr.data[0]["x"][0] >= 9_999) & (fwr.data[0]["x"][-1] <= 20_001) assert np.all(fwr.data[0]["y"] == new_y[fwr.data[0]["x"]]) assert (fwr.layout["yaxis"].range[0] == -20) & (fwr.layout["yaxis"].range[-1] == 3) @@ -869,8 +869,8 @@ def test_hf_data_property_subplots_reload_data(): assert np.all(fwr.hf_data[0]["y"] == new_y) fwr.reload_data() - assert (fwr.data[0]["x"][0] >= 10_000) & (fwr.data[0]["x"][-1] <= 20_000) - assert (fwr.data[1]["x"][0] >= 40_000) & (fwr.data[1]["x"][-1] <= 60_000) + assert (fwr.data[0]["x"][0] >= 9_999) & (fwr.data[0]["x"][-1] <= 20_001) + assert (fwr.data[1]["x"][0] >= 39_999) & (fwr.data[1]["x"][-1] <= 60_001) assert np.all(fwr.data[0]["y"] == new_y[fwr.data[0]["x"]]) assert np.all(fwr.data[1]["y"] == new_y[fwr.data[1]["x"]]) assert (fwr.layout["yaxis"].range[0] == -20) & (fwr.layout["yaxis"].range[-1] == 3) @@ -900,8 +900,8 @@ def test_hf_data_subplots_non_shared_xaxes(): assert 0 <= x_0[0] <= (n / 1000) assert (n - 1000) <= x_0[-1] <= n - 1 x_1 = fwr.data[1]["x"] - assert 40_000 <= x_1[0] <= 40_000 + (20_000 / 1000) - assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_000 + assert 39_999 <= x_1[0] <= 40_001 + (20_000 / 1000) + assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_001 def test_hf_data_subplots_non_shared_xaxes_row_col_none(): @@ -925,8 +925,8 @@ def test_hf_data_subplots_non_shared_xaxes_row_col_none(): assert 0 <= x_0[0] <= (n / 1000) assert (n - 1000) <= x_0[-1] <= n - 1 x_1 = fwr.data[1]["x"] - assert 40_000 <= x_1[0] <= 40_000 + (20_000 / 1000) - assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_000 + assert 39_999 <= x_1[0] <= 40_001 + (20_000 / 1000) + assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_001 def test_updates_two_traces():