Skip to content

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(scripts): grow the native chart frame past the plot so PowerPoint keeps the manual vertical layout

hugohe346b574d3a9a6
diff --git a/skills/ppt-master/scripts/docs/native-data.md b/skills/ppt-master/scripts/docs/native-data.md
index 8efebb3a..9e1d06af 100644
--- a/skills/ppt-master/scripts/docs/native-data.md
+++ b/skills/ppt-master/scripts/docs/native-data.md
@@ -14,7 +14,7 @@ file no longer repeats. Section titles mirror the owning section of
## §2 Metadata placement and bounds
-one child `<metadata type="application/json">` (attribute `data-pptx-json` is read-compatible, not canonical); the marker's `data-pptx-replace-with` selects the schema. Provide `x`, `y`, `width`, `height` in metadata or as `data-pptx-x/y/width/height` on the group; omitted bounds are inferred from the fallback geometry (then marker/ancestor `translate` / `scale` apply), complete explicit bounds are absolute slide coordinates. `x` / `y` are finite and inside the 32-bit DrawingML range; `width` / `height` additionally resolve to at least one EMU (tables: per resolved row and column). JSON-first markers require all four bounds in metadata. Classic charts accept root `plot_area` (`x`, `y`, `width`, `height`, a positive rectangle inside the frame → `c:manualLayout`); ChartEx rejects it. `svg_quality_checker.py` validates marker kind, JSON, bounds/fallback, table rows/columns, chart type and data shape, the authority contract, and (SVG-first) baseline freshness.
+one child `<metadata type="application/json">` (attribute `data-pptx-json` is read-compatible, not canonical); the marker's `data-pptx-replace-with` selects the schema. Provide `x`, `y`, `width`, `height` in metadata or as `data-pptx-x/y/width/height` on the group; omitted bounds are inferred from the fallback geometry (then marker/ancestor `translate` / `scale` apply), complete explicit bounds are absolute slide coordinates. `x` / `y` are finite and inside the 32-bit DrawingML range; `width` / `height` additionally resolve to at least one EMU (tables: per resolved row and column). JSON-first markers require all four bounds in metadata. Classic charts accept root `plot_area` (`x`, `y`, `width`, `height`, a positive rectangle inside the frame → `c:manualLayout`; the frame grows past the plot on the side that carries tick labels until that strip is two axis-font ems tall, because PowerPoint drops the manual vertical layout when its labels do not fit and auto-fits the plot to the frame top instead); ChartEx rejects it. `svg_quality_checker.py` validates marker kind, JSON, bounds/fallback, table rows/columns, chart type and data shape, the authority contract, and (SVG-first) baseline freshness.
## §2 Table schema — `ppt-master.semantic-table.v2`
diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py
index 3c8356e5..a9fc5a1b 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/__init__.py
@@ -12,6 +12,7 @@ from xml.etree import ElementTree as ET
from pptx_shapes import validate_ooxml_xfrm
+from ..drawingml.utils import px_to_emu
from ..drawingml.context import ConvertContext, ShapeResult
from ..drawingml.utils import _xml_escape
from .chart_data import _chart_data, _chart_plot_area_layout
@@ -19,7 +20,6 @@ from .chart_style import (
_axis_titles,
_chart_companion_entries,
_chart_companion_shapes,
- _chart_text_entry,
_chart_text_sizes,
_chart_title_is_bounded,
_classic_chart_style,
@@ -57,7 +57,6 @@ from .marker_common import (
CHARTEX_CONTENT_TYPE,
CHARTEX_REL_TYPE,
CHARTEX_URI,
- _compact_key,
_load_payload,
_local_tag,
_NATIVE_KINDS,
@@ -274,73 +273,78 @@ def _source_chart_frame_xml(
return ET.tostring(frame, encoding="unicode")
-def _chart_top_strip_is_free(payload: dict[str, Any], chart_data: dict[str, Any]) -> bool:
- """Whether nothing chart-owned sits above the plot area of a bar/column chart.
+_AXIS_LABEL_MARGIN_EM = 2.0 # PowerPoint's own auto layout reserves about this much for tick labels
- Native title or subtitle, a top legend, an axis on top, tick labels at
- the high end, and column data labels (which may rise past the axis
- maximum) all claim that strip; then the frame keeps it.
- """
+
+def _vertical_label_sides(chart_data: dict[str, Any]) -> set[str]:
+ """Frame sides (top/bottom) where a classic chart draws tick labels."""
+ kind = chart_data.get("kind")
chart_type = chart_data.get("type")
- if chart_data.get("kind") != "category" or chart_type not in {"bar", "column"}:
- return False
- native_title = (
- _chart_text_entry(payload.get("title")) is not None
- and not _chart_title_is_bounded(payload)
- ) or _chart_text_entry(payload.get("subtitle")) is not None
- if native_title:
- return False
- style = payload.get("style") if isinstance(payload.get("style"), dict) else {}
- if payload.get("show_legend", style.get("show_legend", False)):
- legend_position = _compact_key(
- payload.get("legend_position") or style.get("legend_position") or "bottom"
- )
- if legend_position in {"t", "top"}:
- return False
- if chart_type == "column" and (
- chart_data.get("data_labels") is not None
- or any(item.get("data_labels") is not None for item in chart_data.get("series") or [])
- ):
- return False
+ if kind == "combo":
+ horizontal_roles = ["category"]
+ elif kind == "category" and chart_type in {"area", "column", "line"}:
+ horizontal_roles = ["category"]
+ elif kind == "category" and chart_type == "bar":
+ horizontal_roles = ["value"]
+ else:
+ return set()
axes = chart_data.get("axes") if isinstance(chart_data.get("axes"), dict) else {}
- return all(
- config.get("position") != "top" and config.get("label_position") != "high"
- for config in axes.values()
- if isinstance(config, dict)
- )
+ sides: set[str] = set()
+ for role in horizontal_roles:
+ config = axes.get(role) if isinstance(axes.get(role), dict) else {}
+ if config.get("visible") is False or config.get("label_position") == "none":
+ continue
+ if role == "value" and not chart_data.get("show_value_axis_labels", True):
+ continue
+ sides.add(str(config.get("position") or "bottom"))
+ return sides
-def _trim_chart_frame_top(
- payload: dict[str, Any],
+def _grow_chart_frame_for_axis_labels(
chart_data: dict[str, Any] | None,
bounds: tuple[int, int, int, int],
+ *,
+ axis_font_px: float,
) -> tuple[int, int, int, int]:
- """Start the chart frame at the plot area when the strip above it holds no chart chrome.
-
- PowerPoint does not reliably honour the plot area's manual vertical
- layout and auto-fits the plot to the frame top instead, which would
- drag the first bar over any companion caption drawn in that strip.
- With the frame edge on the plot edge, both layouts agree.
+ """Extend the chart frame past the plot so PowerPoint keeps the manual layout.
+
+ PowerPoint reads the plot area's manual y/h but discards them when the
+ strip between the plot edge and the frame edge cannot hold the tick
+ labels it lays out (about two em); it then auto-fits the plot to the
+ frame top and covers whatever was drawn above the plot. The frame is
+ invisible, so growing it outward on the label side costs nothing and
+ keeps the plot where the fallback drew it.
"""
off_x, off_y, ext_cx, ext_cy = bounds
if chart_data is None:
return bounds
plot_area = chart_data.get("plot_area")
- if not isinstance(plot_area, dict) or not _chart_top_strip_is_free(payload, chart_data):
+ if not isinstance(plot_area, dict):
return bounds
+ required = px_to_emu(axis_font_px * _AXIS_LABEL_MARGIN_EM)
plot_top = _powerpoint_emu(plot_area["y"], "chart plot_area.y")
- if plot_top <= off_y or plot_top >= off_y + ext_cy:
- return bounds
- return off_x, plot_top, ext_cx, ext_cy - (plot_top - off_y)
+ plot_bottom = plot_top + _powerpoint_emu(plot_area["height"], "chart plot_area.height", positive=True)
+ for side in _vertical_label_sides(chart_data):
+ if side == "bottom":
+ deficit = required - ((off_y + ext_cy) - plot_bottom)
+ if deficit > 0:
+ ext_cy += deficit
+ elif side == "top":
+ deficit = required - (plot_top - off_y)
+ if deficit > 0:
+ off_y -= deficit
+ ext_cy += deficit
+ return off_x, off_y, ext_cx, ext_cy
def _build_native_chart(elem: ET.Element, ctx: ConvertContext, payload: dict[str, Any]) -> ShapeResult:
source_package = _decode_source_chart_package(payload)
chart_data = None if source_package is not None else _chart_data(payload)
- off_x, off_y, ext_cx, ext_cy = _trim_chart_frame_top(
- payload,
+ text_sizes = _chart_text_sizes(payload, elem, ctx.inherited_styles)
+ off_x, off_y, ext_cx, ext_cy = _grow_chart_frame_for_axis_labels(
chart_data,
_bounds(elem, payload, ctx),
+ axis_font_px=text_sizes["axis"] / 75,
)
shape_id = (
diff --git a/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py b/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
index a199cd97..b9e35a82 100644
--- a/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
+++ b/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
@@ -340,40 +340,32 @@ class CompanionPlacementTests(unittest.TestCase):
self.assertIn('anchor="b"', note[:note.index("</a:bodyPr>") + 1] if "</a:bodyPr>" in note else note[:900])
-class FrameTrimTests(unittest.TestCase):
- def test_frame_top_moves_to_the_plot_when_nothing_sits_above_it(self) -> None:
- from svg_to_pptx.native_objects import _trim_chart_frame_top
-
- payload = {"type": "bar", "categories": ["A"], "series": [{"name": "S", "values": [1]}]}
- bounds = (0, 100 * 9525, 500 * 9525, 300 * 9525)
- chart_data = _chart_data({**payload, "plot_area": {"x": 50, "y": 120, "width": 400, "height": 250}})
- trimmed = _trim_chart_frame_top(payload, chart_data, bounds)
- self.assertEqual(trimmed, (0, 120 * 9525, 500 * 9525, 280 * 9525))
- titled = _trim_chart_frame_top({**payload, "title": "T"}, chart_data, bounds)
- self.assertEqual(titled, bounds)
- top_axis = _chart_data({**payload, "plot_area": {"x": 50, "y": 120, "width": 400, "height": 250},
- "axes": {"value": {"position": "top"}}})
- self.assertEqual(_trim_chart_frame_top(payload, top_axis, bounds), bounds)
-
- def test_frame_keeps_the_strip_for_subtitle_top_legend_high_labels_and_column_labels(self) -> None:
- from svg_to_pptx.native_objects import _trim_chart_frame_top
-
- base = {"type": "bar", "categories": ["A"], "series": [{"name": "S", "values": [1]}],
+class FrameGrowthTests(unittest.TestCase):
+ def test_frame_grows_below_the_plot_to_hold_value_axis_labels(self) -> None:
+ from svg_to_pptx.native_objects import _grow_chart_frame_for_axis_labels
+
+ payload = {"type": "bar", "categories": ["A"], "series": [{"name": "S", "values": [1]}],
+ "plot_area": {"x": 50, "y": 120, "width": 400, "height": 250}}
+ bounds = (0, 100 * 9525, 500 * 9525, 300 * 9525) # frame bottom 400, plot bottom 370
+ grown = _grow_chart_frame_for_axis_labels(_chart_data(payload), bounds, axis_font_px=20)
+ self.assertEqual(grown, (0, 100 * 9525, 500 * 9525, 310 * 9525)) # bottom 370 + 40
+ roomy = (0, 100 * 9525, 500 * 9525, 320 * 9525)
+ self.assertEqual(_grow_chart_frame_for_axis_labels(_chart_data(payload), roomy, axis_font_px=20), roomy)
+
+ def test_frame_grows_above_for_a_top_axis_and_not_for_hidden_labels(self) -> None:
+ from svg_to_pptx.native_objects import _grow_chart_frame_for_axis_labels
+
+ base = {"type": "column", "categories": ["A"], "series": [{"name": "S", "values": [1]}],
"plot_area": {"x": 50, "y": 120, "width": 400, "height": 250}}
- bounds = (0, 100 * 9525, 500 * 9525, 300 * 9525)
- self.assertNotEqual(_trim_chart_frame_top(base, _chart_data(base), bounds), bounds)
- for extra in (
- {"subtitle": "Native subtitle"},
- {"show_legend": True, "legend_position": "t"},
- {"axes": {"value": {"label_position": "high"}}},
- {"type": "column", "data_labels": True},
- {"type": "pie"},
- ):
- payload = {**base, **extra}
- if extra.get("type") == "pie":
- payload.pop("axes", None)
- with self.subTest(extra=extra):
- self.assertEqual(_trim_chart_frame_top(payload, _chart_data(payload), bounds), bounds)
+ bounds = (0, 100 * 9525, 500 * 9525, 300 * 9525) # plot top 120, frame top 100
+ top = _chart_data({**base, "axes": {"category": {"position": "top"}}})
+ self.assertEqual(_grow_chart_frame_for_axis_labels(top, bounds, axis_font_px=20),
+ (0, 80 * 9525, 500 * 9525, 320 * 9525))
+ hidden = _chart_data({**base, "axes": {"category": {"label_position": "none"}}})
+ self.assertEqual(_grow_chart_frame_for_axis_labels(hidden, bounds, axis_font_px=20), bounds)
+ pie = _chart_data({"type": "pie", "categories": ["A"], "series": [{"name": "S", "values": [1]}],
+ "plot_area": {"x": 50, "y": 120, "width": 400, "height": 250}})
+ self.assertEqual(_grow_chart_frame_for_axis_labels(pie, bounds, axis_font_px=20), bounds)
if __name__ == "__main__":