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
feat(pptx-objects): preserve XY chart axis semantics
hugohe346f8b0ffb434
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 2027ffef..abfacd75 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@@ -180,8 +180,10 @@ def _payload_from_chart_xml()elif chart_tag == "scatterChart":payload = _xy_payload(chart, "scatter", xfrm)+ payload["axes"] = _xy_axis_contract(plot_area, chart)elif chart_tag == "bubbleChart":payload = _xy_payload(chart, "bubble", xfrm)+ payload["axes"] = _xy_axis_contract(plot_area, chart)elif chart_tag == "stockChart":payload, visual_styles = _stock_payload(chart_root,@@ -213,7 +215,9 @@ def _payload_from_chart_xml(plot_area,chart,palette=palette,- validate_axes=not has_date_axis,+ validate_axes=not (+ has_date_axis or chart_tag in {"bubbleChart", "scatterChart"}+ ),)_apply_chart_metadata(payload, chart_root, plot_area, chart)return payload, visual_styles@@ -1110,6 +1114,10 @@ def _axis_config_from_xml(if position not in {"bottom", "top"}:raise _UnsupportedChart("unsupported-chart-axis-options")config["kind"] = "date" if axis_kind == "dateAx" else "text"+ elif role == "x":+ if position not in {"bottom", "top"} or axis_kind != "valAx":+ raise _UnsupportedChart("unsupported-chart-axis-options")+ config["kind"] = "value"else:if position not in {"left", "right"} or axis_kind != "valAx":raise _UnsupportedChart("unsupported-chart-axis-options")@@ -1140,7 +1148,7 @@ def _axis_config_from_xml(major_unit = _axis_number(axis.find("c:majorUnit", C_NS))if major_unit is not None:- if role not in {"value", "secondary_value"} or major_unit <= 0:+ if role not in {"value", "secondary_value", "x", "y"} or major_unit <= 0:raise _UnsupportedChart("unsupported-chart-axis-options")config["major_unit"] = major_unit@@ -1212,6 +1220,67 @@ def _single_axis_contract(return {"category": category, "value": value}+def _xy_axis_contract(+ plot_area: ET.Element,+ plot: ET.Element,+) -> dict[str, dict[str, Any]]:+ """Return the closed two-value-axis contract used by XY charts."""+ axes_by_id = _axis_nodes_by_id(plot_area)+ plot_axis_nodes = plot.findall("c:axId", C_NS)+ if len(plot_axis_nodes) != 2 or any(+ set(node.attrib) != {"val"} or list(node)+ for node in plot_axis_nodes+ ):+ raise _UnsupportedChart("unsupported-chart-axis-options")+ axis_ids = [_element_val(node) for node in plot_axis_nodes]+ if any(not axis_id for axis_id in axis_ids) or len(set(axis_ids)) != 2:+ raise _UnsupportedChart("unsupported-chart-axis-options")+ if set(axes_by_id) != set(axis_ids):+ raise _UnsupportedChart("unsupported-chart-axis-options")++ resolved = [+ (str(axis_id), axes_by_id.get(str(axis_id)))+ for axis_id in axis_ids+ ]+ if any(+ axis is None or _local_name(axis.tag) != "valAx"+ for _, axis in resolved+ ):+ raise _UnsupportedChart("unsupported-chart-axis-options")+ horizontal = [+ (axis_id, axis)+ for axis_id, axis in resolved+ if axis is not None+ and _element_val(axis.find("c:axPos", C_NS)) in {"b", "t"}+ ]+ vertical = [+ (axis_id, axis)+ for axis_id, axis in resolved+ if axis is not None+ and _element_val(axis.find("c:axPos", C_NS)) in {"l", "r"}+ ]+ if len(horizontal) != 1 or len(vertical) != 1:+ raise _UnsupportedChart("unsupported-chart-axis-options")++ x_id, x_axis = horizontal[0]+ y_id, y_axis = vertical[0]+ x_config = _axis_config_from_xml(+ x_axis,+ role="x",+ expected_cross_axis_id=y_id,+ allowed_crosses={"autoZero"},+ expected_cross_between="midCat",+ )+ y_config = _axis_config_from_xml(+ y_axis,+ role="y",+ expected_cross_axis_id=x_id,+ allowed_crosses={"autoZero"},+ expected_cross_between="midCat",+ )+ return {"x": x_config, "y": y_config}++def _validate_legacy_axes(payload: dict[str, Any], plot_area: ET.Element) -> None:"""Keep the original narrow axis gate for payloads without axes metadata."""grouping = payload.get("grouping")@@ -1270,6 +1339,88 @@ def _validate_legacy_axes(payload: dict[str, Any], plot_area: ET.Element) -> Nonraise _UnsupportedChart("unsupported-chart-axis-options")+def _effective_scatter_style(+ plot: ET.Element,+ visual_styles: list[SeriesVisualStyle],+) -> str:+ """Normalize plot-level line intent plus uniform series overrides."""+ style_nodes = plot.findall("c:scatterStyle", C_NS)+ if len(style_nodes) > 1:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ style_node = style_nodes[0] if style_nodes else None+ if style_node is not None and (+ set(style_node.attrib) != {"val"} or list(style_node)+ ):+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ plot_style = _element_val(style_node) or "marker"+ if plot_style not in {"line", "lineMarker", "marker", "smooth", "smoothMarker"}:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ plot_has_line = plot_style in {"line", "lineMarker", "smooth", "smoothMarker"}+ plot_is_smooth = plot_style in {"smooth", "smoothMarker"}++ style_by_state = {+ (False, True, False): "marker",+ (True, False, False): "line",+ (True, True, False): "lineMarker",+ (True, False, True): "smooth",+ (True, True, True): "smoothMarker",+ }+ effective_styles: set[str] = set()+ series_nodes = plot.findall("c:ser", C_NS)+ if len(series_nodes) != len(visual_styles):+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ for series, visual_style in zip(series_nodes, visual_styles):+ line_node = series.find("c:spPr/a:ln", C_NS)+ has_line = plot_has_line if line_node is None else (+ visual_style.stroke is not None+ and visual_style.stroke_opacity > 0+ )+ markers = series.findall("c:marker", C_NS)+ if len(markers) != 1:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ marker = markers[0]+ symbol = marker.find("c:symbol", C_NS) if marker is not None else None+ if (+ marker is None+ or symbol is None+ or set(symbol.attrib) != {"val"}+ or list(symbol)+ ):+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ symbol_value = _element_val(symbol)+ if symbol_value not in {"circle", "none"}:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ has_marker = symbol_value == "circle"++ smooth_nodes = series.findall("c:smooth", C_NS)+ if len(smooth_nodes) > 1:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ smooth = smooth_nodes[0] if smooth_nodes else None+ is_smooth = plot_is_smooth+ if smooth is not None:+ if not set(smooth.attrib).issubset({"val"}) or list(smooth):+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ raw_smooth = smooth.attrib.get("val")+ key = raw_smooth.strip().lower() if raw_smooth is not None else "true"+ if key in {"1", "on", "true"}:+ is_smooth = True+ elif key in {"0", "false", "off"}:+ is_smooth = False+ else:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ if is_smooth and not has_line:+ raise _UnsupportedChart("unsupported-chart-scatter-style")++ effective_style = style_by_state.get((has_line, has_marker, is_smooth))+ if effective_style is None:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ effective_styles.add(effective_style)++ if len(effective_styles) != 1:+ raise _UnsupportedChart("unsupported-chart-scatter-style")+ return effective_styles.pop()++def _validate_chart_semantics(payload: dict[str, Any],plot_area: ET.Element,@@ -1355,26 +1506,7 @@ def _validate_chart_semantics(raise _UnsupportedChart("unsupported-chart-bubble-options")if chart_type == "scatter":- scatter_style = _element_val(plot.find("c:scatterStyle", C_NS)) or "marker"- expected_marker = (- "circle"- if scatter_style in {"lineMarker", "marker", "smoothMarker"}- else "none"- )- expected_smooth = scatter_style in {"smooth", "smoothMarker"}- for series in plot.findall("c:ser", C_NS):- marker = series.find("c:marker", C_NS)- if marker is None:- raise _UnsupportedChart("unsupported-chart-scatter-style")- symbol = _element_val(marker.find("c:symbol", C_NS))- if symbol != expected_marker:- raise _UnsupportedChart("unsupported-chart-scatter-style")- smooth = series.find("c:smooth", C_NS)- actual_smooth = bool(- smooth is not None and ooxml_bool(smooth.attrib.get("val"), True)- )- if actual_smooth != expected_smooth:- raise _UnsupportedChart("unsupported-chart-scatter-style")+ payload["scatter_style"] = _effective_scatter_style(plot, visual_styles)if chart_type in {"pie", "doughnut", "of_pie"}:for explosion in plot.findall(".//c:explosion", C_NS):@@ -1898,10 +2030,6 @@ def _xy_payload(chart: ET.Element, chart_type: str, xfrm: Xfrm) -> dict[str, Any"series": series,"type": chart_type,}- if chart_type == "scatter":- style = _element_val(chart.find("c:scatterStyle", C_NS))- if style:- payload["scatter_style"] = stylereturn payloaddiff --git a/skills/ppt-master/scripts/pptx_to_svg/normalized_chart_svg.py b/skills/ppt-master/scripts/pptx_to_svg/normalized_chart_svg.pyindex afaabd70..f4065dbc 100644--- a/skills/ppt-master/scripts/pptx_to_svg/normalized_chart_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/normalized_chart_svg.py@@ -641,7 +641,31 @@ def _render_xy(y_values = [float(value) for item in series for value in item.get("y") or []]x_lo, x_hi, x_ticks = _nice_scale(x_values, include_zero=False)y_lo, y_hi, y_ticks = _nice_scale(y_values, include_zero=False)- parts = _xy_grid_and_ticks(plot, x_ticks, y_ticks, x_lo, x_hi, y_lo, y_hi, label_size)+ axes = payload.get("axes")+ x_axis = axes.get("x") if isinstance(axes, dict) else None+ y_axis = axes.get("y") if isinstance(axes, dict) else None+ x_major_gridlines = (+ bool(x_axis.get("major_gridlines", False))+ if isinstance(x_axis, dict)+ else False+ )+ y_major_gridlines = (+ bool(y_axis.get("major_gridlines", True))+ if isinstance(y_axis, dict)+ else True+ )+ parts = _xy_grid_and_ticks(+ plot,+ x_ticks,+ y_ticks,+ x_lo,+ x_hi,+ y_lo,+ y_hi,+ label_size,+ show_x_gridlines=x_major_gridlines,+ show_y_gridlines=y_major_gridlines,+ )parts.extend(_xy_axis_titles(plot, content, axis_titles, label_size))nonnegative_bubble_sizes = [float(value)@@ -707,14 +731,16 @@ def _vertical_grid_and_ticks(percent: bool,*,show_labels: bool,+ show_gridlines: bool = True,) -> list[str]:parts: list[str] = []for tick in ticks:y = _map(tick, lo, hi, plot.y + plot.h, plot.y)- parts.append(- f'<line x1="{_fmt(plot.x)}" y1="{_fmt(y)}" x2="{_fmt(plot.x + plot.w)}" '- f'y2="{_fmt(y)}" stroke="#D9D9D9" stroke-width="0.7"/>'- )+ if show_gridlines:+ parts.append(+ f'<line x1="{_fmt(plot.x)}" y1="{_fmt(y)}" x2="{_fmt(plot.x + plot.w)}" '+ f'y2="{_fmt(y)}" stroke="#D9D9D9" stroke-width="0.7"/>'+ )if show_labels:label = _format_percent(tick) if percent else _format_number(tick)parts.append(_text(plot.x - 5.0, y + size * 0.32, label, size=size, anchor="end", fill="#666666"))@@ -810,6 +836,9 @@ def _xy_grid_and_ticks(y_lo: float,y_hi: float,size: float,+ *,+ show_x_gridlines: bool,+ show_y_gridlines: bool,) -> list[str]:parts = _vertical_grid_and_ticks(plot,@@ -819,9 +848,15 @@ def _xy_grid_and_ticks(size,False,show_labels=True,+ show_gridlines=show_y_gridlines,)for tick in x_ticks:x = _map(tick, x_lo, x_hi, plot.x, plot.x + plot.w)+ if show_x_gridlines:+ parts.append(+ f'<line x1="{_fmt(x)}" y1="{_fmt(plot.y)}" x2="{_fmt(x)}" '+ f'y2="{_fmt(plot.y + plot.h)}" stroke="#D9D9D9" stroke-width="0.7"/>'+ )parts.append(_text(x, plot.y + plot.h + size + 4.0, _format_number(tick), size=size, anchor="middle", fill="#666666"))parts.append(f'<line x1="{_fmt(plot.x)}" y1="{_fmt(plot.y + plot.h)}" 'diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_data.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_data.pyindex 83cd227d..92c42992 100644--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_data.py+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_data.py@@ -227,6 +227,8 @@ _AXIS_ROLE_DEFAULTS = {"secondary_category": ("text", "bottom"),"secondary_value": ("value", "right"),"value": ("value", "left"),+ "x": ("value", "bottom"),+ "y": ("value", "left"),}@@ -269,7 +271,7 @@ def _chart_axes()if role in {"category", "secondary_category"} and kind not in {"date", "text"}:raise RuntimeError(f"Native PPTX chart axes.{role}.kind must be date or text")- if role in {"value", "secondary_value"} and kind != "value":+ if role in {"value", "secondary_value", "x", "y"} and kind != "value":raise RuntimeError(f"Native PPTX chart axes.{role}.kind must be value")position_aliases = {@@ -291,7 +293,7 @@ def _chart_axes()allowed_positions = ({"bottom", "top"}- if role in {"category", "secondary_category"}+ if role in {"category", "secondary_category", "x"}else {"left", "right"})if position not in allowed_positions:@@ -345,7 +347,7 @@ def _chart_axes(continuenumber = _chart_number(value)if field == "major_unit":- if role not in {"value", "secondary_value"}:+ if role not in {"value", "secondary_value", "x", "y"}:raise RuntimeError(f"Native PPTX chart axes.{role}.major_unit is unsupported")@@ -1207,6 +1209,7 @@ def _xy_chart_data(raise RuntimeError(f"Native PPTX {chart_type} chart data labels are outside current support")+ axes = _chart_axes(payload, {"x", "y"})raw_series = payload.get("series", [])if not isinstance(raw_series, list) or not raw_series:raise RuntimeError("Native PPTX XY chart requires non-empty series")@@ -1262,6 +1265,7 @@ def _xy_chart_data(if chart_type == "scatter" and scatter_style not in style_aliases:raise RuntimeError("Native PPTX scatter_style is unsupported")return {+ "axes": axes,"kind": "xy","type": chart_type,"scatter_style": style_aliases.get(scatter_style, "marker"),diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_xml.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_xml.pyindex b21dc825..12cadb4c 100644--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_xml.py+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/chart_xml.py@@ -966,6 +966,7 @@ def _chart_plot_xml(axis_title_font_size=axis_title_font_size,axis_titles=axis_titles,chart_style=chart_style,+ axes=chart_data.get("axes") or {},)return (f'<c:scatterChart><c:scatterStyle val="{scatter_style}"/>'@@ -982,6 +983,7 @@ def _chart_plot_xml(axis_title_font_size=axis_title_font_size,axis_titles=axis_titles,chart_style=chart_style,+ axes=chart_data.get("axes") or {},)return ('<c:bubbleChart><c:varyColors val="0"/>'@@ -1209,7 +1211,11 @@ def _xy_axis_xml(axis_title_font_size: int,axis_titles: dict[str, Any],chart_style: dict[str, str | None],+ axes: dict[str, dict[str, Any]] | None = None,) -> str:+ normalized_axes = axes or {}+ x_axis = normalized_axes.get("x", {})+ y_axis = normalized_axes.get("y", {})axis_sp_pr = _chart_line_sp_pr_xml(chart_style.get("axis_color"))axis_tx_pr = _chart_tx_pr_xml(axis_font_size,@@ -1228,24 +1234,56 @@ def _xy_axis_xml(color=chart_style.get("text_color"),font_face=chart_style.get("font_face"),)- return (- "<c:valAx>"- f'<c:axId val="{x_ax_id}"/><c:scaling><c:orientation val="minMax"/></c:scaling>'- f'<c:delete val="0"/><c:axPos val="b"/>{x_title_xml}<c:majorTickMark val="out"/>'- '<c:minorTickMark val="none"/><c:tickLblPos val="nextTo"/>'- f"{axis_sp_pr}{axis_tx_pr}"- f'<c:crossAx val="{y_ax_id}"/><c:crosses val="autoZero"/>'- '<c:crossBetween val="midCat"/>'- "</c:valAx>"- "<c:valAx>"- f'<c:axId val="{y_ax_id}"/><c:scaling><c:orientation val="minMax"/></c:scaling>'- f'<c:delete val="0"/><c:axPos val="l"/>{_major_gridlines_xml(chart_style.get("grid_color"))}'- f'{y_title_xml}<c:majorTickMark val="out"/><c:minorTickMark val="none"/>'- '<c:tickLblPos val="nextTo"/>'- f"{axis_sp_pr}{axis_tx_pr}"- f'<c:crossAx val="{x_ax_id}"/><c:crosses val="autoZero"/>'- '<c:crossBetween val="midCat"/>'- "</c:valAx>"++ def value_axis_xml(+ axis_id: str,+ cross_axis_id: str,+ config: dict[str, Any],+ *,+ default_position: str,+ default_gridlines: bool,+ title_xml: str,+ ) -> str:+ delete = _bool_attr(not config.get("visible", True))+ position = _axis_position(config, default_position)+ gridlines = _axis_major_gridlines_xml(+ config,+ default=default_gridlines,+ color=chart_style.get("grid_color"),+ )+ number_format = _axis_number_format_xml(config)+ tick_label_position = _axis_label_position(config, "nextTo")+ major_unit = (+ f'<c:majorUnit val="{config["major_unit"]}"/>'+ if config.get("major_unit") is not None else ""+ )+ return (+ "<c:valAx>"+ f'<c:axId val="{axis_id}"/>{_axis_scaling_xml(config)}'+ f'<c:delete val="{delete}"/><c:axPos val="{position}"/>'+ f"{gridlines}{title_xml}{number_format}"+ '<c:majorTickMark val="out"/><c:minorTickMark val="none"/>'+ f'<c:tickLblPos val="{tick_label_position}"/>'+ f"{axis_sp_pr}{axis_tx_pr}"+ f'<c:crossAx val="{cross_axis_id}"/><c:crosses val="autoZero"/>'+ f'<c:crossBetween val="midCat"/>{major_unit}'+ "</c:valAx>"+ )++ return value_axis_xml(+ x_ax_id,+ y_ax_id,+ x_axis,+ default_position="b",+ default_gridlines=False,+ title_xml=x_title_xml,+ ) + value_axis_xml(+ y_ax_id,+ x_ax_id,+ y_axis,+ default_position="l",+ default_gridlines=True,+ title_xml=y_title_xml,)