Resolves Display Issues with Pie Charts and Line Charts When Exporting to PDF

This commit is contained in:
马一丁
2025-11-19 16:12:43 +08:00
parent bd0aa987ad
commit cafde07233
+13 -1
View File
@@ -155,7 +155,7 @@ class ChartToSVGConverter:
解析颜色值,将CSS格式转换为matplotlib支持的格式 解析颜色值,将CSS格式转换为matplotlib支持的格式
参数: 参数:
color: 颜色值(可能是CSS格式如rgba()或十六进制) color: 颜色值(可能是CSS格式如rgba()或十六进制或CSS变量
返回: 返回:
str: matplotlib支持的颜色格式 str: matplotlib支持的颜色格式
@@ -165,6 +165,12 @@ class ChartToSVGConverter:
color = color.strip() color = color.strip()
# 【修复】处理CSS变量,例如 var(--color-accent)
# 使用默认颜色替代CSS变量
if color.startswith('var('):
# 返回默认的蓝色
return '#36A2EB'
# 处理rgba(r, g, b, a)格式 # 处理rgba(r, g, b, a)格式
rgba_pattern = r'rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)' rgba_pattern = r'rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)'
match = re.match(rgba_pattern, color) match = re.match(rgba_pattern, color)
@@ -367,6 +373,9 @@ class ChartToSVGConverter:
if not isinstance(colors, list): if not isinstance(colors, list):
colors = self.DEFAULT_COLORS[:len(labels)] colors = self.DEFAULT_COLORS[:len(labels)]
# 【修复】解析每个颜色,将CSS格式转换为matplotlib格式
colors = [self._parse_color(c) for c in colors]
# 绘制饼图 # 绘制饼图
wedges, texts, autotexts = ax.pie( wedges, texts, autotexts = ax.pie(
dataset_data, dataset_data,
@@ -418,6 +427,9 @@ class ChartToSVGConverter:
if not isinstance(colors, list): if not isinstance(colors, list):
colors = self.DEFAULT_COLORS[:len(labels)] colors = self.DEFAULT_COLORS[:len(labels)]
# 【修复】解析每个颜色,将CSS格式转换为matplotlib格式
colors = [self._parse_color(c) for c in colors]
# 绘制圆环图(通过设置wedgeprops实现中空效果) # 绘制圆环图(通过设置wedgeprops实现中空效果)
wedges, texts, autotexts = ax.pie( wedges, texts, autotexts = ax.pie(
dataset_data, dataset_data,