AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(chart-import): stop projecting colors the source chart does not vary
hugohe3351041e4c99a
diff --git a/skills/ppt-master/scripts/pptx_to_svg/chart_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/chart_to_svg.pyindex 2adda271..f5f72634 100644--- a/skills/ppt-master/scripts/pptx_to_svg/chart_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/chart_to_svg.py@@ -885,8 +885,9 @@ def _series_visual_style(else:line_default = Nonestroke = _line_color(shape.line, line_default)- marker_fill = marker.shape.fill if marker.shape.fill_explicit else auto_color- marker_stroke = _line_color(marker.shape.line, auto_color)+ marker_default = (stroke or auto_color) if chart_type in {"line", "scatter"} else auto_color+ marker_fill = marker.shape.fill if marker.shape.fill_explicit else marker_default+ marker_stroke = _line_color(marker.shape.line, marker_default)line = shape.linemarker_line = marker.shape.linereturn SeriesVisualStyle(@@ -982,7 +983,8 @@ def _chart_visual_styles(raise _UnsupportedChart("unsupported-chart-series-style")styles = []for index, series in enumerate(series_nodes):- auto = _automatic_color(palette, index)+ source_index = _element_val(series.find("c:idx", C_NS))+ auto = _automatic_color(palette, int(source_index) if source_index and source_index.isdigit() else index)shape = _resolved_shape_paint(series.find("c:spPr", C_NS), palette)marker = _resolved_marker(series.find("c:marker", C_NS), palette)styles.append(@@ -1195,7 +1197,9 @@ def _normalized_chart_visual_styles(palette,),chart_type=chart_type,- auto_color=_automatic_color(palette, index),+ auto_color=_automatic_color(+ palette, int(_element_val(series.find("c:idx", C_NS)) or index),+ ),))colors = [@@ -2025,9 +2029,9 @@ def _apply_series_formatting(if chart_type == "line" and series.find("c:marker/c:size", C_NS) is not None:item["marker_size"] = _round_payload_number(visual.marker_size / 0.75)- base_color = visual.stroke if chart_type == "line" else visual.fill- if chart_type == "line" and series.find("c:marker/c:spPr/a:solidFill", C_NS) is not None:- base_color = visual.marker_fill or base_color+ base_color = visual.fill+ if chart_type == "line":+ base_color = visual.marker_fill or visual.strokeif payload.get("line_style") == "lineMarker" and base_color != visual.stroke:item["point_colors"] = [base_color] * len(item["values"])points = series.findall("c:dPt", C_NS)@@ -2057,9 +2061,12 @@ def _apply_series_formatting(if marker.symbol == "none":colors[index] = Nonesizes[index] = None- elif marker.symbol == "circle":+ elif marker.symbol == "circle" or (+ marker.symbol is None and payload.get("line_style") == "lineMarker"+ ):colors[index] = marker.shape.fill or base_color- sizes[index] = marker.size+ if marker_node is not None and marker_node.find("c:size", C_NS) is not None:+ sizes[index] = marker.sizeelse:shape = point.find("c:spPr", C_NS)paint = (@@ -2068,8 +2075,12 @@ def _apply_series_formatting(else _resolved_shape_paint(shape, palette))colors[index] = paint.fill or base_color- if chart_type == "line" or all(colors):+ vary_colors = ooxml_bool(_element_val(plot.find("c:varyColors", C_NS)), False)+ series_color = visual.stroke if chart_type == "line" else visual.fill+ if (chart_type == "line" or all(colors)) and (vary_colors or any(color != series_color for color in colors)):item["point_colors"] = colors+ else:+ item.pop("point_colors", None)if chart_type == "line":visible_sizes = {size for size in sizes if size is not None}if len(visible_sizes) == 1:@@ -2197,6 +2208,15 @@ def _apply_chart_metadata(legend_style = _source_chart_text_style(legend.find("c:txPr", C_NS), palette)if "font_size" in legend_style:payload["legend_font_size"] = legend_style["font_size"]+ if palette is not None and any(+ "font_size" in _source_chart_text_style(entry.find("c:txPr", C_NS), palette)+ for entry in legend.findall("c:legendEntry", C_NS)+ ):+ palette._diagnose(+ "chart-legend-entry-font-size-omitted",+ "Legend entry font-size overrides are outside the native chart JSON contract",+ "keep source entry typography on unchanged or data-only round-trip edits",+ )if include_plot_labels:_apply_plot_data_labels(payload, plot, palette=palette)diff --git a/skills/ppt-master/scripts/tests/test_chart_import_formatting.py b/skills/ppt-master/scripts/tests/test_chart_import_formatting.pyindex 84b601c4..a11ec461 100644--- a/skills/ppt-master/scripts/tests/test_chart_import_formatting.py+++ b/skills/ppt-master/scripts/tests/test_chart_import_formatting.py@@ -156,6 +156,75 @@ class ChartImportFormattingTests(unittest.TestCase):self.assertEqual(payload.get("axes", {}).get("category", {}).get("font_size"), 14)self.assertEqual(payload.get("axes", {}).get("value", {}).get("font_size"), 16)+ def test_identical_point_fills_do_not_enable_vary_colors(self) -> None:+ source = _source_chart()+ plot = source.find(".//c:barChart", NS)+ ET.SubElement(plot, f'{{{NS["c"]}}}varyColors', {"val": "0"})+ series = plot.find("c:ser", NS)+ paint = ET.fromstring(+ f'<c:spPr xmlns:c="{NS["c"]}" xmlns:a="{NS["a"]}">'+ '<a:solidFill><a:srgbClr val="123456"/></a:solidFill></c:spPr>'+ )+ series.append(paint)+ for index in range(2):+ point = ET.SubElement(series, f'{{{NS["c"]}}}dPt')+ ET.SubElement(point, f'{{{NS["c"]}}}idx', {"val": str(index)})+ point.append(ET.fromstring(ET.tostring(paint)))+ payload = self._import(source)+ self.assertNotIn("point_colors", payload["series"][0])+ self.assertEqual(self._export(payload).find(".//c:varyColors", NS).get("val"), "0")++ def test_line_and_marker_colors_keep_distinct_source_paints(self) -> None:+ source = self._export({+ "type": "line", "line_style": "lineMarker", "x": 100, "y": 80, "width": 600, "height": 400,+ "categories": ["A", "B"], "series": [{"name": "Line", "values": [1, 2]}],+ "style": {"colors": ["#112233"]},+ })+ series = source.find(".//c:ser", NS)+ series.find("c:marker/c:spPr/a:solidFill/a:srgbClr", NS).set("val", "FFAA00")+ series.append(ET.fromstring(+ f'<c:dPt xmlns:c="{NS["c"]}" xmlns:a="{NS["a"]}"><c:idx val="0"/>'+ '<c:marker><c:spPr><a:solidFill><a:srgbClr val="00AAFF"/></a:solidFill>'+ '</c:spPr></c:marker></c:dPt>'+ ))+ payload = self._import(source)+ self.assertEqual(payload["style"]["colors"], ["#112233"])+ self.assertEqual(payload["series"][0]["point_colors"], ["#00AAFF", "#FFAA00"])+ rebuilt = self._export(payload).find(".//c:ser", NS)+ self.assertEqual(rebuilt.find("c:spPr/a:ln/a:solidFill/a:srgbClr", NS).get("val"), "112233")+ self.assertEqual([node.get("val") for node in rebuilt.findall(+ "c:dPt/c:marker/c:spPr/a:solidFill/a:srgbClr", NS,+ )], ["00AAFF", "FFAA00"])++ def test_implicit_markers_follow_source_line_color(self) -> None:+ source = self._export({+ "type": "line", "line_style": "lineMarker", "x": 100, "y": 80, "width": 600, "height": 400,+ "categories": ["A", "B"], "series": [{"name": "Line", "values": [1, 2]}],+ "style": {"colors": ["#112233"]},+ })+ marker = source.find(".//c:ser/c:marker", NS)+ marker.remove(marker.find("c:spPr", NS))+ payload = self._import(source)+ self.assertEqual(payload["style"]["colors"], ["#112233"])+ self.assertNotIn("point_colors", payload["series"][0])++ def test_combo_colors_follow_plot_order(self) -> None:+ source = self._export({+ "type": "combo", "x": 100, "y": 80, "width": 600, "height": 400,+ "categories": ["A", "B"], "style": {"colors": ["#112233", "#445566"]},+ "plots": [+ {"type": "column", "series_indices": [1], "series": [{"name": "Bars", "values": [1, 2]}]},+ {"type": "line", "series_indices": [0], "line_style": "lineMarker",+ "series": [{"name": "Line", "values": [2, 3]}]},+ ],+ })+ payload = self._import(source)+ self.assertEqual(payload["style"]["colors"], ["#112233", "#445566"])+ rebuilt = self._export(payload)+ for plot in ("barChart", "lineChart"):+ path = f".//c:{plot}/c:ser/c:spPr/a:solidFill/a:srgbClr"+ self.assertEqual(rebuilt.find(path, NS).get("val"), source.find(path, NS).get("val"))+def test_chart_fill_title_and_inherited_axis_style(self) -> None:source = _source_chart()for axis in source.findall(".//c:catAx", NS) + source.findall(".//c:valAx", NS):