0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

fix(color maps): color maps should take the background color into account; fixed min colors to 10

This commit is contained in:
2024-08-27 12:36:02 +02:00
parent 50dbef52c0
commit 060935ffc5
4 changed files with 39 additions and 21 deletions

View File

@ -105,8 +105,19 @@ class Colors:
angles = Colors.golden_ratio(len(cmap_colors))
color_selection = np.round(np.interp(angles, (-np.pi, np.pi), (0, len(cmap_colors))))
colors = []
for ii in color_selection[:num]:
color = cmap_colors[int(ii)]
ii = 0
while len(colors) < num:
color_index = int(color_selection[ii])
color = cmap_colors[color_index]
app = QApplication.instance()
if hasattr(app, "theme") and app.theme["theme"] == "light":
background = 255
else:
background = 0
if np.abs(np.mean(color[:3] * 255) - background) < 50:
ii += 1
continue
if format.upper() == "HEX":
colors.append(QColor.fromRgbF(*color).name())
elif format.upper() == "RGB":
@ -115,6 +126,7 @@ class Colors:
colors.append(QColor.fromRgbF(*color))
else:
raise ValueError("Unsupported format. Please choose 'RGB', 'HEX', or 'QColor'.")
ii += 1
return colors
@staticmethod

View File

@ -451,8 +451,10 @@ class BECWaveform(BECPlotBase):
color = (
color
or Colors.golden_angle_color(
colormap=self.config.color_palette, num=len(self.plot_item.curves) + 1, format="HEX"
)[-1]
colormap=self.config.color_palette,
num=max(10, len(self.plot_item.curves) + 1),
format="HEX",
)[len(self.plot_item.curves)]
)
# Create curve by config
@ -546,9 +548,12 @@ class BECWaveform(BECPlotBase):
color = (
color
or Colors.golden_angle_color(
colormap=self.config.color_palette, num=len(self.plot_item.curves) + 1, format="HEX"
)[-1]
colormap=self.config.color_palette,
num=max(10, len(self.plot_item.curves) + 1),
format="HEX",
)[len(self.plot_item.curves)]
)
print(f"Color: {color}")
# Create curve by config
curve_config = CurveConfig(

View File

@ -44,8 +44,8 @@ class CurveConfig(ConnectionConfig):
symbol_color: Optional[str | tuple] = Field(
None, description="The color of the symbol of the curve."
)
symbol_size: Optional[int] = Field(5, description="The size of the symbol of the curve.")
pen_width: Optional[int] = Field(2, description="The width of the pen of the curve.")
symbol_size: Optional[int] = Field(7, description="The size of the symbol of the curve.")
pen_width: Optional[int] = Field(4, description="The width of the pen of the curve.")
pen_style: Optional[Literal["solid", "dash", "dot", "dashdot"]] = Field(
"solid", description="The style of the pen of the curve."
)

View File

@ -5,8 +5,7 @@ from typing import Literal
from bec_qthemes import material_icon
from pydantic import BaseModel
from qtpy.QtCore import QObject, QSize, Slot
from qtpy.QtGui import QIcon
from qtpy.QtCore import QObject, Slot
from qtpy.QtWidgets import QComboBox, QLineEdit, QPushButton, QSpinBox, QTableWidget, QVBoxLayout
import bec_widgets
@ -121,10 +120,10 @@ class CurveSettings(SettingWidget):
cm = self.ui.color_map_selector_dap.combo.currentText()
table = self.ui.dap_table
rows = table.rowCount()
colors = Colors.golden_angle_color(colormap=cm, num=rows + 1, format="HEX")
colors = Colors.golden_angle_color(colormap=cm, num=max(10, rows + 1), format="HEX")
color_button_col = 2 if target == "scan" else 3
for row, color in zip(range(rows), colors):
table.cellWidget(row, color_button_col).setColor(color)
for row in range(rows):
table.cellWidget(row, color_button_col).setColor(colors[row])
@Slot()
def accept_changes(self):
@ -251,12 +250,12 @@ class DialogRow(QObject):
self.width = QSpinBox()
self.width.setMinimum(1)
self.width.setMaximum(20)
self.width.setValue(2)
self.width.setValue(4)
self.symbol_size = QSpinBox()
self.symbol_size.setMinimum(1)
self.symbol_size.setMaximum(20)
self.symbol_size.setValue(5)
self.symbol_size.setValue(7)
self.remove_button.clicked.connect(
lambda: self.remove_row()
@ -281,9 +280,10 @@ class DialogRow(QObject):
self.width.setValue(self.config.pen_width)
self.symbol_size.setValue(self.config.symbol_size)
else:
default_color = Colors.golden_angle_color(
colormap="magma", num=self.row + 1, format="HEX"
)[-1]
default_colors = Colors.golden_angle_color(
colormap="plasma", num=max(10, self.row + 1), format="HEX"
)
default_color = default_colors[self.row]
self.color_button.setColor(default_color)
self.table_widget.setCellWidget(self.row, 0, self.device_line_edit)
@ -304,9 +304,10 @@ class DialogRow(QObject):
self.width.setValue(self.config.pen_width)
self.symbol_size.setValue(self.config.symbol_size)
else:
default_color = Colors.golden_angle_color(
colormap="magma", num=self.row + 1, format="HEX"
)[-1]
default_colors = Colors.golden_angle_color(
colormap="plasma", num=max(10, self.row + 1), format="HEX"
)
default_color = default_colors[self.row]
self.color_button.setColor(default_color)
self.table_widget.setCellWidget(self.row, 0, self.device_line_edit)