1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-05-08 07:42:13 +02:00

refactor(plot/Waveform1D,plot/BECCurve): BECCurve inherits from BECConnector and can refer to parent_id (Waveform1D) and has its own gui_id

This commit is contained in:
wyzula-jan
2024-02-21 14:26:46 +01:00
parent 402adc44e8
commit 99dce077c4
10 changed files with 511 additions and 207 deletions
+16 -14
View File
@@ -4,7 +4,7 @@ from typing import Literal, Optional
import numpy as np
import pyqtgraph as pg
from bec_lib.utils import user_access
from pydantic import BaseModel, Field
from qtpy.QtWidgets import QWidget
@@ -24,7 +24,7 @@ class AxisConfig(BaseModel):
class WidgetConfig(ConnectionConfig):
parent_figure_id: Optional[str] = Field(None, description="The parent figure of the plot.")
parent_id: Optional[str] = Field(None, description="The parent figure of the plot.")
# Coordinates in the figure
row: int = Field(0, description="The row coordinate in the figure.")
@@ -37,6 +37,20 @@ class WidgetConfig(ConnectionConfig):
class BECPlotBase(BECConnector, pg.PlotItem):
USER_ACCESS = [
"set",
"set_title",
"set_x_label",
"set_y_label",
"set_x_scale",
"set_y_scale",
"set_x_lim",
"set_y_lim",
"set_grid",
"plot_data",
"remove",
]
def __init__(
self,
parent: Optional[QWidget] = None, # TODO decide if needed for this class
@@ -68,8 +82,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
- x_lim: tuple
- y_lim: tuple
"""
# TODO check functionality
# Mapping of keywords to setter methods
method_map = {
"title": self.set_title,
@@ -88,7 +100,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
def apply_axis_config(self):
"""Apply the axis configuration to the plot widget."""
# TODO check functionality
config_mappings = {
"title": self.config.axis.title,
"x_label": self.config.axis.x_label,
@@ -110,7 +121,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
self.setTitle(title)
self.config.axis.title = title
@user_access
def set_x_label(self, label: str):
"""
Set the label of the x-axis.
@@ -120,7 +130,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
self.setLabel("bottom", label)
self.config.axis.x_label = label
@user_access
def set_y_label(self, label: str):
"""
Set the label of the y-axis.
@@ -130,7 +139,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
self.setLabel("left", label)
self.config.axis.y_label = label
@user_access
def set_x_scale(self, scale: Literal["linear", "log"] = "linear"):
"""
Set the scale of the x-axis.
@@ -140,7 +148,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
self.setLogMode(x=(scale == "log"))
self.config.axis.x_scale = scale
@user_access
def set_y_scale(self, scale: Literal["linear", "log"] = "linear"):
"""
Set the scale of the y-axis.
@@ -150,7 +157,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
self.setLogMode(y=(scale == "log"))
self.config.axis.y_scale = scale
@user_access
def set_x_lim(self, x_lim: tuple) -> None:
"""
Set the limits of the x-axis.
@@ -160,7 +166,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
self.setXRange(x_lim[0], x_lim[1])
self.config.axis.x_lim = x_lim
@user_access
def set_y_lim(self, y_lim: tuple) -> None:
"""
Set the limits of the y-axis.
@@ -170,7 +175,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
self.setYRange(y_lim[0], y_lim[1])
self.config.axis.y_lim = y_lim
@user_access
def set_grid(self, x: bool = False, y: bool = False):
"""
Set the grid of the plot widget.
@@ -185,7 +189,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
def add_legend(self):
self.addLegend()
@user_access
def plot_data(self, data_x: list | np.ndarray, data_y: list | np.ndarray, **kwargs):
"""
Plot custom data on the plot widget. These data are not saved in config.
@@ -198,7 +201,6 @@ class BECPlotBase(BECConnector, pg.PlotItem):
# TODO decide name of the method
self.plot(data_x, data_y, **kwargs)
@user_access
def remove(self):
"""Remove the plot widget from the figure."""
if self.figure is not None: