Skip to content

Commit 7f80ef8

Browse files
authored
Merge pull request #138 from predict-idlab/resample_bug
Resample bug, see #137
2 parents b3f06fe + fb25a39 commit 7f80ef8

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ In [this Plotly-Resampler demo](https://github.com/predict-idlab/plotly-resample
140140

141141

142142
<br>
143-
<details><summary>Features</summary>
143+
<details><summary>👉 <b>Features</b></summary>
144144

145145
* **Convenient** to use:
146146
* just add either
@@ -149,7 +149,7 @@ In [this Plotly-Resampler demo](https://github.com/predict-idlab/plotly-resample
149149
* `FigureWidgetResampler` decorator around a plotly Figure and output the instance in a cell
150150
* allows all other plotly figure construction flexibility to be used!
151151
* **Environment-independent**
152-
* can be used in Jupyter, vscode-notebooks, Pycharm-notebooks, Google Colab, and even as application (on a server)
152+
* can be used in Jupyter, vscode-notebooks, Pycharm-notebooks, Google Colab, DataSpell, and even as application (on a server)
153153
* Interface for **various aggregation algorithms**:
154154
* ability to develop or select your preferred sequence aggregation method
155155
</details>

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,9 @@ def _check_update_figure_dict(
398398
if xaxis_filter is not None:
399399
# the x-anchor of the trace is stored in the layout data
400400
if trace.get("yaxis") is None:
401-
# no yaxis -> we make the assumption that yaxis = xaxis_filter_short
402-
y_axis = "y" + xaxis_filter[1:]
401+
# TODO In versions up until v0.8.2 we made the assumption that yaxis
402+
# = xaxis_filter_short. -> Why did we make this assumption?
403+
y_axis = "y" # + xaxis_filter[1:]
403404
else:
404405
y_axis = "yaxis" + trace.get("yaxis")[1:]
405406

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ trace-updater = ">=0.0.8"
2828
numpy = ">=1.14"
2929
Flask-Cors = "^3.0.10"
3030
orjson = "^3.8.0" # Faster json serialization
31-
Werkzeug = "2.1.2" # Fixating werkzeug version because of:
31+
# TODO -> check other werkzeug versions: 2.1.2 and 2.1.1 seem to work.
3232
# https://github.com/predict-idlab/plotly-resampler/issues/123
33+
Werkzeug = "<=2.1.2"
3334

3435
[tool.poetry.dev-dependencies]
3536
pytest = "^6.2.5"

tests/test_figurewidget_resampler.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,55 @@ def test_hf_data_property_subplots_reload_data():
746746
)
747747

748748

749+
def test_hf_data_subplots_non_shared_xaxes():
750+
fwr = FigureWidgetResampler(make_subplots(rows=2, cols=1, shared_xaxes=False))
751+
n = 100_000
752+
x = np.arange(n)
753+
y = np.sin(x)
754+
755+
assert len(fwr.hf_data) == 0
756+
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y, row=1, col=1)
757+
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y, row=2, col=1)
758+
759+
fwr.layout.update(
760+
{
761+
"xaxis2": {"range": [40_000, 60_000]},
762+
"yaxis2": {"range": [-10, 3]},
763+
},
764+
overwrite=False,
765+
)
766+
x_0 = fwr.data[0]['x']
767+
assert 0 <= x_0[0] <= (n / 1000)
768+
assert (n - 1000) <= x_0[-1] <= n - 1
769+
x_1 = fwr.data[1]['x']
770+
assert 40_000 <= x_1[0] <= 40_000 + (20_000 / 1000)
771+
assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_000
772+
773+
774+
def test_hf_data_subplots_non_shared_xaxes_row_col_none():
775+
fwr = FigureWidgetResampler(make_subplots(rows=2, cols=1, shared_xaxes=False))
776+
n = 100_000
777+
x = np.arange(n)
778+
y = np.sin(x)
779+
780+
assert len(fwr.hf_data) == 0
781+
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y)
782+
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y, row=2, col=1)
783+
784+
fwr.layout.update(
785+
{
786+
"xaxis2": {"range": [40_000, 60_000]},
787+
"yaxis2": {"range": [-10, 3]},
788+
},
789+
overwrite=False,
790+
)
791+
x_0 = fwr.data[0]['x']
792+
assert 0 <= x_0[0] <= (n / 1000)
793+
assert (n - 1000) <= x_0[-1] <= n - 1
794+
x_1 = fwr.data[1]['x']
795+
assert 40_000 <= x_1[0] <= 40_000 + (20_000 / 1000)
796+
assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_000
797+
749798
def test_updates_two_traces():
750799
n = 1_000_000
751800
X = np.arange(n)

0 commit comments

Comments
 (0)