0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix(waveform): set_x method various bugs fixed

This commit is contained in:
2024-07-11 23:42:07 +02:00
parent 006992e43c
commit 8516a1d639
3 changed files with 83 additions and 5 deletions

View File

@ -1522,7 +1522,11 @@ class BECWaveform(RPCBase):
arg1(list | np.ndarray | str | None): First argument which can be x data, y data, or y_name. arg1(list | np.ndarray | str | None): First argument which can be x data, y data, or y_name.
y(list | np.ndarray): Custom y data to plot. y(list | np.ndarray): Custom y data to plot.
x(list | np.ndarray): Custom y data to plot. x(list | np.ndarray): Custom y data to plot.
x_name(str): The name of the device for the x-axis. x_name(str): Name of the x signal.
- "best_effort": Use the best effort signal.
- "timestamp": Use the timestamp signal.
- "index": Use the index signal.
- Custom signal name of device from BEC.
y_name(str): The name of the device for the y-axis. y_name(str): The name of the device for the y-axis.
z_name(str): The name of the device for the z-axis. z_name(str): The name of the device for the z-axis.
x_entry(str): The name of the entry for the x-axis. x_entry(str): The name of the entry for the x-axis.
@ -1570,12 +1574,16 @@ class BECWaveform(RPCBase):
""" """
@rpc_call @rpc_call
def change_x_axis(self, x_name: "str", x_entry: "str | None" = None): def set_x(self, x_name: "str", x_entry: "str | None" = None):
""" """
Change the x axis of the plot widget. Change the x axis of the plot widget.
Args: Args:
x_name(str): Name of the x signal. x_name(str): Name of the x signal.
- "best_effort": Use the best effort signal.
- "timestamp": Use the timestamp signal.
- "index": Use the index signal.
- Custom signal name of device from BEC.
x_entry(str): Entry of the x signal. x_entry(str): Entry of the x signal.
""" """

View File

@ -132,15 +132,23 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover:
x_name="index", y_name="bpm4i", new=True, title="Index Plot - w7", row=1, col=2 x_name="index", y_name="bpm4i", new=True, title="Index Plot - w7", row=1, col=2
) )
self.w8 = self.figure.plot( self.w8 = self.figure.plot(
y_name="monitor_async", new=True, title="Async Plot - Best Effort - w8", row=2, col=0
)
self.w9 = self.figure.plot(
x_name="timestamp", x_name="timestamp",
y_name="monitor_async", y_name="monitor_async",
new=True, new=True,
title="Async Plot - timestamp - w8", title="Async Plot - timestamp - w9",
row=2, row=2,
col=1, col=1,
) )
self.w9 = self.figure.plot( self.w10 = self.figure.plot(
y_name="monitor_async", new=True, title="Async Plot - index - w9", row=2, col=2 x_name="index",
y_name="monitor_async",
new=True,
title="Async Plot - index - w10",
row=2,
col=2,
) )
def _init_dock(self): def _init_dock(self):

View File

@ -385,6 +385,24 @@ class BECWaveform(BECPlotBase):
self.async_signal_update.emit() self.async_signal_update.emit()
self.scan_signal_update.emit() self.scan_signal_update.emit()
# self.autorange_timer.start(200)
@pyqtSlot()
def auto_range(self):
self.plot_item.autoRange()
def set_auto_range(self, enabled: bool, axis: str = "xy"):
"""
Set the auto range of the plot widget.
Args:
enabled(bool): If True, enable the auto range.
axis(str, optional): The axis to enable the auto range.
- "xy": Enable auto range for both x and y axis.
- "x": Enable auto range for x axis.
- "y": Enable auto range for y axis.
"""
self.plot_item.enableAutoRange(axis, enabled)
@pyqtSlot() @pyqtSlot()
def auto_range(self): def auto_range(self):
@ -925,6 +943,7 @@ class BECWaveform(BECPlotBase):
""" """
self.on_scan_status(msg) self.on_scan_status(msg)
self.scan_signal_update.emit() self.scan_signal_update.emit()
# self.autorange_timer.start(100)
def set_x_label(self, label: str, size: int = None): def set_x_label(self, label: str, size: int = None):
""" """
@ -1198,6 +1217,49 @@ class BECWaveform(BECPlotBase):
x_data = [] x_data = []
return x_data return x_data
# def _get_x_data(self, curve: BECCurve, y_name: str, y_entry: str) -> list | np.ndarray | None:
# """
# Get the x data for the curve with the decision logic based on the curve configuration:
# - If x is called 'timestamp', use the timestamp data from the scan item.
# - If x is called 'index', use the rolling index.
# - If x is a custom signal, use the data from the scan item.
# - If x is not specified, use the first device from the scan report.
#
# Args:
# curve(BECCurve): The curve object.
#
# Returns:
# list|np.ndarray|None: X data for the curve.
# """
# x_data = None
# if curve.config.signals.x is not None:
# if curve.config.signals.x.name == "timestamp":
# timestamps = self.scan_item.data[y_name][y_entry].timestamps
# x_data = self.convert_timestamps(timestamps)
# elif curve.config.signals.x.name == "index":
# x_data = None
# else:
# x_name = curve.config.signals.x.name
# x_entry = curve.config.signals.x.entry
# try:
# x_data = self.scan_item.data[x_name][x_entry].val
# except TypeError:
# x_data = []
# else:
# if len(self._curves_data["async"]) > 0:
# x_data = None
# else:
# x_name = self.scan_item.status_message.info["scan_report_devices"][0]
# x_entry = self.entry_validator.validate_signal(x_name, None)
# x_data = self.scan_item.data[x_name][x_entry].val
# self._x_axis_mode["label_suffix"] = f" [auto: {x_name}-{x_entry}]"
# current_label = "" if self.config.axis.x_label is None else self.config.axis.x_label
# self.plot_item.setLabel(
# "bottom", f"{current_label}{self._x_axis_mode['label_suffix']}"
# )
#
# return x_data
def _make_z_gradient(self, data_z: list | np.ndarray, colormap: str) -> list | None: def _make_z_gradient(self, data_z: list | np.ndarray, colormap: str) -> list | None:
""" """
Make a gradient color for the z values. Make a gradient color for the z values.