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): native chart frames start at the plot area when nothing chart-owned sits above it

hugohe3c3f0b1d8750b
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 97283386..175fefd9 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
@@ -47,21 +47,22 @@ from .inline_formula import (
inline_formula_marker_errors,
)
from .marker_common import (
- CHART_CONTENT_TYPE,
- CHARTEX_CONTENT_TYPE,
- CHARTEX_REL_TYPE,
- CHARTEX_URI,
+ _bounds,
CHART_COLOR_STYLE_CONTENT_TYPE,
+ CHART_CONTENT_TYPE,
CHART_REL_TYPE,
CHART_STYLE_CONTENT_TYPE,
CHART_URI,
- _NATIVE_KINDS,
- _bounds,
+ CHARTEX_CONTENT_TYPE,
+ CHARTEX_REL_TYPE,
+ CHARTEX_URI,
_load_payload,
_local_tag,
+ _NATIVE_KINDS,
+ native_marker_transform,
_native_marker_validation_context,
+ _powerpoint_emu,
_validate_bounds_inputs,
- native_marker_transform,
)
from .marker_attributes import (
JSON_NATIVE_AUTHORITY,
@@ -271,10 +272,59 @@ 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 (axis, title, legend) sits above the plot area."""
+ if chart_data.get("kind") not in {"category", "combo"}:
+ return False
+ if payload.get("title") is not None and not _chart_title_is_bounded(payload):
+ 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 = str(
+ payload.get("legend_position", style.get("legend_position", "bottom"))
+ ).strip().lower()
+ if legend_position == "top":
+ return False
+ axes = chart_data.get("axes") if isinstance(chart_data.get("axes"), dict) else {}
+ return all(
+ config.get("position") != "top"
+ for config in axes.values()
+ if isinstance(config, dict)
+ )
+
+
+def _trim_chart_frame_top(
+ payload: dict[str, Any],
+ chart_data: dict[str, Any] | None,
+ bounds: tuple[int, int, int, int],
+) -> 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.
+ """
+ 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):
+ return bounds
+ 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)
+
+
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 = _bounds(elem, payload, ctx)
+ off_x, off_y, ext_cx, ext_cy = _trim_chart_frame_top(
+ payload,
+ chart_data,
+ _bounds(elem, payload, ctx),
+ )
shape_id = (
ctx.claim_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 93b87ca2..bd389d3d 100644
--- a/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
+++ b/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
@@ -340,5 +340,21 @@ 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)
+
+
if __name__ == "__main__":
unittest.main()