Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot stack InfLineLabel in front of all other InfiniteLine #2859

Open
bbc131 opened this issue Oct 27, 2023 · 0 comments
Open

Cannot stack InfLineLabel in front of all other InfiniteLine #2859

bbc131 opened this issue Oct 27, 2023 · 0 comments

Comments

@bbc131
Copy link
Contributor

bbc131 commented Oct 27, 2023

If you have multiple InfiniteLine items with enabled labels (i.e. InfLineLabel), it is not possible to make all the labels appear in front of all the lines.

Problem

To illustrate the problem you can use the code below. It displays two lines, each with a label. If you move the lines close to each other, you can get something like this:
image

Here I would like to be able to make the blue label appear in front of the red line. But this should not result in the red label being placed behind the blue line.
In short, I want to have all labels always in front of the lines.

With this example this might seem as a rather unimportant problem, but if you have lots of lines with labels, you run pretty fast in a situation where your labels are hidden by one or more lines and become unreadable.

Possible solution

The problem with the current implementation is, that the InfLineLabel items are child items of their InfiniteLine item. Therefore, changing the zValue doesn't help here.
The only solution I see is to remove the parent-child-item relationship between an InfiniteLine and its attached InfLineLabel.
If they become then siblings, one can use the zValue to control the stacking order. I guess, the default behaviour (default stacking order) could be kept as it is now.

If this feature would be welcome, I could try to come up with a PR.

Code example

import pyqtgraph as pg

app = pg.mkQApp()
win = pg.PlotWidget()
win.show()

_common_label_opts = {'color': 'white', 'movable': True, 'anchors': [(-0.2, 0), (1.2, 0)]}

win.addItem(pg.InfiniteLine(pos=1.0, movable=True, label='bar', pen=pg.mkPen(width=2, color="blue"),
                labelOpts={'position': 0.1, 'fill': 'blue', **_common_label_opts}))
win.addItem(pg.InfiniteLine(pos=2.0, movable=True, label='foo', pen=pg.mkPen(width=2, color="red"),
                labelOpts={'position': 0.125,  'fill': 'red', **_common_label_opts}))

if __name__ == '__main__':
    pg.exec()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant