继续优化深色模式显示

This commit is contained in:
xinzhu.yin
2026-05-28 16:41:52 +08:00
parent cf724d60d7
commit c173e2338d
10 changed files with 278 additions and 96 deletions

View File

@@ -75,7 +75,7 @@ def _xy_to_uv(x: float, y: float):
# 子图:左侧 Calman 风格面板
# ============================================================
def _draw_left_panel(ax, color_patches, delta_e_values, font_scale=1.0):
def _draw_left_panel(ax, color_patches, delta_e_values, font_scale=1.0, dark_mode=False):
"""左侧仅保留大条形图。"""
ax.clear()
@@ -98,19 +98,23 @@ def _draw_left_panel(ax, color_patches, delta_e_values, font_scale=1.0):
zorder=3,
)
text_color = "#F3F5F7" if dark_mode else "#111111"
bg_color = "#0F1115" if dark_mode else "#FFFFFF"
spine_color = "#8C8F94" if dark_mode else "#9A9A9A"
ax.set_yticks(y_pos)
ax.set_yticklabels(color_patches, fontsize=max(5, 7 * font_scale))
ax.set_yticklabels(color_patches, fontsize=max(5, 7 * font_scale), color=text_color)
ax.invert_yaxis()
x_max = max(15.0, max(delta_e_values) * 1.15)
ax.set_xlim(0, x_max)
ax.tick_params(axis="x", labelsize=max(6, 8 * font_scale))
ax.tick_params(axis="x", labelsize=max(6, 8 * font_scale), colors=text_color)
ax.grid(axis="x", linestyle="-", linewidth=0.6, alpha=0.3, zorder=0)
ax.grid(axis="y", linestyle=":", linewidth=0.35, alpha=0.15, zorder=0)
ax.set_facecolor("#FFFFFF")
ax.set_facecolor(bg_color)
for spine in ax.spines.values():
spine.set_color("#9A9A9A")
spine.set_color(spine_color)
spine.set_linewidth(0.9)
@@ -118,7 +122,7 @@ def _draw_left_panel(ax, color_patches, delta_e_values, font_scale=1.0):
# 子图CIE 1976 u'v' 色度图(目标 vs 实测)
# ============================================================
def _draw_uv_diagram(ax, color_patches, measurements, standards, font_scale=1.0):
def _draw_uv_diagram(ax, color_patches, measurements, standards, font_scale=1.0, dark_mode=False):
"""绘制 CIE 1976 u'v' 上的色准对比。"""
ax.clear()
try:
@@ -135,15 +139,23 @@ def _draw_uv_diagram(ax, color_patches, measurements, standards, font_scale=1.0)
ax.set_xlim(0.0, 0.65)
ax.set_ylim(0.0, 0.60)
ax.set_facecolor("#000")
text_color = "#F3F5F7" if dark_mode else "#111111"
sub_text_color = "#D3D7DD" if dark_mode else "#222222"
tick_color = "#D3D7DD" if dark_mode else "#222222"
legend_label_color = "#FFF" if dark_mode else "#111"
legend_bg = "#111" if dark_mode else "#FFFFFF"
legend_edge = "#FFF" if dark_mode else "#333"
outer_edge = "#FFFFFF" if dark_mode else "#333333"
ax.set_facecolor("#000" if dark_mode else "#FFFFFF")
ax.set_aspect("equal", adjustable="box")
ax.set_title("CIE 1976 u'v'", fontsize=max(8, 11 * font_scale), fontweight="bold",
color="#111", pad=4)
ax.set_xlabel("u'", fontsize=max(7, 9 * font_scale), color="#222", labelpad=1)
ax.set_ylabel("v'", fontsize=max(7, 9 * font_scale), color="#222", labelpad=1)
ax.tick_params(axis="both", labelsize=max(6, 8 * font_scale), colors="#222")
color=text_color, pad=4)
ax.set_xlabel("u'", fontsize=max(7, 9 * font_scale), color=sub_text_color, labelpad=1)
ax.set_ylabel("v'", fontsize=max(7, 9 * font_scale), color=sub_text_color, labelpad=1)
ax.tick_params(axis="both", labelsize=max(6, 8 * font_scale), colors=tick_color)
for sp in ax.spines.values():
sp.set_color("#666")
sp.set_color(outer_edge)
sp.set_linewidth(0.9)
for name, meas in zip(color_patches, measurements):
@@ -164,14 +176,14 @@ def _draw_uv_diagram(ax, color_patches, measurements, standards, font_scale=1.0)
ax.scatter(
[s_u], [s_v],
s=56, marker="s",
facecolors="none", edgecolors="#FFFFFF",
facecolors="none", edgecolors=outer_edge,
linewidths=1.25, zorder=18,
)
# 实测点:白色外圈 + 内层圆点
ax.scatter(
[m_u], [m_v],
s=52, marker="o",
facecolors="none", edgecolors="#FFFFFF",
facecolors="none", edgecolors=outer_edge,
linewidths=1.0, zorder=19,
)
ax.scatter(
@@ -183,7 +195,7 @@ def _draw_uv_diagram(ax, color_patches, measurements, standards, font_scale=1.0)
legend_handles = [
Line2D([0], [0], marker="s", linestyle="none",
markerfacecolor="#CCCCCC", markeredgecolor="#FFFFFF",
markerfacecolor="#CCCCCC", markeredgecolor=outer_edge,
markersize=7, label="目标 (Target)"),
Line2D([0], [0], marker="o", linestyle="none",
markerfacecolor="#CCCCCC", markeredgecolor="#000000",
@@ -192,15 +204,15 @@ def _draw_uv_diagram(ax, color_patches, measurements, standards, font_scale=1.0)
leg = ax.legend(
handles=legend_handles,
loc="lower right", fontsize=max(6, 8 * font_scale),
framealpha=0.88, labelcolor="#FFF",
framealpha=0.88, labelcolor=legend_label_color,
)
if leg is not None:
leg.get_frame().set_facecolor("#111")
leg.get_frame().set_edgecolor("#FFF")
leg.get_frame().set_facecolor(legend_bg)
leg.get_frame().set_edgecolor(legend_edge)
leg.set_zorder(50)
def _draw_result_judgement(ax, accuracy_data, font_scale=1.0):
def _draw_result_judgement(ax, accuracy_data, font_scale=1.0, dark_mode=False):
"""底部结果条"""
ax.clear()
ax.set_xlim(0, 1)
@@ -210,24 +222,28 @@ def _draw_result_judgement(ax, accuracy_data, font_scale=1.0):
avg = accuracy_data.get("avg_delta_e", 0.0)
mx = accuracy_data.get("max_delta_e", 0.0)
panel_bg = "#1A1E24" if dark_mode else "#FFFFFF"
panel_edge = "#4A5058" if dark_mode else "#C6C6C6"
text_color = "#F3F5F7" if dark_mode else "#111111"
ax.add_patch(Rectangle(
(0.0, 0.10), 1.0, 0.80,
transform=ax.transAxes,
facecolor="#FFFFFF", edgecolor="#C6C6C6", linewidth=1.0,
facecolor=panel_bg, edgecolor=panel_edge, linewidth=1.0,
))
ax.text(
0.03, 0.50,
f"Avg dE2000: {avg:.2f}",
ha="left", va="center",
fontsize=max(11, 20 * font_scale), fontweight="normal", color="#111111",
fontsize=max(11, 20 * font_scale), fontweight="normal", color=text_color,
transform=ax.transAxes,
)
ax.text(
0.52, 0.50,
f"Max dE2000: {mx:.2f}",
ha="left", va="center",
fontsize=max(11, 20 * font_scale), fontweight="normal", color="#111111",
fontsize=max(11, 20 * font_scale), fontweight="normal", color=text_color,
transform=ax.transAxes,
)
@@ -242,6 +258,14 @@ def plot_accuracy(self: "PQAutomationApp", accuracy_data, test_type):
fig = self.accuracy_fig
fig.clear()
try:
from app.views.theme_manager import is_dark
dark_mode = is_dark()
except Exception:
dark_mode = False
fig.patch.set_facecolor("#1B1F24" if dark_mode else "#FFFFFF")
# 根据当前画布像素尺寸动态缩放字体,避免窗口缩小时文字挤压重叠。
font_scale = 1.0
try:
@@ -271,12 +295,13 @@ def plot_accuracy(self: "PQAutomationApp", accuracy_data, test_type):
else:
title = f"{test_type_name} - 色准测试(全 29色 | Gamma {target_gamma}"
title_color = "#F3F5F7" if dark_mode else "#111"
fig.suptitle(
title,
fontsize=max(8, 11 * font_scale),
y=0.975,
fontweight="bold",
color="#111",
color=title_color,
)
gs = fig.add_gridspec(
@@ -295,7 +320,13 @@ def plot_accuracy(self: "PQAutomationApp", accuracy_data, test_type):
# 兼容外部对 self.accuracy_ax 的引用
self.accuracy_ax = ax_judge
_draw_left_panel(ax_left, color_patches, delta_e_values, font_scale=font_scale)
_draw_left_panel(
ax_left,
color_patches,
delta_e_values,
font_scale=font_scale,
dark_mode=dark_mode,
)
try:
standards = get_accuracy_color_standards(test_type)
@@ -308,8 +339,14 @@ def plot_accuracy(self: "PQAutomationApp", accuracy_data, test_type):
measurements,
standards,
font_scale=font_scale,
dark_mode=dark_mode,
)
_draw_result_judgement(
ax_judge,
accuracy_data,
font_scale=font_scale,
dark_mode=dark_mode,
)
_draw_result_judgement(ax_judge, accuracy_data, font_scale=font_scale)
try:
self.update_accuracy_result_table(accuracy_data, standards)