mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
feat(colors): evenly spaced color generation + new golden ratio calculation
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
from qtpy.QtGui import QColor
|
||||
|
||||
from bec_widgets.utils import Colors
|
||||
from bec_widgets.widgets.figure.plots.waveform.waveform_curve import CurveConfig
|
||||
@ -73,3 +74,39 @@ def test_rgba_to_hex():
|
||||
assert Colors.rgba_to_hex(255, 87, 51, 255) == "#FF5733FF"
|
||||
assert Colors.rgba_to_hex(255, 87, 51, 128) == "#FF573380"
|
||||
assert Colors.rgba_to_hex(255, 87, 51) == "#FF5733FF"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num", [10, 100, 400])
|
||||
def test_evenly_spaced_colors(num):
|
||||
colors_qcolor = Colors.evenly_spaced_colors(colormap="magma", num=num, format="QColor")
|
||||
colors_hex = Colors.evenly_spaced_colors(colormap="magma", num=num, format="HEX")
|
||||
colors_rgb = Colors.evenly_spaced_colors(colormap="magma", num=num, format="RGB")
|
||||
|
||||
assert len(colors_qcolor) == num
|
||||
assert len(colors_hex) == num
|
||||
assert len(colors_rgb) == num
|
||||
|
||||
assert all(isinstance(color, QColor) for color in colors_qcolor)
|
||||
assert all(isinstance(color, str) for color in colors_hex)
|
||||
assert all(isinstance(color, tuple) for color in colors_rgb)
|
||||
|
||||
assert all(color.isValid() for color in colors_qcolor)
|
||||
assert all(color.startswith("#") for color in colors_hex)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num", [10, 100, 400])
|
||||
def test_golder_angle_colors(num):
|
||||
colors_qcolor = Colors.golden_angle_color(colormap="magma", num=num, format="QColor")
|
||||
colors_hex = Colors.golden_angle_color(colormap="magma", num=num, format="HEX")
|
||||
colors_rgb = Colors.golden_angle_color(colormap="magma", num=num, format="RGB")
|
||||
|
||||
assert len(colors_qcolor) == num
|
||||
assert len(colors_hex) == num
|
||||
assert len(colors_rgb) == num
|
||||
|
||||
assert all(isinstance(color, QColor) for color in colors_qcolor)
|
||||
assert all(isinstance(color, str) for color in colors_hex)
|
||||
assert all(isinstance(color, tuple) for color in colors_rgb)
|
||||
|
||||
assert all(color.isValid() for color in colors_qcolor)
|
||||
assert all(color.startswith("#") for color in colors_hex)
|
||||
|
@ -152,12 +152,30 @@ def test_getting_curve(qtbot, mocked_client):
|
||||
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||
w1 = bec_figure.plot()
|
||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
|
||||
c1_expected_config = CurveConfig(
|
||||
c1_expected_config_dark = CurveConfig(
|
||||
widget_class="BECCurve",
|
||||
gui_id="test_curve",
|
||||
parent_id=w1.gui_id,
|
||||
label="bpm4i-bpm4i",
|
||||
color="#b73779",
|
||||
color="#3b0f70",
|
||||
symbol="o",
|
||||
symbol_color=None,
|
||||
symbol_size=7,
|
||||
pen_width=4,
|
||||
pen_style="solid",
|
||||
source="scan_segment",
|
||||
signals=Signal(
|
||||
source="scan_segment",
|
||||
x=SignalData(name="samx", entry="samx", unit=None, modifier=None),
|
||||
y=SignalData(name="bpm4i", entry="bpm4i", unit=None, modifier=None),
|
||||
),
|
||||
)
|
||||
c1_expected_config_light = CurveConfig(
|
||||
widget_class="BECCurve",
|
||||
gui_id="test_curve",
|
||||
parent_id=w1.gui_id,
|
||||
label="bpm4i-bpm4i",
|
||||
color="#000004",
|
||||
symbol="o",
|
||||
symbol_color=None,
|
||||
symbol_size=7,
|
||||
@ -171,14 +189,39 @@ def test_getting_curve(qtbot, mocked_client):
|
||||
),
|
||||
)
|
||||
|
||||
assert w1.curves[0].config == c1_expected_config
|
||||
assert w1._curves_data["scan_segment"]["bpm4i-bpm4i"].config == c1_expected_config
|
||||
assert w1.get_curve(0).config == c1_expected_config
|
||||
assert w1.get_curve_config("bpm4i-bpm4i", dict_output=True) == c1_expected_config.model_dump()
|
||||
assert w1.get_curve_config("bpm4i-bpm4i", dict_output=False) == c1_expected_config
|
||||
assert w1.get_curve("bpm4i-bpm4i").config == c1_expected_config
|
||||
assert c1.get_config(False) == c1_expected_config
|
||||
assert c1.get_config() == c1_expected_config.model_dump()
|
||||
assert (
|
||||
w1.curves[0].config == c1_expected_config_dark
|
||||
or w1.curves[0].config == c1_expected_config_light
|
||||
)
|
||||
assert (
|
||||
w1._curves_data["scan_segment"]["bpm4i-bpm4i"].config == c1_expected_config_dark
|
||||
or w1._curves_data["scan_segment"]["bpm4i-bpm4i"].config == c1_expected_config_light
|
||||
)
|
||||
assert (
|
||||
w1.get_curve(0).config == c1_expected_config_dark
|
||||
or w1.get_curve(0).config == c1_expected_config_light
|
||||
)
|
||||
assert (
|
||||
w1.get_curve_config("bpm4i-bpm4i", dict_output=True) == c1_expected_config_dark.model_dump()
|
||||
or w1.get_curve_config("bpm4i-bpm4i", dict_output=True)
|
||||
== c1_expected_config_light.model_dump()
|
||||
)
|
||||
assert (
|
||||
w1.get_curve_config("bpm4i-bpm4i", dict_output=False) == c1_expected_config_dark
|
||||
or w1.get_curve_config("bpm4i-bpm4i", dict_output=False) == c1_expected_config_light
|
||||
)
|
||||
assert (
|
||||
w1.get_curve("bpm4i-bpm4i").config == c1_expected_config_dark
|
||||
or w1.get_curve("bpm4i-bpm4i").config == c1_expected_config_light
|
||||
)
|
||||
assert (
|
||||
c1.get_config(False) == c1_expected_config_dark
|
||||
or c1.get_config(False) == c1_expected_config_light
|
||||
)
|
||||
assert (
|
||||
c1.get_config() == c1_expected_config_dark.model_dump()
|
||||
or c1.get_config() == c1_expected_config_light.model_dump()
|
||||
)
|
||||
|
||||
|
||||
def test_getting_curve_errors(qtbot, mocked_client):
|
||||
|
Reference in New Issue
Block a user