From 0a7831f68c178777faedc0c1d562f9f6dcb47ed9 Mon Sep 17 00:00:00 2001 From: alemikhov Date: Wed, 5 Jun 2024 10:02:15 +0000 Subject: [PATCH 1/6] [issue-307] add 2 extra (on left and right) dots out of zommed box --- .../aggregation/plotly_aggregator_parser.py | 2 ++ tests/test_figure_resampler.py | 10 +++++----- tests/test_figurewidget_resampler.py | 14 +++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/plotly_resampler/aggregation/plotly_aggregator_parser.py b/plotly_resampler/aggregation/plotly_aggregator_parser.py index 74f4dc8b..cd0ae0c0 100644 --- a/plotly_resampler/aggregation/plotly_aggregator_parser.py +++ b/plotly_resampler/aggregation/plotly_aggregator_parser.py @@ -97,6 +97,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/tests/test_figure_resampler.py b/tests/test_figure_resampler.py index 942bc80f..f5f2d63e 100644 --- a/tests/test_figure_resampler.py +++ b/tests/test_figure_resampler.py @@ -284,7 +284,7 @@ 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"][0] >= 99 assert out[-1]["x"][-1] <= 50_000 @@ -1061,8 +1061,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(): @@ -1147,10 +1147,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 c95b5fba..0ae387a7 100644 --- a/tests/test_figurewidget_resampler.py +++ b/tests/test_figurewidget_resampler.py @@ -813,7 +813,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) @@ -888,8 +888,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) @@ -919,8 +919,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(): @@ -944,8 +944,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(): From a836a4918dbc0eef150477704d12b20a8dc71411 Mon Sep 17 00:00:00 2001 From: alemikhov Date: Sun, 23 Jun 2024 13:25:12 +0000 Subject: [PATCH 2/6] add change log and alter boundaries --- CHANGELOG.md | 3 +++ plotly_resampler/aggregation/plotly_aggregator_parser.py | 6 ++++-- pyproject.toml | 2 +- tests/test_figure_resampler.py | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d02f0609..034a2414 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. # v0.10.0 ## New Features diff --git a/plotly_resampler/aggregation/plotly_aggregator_parser.py b/plotly_resampler/aggregation/plotly_aggregator_parser.py index cd0ae0c0..d61710f0 100644 --- a/plotly_resampler/aggregation/plotly_aggregator_parser.py +++ b/plotly_resampler/aggregation/plotly_aggregator_parser.py @@ -74,6 +74,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 @@ -97,8 +99,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"])) + # 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 b86f0331..fc39a18d 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 f5f2d63e..3e293a34 100644 --- a/tests/test_figure_resampler.py +++ b/tests/test_figure_resampler.py @@ -285,7 +285,7 @@ def test_log_axis(): assert (x1 - x0) < 10 assert len(out[1]["x"]) == 1000 assert out[-1]["x"][0] >= 99 - assert out[-1]["x"][-1] <= 50_000 + assert out[-1]["x"][-1] <= 50_001 def test_add_traces_from_other_figure(): From 99c46c99c6adc9373f2a1cb38211ddde6ac6d8a8 Mon Sep 17 00:00:00 2001 From: Aleksandr Lemikhov Date: Sun, 23 Jun 2024 15:47:39 +0200 Subject: [PATCH 3/6] add extra point --- plotly_resampler/aggregation/plotly_aggregator_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plotly_resampler/aggregation/plotly_aggregator_parser.py b/plotly_resampler/aggregation/plotly_aggregator_parser.py index d61710f0..bbf6caf4 100644 --- a/plotly_resampler/aggregation/plotly_aggregator_parser.py +++ b/plotly_resampler/aggregation/plotly_aggregator_parser.py @@ -99,8 +99,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"])) + start_idx = max(0, start_idx - 1) + end_idx = min(end_idx + 1, len(hf_trace_data["x"])) return start_idx, end_idx @staticmethod From 173b8d26243f072e0b9378d13e3b81a5f59b53b1 Mon Sep 17 00:00:00 2001 From: Aleksandr Lemikhov Date: Mon, 24 Jun 2024 09:03:33 +0200 Subject: [PATCH 4/6] add PR link to CONTRIBUTING.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 034a2414..b95523e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # v0.10.1 ## What's Changed -After resampling the figure, the line goes beyond figure frontier indicating presence of data. +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 From aa64377121e44cbaf56e230d2c40bf9080682355 Mon Sep 17 00:00:00 2001 From: jonasvdd Date: Thu, 6 Mar 2025 15:50:50 +0100 Subject: [PATCH 5/6] :prayer_beads: fix tests --- tests/test_figure_resampler.py | 6 ++++-- tests/test_figurewidget_resampler.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_figure_resampler.py b/tests/test_figure_resampler.py index 3e293a34..41136b7f 100644 --- a/tests/test_figure_resampler.py +++ b/tests/test_figure_resampler.py @@ -1725,8 +1725,10 @@ def check_data(fr: FigureResampler, min_v=0, max_v=nb_datapoints - 1): x_ = decode_trace_bdata(f_pr_data[0]["x"]) assert len(y_) == 500 assert len(x_) == 500 - assert y_[0] >= 100 and y_[-1] <= 1000 - assert x_[0] >= 100 and x_[-1] <= 1000 + # Since https://github.com/predict-idlab/plotly-resampler/pull/343 + # the data range is left-right expanded with 1 sample + assert y_[0] >= 99 and y_[-1] <= 1000 + assert x_[0] >= 99 and x_[-1] <= 1000 # Check the front-end layout assert list(f_pr_layout["xaxis"]["range"]) == [100, 1000] assert list(f_pr_layout["yaxis"]["range"]) == [100, 1000] diff --git a/tests/test_figurewidget_resampler.py b/tests/test_figurewidget_resampler.py index 0ae387a7..8f2766cf 100644 --- a/tests/test_figurewidget_resampler.py +++ b/tests/test_figurewidget_resampler.py @@ -2077,7 +2077,9 @@ def check_data(fwr: FigureWidgetResampler, min_v=0, max_v=nb_datapoints - 1): assert f_pr.layout.yaxis.autorange is None # Now the f_pr contains the data of the selected xrange (downsampled to 500 samples) - check_data(f_pr, 100, 1_000 - 1) + # Since https://github.com/predict-idlab/plotly-resampler/pull/343 + # the data range is left-right expanded with 1 sample + check_data(f_pr, min_v=100 -1, max_v=1_000) def test_fwr_update_layout_axes_range_no_update(): From 986fe93aa25bbf90e94b3bdf267a85242ecd9a21 Mon Sep 17 00:00:00 2001 From: jonasvdd Date: Thu, 6 Mar 2025 15:51:45 +0100 Subject: [PATCH 6/6] :see_no_evil: fix formatting --- tests/test_figurewidget_resampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_figurewidget_resampler.py b/tests/test_figurewidget_resampler.py index 8f2766cf..8ece7f0a 100644 --- a/tests/test_figurewidget_resampler.py +++ b/tests/test_figurewidget_resampler.py @@ -2079,7 +2079,7 @@ def check_data(fwr: FigureWidgetResampler, min_v=0, max_v=nb_datapoints - 1): # Now the f_pr contains the data of the selected xrange (downsampled to 500 samples) # Since https://github.com/predict-idlab/plotly-resampler/pull/343 # the data range is left-right expanded with 1 sample - check_data(f_pr, min_v=100 -1, max_v=1_000) + check_data(f_pr, min_v=100 - 1, max_v=1_000) def test_fwr_update_layout_axes_range_no_update():