Skip to content

Commit 2d2fac3

Browse files
committed
Fix corrupt trend pptx when score trends upward
The Score Trajectory slide drew connecting lines between data points with width = p2.x - p1.x and height = p2.y - p1.y. When the org's score improves between periods, y decreases (smaller y means higher up the chart), so the height was negative. Some Office versions silently corrupt the pptx when a shape has negative dimensions: writeFile reports success and the file looks intact on disk, but the slide rels reference an unwritten slide and the file fails to open ("file or directory is corrupted and unreadable"). Reproduced with two- and three-period histories that trend upward. Always pass positive width/height and use flipV when the trajectory goes up. Result: 3-month upward histories now render correctly across all three trend slides. Also refresh the committed Slide2 screenshot to match the deck the generator now produces (rich tier narrative + 3 cards + focus and strengths).
1 parent c4307c9 commit 2d2fac3

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

docs/screenshots/Slide2.JPG

11.7 KB
Loading

scorer/generate_trend.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,23 @@ if (!hasMultiple) {
273273
return { x, y, score: entry.overallScore || 0, date: entry.date, tier: entry.achievedTier };
274274
});
275275

276-
// Connect points with lines
276+
// Connect points with lines.
277+
// PowerPoint chokes on shapes with negative width/height (the file opens
278+
// but every reader since Office 2016 reports it as corrupted). When the
279+
// trend is upward — score increasing means y decreasing — the naive
280+
// (p2 - p1) delta goes negative, so we always draw with positive
281+
// dimensions and use flipV to mirror the line vertically when needed.
277282
for (let i = 1; i < points.length; i++) {
278283
const p1 = points[i - 1];
279284
const p2 = points[i];
280-
// Use a thin rectangle as a line approximation (pptxgenjs LINE is tricky for angled)
285+
const w = p2.x - p1.x;
286+
const dy = p2.y - p1.y;
281287
s1.addShape(pres.shapes.LINE, {
282288
x: p1.x,
283-
y: p1.y,
284-
w: p2.x - p1.x,
285-
h: p2.y - p1.y,
289+
y: dy >= 0 ? p1.y : p2.y,
290+
w: w,
291+
h: Math.abs(dy),
292+
flipV: dy < 0,
286293
line: { color: C.cyan, width: 2.5 },
287294
});
288295
}

0 commit comments

Comments
 (0)