Add dataBounds() method to TextItem to make autoRange more predictable#2646
Add dataBounds() method to TextItem to make autoRange more predictable#2646j9ac9k merged 4 commits intopyqtgraph:masterfrom
dataBounds() method to TextItem to make autoRange more predictable#2646Conversation
Sacrifices some visual polish to make the autorange functionality with TextItems much more predictable.
|
Looks good to me! I am ok with changing the default behavior here, but can you also add an init argument to disable dataBounds and restore the original behavior? |
|
@campagnola Sure, no problem. Any preferences for what that init argument would be called? (So I can be in line with the rest of the API) |
|
Hi @redruin1 First off, I owe you an apology for letting this PR sit for so long without a response, that wasn't fair to you. This is a very high quality PR that does a fantastic job highlighting the issue, the fix and potential downside. Thank you for that. I'm also good w/ changing the default behavior; I'm not sure we need to keep an argument to preserve legacy behavior tho (but @campagnola being the original author outranks me :D ). I don't think there is an argument in pyqtgraph that we can use for to maintain consistency, but there might be something in the Qt API. Scrolling through the Qt API looks like perhaps a flag is what we would want to add, and while this topic has come up before, we've never actually implemented out our enums that can be used as flags. Maybe |
also updated clause in ViewBox to handle `None` case
|
Alright, this was the least intrusive way to get the desired behavior that I could come up with. Ideally there would probably be some inheritance shuffling to enable/disable the if ensureInBounds:
self.dataBounds = None # Doesn't like del or delattr here, which is probably for the bestThe only other change (aside from docs) is changing the criteria in if hasattr(item, 'dataBounds') and item.dataBounds is not None
...This could maybe be more strict in checking that I didn't make helper methods for setting/modifying |
|
Hmm, seems like this interferes with the OpenGL glGetError wrapper function also not expecting |
|
I think you're on the right track, let me take a look later today and I can see if I come up with something. |
|
oh, the glError in read the docs CI is entirely unrelated, if you rebase The errors on python 3.11 with PyQt6 are due to a cpython bug here: python/cpython#105497 |
|
should the file |
whoops
|
whoops |
|
Thanks for the PR @redruin1 and thanks for your patience with a review. Merging! |
Summary
Sacrifices some visual polish to make the autorange functionality with TextItems much more predictable. "Fixes" #2642, though theoretically with some more effort it should be possible to still get high visual fidelity without runaway scaling.
Details
Adds the
dataBounds()method toTextItem, which supersedes the result fromboundingRect()when updating the ViewBox's autorange. Instead, only the anchor point is returned, behaving similarly to how a set of data points on a graph would be scaled to.Benefits
This PR fixes:
Runaway scaling when there is only one
TextItemin aPlotWidgetExample
Runaway scaling when there is multiple
TextItems in aPlotWidget, but they all share the same axisExample
Runaway scaling when the visual length of a
TextItemcannot entirely fit within aViewBoxat the current resolution/font sizeExample
Runaway scaling with
TextItemas a whole should be largely eliminatedDownsides
Files that need updates
Details
README.md(None needed)setup.py(None needed)tox.ini(None needed).github/workflows/main.ymland associatedrequirements.txtand condaenvironemt.ymlfiles (None needed)pyproject.toml(None needed)binder/requirements.txt(None needed)Pre-Release Checklist
Pre Release Checklist
__init__.pyCHANGELOGprimarily using contents from automated changelog generation in GitHub release pagePost-Release Checklist
Steps To Complete
.dev0to__version__in__init__.py