Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ Under an Upgrading section, the bullets after **Local installs (`sdpm update`).*

## [Unreleased]

### Added

- **Area charts** (`chartType: "area"`, #620). An area chart takes the same categories and
series as a bar chart; `stacked: true` stacks the areas, and series `color`, `valueAxis`,
`categoryAxis`, `style`, `legend` and `dataLabels` work as for `bar`. `pptx_to_json`
reads an area or stacked area chart back as `area`, so an edited one is rebuilt from its
JSON; a 100% stacked area chart still keeps its `_chartXml`. New `chart-area` guide.
Local mode and the AWS stack (SdpmRuntime).

### Fixed

- **Moving between Decks, Styles and Templates no longer flashes the screen.** The rail and
Expand Down
77 changes: 77 additions & 0 deletions sdpm/references/guides/chart-area.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
description: "Area chart JSON structure and style overrides — read when slide contains area or stacked area chart"
---

Area charts for volume over time and stacked share of a total.

## Use cases
- Cumulative or stacked volume over time (requests, active users, cost by service)
- Part-to-whole trends across time periods
- Emphasizing magnitude of change alongside trend direction

## Design points
- `stacked: false` (default) for overlapping areas; `stacked: true` for stacked area charts
- Use `stacked: true` when showing how components add up to a total
- Keep series ordered with the largest or most stable component at the bottom

**Constraints:**
- You SHOULD keep to 2–5 series because stacked layers become hard to compare past 5
- You SHOULD NOT use unstacked areas with more than 2 series because front series hide back series

## Style-adjustable properties
- `gridlineColor`, `gridlineWidth`, `gridlineDash`: gridlines
- `axisColor`, `axisWidth`: axis lines
- `fontColor`, `fontSize`: text
- `legendPosition`: legend position (bottom/right/left/top)

These can be set as a `style` object:
```json
"style": {
"gridlineColor": "#E0E0E0", "gridlineWidth": 0.25, "gridlineDash": "dash",
"fontColor": "#333333", "fontSize": 10, "legendPosition": "bottom"
}
```

## Axis control

```json
"valueAxis": {"min": 0, "max": 500, "majorUnit": 100, "gridlines": true, "line": "none", "tickMark": "none"},
"categoryAxis": {"tickMark": "none"}
```

## Additional properties

- `title`: chart title text
- `titleFontSize`: title font size (default: 14)
- `titleFontColor`: title color
- `numberFormat`: data label format (e.g. `"#,##0"`)

## JSON: Stacked area chart

(Example coordinates assume 16:9 canvas H=1080. Adjust y/height for other ratios.)

```json
{
"slides": [
{
"layout": "content",
"title": "Monthly Compute Usage",
"elements": [
{
"type": "chart",
"chartType": "area",
"stacked": true,
"x": 192, "y": 216, "width": 1536, "height": 700,
"categories": ["Jan", "Feb", "Mar", "Apr"],
"series": [
{"name": "Lambda", "values": [120, 150, 180, 210], "color": "#FF9900"},
{"name": "ECS", "values": [80, 95, 90, 130], "color": "#41B3FF"}
],
"legend": true,
"dataLabels": false
}
]
}
]
}
```
7 changes: 4 additions & 3 deletions sdpm/references/guides/slide-json-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Native PPTX chart (editable in PowerPoint).
```json
{
"type": "chart",
"chartType": "bar|line|pie|donut|radar",
"chartType": "bar|line|pie|donut|radar|area",
"x": 192, "y": 216, "width": 1536, "height": 700,
"categories": ["A", "B", "C"],
"series": [{"name": "Series 1", "values": [10, 20, 30], "color": "#FF9900"}],
Expand All @@ -107,14 +107,15 @@ Native PPTX chart (editable in PowerPoint).
}
```

- `chartType`: `bar`, `line`, `pie`, `donut`, `radar`
- `chartType`: `bar`, `line`, `pie`, `donut`, `radar`, `area`
- Colors, gridlines, and fonts are auto-adjusted from the theme
- `stacked`/`horizontal`: bar variations. `smooth`/`markers`: line variations (`markers` also for radar). `holeSize`: donut only
- `stacked`: bar and area variations. `horizontal`: bar only. `smooth`/`markers`: line variations (`markers` also for radar). `holeSize`: donut only
- For details, variations, axis control, and style overrides, read the relevant guide:
- `read_guides(["chart-bar"])` — bar/column charts
- `read_guides(["chart-line"])` — line/trend charts
- `read_guides(["chart-pie"])` — pie/donut charts
- `read_guides(["chart-radar"])` — radar/spider charts
- `read_guides(["chart-area"])` — area/stacked area charts

## freeform
```json
Expand Down
2 changes: 1 addition & 1 deletion sdpm/references/guides/slide-json-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,5 @@ Each element type's fields are in a guide that `read_guides` returns:
textboxes and images
- `visual-forms` — when to draw a form, icon use and sizes, and the geometry of flow, cycle,
hub, hierarchy, matrix, timeline, progress and the other forms
- `table`, `chart-bar` / `chart-line` / `chart-pie` / `chart-radar`, `freeform` — the full references of those
- `table`, `chart-bar` / `chart-line` / `chart-pie` / `chart-radar` / `chart-area`, `freeform` — the full references of those
elements
2 changes: 1 addition & 1 deletion sdpm/references/workflows/composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ labels and notes follow it.
style spec — use it for rectangular arrangements instead of hand-placing; compute
non-rectangular positions (arcs, radial, curves) yourself.
- Guides exist for specific needs, load only when a slide calls for one:
`grid`, `table`, `chart-bar` / `chart-line` / `chart-pie` / `chart-radar`, `freeform`,
`grid`, `table`, `chart-bar` / `chart-line` / `chart-pie` / `chart-radar` / `chart-area`, `freeform`,
`arch-layout-engine` + `arch-elements` (architecture diagrams via `arch_diagram`),
`design-rules`.
- Slugs sharing a prefix (`demo-1`, `demo-2`) are one override group: later slides inherit
Expand Down
2 changes: 2 additions & 0 deletions sdpm/sdpm/engine/builder/elements/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def _add_chart(self, slide, elem):
("pie", False, False): XL_CHART_TYPE.PIE,
("donut", False, False): XL_CHART_TYPE.DOUGHNUT,
("radar", False, False): XL_CHART_TYPE.RADAR_MARKERS if markers else XL_CHART_TYPE.RADAR,
("area", False, False): XL_CHART_TYPE.AREA,
("area", True, False): XL_CHART_TYPE.AREA_STACKED,
}
xl_type = type_map.get((chart_type, stacked, horizontal))
if xl_type is None:
Expand Down
6 changes: 4 additions & 2 deletions sdpm/sdpm/engine/converter/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def extract_chart_element(shape, theme_colors=None, color_mapping=None):
XL_CHART_TYPE.DOUGHNUT: ("donut", False, False),
XL_CHART_TYPE.RADAR: ("radar", False, False),
XL_CHART_TYPE.RADAR_MARKERS: ("radar", False, False),
XL_CHART_TYPE.AREA: ("area", False, False),
XL_CHART_TYPE.AREA_STACKED: ("area", True, False),
}
chart_type, stacked, horizontal = type_map.get(ct, ("bar", False, False))
# The builder can make this chart again from its JSON only when chartType
# describes it: one plot of a mapped type. Anything else (area, filled radar,
# describes it: one plot of a mapped type. Anything else (filled radar,
# 100% stacked, combo charts…) is read as a bar chart and only _chartXml keeps it.
rebuildable = ct in type_map and len(chart.plots) == 1
elem["chartType"] = chart_type
Expand Down Expand Up @@ -98,7 +100,7 @@ def extract_chart_element(shape, theme_colors=None, color_mapping=None):
s["values"] = []
# Extract color (solid or gradient fallback)
try:
if chart_type in ("bar",):
if chart_type in ("bar", "area"):
rgb = series.format.fill.fore_color.rgb
s["color"] = f"#{rgb}"
elif chart_type == "line":
Expand Down
8 changes: 4 additions & 4 deletions sdpm/sdpm/engine/schema/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ def _lint_image(si: int, ei: int, elem: dict) -> list[dict]:
# chart
# ===================================================================

_CHART_TYPES = {"bar", "line", "pie", "donut", "radar"}
_CHART_TYPES = {"bar", "line", "pie", "donut", "radar", "area"}


def _lint_chart(si: int, ei: int, elem: dict) -> list[dict]:
results: list[dict] = []
ct = elem.get("chartType")
if ct is None:
results.append(_diag(si, ei, "chart-missing-chartType",
"chart element has no 'chartType'. Specify bar, line, pie, donut, or radar."))
"chart element has no 'chartType'. Specify bar, line, pie, donut, radar, or area."))
elif ct not in _CHART_TYPES:
results.append(_diag(si, ei, "chart-invalid-chartType",
f"chartType '{ct}' is not valid. Allowed: {sorted(_CHART_TYPES)}"))
Expand All @@ -301,9 +301,9 @@ def _lint_chart(si: int, ei: int, elem: dict) -> list[dict]:
if elem.get("holeSize") is not None and ct != "donut":
results.append(_diag(si, ei, "chart-holeSize-wrong-type",
f"holeSize is only valid for chartType 'donut', not '{ct}'."))
if elem.get("stacked") and ct not in ("bar", None):
if elem.get("stacked") and ct not in ("bar", "area", None):
results.append(_diag(si, ei, "chart-stacked-wrong-type",
f"stacked is only valid for chartType 'bar', not '{ct}'."))
f"stacked is only valid for chartType 'bar' or 'area', not '{ct}'."))

results.extend(_lint_bbox_required(si, ei, elem, "chart"))
if chart_edit_ignored(elem):
Expand Down
44 changes: 40 additions & 4 deletions tests/test_chart_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ def test_radar_builds_a_radar_chart(self, tmp_path):
assert chart._chartSpace.find(f".//{_C}radarChart") is not None
assert chart._chartSpace.find(f".//{_C}barChart") is None

@pytest.mark.parametrize("stacked", [False, True])
def test_area_variants(self, tmp_path, stacked):
ch = _one_chart(tmp_path, chartType="area", stacked=stacked,
categories=["Jan", "Feb", "Mar"], series=TWO_SERIES)
assert ch["chartType"] == "area"
assert ch.get("stacked", False) is stacked
assert ch["categories"] == ["Jan", "Feb", "Mar"]
assert [s["name"] for s in ch["series"]] == ["p50", "p99"]
assert [s["values"] for s in ch["series"]] == [[12, 45, 89], [34, 120, 250]]
assert "_chartRebuildable" not in ch

def test_area_builds_an_area_chart(self, tmp_path):
chart = _built_chart(tmp_path, chartType="area", categories=["A", "B"],
series=[{"name": "s", "values": [1, 2]}])
assert chart._chartSpace.find(f".//{_C}areaChart") is not None
assert chart._chartSpace.find(f".//{_C}barChart") is None

def test_pie(self, tmp_path):
ch = _one_chart(tmp_path, chartType="pie", categories=["A", "B", "C"],
series=[{"name": "share", "values": [20, 30, 50]}])
Expand Down Expand Up @@ -145,6 +162,11 @@ def test_radar_series_colors(self, tmp_path):
assert ch["chartType"] == "radar"
assert [s["color"] for s in ch["series"]] == ["#FF9900", "#41B3FF"]

def test_area_series_colors(self, tmp_path):
ch = _one_chart(tmp_path, chartType="area", categories=["A", "B", "C"], series=TWO_SERIES)
assert ch["chartType"] == "area"
assert [s["color"] for s in ch["series"]] == ["#FF9900", "#41B3FF"]

def test_default_colors_are_distinct_theme_colors(self, tmp_path):
ch = _one_chart(tmp_path, chartType="bar", categories=["A"],
series=[{"name": "a", "values": [1]}, {"name": "b", "values": [2]}])
Expand Down Expand Up @@ -459,6 +481,20 @@ def test_unedited_radar_keeps_its_series_lines(self, tmp_path):
[frame] = [s for s in Presentation(str(tmp_path / "b" / "out.pptx")).slides[0].shapes if s.has_chart]
assert frame.chart._chartSpace.find(f".//{_C}ser/{_C}spPr/{_A}ln") is None

def test_edited_area_is_built_from_json(self, tmp_path):
(tmp_path / "a").mkdir()
source = _foreign_chart_pptx(tmp_path / "a" / "in.pptx", "area")
[ch] = _charts(pptx_to_json(source, tmp_path / "a" / "x")["slides"][-1])
assert ch["chartType"] == "area"
assert "_chartRebuildable" not in ch
ch["series"][0]["values"] = [5, 6]
deck = _make_deck(tmp_path / "b", [ch])
result = generate(deck, output_path=tmp_path / "b" / "out.pptx")
assert "errors" not in result
assert _plot_tags(tmp_path / "b" / "out.pptx") == ["areaChart"]
[again] = _charts(pptx_to_json(tmp_path / "b" / "out.pptx", tmp_path / "c")["slides"][-1])
assert again["series"][0]["values"] == [5, 6]


_USER_SHAPES = ('<c:userShapes xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" '
'xmlns:cdr="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"/>')
Expand Down Expand Up @@ -504,7 +540,7 @@ def add(prs, chart_type):


class TestChartsTheJsonCannotDescribe:
"""A chart read back as a type chartType does not have (area, 100% stacked, combo)
"""A chart read back as a type chartType does not have (100% stacked, combo)
keeps its ``_chartXml`` when edited, instead of turning into a bar chart."""

def _extract(self, tmp_path: Path, kind: str) -> tuple[dict, list[str]]:
Expand All @@ -519,7 +555,7 @@ def _build(self, tmp_path: Path, elem: dict) -> tuple[dict, list[str]]:
result = generate(deck, output_path=tmp_path / "out.pptx")
return result, _plot_tags(tmp_path / "out.pptx")

@pytest.mark.parametrize("kind", ["area", "stacked100", "combo"])
@pytest.mark.parametrize("kind", ["stacked100", "combo"])
def test_edited_chart_keeps_its_type(self, tmp_path, kind):
ch, original = self._extract(tmp_path / "a", kind)
assert ch["_chartRebuildable"] is False
Expand All @@ -530,13 +566,13 @@ def test_edited_chart_keeps_its_type(self, tmp_path, kind):
assert "chart-edit-ignored" in rules

def test_unedited_chart_has_no_diagnostic(self, tmp_path):
ch, original = self._extract(tmp_path / "a", "area")
ch, original = self._extract(tmp_path / "a", "stacked100")
result, plots = self._build(tmp_path / "b", ch)
assert plots == original
assert "errors" not in result

def test_without_chart_xml_it_is_built_from_json(self, tmp_path):
ch, _ = self._extract(tmp_path / "a", "area")
ch, _ = self._extract(tmp_path / "a", "stacked100")
ch["series"][0]["values"] = [5, 6]
del ch["_chartXml"]
result, plots = self._build(tmp_path / "b", ch)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def test_invalid_chartType(self):
def test_radar_chartType_ok(self):
assert lint(self._base(chartType="radar")) == []

def test_area_chartType_ok(self):
assert lint(self._base(chartType="area")) == []
assert lint(self._base(chartType="area", stacked=True)) == []

def test_missing_series(self):
diags = lint(self._base(series=[]))
assert any(d["rule"] == "chart-missing-series" for d in diags)
Expand Down
Loading