0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

feat(plot_base): toggle to switch outer axes for plotting widgets

This commit is contained in:
2024-09-04 17:08:08 +02:00
committed by wyzula_j
parent 6b15abcc73
commit 06d7741622
7 changed files with 81 additions and 26 deletions

View File

@ -1653,6 +1653,15 @@ class BECPlotBase(RPCBase):
y(bool): Show grid on the y-axis.
"""
@rpc_call
def set_outer_axes(self, show: "bool" = True):
"""
Set the outer axes of the plot widget.
Args:
show(bool): Show the outer axes.
"""
@rpc_call
def lock_aspect_ratio(self, lock):
"""
@ -2317,7 +2326,7 @@ class DapComboBox(RPCBase):
@rpc_call
def select_y_axis(self, y_axis: str):
"""
Receive update signal for the y axis.
Slot to update the y axis.
Args:
y_axis(str): Y axis.
@ -2326,19 +2335,19 @@ class DapComboBox(RPCBase):
@rpc_call
def select_x_axis(self, x_axis: str):
"""
Receive update signal for the x axis.
Slot to update the x axis.
Args:
x_axis(str): X axis.
"""
@rpc_call
def select_fit(self, fit_name: str | None):
def select_fit_model(self, fit_name: str | None):
"""
Select current fit.
Slot to update the fit model.
Args:
default_device(str): Default device name.
Args:
default_device(str): Default device name.
"""

View File

@ -31,6 +31,7 @@ class AxisSettings(SettingWidget):
# Top Box
WidgetIO.set_value(self.ui.plot_title, axis_config["title"])
self.ui.switch_outer_axes.checked = axis_config["outer_axes"]
# X Axis Box
WidgetIO.set_value(self.ui.x_label, axis_config["x_label"])
@ -63,6 +64,7 @@ class AxisSettings(SettingWidget):
@Slot()
def accept_changes(self):
title = WidgetIO.get_value(self.ui.plot_title)
outer_axes = self.ui.switch_outer_axes.checked
# X Axis
x_label = WidgetIO.get_value(self.ui.x_label)
@ -86,3 +88,4 @@ class AxisSettings(SettingWidget):
y_lim=y_lim,
)
self.target_widget.set_grid(x_grid, y_grid)
self.target_widget.set_outer_axes(outer_axes)

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>417</width>
<height>250</height>
<width>427</width>
<height>270</height>
</rect>
</property>
<property name="minimumSize">
@ -26,7 +26,28 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="plot_title_label">
<property name="text">
<string>Plot Title</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="plot_title"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_outer_axes">
<property name="text">
<string>Outer Axes</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QGroupBox" name="y_axis_box">
<property name="title">
<string>Y Axis</string>
@ -120,7 +141,7 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QGroupBox" name="x_axis_box">
<property name="title">
<string>X Axis</string>
@ -214,22 +235,22 @@
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="plot_title_label">
<property name="text">
<string>Plot Title</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="plot_title"/>
</item>
</layout>
<item row="1" column="1">
<widget class="ToggleSwitch" name="switch_outer_axes">
<property name="checked" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ToggleSwitch</class>
<extends>QWidget</extends>
<header>toggle_switch</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,5 +1,6 @@
from __future__ import annotations
from collections import defaultdict
from typing import Literal, Optional
import bec_qthemes
@ -31,6 +32,7 @@ class AxisConfig(BaseModel):
y_lim: Optional[tuple] = Field(None, description="The limits of the y-axis.")
x_grid: bool = Field(False, description="Show grid on the x-axis.")
y_grid: bool = Field(False, description="Show grid on the y-axis.")
outer_axes: bool = Field(False, description="Show the outer axes of the plot widget.")
model_config: dict = {"validate_assignment": True}
@ -75,6 +77,7 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
"set_x_lim",
"set_y_lim",
"set_grid",
"set_outer_axes",
"lock_aspect_ratio",
"export",
"remove",
@ -336,6 +339,17 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
self.config.axis.x_grid = x
self.config.axis.y_grid = y
def set_outer_axes(self, show: bool = True):
"""
Set the outer axes of the plot widget.
Args:
show(bool): Show the outer axes.
"""
self.plot_item.showAxis("top", show)
self.plot_item.showAxis("right", show)
self.config.axis.outer_axes = show
def add_legend(self):
"""Add legend to the plot"""
self.plot_item.addLegend()

View File

@ -560,6 +560,15 @@ class BECWaveformWidget(BECWidget, QWidget):
"""
self.waveform.set_grid(x_grid, y_grid)
def set_outer_axes(self, show: bool):
"""
Set the outer axes visibility of the plot widget.
Args:
show(bool): Visibility of the outer axes.
"""
self.waveform.set_outer_axes(show)
def lock_aspect_ratio(self, lock: bool):
"""
Lock the aspect ratio of the plot widget.
@ -633,10 +642,7 @@ class BECWaveformWidget(BECWidget, QWidget):
def main(): # pragma: no cover
from qtpy.QtWidgets import QApplication
from bec_widgets.utils.colors import set_theme
app = QApplication(sys.argv)
set_theme("auto")
widget = BECWaveformWidget()
widget.show()
sys.exit(app.exec_())

View File

@ -177,6 +177,7 @@ def test_motor_map_init_from_config(qtbot, mocked_client):
"y_lim": None,
"x_grid": True,
"y_grid": True,
"outer_axes": False,
},
"signals": {
"source": "device_readback",

View File

@ -72,6 +72,7 @@ def test_create_waveform1D_by_config(qtbot, mocked_client):
"y_lim": None,
"x_grid": False,
"y_grid": False,
"outer_axes": False,
},
"color_palette": "magma",
"curves": {