Skip to content

fix displace of the selectioon area and mouse position in "Rect Mode".#2017

Closed
leo603222 wants to merge 3 commits intopyqtgraph:masterfrom
leo603222:master
Closed

fix displace of the selectioon area and mouse position in "Rect Mode".#2017
leo603222 wants to merge 3 commits intopyqtgraph:masterfrom
leo603222:master

Conversation

@leo603222
Copy link
Copy Markdown
Contributor

For a plot with x- and y-grid lines as well as the right axis enabled, the selection area's bottom right corner (created for mouse interaction mode set to RectMode) is (stronlgy) displaced from the mouse cursor position.
Detail information see #1937.
I track into the source code,and found some problems in ViewBox.mouseDragEvent() and ViewBox.updateScaleBox().
ev.buttonDownPos() in mouseDragEvent() return a pos in the coordinate of an AxisItem.
r = self.childGroup.mapRectFromParent(r) in updateScaleBox() needs to use a pos in ViewBox's coordinate.
These two coordinate is not consistent, and this problem cause the displace of the selectioon area and mouse position.
I fix this problem by using scene coordinate in these two places, And everything works fine to me.

@leo603222 leo603222 changed the title Update ViewBox.py because displace of the selectioon area and mouse position in "Rect Mode". fix displace of the selectioon area and mouse position in "Rect Mode". Oct 13, 2021
@NilsNemitz
Copy link
Copy Markdown
Contributor

Dear @leo603222 , welcome!

I am sorry, I haven't had time to look at this in detail yet. But your proposed changes look very reasonable, and seem to give a good explanation of what has been going wrong in the first place!

What I am wondering right now is how does the presence of the grid make this work/fail?
My wild guess is that the AxisItem intercepts the initial event and fills in some of the position data based on a different coordinate transformation than the ViewBox would normally do.

I guess you might have a better understanding of this after your experimentation... Would you mind sharing that with us?

@leo603222
Copy link
Copy Markdown
Contributor Author

@NilsNemitz , there's a big difference between grid on and off.
When gird is on, the mouse drag event is triggered by the AxisItem, when grid is off, the mouse drag event is triggered by ViewBox.
So with grid off, ev.buttonDownPos() return a position in the coordinate of ViewBox, which is right for r = self.childGroup.mapRectFromParent(r) in updateScaleBox().
But with grid on, ev.buttonDownPos() return a position in the coordinate of AxisItem, which is not consistent with the need of self.childGroup.mapRectFromParent(r) in updateScaleBox().
By using scene coordinate in these two places, I think this problem is fixed.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 21, 2021

Hi @leo603222 Thanks for the PR!

Around these parts we get nervous when it comes to changes to ViewBox.py, not because we think it's bug-free, we know it's not, but because making changes there can have very subtle other issues.

That said, as @NilsNemitz said, the changes look very reasonable, I'll try and test it out against the test code in the issue you referenced in the next day or so, since the test suite passes, and if I can verify the PR fixes the issue as described I'll merge right away.

Also FYI, when you make a PR, it's easier for us if you don't name your branch the name of a branch in this repository. The reasoning being that I can't just git switch master to hop on your branch to test things for myself (we can work around this by having a different local branch name that tracks to your fork).

Your first PR modifying ViewBox.py is an impressive feat 😆

GraphicsWidget.__init__(self)
GraphicsWidgetAnchor.__init__(self)
self.setFlag(self.GraphicsItemFlag.ItemIgnoresTransformations)
# self.setFlag(self.GraphicsItemFlag.ItemIgnoresTransformations)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @leo603222

Can you either delete this line, or undo the comment and make the removal of this line part of a separate PR?

Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I'm not familiar with git.
I have undo the change of LegendItem, and rename my branch name too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ahh, didn't mean for you to close the PR, I'd be happy to provide some guidance. In the future, if you want to drop the most recent commit in a branch, you can run

git reset --hard HEAD^
git push --force-with-lease

I'm happy to provide that kind of assistance; while I'm no git expert, I know it can be confusing with how to make these kinds of changes 👍🏻

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 21, 2021

I've verified the PR works as intended; I'm good to merge. I would prefer to leave the change to LegendItem.py to be part of a separate PR for tracking purposes. 👍🏻

@leo603222 leo603222 deleted the branch pyqtgraph:master October 21, 2021 06:38
@leo603222 leo603222 closed this Oct 21, 2021
@leo603222 leo603222 deleted the master branch October 21, 2021 06:38
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 21, 2021

Hi @leo603222 I wrote this late last night, didn't mean to imply you should close out this PR; I was able to clone into your branch; I did have to run a more complex command due to the branch naming, but it wasn't some insurmountable task :)

In case you're curious, if someone has a branch name something like fix-issue1000 and if I want to hop on that branch to experiment I would run the following commands

git remote add pr-author-username https://github.com/pr-author-username/pyqtgraph.git
git fetch pr-author-username
git switch fix-issue1000

In the case where there is branch naming conflicts, as this PR had, for the last command instead of the git switch I run

git checkout -b pr-author-username-master pr-author-username/master

but I have to stack overflow it each time because I always forget 😆

Anyway Hope you submit the changes to ViewBox.py, I tested them out and can confirm they worked, and would love to merge the changes 👍🏻

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

showGrid with showAxis('right', ...) causes displacement between mouse mode selection area and mouse cursor position

3 participants