Render: omit the moving-average R² label

PowerPoint does not show R² for a moving average, and the value can be
negative. The line is still drawn.
This commit is contained in:
Nikita Rakitin
2026-10-14 01:32:31 +03:00
parent 768641615a
commit 7e4e628b13
2 changed files with 15 additions and 4 deletions
+12 -3
View File
@@ -137,8 +137,9 @@ impl Trendline {
Some(TrendFit { kind: self.kind, model, r2: r_squared(&used_y, &yhat), x_min, x_max })
}
/// The equation and R² lines this trendline asks to show. Empty when neither is on, and a
/// moving average has no equation.
/// The equation and R² lines this trendline asks to show. Empty when neither is on. A moving
/// average has no equation, and PowerPoint does not show its R², so that label is left off
/// even when the file asks for it.
pub fn caption(&self, fit: &TrendFit) -> String {
let mut lines = Vec::new();
if self.disp_eq
@@ -146,7 +147,7 @@ impl Trendline {
{
lines.push(eq);
}
if self.disp_r_sqr {
if self.disp_r_sqr && self.kind != TrendlineType::MovingAvg {
lines.push(fit.r2_label());
}
lines.join("\n")
@@ -599,6 +600,14 @@ mod tests {
assert_eq!(fit.span(Some(4.0), Some(4.0)), (2.0, 4.0));
}
#[test]
fn moving_average_shows_neither_equation_nor_r2() {
let t = Trendline { kind: TrendlineType::MovingAvg, period: Some(2), disp_eq: true, disp_r_sqr: true, ..Default::default() };
let fit = t.fit(&[1.0, 2.0, 3.0, 4.0], &[2.0, 8.0, 4.0, 10.0]).expect("ma");
assert!(fit.r2_label().starts_with("R² ="));
assert!(t.caption(&fit).is_empty(), "{}", t.caption(&fit));
}
#[test]
fn too_few_points_and_non_finite_input_fit_nothing() {
assert!(line(TrendlineType::Linear).fit(&[1.0], &[2.0]).is_none());
+3 -1
View File
@@ -150,7 +150,8 @@ Detail in [file-format-parity.md](file-format-parity.md).
chart types" (partial); `chartex` parts (waterfall, funnel, treemap, sunburst, histogram, box &
whisker) aren't read. Trendlines round-trip (`corpus_charts.rs`) and are drawn: linear,
exponential, logarithmic, polynomial, power and moving average, with forecast and the equation
and R² label. A combo chart's secondary value axis is read (`y2_*`, `Series.secondary_axis`) and
and R² label. A moving average is drawn with neither label. A combo chart's secondary value axis
is read (`y2_*`, `Series.secondary_axis`) and
is not written back when the chart is rebuilt.
- **Impact:** most business decks have charts; editing their data is routine.
- **Estimate:** 12–20 h. Data and elements are **beta blockers** (6–10 h).
@@ -261,6 +262,7 @@ Detail in [localization-parity.md](localization-parity.md).
| Date | Change | Summary |
|---|---|---|
| 2026-10-14 | trivial | A moving average trendline is drawn without an equation or an R² label |
| 2026-10-14 | minor | Chart trendlines are drawn (six types, forecast, equation and R²). The charts gap stays open for the data grid, chartex and secondary-axis export; the real-deck corpus gap stays open |
| 2026-10-14 | minor | Chart trendlines round-trip. The real-deck corpus gap stays open; secondary-axis export and drawing trendlines stay in the charts gap |
| 2026-10-13 | minor | Shape, picture and table rendering checked against PowerPoint on ~150 synthetic edge-case slides; 3-D bevels, cameras and face lighting now render approximately (gap narrowed to extrusion, rigs and the 3-D pane) |