Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
RangeSlider handle set_val bugfix#22711
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping@matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join uson gitter for real-time discussion.
For details on testing, writing docs, and our review process, please seethe developer guide
We strive to be a welcoming and open project. Please follow ourCode of Conduct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for working on this@andrew-fennell !
First thing before going further the handle moving code needs to be moved into theif else
block for orientation otherwise this will break for vertical sliders.
Otherwise I think this is on the right track! Only other thing to consider if this will have any weird interactions with theactive_slider
mechanism
b14fcc4
to4bb9274
CompareI moved the horizontal RangeSlider handle section into the This gif shows that the I went ahead and fixed the vertical slider handles as well, since it was discussed in issue#22706 as well. Here is an example of the vertical RangeSlider handles before: |
4bb9274
to79252d5
Comparelib/matplotlib/widgets.py Outdated
hbottom_pos = self._handles[0].get_ydata() | ||
htop_pos = self._handles[1].get_ydata() | ||
if hbottom_pos != val[0]: | ||
hbottom_pos[0] = val[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
are all these checks necessary or can we we just go ahead and set them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
AlsoI think that the more technically correct way to get the position as a scalar (which is how you're using it here)
would be with:
hbottom_pos=self._handles[0].get_ydata()[0]
becauseget_{x,y}data
returns an array (length 1 in this case) and then you're comparing an array to scalar adn asking if theyre equal
andrew-fennellMar 27, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The RangleSlider._update_val_from_pos requires an array and not just a scalar.
With that said, I am no longer doing the comparison, so I was able to remove that line completely and just use the value passed into the set_val function.
I re-tested my two examples and everything is looking great!
You're doing great :) |
af3639b
to3c5a6e9
Compare3c5a6e9
to2566eaa
CompareShould the codecov tests be passing? Will those checks prevent this PR from being approved? |
My understanding is that it's not strictly required but strongly preferable. My next ask was actually going to be to have you add some tests. Can you at the very least add checks of the handle position to this test:
better still would be to also add new tests that simulate mouse clicks which can be simulated in testing using this method:
|
bbabbea
to110ee1f
CompareThe tests that I wrote should suffice. I just followed what was already there for checking slider values. I don't like my usage of redundant variables, but in trying to keep everything readable (and to pass the flake8 line length restrictions), I added a few (like Let me if there is anything else I should to do improve this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍 from me. Nice work@andrew-fennell
The only final improvement I would suggest would be to add a test of clicking and dragging that captures the switching behavior between the two handles. But I don't think this fix needs to be held up on that.
Next steps for this PR: You need two approvals from people with write access to the repo (and they may also have comments). This is a primarily volunteer project so it may take a few days. But if no one reviews after a few days feel free to drop a message to ping people.
lib/matplotlib/tests/test_widgets.py Outdated
hpositions = [h.get_ydata()[0] for h in slider._handles] | ||
assert_allclose(hpositions, (0, 1)) | ||
else: | ||
hpositions = [h.get_xdata()[0] for h in slider._handles] | ||
assert_allclose(hpositions, (0, 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you want to simplify a bit you can do this
hpositions= [h.get_ydata()[0]forhinslider._handles] | |
assert_allclose(hpositions, (0,1)) | |
else: | |
hpositions= [h.get_xdata()[0]forhinslider._handles] | |
assert_allclose(hpositions, (0,1)) | |
hpositions= [h.get_ydata()[0]forhinslider._handles] | |
else: | |
hpositions= [h.get_xdata()[0]forhinslider._handles] | |
assert_allclose(hpositions, (0,1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Alright, I simplified the tests in the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I wanted to add click_and_drag testing, but I think it may be a bit difficult with the RangeSlider because of how the click event is registered. I'll keep looking into it, but I'm not sure that I'll have it ready for this PR.
There are other widgets that look like they could also benefit from click_and_drag testing, so I may make another PR in the future addressing that.
I appreciate all of the help, Ian.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ah indeed I see the problem with using that. I'd suggest opening a new issue about that where we can discuss how to further improve and generalize theclick_and_drag
I think it will boil down to actually sending events through the canvas like I do in mpl-playback:https://github.com/ianhi/mpl-playback/blob/2c0896205b94e2c3c1ee9e8582291cc2e94aab99/mpl_playback/playback.py#L219
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I wanted to add click_and_drag testing, but I think it may be a bit difficult with the RangeSlider because of how the click event is registered. I'll keep looking into it, but I'm not sure that I'll have it ready for this PR.
I opened the issue#22720 to address the issues with using mouse testing with some widgets.
110ee1f
to787db12
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM, only some minor style suggestions.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
787db12
to0c6ccf6
CompareJust to reiterate here in a standalone comment: I opened the issue#22720 to address this because it is out of scope of this PR. |
Thanks@andrew-fennell! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
…711-on-v3.5.xBackport PR#22711 on branch v3.5.x (RangeSlider handle set_val bugfix)
Been working on something similar in case anyone might be interested. Code availablehere. Docs etc still WIP. importnumpyasnpfromscrawl.imageimportImageDisplayim=ImageDisplay(np.random.randn(100,100)) |
Uh oh!
There was an error while loading.Please reload this page.
PR Summary
This bug fix is in response to issue#22706.
There was an issue with the handles not updating when set_val was called on a RangeSlider object.
I updated set_val to adjust the appropriate handles when set_val is called. There are still other issues with handles in the RangeSlider class, but this pull request should address the issue highlighted.
Here is an example test that I used to reproduce the original issue:
This was the original result:

Result after my updates:

This is my first PR to a major repository. If I am misunderstanding something, please let me know.
Closes#22686
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).