Skip to content

Resample bug, see #137 #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ In [this Plotly-Resampler demo](https://github.com/predict-idlab/plotly-resample


<br>
<details><summary>Features</summary>
<details><summary>👉 <b>Features</b></summary>

* **Convenient** to use:
* just add either
Expand All @@ -149,7 +149,7 @@ In [this Plotly-Resampler demo](https://github.com/predict-idlab/plotly-resample
* `FigureWidgetResampler` decorator around a plotly Figure and output the instance in a cell
* allows all other plotly figure construction flexibility to be used!
* **Environment-independent**
* can be used in Jupyter, vscode-notebooks, Pycharm-notebooks, Google Colab, and even as application (on a server)
* can be used in Jupyter, vscode-notebooks, Pycharm-notebooks, Google Colab, DataSpell, and even as application (on a server)
* Interface for **various aggregation algorithms**:
* ability to develop or select your preferred sequence aggregation method
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ def _check_update_figure_dict(
if xaxis_filter is not None:
# the x-anchor of the trace is stored in the layout data
if trace.get("yaxis") is None:
# no yaxis -> we make the assumption that yaxis = xaxis_filter_short
y_axis = "y" + xaxis_filter[1:]
# TODO In versions up until v0.8.2 we made the assumption that yaxis
# = xaxis_filter_short. -> Why did we make this assumption?
y_axis = "y" # + xaxis_filter[1:]
else:
y_axis = "yaxis" + trace.get("yaxis")[1:]

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ trace-updater = ">=0.0.8"
numpy = ">=1.14"
Flask-Cors = "^3.0.10"
orjson = "^3.8.0" # Faster json serialization
Werkzeug = "2.1.2" # Fixating werkzeug version because of:
# TODO -> check other werkzeug versions: 2.1.2 and 2.1.1 seem to work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be included in this PR? For me it's fine to move this to another PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be included!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will merge this PR and leave this for what it is

# https://github.com/predict-idlab/plotly-resampler/issues/123
Werkzeug = "<=2.1.2"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
Expand Down
49 changes: 49 additions & 0 deletions tests/test_figurewidget_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,55 @@ def test_hf_data_property_subplots_reload_data():
)


def test_hf_data_subplots_non_shared_xaxes():
fwr = FigureWidgetResampler(make_subplots(rows=2, cols=1, shared_xaxes=False))
n = 100_000
x = np.arange(n)
y = np.sin(x)

assert len(fwr.hf_data) == 0
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y, row=1, col=1)
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y, row=2, col=1)

fwr.layout.update(
{
"xaxis2": {"range": [40_000, 60_000]},
"yaxis2": {"range": [-10, 3]},
},
overwrite=False,
)
x_0 = fwr.data[0]['x']
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


def test_hf_data_subplots_non_shared_xaxes_row_col_none():
fwr = FigureWidgetResampler(make_subplots(rows=2, cols=1, shared_xaxes=False))
n = 100_000
x = np.arange(n)
y = np.sin(x)

assert len(fwr.hf_data) == 0
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y)
fwr.add_trace(go.Scattergl(name="test"), hf_x=x, hf_y=y, row=2, col=1)

fwr.layout.update(
{
"xaxis2": {"range": [40_000, 60_000]},
"yaxis2": {"range": [-10, 3]},
},
overwrite=False,
)
x_0 = fwr.data[0]['x']
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

def test_updates_two_traces():
n = 1_000_000
X = np.arange(n)
Expand Down