@openpresentation/opf-render 0.33.0 → 0.34.1

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,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 { 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";
7
+ import { chartAxisFraction as axisFraction, chartAxisScale as composedScale, chartBarGeometry, chartBarSeriesOffset, chartDrawPlan, chartSlicePlan, CHART_SLICE_SEPARATOR_PX, histogramBins, paretoPlan, scottBinCount, chartWaterfallColors, waterfallLabelText, markLabelColor, chartEmphasisColors, chartSeriesLabelColor, chartContextColors, chartFocusContextColors, chartSeriesStrokes, 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, formatNumber, formatPercentNumber, chartNumberLanguage } 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
@@ -56,7 +56,9 @@ function focusFor(c, layer, spec) {
56
56
  const series = c.columns.slice(1).map((_, j) => focus.series?.includes(j) === true);
57
57
  // A series focus: the unnamed series are the context, in order. A category focus: every series has context marks.
58
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));
59
+ // A series drawn as a stroke (a line, a combo's line) keeps the ordinary floor even when labeled (core chartFocusContextColors).
60
+ const avoid = series.map((_, j) => j).filter((j) => focus.categories ? true : series[j]).map(strong);
61
+ const grays = chartFocusContextColors(c.surface, c.labelColor, rest, { labeled: focus.labeled === true, strokes: chartSeriesStrokes(spec.kind, series.length, c.combo), avoid });
60
62
  const mutedSeries = series.map((_, j) => grays[Math.max(0, rest.indexOf(j))]);
61
63
  return { series, categories, accent: strong(0), muted: grays[0], accents: series.map((_, j) => strong(j)), mutedSeries };
62
64
  }
@@ -198,14 +200,14 @@ export function renderCatalogChart(item, box, bound, options, svg) {
198
200
  // LH-105: direct labels instead of a legend: the series names at the line ends, the category names on the slices.
199
201
  c.endLabels = layer?.endLabels;
200
202
  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
+ // Shared chart marks: waterfall roles, pie value lists, stacked values/names and explicit references.
203
204
  c.waterfall = layer?.waterfall;
204
205
  c.histogram = layer?.histogram;
205
206
  c.valueList = layer?.valueList;
206
207
  // LH-182: a doughnut's square and its hole (core), the hole filled with the surface.
207
208
  c.doughnut = layer?.doughnut;
208
209
  c.stack = layer?.stack;
210
+ c.references = layer?.references;
209
211
  if (layer?.valueList || layer?.stack?.names) c.legendManaged = true;
210
212
  // 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.
211
213
  const inset = layer?.plot;
@@ -214,6 +216,10 @@ export function renderCatalogChart(item, box, bound, options, svg) {
214
216
  // from the top of the chart box, taken before the header row narrows c.box.
215
217
  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) };
216
218
  if (layer?.header) drawHeader(c, spec, layer.header);
219
+ // RR-105: a radar whose web is larger with its legend under it (core chart-radar.ts) draws the legend as a bottom row; the PPTX export
220
+ // writes c:legendPos b. Its value axis is core's too.
221
+ c.radar = layer?.radar;
222
+ if (layer?.radar?.legend === "bottom" && resolved.legend === undefined) placeLegend(c, spec, "bottom");
217
223
  if (!resolved.active) reportOptionDiagnostics(c, resolved);
218
224
  if (resolved.active) {
219
225
  reportOptionDiagnostics(c, resolved);
@@ -238,8 +244,7 @@ export function renderCatalogChart(item, box, bound, options, svg) {
238
244
  c.dataLabels = { content: ["value"], position: "outside-end", separator: ", " };
239
245
  c.waterfallSigned = true;
240
246
  }
241
- // LH-110: the period band lies under the marks, the reference lines over them.
242
- 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`);
247
+ // Explicit reference lines are drawn over the data.
243
248
  render(c, spec);
244
249
  drawReferenceLines(c, layer?.references?.lines);
245
250
  drawStackNames(c, layer?.stack?.names);
@@ -257,7 +262,7 @@ export function chartData(item, bound) {
257
262
  const resolved = resolveChartData(chart, bound?.presentation, { path: item.path });
258
263
  if (!resolved.ok) return null;
259
264
  // LH-60: core's draw plan (the fallback construct and the data as drawn), shared with the PPTX export.
260
- const language = bound?.presentation?.language;
265
+ const language = bound?.scriptFonts?.profile?.bcp47;
261
266
  const plan = chartDrawPlan(chart, resolved, { language: typeof language === "string" ? language : undefined });
262
267
  const formats = plan.formats.map((format) => typeof format === "string" && format !== "" && !numberFormatError(format) ? format : undefined);
263
268
  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 } : {}) };
@@ -340,6 +345,8 @@ const neutrals = bound.design.roles.neutrals;
340
345
  strongColors: chartSeriesPalette(surface, bound.design.colorScheme, item.value?.colors, { accents: bound.design.roles.map.accents, roles: bound.design.colors, variables: bound.design.variables }),
341
346
  // RR-92: the value axis core composed for a column, bar, line or area chart ({ min, max, majorUnit }); absent for the other types.
342
347
  valueAxis: item.chart?.valueAxis,
348
+ secondaryValueAxis:item.chart?.secondaryValueAxis,
349
+ resolveColorRef:svg.resolveColorRef,
343
350
  numericAxes: item.chart?.layer?.numericAxes,
344
351
  gridColor: neutrals.gridline.hex,
345
352
  axisColor: neutrals.axisLine.hex,
@@ -355,7 +362,7 @@ const neutrals = bound.design.roles.neutrals;
355
362
  },
356
363
  textElement(value, rect, path, align = "center", fill = chartTextColor, weight = 400) {
357
364
  if (!(rect.width > 0 && rect.height > 0)) return "";
358
- return svg.renderTextBox(String(value), rect, bound, {
365
+ return svg.renderTextBox(isolateNumerals(String(value)), rect, bound, {
359
366
  path: tracePath(path), fontSize: requested, fontFamily: bound.design.fonts.body, fontWeight: weight,
360
367
  fill, options, align, verticalAlign: "middle"
361
368
  });
@@ -366,7 +373,8 @@ const neutrals = bound.design.roles.neutrals;
366
373
  },
367
374
  // LH-141: whether the default value labels of column `column` group their thousands (no format of its own, whole numbers, one of four digits).
368
375
  group: (column) => (formats[column] === undefined || formats[column] === "") && groupsThousands(rows.map((row) => chartNumber(row[column]))),
369
- language: bound.presentation?.language,
376
+ // LH-106: a chartex chart (waterfall, histogram, ...) draws Latin digits, as PowerPoint does (core chartNumberLanguage).
377
+ language: chartNumberLanguage(item.value, bound.scriptFonts?.profile?.bcp47),
370
378
  series(first = 1) {
371
379
  return columns.slice(first).map((name, offset) => ({
372
380
  name: c.label(name), column: first + offset, index: offset,
@@ -389,32 +397,23 @@ const neutrals = bound.design.roles.neutrals;
389
397
  export { chartNumber };
390
398
 
391
399
  /** A number as its column's format shows it (core's formatDataNumber); without a format, the General form the preview always drew. */
392
- export function formatChartValue(value, format) {
393
- if (format === undefined) return String(clean(value));
394
- return formatDataNumber(clean(value), format);
400
+ export function formatChartValue(value, format, language = undefined) {
401
+ // LH-106: in the language's numbering system (core formatNumber and formatDataNumber).
402
+ if (format === undefined) return formatNumber(clean(value), language);
403
+ return formatDataNumber(clean(value), format, language);
395
404
  }
396
405
 
397
- // ---------------------------------------------------------------------------
398
- // Shared axis and legend helpers
399
-
400
- // Keep ordinary arithmetic unchanged. A range spanning both finite endpoints
401
- // can overflow even though every value/bound is finite; divide before subtracting.
402
- function axisFraction(value, scale, reverse = false) {
403
- const range = scale.max - scale.min;
404
- const distance = reverse ? scale.max - value : value - scale.min;
405
- if (Number.isFinite(range) && Number.isFinite(distance)) return distance / (range || 1);
406
- const unit = Math.max(Math.abs(scale.min), Math.abs(scale.max));
407
- const min = scale.min / unit, max = scale.max / unit, position = value / unit;
408
- return (reverse ? max - position : position - min) / (max - min);
406
+ // LH-106: a chart number in another script's digits (٢٥%, -٣٢٠.٨, ۱٬۰۰۰) is laid out left to right as one unit wherever it is drawn:
407
+ // digits, then the percent sign, a sign before the digits, as PowerPoint draws its chart labels. Arabic-Indic digits are Arabic
408
+ // numbers in the bidi algorithm, which leave a percent or minus sign to the right-to-left paragraph; a left-to-right isolate keeps
409
+ // them together. The text is measured without the isolates, which take no width, so SVG, PNG and PDF agree.
410
+ const NUMERAL_RUN = /(?<![\p{L}\p{N}])[+\-\u2212\u00b1]?[\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef](?:[\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef]|[,.\u066b\u066c](?=[\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef]))*[%\u066a]?/gu;
411
+ export function isolateNumerals(text) {
412
+ return /[\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef]/.test(text) ? text.replace(NUMERAL_RUN, run => `\u2066${run}\u2069`) : text;
409
413
  }
410
414
 
411
- // LH-59: ticks run from min in steps of step up to max, which a tightened axis (core's niceScale) need not land on.
412
- function scaleFrom(min, max, step) {
413
- const ticks = [];
414
- const count = Math.floor((max - min) / step + 1e-9);
415
- for (let index = 0; index <= count; index++) ticks.push(clean(min + index * step));
416
- return { min, max, step, ticks };
417
- }
415
+ // ---------------------------------------------------------------------------
416
+ // Shared axis and legend helpers
418
417
 
419
418
  function clean(value) {
420
419
  const rounded = Number(value.toPrecision(12));
@@ -425,10 +424,11 @@ function clean(value) {
425
424
  * Office General / 0% tick labels; a value axis takes its first plotted series' number format (RR-54). LH-141: `group` ({ language }, an axis
426
425
  * with no format whose ticks are whole numbers of four digits, core `groupsAxisTicks`) groups the thousands by the deck language.
427
426
  */
428
- export function formatTick(value, percent = false, format = undefined, group = undefined) {
429
- if (percent) return `${clean(value * 100)}%`;
430
- if (format === undefined) return group ? groupNumber(clean(value), group.language) : String(clean(value));
431
- return formatChartValue(value, format);
427
+ export function formatTick(value, percent = false, format = undefined, group = undefined, language = group?.language) {
428
+ // LH-106: every tick is in the language's numbering system, grouped or not.
429
+ if (percent) return formatPercentNumber(clean(value * 100), language);
430
+ if (format === undefined) return group ? groupNumber(clean(value), group.language) : formatNumber(clean(value), language);
431
+ return formatChartValue(value, format, language);
432
432
  }
433
433
 
434
434
  /**
@@ -449,7 +449,7 @@ function insetForEndLabels(c, x, width, format, scaleFor) {
449
449
  for (let pass = 0; pass < 3; pass++) {
450
450
  const ticks = scale.ticks;
451
451
  if (!ticks.length) break;
452
- const first = c.width(formatTick(ticks[0], false, format)) / 2, last = c.width(formatTick(ticks[ticks.length - 1], false, format)) / 2;
452
+ const first = c.width(formatTick(ticks[0], false, format, undefined, c.language)) / 2, last = c.width(formatTick(ticks[ticks.length - 1], false, format, undefined, c.language)) / 2;
453
453
  const nextX = Math.max(x, left + first), nextWidth = Math.max(1, Math.min(x + width, right - last) - nextX);
454
454
  if (nextX === x && nextWidth === width) break;
455
455
  x = nextX; width = nextWidth; scale = scaleFor(width);
@@ -772,19 +772,11 @@ function chartAggregateError(path, aggregate) {
772
772
 
773
773
  // RR-92: a column, bar, line or area chart draws the value axis core composed for its box (c.valueAxis), the one the PPTX export
774
774
  // writes. Without it (a chart the composition has no axis for) the scale is fitted to the plot's length as before.
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
776
- // three numbers; it takes the saturating scale `niceScale` computes.
775
+ // Shared reconstruction handles finite endpoints whose span or intermediate tick product exceeds Number's range.
777
776
  function categoryScale(c, dataMin, dataMax, length, labelExtent, percent) {
778
777
  return composedScale(c.valueAxis) ?? niceScale(dataMin, dataMax, chartIntervalsFor(length, labelExtent, c.u), { percent });
779
778
  }
780
779
 
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;
786
- }
787
-
788
780
  function renderCategoryChart(c, spec) {
789
781
  const { box, pad, fontPx } = c;
790
782
  const horizontal = spec.kind === "bar" && spec.dir === "bar";
@@ -821,7 +813,7 @@ function renderCategoryChart(c, spec) {
821
813
  let x = box.x + pad + categoryWidth + c.pad / 2;
822
814
  const bottom = box.y + box.height - pad - (hidden ? 0 : c.lineHeight);
823
815
  let width = Math.max(1, right - x - fontPx - labelRoom);
824
- const tickWidth = Math.max(c.width(formatTick(dataMax, percent, valueFormat, tickGroup)), c.width(formatTick(dataMin, percent, valueFormat, tickGroup)), c.width("100%")) + fontPx;
816
+ const tickWidth = Math.max(c.width(formatTick(dataMax, percent, valueFormat, tickGroup, c.language)), c.width(formatTick(dataMin, percent, valueFormat, tickGroup, c.language)), c.width("100%")) + fontPx;
825
817
  const scaleFor = (w) => categoryScale(c, dataMin, dataMax, w, tickWidth, percent);
826
818
  scale = scaleFor(width);
827
819
  // RR-54: a formatted value axis keeps its end labels inside the chart.
@@ -829,7 +821,7 @@ function renderCategoryChart(c, spec) {
829
821
  const aligned = c.alignedRows?.centers.length === count ? c.alignedRows : undefined;
830
822
  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) };
831
823
  // 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.
832
- if (c.plotBox && !aligned) { plot = { ...c.plotBox }; scale = scaleFor(plot.width); }
824
+ if (c.plotBox && (!aligned || c.references)) { plot = { ...c.plotBox }; scale = scaleFor(plot.width); }
833
825
  // LH-59: the categories read top to bottom in data order (PowerPoint's reversed category axis, which the export writes).
834
826
  const entries = categories.map((name, i) => ({ name, path: `${c.path}.data.rows.${i}.0` }));
835
827
  const rowBand = plot.height / count;
@@ -853,7 +845,7 @@ function renderCategoryChart(c, spec) {
853
845
  } : planCategoryAxis(c, entries, (reserve) => {
854
846
  const height = Math.max(1, box.y + box.height - pad - reserve - top);
855
847
  const fitted = categoryScale(c, dataMin, dataMax, height, c.lineHeight * 1.2, percent);
856
- const tickWidth = hidden ? fontPx / 2 : Math.max(...fitted.ticks.map((tick) => c.width(formatTick(tick, percent, valueFormat, tickGroup)))) + fontPx * 0.5;
848
+ const tickWidth = hidden ? fontPx / 2 : Math.max(...fitted.ticks.map((tick) => c.width(formatTick(tick, percent, valueFormat, tickGroup, c.language)))) + fontPx * 0.5;
857
849
  if (rtl) {
858
850
  const x = box.x + pad + fontPx / 2;
859
851
  return { scale: fitted, plot: { x, y: top, width: Math.max(1, right - tickWidth - x), height }, tickWidth };
@@ -871,7 +863,7 @@ function renderCategoryChart(c, spec) {
871
863
  // Category axis crosses at zero when zero is on the axis (autoZero).
872
864
  const crossing = at(Math.min(scale.max, Math.max(scale.min, 0)));
873
865
  for (const tick of hidden ? [] : scale.ticks) {
874
- const position = at(tick), label = formatTick(tick, percent, valueFormat, tickGroup);
866
+ const position = at(tick), label = formatTick(tick, percent, valueFormat, tickGroup, c.language);
875
867
  if (horizontal) {
876
868
  gridline(c, position, plot.y, position, plot.y + plot.height);
877
869
  const width = c.width(label) + fontPx;
@@ -907,7 +899,7 @@ function drawBars(c, spec, series, stacks, { plot, band, at, horizontal, scale,
907
899
  stacks[j].forEach((point, i) => {
908
900
  if (!point) return;
909
901
  const color = markColor(c, j, i);
910
- const slot = geometry.clustered ? j * geometry.width : 0;
902
+ const slot = chartBarSeriesOffset(geometry, j, series.length, !horizontal && rtl(c));
911
903
  const a = at(base(point.from)), b = at(point.to);
912
904
  const path = `${c.path}.data.rows.${i}.${s.column}`;
913
905
  let rect;
@@ -959,7 +951,7 @@ function drawLines(c, spec, series, stacks, { plot, band, at, categorySlot = (i)
959
951
  const s = series[entry.series];
960
952
  if (!s) continue;
961
953
  const fill = chartSeriesLabelColor(c.surface, c.highlight ? seriesColor(c, entry.series) : c.strongColors[entry.series % c.strongColors.length]);
962
- const element = c.svg.renderTextBox(entry.text ?? entry.name, entry.box, c.bound, {
954
+ const element = c.svg.renderTextBox(isolateNumerals(entry.text ?? entry.name), entry.box, c.bound, {
963
955
  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,
964
956
  fill, options: c.options, align: rtl(c) ? "right" : "left", verticalAlign: "middle"
965
957
  });
@@ -974,25 +966,39 @@ function drawAreas(c, series, stacks, { plot, band, at, crossing, categorySlot =
974
966
  const pointX = edge ? (i) => plot.x + categorySlot(i) * plot.width / (stacks[0].length - 1) : (i) => plot.x + (categorySlot(i) + 0.5) * band;
975
967
  for (let j = 0; j < series.length; j++) {
976
968
  const s = series[j];
977
- const points = stacks[j].map((point, i) => ({ x: pointX(i), from: point.from, to: point.to }));
978
- const upper = points.map((p) => `${c.num(p.x)} ${c.num(at(p.to))}`);
979
- const lower = points.slice().reverse().map((p) => `${c.num(p.x)} ${c.num(p.from === 0 ? crossing : at(p.from))}`);
980
- c.mark("path", { d: `M ${upper.join(" L ")} L ${lower.join(" L ")} Z`, fill: seriesColor(c, j) }, `${c.path}.data.columns.${s.column}`);
969
+ // RR-105: a gap (null, core's stackCategoryValues) splits an unstacked area into runs of points; each run stands on the axis at its
970
+ // own first and last point, as PowerPoint draws a blank with c:dispBlanksAs "gap" (a lone point between gaps is a zero-width run).
971
+ const runs = [];
972
+ let run = [];
973
+ stacks[j].forEach((point, i) => {
974
+ if (!point) { if (run.length) runs.push(run); run = []; return; }
975
+ run.push({ x: pointX(i), from: point.from, to: point.to });
976
+ });
977
+ if (run.length) runs.push(run);
978
+ const d = runs.map((points) => {
979
+ const upper = points.map((p) => `${c.num(p.x)} ${c.num(at(p.to))}`);
980
+ const lower = points.slice().reverse().map((p) => `${c.num(p.x)} ${c.num(p.from === 0 ? crossing : at(p.from))}`);
981
+ return `M ${upper.join(" L ")} L ${lower.join(" L ")} Z`;
982
+ }).join(" ");
983
+ if (d) c.mark("path", { d, fill: seriesColor(c, j) }, `${c.path}.data.columns.${s.column}`);
981
984
  }
982
- // RR-35: an area's label sits in the area at each category, halfway between its lower and upper edge.
985
+ // RR-35: an area's label sits in the area at each category, halfway between its lower and upper edge. A gap has no label (RR-105).
983
986
  if (c.dataLabels) series.forEach((s, j) => stacks[j].forEach((point, i) => {
984
- if (!point || c.stackValues?.[j]?.[i] === false) return;
987
+ if (!point || s.values[i] === null || c.stackValues?.[j]?.[i] === false) return;
985
988
  const lowerEdge = point.from === 0 ? crossing : at(point.from);
986
989
  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));
987
990
  }));
988
991
  }
989
992
 
990
- // LH-110: the reference lines the title names, dashed across the plot in the chart text color, each labeled bold in the text color
991
- // where core placed the label (the plot's start, under or over the line).
993
+ // Explicit reference values and independent strokes, with optional labels at the endpoints core placed.
992
994
  function drawReferenceLines(c, lines) {
993
995
  for (const line of lines ?? []) {
994
- 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)}` });
995
- c.text(line.text, line.label, c.path, rtl(c) ? "right" : "left", c.labelColor, 700);
996
+ const color=line.stroke.color===undefined?c.chartTextColor:c.resolveColorRef(line.stroke.color,c.chartTextColor);
997
+ const width=line.strokeWidth,dash=line.stroke.dash==='dash'?[4*width,3*width]:line.stroke.dash==='dot'?[width,3*width]:undefined;
998
+ if(width>0)c.mark('line',{x1:line.x1,y1:line.y1,x2:line.x2,y2:line.y2,stroke:color,'stroke-width':width,...(dash?{'stroke-dasharray':dash.map(c.num).join(' ')}:{})},c.path+'.referenceLines.'+line.index);
999
+ // RR-105: a label core could not keep off the marks stands on a plate of the chart's surface (the PPTX export fills its label so).
1000
+ if(line.label!==undefined&&line.labelBox&&line.labelPlate)c.mark('rect',{...line.labelBox,fill:c.surface},c.path+'.referenceLines.'+line.index+'.label');
1001
+ if(line.label!==undefined&&line.labelBox)c.text(line.label,line.labelBox,c.path+'.referenceLines.'+line.index+'.label',line.labelAlign??'center',c.labelColor);
996
1002
  }
997
1003
  }
998
1004
 
@@ -1042,7 +1048,7 @@ function drawValueList(c, list) {
1042
1048
  // its category under it in the chart text color.
1043
1049
  const hole = list.hole;
1044
1050
  if (hole) {
1045
- const element = c.svg.renderTextBox(hole.value.text, hole.value.box, c.bound, {
1051
+ const element = c.svg.renderTextBox(isolateNumerals(hole.value.text), hole.value.box, c.bound, {
1046
1052
  path: c.tracePath(`${c.path}.data.rows.${hole.row}.1`), fontSize: hole.value.size / c.u, fontFamily: c.bound.design.fonts.body, fontWeight: 700,
1047
1053
  fill: chartSeriesLabelColor(c.surface, sliceColor(c, hole.row)), options: c.options, align: "center", verticalAlign: "middle"
1048
1054
  });
@@ -1107,21 +1113,23 @@ function renderComboChart(c, spec) {
1107
1113
  const top = box.y + pad + c.lineHeight / 2;
1108
1114
  const entries = categories.map((name, i) => ({ name, path: `${c.path}.data.rows.${i}.0` }));
1109
1115
  if (rtl) entries.reverse();
1110
- const tickWidthOf = (scale, format, group) => Math.max(...scale.ticks.map((tick) => c.width(formatTick(tick, false, format, group)))) + fontPx * 0.5;
1116
+ const tickWidthOf = (scale, format, group) => Math.max(...scale.ticks.map((tick) => c.width(formatTick(tick, false, format, group, c.language)))) + fontPx * 0.5;
1111
1117
  const axis = planCategoryAxis(c, entries, (reserve) => {
1112
1118
  const height = Math.max(1, box.y + box.height - pad - reserve - top);
1113
1119
  const intervals = chartIntervalsFor(height, c.lineHeight * 1.2, c.u);
1114
1120
  // The two axes share the gridlines, so each ends on a tick (LH-59 endOnTick).
1115
- const scale = niceScale(primaryMin, primaryMax, intervals, { endOnTick: true });
1116
- const secondary = secondaryLines.length ? niceScale(secondaryMin, secondaryMax, intervals, { endOnTick: true }) : null;
1121
+ const scale = composedScale(c.valueAxis) ?? niceScale(primaryMin, primaryMax, intervals, { endOnTick: true });
1122
+ const secondary = secondaryLines.length ? composedScale(c.secondaryValueAxis) ?? niceScale(secondaryMin, secondaryMax, intervals, { endOnTick: true }) : null;
1117
1123
  const primaryWidth = tickWidthOf(scale, primaryFormat, primaryGroup), secondaryWidth = secondary ? tickWidthOf(secondary, secondaryFormat, secondaryGroup) : 0;
1118
1124
  const leftWidth = rtl ? secondaryWidth : primaryWidth, rightWidth = rtl ? primaryWidth : secondaryWidth;
1119
1125
  const x = box.x + pad + (leftWidth || fontPx / 2);
1120
1126
  const plotRight = right - (rightWidth || fontPx / 2);
1121
1127
  return { scale, secondary, primaryWidth, secondaryWidth, plot: { x, y: top, width: Math.max(1, plotRight - x), height } };
1122
1128
  });
1123
- const { plot, scale, secondary } = axis;
1124
- drawBottomLabels(c, axis.plan, plot, entries);
1129
+ const { scale, secondary } = axis;
1130
+ const plot=c.plotBox??axis.plot;
1131
+ const categoryLabels=c.plotBox?planBottomLabels(c,entries,plot,Math.max(c.lineHeight+c.textHeight,c.box.height*0.4),{minX:plot.x-fontPx*0.5,maxX:plot.x+plot.width+fontPx*0.5,rotatedMinX:c.box.x+c.pad}):axis.plan;
1132
+ drawBottomLabels(c, categoryLabels, plot, entries);
1125
1133
  c.plotArea = plot;
1126
1134
  const valueAt = (axisScale) => (value) => plot.y + axisFraction(value, axisScale, true) * plot.height;
1127
1135
  const at = valueAt(scale), atSecondary = secondary ? valueAt(secondary) : at;
@@ -1132,9 +1140,9 @@ function renderComboChart(c, spec) {
1132
1140
  for (const tick of scale.ticks) {
1133
1141
  const position = at(tick);
1134
1142
  gridline(c, plot.x, position, plot.x + plot.width, position);
1135
- tickLabel(formatTick(tick, false, primaryFormat, primaryGroup), position, rtl ? "right" : "left", axis.primaryWidth);
1143
+ tickLabel(formatTick(tick, false, primaryFormat, primaryGroup, c.language), position, rtl ? "right" : "left", axis.primaryWidth);
1136
1144
  }
1137
- if (secondary) for (const tick of secondary.ticks) tickLabel(formatTick(tick, false, secondaryFormat, secondaryGroup), atSecondary(tick), rtl ? "left" : "right", axis.secondaryWidth);
1145
+ if (secondary) for (const tick of secondary.ticks) tickLabel(formatTick(tick, false, secondaryFormat, secondaryGroup, c.language), atSecondary(tick), rtl ? "left" : "right", axis.secondaryWidth);
1138
1146
  const band = plot.width / count;
1139
1147
  // Column series come first in core's order, so a column's palette index is its series index.
1140
1148
  if (bars.length) drawBars(c, spec, bars, stackCategoryValues(bars, count, "bar", "clustered", c.path), { plot, band, at, horizontal: false, scale, categorySlot });
@@ -1188,7 +1196,7 @@ function renderCircularChart(c, spec) {
1188
1196
  // LH-108: with a value list, the pie fills the square core gave it.
1189
1197
  const list = c.valueList;
1190
1198
  // 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) };
1199
+ const area = c.plotBox ?? (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) });
1192
1200
  const cx = area.x + area.width / 2, cy = area.y + area.height / 2;
1193
1201
  // 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.
1194
1202
  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;
@@ -1197,7 +1205,7 @@ function renderCircularChart(c, spec) {
1197
1205
  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] : [];
1198
1206
  const outside = outsideTexts.length > 0;
1199
1207
  const reserve = outside ? outsideLabelReserve(c, outsideTexts) : { x: 0, y: 0 };
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);
1208
+ const r = c.plotBox || 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);
1201
1209
  const hole = spec.kind === "doughnut" ? r * 0.5 : 0;
1202
1210
  if (rings.every((ring) => !ring.total)) {
1203
1211
  c.text("No positive chart values", area, c.path);
@@ -1300,24 +1308,25 @@ function renderScatterChart(c) {
1300
1308
  const top = box.y + pad + c.lineHeight / 2, bottom = box.y + box.height - pad - c.lineHeight;
1301
1309
  const height = Math.max(1, bottom - top);
1302
1310
  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;
1311
+ const tickWidth = Math.max(...yScale.ticks.map((tick) => c.width(formatTick(tick, false, yFormat, yGroup, c.language)))) + fontPx * 0.5;
1304
1312
  const plot = { x: box.x + pad + tickWidth, y: top, height };
1305
1313
  plot.width = Math.max(1, box.x + box.width - pad - legendWidth - fontPx - plot.x);
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;
1314
+ const xLabelWidth = Math.max(c.width(formatTick(xs.length ? Math.max(...xs) : 1, false, xFormat, xGroup, c.language)), c.width(formatTick(xs.length ? Math.min(...xs) : 0, false, xFormat, xGroup, c.language))) + fontPx;
1307
1315
  const scaleForX = (w) => niceScale(xs.length ? Math.min(...xs) : 0, xs.length ? Math.max(...xs) : 1, chartIntervalsFor(w, xLabelWidth, c.u));
1308
1316
  let xScale = composedScale(c.numericAxes?.category) ?? scaleForX(plot.width);
1309
1317
  // RR-54: a formatted X axis keeps its end labels inside the chart.
1310
1318
  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)));
1319
+ if (c.plotBox) Object.assign(plot, c.plotBox);
1311
1320
  c.plotArea = plot;
1312
1321
  const xAt = (v) => plot.x + axisFraction(v, xScale) * plot.width;
1313
1322
  const yAt = (v) => plot.y + axisFraction(v, yScale, true) * plot.height;
1314
1323
  for (const tick of yScale.ticks) {
1315
1324
  const y = yAt(tick);
1316
1325
  gridline(c, plot.x, y, plot.x + plot.width, y);
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");
1326
+ c.text(formatTick(tick, false, yFormat, yGroup, c.language), { x: box.x + pad, y: y - c.lineHeight / 2, width: plot.x - box.x - pad - fontPx * 0.35, height: c.lineHeight }, c.path, "right");
1318
1327
  }
1319
1328
  for (const tick of xScale.ticks) {
1320
- const label = formatTick(tick, false, xFormat, xGroup), width = c.width(label) + fontPx;
1329
+ const label = formatTick(tick, false, xFormat, xGroup, c.language), width = c.width(label) + fontPx;
1321
1330
  c.text(label, { x: xAt(tick) - width / 2, y: plot.y + plot.height, width, height: c.lineHeight }, c.path);
1322
1331
  }
1323
1332
  const yCross = yAt(Math.min(yScale.max, Math.max(yScale.min, 0))), xCross = xAt(Math.min(xScale.max, Math.max(xScale.min, 0)));
@@ -1329,7 +1338,7 @@ function renderScatterChart(c) {
1329
1338
  }
1330
1339
  // RR-35: a scatter label shows the Y value, and the X value as its category.
1331
1340
  if (c.dataLabels) series.forEach((s) => {
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}`);
1341
+ for (const point of s.points) drawPointLabel(c, labelString(c, { category: formatChartValue(point.x, xFormat, c.language), 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}`);
1333
1342
  });
1334
1343
  }
1335
1344
 
@@ -1353,7 +1362,7 @@ function renderRadarChart(c, spec) {
1353
1362
  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) };
1354
1363
  const cx = area.x + area.width / 2, cy = area.y + area.height / 2;
1355
1364
  const radius = Math.max(1, Math.min(area.width / 2 - labelWidth, area.height / 2 - c.lineHeight - (wraps ? c.textHeight : 0)));
1356
- const scale = niceScale(values.length ? Math.min(...values) : 0, values.length ? Math.max(...values) : 1, maxIntervalsFor(radius, c.lineHeight), { endOnTick: true });
1365
+ const scale = (c.radar && composedScale(c.radar.axis)) ?? niceScale(values.length ? Math.min(...values) : 0, values.length ? Math.max(...values) : 1, maxIntervalsFor(radius, c.lineHeight), { endOnTick: true });
1357
1366
  const angle = (i) => -Math.PI / 2 + i / count * Math.PI * 2;
1358
1367
  const rAt = (v) => axisFraction(Math.min(scale.max, Math.max(scale.min, v)), scale) * radius;
1359
1368
  const point = (i, v) => polar(cx, cy, rAt(v), angle(i));
@@ -1418,7 +1427,7 @@ function renderRadarChart(c, spec) {
1418
1427
  }
1419
1428
  // Value axis labels sit on top of filled series, as in PowerPoint.
1420
1429
  for (const tick of scale.ticks) {
1421
- const label = formatTick(tick, false, valueFormat), width = c.width(label) + fontPx * 0.5;
1430
+ const label = formatTick(tick, false, valueFormat, undefined, c.language), width = c.width(label) + fontPx * 0.5;
1422
1431
  c.text(label, { x: cx - width - fontPx * 0.2, y: cy - rAt(tick) - c.lineHeight / 2, width, height: c.lineHeight }, c.path, "right");
1423
1432
  }
1424
1433
  // RR-35: radar data labels sit above each point (PowerPoint has no position choice for a radar).
@@ -1477,7 +1486,7 @@ function valueAxis(c, plot, scale, format, group) {
1477
1486
  for (const tick of scale.ticks) {
1478
1487
  const y = at(tick);
1479
1488
  gridline(c, plot.x, y, plot.x + plot.width, y);
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");
1489
+ c.text(formatTick(tick, false, format, group, c.language), { 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");
1481
1490
  }
1482
1491
  const crossing = at(Math.min(scale.max, Math.max(scale.min, 0)));
1483
1492
  axisLine(c, plot.x, plot.y, plot.x, plot.y + plot.height);
@@ -1497,8 +1506,9 @@ function renderHistogramChart(c, spec) {
1497
1506
  } else {
1498
1507
  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 }));
1499
1508
  }
1500
- if (pareto) bars = bars.slice().sort((a, b) => b.value - a.value);
1501
- const total = bars.reduce((sum, bar) => sum + Math.max(0, bar.value), 0);
1509
+ const cumulative = pareto ? paretoPlan(bars) : undefined;
1510
+ if (cumulative) bars = cumulative.bars;
1511
+ const total = cumulative?.total ?? bars.reduce((sum, bar) => sum + Math.max(0, bar.value), 0);
1502
1512
  if (!Number.isFinite(total)) throw chartAggregateError(c.path, "cumulative total");
1503
1513
  const dataMax = bars.length ? Math.max(...bars.map((bar) => bar.value)) : 1, dataMin = bars.length ? Math.min(0, ...bars.map((bar) => bar.value)) : 0;
1504
1514
  // RR-105: the value axis core composed (layer.histogram.valueAxis), which the PPTX export writes as the chartex cx:valScaling.
@@ -1506,7 +1516,7 @@ function renderHistogramChart(c, spec) {
1506
1516
  const probe = { ticks: composed ? composed.ticks : probeTicks(dataMin, dataMax) };
1507
1517
  // LH-153: the labels and the value axis group their thousands (a histogram's bin counts too) unless the column has a format.
1508
1518
  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 });
1519
+ 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, c.language)), percentAxis: pareto });
1510
1520
  const scale = composed ?? niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1511
1521
  const { at, crossing } = valueAxis(c, plot, scale, format, tickGroup);
1512
1522
  const width = band / 1.06, offset = (band - width) / 2;
@@ -1527,12 +1537,10 @@ function renderHistogramChart(c, spec) {
1527
1537
  axisLine(c, right, plot.y, right, plot.y + plot.height);
1528
1538
  for (const tick of percent.ticks) {
1529
1539
  const y = plot.y + axisFraction(tick, percent, true) * plot.height;
1530
- c.text(formatTick(tick, true), { x: right + c.fontPx * 0.35, y: y - c.lineHeight / 2, width: c.box.x + c.box.width - c.pad - right - c.fontPx * 0.35, height: c.lineHeight }, c.path, "left");
1540
+ c.text(formatTick(tick, true, undefined, undefined, c.language), { x: right + c.fontPx * 0.35, y: y - c.lineHeight / 2, width: c.box.x + c.box.width - c.pad - right - c.fontPx * 0.35, height: c.lineHeight }, c.path, "left");
1531
1541
  }
1532
- let running = 0;
1533
1542
  const points = bars.map((bar, i) => {
1534
- running += Math.max(0, bar.value);
1535
- const fraction = total ? running / total : 0;
1543
+ const fraction = cumulative.cumulative[i];
1536
1544
  return `${c.num(plot.x + (i + 0.5) * band)},${c.num(plot.y + axisFraction(fraction, percent, true) * plot.height)}`;
1537
1545
  });
1538
1546
  c.mark("polyline", { points: points.join(" "), fill: "none", stroke: c.colors[1 % c.colors.length], "stroke-width": 2 * c.pt, "stroke-linejoin": "round", "stroke-linecap": "round" }, `${c.path}.data.columns.${column}`);
@@ -1558,7 +1566,7 @@ function renderWaterfallChart(c) {
1558
1566
  const probe = { ticks: hidden ? [] : probeTicks(dataMin, dataMax) };
1559
1567
  // 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
1568
  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 });
1569
+ 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, c.language)), labelRoom: hidden });
1562
1570
  const scale = composedScale(c.numericAxes?.value) ?? niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1563
1571
  let at;
1564
1572
  if (hidden) {
@@ -1578,7 +1586,7 @@ function renderWaterfallChart(c) {
1578
1586
  // RR-35: data labels show each step's value (not the running total) on the floating bars.
1579
1587
  if (c.dataLabels) bars.forEach((bar) => {
1580
1588
  const a = at(bar.from), b = at(bar.to);
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 });
1589
+ const text = c.waterfallSigned ? waterfallLabelText(bar.value, format, bar.role, labelGroup ? { language: typeof c.language === "string" ? c.language : undefined } : undefined, c.language) : labelString(c, { category: categories[bar.i], value: bar.value, format, group: labelGroup });
1582
1590
  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);
1583
1591
  });
1584
1592
  }
@@ -1607,7 +1615,7 @@ function renderFunnelChart(c) {
1607
1615
  c.mark("rect", { x, y: y + offset, width, height, fill: c.colors[0] }, `${c.path}.data.rows.${i}.${column}`);
1608
1616
  // RR-35: the funnel labels its bars with values by default; dataLabels picks the content, false removes them.
1609
1617
  if (c.dataLabelsOff) return;
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]);
1618
+ insideText(c, c.dataLabels ? labelString(c, { category: name, value, format, group }) : formatTick(value, false, format, grouping, c.language), { x: plot.x, y: y + offset, width: plot.width, height }, `${c.path}.data.rows.${i}.${column}`, c.colors[0]);
1611
1619
  });
1612
1620
  }
1613
1621
 
@@ -1727,7 +1735,7 @@ function renderBoxWhiskerChart(c) {
1727
1735
  const probe = { ticks: probeTicks(dataMin, dataMax) };
1728
1736
  // 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
1737
  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)) });
1738
+ 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, c.language)) });
1731
1739
  const scale = composedScale(c.numericAxes?.value) ?? niceScale(dataMin, dataMax, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u));
1732
1740
  const { at } = valueAxis(c, plot, scale, format, tickGroup);
1733
1741
  const group = band / 2, width = group / series.length, offset = (band - group) / 2;
@@ -1793,7 +1801,7 @@ function renderRegionMapChart(c) {
1793
1801
  const inset = { x: x + fontPx * 0.25, width: Math.max(1, tileWidth - fontPx * 0.5) };
1794
1802
  if (tileHeight >= c.lineHeight * 2) {
1795
1803
  insideText(c, name, { ...inset, y: y + tileHeight / 2 - c.lineHeight, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`, tile);
1796
- if (value !== null) insideText(c, formatTick(value, false, format), { ...inset, y: y + tileHeight / 2, height: c.lineHeight }, `${c.path}.data.rows.${i}.${column}`, tile);
1804
+ if (value !== null) insideText(c, formatTick(value, false, format, undefined, c.language), { ...inset, y: y + tileHeight / 2, height: c.lineHeight }, `${c.path}.data.rows.${i}.${column}`, tile);
1797
1805
  } else if (tileHeight >= c.lineHeight) {
1798
1806
  insideText(c, name, { ...inset, y: y + (tileHeight - c.lineHeight) / 2, height: c.lineHeight }, `${c.path}.data.rows.${i}.0`, tile);
1799
1807
  }
@@ -8,6 +8,11 @@ export interface BrowserToPngOptions extends ToSvgOptions {
8
8
  scale?: number;
9
9
  /** A CSS colour painted first (default white); `"transparent"` keeps the alpha channel. */
10
10
  background?: string;
11
+ /**
12
+ * How the SVG is handed to the browser's image decoder: a `blob:` URL (default) or a `data:` URL, for a page whose Content-Security-Policy
13
+ * allows `data:` images but not `blob:` ones (the sandbox of an MCP App). A `blob:` URL that does not load is tried again as `data:`.
14
+ */
15
+ svgSource?: "blob" | "data";
11
16
  signal?: AbortSignal;
12
17
  }
13
18
 
@@ -15,6 +20,8 @@ export interface BrowserToPngOptions extends ToSvgOptions {
15
20
  export interface BrowserToPdfOptions extends Omit<ToSvgOptions, "fonts" | "onDiagnostic">, Pick<ToPdfOptions, "raster" | "background" | "serifFamily" | "metadata" | "tagged" | "compress" | "strict" | "rasterFallbackScale" | "defaultFontFamily" | "sansSerifFamily" | "monospaceFamily" | "onDiagnostic"> {
16
21
  /** `raster: true`: pixel density of each page image (default 2). */
17
22
  scale?: number;
23
+ /** As for `toPng`: how a slide drawn as an image (a raster PDF, or a part the vector PDF cannot draw) reaches the image decoder. */
24
+ svgSource?: "blob" | "data";
18
25
  /**
19
26
  * `raster: true` only: the pdf-lib module (`import * as pdfLib from "pdf-lib"`), an optional peer of the renderer that this entry never imports itself, so a
20
27
  * bundle of it holds no PDF library. Without it a raster PDF tries to import "pdf-lib" by name and rejects with `OPFRenderError` `converter-missing`
@@ -36,7 +36,7 @@ async function svgPng(svg, options = {}) {
36
36
  const width = Math.max(1, Math.round(size.width * scale)), height = Math.max(1, Math.round(size.height * scale));
37
37
  if (width * height > MAX_PIXELS) throw new OPFRenderError("png-render-failed", `The PNG would be ${width} by ${height} pixels; the limit is ${MAX_PIXELS / 1e6} megapixels.`, { width, height });
38
38
  options.signal?.throwIfAborted?.();
39
- const image = await loadSvgImage(text, options.signal);
39
+ const image = await loadSvgImage(text, options.signal, options.svgSource);
40
40
  const { canvas, context } = createCanvas(width, height);
41
41
  const background = options.background ?? "#FFFFFF";
42
42
  if (background && background !== "transparent" && background !== "none") { context.fillStyle = background; context.fillRect(0, 0, width, height); }
@@ -83,7 +83,7 @@ export async function toPdf(source, slides, options) {
83
83
  producer: packageName,
84
84
  ErrorClass: OPFRenderError,
85
85
  // The element's own text has no fonts in a standalone SVG image: give it the faces the slides embed.
86
- rasterize: async (svg, factor) => ({ png: await svgPng(fontCss && /<text[\s>]/.test(svg) ? svg.replace(/(<svg\b[^>]*>)/, `$1<style>${fontCss}</style>`) : svg, { scale: factor, background: "transparent", signal: options.signal }) }),
86
+ rasterize: async (svg, factor) => ({ png: await svgPng(fontCss && /<text[\s>]/.test(svg) ? svg.replace(/(<svg\b[^>]*>)/, `$1<style>${fontCss}</style>`) : svg, { scale: factor, background: "transparent", signal: options.signal, svgSource: options.svgSource }) }),
87
87
  });
88
88
  }
89
89
 
@@ -96,7 +96,7 @@ async function rasterPdf(inputs, options) {
96
96
  for (const [index, svg] of inputs.entries()) {
97
97
  options.signal?.throwIfAborted?.();
98
98
  const size = pageSize(svg);
99
- const png = await svgPng(svg, { scale, background: options.background ?? "#FFFFFF", signal: options.signal });
99
+ const png = await svgPng(svg, { scale, background: options.background ?? "#FFFFFF", signal: options.signal, svgSource: options.svgSource });
100
100
  const image = await pdf.embedPng(png);
101
101
  pdf.addPage([size.width, size.height]).drawImage(image, { x: 0, y: 0, width: size.width, height: size.height });
102
102
  options.onProgress?.({ page: index + 1, pages: inputs.length });
@@ -132,9 +132,12 @@ async function canvasPng(canvas) {
132
132
  return new Uint8Array(await blob.arrayBuffer());
133
133
  }
134
134
 
135
- async function loadSvgImage(text, signal) {
136
- const url = URL.createObjectURL(new Blob([text], { type: "image/svg+xml;charset=utf-8" }));
137
- try {
135
+ // The SVG reaches the browser's image decoder by URL: a blob: URL by default, or a data: URL (`svgSource: "data"`) for a page whose
136
+ // Content-Security-Policy allows data: images but not blob: ones (the sandbox of an MCP App). A blob: URL that does not load is tried
137
+ // again as data:, so a page that did not say still gets its picture.
138
+ async function loadSvgImage(text, signal, source = "blob") {
139
+ if (source !== "blob" && source !== "data") throw new OPFRenderError("invalid-conversion-option", 'svgSource must be "blob" or "data".', { option: "svgSource", value: source });
140
+ const load = async (url) => {
138
141
  const image = new Image();
139
142
  image.decoding = "sync";
140
143
  const loaded = new Promise((resolve, reject) => {
@@ -147,6 +150,15 @@ async function loadSvgImage(text, signal) {
147
150
  // Fonts the SVG embeds as data: faces load with the image; decode() settles the picture before the first draw.
148
151
  try { await image.decode(); } catch { /* drawn below as the browser has it */ }
149
152
  return image;
153
+ };
154
+ const asData = () => load(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(text)}`);
155
+ if (source === "data") return asData();
156
+ const url = URL.createObjectURL(new Blob([text], { type: "image/svg+xml;charset=utf-8" }));
157
+ try {
158
+ return await load(url);
159
+ } catch (error) {
160
+ if (signal?.aborted) throw error;
161
+ return asData();
150
162
  } finally {
151
163
  // The decoded image keeps its own copy; the URL is no longer needed once loaded.
152
164
  setTimeout(() => URL.revokeObjectURL(url), 0);