Skip to content

Refactor/remove trace updater#281

Merged
jonasvdd merged 16 commits intomainfrom
refactor/remove-trace_updater
Jan 3, 2024
Merged

Refactor/remove trace updater#281
jonasvdd merged 16 commits intomainfrom
refactor/remove-trace_updater

Conversation

@jonasvdd
Copy link
Collaborator

@jonasvdd jonasvdd commented Dec 5, 2023

[BUG] Patch does not seem to work with subplots
solved now!

Reproduce issue - clone this branch and run this code in a notebook.

from plotly_resampler import FigureResampler
from plotly.subplots import make_subplots
import plotly.graph_objects as go

import numpy as np


x = np.arange(2_000_000)
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000

fig = FigureResampler(
    make_subplots(rows=2, cols=2, shared_xaxes="columns", horizontal_spacing=0.03)
)


log = noisy_sin * 0.9999995**x
exp = noisy_sin * 1.000002**x
fig.add_trace(go.Scattergl(name="log"), hf_x=x, hf_y=log)
fig.add_trace(go.Scattergl(name="exp"), hf_x=x, hf_y=exp)

fig.add_trace(go.Scattergl(name="-log"), hf_x=x, hf_y=-exp, row=1, col=2)

fig.add_trace(go.Scattergl(name="log"), hf_x=x, hf_y=-log, row=2, col=1)

fig.add_trace(go.Scattergl(name="3-exp"), hf_x=x, hf_y=3 - exp, row=2, col=1)
fig.add_trace(go.Scattergl(name="log"), hf_x=x, hf_y=log**2, row=2, col=2)
fig.show_dash(mode="inline")

Patch does not seem to properly work with subplots.

How I use patch to update a figure with subplots:

        patched_figure = dash.Patch()  # create patch
        for trace in update_data[1:]:  # skip first item as it contains the relayout
            trace_index = trace.pop("index")  # the index of the corresponding trace
            # All the other items are the trace data which needs to be updated
            patched_figure["data"][trace_index] = trace
        # TODO -> how to make this work with subplots?
        return patched_figure

TODO:

  • rewrite docs
  • verify all examples
    • dash apps
    • notebook examples
  • verify all tests
    • rewrite the selenium class to be compatible with patch type objects

@codecov-commenter
Copy link

codecov-commenter commented Dec 29, 2023

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.40%. Comparing base (9b48723) to head (3570b01).
⚠️ Report is 47 commits behind head on main.

Files with missing lines Patch % Lines
...tly_resampler/figure_resampler/figure_resampler.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #281      +/-   ##
==========================================
- Coverage   96.46%   96.40%   -0.06%     
==========================================
  Files          14       14              
  Lines        1130     1140      +10     
==========================================
+ Hits         1090     1099       +9     
- Misses         40       41       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jonasvdd
Copy link
Collaborator Author

Ready for review @jvdd!

@jonasvdd jonasvdd added the enhancement New feature or request label Dec 29, 2023
@jonasvdd jonasvdd marked this pull request as ready for review January 2, 2024 10:01
Copy link
Collaborator

@jvdd jvdd left a comment

Choose a reason for hiding this comment

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

LGTM! Well done @jonasvdd 🔥

@jonasvdd jonasvdd merged commit cc07774 into main Jan 3, 2024
extra_layout_updates[f"{axis}.autorange"] = None
return extra_layout_updates

def construct_update_data(

Choose a reason for hiding this comment

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

Good work guys, be aware this changes the interface. When it's not backwards compatible it should be tagged with a major version bump if following Semantic Versioning. Congrats on 1.0.0 :D

Choose a reason for hiding this comment

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

Would be nice to add this to the change log, with supporting documentation to use the new interface. This broke my code and I had to dig to find this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants