From 339e0152ffa2553fd65336b18f49d11ed185ae98 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Wed, 12 Mar 2025 17:16:30 +0100 Subject: [PATCH] fix(plot_base): ability to set y label suffix --- .../widgets/plots_next_gen/plot_base.py | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/bec_widgets/widgets/plots_next_gen/plot_base.py b/bec_widgets/widgets/plots_next_gen/plot_base.py index 68e8901d..157c789d 100644 --- a/bec_widgets/widgets/plots_next_gen/plot_base.py +++ b/bec_widgets/widgets/plots_next_gen/plot_base.py @@ -112,6 +112,8 @@ class PlotBase(BECWidget, QWidget): self.fps_label = QLabel(alignment=Qt.AlignmentFlag.AlignRight) self._user_x_label = "" self._x_label_suffix = "" + self._user_y_label = "" + self._y_label_suffix = "" self._init_ui() @@ -476,7 +478,7 @@ class PlotBase(BECWidget, QWidget): """ The set label for the y-axis. """ - return self.plot_item.getAxis("left").labelText + return self._user_y_label @y_label.setter def y_label(self, value: str): @@ -485,9 +487,39 @@ class PlotBase(BECWidget, QWidget): Args: value(str): The label to set. """ - self.plot_item.setLabel("left", text=value) + self._user_y_label = value + self._apply_y_label() self.property_changed.emit("y_label", value) + @property + def y_label_suffix(self) -> str: + """ + A read-only suffix automatically appended to the y label. + """ + return self._y_label_suffix + + def set_y_label_suffix(self, suffix: str): + """ + Public method to update the y label suffix. + """ + self._y_label_suffix = suffix + self._apply_y_label() + + @property + def y_label_combined(self) -> str: + """ + The final y label shown on the axis = user portion + suffix. + """ + return self._user_y_label + self._y_label_suffix + + def _apply_y_label(self): + """ + Actually updates the pyqtgraph y axis label text to + the combined y label. Called whenever y label or suffix changes. + """ + final_label = self.y_label_combined + self.plot_item.setLabel("left", text=final_label) + def _tuple_to_qpointf(self, tuple: tuple | list): """ Helper function to convert a tuple to a QPointF.