slaclab / pydm

Python Display Manager
http://slaclab.github.io/pydm/
Other
111 stars 76 forks source link

Crosshair coordinates don't follow plot coordinates #1040

Open ivan-usov opened 9 months ago

ivan-usov commented 9 months ago

Describe the bug The crosshair feature on a pydm plot (via enableCrosshair method) doesn't return x,y coordinates in units of corresponding plot axes, even though there only is a single y-axis present.

Expected behavior Crosshair coordinates should follow plot coordinates in case there are no multiple y-axis.

Steps to Reproduce Here is a simple example to demonstrate the issue:

from pydm import Display
from pydm.widgets import PyDMWaveformPlot
from qtpy.QtCore import Slot
from qtpy.QtWidgets import QApplication, QVBoxLayout

class TestScreen(Display):
    def __init__(self, parent=None, args=None, macros=None):
        super().__init__(parent=parent, args=args, macros=macros)
        self.app = QApplication.instance()
        main_layout = QVBoxLayout()
        self.setLayout(main_layout)
        plot = PyDMWaveformPlot()
        plot.addChannel()
        plot.enableCrosshair(is_enabled=True, starting_x_pos=0, starting_y_pos=0)
        plot.crosshair_position_updated.connect(print_coords)
        main_layout.addWidget(plot)

@Slot(float, float)
def print_coords(x, y):
    print(f"{x=:.2}", f"{y=:.2}")

starting the corresponding code via pydm, zooming in/out and moving a mouse prints unrelated x,y coordinates in terminal.

Possible Solution It seems that the issue stems from the fact that all pydm plots are MultiAxisPlots, and that there are multiple ViewBoxes that are kept in a custom property to support this functionality: https://github.com/slaclab/pydm/blob/d77104345741e84e9f3e51d69eae92b4c248b3ab/pydm/widgets/multi_axis_plot.py#L38 It's their ranges that reflect ranges of the corresponding axes, while the default vb seems to have an arbitrary range to which the crosshair gets hooked. It's clear, that in multi axis use case a single pair of x,y coordinates would be ambiguous. But it seems buggy when the same is happening also with a plot with only a single y-axis. Alternatively, this issue could be considered as a feature request for a more useful crosshair :)

My Platform image

jbellister-slac commented 9 months ago

Thanks for the report and investigation into the issue! Agreed that it is definitely a MultiAxisPlot/ViewBox issue and at a minimum we will get the crosshair working again for plots with a single y axis.