Skip to content

Simplify webagg blitting. #23182

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 1 commit into from
Jun 3, 2022
Merged

Simplify webagg blitting. #23182

merged 1 commit into from
Jun 3, 2022

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 1, 2022

  • Directly reuse FigureCanvasAgg.get_renderer. We don't need to init
    _last_buff there as we can just use buff.copy() in get_diff_image()
    (If we really care about reusing the same array whenever possible, we
    could add a shape check before the removed copyto() and reuse the old
    array if the shapes match, but I doubt it matters.) Instead, init it
    once to a non-valid shape in the constructor.

    Note that the comments in the function were outdated since 78c182d.

  • First creating pixels and then viewing it as buff is slighly
    simpler than doing it the other way round.

The animation example in #19059 works for me.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@tacaswell tacaswell requested a review from ianhi June 2, 2022 02:36
@tacaswell tacaswell added this to the v3.6.0 milestone Jun 2, 2022
Copy link
Contributor

@ianhi ianhi left a comment

Choose a reason for hiding this comment

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

nice! much simpler


if self._force_full or np.any(pixels[:, :, 3] != 255):
if (self._force_full
or buff.shape != self._last_buff.shape
Copy link
Contributor

Choose a reason for hiding this comment

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

may be nice to add a comment as well about this line. It took me a while to hunt down why it was ok to compare the initial np.empty((0,0)) with the buffer and this line is the escape


if self._force_full or np.any(pixels[:, :, 3] != 255):
if (self._force_full
or buff.shape != self._last_buff.shape
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
or buff.shape != self._last_buff.shape
# If the buffer has changed size we need to do a full draw
or buff.shape != self._last_buff.shape

- Directly reuse FigureCanvasAgg.get_renderer.  We don't need to init
  _last_buff there as we can just use buff.copy() in get_diff_image()
  (If we really care about reusing the same array whenever possible, we
  could add a shape check before the removed copyto() and reuse the old
  array if the shapes match, but I doubt it matters.)  Instead, init it
  once to a non-valid shape in the constructor.

  Note that the comments in the function were outdated since 78c182d.

- First creating `pixels` and then viewing it as `buff` is slighly
  simpler than doing it the other way round.
@anntzer
Copy link
Contributor Author

anntzer commented Jun 2, 2022

Added comment as requested.

@oscargus oscargus merged commit 8ab732d into matplotlib:main Jun 3, 2022
@anntzer anntzer deleted the webagg_blit branch June 3, 2022 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants