@openpresentation/opf-render 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -212,7 +212,7 @@ console.log(fonts.substitutions);
212
212
 
213
213
  Set `trace: true` to stamp rendered SVG elements with `data-opf-path` values such as `slides.0.title`; omit it for smaller production SVG.
214
214
 
215
- Layout templates (OPF 0.19, core `opf-layout/v2`: a `direction` and one ordered `regions` list, nested for two dimensions) draw from core's composed geometry, as every slide does: the renderer adds no arrangement of its own. Core places each block in its region (`geometry.regions`, `item.region`); a card is the `item.frameBox` core composed in the block's cell (`design.contentBox`), and a region with `bleed` arrives with its outer edges on the slide edge and no card. A list core laid out in columns (`item.listColumns`: a lone list in a region with `listColumns: "auto"`, or a list payload with `columns`) draws each column's own fit in its own box, at one shared size, with numbering continuing across the columns; `item.text` (the whole list) is not drawn then. With `trace: true` everything an item of a region draws (card, payload, caption) is grouped in `<g data-opf-region="<name>">`, and each list column is a group with `data-opf-list-column` (its index), `data-opf-list-start` and `data-opf-list-end` (the half-open range of the payload's items it holds) and its `data-opf-box-*`. OPF 0.19 removes `opf-layout/v1` records with no alias or migration shim. Slides without a layout use core's automatic composition; only items bound to template regions carry these region attributes. `test/layout-template-goldens.mjs` pins the SVG and PNG of the 28 built-in templates with 1 to 6 short and long blocks, and of the pages core's `paginate` makes of the ones that overflow.
215
+ Layout templates (OPF 0.19, core `opf-layout/v2`: a `direction` and one ordered `regions` list, nested for two dimensions) draw from core's composed geometry, as every slide does: the renderer adds no arrangement of its own. Core places each block in its region (`geometry.regions`, `item.region`); a card is the `item.frameBox` core composed in the block's cell (`design.contentBox`), and a region with `bleed` arrives with its outer edges on the slide edge and no card. A list core laid out in columns (`item.listColumns`: a lone list in a region with `listColumns: "auto"`, or a list payload with `columns`) draws each column's own fit in its own box, at one shared size, with numbering continuing across the columns; `item.text` (the whole list) is not drawn then. With `trace: true` everything an item of a region draws (card, payload, caption) is grouped in `<g data-opf-region="<name>">`, and each list column is a group with `data-opf-list-column` (its index), `data-opf-list-start` and `data-opf-list-end` (the half-open range of the payload's items it holds) and its `data-opf-box-*`. OPF 0.19 removes `opf-layout/v1` records with no alias or migration shim. Slides without a layout use core's automatic composition; only items bound to template regions carry these region attributes. `test/layout-template-goldens.mjs` pins the SVG and PNG of the 36 built-in templates with 1 to 6 short and long blocks, and of the pages core's `paginate` makes of the ones that overflow.
216
216
 
217
217
  The installed open font pack works offline. The Aptos family previews with the metric-compatible Intos even under the default metric policy; this example additionally permits visual-only look-alikes for families with no metric replacement yet (a documented fallback), and the substitution report identifies requested and resolved faces. A visual substitute is not a claim of metric or pixel equivalence, and it is a known layout-fidelity gap rather than the end state. Replacements apply to rendering only; the document keeps the selected font name. Omit `substitutionPolicy` to restrict the Office pack to its metric mappings, or supply your own licensed faces (`faces`). Missing fonts/glyphs fail explicitly. Without `fonts`, synchronous SVG APIs use estimated widths; named fonts alone do not make rich-run spacing reliable. Browser hosts should load the same bytes using the loader below.
218
218
 
package/dist/charts.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // The table below is carried here so the preview stays synchronous and self-contained; test/chart-catalog.mjs checks it
5
5
  // against core's CHART_TYPES. Each type renders the construct PowerPoint shows for the exported chart; any other value
6
6
  // returns null so the caller keeps its legacy single-series preview.
7
- import { chartDrawPlan, chartBandColor, chartWaterfallColors, waterfallLabelText, markLabelColor, chartEmphasisColors, chartSeriesLabelColor, chartContextColors, chartHighlightColors, chartHighlightMarks, chartLayerDataLabels, chartNumber, chartValueAxisHidden, chartPaletteForFill, chartSchemeSeries, chartSeriesPalette as coreChartSeriesPalette, chartTextSize, CHART_MAX_INTERVALS, chartIntervalsFor, formatDataNumber, groupNumber, groupsAxisTicks, groupsThousands, maxIntervalsFor, niceScale, stackCategoryValues, waterfallSteps, numberFormatError, resolveChartData, resolveTextStyle, textColorForFill, textWidthMeasurer } from "@openpresentation/opf/composition";
7
+ import { chartBarGeometry, chartDrawPlan, chartBandColor, chartSlicePlan, CHART_SLICE_SEPARATOR_PX, histogramBins, scottBinCount, chartWaterfallColors, waterfallLabelText, markLabelColor, chartEmphasisColors, chartSeriesLabelColor, chartContextColors, chartHighlightColors, chartHighlightMarks, chartLayerDataLabels, chartNumber, chartValueAxisHidden, chartPaletteForFill, chartSchemeSeries, chartSeriesPalette as coreChartSeriesPalette, chartTextSize, CHART_MAX_INTERVALS, chartIntervalsFor, formatDataNumber, groupNumber, groupsAxisTicks, groupsDataRange, groupsThousands, maxIntervalsFor, niceScale, stackCategoryValues, waterfallSteps, numberFormatError, resolveChartData, resolveTextStyle, textColorForFill, textWidthMeasurer } from "@openpresentation/opf/composition";
8
8
  import { drawAxisTitles, drawBarLabel, drawCenteredLabel, drawPointLabel, drawSliceLabel, labelFill, labelString, outsideLabelReserve, reportOptionDiagnostics, reserveAxisTitles, resolveOptions } from "./chart-options.js";
9
9
 
10
10
  // The series colours for a chart panel: core's `chartSeriesPalette` (the deck colour scheme's accents, RR-89, with the chart's own
@@ -97,9 +97,9 @@ function markColor(c, j, i) {
97
97
  return c.highlight ? (c.highlight.series[j] || c.highlight.categories[i] ? c.highlight.accents?.[j] ?? c.highlight.accent : c.highlight.mutedSeries?.[j] ?? c.highlight.muted) : c.colors[j % c.colors.length];
98
98
  }
99
99
 
100
- /** The colour of the pie or doughnut slice of row `i`. */
100
+ /** The color of the pie or doughnut slice of row `i`. LH-161: core's slice palette, which moves a last slice that reads as the first off it. */
101
101
  function sliceColor(c, i) {
102
- return c.highlight ? (c.highlight.categories[i] ? c.highlight.sliceAccents?.[i] ?? c.highlight.accent : c.highlight.sliceMuted?.[i] ?? c.highlight.muted) : c.colors[i % c.colors.length];
102
+ return c.highlight ? (c.highlight.categories[i] ? c.highlight.sliceAccents?.[i] ?? c.highlight.accent : c.highlight.sliceMuted?.[i] ?? c.highlight.muted) : c.sliceColors[i % c.sliceColors.length];
103
103
  }
104
104
 
105
105
  const bar = (dir, grouping) => ({ kind: "bar", dir, grouping });
@@ -201,7 +201,10 @@ export function renderCatalogChart(item, box, bound, options, svg) {
201
201
  // LH-107 to LH-110 (core chart-marks.ts): a waterfall's roles, a pie's value list, a stacked chart's values and names, the title's
202
202
  // reference marks.
203
203
  c.waterfall = layer?.waterfall;
204
+ c.histogram = layer?.histogram;
204
205
  c.valueList = layer?.valueList;
206
+ // LH-182: a doughnut's square and its hole (core), the hole filled with the surface.
207
+ c.doughnut = layer?.doughnut;
205
208
  c.stack = layer?.stack;
206
209
  if (layer?.valueList || layer?.stack?.names) c.legendManaged = true;
207
210
  // LH-93: sibling charts sharing one value axis share one plot height; core gives each its inner plot as an inset from the chart box.
@@ -337,6 +340,7 @@ const neutrals = bound.design.roles.neutrals;
337
340
  strongColors: chartSeriesPalette(surface, bound.design.colorScheme, item.value?.colors, { accents: bound.design.roles.map.accents, roles: bound.design.colors, variables: bound.design.variables }),
338
341
  // RR-92: the value axis core composed for a column, bar, line or area chart ({ min, max, majorUnit }); absent for the other types.
339
342
  valueAxis: item.chart?.valueAxis,
343
+ numericAxes: item.chart?.layer?.numericAxes,
340
344
  gridColor: neutrals.gridline.hex,
341
345
  axisColor: neutrals.axisLine.hex,
342
346
  outlineColor: neutrals.outline.hex,
@@ -372,6 +376,11 @@ const neutrals = bound.design.roles.neutrals;
372
376
  }));
373
377
  }
374
378
  };
379
+ // LH-161: a pie's or doughnut's slices: the series colors, the last slice moved off the first (at most 20 L*) when they would read as one tone,
380
+ // else every slice bordered in the surface color.
381
+ const slicePlan = chartSlicePlan(surface, c.colors, rows.length, { legible: chartSchemeSeries(item.value?.colors, bound.design.colorScheme, { accents: bound.design.roles.map.accents, roles: bound.design.colors, variables: bound.design.variables }) });
382
+ c.sliceColors = slicePlan.colors;
383
+ c.sliceBordered = slicePlan.bordered;
375
384
  return c;
376
385
  }
377
386
 
@@ -422,6 +431,14 @@ export function formatTick(value, percent = false, format = undefined, group = u
422
431
  return formatChartValue(value, format);
423
432
  }
424
433
 
434
+ /**
435
+ * LH-153: the tick grouping of a value axis core does not compose (combo, scatter, the chartex constructs), decided from the values it
436
+ * plots (core `groupsDataRange`) so PowerPoint, which picks its own ticks, agrees: no format of its own, whole numbers, one of four digits.
437
+ */
438
+ function dataGroup(c, format, values, options) {
439
+ return format === undefined && groupsDataRange(values, options) ? { language: typeof c.language === "string" ? c.language : undefined } : undefined;
440
+ }
441
+
425
442
  // RR-54: a formatted horizontal axis (horizontal bars, the scatter X axis) can have end tick labels far wider than the margin the layout
426
443
  // leaves beside the plot (a General label is a few characters, a long format code is not). Pull the plot in until the first and
427
444
  // last labels, centred on their ticks, stay inside the chart, and lay the ticks out again for the new width. Only formatted axes call it,
@@ -758,12 +775,14 @@ function chartAggregateError(path, aggregate) {
758
775
  // A range so wide that min + n x majorUnit leaves Number's range (finite data up to Number.MAX_VALUE) has no ticks to rebuild from the
759
776
  // three numbers; it takes the saturating scale `niceScale` computes.
760
777
  function categoryScale(c, dataMin, dataMax, length, labelExtent, percent) {
761
- const axis = c.valueAxis;
762
- if (axis && Number.isFinite(axis.max - axis.min) && (axis.max - axis.min) / axis.majorUnit <= 1000) {
763
- const scale = scaleFrom(axis.min, axis.max, axis.majorUnit);
764
- if (scale.ticks.every(Number.isFinite)) return scale;
765
- }
766
- return niceScale(dataMin, dataMax, chartIntervalsFor(length, labelExtent, c.u), { percent });
778
+ return composedScale(c.valueAxis) ?? niceScale(dataMin, dataMax, chartIntervalsFor(length, labelExtent, c.u), { percent });
779
+ }
780
+
781
+ // The scale of an axis core composed ({min, max, majorUnit}), or undefined when there is none or its ticks leave Number's range.
782
+ function composedScale(axis) {
783
+ if (!axis || !Number.isFinite(axis.max - axis.min) || !(axis.majorUnit > 0) || (axis.max - axis.min) / axis.majorUnit > 1000) return undefined;
784
+ const scale = scaleFrom(axis.min, axis.max, axis.majorUnit);
785
+ return scale.ticks.every(Number.isFinite) ? scale : undefined;
767
786
  }
768
787
 
769
788
  function renderCategoryChart(c, spec) {
@@ -878,20 +897,11 @@ function renderCategoryChart(c, spec) {
878
897
  }
879
898
  }
880
899
 
881
- // PptxGenJS gap widths: clustered 150%, stacked 50% (overlap 100).
882
- export function barGeometry(band, seriesCount, grouping) {
883
- if (grouping === "clustered") {
884
- const group = band / 2.5;
885
- return { group, width: group / seriesCount, offset: (band - group) / 2, clustered: true };
886
- }
887
- const width = band / 1.5;
888
- return { group: width, width, offset: (band - width) / 2, clustered: false };
889
- }
890
-
891
900
  function drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale, categorySlot = (i) => i, rowTop = (i) => plot.y + i * band }) {
892
901
  // Bars grow from zero, or from the axis minimum (maximum, for all-negative data) when zero is off the axis.
893
902
  const base = (value) => Math.min(scale.max, Math.max(scale.min, value));
894
- const geometry = barGeometry(band, series.length, spec.grouping);
903
+ // LH-176: core's bar geometry, PowerPoint's gap width (clustered 150%, stacked 50%) and overlap, as the PPTX export writes them.
904
+ const geometry = chartBarGeometry(band, series.length, spec.grouping);
895
905
  const labels = [];
896
906
  series.forEach((s, j) => {
897
907
  stacks[j].forEach((point, i) => {
@@ -1079,6 +1089,9 @@ function renderComboChart(c, spec) {
1079
1089
  const [primaryMin, primaryMax] = extent([...bars, ...primaryLines]);
1080
1090
  const [secondaryMin, secondaryMax] = extent(secondaryLines);
1081
1091
  const primaryFormat = (bars[0] ?? primaryLines[0])?.format, secondaryFormat = secondaryLines[0]?.format;
1092
+ // LH-153: each value axis groups its thousands when it has no format and its series are whole numbers of four digits (core `groupsDataRange`).
1093
+ const primaryGroup = dataGroup(c, primaryFormat, [...bars, ...primaryLines].flatMap((s) => s.values), { zeroBased: bars.length > 0 });
1094
+ const secondaryGroup = dataGroup(c, secondaryFormat, secondaryLines.flatMap((s) => s.values), { zeroBased: false });
1082
1095
  // The default legend sits at the far right, outside a right axis title (the secondary axis title, or right to left the primary
1083
1096
  // one), as PowerPoint places it: the legend is laid out against the box before the title band was carved, and the title moves in.
1084
1097
  const rightTitle = c.axisTitleBands?.some((band) => band.side === "right") && !c.legendManaged;
@@ -1094,14 +1107,14 @@ function renderComboChart(c, spec) {
1094
1107
  const top = box.y + pad + c.lineHeight / 2;
1095
1108
  const entries = categories.map((name, i) => ({ name, path: `${c.path}.data.rows.${i}.0` }));
1096
1109
  if (rtl) entries.reverse();
1097
- const tickWidthOf = (scale, format) => Math.max(...scale.ticks.map((tick) => c.width(formatTick(tick, false, format)))) + fontPx * 0.5;
1110
+ const tickWidthOf = (scale, format, group) => Math.max(...scale.ticks.map((tick) => c.width(formatTick(tick, false, format, group)))) + fontPx * 0.5;
1098
1111
  const axis = planCategoryAxis(c, entries, (reserve) => {
1099
1112
  const height = Math.max(1, box.y + box.height - pad - reserve - top);
1100
1113
  const intervals = chartIntervalsFor(height, c.lineHeight * 1.2, c.u);
1101
1114
  // The two axes share the gridlines, so each ends on a tick (LH-59 endOnTick).
1102
1115
  const scale = niceScale(primaryMin, primaryMax, intervals, { endOnTick: true });
1103
1116
  const secondary = secondaryLines.length ? niceScale(secondaryMin, secondaryMax, intervals, { endOnTick: true }) : null;
1104
- const primaryWidth = tickWidthOf(scale, primaryFormat), secondaryWidth = secondary ? tickWidthOf(secondary, secondaryFormat) : 0;
1117
+ const primaryWidth = tickWidthOf(scale, primaryFormat, primaryGroup), secondaryWidth = secondary ? tickWidthOf(secondary, secondaryFormat, secondaryGroup) : 0;
1105
1118
  const leftWidth = rtl ? secondaryWidth : primaryWidth, rightWidth = rtl ? primaryWidth : secondaryWidth;
1106
1119
  const x = box.x + pad + (leftWidth || fontPx / 2);
1107
1120
  const plotRight = right - (rightWidth || fontPx / 2);
@@ -1119,9 +1132,9 @@ function renderComboChart(c, spec) {
1119
1132
  for (const tick of scale.ticks) {
1120
1133
  const position = at(tick);
1121
1134
  gridline(c, plot.x, position, plot.x + plot.width, position);
1122
- tickLabel(formatTick(tick, false, primaryFormat), position, rtl ? "right" : "left", axis.primaryWidth);
1135
+ tickLabel(formatTick(tick, false, primaryFormat, primaryGroup), position, rtl ? "right" : "left", axis.primaryWidth);
1123
1136
  }
1124
- if (secondary) for (const tick of secondary.ticks) tickLabel(formatTick(tick, false, secondaryFormat), atSecondary(tick), rtl ? "left" : "right", axis.secondaryWidth);
1137
+ if (secondary) for (const tick of secondary.ticks) tickLabel(formatTick(tick, false, secondaryFormat, secondaryGroup), atSecondary(tick), rtl ? "left" : "right", axis.secondaryWidth);
1125
1138
  const band = plot.width / count;
1126
1139
  // Column series come first in core's order, so a column's palette index is its series index.
1127
1140
  if (bars.length) drawBars(c, spec, bars, stackCategoryValues(bars, count, "bar", "clustered", c.path), { plot, band, at, horizontal: false, scale, categorySlot });
@@ -1174,7 +1187,8 @@ function renderCircularChart(c, spec) {
1174
1187
  })));
1175
1188
  // LH-108: with a value list, the pie fills the square core gave it.
1176
1189
  const list = c.valueList;
1177
- const area = list ? list.pie : { x: box.x + pad, y: box.y + pad, width: Math.max(1, box.width - 2 * pad - legendWidth), height: Math.max(1, box.height - 2 * pad) };
1190
+ // LH-182: a doughnut in core's square (the PPTX export pins its plot there too).
1191
+ const area = list ? list.pie : spec.kind === "doughnut" && c.doughnut ? c.doughnut.pie : { x: box.x + pad, y: box.y + pad, width: Math.max(1, box.width - 2 * pad - legendWidth), height: Math.max(1, box.height - 2 * pad) };
1178
1192
  const cx = area.x + area.width / 2, cy = area.y + area.height / 2;
1179
1193
  // RR-35: a slice's label text (category, the signed value, the share of the total); outside-end labels shrink the pie to leave room.
1180
1194
  const ringTexts = c.dataLabels ? rings.map((ring) => ring.values.map((value, i) => labelString(c, { category: categories[i], value: chartNumber(c.rows[i][ring.column]) ?? 0, share: ring.total ? value / ring.total : 0, format: c.formats[ring.column], group: c.group(ring.column) }))) : null;
@@ -1183,14 +1197,17 @@ function renderCircularChart(c, spec) {
1183
1197
  const outsideTexts = !ringTexts || spec.kind !== "pie" ? [] : c.sliceLabels ? ringTexts[0].filter((_, i) => c.sliceLabels.get(i) === "outside") : (c.dataLabels.position ?? "outside-end") === "outside-end" ? ringTexts[0] : [];
1184
1198
  const outside = outsideTexts.length > 0;
1185
1199
  const reserve = outside ? outsideLabelReserve(c, outsideTexts) : { x: 0, y: 0 };
1186
- const r = list ? Math.max(1, Math.min(area.width, area.height) / 2) : outside ? Math.max(1, Math.min(area.width / 2 - reserve.x, area.height / 2 - reserve.y)) : Math.max(1, Math.min(area.width, area.height) / 2 * 0.9);
1200
+ const r = list || (spec.kind === "doughnut" && c.doughnut) ? Math.max(1, Math.min(area.width, area.height) / 2) : outside ? Math.max(1, Math.min(area.width / 2 - reserve.x, area.height / 2 - reserve.y)) : Math.max(1, Math.min(area.width, area.height) / 2 * 0.9);
1187
1201
  const hole = spec.kind === "doughnut" ? r * 0.5 : 0;
1188
1202
  if (rings.every((ring) => !ring.total)) {
1189
1203
  c.text("No positive chart values", area, c.path);
1190
1204
  return;
1191
1205
  }
1192
- const border = { stroke: c.outlineColor, "stroke-width": 0.75 * c.pt };
1206
+ // LH-161: a bordered pie separates its slices (the last from the first) by a surface-colored line.
1207
+ const border = c.sliceBordered ? { stroke: c.surface, "stroke-width": CHART_SLICE_SEPARATOR_PX * c.u } : { stroke: c.outlineColor, "stroke-width": 0.75 * c.pt };
1193
1208
  const thickness = (r - hole) / rings.length;
1209
+ // LH-182: the hole takes the surface the chart stands on, so a watermark or motif behind the chart does not show through it.
1210
+ if (hole && c.doughnut) c.mark("circle", { cx, cy, r: hole, fill: c.surface });
1194
1211
  rings.forEach((ring, j) => {
1195
1212
  const inner = hole + j * thickness, outer = inner + thickness;
1196
1213
  let angle = -Math.PI / 2;
@@ -1277,28 +1294,30 @@ function renderScatterChart(c) {
1277
1294
  const yFormat = series[0]?.format, xFormat = c.hasX ? c.formats[1] : undefined;
1278
1295
  const points = series.flatMap((s) => s.points);
1279
1296
  const xs = points.map((p) => p.x), ys = points.map((p) => p.y);
1297
+ // LH-153: both value axes group their thousands (no format, whole numbers, one of four digits); the X axis only over a span of 1000 or more, so a column of years never reads "1,990".
1298
+ const yGroup = dataGroup(c, yFormat, ys, { zeroBased: false }), xGroup = c.hasX ? dataGroup(c, xFormat, xs, { zeroBased: false, minRange: 1000 }) : undefined;
1280
1299
  const legendWidth = seriesLegend(c, series, "marker");
1281
1300
  const top = box.y + pad + c.lineHeight / 2, bottom = box.y + box.height - pad - c.lineHeight;
1282
1301
  const height = Math.max(1, bottom - top);
1283
- const yScale = niceScale(ys.length ? Math.min(...ys) : 0, ys.length ? Math.max(...ys) : 1, chartIntervalsFor(height, c.lineHeight * 1.2, c.u));
1284
- const tickWidth = Math.max(...yScale.ticks.map((tick) => c.width(formatTick(tick, false, yFormat)))) + fontPx * 0.5;
1302
+ const yScale = composedScale(c.numericAxes?.value) ?? niceScale(ys.length ? Math.min(...ys) : 0, ys.length ? Math.max(...ys) : 1, chartIntervalsFor(height, c.lineHeight * 1.2, c.u));
1303
+ const tickWidth = Math.max(...yScale.ticks.map((tick) => c.width(formatTick(tick, false, yFormat, yGroup)))) + fontPx * 0.5;
1285
1304
  const plot = { x: box.x + pad + tickWidth, y: top, height };
1286
1305
  plot.width = Math.max(1, box.x + box.width - pad - legendWidth - fontPx - plot.x);
1287
- const xLabelWidth = Math.max(c.width(formatTick(xs.length ? Math.max(...xs) : 1, false, xFormat)), c.width(formatTick(xs.length ? Math.min(...xs) : 0, false, xFormat))) + fontPx;
1306
+ const xLabelWidth = Math.max(c.width(formatTick(xs.length ? Math.max(...xs) : 1, false, xFormat, xGroup)), c.width(formatTick(xs.length ? Math.min(...xs) : 0, false, xFormat, xGroup))) + fontPx;
1288
1307
  const scaleForX = (w) => niceScale(xs.length ? Math.min(...xs) : 0, xs.length ? Math.max(...xs) : 1, chartIntervalsFor(w, xLabelWidth, c.u));
1289
- let xScale = scaleForX(plot.width);
1308
+ let xScale = composedScale(c.numericAxes?.category) ?? scaleForX(plot.width);
1290
1309
  // RR-54: a formatted X axis keeps its end labels inside the chart.
1291
- if (xFormat !== undefined) ({ x: plot.x, width: plot.width, scale: xScale } = insetForEndLabels(c, plot.x, plot.width, xFormat, scaleForX));
1310
+ if (xFormat !== undefined) ({ x: plot.x, width: plot.width, scale: xScale } = insetForEndLabels(c, plot.x, plot.width, xFormat, w => composedScale(c.numericAxes?.category) ?? scaleForX(w)));
1292
1311
  c.plotArea = plot;
1293
1312
  const xAt = (v) => plot.x + axisFraction(v, xScale) * plot.width;
1294
1313
  const yAt = (v) => plot.y + axisFraction(v, yScale, true) * plot.height;
1295
1314
  for (const tick of yScale.ticks) {
1296
1315
  const y = yAt(tick);
1297
1316
  gridline(c, plot.x, y, plot.x + plot.width, y);
1298
- c.text(formatTick(tick, false, yFormat), { x: box.x + pad, y: y - c.lineHeight / 2, width: plot.x - box.x - pad - fontPx * 0.35, height: c.lineHeight }, c.path, "right");
1317
+ c.text(formatTick(tick, false, yFormat, yGroup), { x: box.x + pad, y: y - c.lineHeight / 2, width: plot.x - box.x - pad - fontPx * 0.35, height: c.lineHeight }, c.path, "right");
1299
1318
  }
1300
1319
  for (const tick of xScale.ticks) {
1301
- const label = formatTick(tick, false, xFormat), width = c.width(label) + fontPx;
1320
+ const label = formatTick(tick, false, xFormat, xGroup), width = c.width(label) + fontPx;
1302
1321
  c.text(label, { x: xAt(tick) - width / 2, y: plot.y + plot.height, width, height: c.lineHeight }, c.path);
1303
1322
  }
1304
1323
  const yCross = yAt(Math.min(yScale.max, Math.max(yScale.min, 0))), xCross = xAt(Math.min(xScale.max, Math.max(xScale.min, 0)));
@@ -1310,7 +1329,7 @@ function renderScatterChart(c) {
1310
1329
  }
1311
1330
  // RR-35: a scatter label shows the Y value, and the X value as its category.
1312
1331
  if (c.dataLabels) series.forEach((s) => {
1313
- for (const point of s.points) drawPointLabel(c, labelString(c, { category: formatChartValue(point.x, xFormat), value: point.y, format: s.format, group: s.group }), [xAt(point.x), yAt(point.y)], `${c.path}.data.rows.${point.row}.${s.column}`);
1332
+ for (const point of s.points) drawPointLabel(c, labelString(c, { category: formatChartValue(point.x, xFormat), value: point.y, format: s.format, group: c.group(s.column) }), [xAt(point.x), yAt(point.y)], `${c.path}.data.rows.${point.row}.${s.column}`);
1314
1333
  });
1315
1334
  }
1316
1335
 
@@ -1427,47 +1446,8 @@ export function chartexValues(rows, columns) {
1427
1446
  return { hasCategories, column, values, categories };
1428
1447
  }
1429
1448
 
1430
- // Office's automatic histogram bins: Scott's normal reference rule gives the bin
1431
- // width 3.49 * sd * n^(-1/3) (sample standard deviation) over [min, max]; the
1432
- // exporter writes the same count as cx:binCount.
1433
- export function scottBinCount(values) {
1434
- const n = values.length;
1435
- if (n === 0) return 1;
1436
- let min = Infinity, max = -Infinity, mean = 0;
1437
- for (const value of values) { if (value < min) min = value; if (value > max) max = value; mean += value / n; }
1438
- if (!(max > min) || n < 2) return 1;
1439
- let variance = 0;
1440
- for (const value of values) variance += (value - mean) * (value - mean) / (n - 1);
1441
- const width = 3.49 * Math.sqrt(variance) * Math.cbrt(n) ** -1;
1442
- if (!(width > 0) || !Number.isFinite(width)) return 1;
1443
- const count = Math.ceil((max - min) / width - 1e-9);
1444
- return Number.isFinite(count) && count >= 1 ? count : 1;
1445
- }
1446
-
1447
- /**
1448
- * Equal-width bins from the minimum, closed on the right like PowerPoint's
1449
- * ("[min, e1]", then "(e1, e2]"): each value falls in the last bin whose upper
1450
- * edge it does not exceed. Labels carry six significant digits, and more when
1451
- * two bins would read alike.
1452
- */
1453
- export function histogramBins(values) {
1454
- const finite = values.filter((value) => value !== null && Number.isFinite(value));
1455
- if (!finite.length) return [];
1456
- const min = finite.reduce((a, b) => Math.min(a, b)), max = finite.reduce((a, b) => Math.max(a, b));
1457
- const count = scottBinCount(finite);
1458
- const edge = (index) => index === 0 ? min : index === count ? max : min / count * (count - index) + max / count * index;
1459
- const bins = Array.from({ length: count }, (_, index) => ({ low: edge(index), high: edge(index + 1), count: 0 }));
1460
- for (const value of finite) {
1461
- let index = 0;
1462
- while (index + 1 < count && value > bins[index].high) index++;
1463
- bins[index].count++;
1464
- }
1465
- for (let precision = 6; ; precision++) {
1466
- const format = (value) => String(Number(value.toPrecision(precision)));
1467
- const labels = bins.map((bin, index) => count === 1 && min === max ? format(min) : `${index === 0 ? "[" : "("}${format(bin.low)}, ${format(bin.high)}]`);
1468
- if (new Set(labels).size === labels.length || precision === 17) return bins.map((bin, index) => ({ ...bin, label: labels[index] }));
1469
- }
1470
- }
1449
+ // LH-160: the bins (Scott's count, capped so their labels fit) and their edge labels are core's (chart-histogram.ts), shared with the PPTX export.
1450
+ export { histogramBins, scottBinCount };
1471
1451
 
1472
1452
  // WI-5: the plot is laid out before its axis is fitted, so the tick-label column is sized from the labels any of the axes the plot could end up with
1473
1453
  // (one to CHART_MAX_INTERVALS intervals) would draw, not from a ten-interval scale that the final, sparser axis may exceed ("100" after "90").
@@ -1492,12 +1472,12 @@ function chartexPlot(c, { categories, legendWidth = 0, tickLabels = [], percentA
1492
1472
  return { plot, band: plot.width / Math.max(1, categories.length) };
1493
1473
  }
1494
1474
 
1495
- function valueAxis(c, plot, scale, format) {
1475
+ function valueAxis(c, plot, scale, format, group) {
1496
1476
  const at = (value) => plot.y + axisFraction(value, scale, true) * plot.height;
1497
1477
  for (const tick of scale.ticks) {
1498
1478
  const y = at(tick);
1499
1479
  gridline(c, plot.x, y, plot.x + plot.width, y);
1500
- c.text(formatTick(tick, false, format), { x: c.box.x + c.pad, y: y - c.lineHeight / 2, width: plot.x - c.box.x - c.pad - c.fontPx * 0.35, height: c.lineHeight }, c.path, "right");
1480
+ c.text(formatTick(tick, false, format, group), { x: c.box.x + c.pad, y: y - c.lineHeight / 2, width: plot.x - c.box.x - c.pad - c.fontPx * 0.35, height: c.lineHeight }, c.path, "right");
1501
1481
  }
1502
1482
  const crossing = at(Math.min(scale.max, Math.max(scale.min, 0)));
1503
1483
  axisLine(c, plot.x, plot.y, plot.x, plot.y + plot.height);
@@ -1515,29 +1495,34 @@ function renderHistogramChart(c, spec) {
1515
1495
  if (hasCategories) {
1516
1496
  bars = values.map((value, i) => ({ value, name: categories[i], path: `${c.path}.data.rows.${i}.${column}`, labelPath: `${c.path}.data.rows.${i}.0` })).filter((bar) => bar.value !== null);
1517
1497
  } else {
1518
- bars = histogramBins(values).map((bin) => ({ value: bin.count, name: bin.label, path: `${c.path}.data.columns.${column}`, labelPath: c.path }));
1498
+ bars = histogramBins(values, { count: c.histogram?.bins, decimals: c.histogram?.decimals }).map((bin) => ({ value: bin.count, name: bin.label, path: `${c.path}.data.columns.${column}`, labelPath: c.path }));
1519
1499
  }
1520
1500
  if (pareto) bars = bars.slice().sort((a, b) => b.value - a.value);
1521
1501
  const total = bars.reduce((sum, bar) => sum + Math.max(0, bar.value), 0);
1522
1502
  if (!Number.isFinite(total)) throw chartAggregateError(c.path, "cumulative total");
1523
1503
  const dataMax = bars.length ? Math.max(...bars.map((bar) => bar.value)) : 1, dataMin = bars.length ? Math.min(0, ...bars.map((bar) => bar.value)) : 0;
1524
- const probe = { ticks: probeTicks(dataMin, dataMax) };
1525
- const { plot, band } = chartexPlot(c, { categories: bars.map((bar) => ({ name: bar.name, path: bar.labelPath })), tickLabels: probe.ticks.map((tick) => formatTick(tick, false, format)), percentAxis: pareto });
1526
- const scale = niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1527
- const { at, crossing } = valueAxis(c, plot, scale, format);
1504
+ // RR-105: the value axis core composed (layer.histogram.valueAxis), which the PPTX export writes as the chartex cx:valScaling.
1505
+ const composed = composedScale(c.histogram?.valueAxis);
1506
+ const probe = { ticks: composed ? composed.ticks : probeTicks(dataMin, dataMax) };
1507
+ // LH-153: the labels and the value axis group their thousands (a histogram's bin counts too) unless the column has a format.
1508
+ const labelGroup = format === undefined && groupsThousands(bars.map((bar) => bar.value)), tickGroup = dataGroup(c, format, bars.map((bar) => bar.value), { zeroBased: true });
1509
+ const { plot, band } = chartexPlot(c, { categories: bars.map((bar) => ({ name: bar.name, path: bar.labelPath })), tickLabels: probe.ticks.map((tick) => formatTick(tick, false, format, tickGroup)), percentAxis: pareto });
1510
+ const scale = composed ?? niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1511
+ const { at, crossing } = valueAxis(c, plot, scale, format, tickGroup);
1528
1512
  const width = band / 1.06, offset = (band - width) / 2;
1529
1513
  bars.forEach((bar, i) => {
1530
1514
  const y = at(bar.value);
1531
1515
  c.mark("rect", { x: plot.x + i * band + offset, y: Math.min(y, crossing), width, height: Math.abs(crossing - y), fill: c.colors[0] }, bar.path);
1532
1516
  });
1533
- // RR-35: data labels on the columns (a histogram label is the bin's count).
1534
- if (c.dataLabels) bars.forEach((bar, i) => {
1517
+ // RR-35: data labels on the columns (a histogram label is the bin's count). LH-160: not where they would not fit beside each other (core).
1518
+ if (c.dataLabels && c.histogram?.valueLabels !== false) bars.forEach((bar, i) => {
1535
1519
  const y = at(bar.value);
1536
- drawBarLabel(c, labelString(c, { category: bar.name, value: bar.value, format }), { x: plot.x + i * band + offset, y: Math.min(y, crossing), width, height: Math.abs(crossing - y) }, bar.value >= 0 ? "up" : "down", bar.path, c.colors[0]);
1520
+ drawBarLabel(c, labelString(c, { category: bar.name, value: bar.value, format, group: labelGroup }), { x: plot.x + i * band + offset, y: Math.min(y, crossing), width, height: Math.abs(crossing - y) }, bar.value >= 0 ? "up" : "down", bar.path, c.colors[0]);
1537
1521
  });
1538
1522
  if (pareto && bars.length) {
1539
1523
  // Percentage axis on the right, 0-100%, and the cumulative line through the bar centres.
1540
- const percent = niceScale(0, 1, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u), { percent: true });
1524
+ // RR-105: the percentage step core composed (layer.histogram.percentUnit), which the PPTX export writes on the secondary axis.
1525
+ const percent = (c.histogram?.percentUnit > 0 ? composedScale({ min: 0, max: 1, majorUnit: c.histogram.percentUnit }) : undefined) ?? niceScale(0, 1, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u), { percent: true });
1541
1526
  const right = plot.x + plot.width;
1542
1527
  axisLine(c, right, plot.y, right, plot.y + plot.height);
1543
1528
  for (const tick of percent.ticks) {
@@ -1571,15 +1556,17 @@ function renderWaterfallChart(c) {
1571
1556
  const extents = bars.flatMap((bar) => [bar.from, bar.to]);
1572
1557
  const dataMin = extents.length ? Math.min(0, ...extents) : 0, dataMax = extents.length ? Math.max(0, ...extents) : 1;
1573
1558
  const probe = { ticks: hidden ? [] : probeTicks(dataMin, dataMax) };
1574
- const { plot, band } = chartexPlot(c, { categories: categories.map((name, i) => ({ name, path: `${c.path}.data.rows.${i}.0` })), tickLabels: probe.ticks.map((tick) => formatTick(tick, false, format)), labelRoom: hidden });
1575
- const scale = niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1559
+ // LH-153: the labels group their thousands by the deck language (no format, whole numbers, one of four digits), and so does the axis.
1560
+ const labelGroup = c.group(column), tickGroup = dataGroup(c, format, extents, { zeroBased: true });
1561
+ const { plot, band } = chartexPlot(c, { categories: categories.map((name, i) => ({ name, path: `${c.path}.data.rows.${i}.0` })), tickLabels: probe.ticks.map((tick) => formatTick(tick, false, format, tickGroup)), labelRoom: hidden });
1562
+ const scale = composedScale(c.numericAxes?.value) ?? niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1576
1563
  let at;
1577
1564
  if (hidden) {
1578
1565
  // The category axis line stays, at zero; the labels carry the values.
1579
1566
  at = (value) => plot.y + axisFraction(value, scale, true) * plot.height;
1580
1567
  const crossing = at(Math.min(scale.max, Math.max(scale.min, 0)));
1581
1568
  axisLine(c, plot.x, crossing, plot.x + plot.width, crossing);
1582
- } else ({ at } = valueAxis(c, plot, scale, format));
1569
+ } else ({ at } = valueAxis(c, plot, scale, format, tickGroup));
1583
1570
  const width = band / 1.5, offset = (band - width) / 2;
1584
1571
  bars.forEach((bar, k) => {
1585
1572
  const a = at(bar.from), b = at(bar.to);
@@ -1591,7 +1578,7 @@ function renderWaterfallChart(c) {
1591
1578
  // RR-35: data labels show each step's value (not the running total) on the floating bars.
1592
1579
  if (c.dataLabels) bars.forEach((bar) => {
1593
1580
  const a = at(bar.from), b = at(bar.to);
1594
- const text = c.waterfallSigned ? waterfallLabelText(bar.value, format, bar.role) : labelString(c, { category: categories[bar.i], value: bar.value, format });
1581
+ const text = c.waterfallSigned ? waterfallLabelText(bar.value, format, bar.role, labelGroup ? { language: typeof c.language === "string" ? c.language : undefined } : undefined) : labelString(c, { category: categories[bar.i], value: bar.value, format, group: labelGroup });
1595
1582
  drawBarLabel(c, text, { x: plot.x + bar.i * band + offset, y: Math.min(a, b), width, height: Math.abs(b - a) }, bar.value >= 0 ? "up" : "down", `${c.path}.data.rows.${bar.i}.${column}`, colorOf(bar), c.waterfallSigned && bar.role === "total" ? 700 : 400);
1596
1583
  });
1597
1584
  }
@@ -1602,6 +1589,8 @@ function renderFunnelChart(c) {
1602
1589
  const { column, values, categories } = chartexValues(c.rows, c.columns);
1603
1590
  const format = c.formats[column];
1604
1591
  const count = categories.length;
1592
+ // LH-153: the bar values group their thousands by the deck language (no format, whole numbers, one of four digits).
1593
+ const group = c.group(column), grouping = group ? { language: typeof c.language === "string" ? c.language : undefined } : undefined;
1605
1594
  const max = Math.max(0, ...values.filter((value) => value !== null));
1606
1595
  const labelWidth = Math.min(box.width * 0.3, Math.max(0, ...categories.map((name) => c.width(flatLabel(name)))) + fontPx * 0.5);
1607
1596
  const plot = { x: box.x + pad + labelWidth + pad / 2, y: box.y + pad, width: Math.max(1, box.width - 2 * pad - labelWidth - pad / 2), height: Math.max(1, box.height - 2 * pad) };
@@ -1618,7 +1607,7 @@ function renderFunnelChart(c) {
1618
1607
  c.mark("rect", { x, y: y + offset, width, height, fill: c.colors[0] }, `${c.path}.data.rows.${i}.${column}`);
1619
1608
  // RR-35: the funnel labels its bars with values by default; dataLabels picks the content, false removes them.
1620
1609
  if (c.dataLabelsOff) return;
1621
- insideText(c, c.dataLabels ? labelString(c, { category: name, value, format }) : formatTick(value, false, format), { x: plot.x, y: y + offset, width: plot.width, height }, `${c.path}.data.rows.${i}.${column}`, c.colors[0]);
1610
+ insideText(c, c.dataLabels ? labelString(c, { category: name, value, format, group }) : formatTick(value, false, format, grouping), { x: plot.x, y: y + offset, width: plot.width, height }, `${c.path}.data.rows.${i}.${column}`, c.colors[0]);
1622
1611
  });
1623
1612
  }
1624
1613
 
@@ -1688,7 +1677,7 @@ function renderTreemapChart(c) {
1688
1677
  // RR-35: the treemap labels its tiles with category names by default; dataLabels picks the content, false removes them. PowerPoint
1689
1678
  // draws the label at the bottom left of its tile whatever the position attribute says (native check 2026-10-01), so the preview does.
1690
1679
  if (!c.dataLabelsOff && rect.width >= fontPx * 2 && rect.height >= c.lineHeight) {
1691
- insideText(c, c.dataLabels ? labelString(c, { category: categories[i], value: values[i], format }) : categories[i], { x: rect.x + fontPx * 0.25, y: rect.y + rect.height - c.lineHeight - fontPx * 0.2, width: rect.width - fontPx * 0.5, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`, c.colors[i % c.colors.length], "left");
1680
+ insideText(c, c.dataLabels ? labelString(c, { category: categories[i], value: values[i], format, group: c.group(column) }) : categories[i], { x: rect.x + fontPx * 0.25, y: rect.y + rect.height - c.lineHeight - fontPx * 0.2, width: rect.width - fontPx * 0.5, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`, c.colors[i % c.colors.length], "left");
1692
1681
  }
1693
1682
  });
1694
1683
  }
@@ -1736,9 +1725,11 @@ function renderBoxWhiskerChart(c) {
1736
1725
  const dataMin = all.length ? Math.min(...all) : 0, dataMax = all.length ? Math.max(...all) : 1;
1737
1726
  const legendWidth = seriesLegend(c, series);
1738
1727
  const probe = { ticks: probeTicks(dataMin, dataMax) };
1739
- const { plot, band } = chartexPlot(c, { categories: groups.map((group) => ({ name: group.name, path: lone ? c.path : `${c.path}.data.rows.${group.first}.0` })), legendWidth, tickLabels: probe.ticks.map((tick) => formatTick(tick, false, format)) });
1740
- const scale = niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1741
- const { at } = valueAxis(c, plot, scale, format);
1728
+ // LH-153: the value axis groups its thousands when the plotted values are whole numbers of four digits (the statistics between them do not decide).
1729
+ const tickGroup = dataGroup(c, format, series.flatMap((s) => s.values), { zeroBased: false });
1730
+ const { plot, band } = chartexPlot(c, { categories: groups.map((group) => ({ name: group.name, path: lone ? c.path : `${c.path}.data.rows.${group.first}.0` })), legendWidth, tickLabels: probe.ticks.map((tick) => formatTick(tick, false, format, tickGroup)) });
1731
+ const scale = composedScale(c.numericAxes?.value) ?? niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1732
+ const { at } = valueAxis(c, plot, scale, format, tickGroup);
1742
1733
  const group = band / 2, width = group / series.length, offset = (band - group) / 2;
1743
1734
  series.forEach((s, j) => {
1744
1735
  const color = c.colors[j % c.colors.length], path = `${c.path}.data.columns.${s.column}`;