Resolves Display Issues with Pie Charts and Line Charts When Exporting to PDF
Showing
1 changed file
with
13 additions
and
1 deletions
| @@ -155,7 +155,7 @@ class ChartToSVGConverter: | @@ -155,7 +155,7 @@ class ChartToSVGConverter: | ||
| 155 | 解析颜色值,将CSS格式转换为matplotlib支持的格式 | 155 | 解析颜色值,将CSS格式转换为matplotlib支持的格式 |
| 156 | 156 | ||
| 157 | 参数: | 157 | 参数: |
| 158 | - color: 颜色值(可能是CSS格式如rgba()或十六进制) | 158 | + color: 颜色值(可能是CSS格式如rgba()或十六进制或CSS变量) |
| 159 | 159 | ||
| 160 | 返回: | 160 | 返回: |
| 161 | str: matplotlib支持的颜色格式 | 161 | str: matplotlib支持的颜色格式 |
| @@ -165,6 +165,12 @@ class ChartToSVGConverter: | @@ -165,6 +165,12 @@ class ChartToSVGConverter: | ||
| 165 | 165 | ||
| 166 | color = color.strip() | 166 | color = color.strip() |
| 167 | 167 | ||
| 168 | + # 【修复】处理CSS变量,例如 var(--color-accent) | ||
| 169 | + # 使用默认颜色替代CSS变量 | ||
| 170 | + if color.startswith('var('): | ||
| 171 | + # 返回默认的蓝色 | ||
| 172 | + return '#36A2EB' | ||
| 173 | + | ||
| 168 | # 处理rgba(r, g, b, a)格式 | 174 | # 处理rgba(r, g, b, a)格式 |
| 169 | rgba_pattern = r'rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)' | 175 | rgba_pattern = r'rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)' |
| 170 | match = re.match(rgba_pattern, color) | 176 | match = re.match(rgba_pattern, color) |
| @@ -367,6 +373,9 @@ class ChartToSVGConverter: | @@ -367,6 +373,9 @@ class ChartToSVGConverter: | ||
| 367 | if not isinstance(colors, list): | 373 | if not isinstance(colors, list): |
| 368 | colors = self.DEFAULT_COLORS[:len(labels)] | 374 | colors = self.DEFAULT_COLORS[:len(labels)] |
| 369 | 375 | ||
| 376 | + # 【修复】解析每个颜色,将CSS格式转换为matplotlib格式 | ||
| 377 | + colors = [self._parse_color(c) for c in colors] | ||
| 378 | + | ||
| 370 | # 绘制饼图 | 379 | # 绘制饼图 |
| 371 | wedges, texts, autotexts = ax.pie( | 380 | wedges, texts, autotexts = ax.pie( |
| 372 | dataset_data, | 381 | dataset_data, |
| @@ -418,6 +427,9 @@ class ChartToSVGConverter: | @@ -418,6 +427,9 @@ class ChartToSVGConverter: | ||
| 418 | if not isinstance(colors, list): | 427 | if not isinstance(colors, list): |
| 419 | colors = self.DEFAULT_COLORS[:len(labels)] | 428 | colors = self.DEFAULT_COLORS[:len(labels)] |
| 420 | 429 | ||
| 430 | + # 【修复】解析每个颜色,将CSS格式转换为matplotlib格式 | ||
| 431 | + colors = [self._parse_color(c) for c in colors] | ||
| 432 | + | ||
| 421 | # 绘制圆环图(通过设置wedgeprops实现中空效果) | 433 | # 绘制圆环图(通过设置wedgeprops实现中空效果) |
| 422 | wedges, texts, autotexts = ax.pie( | 434 | wedges, texts, autotexts = ax.pie( |
| 423 | dataset_data, | 435 | dataset_data, |
-
Please register or login to post a comment