Add style option 'hideOverlappingLabels'#2385
Conversation
* With 'hideOverlappingLabels==False' nothing changes. Tick labels might be drawn overlapping with tick labels from neighboring plots or overlap with other items or might be simply clipped. * With 'hideOverlappingLabels==True', only tick labels, which are fully contained within the items geometry rectangle are drawn.
|
Hi @bbc131 thanks for the PR! Code diff looks fine, I just left one in-line comment. Read the docs doesn't like the changes to the docstring, here is the blurb that it is emitting warnings/errors about. |
ixjlyons
left a comment
There was a problem hiding this comment.
This looks like a nice improvement to me.
I wonder if it makes sense to expose the allowable overlap value itself. I notice matplotlib gives axis tick labels a little extra space outside the axis line, but that could be because of some padding at an Axes or Figure level or something, I'm not sure. I struggle to think of a good name for such a parameter though, which probably means it's better as on/off.
I also don't know about changing behavior to default 0. It seems like a more reasonable default than 15 though I'd say.
pyqtgraph/graphicsItems/AxisItem.py
Outdated
| Set various style options. | ||
|
|
||
| =================== ======================================================= | ||
| =========================================================================== |
There was a problem hiding this comment.
Need to preserve the breaks in the top and bottom table borders, lined up with the column of space between the argument names and descriptions.
1ab274a to
76111d5
Compare
I think it makes sense to have this value being equal to the surrounding layout's border margins. So if you use different margins, you may want to change this value. |
| #p.drawText(rect, textFlags, vstr) | ||
|
|
||
| br = self.boundingRect() | ||
| if not br.contains(rect): |
There was a problem hiding this comment.
I just realized, that my note in the commit message
With 'hideOverlappingLabels==False' nothing changes.
isn't true. Originally, the labels get clipped, if they go over the bounding rect. After my change, they will be hidden, independent of hideOverlappingLabels.
So, to get really the same behaviour as originally with hideOverlappingLabels==False, one should change the following.
| if not br.contains(rect): | |
| if self.style['hideOverlappingLabels'] and not br.contains(rect): |
But, as painting outside of the bounding rect is not allowed (see https://doc.qt.io/qt-5/qgraphicsitem.html#paint), this clipping should additionally be implemented or we simply keep the hiding enabled if it goes out ot the bounding rect.
There was a problem hiding this comment.
Given that painting outside boundingRect I'm good w/ how it currently is
that's fairly sensible, would you be up for changing the |
I quickly looked into this using the GraphicsLayout example and it seems to be not so straight forward as I thought: For example the bottom So, first problem: It's not easy to decide from which layout the margins should be taken. Further, this aforementioned superior layout So all in all I would say, that it would be too much to consider all these possibilities. I suggest to stick with a constant default value. |
|
Thanks for investigating @bbc131 this LGTM, merging. |
* Add style option 'hideOverlappingLabels' * With 'hideOverlappingLabels==False' nothing changes. Tick labels might be drawn overlapping with tick labels from neighboring plots or overlap with other items or might be simply clipped. * With 'hideOverlappingLabels==True', only tick labels, which are fully contained within the items geometry rectangle are drawn. * Fix docstring
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
Tick labels might be drawn overlapping with tick labels from
neighboring plots or overlap with other items or might be simply
clipped.
fully contained within the items geometry rectangle are drawn.
Fixes the following problem
The tick labels of
AxisItemcan be drawn outside ofGraphicsWidget.geometry()rectangle, therefore, they might overlap with neighboring items, e.g. tick labels from other plots or simply be clipped.It's very easy to reproduce this with the
GraphicsLayoutexample, just zoom and pan the view, to provoke some labels with long values at the axis edges. See also the following screenshot with overlapping / clipped tick labels.In comparison to that, the screenshot below shows the result of this fix which means the labels which would overlap or be clipped haven't been drawn.