mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat(plot_base): toggle to switch outer axes for plotting widgets
This commit is contained in:
@ -1653,6 +1653,15 @@ class BECPlotBase(RPCBase):
|
|||||||
y(bool): Show grid on the y-axis.
|
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
|
@rpc_call
|
||||||
def lock_aspect_ratio(self, lock):
|
def lock_aspect_ratio(self, lock):
|
||||||
"""
|
"""
|
||||||
@ -2317,7 +2326,7 @@ class DapComboBox(RPCBase):
|
|||||||
@rpc_call
|
@rpc_call
|
||||||
def select_y_axis(self, y_axis: str):
|
def select_y_axis(self, y_axis: str):
|
||||||
"""
|
"""
|
||||||
Receive update signal for the y axis.
|
Slot to update the y axis.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
y_axis(str): Y axis.
|
y_axis(str): Y axis.
|
||||||
@ -2326,19 +2335,19 @@ class DapComboBox(RPCBase):
|
|||||||
@rpc_call
|
@rpc_call
|
||||||
def select_x_axis(self, x_axis: str):
|
def select_x_axis(self, x_axis: str):
|
||||||
"""
|
"""
|
||||||
Receive update signal for the x axis.
|
Slot to update the x axis.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
x_axis(str): X axis.
|
x_axis(str): X axis.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@rpc_call
|
@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:
|
Args:
|
||||||
default_device(str): Default device name.
|
default_device(str): Default device name.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ class AxisSettings(SettingWidget):
|
|||||||
|
|
||||||
# Top Box
|
# Top Box
|
||||||
WidgetIO.set_value(self.ui.plot_title, axis_config["title"])
|
WidgetIO.set_value(self.ui.plot_title, axis_config["title"])
|
||||||
|
self.ui.switch_outer_axes.checked = axis_config["outer_axes"]
|
||||||
|
|
||||||
# X Axis Box
|
# X Axis Box
|
||||||
WidgetIO.set_value(self.ui.x_label, axis_config["x_label"])
|
WidgetIO.set_value(self.ui.x_label, axis_config["x_label"])
|
||||||
@ -63,6 +64,7 @@ class AxisSettings(SettingWidget):
|
|||||||
@Slot()
|
@Slot()
|
||||||
def accept_changes(self):
|
def accept_changes(self):
|
||||||
title = WidgetIO.get_value(self.ui.plot_title)
|
title = WidgetIO.get_value(self.ui.plot_title)
|
||||||
|
outer_axes = self.ui.switch_outer_axes.checked
|
||||||
|
|
||||||
# X Axis
|
# X Axis
|
||||||
x_label = WidgetIO.get_value(self.ui.x_label)
|
x_label = WidgetIO.get_value(self.ui.x_label)
|
||||||
@ -86,3 +88,4 @@ class AxisSettings(SettingWidget):
|
|||||||
y_lim=y_lim,
|
y_lim=y_lim,
|
||||||
)
|
)
|
||||||
self.target_widget.set_grid(x_grid, y_grid)
|
self.target_widget.set_grid(x_grid, y_grid)
|
||||||
|
self.target_widget.set_outer_axes(outer_axes)
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>417</width>
|
<width>427</width>
|
||||||
<height>250</height>
|
<height>270</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
@ -26,7 +26,28 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<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">
|
<widget class="QGroupBox" name="y_axis_box">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Y Axis</string>
|
<string>Y Axis</string>
|
||||||
@ -120,7 +141,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QGroupBox" name="x_axis_box">
|
<widget class="QGroupBox" name="x_axis_box">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>X Axis</string>
|
<string>X Axis</string>
|
||||||
@ -214,22 +235,22 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="1" column="1">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<widget class="ToggleSwitch" name="switch_outer_axes">
|
||||||
<item>
|
<property name="checked" stdset="0">
|
||||||
<widget class="QLabel" name="plot_title_label">
|
<bool>false</bool>
|
||||||
<property name="text">
|
</property>
|
||||||
<string>Plot Title</string>
|
</widget>
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="plot_title"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>ToggleSwitch</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>toggle_switch</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
from typing import Literal, Optional
|
from typing import Literal, Optional
|
||||||
|
|
||||||
import bec_qthemes
|
import bec_qthemes
|
||||||
@ -31,6 +32,7 @@ class AxisConfig(BaseModel):
|
|||||||
y_lim: Optional[tuple] = Field(None, description="The limits of the y-axis.")
|
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.")
|
x_grid: bool = Field(False, description="Show grid on the x-axis.")
|
||||||
y_grid: bool = Field(False, description="Show grid on the y-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}
|
model_config: dict = {"validate_assignment": True}
|
||||||
|
|
||||||
|
|
||||||
@ -75,6 +77,7 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
|
|||||||
"set_x_lim",
|
"set_x_lim",
|
||||||
"set_y_lim",
|
"set_y_lim",
|
||||||
"set_grid",
|
"set_grid",
|
||||||
|
"set_outer_axes",
|
||||||
"lock_aspect_ratio",
|
"lock_aspect_ratio",
|
||||||
"export",
|
"export",
|
||||||
"remove",
|
"remove",
|
||||||
@ -336,6 +339,17 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
|
|||||||
self.config.axis.x_grid = x
|
self.config.axis.x_grid = x
|
||||||
self.config.axis.y_grid = y
|
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):
|
def add_legend(self):
|
||||||
"""Add legend to the plot"""
|
"""Add legend to the plot"""
|
||||||
self.plot_item.addLegend()
|
self.plot_item.addLegend()
|
||||||
|
@ -560,6 +560,15 @@ class BECWaveformWidget(BECWidget, QWidget):
|
|||||||
"""
|
"""
|
||||||
self.waveform.set_grid(x_grid, y_grid)
|
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):
|
def lock_aspect_ratio(self, lock: bool):
|
||||||
"""
|
"""
|
||||||
Lock the aspect ratio of the plot widget.
|
Lock the aspect ratio of the plot widget.
|
||||||
@ -633,10 +642,7 @@ class BECWaveformWidget(BECWidget, QWidget):
|
|||||||
def main(): # pragma: no cover
|
def main(): # pragma: no cover
|
||||||
from qtpy.QtWidgets import QApplication
|
from qtpy.QtWidgets import QApplication
|
||||||
|
|
||||||
from bec_widgets.utils.colors import set_theme
|
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
set_theme("auto")
|
|
||||||
widget = BECWaveformWidget()
|
widget = BECWaveformWidget()
|
||||||
widget.show()
|
widget.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
@ -177,6 +177,7 @@ def test_motor_map_init_from_config(qtbot, mocked_client):
|
|||||||
"y_lim": None,
|
"y_lim": None,
|
||||||
"x_grid": True,
|
"x_grid": True,
|
||||||
"y_grid": True,
|
"y_grid": True,
|
||||||
|
"outer_axes": False,
|
||||||
},
|
},
|
||||||
"signals": {
|
"signals": {
|
||||||
"source": "device_readback",
|
"source": "device_readback",
|
||||||
|
@ -72,6 +72,7 @@ def test_create_waveform1D_by_config(qtbot, mocked_client):
|
|||||||
"y_lim": None,
|
"y_lim": None,
|
||||||
"x_grid": False,
|
"x_grid": False,
|
||||||
"y_grid": False,
|
"y_grid": False,
|
||||||
|
"outer_axes": False,
|
||||||
},
|
},
|
||||||
"color_palette": "magma",
|
"color_palette": "magma",
|
||||||
"curves": {
|
"curves": {
|
||||||
|
Reference in New Issue
Block a user