Fix InfiniteLine bounding rect calculation#2407
Merged
j9ac9k merged 2 commits intopyqtgraph:masterfrom Oct 2, 2022
Merged
Conversation
Member
Author
Member
Author
|
Well, #727 appears to be more correct - re-enabling the 4-pixel padding on this branch and comparing to #727, #727 gives a more consistently thick bounding box. I'm still not sure why exactly but I'm guessing it's related to the bounding rect being initialized from In any case, I think #727 cleans up the |
Member
Author
|
Discussed with Luke and he figured out the issue. For the purposes of computing how much to extend the bounding rect orthogonal to the line, we want the y component instead of the length. Better demonstration of the issue than in the original comment: import numpy as np
import pyqtgraph as pg
class InfLine(pg.InfiniteLine):
def paint(self, p, *args):
p.setPen(pg.mkPen("b", width=1))
p.drawRect(self.boundingRect())
super().paint(p, args)
app = pg.mkQApp()
plt = pg.plot()
plt.showGrid(x=True, y=True)
angle = 1
mag = 50
sample = plt.plot(np.arange(10) * mag, np.arange(10))
oline = InfLine(angle=angle, movable=True)
oline.addMarker("o")
plt.addItem(oline)
app.exec() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1878
Sometimes the smallest changes need the most explanation...
InfiniteLinepreviously usedGraphicsItem.pixelLength(Point(0, 1), ortho=True)to compute the size of 1 pixel in the direction orthogonal to the line, in the item's coordinate system. I'm not sure why the current version requests pixel length orthogonal to the direction along the line rather than via the orthogonal direction directly - I'm still suspicious that I'm missing something.I haven't figured out yet if
pixelVectorsdoes what it should or not. It'd be worth taking a closer look at it as I vaguely recall some bounding rect type issues with ROIs which also use it.Demonstration
Without the proposed change, zooming on say the y axis causes the blue bounding rect to change "width", when it should hug the line with a small ~constant buffer.
Notice also the red and green lines stay parallel and orthogonal to the infinite line. If you change it to
pixelVectors(pg.Point(0, 1)), this is no longer the case.It's also strange that if you directly plot
Point(0, 1)andPoint(1, 0),Point(0, 1)doesn't really do what you'd expect. I'm not sure what to make of that.