@openpresentation/opf-render 0.30.0 → 0.32.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/dist/charts.js CHANGED
@@ -4,15 +4,18 @@
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 { chartHighlightColors, chartHighlightMarks, chartLeadFromScheme, chartNumber, chartPaletteForFill, chartSeriesPalette as coreChartSeriesPalette, chartTextSize, CHART_MAX_INTERVALS, chartIntervalsFor, formatDataNumber, maxIntervalsFor, niceScale, stackCategoryValues, numberFormatError, resolveChartData, resolveTextStyle, textColorForFill, textWidthMeasurer } from "@openpresentation/opf/composition";
8
- import { drawAxisTitles, drawBarLabel, drawCenteredLabel, drawPointLabel, drawSliceLabel, labelString, outsideLabelReserve, reportOptionDiagnostics, reserveAxisTitles, resolveOptions } from "./chart-options.js";
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";
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
11
11
  // `colors` entries replacing their positions) adjusted by core's `chartPaletteForFill` (contrast against the panel without letting
12
12
  // two series merge). The PPTX export and the validator use the same pair, so the preview draws the colours they write.
13
- // WI-5 (P18, D3): series 1 from the scheme reaches 4.5:1 on a dark panel (an authored `colors[0]` keeps its colour).
14
- export function chartSeriesPalette(surface, colorScheme, colors, context) {
15
- return chartPaletteForFill(surface, coreChartSeriesPalette(colorScheme, colors, context), { legibleLead: chartLeadFromScheme(colors, colorScheme, context) });
13
+ // WI-5 (P18, D3) and LH-55: every series from the scheme reaches 4.5:1 on a dark panel, series 2 a lightness step from series 1 (an authored
14
+ // `colors` entry keeps the 3:1 floor).
15
+ // LH-105: `soften` mixes each scheme series a quarter of the way towards the backdrop (core softenChartPalette), keeping its contrast and its
16
+ // lightness step from its neighbours: ordinary data in soft colours, the full-strength colour left for emphasis.
17
+ export function chartSeriesPalette(surface, colorScheme, colors, context, { soften = false } = {}) {
18
+ return chartPaletteForFill(surface, coreChartSeriesPalette(colorScheme, colors, context), { legible: chartSchemeSeries(colors, colorScheme, context), soften });
16
19
  }
17
20
 
18
21
  // FA-14: chart.highlight. Core resolves which series and categories are named (chartHighlightMarks) and the two colours
@@ -20,24 +23,83 @@ export function chartSeriesPalette(surface, colorScheme, colors, context) {
20
23
  // highlight has no `c.highlight`, and every colour below is the palette colour it always was.
21
24
  function highlightFor(c, resolved, spec, data) {
22
25
  if (!resolved.highlight) return undefined;
23
- const marks = chartHighlightMarks(resolved.highlight, { columns: data.columns, hasX: spec.kind === "scatter" && data.columns.length > 2, rows: data.rows });
26
+ const marks = chartHighlightMarks(resolved.highlight, { columns: data.columns, hasX: spec.kind === "scatter" && data.hasX, rows: data.rows });
24
27
  if (!marks) return undefined;
25
28
  return { ...marks, ...chartHighlightColors(c.surface, c.bound.design.colors.primary, c.labelColor) };
26
29
  }
27
30
 
31
+ // LH-03, LH-95: a one-series small column or bar chart draws its emphasised point (core: the last one with a value) in a stronger shade of
32
+ // the series colour and every other point in the series colour (core chartEmphasisColors); it is drawn as a category highlight of that point.
33
+ function emphasisFor(c, layer) {
34
+ const row = layer?.small?.emphasis;
35
+ // LH-105: the emphasised point takes the series colour at full strength (or a shade of it); the others keep the soft colour.
36
+ const colors = row === undefined ? undefined : chartEmphasisColors(c.surface, c.colors[0], c.strongColors[0]);
37
+ return colors ? { series: [false], categories: c.rows.map((_, i) => i === row), ...colors } : undefined;
38
+ }
39
+
40
+ // LH-105: the series or categories the slide title names (core chart-focus.ts) take their full-strength colour, the other marks the
41
+ // context neutrals (core chartContextColors: one gray per context series or slice, 11 L* apart, the first the strongest; 3:1 against the
42
+ // backdrop, or 1.6:1 when every context mark carries its text). It is drawn as a highlight whose accent is each series' own colour (and
43
+ // each slice's, on a pie) and whose muted colour is each context series' (or slice's) own gray.
44
+ function focusFor(c, layer, spec) {
45
+ const focus = layer?.focus;
46
+ if (!focus) return undefined;
47
+ const strong = (index) => c.strongColors[index % c.strongColors.length];
48
+ const context = (count, avoid) => chartContextColors(c.surface, c.labelColor, count, { labeled: focus.labeled === true, avoid });
49
+ const categories = c.rows.map((_, i) => focus.categories?.includes(i) === true);
50
+ if (spec.kind === "pie" || spec.kind === "doughnut") {
51
+ const rest = c.rows.map((_, i) => i).filter((i) => !categories[i]);
52
+ const grays = context(rest.length, c.rows.map((_, i) => i).filter((i) => categories[i]).map(strong));
53
+ const sliceMuted = c.rows.map((_, i) => grays[Math.max(0, rest.indexOf(i))]);
54
+ return { series: [false], categories, accent: strong(0), muted: grays[0], sliceAccents: c.rows.map((_, i) => strong(i)), sliceMuted };
55
+ }
56
+ const series = c.columns.slice(1).map((_, j) => focus.series?.includes(j) === true);
57
+ // A series focus: the unnamed series are the context, in order. A category focus: every series has context marks.
58
+ const rest = series.map((_, j) => j).filter((j) => !series[j]);
59
+ const grays = context(rest.length, series.map((_, j) => j).filter((j) => focus.categories ? true : series[j]).map(strong));
60
+ const mutedSeries = series.map((_, j) => grays[Math.max(0, rest.indexOf(j))]);
61
+ return { series, categories, accent: strong(0), muted: grays[0], accents: series.map((_, j) => strong(j)), mutedSeries };
62
+ }
63
+
64
+ // LH-81: the header row. The caption (bold, the full text colour) and the legend entries sit where core placed them; the band they take
65
+ // is carved from the top of the chart box, and a header legend replaces the side legend (c.legendManaged).
66
+ function drawHeader(c, spec, header) {
67
+ const rtl = c.bound.geometry?.direction === "rtl";
68
+ if (header.caption) {
69
+ const element = c.svg.renderTextBox(header.caption.text, header.caption.box, c.bound, {
70
+ path: c.path, fontSize: c.fontPx / c.u, fontFamily: c.bound.design.fonts.body, fontWeight: 700,
71
+ fill: c.labelColor, options: c.options, align: rtl ? "right" : "left", verticalAlign: "middle"
72
+ });
73
+ if (element) c.children.push(element);
74
+ }
75
+ if (header.legend) {
76
+ c.legendManaged = true;
77
+ const plan = spec.kind === "combo" ? comboPlan(c, c.series()) : undefined;
78
+ for (const entry of header.legend.entries) {
79
+ const s = c.series()[entry.series];
80
+ const key = entry.key === "line" ? "line" : undefined;
81
+ const marker = key === "line" && (spec.kind === "combo" ? plan?.[entry.series]?.role === "line" : Boolean(spec.markers));
82
+ const metrics = { swatch: c.fontPx * 0.6, gap: c.fontPx * 0.4, keyWidth: key ? c.fontPx * 1.4 : c.fontPx * 0.6 };
83
+ drawLegendEntry(c, { name: entry.name, color: seriesColor(c, entry.series), path: `${c.path}.data.columns.${s?.column ?? entry.series + 1}`, key, marker }, entry.box.x, entry.box.y, entry.box.height, metrics, entry.box.width);
84
+ }
85
+ }
86
+ const outer = c.box;
87
+ c.box = { x: outer.x, y: outer.y + header.height, width: outer.width, height: Math.max(1, outer.height - header.height) };
88
+ }
89
+
28
90
  /** The colour of series `j` as a whole (a line, an area, a legend key): the accent when highlighted, else muted. */
29
91
  function seriesColor(c, j) {
30
- return c.highlight ? (c.highlight.series[j] ? c.highlight.accent : c.highlight.muted) : c.colors[j % c.colors.length];
92
+ return c.highlight ? (c.highlight.series[j] ? c.highlight.accents?.[j] ?? c.highlight.accent : c.highlight.mutedSeries?.[j] ?? c.highlight.muted) : c.colors[j % c.colors.length];
31
93
  }
32
94
 
33
95
  /** The colour of the mark of series `j` at row `i`: highlighted when its series or its category is named. */
34
96
  function markColor(c, j, i) {
35
- return c.highlight ? (c.highlight.series[j] || c.highlight.categories[i] ? c.highlight.accent : c.highlight.muted) : c.colors[j % c.colors.length];
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];
36
98
  }
37
99
 
38
100
  /** The colour of the pie or doughnut slice of row `i`. */
39
101
  function sliceColor(c, i) {
40
- return c.highlight ? (c.highlight.categories[i] ? c.highlight.accent : 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.colors[i % c.colors.length];
41
103
  }
42
104
 
43
105
  const bar = (dir, grouping) => ({ kind: "bar", dir, grouping });
@@ -112,18 +174,43 @@ const CHARTEX_KINDS = new Set(["treemap", "histogram", "pareto", "box", "waterfa
112
174
  */
113
175
  export function renderCatalogChart(item, box, bound, options, svg) {
114
176
  const id = resolveChartType(item.value?.type);
115
- const spec = id && CHART_TYPES[id];
177
+ const authoredSpec = id && CHART_TYPES[id];
178
+ const data = authoredSpec && RENDERERS[authoredSpec.kind] ? chartData(item, bound) : null;
179
+ // LH-60: the construct core's chartDrawPlan draws (a map over categories that are not places as columns, a pie of several series
180
+ // as nested rings); the options stay resolved against the authored type, as the validator and the PPTX export resolve them.
181
+ const spec = data?.type && CHART_TYPES[data.type] ? CHART_TYPES[data.type] : authoredSpec;
116
182
  const render = spec && RENDERERS[spec.kind];
117
- const data = render ? chartData(item, bound) : null;
118
- if (!data || !data.rows.length || data.columns.length < (CHARTEX_KINDS.has(spec.kind) ? 1 : 2)) return null;
119
- const c = chartContext(item, box, bound, options, svg, data);
120
- // WI-5 (P19): the panel is a fill only; the axes and gridlines draw the plot, so there is no outer frame (the PPTX chart area has no line either).
121
- c.mark("rect", { x: box.x, y: box.y, width: box.width, height: box.height, fill: c.surface }, item.path);
183
+ if (!render || !data || !data.rows.length || data.columns.length < (CHARTEX_KINDS.has(spec.kind) ? 1 : 2)) return null;
184
+ // LH-03, LH-81: the chart layer composition decided (core chart-layer.ts): a small chart's labels, axis, panel and emphasis, and the
185
+ // header row. A chart without one draws as before. Core decides it for the construct drawn (a map drawn as columns is a column chart).
186
+ const layer = item.chart?.layer;
187
+ const c = chartContext(item, box, bound, options, svg, data, layer);
188
+ // LH-105: no chart draws a panel (Few: every pixel of ink shows data); its marks stand on the card or the slide background (c.surface),
189
+ // and the PPTX chart and plot areas have no fill either.
122
190
  // RR-35: a chart with axis titles, a legend position or data labels reserves their space before the plot is laid out. A chart
123
- // with none of them skips this block entirely, so its output is unchanged.
124
- const resolved = resolveOptions(item.value, spec);
191
+ // with none of them skips this block entirely, so its output is unchanged. LH-03: a small chart's default value labels count as data labels.
192
+ const resolved = chartLayerDataLabels(resolveOptions(item.value, authoredSpec), layer, spec.kind);
125
193
  // FA-14: a highlight changes colours only (no space is reserved), so it is resolved whether or not an option is active.
126
- c.highlight = highlightFor(c, resolved, spec, data);
194
+ c.highlight = highlightFor(c, resolved, spec, data) ?? focusFor(c, layer, spec) ?? emphasisFor(c, layer);
195
+ // LH-03, LH-142: no value axis (a small chart's labels or a horizontal stacked bar chart's segment values carry the values): core decides it.
196
+ c.valueAxisHidden = chartValueAxisHidden(layer);
197
+ c.ringNames = layer?.rings;
198
+ // LH-105: direct labels instead of a legend: the series names at the line ends, the category names on the slices.
199
+ c.endLabels = layer?.endLabels;
200
+ if (layer?.endLabels) c.legendManaged = true;
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
+ // reference marks.
203
+ c.waterfall = layer?.waterfall;
204
+ c.valueList = layer?.valueList;
205
+ c.stack = layer?.stack;
206
+ if (layer?.valueList || layer?.stack?.names) c.legendManaged = true;
207
+ // 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.
208
+ const inset = layer?.plot;
209
+ c.plotBox = inset && { x: box.x + inset.left, y: box.y + inset.top, width: Math.max(1, box.width - inset.left - inset.right), height: Math.max(1, box.height - inset.top - inset.bottom) };
210
+ // LH-115: a horizontal bar chart beside a table of the same keys draws each category on its table row (core chart-rows.ts): offsets
211
+ // from the top of the chart box, taken before the header row narrows c.box.
212
+ c.alignedRows = layer?.rows && { top: box.y + layer.rows.top, bottom: box.y + layer.rows.bottom, centers: layer.rows.centers.map((center) => box.y + center) };
213
+ if (layer?.header) drawHeader(c, spec, layer.header);
127
214
  if (!resolved.active) reportOptionDiagnostics(c, resolved);
128
215
  if (resolved.active) {
129
216
  reportOptionDiagnostics(c, resolved);
@@ -132,7 +219,28 @@ export function renderCatalogChart(item, box, bound, options, svg) {
132
219
  if (resolved.legend !== undefined) placeLegend(c, spec, resolved.legend);
133
220
  reserveAxisTitles(c, spec, resolved.axisTitles);
134
221
  }
222
+ // LH-105: a pie or one-series doughnut names its categories on its slices, inside or (a pie) outside each as core decided, and draws no legend.
223
+ if (layer?.slices && !c.dataLabels) {
224
+ c.legendManaged = true;
225
+ c.dataLabels = { content: ["category"], position: "inside-end", separator: ", " };
226
+ c.sliceLabels = new Map(layer.slices.labels.map((entry) => [entry.row, entry.position]));
227
+ }
228
+ // LH-109: a stacked chart's default labels are the values inside the segments that hold them.
229
+ if (layer?.stack?.values.some((row) => row.some(Boolean)) && !c.dataLabels) {
230
+ c.dataLabels = { content: ["value"], position: "center", separator: ", " };
231
+ c.stackValues = layer.stack.values;
232
+ }
233
+ // LH-107: a waterfall's default labels are its signed values over (a loss: under) each bar.
234
+ if (layer?.waterfall?.labels && !c.dataLabels) {
235
+ c.dataLabels = { content: ["value"], position: "outside-end", separator: ", " };
236
+ c.waterfallSigned = true;
237
+ }
238
+ // LH-110: the period band lies under the marks, the reference lines over them.
239
+ for (const band of layer?.references?.bands ?? []) c.mark("rect", { ...band.box, fill: chartBandColor(c.surface, c.labelColor) }, `${c.path}.data.rows.${band.row}.0`);
135
240
  render(c, spec);
241
+ drawReferenceLines(c, layer?.references?.lines);
242
+ drawStackNames(c, layer?.stack?.names);
243
+ drawStackEnds(c, layer?.stack?.ends);
136
244
  if (resolved.active) drawAxisTitles(c);
137
245
  return svg.tag("g", { ...svg.traceAttrs(options, item.path), "data-opf-chart": options.trace ? id : undefined }, c.children.join("\n"));
138
246
  }
@@ -145,8 +253,11 @@ export function chartData(item, bound) {
145
253
  const chart = item.value;
146
254
  const resolved = resolveChartData(chart, bound?.presentation, { path: item.path });
147
255
  if (!resolved.ok) return null;
148
- const formats = resolved.formats.map((format) => typeof format === "string" && format !== "" && !numberFormatError(format) ? format : undefined);
149
- return { columns: resolved.columns, rows: resolved.rows, formats, trace: tracePaths(item, bound, resolved), ...(resolved.combo ? { combo: resolved.combo } : {}) };
256
+ // LH-60: core's draw plan (the fallback construct and the data as drawn), shared with the PPTX export.
257
+ const language = bound?.presentation?.language;
258
+ const plan = chartDrawPlan(chart, resolved, { language: typeof language === "string" ? language : undefined });
259
+ const formats = plan.formats.map((format) => typeof format === "string" && format !== "" && !numberFormatError(format) ? format : undefined);
260
+ return { type: plan.type, fallback: plan.fallback, columns: plan.columns, hasX: plan.hasX, rows: plan.rows, formats, trace: tracePaths(item, bound, { ...resolved, columns: plan.columns, regrouped: plan.columns.length !== resolved.columns.length }), ...(resolved.combo ? { combo: resolved.combo } : {}) };
150
261
  }
151
262
 
152
263
  // The authored object at a composed path ("slides.0.blocks.1.chart"), or undefined.
@@ -179,18 +290,19 @@ function tracePaths(item, bound, resolved) {
179
290
  if (isDatasetChart(item, bound)) return { collapse: true };
180
291
  const authored = authoredAt(bound?.presentation, item.path);
181
292
  const authoredData = authored && typeof authored === "object" ? authored.data : undefined;
182
- if (!authored || typeof authored !== "object" || (!authored.mapping && !resolved.combo) || !Array.isArray(authoredData?.columns)) return null;
293
+ if (!authored || typeof authored !== "object" || (!authored.mapping && !resolved.combo && !resolved.regrouped) || !Array.isArray(authoredData?.columns)) return null;
183
294
  const names = authoredData.columns.map((column) => column !== null && typeof column === "object" ? column.name : column);
184
295
  const columnMap = resolved.columns.map((name, index) => { const found = names.indexOf(name); return found < 0 ? index : found; });
185
296
  return columnMap.every((column, index) => column === index) ? null : { columnMap };
186
297
  }
187
298
 
188
- function chartContext(item, box, bound, options, svg, { rows, columns, formats, trace, combo }) {
299
+ function chartContext(item, box, bound, options, svg, { rows, columns, formats, trace, combo, hasX = false }, layer) {
189
300
  const u = Math.min(bound.design.dimensions.width, bound.design.dimensions.height) / 720;
190
301
  const composition = bound.composition ?? bound.geometry.composition ?? {};
191
302
  // RR-90: core's chart text size (20 px, shrunk only for a small box, never below minFontSize), the size core's value-axis density assumes.
192
303
  const requested = chartTextSize({ width: box.width, height: box.height, scale: u, minFontSize: composition.minFontSize }), fontPx = requested * u;
193
- const surface = bound.design.colors.surface;
304
+ // LH-03, LH-105: a chart has no panel, so its colours are judged against what it stands on: the card, or the slide background.
305
+ const surface = item.frameBox ? bound.design.roles.neutrals.card.hex : bound.design.backgroundColor ?? bound.design.colors.background;
194
306
  // RR-96: every neutral comes from the slide's variant (core `roles.neutrals`: tx1 mixed into bg1, the colours the PPTX export writes as
195
307
  // scheme colours): chart text, gridlines, axis lines and the outline between marks (bg1).
196
308
  const neutrals = bound.design.roles.neutrals;
@@ -210,8 +322,9 @@ const neutrals = bound.design.roles.neutrals;
210
322
  return path.replace(/^(.*\.data\.(?:columns\.|rows\.\d+\.))(\d+)$/, (whole, head, column) => `${head}${trace.columnMap[Number(column)] ?? column}`);
211
323
  };
212
324
  const c = {
213
- item, box, bound, options, svg, rows, columns, formats, combo, children, u, fontPx, surface, labelColor, chartTextColor,
325
+ item, box, bound, options, svg, rows, columns, formats, combo, hasX, children, u, fontPx, surface, labelColor, chartTextColor,
214
326
  path: item.path,
327
+ tracePath,
215
328
  pt: u * 4 / 3,
216
329
  pad: 10 * u,
217
330
  lineHeight: fontPx * 1.5,
@@ -219,7 +332,9 @@ const neutrals = bound.design.roles.neutrals;
219
332
  // clear space kept between neighbouring category labels.
220
333
  textHeight: fontPx * 1.22,
221
334
  labelGap: fontPx * 0.1,
222
- colors: chartSeriesPalette(surface, bound.design.colorScheme, item.value?.colors, { accents: bound.design.roles.map.accents, roles: bound.design.colors, variables: bound.design.variables }),
335
+ colors: chartSeriesPalette(surface, bound.design.colorScheme, item.value?.colors, { accents: bound.design.roles.map.accents, roles: bound.design.colors, variables: bound.design.variables }, { soften: true }),
336
+ // LH-105: the same series at full strength, for emphasis and for the names at the line ends.
337
+ strongColors: chartSeriesPalette(surface, bound.design.colorScheme, item.value?.colors, { accents: bound.design.roles.map.accents, roles: bound.design.colors, variables: bound.design.variables }),
223
338
  // RR-92: the value axis core composed for a column, bar, line or area chart ({ min, max, majorUnit }); absent for the other types.
224
339
  valueAxis: item.chart?.valueAxis,
225
340
  gridColor: neutrals.gridline.hex,
@@ -234,21 +349,25 @@ const neutrals = bound.design.roles.neutrals;
234
349
  for (const [key, value] of Object.entries(attrs)) out[key] = numericAttrs.has(key) && typeof value === "number" ? n(value) : value;
235
350
  children.push(svg.tag(name, { ...out, ...(path ? svg.traceAttrs(options, tracePath(path)) : {}) }));
236
351
  },
237
- textElement(value, rect, path, align = "center", fill = chartTextColor) {
352
+ textElement(value, rect, path, align = "center", fill = chartTextColor, weight = 400) {
238
353
  if (!(rect.width > 0 && rect.height > 0)) return "";
239
354
  return svg.renderTextBox(String(value), rect, bound, {
240
- path: tracePath(path), fontSize: requested, fontFamily: bound.design.fonts.body, fontWeight: 400,
355
+ path: tracePath(path), fontSize: requested, fontFamily: bound.design.fonts.body, fontWeight: weight,
241
356
  fill, options, align, verticalAlign: "middle"
242
357
  });
243
358
  },
244
- text(value, rect, path, align = "center") {
245
- const element = c.textElement(value, rect, path, align);
359
+ text(value, rect, path, align = "center", fill = chartTextColor, weight = 400) {
360
+ const element = c.textElement(value, rect, path, align, fill, weight);
246
361
  if (element) children.push(element);
247
362
  },
363
+ // LH-141: whether the default value labels of column `column` group their thousands (no format of its own, whole numbers, one of four digits).
364
+ group: (column) => (formats[column] === undefined || formats[column] === "") && groupsThousands(rows.map((row) => chartNumber(row[column]))),
365
+ language: bound.presentation?.language,
248
366
  series(first = 1) {
249
367
  return columns.slice(first).map((name, offset) => ({
250
368
  name: c.label(name), column: first + offset, index: offset,
251
369
  ...(formats[first + offset] !== undefined ? { format: formats[first + offset] } : {}),
370
+ group: c.group(first + offset),
252
371
  values: rows.map((row) => chartNumber(row[first + offset]))
253
372
  }));
254
373
  }
@@ -280,9 +399,10 @@ function axisFraction(value, scale, reverse = false) {
280
399
  return (reverse ? max - position : position - min) / (max - min);
281
400
  }
282
401
 
402
+ // LH-59: ticks run from min in steps of step up to max, which a tightened axis (core's niceScale) need not land on.
283
403
  function scaleFrom(min, max, step) {
284
404
  const ticks = [];
285
- const count = Math.round((max - min) / step);
405
+ const count = Math.floor((max - min) / step + 1e-9);
286
406
  for (let index = 0; index <= count; index++) ticks.push(clean(min + index * step));
287
407
  return { min, max, step, ticks };
288
408
  }
@@ -292,10 +412,14 @@ function clean(value) {
292
412
  return Object.is(rounded, -0) ? 0 : rounded;
293
413
  }
294
414
 
295
- /** Office General / 0% tick labels; a value axis takes its first plotted series' number format (RR-54). */
296
- export function formatTick(value, percent = false, format = undefined) {
415
+ /**
416
+ * Office General / 0% tick labels; a value axis takes its first plotted series' number format (RR-54). LH-141: `group` ({ language }, an axis
417
+ * with no format whose ticks are whole numbers of four digits, core `groupsAxisTicks`) groups the thousands by the deck language.
418
+ */
419
+ export function formatTick(value, percent = false, format = undefined, group = undefined) {
297
420
  if (percent) return `${clean(value * 100)}%`;
298
- return format === undefined ? String(clean(value)) : formatChartValue(value, format);
421
+ if (format === undefined) return group ? groupNumber(clean(value), group.language) : String(clean(value));
422
+ return formatChartValue(value, format);
299
423
  }
300
424
 
301
425
  // RR-54: a formatted horizontal axis (horizontal bars, the scatter X axis) can have end tick labels far wider than the margin the layout
@@ -354,7 +478,7 @@ function legendSource(c, spec) {
354
478
  switch (spec.kind) {
355
479
  case "pie":
356
480
  case "doughnut": return c.rows.map((row, i) => ({ name: c.label(row[0]), color: sliceColor(c, i), path: `${c.path}.data.rows.${i}.0` }));
357
- case "scatter": return fromSeries(scatterSeries(c.rows, c.columns, c.formats).series, "marker");
481
+ case "scatter": return fromSeries(scatterSeries(c.rows, c.columns, c.formats, c.hasX).series, "marker");
358
482
  case "line": return fromSeries(c.series(), "line", spec.markers);
359
483
  case "radar": return fromSeries(c.series(), spec.style === "filled" ? undefined : "line", spec.markers);
360
484
  case "box": return fromSeries(c.columns.length === 1 ? [{ name: c.label(c.columns[0]), column: 0, index: 0 }] : c.series());
@@ -565,8 +689,8 @@ function planCategoryAxis(c, entries, geometry) {
565
689
  return { ...axis, plan };
566
690
  }
567
691
 
568
- function drawBottomLabels(c, plan, plot, entries) {
569
- const y = plot.y + plot.height, band = plot.width / Math.max(1, entries.length), lineH = c.textHeight;
692
+ function drawBottomLabels(c, plan, plot, entries, drop = 0) {
693
+ const y = plot.y + plot.height + drop, band = plot.width / Math.max(1, entries.length), lineH = c.textHeight;
570
694
  for (const label of plan.labels) {
571
695
  const path = entries[label.i].path;
572
696
  if (plan.angle) {
@@ -589,11 +713,14 @@ function drawBottomLabels(c, plan, plot, entries) {
589
713
  // A vertical category axis (labels to the left of horizontal bars and funnels).
590
714
  // Labels stay on one line inside the gutter, wrap at spaces onto two lines when
591
715
  // their rows are tall enough, else are ellipsized; every n-th row is labelled
592
- // when the rows are shorter than a line of text.
716
+ // when the rows are shorter than a line of text. LH-120: a row is tall enough for
717
+ // two lines when it holds one line and the glyphs of a second (a line plus one
718
+ // text size): the label then reaches into the gap between bars, and only a label
719
+ // whose words do not fit two lines is ellipsized.
593
720
  function planRowLabels(c, entries, band, gutter) {
594
721
  const labels = labelCandidates(c, entries);
595
722
  const n = Math.max(1, Math.ceil(c.textHeight / band - 1e-9));
596
- const canWrap = n * band >= 2 * c.textHeight - 0.01;
723
+ const canWrap = n * band >= c.textHeight + c.fontPx - 0.01;
597
724
  const placed = [];
598
725
  for (let i = 0; i < labels.length; i += n) {
599
726
  const label = labels[i];
@@ -608,12 +735,13 @@ function planRowLabels(c, entries, band, gutter) {
608
735
  return { n, labels: placed };
609
736
  }
610
737
 
611
- // `rowTop(i)` is the top of category i's row; rows are `band` tall.
738
+ // `rowTop(i)` is the top of category i's row; rows are `band` tall. A two-line label is given its two lines' height around its row's
739
+ // middle, so it is drawn at the chart text size even where it reaches past its row (LH-120).
612
740
  function drawRowLabels(c, plan, entries, band, gutter, x, rowTop) {
613
741
  const span = plan.n * band;
614
742
  for (const label of plan.labels) {
615
- const middle = rowTop(label.i) + band / 2;
616
- c.text(label.text, { x, y: middle - span / 2, width: gutter, height: span }, entries[label.i].path, "right");
743
+ const middle = rowTop(label.i) + band / 2, height = Math.max(span, label.text.split(/\n/).length * c.textHeight);
744
+ c.text(label.text, { x, y: middle - height / 2, width: gutter, height }, entries[label.i].path, "right");
617
745
  }
618
746
  reportTruncatedLabels(c, plan.labels.filter((label) => label.truncated).map((label) => entries[label.i].path));
619
747
  }
@@ -644,6 +772,8 @@ function renderCategoryChart(c, spec) {
644
772
  const percent = spec.grouping === "percentStacked";
645
773
  const series = c.series();
646
774
  const valueFormat = series[0]?.format;
775
+ // LH-141: an axis with no format and whole-number ticks of four digits groups its thousands, as the data labels do.
776
+ const tickGroup = !percent && valueFormat === undefined && c.valueAxis && groupsAxisTicks(c.valueAxis) ? { language: typeof c.language === "string" ? c.language : undefined } : undefined;
647
777
  const categories = c.rows.map((row) => c.label(row[0]));
648
778
  const count = categories.length;
649
779
  // Right to left (RR-05): column, line and area charts run their category axis from the right (PowerPoint's reversed categories,
@@ -657,31 +787,54 @@ function renderCategoryChart(c, spec) {
657
787
  const extents = stacks.flat().filter(Boolean).flatMap((point) => spec.kind === "line" || !stackedGrouping ? [point.to] : [point.from, point.to]);
658
788
  const dataMin = extents.length ? Math.min(...extents, ...((spec.kind === "bar" || spec.kind === "area") ? [0] : [])) : 0, dataMax = extents.length ? Math.max(...extents, ...((spec.kind === "bar" || spec.kind === "area") ? [0] : [])) : 1;
659
789
  const legendWidth = seriesLegend(c, series, spec.kind === "line" ? "line" : undefined, spec.markers);
790
+ // LH-03: a small chart without its value axis draws no tick labels and no gridlines; its labels carry the values. The plot keeps a
791
+ // line above the tallest column (or point) for its label, and a horizontal bar chart the widest label's room beyond the longest bar.
792
+ const hidden = c.valueAxisHidden === true;
793
+ const labelRoom = hidden && horizontal && c.dataLabels && !c.stackValues ? Math.max(0, ...series.flatMap((s) => s.values.map((value, i) => value === null ? 0 : c.width(labelString(c, { category: c.label(c.rows[i][0]), value, format: s.format, group: s.group })) + fontPx * 0.5))) : 0;
660
794
  const right = box.x + box.width - pad - legendWidth;
661
- const top = box.y + pad + c.lineHeight / 2;
662
- let plot, scale, valueTickWidth;
795
+ const top = box.y + pad + (hidden && !horizontal && c.dataLabels ? c.lineHeight : c.lineHeight / 2);
796
+ let plot, scale, valueTickWidth, rowTop, labelPlot;
663
797
  if (horizontal) {
664
- const categoryWidth = Math.min(box.width * 0.3, Math.max(0, ...categories.map((name) => c.width(flatLabel(name)))) + fontPx * 0.5);
798
+ // LH-120: the label gutter is at most 30% of the chart, or up to 40% for a word that does not break (a label's longest word fits
799
+ // before a label is ellipsized; longer labels wrap onto two lines, planRowLabels).
800
+ const longestWord = Math.max(0, ...categories.flatMap((name) => flatLabel(name).split(BREAKABLE).map((word) => c.width(word)))) + fontPx * 0.5;
801
+ const categoryWidth = Math.min(Math.max(box.width * 0.3, Math.min(box.width * 0.4, longestWord)), Math.max(0, ...categories.map((name) => c.width(flatLabel(name)))) + fontPx * 0.5);
665
802
  let x = box.x + pad + categoryWidth + c.pad / 2;
666
- const bottom = box.y + box.height - pad - c.lineHeight;
667
- let width = Math.max(1, right - x - fontPx);
668
- const tickWidth = Math.max(c.width(formatTick(dataMax, percent, valueFormat)), c.width(formatTick(dataMin, percent, valueFormat)), c.width("100%")) + fontPx;
803
+ const bottom = box.y + box.height - pad - (hidden ? 0 : c.lineHeight);
804
+ let width = Math.max(1, right - x - fontPx - labelRoom);
805
+ const tickWidth = Math.max(c.width(formatTick(dataMax, percent, valueFormat, tickGroup)), c.width(formatTick(dataMin, percent, valueFormat, tickGroup)), c.width("100%")) + fontPx;
669
806
  const scaleFor = (w) => categoryScale(c, dataMin, dataMax, w, tickWidth, percent);
670
807
  scale = scaleFor(width);
671
808
  // RR-54: a formatted value axis keeps its end labels inside the chart.
672
809
  if (valueFormat !== undefined && !percent) ({ x, width, scale } = insetForEndLabels(c, x, width, valueFormat, scaleFor));
673
- plot = { x, y: top, width, height: Math.max(1, bottom - top) };
674
- // Office bar charts draw the first category nearest the origin (bottom).
810
+ const aligned = c.alignedRows?.centers.length === count ? c.alignedRows : undefined;
811
+ plot = aligned ? { x, y: aligned.top, width, height: Math.max(1, aligned.bottom - aligned.top) } : { x, y: top, width, height: Math.max(1, bottom - top) };
812
+ // LH-125: a horizontal stacked bar chart draws its plot where core pinned it (its names stand in a row above); the PPTX export pins the same.
813
+ if (c.plotBox && !aligned) { plot = { ...c.plotBox }; scale = scaleFor(plot.width); }
814
+ // LH-59: the categories read top to bottom in data order (PowerPoint's reversed category axis, which the export writes).
675
815
  const entries = categories.map((name, i) => ({ name, path: `${c.path}.data.rows.${i}.0` }));
676
816
  const rowBand = plot.height / count;
677
- drawRowLabels(c, planRowLabels(c, entries, rowBand, categoryWidth), entries, rowBand, categoryWidth, box.x + pad, (i) => plot.y + plot.height - (i + 1) * rowBand);
817
+ // LH-115: on a table's rows each category's band is centered on its row (rows of unequal height keep the even band thickness).
818
+ rowTop = aligned ? (i) => aligned.centers[i] - rowBand / 2 : (i) => plot.y + i * rowBand;
819
+ drawRowLabels(c, planRowLabels(c, entries, rowBand, categoryWidth), entries, rowBand, categoryWidth, box.x + pad, rowTop);
678
820
  } else {
679
821
  const entries = categories.map((name, i) => ({ name, path: `${c.path}.data.rows.${i}.0` }));
680
822
  if (rtl) entries.reverse();
681
- const axis = planCategoryAxis(c, entries, (reserve) => {
823
+ // LH-93: a chart that shares its value axis with siblings draws its plot in the box core gave the set (one plot height); its tick
824
+ // labels sit beside it and its category labels under it, laid out as they would be for a plot of its own.
825
+ const shared = c.plotBox;
826
+ // LH-125: a stacked area runs edge to edge: its n categories stand on the plot's n points, so their labels are laid out as the centers of
827
+ // n bands over a plot one band wider (labelPlot); the end labels reach half their width past the plot, which core left room for.
828
+ const edgeToEdge = spec.kind === "area" && c.stack?.edge === true && count >= 2;
829
+ labelPlot = shared && edgeToEdge ? { x: shared.x - shared.width / (count - 1) / 2, y: shared.y, width: shared.width + shared.width / (count - 1), height: shared.height } : shared;
830
+ const axis = shared ? {
831
+ scale: categoryScale(c, dataMin, dataMax, shared.height, c.lineHeight * 1.2, percent), plot: shared,
832
+ tickWidth: rtl ? Math.max(1, right - shared.x - shared.width) : undefined,
833
+ plan: planBottomLabels(c, entries, labelPlot, Math.max(c.lineHeight + c.textHeight, c.box.height * 0.4), edgeToEdge ? { minX: c.box.x, maxX: c.box.x + c.box.width, rotatedMinX: c.box.x + c.pad } : { minX: shared.x - fontPx * 0.5, maxX: shared.x + shared.width + fontPx * 0.5, rotatedMinX: c.box.x + c.pad })
834
+ } : planCategoryAxis(c, entries, (reserve) => {
682
835
  const height = Math.max(1, box.y + box.height - pad - reserve - top);
683
836
  const fitted = categoryScale(c, dataMin, dataMax, height, c.lineHeight * 1.2, percent);
684
- const tickWidth = Math.max(...fitted.ticks.map((tick) => c.width(formatTick(tick, percent, valueFormat)))) + fontPx * 0.5;
837
+ const tickWidth = hidden ? fontPx / 2 : Math.max(...fitted.ticks.map((tick) => c.width(formatTick(tick, percent, valueFormat, tickGroup)))) + fontPx * 0.5;
685
838
  if (rtl) {
686
839
  const x = box.x + pad + fontPx / 2;
687
840
  return { scale: fitted, plot: { x, y: top, width: Math.max(1, right - tickWidth - x), height }, tickWidth };
@@ -691,14 +844,15 @@ function renderCategoryChart(c, spec) {
691
844
  });
692
845
  ({ plot, scale } = axis);
693
846
  valueTickWidth = axis.tickWidth;
694
- drawBottomLabels(c, axis.plan, plot, entries);
847
+ // LH-125: an edge-to-edge area's first label stands under the value axis's zero label: its labels sit a fifth of a text size lower (core reserves it).
848
+ drawBottomLabels(c, axis.plan, labelPlot ?? plot, entries, labelPlot !== undefined && labelPlot !== plot ? c.fontPx * 0.2 : 0);
695
849
  }
696
850
  c.plotArea = plot;
697
851
  const at = (value) => horizontal ? plot.x + axisFraction(value, scale) * plot.width : plot.y + axisFraction(value, scale, true) * plot.height;
698
852
  // Category axis crosses at zero when zero is on the axis (autoZero).
699
853
  const crossing = at(Math.min(scale.max, Math.max(scale.min, 0)));
700
- for (const tick of scale.ticks) {
701
- const position = at(tick), label = formatTick(tick, percent, valueFormat);
854
+ for (const tick of hidden ? [] : scale.ticks) {
855
+ const position = at(tick), label = formatTick(tick, percent, valueFormat, tickGroup);
702
856
  if (horizontal) {
703
857
  gridline(c, position, plot.y, position, plot.y + plot.height);
704
858
  const width = c.width(label) + fontPx;
@@ -710,15 +864,16 @@ function renderCategoryChart(c, spec) {
710
864
  }
711
865
  }
712
866
  const band = (horizontal ? plot.height : plot.width) / count;
713
- if (spec.kind === "bar") drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale, categorySlot });
867
+ if (spec.kind === "bar") drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale, categorySlot, rowTop });
714
868
  else if (spec.kind === "line") drawLines(c, spec, series, stacks, { plot, band, at, categorySlot });
715
- else drawAreas(c, series, stacks, { plot, band, at, crossing, categorySlot });
869
+ else drawAreas(c, series, stacks, { plot, band, at, crossing, categorySlot, edge: labelPlot !== undefined && labelPlot !== plot });
870
+ // The value axis line goes with its tick labels (LH-03); the category axis line stays, at zero.
716
871
  if (horizontal) {
717
872
  axisLine(c, crossing, plot.y, crossing, plot.y + plot.height);
718
- axisLine(c, plot.x, plot.y + plot.height, plot.x + plot.width, plot.y + plot.height);
873
+ if (!hidden) axisLine(c, plot.x, plot.y + plot.height, plot.x + plot.width, plot.y + plot.height);
719
874
  } else {
720
875
  const valueAxisX = rtl ? plot.x + plot.width : plot.x;
721
- axisLine(c, valueAxisX, plot.y, valueAxisX, plot.y + plot.height);
876
+ if (!hidden) axisLine(c, valueAxisX, plot.y, valueAxisX, plot.y + plot.height);
722
877
  axisLine(c, plot.x, crossing, plot.x + plot.width, crossing);
723
878
  }
724
879
  }
@@ -733,7 +888,7 @@ export function barGeometry(band, seriesCount, grouping) {
733
888
  return { group: width, width, offset: (band - width) / 2, clustered: false };
734
889
  }
735
890
 
736
- function drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale, categorySlot = (i) => i }) {
891
+ function drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale, categorySlot = (i) => i, rowTop = (i) => plot.y + i * band }) {
737
892
  // Bars grow from zero, or from the axis minimum (maximum, for all-negative data) when zero is off the axis.
738
893
  const base = (value) => Math.min(scale.max, Math.max(scale.min, value));
739
894
  const geometry = barGeometry(band, series.length, spec.grouping);
@@ -747,8 +902,8 @@ function drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale,
747
902
  const path = `${c.path}.data.rows.${i}.${s.column}`;
748
903
  let rect;
749
904
  if (horizontal) {
750
- // Office bar charts draw the first category and first series nearest the origin (bottom).
751
- const y = plot.y + plot.height - i * band - geometry.offset - slot - geometry.width;
905
+ // LH-59: the first category and its first series at the top (PowerPoint's reversed category axis, c:orientation maxMin).
906
+ const y = rowTop(i) + geometry.offset + slot;
752
907
  rect = { x: Math.min(a, b), y, width: Math.abs(b - a), height: geometry.width };
753
908
  c.mark("rect", { ...rect, fill: color }, path);
754
909
  } else {
@@ -756,7 +911,7 @@ function drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale,
756
911
  rect = { x, y: Math.min(a, b), width: geometry.width, height: Math.abs(b - a) };
757
912
  c.mark("rect", { ...rect, fill: color }, path);
758
913
  }
759
- if (c.dataLabels) labels.push({ rect, direction: horizontal ? (point.to >= point.from ? "right" : "left") : (point.to >= point.from ? "up" : "down"), path, color, text: labelString(c, { category: c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]), value: s.values[i], format: s.format }) });
914
+ if (c.dataLabels && c.stackValues?.[j]?.[i] !== false) labels.push({ rect, direction: horizontal ? (point.to >= point.from ? "right" : "left") : (point.to >= point.from ? "up" : "down"), path, color, text: labelString(c, { category: c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]), value: s.values[i], format: s.format, group: s.group }) });
760
915
  });
761
916
  });
762
917
  // RR-35: data labels sit on top of every bar.
@@ -786,26 +941,106 @@ function drawLines(c, spec, series, stacks, { plot, band, at, categorySlot = (i)
786
941
  }
787
942
  // RR-35: data labels sit beside each point, over every line.
788
943
  if (c.dataLabels) series.forEach((s, j) => stacks[j].forEach((point, i) => {
789
- if (point) drawPointLabel(c, labelString(c, { category: c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]), value: s.values[i], format: s.format }), [plot.x + (categorySlot(i) + 0.5) * band, at(point.to)], `${c.path}.data.rows.${i}.${s.column}`);
944
+ if (point) drawPointLabel(c, labelString(c, { category: c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]), value: s.values[i], format: s.format, group: s.group }), [plot.x + (categorySlot(i) + 0.5) * band, at(point.to)], `${c.path}.data.rows.${i}.${s.column}`);
790
945
  }));
946
+ // LH-105: each series' last value and name at the end of its line ("61 Enterprise NPS"), in the box core placed it
947
+ // (chart-direct-labels.ts), in its colour made legible as text; bold for a series the title names.
948
+ for (const entry of c.endLabels?.entries ?? []) {
949
+ const s = series[entry.series];
950
+ if (!s) continue;
951
+ const fill = chartSeriesLabelColor(c.surface, c.highlight ? seriesColor(c, entry.series) : c.strongColors[entry.series % c.strongColors.length]);
952
+ const element = c.svg.renderTextBox(entry.text ?? entry.name, entry.box, c.bound, {
953
+ path: c.tracePath(`${c.path}.data.columns.${s.column}`), fontSize: c.fontPx / c.u, fontFamily: c.bound.design.fonts.body, fontWeight: entry.bold ? 700 : 400,
954
+ fill, options: c.options, align: rtl(c) ? "right" : "left", verticalAlign: "middle"
955
+ });
956
+ if (element) c.children.push(element);
957
+ }
791
958
  }
792
959
 
793
- function drawAreas(c, series, stacks, { plot, band, at, crossing, categorySlot = (i) => i }) {
960
+ const rtl = (c) => c.bound.geometry?.direction === "rtl";
961
+
962
+ function drawAreas(c, series, stacks, { plot, band, at, crossing, categorySlot = (i) => i, edge = false }) {
963
+ // LH-125: an edge-to-edge area (core layer.stack.edge) stands on its points: the first at the plot's start, the last at its end.
964
+ const pointX = edge ? (i) => plot.x + categorySlot(i) * plot.width / (stacks[0].length - 1) : (i) => plot.x + (categorySlot(i) + 0.5) * band;
794
965
  for (let j = 0; j < series.length; j++) {
795
966
  const s = series[j];
796
- const points = stacks[j].map((point, i) => ({ x: plot.x + (categorySlot(i) + 0.5) * band, from: point.from, to: point.to }));
967
+ const points = stacks[j].map((point, i) => ({ x: pointX(i), from: point.from, to: point.to }));
797
968
  const upper = points.map((p) => `${c.num(p.x)} ${c.num(at(p.to))}`);
798
969
  const lower = points.slice().reverse().map((p) => `${c.num(p.x)} ${c.num(p.from === 0 ? crossing : at(p.from))}`);
799
970
  c.mark("path", { d: `M ${upper.join(" L ")} L ${lower.join(" L ")} Z`, fill: seriesColor(c, j) }, `${c.path}.data.columns.${s.column}`);
800
971
  }
801
972
  // RR-35: an area's label sits in the area at each category, halfway between its lower and upper edge.
802
973
  if (c.dataLabels) series.forEach((s, j) => stacks[j].forEach((point, i) => {
803
- if (!point) return;
974
+ if (!point || c.stackValues?.[j]?.[i] === false) return;
804
975
  const lowerEdge = point.from === 0 ? crossing : at(point.from);
805
- drawCenteredLabel(c, labelString(c, { category: c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]), value: s.values[i], format: s.format }), plot.x + (categorySlot(i) + 0.5) * band, (lowerEdge + at(point.to)) / 2, `${c.path}.data.rows.${i}.${s.column}`, seriesColor(c, j));
976
+ drawCenteredLabel(c, labelString(c, { category: c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]), value: s.values[i], format: s.format, group: s.group }), pointX(i), (lowerEdge + at(point.to)) / 2, `${c.path}.data.rows.${i}.${s.column}`, seriesColor(c, j));
806
977
  }));
807
978
  }
808
979
 
980
+ // LH-110: the reference lines the title names, dashed across the plot in the chart text color, each labeled bold in the text color
981
+ // where core placed the label (the plot's start, under or over the line).
982
+ function drawReferenceLines(c, lines) {
983
+ for (const line of lines ?? []) {
984
+ c.mark("line", { x1: line.x1, y1: line.y, x2: line.x2, y2: line.y, stroke: c.chartTextColor, "stroke-width": c.pt, "stroke-dasharray": `${c.num(4 * c.pt)} ${c.num(3 * c.pt)}` });
985
+ c.text(line.text, line.label, c.path, rtl(c) ? "right" : "left", c.labelColor, 700);
986
+ }
987
+ }
988
+
989
+ // LH-125: the values at the first and last points of an edge-to-edge stacked area, inside the band at the plot's edges, in the color that
990
+ // contrasts with the series' fill, aligned to the edge, in the box core placed them.
991
+ function drawStackEnds(c, ends) {
992
+ for (const entry of ends ?? []) {
993
+ const s = c.series()[entry.series];
994
+ if (!s) continue;
995
+ c.text(entry.text, entry.box, `${c.path}.data.rows.${entry.row}.${s.column}`, entry.align, labelFill(c, "center", seriesColor(c, entry.series)));
996
+ }
997
+ }
998
+
999
+ // LH-109: the series names beside a stacked chart's last column or band, each a swatch in the series color and the name in the chart
1000
+ // text color (bold, in the text color, for a series the title names), in the box core placed it.
1001
+ function drawStackNames(c, names) {
1002
+ for (const entry of names?.entries ?? []) {
1003
+ const s = c.series()[entry.series];
1004
+ if (!s) continue;
1005
+ const swatch = names.swatch, middle = entry.box.y + entry.box.height / 2, path = `${c.path}.data.columns.${s.column}`;
1006
+ const x = rtl(c) ? entry.box.x + entry.box.width - swatch : entry.box.x;
1007
+ c.mark("rect", { x, y: middle - swatch / 2, width: swatch, height: swatch, fill: seriesColor(c, entry.series) }, path);
1008
+ const textX = rtl(c) ? entry.box.x : entry.box.x + swatch + c.fontPx * 0.4;
1009
+ c.text(entry.name, { x: textX, y: entry.box.y, width: Math.max(1, entry.box.width - swatch - c.fontPx * 0.4), height: entry.box.height }, path, rtl(c) ? "right" : "left", entry.bold ? c.labelColor : c.chartTextColor, entry.bold ? 700 : 400);
1010
+ }
1011
+ }
1012
+
1013
+ // LH-108: the value list beside a pie (core chartValueList): the unit over the values, then one row per category: a swatch in the
1014
+ // slice's color, the category and its value at the row's end, a hairline between rows. The rows the title names are bold in the text
1015
+ // color; the others (when some are bold) in the chart text color.
1016
+ function drawValueList(c, list) {
1017
+ const end = rtl(c) ? "left" : "right", start = rtl(c) ? "right" : "left";
1018
+ const emphasis = list.rows.some((row) => row.bold);
1019
+ if (list.header) c.text(list.header.text, list.header.box, `${c.path}.data.columns.1`, end);
1020
+ list.rows.forEach((row, index) => {
1021
+ const { box } = row, middle = box.y + box.height / 2, path = `${c.path}.data.rows.${row.row}.1`;
1022
+ if (index) gridline(c, box.x, box.y, box.x + box.width, box.y);
1023
+ const swatchX = rtl(c) ? box.x + box.width - list.swatch : box.x;
1024
+ c.mark("rect", { x: swatchX, y: middle - list.swatch / 2, width: list.swatch, height: list.swatch, fill: sliceColor(c, row.row) }, `${c.path}.data.rows.${row.row}.0`);
1025
+ const fill = row.bold || !emphasis ? c.labelColor : c.chartTextColor, weight = row.bold ? 700 : 400;
1026
+ const inner = { x: box.x + (rtl(c) ? 0 : list.swatch + list.gap), y: box.y, width: Math.max(1, box.width - list.swatch - list.gap), height: box.height };
1027
+ c.text(row.value, inner, path, end, fill, weight);
1028
+ const valueWidth = c.width(row.value) * (row.bold ? 1.08 : 1) + c.fontPx;
1029
+ c.text(row.name, { ...inner, x: rtl(c) ? inner.x + valueWidth : inner.x, width: Math.max(1, inner.width - valueWidth) }, `${c.path}.data.rows.${row.row}.0`, start, fill, weight);
1030
+ });
1031
+ // LH-125: a doughnut prints the value of the slice the title names in its hole, large and bold in the slice's color made legible as text,
1032
+ // its category under it in the chart text color.
1033
+ const hole = list.hole;
1034
+ if (hole) {
1035
+ const element = c.svg.renderTextBox(hole.value.text, hole.value.box, c.bound, {
1036
+ path: c.tracePath(`${c.path}.data.rows.${hole.row}.1`), fontSize: hole.value.size / c.u, fontFamily: c.bound.design.fonts.body, fontWeight: 700,
1037
+ fill: chartSeriesLabelColor(c.surface, sliceColor(c, hole.row)), options: c.options, align: "center", verticalAlign: "middle"
1038
+ });
1039
+ if (element) c.children.push(element);
1040
+ if (hole.name) c.text(hole.name.text, hole.name.box, `${c.path}.data.rows.${hole.row}.0`, "center");
1041
+ }
1042
+ }
1043
+
809
1044
  // ---------------------------------------------------------------------------
810
1045
  // Combo (FA-15): clustered columns and line series with markers in one plot. Core's resolveChartData orders the series
811
1046
  // (column series first, then lines) and says which lines use the secondary value axis. That axis sits at the right (the left,
@@ -863,8 +1098,9 @@ function renderComboChart(c, spec) {
863
1098
  const axis = planCategoryAxis(c, entries, (reserve) => {
864
1099
  const height = Math.max(1, box.y + box.height - pad - reserve - top);
865
1100
  const intervals = chartIntervalsFor(height, c.lineHeight * 1.2, c.u);
866
- const scale = niceScale(primaryMin, primaryMax, intervals);
867
- const secondary = secondaryLines.length ? niceScale(secondaryMin, secondaryMax, intervals) : null;
1101
+ // The two axes share the gridlines, so each ends on a tick (LH-59 endOnTick).
1102
+ const scale = niceScale(primaryMin, primaryMax, intervals, { endOnTick: true });
1103
+ const secondary = secondaryLines.length ? niceScale(secondaryMin, secondaryMax, intervals, { endOnTick: true }) : null;
868
1104
  const primaryWidth = tickWidthOf(scale, primaryFormat), secondaryWidth = secondary ? tickWidthOf(secondary, secondaryFormat) : 0;
869
1105
  const leftWidth = rtl ? secondaryWidth : primaryWidth, rightWidth = rtl ? primaryWidth : secondaryWidth;
870
1106
  const x = box.x + pad + (leftWidth || fontPx / 2);
@@ -910,7 +1146,7 @@ function renderComboChart(c, spec) {
910
1146
  if (c.dataLabels) for (const s of lines) s.values.forEach((value, i) => {
911
1147
  if (value === null) return;
912
1148
  const category = c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]);
913
- drawPointLabel(c, labelString(c, { category, value, format: s.format }), point(s, i, value), `${c.path}.data.rows.${i}.${s.column}`, c.dataLabels.linePosition ?? "above");
1149
+ drawPointLabel(c, labelString(c, { category, value, format: s.format, group: s.group }), point(s, i, value), `${c.path}.data.rows.${i}.${s.column}`, c.dataLabels.linePosition ?? "above");
914
1150
  });
915
1151
  const primaryX = rtl ? plot.x + plot.width : plot.x, secondaryX = rtl ? plot.x : plot.x + plot.width;
916
1152
  axisLine(c, primaryX, plot.y, primaryX, plot.y + plot.height);
@@ -919,50 +1155,87 @@ function renderComboChart(c, spec) {
919
1155
  }
920
1156
 
921
1157
  // ---------------------------------------------------------------------------
922
- // Pie and doughnut: first series only, clockwise from 12 o'clock, one colour per category.
1158
+ // Pie and doughnut: clockwise from 12 o'clock, one colour per category; a doughnut of several series draws one ring per series (LH-60).
923
1159
 
924
1160
  function renderCircularChart(c, spec) {
925
1161
  const { box, pad } = c;
926
1162
  const categories = c.rows.map((row) => c.label(row[0]));
927
- const values = c.rows.map((row) => Math.abs(chartNumber(row[1]) ?? 0));
1163
+ // LH-60: a doughnut of several series (core's nested-rings fallback, a pie of several series included) draws one ring per series, the
1164
+ // first innermost as PowerPoint orders a doughnut's rings; a pie and a one-series doughnut draw the first series.
1165
+ const columns = spec.kind === "doughnut" && c.columns.length > 2 ? c.columns.slice(1).map((_, j) => j + 1) : [1];
1166
+ const rings = columns.map((column) => {
1167
+ const values = c.rows.map((row) => Math.abs(chartNumber(row[column]) ?? 0));
1168
+ const total = values.reduce((sum, value) => sum + value, 0);
1169
+ if (!Number.isFinite(total)) throw chartAggregateError(c.path, "slice total");
1170
+ return { column, values, total };
1171
+ });
928
1172
  const legendWidth = legendEntries(c, categories.map((name, i) => ({
929
1173
  name, color: sliceColor(c, i), path: `${c.path}.data.rows.${i}.0`
930
1174
  })));
931
- const area = { 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) };
1175
+ // LH-108: with a value list, the pie fills the square core gave it.
1176
+ 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) };
932
1178
  const cx = area.x + area.width / 2, cy = area.y + area.height / 2;
933
- const total = values.reduce((sum, value) => sum + value, 0);
934
- if (!Number.isFinite(total)) throw chartAggregateError(c.path, "slice total");
935
1179
  // 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.
936
- const sliceTexts = c.dataLabels ? values.map((value, i) => labelString(c, { category: categories[i], value: chartNumber(c.rows[i][1]) ?? 0, share: total ? value / total : 0, format: c.formats[1] })) : null;
937
- const outside = sliceTexts && spec.kind === "pie" && (c.dataLabels.position ?? "outside-end") === "outside-end";
938
- const reserve = outside ? outsideLabelReserve(c, sliceTexts) : { x: 0, y: 0 };
939
- const r = 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);
940
- const inner = spec.kind === "doughnut" ? r * 0.5 : 0;
941
- if (!total) {
1180
+ 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;
1181
+ // LH-105: core's slice labels say per slice whether the name sits inside or outside; only the outside names take room around the pie.
1182
+ const slicePosition = (i) => c.sliceLabels ? (c.sliceLabels.get(i) === "outside" ? "outside-end" : "inside-end") : undefined;
1183
+ 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
+ const outside = outsideTexts.length > 0;
1185
+ 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);
1187
+ const hole = spec.kind === "doughnut" ? r * 0.5 : 0;
1188
+ if (rings.every((ring) => !ring.total)) {
942
1189
  c.text("No positive chart values", area, c.path);
943
1190
  return;
944
1191
  }
945
1192
  const border = { stroke: c.outlineColor, "stroke-width": 0.75 * c.pt };
946
- let angle = -Math.PI / 2;
947
- values.forEach((value, i) => {
948
- const delta = value / total * Math.PI * 2, end = angle + delta;
949
- const fill = sliceColor(c, i), path = `${c.path}.data.rows.${i}.1`;
950
- if (delta >= Math.PI * 2 - 1e-9) {
951
- if (inner) c.mark("path", { d: `${circlePath(c, cx, cy, r)} ${circlePath(c, cx, cy, inner)}`, fill, "fill-rule": "evenodd", ...border }, path);
952
- else c.mark("circle", { cx, cy, r, fill, ...border }, path);
953
- } else if (delta > 0) {
954
- c.mark("path", { d: slicePath(c, cx, cy, r, inner, angle, end), fill, ...border }, path);
955
- }
956
- angle = end;
1193
+ const thickness = (r - hole) / rings.length;
1194
+ rings.forEach((ring, j) => {
1195
+ const inner = hole + j * thickness, outer = inner + thickness;
1196
+ let angle = -Math.PI / 2;
1197
+ ring.values.forEach((value, i) => {
1198
+ if (!ring.total) return;
1199
+ const delta = value / ring.total * Math.PI * 2, end = angle + delta;
1200
+ const fill = sliceColor(c, i), path = `${c.path}.data.rows.${i}.${ring.column}`;
1201
+ if (delta >= Math.PI * 2 - 1e-9) {
1202
+ if (inner) c.mark("path", { d: `${circlePath(c, cx, cy, outer)} ${circlePath(c, cx, cy, inner)}`, fill, "fill-rule": "evenodd", ...border }, path);
1203
+ else c.mark("circle", { cx, cy, r: outer, fill, ...border }, path);
1204
+ } else if (delta > 0) {
1205
+ c.mark("path", { d: slicePath(c, cx, cy, outer, inner, angle, end), fill, ...border }, path);
1206
+ }
1207
+ angle = end;
1208
+ });
957
1209
  });
958
- if (sliceTexts) {
1210
+ // LH-92: core names each ring on its largest slice (layer.rings): the series name, before that slice's own label text when it has one,
1211
+ // as PowerPoint writes a label that shows the series name.
1212
+ const named = new Map(rings.length > 1 ? (c.ringNames ?? []).map((entry) => [entry.series, entry]) : []);
1213
+ const separator = c.dataLabels?.separator ?? ", ";
1214
+ rings.forEach((ring, j) => {
1215
+ const name = named.get(ring.column - 1);
1216
+ if (!ringTexts && !name) return;
1217
+ const inner = hole + j * thickness;
959
1218
  let start = -Math.PI / 2;
960
- values.forEach((value, i) => {
961
- const delta = value / total * Math.PI * 2;
962
- if (delta > 0) drawSliceLabel(c, sliceTexts[i], { cx, cy, r, inner, mid: start + delta / 2 }, `${c.path}.data.rows.${i}.1`, sliceColor(c, i));
1219
+ ring.values.forEach((value, i) => {
1220
+ const delta = ring.total ? value / ring.total * Math.PI * 2 : 0;
1221
+ const own = ringTexts?.[j][i] ?? "";
1222
+ const text = name?.row === i ? (own ? `${name.name}${separator}${own}` : name.name) : own;
1223
+ const slice = { cx, cy, r: inner + thickness, inner, mid: start + delta / 2 }, path = `${c.path}.data.rows.${i}.${ring.column}`;
1224
+ if (delta > 0 && text && name?.row === i) drawRingName(c, text, slice, path, sliceColor(c, i), name.rotation);
1225
+ else if (delta > 0 && text) drawSliceLabel(c, text, slice, path, sliceColor(c, i), slicePosition(i));
963
1226
  start += delta;
964
1227
  });
965
- }
1228
+ });
1229
+ if (list) drawValueList(c, list);
1230
+ }
1231
+
1232
+ // LH-92: a ring's name, centred in its band at the slice's middle and turned along the ring by core's rotation (the PPTX label's
1233
+ // custom angle), in the colour that contrasts with the slice.
1234
+ function drawRingName(c, text, { cx, cy, r, inner, mid }, path, fill, rotation = 0) {
1235
+ const radius = (r + inner) / 2, x = cx + radius * Math.cos(mid), y = cy + radius * Math.sin(mid);
1236
+ const width = c.width(text) + c.fontPx * 0.5, height = c.lineHeight;
1237
+ const element = c.textElement(text, { x: x - width / 2, y: y - height / 2, width, height }, path, "center", labelFill(c, "center", fill));
1238
+ if (element) c.children.push(rotation ? c.svg.tag("g", { transform: `rotate(${c.num(rotation)} ${c.num(x)} ${c.num(y)})` }, element) : element);
966
1239
  }
967
1240
 
968
1241
  function polar(cx, cy, r, angle) {
@@ -985,8 +1258,9 @@ function slicePath(c, cx, cy, r, inner, start, end) {
985
1258
  // ---------------------------------------------------------------------------
986
1259
  // Scatter: X from columns[1], Y series from columns[2..], markers only.
987
1260
 
988
- export function scatterSeries(rows, columns, formats = []) {
989
- const numericX = columns.length > 2;
1261
+ // LH-60: `hasX` is core's (resolveChartData, then chartDrawPlan): a scatter whose X column holds no number plots every series against the row position.
1262
+ export function scatterSeries(rows, columns, formats = [], hasX = columns.length > 2) {
1263
+ const numericX = hasX;
990
1264
  const xs = rows.map((row, i) => numericX ? chartNumber(row[1]) : i + 1);
991
1265
  const first = numericX ? 2 : 1;
992
1266
  const series = columns.slice(first).map((name, offset) => ({
@@ -999,8 +1273,8 @@ export function scatterSeries(rows, columns, formats = []) {
999
1273
 
1000
1274
  function renderScatterChart(c) {
1001
1275
  const { box, pad, fontPx } = c;
1002
- const { series } = scatterSeries(c.rows, c.columns, c.formats);
1003
- const yFormat = series[0]?.format, xFormat = c.columns.length > 2 ? c.formats[1] : undefined;
1276
+ const { series } = scatterSeries(c.rows, c.columns, c.formats, c.hasX);
1277
+ const yFormat = series[0]?.format, xFormat = c.hasX ? c.formats[1] : undefined;
1004
1278
  const points = series.flatMap((s) => s.points);
1005
1279
  const xs = points.map((p) => p.x), ys = points.map((p) => p.y);
1006
1280
  const legendWidth = seriesLegend(c, series, "marker");
@@ -1036,7 +1310,7 @@ function renderScatterChart(c) {
1036
1310
  }
1037
1311
  // RR-35: a scatter label shows the Y value, and the X value as its category.
1038
1312
  if (c.dataLabels) series.forEach((s) => {
1039
- for (const point of s.points) drawPointLabel(c, labelString(c, { category: formatChartValue(point.x, xFormat), value: point.y, format: s.format }), [xAt(point.x), yAt(point.y)], `${c.path}.data.rows.${point.row}.${s.column}`);
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}`);
1040
1314
  });
1041
1315
  }
1042
1316
 
@@ -1060,7 +1334,7 @@ function renderRadarChart(c, spec) {
1060
1334
  const area = { 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) };
1061
1335
  const cx = area.x + area.width / 2, cy = area.y + area.height / 2;
1062
1336
  const radius = Math.max(1, Math.min(area.width / 2 - labelWidth, area.height / 2 - c.lineHeight - (wraps ? c.textHeight : 0)));
1063
- const scale = niceScale(values.length ? Math.min(...values) : 0, values.length ? Math.max(...values) : 1, maxIntervalsFor(radius, c.lineHeight));
1337
+ const scale = niceScale(values.length ? Math.min(...values) : 0, values.length ? Math.max(...values) : 1, maxIntervalsFor(radius, c.lineHeight), { endOnTick: true });
1064
1338
  const angle = (i) => -Math.PI / 2 + i / count * Math.PI * 2;
1065
1339
  const rAt = (v) => axisFraction(Math.min(scale.max, Math.max(scale.min, v)), scale) * radius;
1066
1340
  const point = (i, v) => polar(cx, cy, rAt(v), angle(i));
@@ -1130,7 +1404,7 @@ function renderRadarChart(c, spec) {
1130
1404
  }
1131
1405
  // RR-35: radar data labels sit above each point (PowerPoint has no position choice for a radar).
1132
1406
  if (c.dataLabels) series.forEach((s) => s.values.forEach((v, i) => {
1133
- if (v !== null) drawPointLabel(c, labelString(c, { category: categories[i], value: v, format: s.format }), point(i, v), `${c.path}.data.rows.${i}.${s.column}`);
1407
+ if (v !== null) drawPointLabel(c, labelString(c, { category: categories[i], value: v, format: s.format, group: s.group }), point(i, v), `${c.path}.data.rows.${i}.${s.column}`);
1134
1408
  }));
1135
1409
  }
1136
1410
 
@@ -1203,9 +1477,10 @@ function probeTicks(dataMin, dataMax) {
1203
1477
 
1204
1478
  // Vertical layout shared by the axis-bearing constructs: category labels below,
1205
1479
  // value ticks on the left (and a percentage axis on the right for pareto).
1206
- function chartexPlot(c, { categories, legendWidth = 0, tickLabels = [], percentAxis = false }) {
1480
+ function chartexPlot(c, { categories, legendWidth = 0, tickLabels = [], percentAxis = false, labelRoom = false }) {
1207
1481
  const { box, pad, fontPx } = c;
1208
- const top = box.y + pad + c.lineHeight / 2;
1482
+ // LH-107: a waterfall without its value axis keeps a line above the tallest bar for its label.
1483
+ const top = box.y + pad + (labelRoom ? c.lineHeight : c.lineHeight / 2);
1209
1484
  const tickWidth = Math.max(0, ...tickLabels.map((label) => c.width(label))) + fontPx * 0.5;
1210
1485
  const x = box.x + pad + tickWidth;
1211
1486
  const right = box.x + box.width - pad - legendWidth - (percentAxis ? c.width("100%") + fontPx : fontPx / 2);
@@ -1280,35 +1555,44 @@ function renderHistogramChart(c, spec) {
1280
1555
  }
1281
1556
 
1282
1557
  // Waterfall: floating bars from the running total, increases and decreases in the first two palette colours, connector lines between bars.
1558
+ // LH-59: a last value equal to the running sum of the steps before it is a total (core's waterfallSteps): it stands on zero in the third
1559
+ // palette colour, as PowerPoint draws the cx:subtotals point the export writes.
1560
+ // LH-107: core's roles (layer.waterfall): totals in the strong color, gains in the accent, losses in the context gray (core
1561
+ // chartWaterfallColors), signed default labels (a total's bold and unsigned), dashed connectors and, with default labels, no value axis.
1562
+ const waterfallColor = (bar, palette) => palette[(bar.total ? 2 : bar.value < 0 ? 1 : 0) % palette.length];
1283
1563
  function renderWaterfallChart(c) {
1284
1564
  const { column, values, categories } = chartexValues(c.rows, c.columns);
1285
1565
  const format = c.formats[column];
1286
- let running = 0;
1287
- const bars = values.map((value, i) => {
1288
- if (value === null) return null;
1289
- const from = running;
1290
- running += value;
1291
- if (!Number.isFinite(running)) throw chartAggregateError(c.path, "running total");
1292
- return { i, value, from, to: running };
1293
- }).filter(Boolean);
1566
+ const layer = c.waterfall;
1567
+ const bars = waterfallSteps(values, c.path).map((step) => ({ ...step, i: step.index, role: layer?.roles[step.index] ?? null }));
1568
+ const roleColors = layer?.colors ? chartWaterfallColors(c.surface, c.strongColors[0], c.labelColor, c.bound.design.colorScheme?.dark2, { labeled: layer.labels }) : undefined;
1569
+ const colorOf = (bar) => roleColors && bar.role ? roleColors[bar.role] : waterfallColor(bar, c.colors);
1570
+ const hidden = layer?.valueAxis === false;
1294
1571
  const extents = bars.flatMap((bar) => [bar.from, bar.to]);
1295
1572
  const dataMin = extents.length ? Math.min(0, ...extents) : 0, dataMax = extents.length ? Math.max(0, ...extents) : 1;
1296
- const probe = { ticks: probeTicks(dataMin, dataMax) };
1297
- 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)) });
1573
+ 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 });
1298
1575
  const scale = niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1299
- const { at } = valueAxis(c, plot, scale, format);
1576
+ let at;
1577
+ if (hidden) {
1578
+ // The category axis line stays, at zero; the labels carry the values.
1579
+ at = (value) => plot.y + axisFraction(value, scale, true) * plot.height;
1580
+ const crossing = at(Math.min(scale.max, Math.max(scale.min, 0)));
1581
+ axisLine(c, plot.x, crossing, plot.x + plot.width, crossing);
1582
+ } else ({ at } = valueAxis(c, plot, scale, format));
1300
1583
  const width = band / 1.5, offset = (band - width) / 2;
1301
1584
  bars.forEach((bar, k) => {
1302
1585
  const a = at(bar.from), b = at(bar.to);
1303
1586
  const x = plot.x + bar.i * band + offset;
1304
- c.mark("rect", { x, y: Math.min(a, b), width, height: Math.abs(b - a), fill: c.colors[bar.value < 0 ? 1 : 0] }, `${c.path}.data.rows.${bar.i}.${column}`);
1587
+ c.mark("rect", { x, y: Math.min(a, b), width, height: Math.abs(b - a), fill: colorOf(bar) }, `${c.path}.data.rows.${bar.i}.${column}`);
1305
1588
  const next = bars[k + 1];
1306
- if (next) c.mark("line", { x1: x + width, y1: b, x2: plot.x + next.i * band + offset, y2: b, stroke: c.axisColor, "stroke-width": c.pt });
1589
+ if (next) c.mark("line", { x1: x + width, y1: b, x2: plot.x + next.i * band + offset, y2: b, stroke: c.axisColor, "stroke-width": c.pt, ...(layer ? { "stroke-dasharray": `${c.num(4 * c.pt)} ${c.num(3 * c.pt)}` } : {}) });
1307
1590
  });
1308
1591
  // RR-35: data labels show each step's value (not the running total) on the floating bars.
1309
1592
  if (c.dataLabels) bars.forEach((bar) => {
1310
1593
  const a = at(bar.from), b = at(bar.to);
1311
- drawBarLabel(c, labelString(c, { category: categories[bar.i], value: bar.value, format }), { 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}`, c.colors[bar.value < 0 ? 1 : 0]);
1594
+ const text = c.waterfallSigned ? waterfallLabelText(bar.value, format, bar.role) : labelString(c, { category: categories[bar.i], value: bar.value, format });
1595
+ 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);
1312
1596
  });
1313
1597
  }
1314
1598
 
@@ -1334,7 +1618,7 @@ function renderFunnelChart(c) {
1334
1618
  c.mark("rect", { x, y: y + offset, width, height, fill: c.colors[0] }, `${c.path}.data.rows.${i}.${column}`);
1335
1619
  // RR-35: the funnel labels its bars with values by default; dataLabels picks the content, false removes them.
1336
1620
  if (c.dataLabelsOff) return;
1337
- c.text(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}`);
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]);
1338
1622
  });
1339
1623
  }
1340
1624
 
@@ -1404,7 +1688,7 @@ function renderTreemapChart(c) {
1404
1688
  // RR-35: the treemap labels its tiles with category names by default; dataLabels picks the content, false removes them. PowerPoint
1405
1689
  // draws the label at the bottom left of its tile whatever the position attribute says (native check 2026-10-01), so the preview does.
1406
1690
  if (!c.dataLabelsOff && rect.width >= fontPx * 2 && rect.height >= c.lineHeight) {
1407
- c.text(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`, "left");
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");
1408
1692
  }
1409
1693
  });
1410
1694
  }
@@ -1479,6 +1763,13 @@ function renderBoxWhiskerChart(c) {
1479
1763
  });
1480
1764
  }
1481
1765
 
1766
+ // LH-56: a label inside a mark (a treemap tile, a funnel bar, a map tile) takes core's markLabelColor for that fill: the full text colour
1767
+ // when it reaches 4.5:1 on the fill, else the slide background, else black or white, as the PPTX export writes the same labels.
1768
+ function insideText(c, value, rect, path, fill, align = "center") {
1769
+ const element = c.textElement(value, rect, path, align, markLabelColor(fill, c.labelColor, c.bound.design.colors.background));
1770
+ if (element) c.children.push(element);
1771
+ }
1772
+
1482
1773
  /** Mix two hex colours (#RRGGBB) by `t` in [0, 1], rounded per channel. */
1483
1774
  export function mixHex(from, to, t) {
1484
1775
  const channel = (hex, i) => parseInt(hex.slice(1 + 2 * i, 3 + 2 * i), 16);
@@ -1506,13 +1797,14 @@ function renderRegionMapChart(c) {
1506
1797
  const value = values[i];
1507
1798
  const t = value === null ? 0 : max > min ? axisFraction(value, {min, max}) : 1;
1508
1799
  const x = area.x + (i % columns) * tileWidth, y = area.y + Math.floor(i / columns) * tileHeight;
1509
- c.mark("rect", { x, y, width: tileWidth, height: tileHeight, fill: value === null ? c.surface : mixHex(light, c.colors[0], t), stroke: c.outlineColor, "stroke-width": c.pt }, `${c.path}.data.rows.${i}.${column}`);
1800
+ const tile = value === null ? c.surface : mixHex(light, c.colors[0], t);
1801
+ c.mark("rect", { x, y, width: tileWidth, height: tileHeight, fill: tile, stroke: c.outlineColor, "stroke-width": c.pt }, `${c.path}.data.rows.${i}.${column}`);
1510
1802
  const inset = { x: x + fontPx * 0.25, width: Math.max(1, tileWidth - fontPx * 0.5) };
1511
1803
  if (tileHeight >= c.lineHeight * 2) {
1512
- c.text(name, { ...inset, y: y + tileHeight / 2 - c.lineHeight, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`);
1513
- if (value !== null) c.text(formatTick(value, false, format), { ...inset, y: y + tileHeight / 2, height: c.lineHeight }, `${c.path}.data.rows.${i}.${column}`);
1804
+ insideText(c, name, { ...inset, y: y + tileHeight / 2 - c.lineHeight, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`, tile);
1805
+ if (value !== null) insideText(c, formatTick(value, false, format), { ...inset, y: y + tileHeight / 2, height: c.lineHeight }, `${c.path}.data.rows.${i}.${column}`, tile);
1514
1806
  } else if (tileHeight >= c.lineHeight) {
1515
- c.text(name, { ...inset, y: y + (tileHeight - c.lineHeight) / 2, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`);
1807
+ insideText(c, name, { ...inset, y: y + (tileHeight - c.lineHeight) / 2, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`, tile);
1516
1808
  }
1517
1809
  });
1518
1810
  }