matplotlib
matplotlib copied to clipboard
Fix PolygonSelector.clear()
PR Summary
This PR implements PolygonSelector.clear() to delete all vertices and enable visibility.
PR Checklist
Tests and Styling
- [N/A] Has pytest style unit tests (and
pytest
passes). - [x] Is Flake 8 compliant (install
flake8-docstrings
and runflake8 --docstring-convention=all
).
Documentation
- [N/A] New features are documented, with examples if plot related.
- [N/A] New features have an entry in
doc/users/next_whats_new/
(follow instructions in README.rst there). - [N/A] API changes documented in
doc/api/next_api_changes/
(follow instructions in README.rst there). - [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
Thank you for your work on this and I think overall it makes sense however I have a couple questions.
This looks like this will call self.update
twice, once through _draw_polygon
and once through super().clear()
Is there a way to get this down to just one call to update (we have a lot of performance issuses that boil down to "we do the same thing N times when once would do")?
Why enable visibilty what the base-class turns it off?
Can you add a test?
Why enable visibilty what the base-class turns it off?
Otherwise the selection widget is not visible after calling clear
. Visibility is also enabled explicitly in __init__
. I guess PolygonSelector
is implemented a little differently.
This looks like this will call
self.update
twice, once through_draw_polygon
and once throughsuper().clear()
Is there a way to get this down to just one call to update (we have a lot of performance issuses that boil down to "we do the same thing N times when once would do")?
I guess, it would be smarter to call self._clear_without_update()
instead of super().clear()
. However, since this is just
def _clear_without_update(self):
self._selection_completed = False
self.set_visible(False)
it would also be possible to skip the call and re-enabling visibility altogether, and PolygonSelector.clear
would become
def clear(self):
self._selection_completed = False
self._xys = [(0, 0)]
self._draw_polygon()
What would you suggest?
Otherwise the selection widget is not visible after calling clear. Visibility is also enabled explicitly in init. I guess PolygonSelector is implemented a little differently.
fair. Looking at this more carefully I see what you mean about PolygonSelector
having slightly different notions of what the "right" visibility / transient state is....
The best path here may be to override _clear_without_update()
?
Sorry this fell off my radar, are you still interested in working on this @lschr ?
Feel free to mark ready for review when it's ready! Thanks
I just rebased on current main, updated the code to call update()
only once and added a test.
@tacaswell can you have another look? I don't think the failing tests are related to this.
Thanks @lschr! Congratulations on your first PR to Matplotlib :tada: We hope to hear from you again.