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): frame-top trimming applies to bar/column only and keeps the strip for subtitles, top legends, high labels, column data labels

hugohe341ad20d141bd
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 175fefd9..3c8356e5 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
@@ -19,6 +19,7 @@ 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,
@@ -56,6 +57,7 @@ from .marker_common import (
CHARTEX_CONTENT_TYPE,
CHARTEX_REL_TYPE,
CHARTEX_URI,
+ _compact_key,
_load_payload,
_local_tag,
_NATIVE_KINDS,
@@ -273,21 +275,36 @@ def _source_chart_frame_xml(
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"}:
+ """Whether nothing chart-owned sits above the plot area of a bar/column chart.
+
+ 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.
+ """
+ chart_type = chart_data.get("type")
+ if chart_data.get("kind") != "category" or chart_type not in {"bar", "column"}:
return False
- if payload.get("title") is not None and not _chart_title_is_bounded(payload):
+ 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 = str(
- payload.get("legend_position", style.get("legend_position", "bottom"))
- ).strip().lower()
- if legend_position == "top":
+ 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
axes = chart_data.get("axes") if isinstance(chart_data.get("axes"), dict) else {}
return all(
- config.get("position") != "top"
+ config.get("position") != "top" and config.get("label_position") != "high"
for config in axes.values()
if isinstance(config, dict)
)
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 bd389d3d..a199cd97 100644
--- a/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
+++ b/skills/ppt-master/scripts/tests/test_native_chart_fidelity.py
@@ -355,6 +355,26 @@ class FrameTrimTests(unittest.TestCase):
"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]}],
+ "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)
+
if __name__ == "__main__":
unittest.main()