Fix invisible InfiniteLine at plot edges#2762
Conversation
|
Looks like there is some infinite recursion happening; can you investigate this test failure? |
|
Currently I don't understand why this recursion happens, but it origins from my changes to the boundingRect. It doesn't happen, if I put this boundingRect adjustment into But since the issue with the boundingRect (2. in PR message) is independent of the issue with the axis baselines (1. in PR message) I would like to handle this separately and create another issue / PR. So, at the present state, this PR solves the problems for at least the left and upper edge of the plot. |
|
I find that the recursion error stops if you return a copy of the def boundingRect(self):
br = super().boundingRect()
return br.adjusted(-0.5, 0, +0.5, +0.5)I suppose if the parent class caches its Could you explain the reason for the asymmetry in the bounds adjustment? |
|
I did a look through the various items that provide an
A related change to fix your PR would be to make def boundingRect(self):
# snip
return QtCore.QRectF(br)It's unclear whether |
|
I'm team modify |
|
Thank you for your help. I added the fix to Regarding the asymmetry in the bounds adjustment, I removed it. |
This has to do with the following hierarchy: zValues are only considered for ordering of siblings. Therefore, InfiniteLine, as a child of ViewBox, will always get drawn before AxisItem. |
I have an InfiniteLine in a plot, which have both the same limits, i.e. the line can be dragged until the limits of the plot but not further.
Now, if you do exactly this, the line won't be visible.
See below the before screenshot and the code I used to set it up.
This problem exists for all for edges of a plot and independent of axes being visible or not.
I think, if a plot displays a range of e.g. 0..10 and you place a line at 0 or 10, you should still see it. Therefore, I consider this as a bug.
Searching for the reasons I found the following two issues and tried to solve them in the present PR:
AxisItem draws its baseline right within the plot and overlays the InfiniteLine
For abothes example with visible range of 0..10, the axis' baseline is drawn e.g. at 0, and a InfiniteLine which is placed there will be hidden behind the axis baseline.
This can easily be debugged by making the axis' baseline dashed.
Therefore I changed this and let the axis baselines be drawn right outside of the plot-area (move by 1 px in the corresponding direction)
Another idea regarding the axis baselines I had, was to let the InfiniteLine be drawn in front of the axis baseline, but this didn't work. The axis' z-value is 0.5 and I can set the InfiniteLine's z-value to anything larger than this but it's still not visible. I guess this has something to do with the parent-child relationships within the scene but I didn't analyzed this further.
The InfiniteLine is invisible itself, because it's out of the boundingRect of the ViewBox
This can easily be seen if the baselines of the axes are not drawn anymore. In this case you can see the InfiniteLine disappearing if its moved to the edge.
To resolve this, I increased the boundingRect of the ViewBox slightly. Here I had to play around to find the values which work for me. I don't know why the left edge behaves different than the top edge!
Before

After
