feat(waveform): add no-line curve style

This commit is contained in:
wakonig_k committed 2026-09-17 16:23:13 +02:00
1 parent b76b95e7d8
commit e4b02bcdf3
6 files changed
+136 -15

No files matched your search

+35
View File
@@ -3,6 +3,7 @@ from unittest.mock import MagicMock, patch
import pytest
from bec_lib.scan_history import ScanHistory
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QComboBox, QVBoxLayout
from bec_widgets.widgets.plots.waveform.settings.curve_settings.curve_setting import CurveSetting
@@ -84,6 +85,40 @@ def test_curve_setting_accept_changes(curve_setting_fixture, qtbot):
send_spy.assert_called_once()
@pytest.mark.parametrize(
"style, label, expected_pen",
[
("none", "No line", Qt.NoPen),
("solid", "solid", Qt.SolidLine),
("dash", "dash", Qt.DashLine),
("dot", "dot", Qt.DotLine),
("dashdot", "dashdot", Qt.DashDotLine),
],
)
def test_curve_setting_style_round_trip(curve_setting_fixture, style, label, expected_pen):
"""Applying and restoring curve styles preserves the selection and rendered pen."""
settings, wf = curve_setting_fixture
wf.plot("bpm4i")
settings.refresh()
row = settings.curve_manager.all_items[0]
row.style_combo.setCurrentText(label)
settings.accept_changes()
serialized = wf.curve_json
assert json.loads(serialized)[0]["pen_style"] == style
wf.curve_json = serialized
curve = wf.curves[0]
curve.setData([1, 2, 3], [4, 5, 6])
assert curve.curve.opts["pen"].style() == expected_pen
assert curve.scatter.isVisible()
assert curve.scatter.opts["symbol"] == "o"
settings.refresh()
restored_row = settings.curve_manager.all_items[0]
assert restored_row.style_combo.currentText() == label
assert restored_row.style_combo.currentData() == style
def test_curve_setting_switch_device_mode(curve_setting_fixture, qtbot):
"""
If user chooses device mode from the combo, the device_x line edit should be enabled
+74 -1
View File
@@ -11,7 +11,7 @@ import pytest
from bec_lib import messages
from bec_lib.scan_items import ScanItem
from pyqtgraph.graphicsItems.DateAxisItem import DateAxisItem
from qtpy.QtCore import QTimer
from qtpy.QtCore import Qt, QTimer
from qtpy.QtWidgets import QApplication, QCheckBox, QDialog, QDialogButtonBox, QDoubleSpinBox
from bec_widgets.widgets.plots.plot_base import UIMode
@@ -1239,6 +1239,79 @@ def test_curve_set_appearance_methods(qtbot, mocked_client):
assert c.config.pen_style == "dashdot"
def test_curve_no_line_style_preserves_markers(qtbot, mocked_client):
"""Disabling the connecting line preserves markers across appearance and data updates."""
wf = create_widget(qtbot, Waveform, client=mocked_client)
curve = wf.plot(x=[1, 2, 3], y=[4, 5, 6], symbol="d")
curve.set_pen_style("none")
assert curve.opts["pen"].style() == Qt.NoPen
curve.set_color("#123456")
curve.set_symbol_color("#654321")
curve.set_symbol_size(12)
curve.set_pen_width(5)
curve.set_data([2, 3, 4], [5, 6, 7])
assert curve.config.pen_style == "none"
assert curve.curve.opts["pen"].style() == Qt.NoPen
assert curve.opts["pen"].color().name() == "#123456"
assert curve.scatter.isVisible()
assert curve.scatter.opts["symbol"] == "d"
assert curve.scatter.opts["size"] == 12
assert curve.scatter.opts["brush"].color().name() == "#654321"
np.testing.assert_array_equal(curve.scatter.getData(), [[2, 3, 4], [5, 6, 7]])
@pytest.mark.parametrize("data_length", [500, 1500])
@pytest.mark.parametrize("symbol", [None, "d"])
def test_curve_no_line_style_keeps_async_markers(qtbot, mocked_client, data_length, symbol):
"""Async data retain markers, including when automatic styling previously hid them."""
wf = create_widget(qtbot, Waveform, client=mocked_client)
curve = wf.plot(
x=[1, 2, 3],
y=[4, 5, 6],
pen_style="none",
pen_width=3,
symbol=symbol,
symbol_color="#654321",
symbol_size=12,
)
wf._auto_adjust_async_curve_settings(curve, data_length)
curve.setData(np.arange(data_length), np.arange(data_length))
assert curve.curve.opts["pen"].style() == Qt.NoPen
assert curve.scatter.isVisible()
assert curve.config.symbol == (symbol or "o")
assert curve.scatter.opts["symbol"] == (symbol or "o")
assert curve.scatter.opts["size"] == 12
assert curve.scatter.opts["brush"].color().name() == "#654321"
def test_curve_no_line_style_restores_existing_styles(qtbot, mocked_client):
"""The no-line style is reversible, and legacy null styles still draw solid lines."""
wf = create_widget(qtbot, Waveform, client=mocked_client)
curve = wf.plot(x=[1, 2, 3], y=[4, 5, 6], pen_style="none")
assert curve.curve.opts["pen"].style() == Qt.NoPen
for style, expected in (
("solid", Qt.SolidLine),
("dash", Qt.DashLine),
("dot", Qt.DotLine),
("dashdot", Qt.DashDotLine),
):
curve.set_pen_style(style)
assert curve.curve.opts["pen"].style() == expected
assert curve.curve.isVisible()
curve.set(pen_style="none")
assert curve.curve.opts["pen"].style() == Qt.NoPen
config = curve.config.model_dump()
config["pen_style"] = None
curve.apply_config(config)
assert curve.curve.opts["pen"].style() == Qt.SolidLine
def test_curve_set_custom_data(qtbot, mocked_client):
"""
Test that custom curves allow setting new data via set_data.