Skip to content

InfiniteLine: Fix bounding box for differing x and y ranges#727

Closed
dnadlinger wants to merge 2 commits intopyqtgraph:developfrom
dnadlinger:infinite-label-scale
Closed

InfiniteLine: Fix bounding box for differing x and y ranges#727
dnadlinger wants to merge 2 commits intopyqtgraph:developfrom
dnadlinger:infinite-label-scale

Conversation

@dnadlinger
Copy link
Copy Markdown
Contributor

@dnadlinger dnadlinger commented Jul 15, 2018

Previously, the same pixel -> local transform was used for both
direction, which breaks e.g. for AxisItem.scale if the
displayed coordinate range is not the same for both axes. This also
fixes the computation of label coordinates in that situation.

@dnadlinger dnadlinger force-pushed the infinite-label-scale branch from f7d0782 to 527e199 Compare July 15, 2018 23:05
@dnadlinger dnadlinger changed the title InfiniteLine: Fix bounding box for different x and y scales InfiniteLine: Fix bounding box for differing x and y scales Jul 15, 2018
@campagnola
Copy link
Copy Markdown
Member

Hi @klickverbot, your code looks much nicer. Can you give me an example (with minimal code if necessary) of the situation that is fixed by this? Ideally, you or I can write a unit test to cover that case.

@dnadlinger
Copy link
Copy Markdown
Contributor Author

dnadlinger commented Jul 20, 2018

My use case was just a vertical InfiniteLine with a label attached at position 0.95 as per the examples code. When setting an AxisItem.scale of, say, 1000 on only one of the left or bottom axis, the label would be placed off-screen.

I don't have access to the code right now, unfortunately, but the issue should be fairly easy to reverse-engineer – the problem in the original code is that the same px is used for both axes, which is incorrect with different scale factors involved. (In one of the directions, the label will still be shown near the line, as the offset will just be too small rather than too large.)

Unit tests for this would obviously be great, but I haven't had a chance to dig into setting them up for the graphical output yet.

@dnadlinger dnadlinger force-pushed the infinite-label-scale branch from 527e199 to 34d5391 Compare July 21, 2018 14:13
@dnadlinger
Copy link
Copy Markdown
Contributor Author

Apologies, this is not related to AxisItem.scale at all, but just to the displayed ranges. I was manually pre-scaling the data to compensate for not setting .scale in the application where I found this issue which happened to more or less equalise the x and y ranges, hence the confusion. Commit message updated accordingly.

Here is a minimal test case:

win = pg.GraphicsLayoutWidget(show=True)

plot = win.addPlot()
plot.setXRange(0, 1)
plot.setYRange(0, 1e-3)

inf = pg.InfiniteLine(angle=90, label='test', labelOpts={'position':0.7})
inf.setPos(0.5)
plot.addItem(inf)

@dnadlinger dnadlinger changed the title InfiniteLine: Fix bounding box for differing x and y scales InfiniteLine: Fix bounding box for differing x and y ranges Jul 21, 2018
@dnadlinger dnadlinger force-pushed the infinite-label-scale branch from 34d5391 to 696edde Compare July 24, 2018 12:31
@dnadlinger
Copy link
Copy Markdown
Contributor Author

dnadlinger commented Jul 24, 2018

@campagnola: I added a unit test. It's somewhat pedestrian, but I didn't want the test to rely on the same local->scene coordinate conversion code.

@dnadlinger
Copy link
Copy Markdown
Contributor Author

Hmm, the test case passes locally (OS X); I've pushed a temporary commit to try and figure out what is going on.

@dnadlinger dnadlinger force-pushed the infinite-label-scale branch 2 times, most recently from b93c932 to 10f7a8f Compare July 24, 2018 15:31
@dnadlinger
Copy link
Copy Markdown
Contributor Author

Tests now pass; apparently there is just a bit over a pixel in placement difference between the platforms.

@dnadlinger dnadlinger force-pushed the infinite-label-scale branch from 10f7a8f to 46ddf61 Compare August 24, 2018 22:04
@dnadlinger
Copy link
Copy Markdown
Contributor Author

dnadlinger commented Aug 24, 2018

@campagnola: Sorry to be impatient, but: Ping? I'd like to avoid having to maintain an internal fork/monkey patch…

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #727 into develop will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #727      +/-   ##
===========================================
+ Coverage    34.74%   34.75%   +<.01%     
===========================================
  Files          208      208              
  Lines        28285    28281       -4     
  Branches      4574     4572       -2     
===========================================
  Hits          9829     9829              
  Misses       17577    17577              
+ Partials       879      875       -4
Impacted Files Coverage Δ
pyqtgraph/graphicsItems/InfiniteLine.py 59% <100%> (+0.32%) ⬆️
pyqtgraph/multiprocess/remoteproxy.py 57.69% <0%> (-0.93%) ⬇️
pyqtgraph/graphicsItems/AxisItem.py 62.99% <0%> (+0.51%) ⬆️
pyqtgraph/graphicsItems/GraphicsItem.py 67.45% <0%> (+1.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9aaae8d...46ddf61. Read the comment docs.

@dnadlinger
Copy link
Copy Markdown
Contributor Author

Rebased. (I also cleaned up the tests a bit a while back.)

@dnadlinger
Copy link
Copy Markdown
Contributor Author

dnadlinger commented Jan 29, 2019

@campagnola: Ping. The software I mentioned above that depends on this is going to be deployed more widely soon, and while having to pin a pyqtgraph Git commit instead of a release is one thing, shipping a custom fork is a bit annoying.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 24, 2019

@dnadlinger Thanks for the PR, sorry we're taking a while to get to it, we're going through a lot of house-keeping and getting our test suite in order has been the priority.

I'll try and get to this in the coming few days; feel free to ping me if I haven't followed up in a week or so.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 31, 2020

hi @dnadlinger, I attempted to do the conflict resolution and blew up your PR, sorry about that, I'll straighten this out.

Previously, the same pixel -> local transform was used for both
direction, which breaks if the displayed coordinate range is not
the same for both axes.
@j9ac9k j9ac9k force-pushed the infinite-label-scale branch from b2df2bd to ebc192d Compare May 31, 2020 05:40
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 31, 2020

So the CI system doesn't like this PR... failure pattern is the oddest I've ever seen. All Linux builds pass, all Windows builds fail, most macOS builds fail, but some pass. I'm on macOS and replicated one of the failed builds, and replicated the passed build as well.

I'll dive into this a bit more and see if I can turn anything up.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 31, 2020

Now Windows images are failing on

>       assert not contains(hbr, 37, 185)
E       assert not True
E        +  where True = <function test_InfiniteLine_scaled_bounding_box.<locals>.contains at 0x0000018852A023A0>(<PyQt5.QtGui.QPolygonF object at 0x0000018852A00660>, 37, 185)

If I had more time I would get the custom pytest assertrepr functionality working so I could at least see what the bounding rect was for these polygons and see how close these points are...

@j9ac9k j9ac9k force-pushed the infinite-label-scale branch from 2e77db8 to 53617ed Compare May 31, 2020 07:03
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 31, 2020

CI is about to wrap up, two of the assert contains(...) checks are commented out. I'll see if anyone else has thoughts on how we should modify them (or remove those checks entirely).

@dnadlinger
Copy link
Copy Markdown
Contributor Author

No idea, sorry – I just modeled the tests after the existing ones.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jun 1, 2020

Hi @dnadlinger figured as much due to thinking about how I would programmatically determine good points to verify. Wasn't expecting you to come back after 2 years, again, sorry its taken us so long to look into this. I'm still going to want to merge but I'll think a bit more about relevant test conditions.

@dnadlinger
Copy link
Copy Markdown
Contributor Author

Yep, it's a bit non-trivial, because ideally you wouldn't want to depend on the same piece of math used to compute the bounding box to verify the result as well.

I thought the scene coordinates should be quite stable, but perhaps there is a platform-dependent offset or something to take into consideration?

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jun 1, 2020

From my first re-run on this, it's not even platform dependent (which may just be a CI related issue, after all, I'm running these tests on headless systems with virtual displays, who knows how things render), but the test results varied within versions of Qt, so I'm not comfortable w/ even just experimenting until we find known good values, as things could change.

I do want to get this merged at some point, but I'm going to leave it open for now until I can try and come up with a more robust test method.

@dnadlinger
Copy link
Copy Markdown
Contributor Author

A simple regression test would just be to inspect _bounds – this would still show the problem with the old implementation.

@dnadlinger
Copy link
Copy Markdown
Contributor Author

dnadlinger commented Jun 1, 2020

And yes, experimenting is definitely not the way to go. I was just hoping someone who has the various coordinate transforms in pyqtgraph paged into their working memory could find a more appropriate coordinate space in which to do the comparisons.

@outofculture outofculture added the sprint Tag relating to issue/PR that is a good candidate for addressing during the sprints label Jul 13, 2021
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 2, 2022

Will be fixed in #2407 🎊

@j9ac9k j9ac9k closed this Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sprint Tag relating to issue/PR that is a good candidate for addressing during the sprints

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants