@bino-bi/bn-template-engine 1.0.0-next.49 → 1.0.0-next.51

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.
Files changed (107) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/p-0cad5598.entry.js +1 -0
  3. package/dist/bn-template-engine/{p-2de524d0.entry.js → p-150bdb68.entry.js} +1 -1
  4. package/dist/bn-template-engine/{p-Bxa4pX1M.js → p-Bvunba5p.js} +1 -1
  5. package/dist/bn-template-engine/p-NxJ6P79y.js +1 -0
  6. package/dist/bn-template-engine/{p-8fc90dc8.entry.js → p-b75a4b52.entry.js} +1 -1
  7. package/dist/bn-template-engine/{p-510d2ee6.entry.js → p-fdf42a77.entry.js} +1 -1
  8. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +1045 -63
  9. package/dist/cjs/bn-grid.cjs.entry.js +1 -1
  10. package/dist/cjs/bn-image.cjs.entry.js +1 -1
  11. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  12. package/dist/cjs/bn-text.cjs.entry.js +2 -2
  13. package/dist/cjs/loader.cjs.js +1 -1
  14. package/dist/cjs/{withStyled-pkdctrK9.js → withStyled-BISQLGLe.js} +9 -0
  15. package/dist/cjs/{withTranslation-BIzTNYZM.js → withTranslation-B7T30EVU.js} +1 -1
  16. package/dist/collection/components/bn-annotation-layer/bn-annotation-layer.js +109 -11
  17. package/dist/collection/components/bn-annotation-layer/utils/marks.js +126 -4
  18. package/dist/collection/components/bn-annotation-layer/utils/matchPoint.js +2 -1
  19. package/dist/collection/components/bn-chart-structure/bn-chart-structure-renderer/bn-chart-structure-renderer.js +133 -0
  20. package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +258 -2
  21. package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +507 -27
  22. package/dist/collection/components/bn-chart-structure/utils/elements/Bar.js +3 -1
  23. package/dist/collection/components/bn-chart-structure/utils/elements/Label.js +12 -0
  24. package/dist/collection/components/bn-chart-structure/utils/elements/StackedBar.js +23 -8
  25. package/dist/collection/components/bn-chart-structure/utils/helper/ElementPositions.js +19 -3
  26. package/dist/collection/components/bn-chart-structure/utils/model/StructureChartComponentConfig.js +23 -0
  27. package/dist/collection/components/bn-context/bn-context.js +56 -1
  28. package/dist/collection/components/bn-layout-card/bn-layout-card.js +62 -2
  29. package/dist/collection/utils/formatter.js +13 -2
  30. package/dist/collection/utils/validate.js +9 -0
  31. package/dist/components/bn-annotation-layer.js +1 -1
  32. package/dist/components/bn-chart-bubble-renderer.js +1 -1
  33. package/dist/components/bn-chart-bubble.js +1 -1
  34. package/dist/components/bn-chart-bullet-renderer.js +1 -1
  35. package/dist/components/bn-chart-bullet.js +1 -1
  36. package/dist/components/bn-chart-scatter-renderer.js +1 -1
  37. package/dist/components/bn-chart-scatter.js +1 -1
  38. package/dist/components/bn-chart-structure-renderer.js +1 -1
  39. package/dist/components/bn-chart-structure.js +1 -1
  40. package/dist/components/bn-chart-time-renderer.js +1 -1
  41. package/dist/components/bn-chart-time.js +1 -1
  42. package/dist/components/bn-context.js +1 -1
  43. package/dist/components/bn-grid.js +1 -1
  44. package/dist/components/bn-image.js +1 -1
  45. package/dist/components/bn-layout-card.js +1 -1
  46. package/dist/components/bn-layout-page.js +1 -1
  47. package/dist/components/bn-page.js +1 -1
  48. package/dist/components/bn-table-renderer.js +1 -1
  49. package/dist/components/bn-table.js +1 -1
  50. package/dist/components/bn-text.js +1 -1
  51. package/dist/components/bn-title-renderer.js +1 -1
  52. package/dist/components/bn-title.js +1 -1
  53. package/dist/components/bn-tree.js +1 -1
  54. package/dist/components/p-BOwmXBm-.js +1 -0
  55. package/dist/components/p-Bs5V6Ibu.js +1 -0
  56. package/dist/components/{p-CVfmhtEW.js → p-CU9CdEBF.js} +1 -1
  57. package/dist/components/{p-Cc0gaLwp.js → p-CZSp0rSS.js} +1 -1
  58. package/dist/components/p-CcfvGlBq.js +1 -0
  59. package/dist/components/p-CiljAoC5.js +1 -0
  60. package/dist/components/p-D0v9GMIf.js +1 -0
  61. package/dist/components/{p-DBj1Yd3M.js → p-D65TnLS9.js} +1 -1
  62. package/dist/components/p-DKcw-1ot.js +1 -0
  63. package/dist/components/{p-k7heRDPP.js → p-DLmQ_mi7.js} +1 -1
  64. package/dist/components/p-DOKqRsAu.js +1 -0
  65. package/dist/components/p-Dpc8_R-Y.js +1 -0
  66. package/dist/components/p-LHIKI9Dp.js +1 -0
  67. package/dist/components/{p-Blre9f28.js → p-NdDdfez6.js} +1 -1
  68. package/dist/components/p-Zz3fAPcH.js +1 -0
  69. package/dist/components/{p-y12CmIFS.js → p-dSUX43yf.js} +1 -1
  70. package/dist/components/p-jEqo8YD5.js +1 -0
  71. package/dist/esm/bn-annotation-layer_30.entry.js +1045 -63
  72. package/dist/esm/bn-grid.entry.js +1 -1
  73. package/dist/esm/bn-image.entry.js +1 -1
  74. package/dist/esm/bn-template-engine.js +1 -1
  75. package/dist/esm/bn-text.entry.js +2 -2
  76. package/dist/esm/loader.js +1 -1
  77. package/dist/esm/{withStyled-B62R20Zx.js → withStyled-CrTxIZ0Q.js} +9 -0
  78. package/dist/esm/{withTranslation-BEseMLQ6.js → withTranslation-BtSJmx1J.js} +1 -1
  79. package/dist/schemas/stack.schema.json +42 -0
  80. package/dist/types/components/bn-annotation-layer/utils/marks.d.ts +53 -0
  81. package/dist/types/components/bn-annotation-layer/utils/matchPoint.d.ts +2 -0
  82. package/dist/types/components/bn-chart-structure/bn-chart-structure-renderer/bn-chart-structure-renderer.d.ts +11 -1
  83. package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +49 -0
  84. package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +45 -0
  85. package/dist/types/components/bn-chart-structure/utils/elements/Label.d.ts +4 -0
  86. package/dist/types/components/bn-chart-structure/utils/elements/StackedBar.d.ts +13 -1
  87. package/dist/types/components/bn-chart-structure/utils/helper/ElementPositions.d.ts +13 -1
  88. package/dist/types/components/bn-chart-structure/utils/model/StructureChartComponentConfig.d.ts +23 -0
  89. package/dist/types/components/bn-context/bn-context.d.ts +11 -0
  90. package/dist/types/components/bn-layout-card/bn-layout-card.d.ts +12 -0
  91. package/dist/types/components.d.ts +113 -2
  92. package/dist/types/schemas.d.ts +12 -0
  93. package/dist/types/utils/annotations.d.ts +1 -1
  94. package/dist/types/utils/formatter.d.ts +5 -0
  95. package/package.json +1 -1
  96. package/dist/bn-template-engine/p-BFl7OwcC.js +0 -1
  97. package/dist/bn-template-engine/p-c1d679af.entry.js +0 -1
  98. package/dist/components/p-B11cXOLy.js +0 -1
  99. package/dist/components/p-BVNOmHh4.js +0 -1
  100. package/dist/components/p-CHhxQoF9.js +0 -1
  101. package/dist/components/p-CO6bgquz.js +0 -1
  102. package/dist/components/p-CmvpJzLd.js +0 -1
  103. package/dist/components/p-CuUfiEu0.js +0 -1
  104. package/dist/components/p-DHloMyxV.js +0 -1
  105. package/dist/components/p-Dd1QOWDV.js +0 -1
  106. package/dist/components/p-HVN8BNWN.js +0 -1
  107. package/dist/components/p-x0W2_FAX.js +0 -1
@@ -2,8 +2,8 @@
2
2
 
3
3
  var index = require('./index-DwBbheYB.js');
4
4
  var withHasError = require('./withHasError-CZFrIJw0.js');
5
- var withStyled = require('./withStyled-pkdctrK9.js');
6
- var withTranslation = require('./withTranslation-BIzTNYZM.js');
5
+ var withStyled = require('./withStyled-BISQLGLe.js');
6
+ var withTranslation = require('./withTranslation-B7T30EVU.js');
7
7
  var withBodyObserver = require('./withBodyObserver-CIGVLQEB.js');
8
8
  var localFrame = require('./localFrame-C4RBw_zT.js');
9
9
  var types = require('./types-BngAWYMW.js');
@@ -249,9 +249,12 @@ function buildMark(item, box, toBox, em, options = {}) {
249
249
  }
250
250
  if (item.mark === "frame") {
251
251
  // a text of its own stands in the upper part of the target, above a value label in its middle
252
- const caption = item.text != null && !whole
253
- ? { x: box.x + box.width / 2, y: box.y + Math.min(box.height / 2, Math.max(0.9 * em, 0.3 * box.height)) }
254
- : undefined;
252
+ const caption = item.text == null || whole
253
+ ? undefined
254
+ : options.label
255
+ ? // right of a value label, so both can be read
256
+ { x: box.x + box.width + 0.7 * em + textWidth(item.text, em) / 2, y: box.y + box.height / 2 }
257
+ : { x: box.x + box.width / 2, y: box.y + Math.min(box.height / 2, Math.max(0.9 * em, 0.3 * box.height)) };
255
258
  const captionBox = caption && {
256
259
  x: caption.x - textWidth(item.text, em) / 2,
257
260
  y: caption.y - 0.6 * em,
@@ -302,7 +305,20 @@ function buildMark(item, box, toBox, em, options = {}) {
302
305
  const size = (label == null ? 0.4 : 0.75) * unit;
303
306
  const r = isRow ? Math.min(size, box.height / 2) : size;
304
307
  let at = whole ? { x: box.x + box.width - r, y: box.y + r } : centre(box);
305
- if (!whole && options.stacked && ((_c = item.point) === null || _c === void 0 ? void 0 : _c.part) !== "label" && ((_d = item.point) === null || _d === void 0 ? void 0 : _d.part) !== "total") {
308
+ if (!whole && options.label) {
309
+ // right of the label of a chart, not on it
310
+ at = { x: box.x + box.width + 0.25 * unit + r, y: box.y + box.height / 2 };
311
+ }
312
+ else if (!whole && options.stacked && options.horizontal) {
313
+ // in a wide segment right of its label, like in a table. Else on the upper edge at its end.
314
+ // The total behind the bar stays free in both cases.
315
+ const beside = 1.3 * unit + r;
316
+ at =
317
+ box.width / 2 >= beside + r
318
+ ? { x: box.x + box.width / 2 + beside, y: box.y + box.height / 2 }
319
+ : { x: box.x + box.width - Math.min(r, box.width / 2), y: box.y };
320
+ }
321
+ else if (!whole && options.stacked && ((_c = item.point) === null || _c === void 0 ? void 0 : _c.part) !== "label" && ((_d = item.point) === null || _d === void 0 ? void 0 : _d.part) !== "total") {
306
322
  // on the upper right corner: the label in the middle and a name beside the segment stay free
307
323
  at = { x: box.x + box.width, y: box.y + Math.min(0.5 * r, box.height / 2) };
308
324
  }
@@ -317,6 +333,112 @@ function buildMark(item, box, toBox, em, options = {}) {
317
333
  }
318
334
  return { kind: "marker", color, badge: keepInside({ cx: at.x, cy: at.y, r, label }, area) };
319
335
  }
336
+ /**
337
+ * The difference of two bars that run from left to right. `levels` are the x of the
338
+ * two values. The bar of the difference lies in the gap below the second row, or above
339
+ * it when that row is the upper one. A thin line runs from each value to it, and the
340
+ * label stands right of it.
341
+ */
342
+ function buildHorizontalDifference(item, box, toBox, fromValue, toValue, em, levels) {
343
+ var _a;
344
+ if (fromValue == null || toValue == null)
345
+ return undefined;
346
+ const difference = toValue - fromValue;
347
+ const digits = Number.isInteger(item.digits) && item.digits >= 0 ? item.digits : 1;
348
+ const good = item.sentiment === "good-down" ? difference <= 0 : difference >= 0;
349
+ const direction = toBox.y + toBox.height / 2 >= box.y + box.height / 2 ? 1 : -1;
350
+ const edge = (of) => (direction === 1 ? of.y + of.height : of.y);
351
+ const barHeight = 0.25 * em;
352
+ const barY = edge(toBox) + direction * 0.25 * em;
353
+ const left = Math.min(levels.from, levels.to);
354
+ const right = Math.max(levels.from, levels.to);
355
+ const percent = item.percent && fromValue !== 0 ? `(${signed((difference / Math.abs(fromValue)) * 100, 0)}%)` : undefined;
356
+ const value = signed(difference, digits);
357
+ const textX = right + 0.5 * em;
358
+ const valueWidth = value.length * 0.5 * em;
359
+ const percentWidth = percent ? textWidth(percent, 0.85 * em) : 0;
360
+ const percentX = textX + valueWidth + 0.35 * em;
361
+ return {
362
+ kind: "difference",
363
+ color: (_a = item.color) !== null && _a !== void 0 ? _a : (good ? "positive" : "negative"),
364
+ lines: [
365
+ { x1: levels.from, y1: edge(box), x2: levels.from, y2: barY },
366
+ { x1: levels.to, y1: edge(toBox), x2: levels.to, y2: barY },
367
+ ],
368
+ bar: { x: left, y: barY - barHeight / 2, width: Math.max(right - left, 1), height: barHeight },
369
+ text: { x: textX, y: barY, anchor: "start", value, percent },
370
+ frame: percent && item.highlight
371
+ ? {
372
+ x: percentX - 0.25 * em,
373
+ y: barY - 0.65 * em,
374
+ width: percentWidth + 0.5 * em,
375
+ height: 1.3 * em,
376
+ r: 0.65 * em,
377
+ }
378
+ : undefined,
379
+ badge: item.label != null ? { cx: left - 0.9 * em, cy: barY, r: 0.65 * em, label: item.label } : undefined,
380
+ };
381
+ }
382
+ /** A thick arrow that points down at `tip`: the value end of a bar, or the top of a column. */
383
+ function buildPointer(item, at, em) {
384
+ const x = at.x;
385
+ const tip = at.y - 0.15 * em;
386
+ const neck = tip - 0.7 * em;
387
+ const top = tip - 1.9 * em;
388
+ const head = 0.55 * em;
389
+ const shaft = 0.22 * em;
390
+ const points = [
391
+ [x, tip],
392
+ [x - head, neck],
393
+ [x - shaft, neck],
394
+ [x - shaft, top],
395
+ [x + shaft, top],
396
+ [x + shaft, neck],
397
+ [x + head, neck],
398
+ ];
399
+ return {
400
+ kind: "pointer",
401
+ color: item.color,
402
+ shape: points.map(([px, py]) => `${px},${py}`).join(" "),
403
+ badge: item.label != null ? { cx: x + 1.1 * em, cy: top + 0.65 * em, r: 0.65 * em, label: item.label } : undefined,
404
+ };
405
+ }
406
+ /**
407
+ * A bracket around a range of rows of a chart with bars from left to right. A line
408
+ * runs below the last row from `left` to the end of its bar, and from there up to the
409
+ * end of the bar of the first row. `ends` are the x of the two values. `text` stands
410
+ * in a frame at the left, above the first row.
411
+ */
412
+ function buildBracket(item, first, last, ends, left, text, em) {
413
+ const firstIsUpper = first.y <= last.y;
414
+ const [upper, lower] = firstIsUpper ? [first, last] : [last, first];
415
+ const [upperEnd, lowerEnd] = firstIsUpper ? [ends.first, ends.last] : [ends.last, ends.first];
416
+ const bottom = lower.y + lower.height + 0.2 * em;
417
+ const points = [
418
+ [left, bottom],
419
+ [lowerEnd, bottom],
420
+ [upperEnd, upper.y - 0.1 * em],
421
+ ];
422
+ const width = text ? textWidth(text, em) : 0;
423
+ const captionY = upper.y - 0.9 * em;
424
+ const caption = text ? { x: left + 0.5 * em + width / 2, y: captionY, text } : undefined;
425
+ // the number stands behind the text, or in its place
426
+ const badgeX = caption ? caption.x + width / 2 + 1.2 * em : left + 0.65 * em;
427
+ return {
428
+ kind: "bracket",
429
+ color: item.color,
430
+ path: points.map(([px, py]) => `${px},${py}`).join(" "),
431
+ caption,
432
+ frame: caption && {
433
+ x: caption.x - width / 2 - 0.45 * em,
434
+ y: caption.y - 0.7 * em,
435
+ width: width + 0.9 * em,
436
+ height: 1.4 * em,
437
+ r: 0.7 * em,
438
+ },
439
+ badge: item.label != null ? { cx: badgeX, cy: captionY, r: 0.65 * em, label: item.label } : undefined,
440
+ };
441
+ }
320
442
 
321
443
  const KEY_FIELDS = ["rowGroup", "category", "subCategory", "date", "scenario", "row"];
322
444
  /** A point without a field, or no point at all, means the component as a whole. */
@@ -341,17 +463,30 @@ function matchPoint(state, point) {
341
463
  const noThereof = state.table != null && point.subCategory == null;
342
464
  return candidates
343
465
  .filter((candidate) => matches(candidate.point, point) && !(noThereof && candidate.point.subCategory != null))
344
- .map(({ rect, content, contentSign, value, scenario }) => ({
466
+ .map(({ rect, content, contentSign, value, scenario, kind }) => ({
345
467
  rect,
346
468
  content,
347
469
  contentSign,
348
470
  value,
349
471
  stacked: typeof scenario === "string" && scenario.startsWith("stack:"),
472
+ label: kind === "label",
350
473
  }));
351
474
  }
352
475
 
353
476
  const bnAnnotationLayerCss = () => `:host{position:absolute;inset:0;z-index:1;display:block;pointer-events:none;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px)}svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}.badge-text{fill:#ffffff;font-weight:bold;text-anchor:middle;dominant-baseline:central}.mark-text{fill:#000000;dominant-baseline:central}.mark-text.caption{text-anchor:middle;font-size:0.9em}.mark-text .percent{font-size:0.85em}.difference-line{stroke:#000000;stroke-width:0.75}`;
354
477
 
478
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
479
+ var t = {};
480
+ for (var p in s)
481
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
482
+ t[p] = s[p];
483
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
484
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
485
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
486
+ t[p[i]] = s[p[i]];
487
+ }
488
+ return t;
489
+ };
355
490
  /** A chart can draw its data late: a point without a match is reported when the page has been quiet for two checks. */
356
491
  const REPORT_CHECK_MS = 200;
357
492
  const REPORT_MAX_CHECKS = 50;
@@ -453,12 +588,12 @@ const AnnotationLayer = class {
453
588
  (_a = document.fonts) === null || _a === void 0 ? void 0 : _a.addEventListener("loadingdone", this.schedule);
454
589
  }
455
590
  disconnectedCallback() {
456
- var _a, _b, _c, _d;
591
+ var _a, _b, _e, _f;
457
592
  (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
458
593
  (_b = this.mutationObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
459
- (_c = document.fonts) === null || _c === void 0 ? void 0 : _c.removeEventListener("loadingdone", this.schedule);
594
+ (_e = document.fonts) === null || _e === void 0 ? void 0 : _e.removeEventListener("loadingdone", this.schedule);
460
595
  this.run++;
461
- if ((_d = this.stores) === null || _d === void 0 ? void 0 : _d.annotationsUnplaced.state[this.pageKey]) {
596
+ if ((_f = this.stores) === null || _f === void 0 ? void 0 : _f.annotationsUnplaced.state[this.pageKey]) {
462
597
  this.stores.annotationsUnplaced.set(this.pageKey, undefined);
463
598
  }
464
599
  }
@@ -483,7 +618,7 @@ const AnnotationLayer = class {
483
618
  this.parsedItems = items !== null && items !== void 0 ? items : [];
484
619
  }
485
620
  async place() {
486
- var _a, _b;
621
+ var _a, _b, _e, _f;
487
622
  const run = ++this.run;
488
623
  if (!this.element.isConnected || !this.svg)
489
624
  return;
@@ -543,8 +678,9 @@ const AnnotationLayer = class {
543
678
  return { problem: `the point ${JSON.stringify(point)} in "${id}" is cut off` };
544
679
  }
545
680
  const content = found[0].content;
546
- if (!state.table)
547
- return { box, whole: false, stacked: found[0].stacked };
681
+ if (!state.table) {
682
+ return { box, whole: false, stacked: found[0].stacked, label: found[0].label, horizontal: isHorizontal(state) };
683
+ }
548
684
  const cells = ((_a = state.elements) !== null && _a !== void 0 ? _a : []).flatMap((element) => element.kind === "cell" && element.content
549
685
  ? [{ box: onScreen(element.content), sign: element.contentSign }]
550
686
  : []);
@@ -555,6 +691,8 @@ const AnnotationLayer = class {
555
691
  obstacles: cells,
556
692
  };
557
693
  };
694
+ // the bars of a structure chart run from left to right: its value axis is an upright line
695
+ const isHorizontal = (state) => { var _a; return ((_a = state === null || state === void 0 ? void 0 : state.elements) !== null && _a !== void 0 ? _a : []).some((element) => element.kind === "axis" && element.orientation === "vertical"); };
558
696
  // a difference takes all bars of a point: the segments of a stack together are its sum
559
697
  const sumOf = (id, point) => {
560
698
  const visual = id != null ? targets.get(id) : undefined;
@@ -585,8 +723,27 @@ const AnnotationLayer = class {
585
723
  box: { x: host.left + left, y: host.top + top, width: right - left, height: bottom - top },
586
724
  negatives: bars.filter((bar) => bar.value < 0).map((bar) => screen(bar.rect.component)),
587
725
  value: bars.reduce((sum, bar) => sum + bar.value, 0),
726
+ horizontal: isHorizontal(state),
588
727
  };
589
728
  };
729
+ // the share of the rows from one point to another in all rows of the chart, for the bars the points name
730
+ const shareOf = (item, upper, lower) => {
731
+ const visual = targets.get(item.target);
732
+ const state = visual && states.get(visual);
733
+ if (!visual || !state || !item.point)
734
+ return undefined;
735
+ const host = visual.getBoundingClientRect();
736
+ const _a = item.point, series = __rest(_a, ["rowGroup", "category", "subCategory", "date"]);
737
+ const bars = matchPoint(state, Object.assign(Object.assign({}, series), { part: "element" })).filter((bar) => bar.value != null);
738
+ const all = bars.reduce((sum, bar) => sum + bar.value, 0);
739
+ const inside = bars
740
+ .filter((bar) => {
741
+ const middle = host.top + bar.rect.component.y + bar.rect.component.height / 2;
742
+ return middle >= upper.y && middle <= lower.y + lower.height;
743
+ })
744
+ .reduce((sum, bar) => sum + bar.value, 0);
745
+ return all !== 0 ? inside / all : undefined;
746
+ };
590
747
  const toLocal = this.toLocalSpace();
591
748
  // here the text runs along x and a layout px is a px, also on a rotated or scaled page
592
749
  const textToLocal = ({ box, sign = 0 }) => {
@@ -608,6 +765,20 @@ const AnnotationLayer = class {
608
765
  continue;
609
766
  }
610
767
  const [a, b] = [first, second];
768
+ if (a.horizontal) {
769
+ // the level of a sum is the right end, and left of it by the length of the negative values
770
+ const endOf = (anchor) => {
771
+ const local = toLocal(anchor.box);
772
+ return local.x + local.width - anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).width, 0);
773
+ };
774
+ const mark = buildHorizontalDifference(item, toLocal(a.box), toLocal(b.box), a.value, b.value, em, {
775
+ from: endOf(a),
776
+ to: endOf(b),
777
+ });
778
+ if (mark)
779
+ marks.push(mark);
780
+ continue;
781
+ }
611
782
  // the level of a sum: the top for positive values, and below it by the length of the negative ones.
612
783
  // Measured in the space of the layer, so it holds on a turned page too.
613
784
  const levelOf = (anchor) => toLocal(anchor.box).y + anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).height, 0);
@@ -619,6 +790,48 @@ const AnnotationLayer = class {
619
790
  marks.push(mark);
620
791
  continue;
621
792
  }
793
+ if (item.mark === "pointer" || item.mark === "bracket") {
794
+ const first = sumOf(item.target, item.point);
795
+ const second = item.mark === "bracket" ? sumOf((_b = item.to) !== null && _b !== void 0 ? _b : item.target, item.toPoint) : first;
796
+ const failed = "problem" in first ? first : "problem" in second ? second : undefined;
797
+ if (failed) {
798
+ problems.push({ item, problem: failed.problem });
799
+ continue;
800
+ }
801
+ const [a, b] = [first, second];
802
+ // the end of a value: the right end of a bar or the top of a column, moved by the negative values
803
+ const endOf = (anchor) => {
804
+ const local = toLocal(anchor.box);
805
+ return anchor.horizontal
806
+ ? {
807
+ x: local.x + local.width - anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).width, 0),
808
+ y: local.y,
809
+ }
810
+ : {
811
+ x: local.x + local.width / 2,
812
+ y: local.y + anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).height, 0),
813
+ };
814
+ };
815
+ if (item.mark === "pointer") {
816
+ marks.push(buildPointer(item, endOf(a), em));
817
+ continue;
818
+ }
819
+ if (!a.horizontal) {
820
+ problems.push({ item, problem: "a bracket needs bars that run from left to right" });
821
+ continue;
822
+ }
823
+ if (item.to != null && item.to !== item.target) {
824
+ problems.push({ item, problem: "both ends of a bracket must be in one chart" });
825
+ continue;
826
+ }
827
+ const [upper, lower] = a.box.y <= b.box.y ? [a.box, b.box] : [b.box, a.box];
828
+ const share = item.percent ? shareOf(item, upper, lower) : undefined;
829
+ const host = targets.get(item.target).getBoundingClientRect();
830
+ const hostBox = toLocal({ x: host.left, y: host.top, width: host.width, height: host.height });
831
+ const caption = (_e = item.text) !== null && _e !== void 0 ? _e : (share != null ? `${Math.round(share * 100)}%` : undefined);
832
+ marks.push(buildBracket(item, toLocal(a.box), toLocal(b.box), { first: endOf(a).x, last: endOf(b).x }, hostBox.x, caption, em));
833
+ continue;
834
+ }
622
835
  const from = anchorOf(item.target, item.point);
623
836
  const to = item.mark === "arrow" ? anchorOf(item.to, item.toPoint) : undefined;
624
837
  const failed = "problem" in from ? from : to && "problem" in to ? to : undefined;
@@ -632,8 +845,10 @@ const AnnotationLayer = class {
632
845
  whole: start.whole,
633
846
  area,
634
847
  text: start.text && textToLocal(start.text),
635
- obstacles: (_b = start.obstacles) === null || _b === void 0 ? void 0 : _b.map(textToLocal),
848
+ obstacles: (_f = start.obstacles) === null || _f === void 0 ? void 0 : _f.map(textToLocal),
636
849
  stacked: start.stacked,
850
+ label: start.label,
851
+ horizontal: start.horizontal,
637
852
  });
638
853
  if (mark) {
639
854
  marks.push(mark);
@@ -753,7 +968,7 @@ const AnnotationLayer = class {
753
968
  return (index.h("g", null, index.h("circle", { cx: badge.cx, cy: badge.cy, r: badge.r, style: { fill: color } }), badge.label != null ? (index.h("text", { class: "badge-text", x: badge.cx, y: badge.cy, style: { fontSize: `${badge.r * 1.1}px` } }, badge.label)) : null));
754
969
  }
755
970
  renderMark(mark) {
756
- var _a, _b, _c;
971
+ var _a, _b, _e, _f, _g;
757
972
  const color = annotationColor(mark.color, this.componentStyle(($) => $["bn-annotation"]));
758
973
  if (mark.kind === "marker") {
759
974
  return (index.h("g", { class: "mark marker", "data-label": mark.badge.label }, this.renderBadge(mark.badge, color)));
@@ -765,10 +980,16 @@ const AnnotationLayer = class {
765
980
  const main = annotationColor(undefined, this.componentStyle(($) => $["bn-annotation"]));
766
981
  return (index.h("g", { class: "mark difference", "data-label": (_b = mark.badge) === null || _b === void 0 ? void 0 : _b.label }, mark.lines.map((line) => (index.h("line", { class: "difference-line", x1: line.x1, y1: line.y1, x2: line.x2, y2: line.y2 }))), index.h("rect", { x: mark.bar.x, y: mark.bar.y, width: mark.bar.width, height: mark.bar.height, style: { fill: color } }), index.h("text", { class: "mark-text", x: mark.text.x, y: mark.text.y, style: { textAnchor: mark.text.anchor } }, mark.text.value, mark.text.percent ? (index.h("tspan", { class: "percent", dx: "0.35em" }, mark.text.percent)) : null), mark.frame ? (index.h("rect", { x: mark.frame.x, y: mark.frame.y, width: mark.frame.width, height: mark.frame.height, rx: mark.frame.r, ry: mark.frame.r, style: { fill: "none", stroke: main, strokeWidth: "1.5" } })) : null, this.renderBadge(mark.badge, main)));
767
982
  }
768
- return (index.h("g", { class: "mark arrow", "data-label": (_c = mark.badge) === null || _c === void 0 ? void 0 : _c.label }, index.h("line", { x1: mark.x1, y1: mark.y1, x2: mark.x2, y2: mark.y2, style: { stroke: color, strokeWidth: "1.5" } }), index.h("polygon", { points: mark.head, style: { fill: color } }), this.renderBadge(mark.badge, color)));
983
+ if (mark.kind === "pointer") {
984
+ return (index.h("g", { class: "mark pointer", "data-label": (_e = mark.badge) === null || _e === void 0 ? void 0 : _e.label }, index.h("polygon", { points: mark.shape, style: { fill: color } }), this.renderBadge(mark.badge, color)));
985
+ }
986
+ if (mark.kind === "bracket") {
987
+ return (index.h("g", { class: "mark bracket", "data-label": (_f = mark.badge) === null || _f === void 0 ? void 0 : _f.label }, index.h("polyline", { points: mark.path, style: { fill: "none", stroke: color, strokeWidth: "1.5" } }), mark.frame ? (index.h("rect", { x: mark.frame.x, y: mark.frame.y, width: mark.frame.width, height: mark.frame.height, rx: mark.frame.r, ry: mark.frame.r, style: { fill: "#ffffff", stroke: color, strokeWidth: "1.5" } })) : null, mark.caption ? (index.h("text", { class: "mark-text caption", x: mark.caption.x, y: mark.caption.y }, mark.caption.text)) : null, this.renderBadge(mark.badge, color)));
988
+ }
989
+ return (index.h("g", { class: "mark arrow", "data-label": (_g = mark.badge) === null || _g === void 0 ? void 0 : _g.label }, index.h("line", { x1: mark.x1, y1: mark.y1, x2: mark.x2, y2: mark.y2, style: { stroke: color, strokeWidth: "1.5" } }), index.h("polygon", { points: mark.head, style: { fill: color } }), this.renderBadge(mark.badge, color)));
769
990
  }
770
991
  render() {
771
- return (index.h(index.Host, { key: 'f2864246b86078e97a15f58cab7f46a792e6d300' }, index.h("svg", { key: '52f932a7f8dff3e00773f8f827c82ec62848cb34', ref: (el) => (this.svg = el) }, this.marks.map((mark) => this.renderMark(mark)))));
992
+ return (index.h(index.Host, { key: '3b82cff435bdbabe51cdb7581afef428a16716b0' }, index.h("svg", { key: '0613bd3ecb59150c6959c9f96322b0f3eafc6164', ref: (el) => (this.svg = el) }, this.marks.map((mark) => this.renderMark(mark)))));
772
993
  }
773
994
  get element() { return index.getElement(this); }
774
995
  static get watchers() { return {
@@ -9464,9 +9685,15 @@ class Formatter {
9464
9685
  }
9465
9686
  this.formats.set(key, format);
9466
9687
  }
9467
- const text = format.format(value / scale);
9688
+ const print = (number) => this.groupSeparator === null
9689
+ ? format.format(number)
9690
+ : format
9691
+ .formatToParts(number)
9692
+ .map((part) => (part.type === "group" ? this.groupSeparator : part.value))
9693
+ .join("");
9694
+ const text = print(value / scale);
9468
9695
  // a small negative that rounds to zero would print "-0"
9469
- return (text === format.format(-0) ? format.format(0) : text).replace(/\s+(%)/g, "$1");
9696
+ return (text === print(-0) ? print(0) : text).replace(/\s+(%)/g, "$1");
9470
9697
  }
9471
9698
  /**
9472
9699
  * Translates a technical scenario identifier into a human-readable IBCS label.
@@ -9524,6 +9751,11 @@ class Formatter {
9524
9751
  }
9525
9752
  /** One formatter per locale, style and digits: building one per cell is slow. */
9526
9753
  Formatter.formats = new Map();
9754
+ /**
9755
+ * Replaces the group separator of the locale in every number, for example by a thin
9756
+ * space. Null: the separator of the locale. One setting for the page: `bn-context` sets it.
9757
+ */
9758
+ Formatter.groupSeparator = null;
9527
9759
 
9528
9760
  /** Most decimals a label gets: a double has about 15 significant digits. */
9529
9761
  const MAX_DECIMALS = 15;
@@ -14596,6 +14828,55 @@ const Chart$1 = class Chart {
14596
14828
  this.errors.remove(errId);
14597
14829
  }
14598
14830
  }
14831
+ validateSums(newValue) {
14832
+ this.warnUnless("sums", ["none", "groups", "total", "all"].includes(newValue), newValue);
14833
+ }
14834
+ validateScenarioLabelPosition(newValue) {
14835
+ this.warnUnless("scenarioLabelPosition", ["bottom", "top"].includes(newValue), newValue);
14836
+ }
14837
+ validateReferenceLine(newValue) {
14838
+ this.warnUnless("referenceLine", withStyled.isBlankInput(newValue) || this.prepareReferenceLine() !== null, newValue);
14839
+ }
14840
+ validateItalicCategories(newValue) {
14841
+ this.warnUnless("italicCategories", withStyled.isBlankInput(newValue) || this.prepareItalicCategories() !== null, newValue);
14842
+ }
14843
+ warnUnless(name, valid, value) {
14844
+ const errId = `WARN_${name}`;
14845
+ if (valid) {
14846
+ this.errors.remove(errId);
14847
+ }
14848
+ else {
14849
+ this.errors.addOrReplace({
14850
+ id: errId,
14851
+ type: "warning",
14852
+ message: name + ": invalid value '" + value + "' is not supported.",
14853
+ });
14854
+ }
14855
+ }
14856
+ prepareReferenceLine() {
14857
+ if (withStyled.isBlankInput(this.referenceLine))
14858
+ return null;
14859
+ try {
14860
+ const parsed = JSON.parse(this.referenceLine);
14861
+ if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.value) !== "number" || !Number.isFinite(parsed.value))
14862
+ return null;
14863
+ return { value: parsed.value, label: typeof parsed.label === "string" ? parsed.label : undefined };
14864
+ }
14865
+ catch (_a) {
14866
+ return null;
14867
+ }
14868
+ }
14869
+ prepareItalicCategories() {
14870
+ if (withStyled.isBlankInput(this.italicCategories))
14871
+ return [];
14872
+ try {
14873
+ const parsed = JSON.parse(this.italicCategories);
14874
+ return Array.isArray(parsed) && parsed.every((entry) => typeof entry === "string") ? parsed : null;
14875
+ }
14876
+ catch (_a) {
14877
+ return null;
14878
+ }
14879
+ }
14599
14880
  validateStack(newValue) {
14600
14881
  const errId = "WARN_stack";
14601
14882
  const errors = withStyled.validateStackConfig(newValue);
@@ -14709,6 +14990,48 @@ const Chart$1 = class Chart {
14709
14990
  * Number of decimal digits of the percent labels (relative variances, shares of a 100 % stack)
14710
14991
  */
14711
14992
  this.dataFormatDigitsPercent = 2;
14993
+ /**
14994
+ * Sum rows. `groups` adds a row below the rows of each `rowGroup` (level
14995
+ * `category`), `total` a row over all rows, `all` both. A sum row has no
14996
+ * bar: it prints the sum in bold, in a stack one number per series with a
14997
+ * small square in the colour of the series. In a 100 % stack it is a bar
14998
+ * of shares. A sum row does not count for the scale.
14999
+ *
15000
+ * @default "none"
15001
+ * @example sums="all"
15002
+ */
15003
+ this.sums = "none";
15004
+ /**
15005
+ * Label of the sum row over all rows.
15006
+ *
15007
+ * @default "" (the `SUM_TOTAL` text)
15008
+ * @example sum-title="World"
15009
+ */
15010
+ this.sumTitle = "";
15011
+ /**
15012
+ * Where the name of the scenario of a chart with plain bars stands:
15013
+ * `bottom` below the last bar, `top` above the first one.
15014
+ *
15015
+ * @default "bottom"
15016
+ * @example scenario-label-position="top"
15017
+ */
15018
+ this.scenarioLabelPosition = "bottom";
15019
+ /**
15020
+ * A line across the bars at one value of the axis, as a JSON string:
15021
+ * `value` and an optional `label`. In a 100 % stack the value is a percent.
15022
+ *
15023
+ * @default "" (no line)
15024
+ * @example reference-line='{"value":50,"label":"50%"}'
15025
+ */
15026
+ this.referenceLine = "";
15027
+ /**
15028
+ * Rows that are printed in italics, as a JSON array of values of the
15029
+ * level column, for example the rest rows.
15030
+ *
15031
+ * @default "" (none)
15032
+ * @example italic-categories='["Rest of world"]'
15033
+ */
15034
+ this.italicCategories = "";
14712
15035
  /**
14713
15036
  * Stacking configuration as a JSON string. When set, bars are drawn as
14714
15037
  * stacked segments instead of side-by-side.
@@ -14811,6 +15134,10 @@ const Chart$1 = class Chart {
14811
15134
  this.validateOrderList(this.order);
14812
15135
  this.validateMeasureScale(this.measureScale);
14813
15136
  this.validateStack(this.stack);
15137
+ this.validateSums(this.sums);
15138
+ this.validateScenarioLabelPosition(this.scenarioLabelPosition);
15139
+ this.validateReferenceLine(this.referenceLine);
15140
+ this.validateItalicCategories(this.italicCategories);
14814
15141
  this.validateScaling(this.scale);
14815
15142
  }
14816
15143
  componentDidRender() {
@@ -15211,6 +15538,7 @@ const Chart$1 = class Chart {
15211
15538
  prepareStackConfig() {
15212
15539
  if (withStyled.isBlankInput(this.stack)) {
15213
15540
  this.errors.remove("WARN_stack_dimensions_scenarios");
15541
+ this.errors.remove("WARN_stack_thickness_variances");
15214
15542
  return null;
15215
15543
  }
15216
15544
  try {
@@ -15233,10 +15561,27 @@ const Chart$1 = class Chart {
15233
15561
  else {
15234
15562
  this.errors.remove(errId);
15235
15563
  }
15564
+ // rows of different height are for the base chart alone: a variance bar has one thickness
15565
+ const byTotal = parsed.thickness === "total";
15566
+ const withVariances = byTotal && this.prepareVariances().length > 0;
15567
+ if (withVariances) {
15568
+ this.errors.addOrReplace({
15569
+ id: "WARN_stack_thickness_variances",
15570
+ type: "warning",
15571
+ message: "stack thickness total: not used together with variances, the rows keep one height.",
15572
+ });
15573
+ }
15574
+ else {
15575
+ this.errors.remove("WARN_stack_thickness_variances");
15576
+ }
15236
15577
  return {
15237
15578
  by,
15238
15579
  mode: parsed.mode || withStyled.StackMode.ABSOLUTE,
15239
15580
  order: parsed.order || withStyled.StackOrder.DATASET,
15581
+ percentMark: parsed.percentMark === true,
15582
+ labels: parsed.labels === "value" ? "value" : "share",
15583
+ thickness: byTotal && !withVariances ? "total" : "equal",
15584
+ totalTitle: typeof parsed.totalTitle === "string" ? parsed.totalTitle : undefined,
15240
15585
  };
15241
15586
  }
15242
15587
  catch (_a) {
@@ -15310,6 +15655,7 @@ const Chart$1 = class Chart {
15310
15655
  return this.measureUnit;
15311
15656
  }
15312
15657
  chartTemplate(localScenarioString, idx) {
15658
+ var _a;
15313
15659
  const ppu = this.preparePixelPerUnit();
15314
15660
  const ppp = this.preparePixelPerPercentage();
15315
15661
  const stackConfig = this.prepareStackConfig();
@@ -15317,7 +15663,7 @@ const Chart$1 = class Chart {
15317
15663
  const scenarios = this.hidesScenarios() ? variancesScenarios([localScenarioString]) : this.prepareScenarios();
15318
15664
  // Dimension stacking uses only the first scenario. Only the base chart draws a stack, a variance needs both of its scenarios
15319
15665
  const effectiveScenarios = isBase && (stackConfig === null || stackConfig === void 0 ? void 0 : stackConfig.by) === withStyled.StackBy.DIMENSIONS ? scenarios.slice(0, 1) : scenarios;
15320
- return (index.h("bn-chart-structure-renderer", { tableName: this.datasetName, dataVersion: this.dataVersion, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideCategories: this.prepareHideCategories(idx), pixelPerUnit: ppu, pixelPerPercentage: ppp, reportAutoScaling: this.handleAutoScalingReport, errors: this.errors, limit: this.prepareLimit(), styles: this.prepareStyle(), i18n: this.prepareI18n(), order: this.prepareOrder(), level: this.prepareLevel(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(idx), stackConfig: stackConfig, dataFormatDigits: { percent: this.dataFormatDigitsPercent, decimal: this.dataFormatDigitsDecimal }, parentDimensions: this.prepareDimension(), ruleSetConfig: this.ruleSetConfig() }));
15666
+ return (index.h("bn-chart-structure-renderer", { tableName: this.datasetName, dataVersion: this.dataVersion, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideCategories: this.prepareHideCategories(idx), pixelPerUnit: ppu, pixelPerPercentage: ppp, reportAutoScaling: this.handleAutoScalingReport, errors: this.errors, limit: this.prepareLimit(), styles: this.prepareStyle(), i18n: this.prepareI18n(), order: this.prepareOrder(), level: this.prepareLevel(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(idx), stackConfig: stackConfig, sums: ["groups", "total", "all"].includes(this.sums) ? this.sums : "none", sumTitle: this.sumTitle, scenarioLabelTop: this.scenarioLabelPosition === "top", referenceLine: isBase ? this.prepareReferenceLine() : null, italicCategories: (_a = this.prepareItalicCategories()) !== null && _a !== void 0 ? _a : [], dataFormatDigits: { percent: this.dataFormatDigitsPercent, decimal: this.dataFormatDigitsDecimal }, parentDimensions: this.prepareDimension(), ruleSetConfig: this.ruleSetConfig() }));
15321
15667
  }
15322
15668
  /**
15323
15669
  * The line this chart wants to be aligned on, in CSS px from the host's
@@ -15447,7 +15793,7 @@ const Chart$1 = class Chart {
15447
15793
  this.errors.remove("WARN_scenarios_none");
15448
15794
  }
15449
15795
  const fontStyles = this.getFontStyles();
15450
- return (index.h(index.Host, { key: 'a9b487fd43e785b1f14d0599ad0145a248b35f5d', style: fontStyles }, index.h("div", { key: '950ab383346b288ab17c2a1bbdfcfcd240e0f4d8', class: "container" }, scenariosArray.map(this.chartTemplate))));
15796
+ return (index.h(index.Host, { key: 'eb0b081632a3d8e9475f280357c0b22b17b23df3', style: fontStyles }, index.h("div", { key: '8ecaea33bcd96b312e39868f008aa630e12077c2', class: "container" }, scenariosArray.map(this.chartTemplate))));
15451
15797
  }
15452
15798
  get element() { return index.getElement(this); }
15453
15799
  static get watchers() { return {
@@ -15487,6 +15833,18 @@ const Chart$1 = class Chart {
15487
15833
  "dataFormatDigitsPercent": [{
15488
15834
  "validateDataFormatDigitsPercent": 0
15489
15835
  }],
15836
+ "sums": [{
15837
+ "validateSums": 0
15838
+ }],
15839
+ "scenarioLabelPosition": [{
15840
+ "validateScenarioLabelPosition": 0
15841
+ }],
15842
+ "referenceLine": [{
15843
+ "validateReferenceLine": 0
15844
+ }],
15845
+ "italicCategories": [{
15846
+ "validateItalicCategories": 0
15847
+ }],
15490
15848
  "stack": [{
15491
15849
  "validateStack": 0
15492
15850
  }],
@@ -15514,7 +15872,7 @@ Chart$1.style = bnChartStructureCss$1();
15514
15872
  */
15515
15873
  let ElementPositions$1 = class ElementPositions {
15516
15874
  // private smallestDataPoint: DataPoint;
15517
- constructor(padding, scaleFactors, fontSize, numberOfColumns, leftSideLengthSync, titleLength, leftSideWidth, categoryWidth, hasStackedHeaders = false) {
15875
+ constructor(padding, scaleFactors, fontSize, numberOfColumns, leftSideLengthSync, titleLength, leftSideWidth, categoryWidth, hasStackedHeaders = false, rows = null) {
15518
15876
  this.categoryPosition = { x: 0, y: 0 };
15519
15877
  this.spacings = {
15520
15878
  scenarioOffset: 0,
@@ -15545,6 +15903,7 @@ let ElementPositions$1 = class ElementPositions {
15545
15903
  this.leftSideLengthSync = leftSideLengthSync;
15546
15904
  this.topSideLabelHeight = titleLength > 0 ? this.fontSize : 0;
15547
15905
  this.hasStackedHeaders = hasStackedHeaders;
15906
+ this.rows = rows;
15548
15907
  this.leftSideLabelLength = this.calculateSideLabelLength(titleLength, leftSideWidth, categoryWidth);
15549
15908
  this.calculateSpacings();
15550
15909
  this.calculateCategoryPosition();
@@ -15554,8 +15913,22 @@ let ElementPositions$1 = class ElementPositions {
15554
15913
  return this.axisPosition.x;
15555
15914
  }
15556
15915
  getBarCenterPositionY(index) {
15916
+ if (this.rows && index < this.rows.start.length) {
15917
+ const middle = this.rows.start[index] + this.rows.weight[index] / 2;
15918
+ return this.getAxisPositionY() + this.spacings.scenarioOffset + middle * this.spacings.categoryWidth;
15919
+ }
15557
15920
  return this.categoryPosition.y + this.spacings.scenarioOffset + index * this.spacings.categoryWidth;
15558
15921
  }
15922
+ /** Upper edge of the room of a row. */
15923
+ getRowTopPositionY(index) {
15924
+ const start = this.rows && index < this.rows.start.length ? this.rows.start[index] : index;
15925
+ return this.getAxisPositionY() + this.spacings.scenarioOffset + start * this.spacings.categoryWidth;
15926
+ }
15927
+ /** Thickness of the bar of a row. Rows have one thickness unless the chart sets a row layout. */
15928
+ getBarWidthAt(index) {
15929
+ const weight = this.rows && index < this.rows.weight.length ? this.rows.weight[index] : 1;
15930
+ return this.spacings.barWidth * weight;
15931
+ }
15559
15932
  getBarPositionY(index, isPrimaryMarker) {
15560
15933
  if (isPrimaryMarker) {
15561
15934
  return this.getBarCenterPositionY(index);
@@ -15576,7 +15949,7 @@ let ElementPositions$1 = class ElementPositions {
15576
15949
  return this.axisPosition.y - this.spacings.labelToAxis - this.getTopLabelOverhang();
15577
15950
  }
15578
15951
  getStackedHeaderPositionY() {
15579
- return this.getBarCenterPositionY(0) - this.spacings.barWidth * 0.5 - this.spacings.scenarioLabelToBar;
15952
+ return this.getBarCenterPositionY(0) - this.getBarWidthAt(0) * 0.5 - this.spacings.scenarioLabelToBar;
15580
15953
  }
15581
15954
  getNeedleWidth() {
15582
15955
  return this.spacings.needleWidth;
@@ -15628,7 +16001,8 @@ let ElementPositions$1 = class ElementPositions {
15628
16001
  return this.spacings.scenarioOffset; // this.categoryOffset;
15629
16002
  }
15630
16003
  getAxisEndPositionY() {
15631
- return this.getAxisPositionY() + (this.numberOfColumns + 1 / 2) * this.spacings.categoryWidth;
16004
+ const rows = this.rows ? this.rows.total : this.numberOfColumns;
16005
+ return this.getAxisPositionY() + (rows + 1 / 2) * this.spacings.categoryWidth;
15632
16006
  }
15633
16007
  getScenarioLabelPositionOffsetY(isPrimaryBar) {
15634
16008
  if (isPrimaryBar) {
@@ -16023,6 +16397,14 @@ class StructureChartComponentConfig {
16023
16397
  this.showMeasureScale = true;
16024
16398
  this.dataFormatDigits = { decimal: 1, percent: 2 };
16025
16399
  this.stackConfig = null;
16400
+ this.sums = "none";
16401
+ /** Label of the row over all rows. Empty: the `SUM_TOTAL` text. */
16402
+ this.sumTitle = "";
16403
+ /** The name of the scenario stands above the first bar and not below the last one. */
16404
+ this.scenarioLabelTop = false;
16405
+ this.referenceLine = null;
16406
+ /** Values of the level column whose row is printed in italics. */
16407
+ this.italicCategories = [];
16026
16408
  }
16027
16409
  }
16028
16410
  /**
@@ -16086,6 +16468,21 @@ class StructureChartComponentConfigAdapter {
16086
16468
  if (withStyled.CompareUtil.isExisting(data.stackConfig)) {
16087
16469
  config.stackConfig = data.stackConfig;
16088
16470
  }
16471
+ if (withStyled.CompareUtil.isString(data.sums) && ["groups", "total", "all"].includes(data.sums)) {
16472
+ config.sums = data.sums;
16473
+ }
16474
+ if (withStyled.CompareUtil.isString(data.sumTitle)) {
16475
+ config.sumTitle = data.sumTitle;
16476
+ }
16477
+ if (withStyled.CompareUtil.isBoolean(data.scenarioLabelTop)) {
16478
+ config.scenarioLabelTop = data.scenarioLabelTop;
16479
+ }
16480
+ if (withStyled.CompareUtil.isExisting(data.referenceLine)) {
16481
+ config.referenceLine = data.referenceLine;
16482
+ }
16483
+ if (withStyled.CompareUtil.isArray(data.italicCategories)) {
16484
+ config.italicCategories = withStyled.AdapterUtils.adaptArray(data.italicCategories, this.stringAdapter);
16485
+ }
16089
16486
  return config;
16090
16487
  }
16091
16488
  default() {
@@ -16555,6 +16952,8 @@ class Label {
16555
16952
  this.group = null;
16556
16953
  this.segmentFillColor = null;
16557
16954
  this.maxWidth = null;
16955
+ this.bold = false;
16956
+ this.italic = false;
16558
16957
  this.ID_SCENARIOLABEL = "Label";
16559
16958
  this.CSS_CATEGORIES = "categories";
16560
16959
  this.pointPart = "label";
@@ -16583,6 +16982,12 @@ class Label {
16583
16982
  this.segmentFillColor = color;
16584
16983
  return this;
16585
16984
  }
16985
+ /** Bold for a sum row, italic for a rest row. */
16986
+ setEmphasis(bold, italic) {
16987
+ this.bold = bold;
16988
+ this.italic = italic;
16989
+ return this;
16990
+ }
16586
16991
  setMaxWidth(width) {
16587
16992
  this.maxWidth = width;
16588
16993
  return this;
@@ -16638,6 +17043,10 @@ class Label {
16638
17043
  }
16639
17044
  // @ts-ignore
16640
17045
  const text = label.text(prefix + valueStr);
17046
+ if (this.bold)
17047
+ text.font({ weight: "bold" });
17048
+ if (this.italic)
17049
+ text.font({ style: "italic" });
16641
17050
  text.move(this.x, this.y);
16642
17051
  // One bbox() per label, not two: svg.js caches nothing, and on a detached
16643
17052
  // tree each call clones the subtree into the document to measure it.
@@ -16807,7 +17216,7 @@ class Bar {
16807
17216
  return this;
16808
17217
  }
16809
17218
  draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
16810
- var _a, _b;
17219
+ var _a, _b, _c;
16811
17220
  if (this.isEmpty() || this.dataPoint.getScenario() == null) {
16812
17221
  return this;
16813
17222
  }
@@ -16827,6 +17236,8 @@ class Bar {
16827
17236
  }
16828
17237
  (_a = this.scenarioGroup) === null || _a === void 0 ? void 0 : _a.attr(dataPointAttributes(this.dataPoint.key));
16829
17238
  (_b = this.barGroup) === null || _b === void 0 ? void 0 : _b.attr(dataPointAttributes(this.dataPoint.key, "element"));
17239
+ if (!this.isVarianceBar)
17240
+ (_c = this.barGroup) === null || _c === void 0 ? void 0 : _c.attr("data-bn-value", this.dataPoint.value);
16830
17241
  if (this.barGroup != null) {
16831
17242
  if (this.isOverflowing && this.overflowConfig) {
16832
17243
  this.drawOverdriveBar(fillStyle, strokeStyle);
@@ -17303,7 +17714,7 @@ let Needle$1 = class Needle {
17303
17714
  * Renders a single horizontal stacked bar segment for the structure chart.
17304
17715
  */
17305
17716
  class StackedBar {
17306
- constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup) {
17717
+ constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup, options = {}) {
17307
17718
  this.hasData = false;
17308
17719
  this.position = position;
17309
17720
  this.styles = styles;
@@ -17313,6 +17724,7 @@ class StackedBar {
17313
17724
  this.segmentIndex = segmentIndex;
17314
17725
  this.stackMode = stackMode;
17315
17726
  this.stack = stack;
17727
+ this.options = options;
17316
17728
  this.group = parentGroup;
17317
17729
  this.barGroup = parentGroup.group().id(`stacked_bar_${index}_seg_${segmentIndex}`);
17318
17730
  if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true && dataPoint.value != null) {
@@ -17320,6 +17732,7 @@ class StackedBar {
17320
17732
  }
17321
17733
  }
17322
17734
  draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
17735
+ var _a;
17323
17736
  // a segment without a value (NaN) keeps its place in the stack, so the colours stay, but draws nothing
17324
17737
  if (!this.hasData || !Number.isFinite(this.dataPoint.value)) {
17325
17738
  return;
@@ -17327,7 +17740,7 @@ class StackedBar {
17327
17740
  const value = this.dataPoint.value;
17328
17741
  const pixelPerUnit = this.dataPoint.pixelPerUnit;
17329
17742
  const axisX = this.position.getBarPositionX();
17330
- const barWidth = this.position.getBarWidth();
17743
+ const barWidth = this.position.getBarWidthAt(this.index);
17331
17744
  // a negative segment ends left of its start: the rect begins at the edge that is further left
17332
17745
  const segmentLength = Math.abs(this.segment.end - this.segment.start) * pixelPerUnit;
17333
17746
  const xPos = axisX + Math.min(this.segment.start, this.segment.end) * pixelPerUnit;
@@ -17337,16 +17750,24 @@ class StackedBar {
17337
17750
  const fillStyle = { color: fillColor };
17338
17751
  const strokeStyle = { color: fillColor, width: 0.5 };
17339
17752
  this.barGroup.attr(dataPointAttributes(this.dataPoint.key, "element"));
17753
+ this.barGroup.attr("data-bn-value", value);
17340
17754
  this.barGroup.rect(Math.max(segmentLength, 0.5), barWidth).fill(fillStyle).stroke(strokeStyle).cy(yPos).x(xPos);
17341
17755
  // Draw segment value label centered on bar if wide enough
17342
- const LABEL_PADDING = 6;
17343
- const availableWidth = segmentLength - LABEL_PADDING;
17756
+ // 6 px at the base font of 16 px, less with a smaller font
17757
+ const labelPadding = Math.min(6, this.styles.fontStyles.size * 0.375);
17758
+ const availableWidth = segmentLength - labelPadding;
17759
+ const { bold = false, italic = false } = this.options;
17760
+ const relative = this.stackMode === withStyled.StackMode.RELATIVE || this.stackMode === withStyled.StackMode.ABSOLUTE_RELATIVE;
17761
+ const labelKind = this.stackMode === withStyled.StackMode.RELATIVE ? ((_a = this.options.label) !== null && _a !== void 0 ? _a : "share") : "share";
17344
17762
  if (availableWidth > 0) {
17345
17763
  const labelX = xPos + segmentLength / 2;
17346
- if (this.stackMode === withStyled.StackMode.RELATIVE || this.stackMode === withStyled.StackMode.ABSOLUTE_RELATIVE) {
17347
- const labelValue = Formatter.number(this.segment.share, "percent", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale);
17764
+ if (relative && labelKind !== "value") {
17765
+ const labelValue = labelKind === "plain-share"
17766
+ ? Formatter.number(this.segment.share * 100, "decimal", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale)
17767
+ : Formatter.number(this.segment.share, "percent", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale);
17348
17768
  new Label(this.group, labelX, yPos, "STACK_SEG", labelValue, this.styles, HookLocation.Center, HookLocation.Center)
17349
17769
  .setSegmentFill(fillColor)
17770
+ .setEmphasis(bold, italic)
17350
17771
  .setMaxWidth(availableWidth)
17351
17772
  .setPoint(this.dataPoint.key)
17352
17773
  .draw();
@@ -17355,6 +17776,7 @@ class StackedBar {
17355
17776
  // Pass raw numeric value - Label.draw() formats with measureScale
17356
17777
  new Label(this.group, labelX, yPos, "STACK_SEG", value, this.styles, HookLocation.Center, HookLocation.Center)
17357
17778
  .setSegmentFill(fillColor)
17779
+ .setEmphasis(bold, italic)
17358
17780
  .setMaxWidth(availableWidth)
17359
17781
  .setPoint(this.dataPoint.key)
17360
17782
  .draw(dataFormatDigits, measureScale);
@@ -17362,7 +17784,8 @@ class StackedBar {
17362
17784
  }
17363
17785
  }
17364
17786
  drawTotalLabel(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix(), key) {
17365
- if (this.stackMode === withStyled.StackMode.RELATIVE) {
17787
+ var _a, _b;
17788
+ if (this.stackMode === withStyled.StackMode.RELATIVE && !this.options.total) {
17366
17789
  return;
17367
17790
  }
17368
17791
  // like a plain bar: the label of a negative total sits left of the negative side
@@ -17371,7 +17794,10 @@ class StackedBar {
17371
17794
  const labelX = this.position.getLabelPositionX(end * this.dataPoint.pixelPerUnit);
17372
17795
  const yPos = this.position.getBarPositionY(this.index, true);
17373
17796
  const label = new Label(this.group, labelX, yPos, "STACK_TOTAL", this.stack.total, this.styles, HookLocation.Center, isNegative ? HookLocation.Right : HookLocation.Left);
17374
- label.setPoint(key, "total").draw(dataFormatDigits, measureScale);
17797
+ label
17798
+ .setEmphasis((_a = this.options.bold) !== null && _a !== void 0 ? _a : false, (_b = this.options.italic) !== null && _b !== void 0 ? _b : false)
17799
+ .setPoint(key, "total")
17800
+ .draw(dataFormatDigits, measureScale);
17375
17801
  }
17376
17802
  }
17377
17803
 
@@ -17628,6 +18054,8 @@ function stackLabelSide(layouts, totalLabelRoom = () => 0) {
17628
18054
  return { flipped, clearance: Math.max(0, ...clearance) };
17629
18055
  }
17630
18056
 
18057
+ /** The id of the row that sums the rows a limit cut off. */
18058
+ const REST_ROW_ID = 9999;
17631
18059
  /**
17632
18060
  * Orchestrates the full rendering pipeline for an IBCS structure (categorical) chart.
17633
18061
  *
@@ -17684,6 +18112,11 @@ class StructureChart {
17684
18112
  this.stackLabelClearance = { left: 0, right: 0 };
17685
18113
  this.fromExpr = "";
17686
18114
  this.rowCount = 0;
18115
+ this.sums = "none";
18116
+ this.sumTitle = "";
18117
+ this.scenarioLabelTop = false;
18118
+ this.referenceLine = null;
18119
+ this.italicCategories = [];
17687
18120
  this.db = db;
17688
18121
  this.tableName = tableName;
17689
18122
  this.ruleSet = ruleSet || new IBCSRuleSet();
@@ -17702,7 +18135,7 @@ class StructureChart {
17702
18135
  if (this.titleLength > leftSideWidth) {
17703
18136
  leftSideWidth = this.titleLength;
17704
18137
  }
17705
- return new ElementPositions$1(new Padding$1(this.styles.padding), this.styles.scaleFactors, this.styles.fontStyles.size, this.dataModel.length, this.leftSideOffsetForHorizontalSync, this.titleLength, leftSideWidth, categoryWidth, !!this.stackConfig && this.variancesDataModel.length === 0);
18138
+ return new ElementPositions$1(new Padding$1(this.styles.padding), this.styles.scaleFactors, this.styles.fontStyles.size, this.dataModel.length, this.leftSideOffsetForHorizontalSync, this.titleLength, leftSideWidth, categoryWidth, (!!this.stackConfig && this.variancesDataModel.length === 0) || this.scenarioLabelTop, this.rowLayout());
17706
18139
  }
17707
18140
  setStyles(newStyle) {
17708
18141
  this.styles = newStyle;
@@ -17721,7 +18154,17 @@ class StructureChart {
17721
18154
  this.pixelPerPercentage = config.pixelPerPercentage || 100;
17722
18155
  this.setSource(config.filter);
17723
18156
  this.level = config.level;
18157
+ this.sums = config.sums;
18158
+ this.sumTitle = config.sumTitle;
18159
+ this.scenarioLabelTop = config.scenarioLabelTop;
18160
+ this.referenceLine = config.referenceLine;
18161
+ this.italicCategories = config.italicCategories;
17724
18162
  this.dataModel = this.populateModel(scenarios, config.level, config.sortOrder);
18163
+ // Populate per-dimension stack segments when stacking by a data dimension
18164
+ if (config.stackConfig && config.stackConfig.by !== withStyled.StackBy.SCENARIOS) {
18165
+ this.populateDimensionStackSegments(scenarios, config.stackConfig, config.level);
18166
+ }
18167
+ this.addSumRows(scenarios);
17725
18168
  for (const row of this.dataModel) {
17726
18169
  for (const dataPoint of [row.scenario1, row.scenario2, row.scenario3, row.scenario4]) {
17727
18170
  // a category without a value has no bar: nothing an annotation can point at
@@ -17730,18 +18173,17 @@ class StructureChart {
17730
18173
  }
17731
18174
  }
17732
18175
  }
17733
- // Populate per-dimension stack segments when stacking by a data dimension
17734
- if (config.stackConfig && config.stackConfig.by !== withStyled.StackBy.SCENARIOS) {
17735
- this.populateDimensionStackSegments(scenarios, config.stackConfig, config.level);
17736
- }
17737
18176
  this.variancesDataModel = this.populateVarianceModel(config.variances, this.dataModel);
17738
18177
  this.configTitle = config.title;
17739
18178
  this.configVariances = (_b = config === null || config === void 0 ? void 0 : config.variances) !== null && _b !== void 0 ? _b : [];
17740
18179
  this.updateTitle();
17741
- this.smallestDataPointValue = this.findSmallestDataPointValue(this.dataModel);
17742
- this.smallestVarianceDataPointValue = this.findSmallestDataPointValue(this.variancesDataModel);
17743
- this.highestDataPointValue = this.findHighestDataPointValue(this.dataModel);
17744
- this.highestVarianceDataPointValue = this.findHighestDataPointValue(this.variancesDataModel);
18180
+ // a sum row has no bar: it does not count for the scale
18181
+ const bars = this.dataModel.filter((row) => !row.sum);
18182
+ this.smallestDataPointValue = this.findSmallestDataPointValue(bars);
18183
+ const varianceBars = this.variancesDataModel.filter((row) => !row.sum);
18184
+ this.smallestVarianceDataPointValue = this.findSmallestDataPointValue(varianceBars);
18185
+ this.highestDataPointValue = this.findHighestDataPointValue(bars);
18186
+ this.highestVarianceDataPointValue = this.findHighestDataPointValue(varianceBars);
17745
18187
  this.axisScenario = this.setAxisScenario(config.variances);
17746
18188
  this.measureScale = config.measureScale;
17747
18189
  this.measureUnit = config.measureUnit;
@@ -17857,7 +18299,7 @@ class StructureChart {
17857
18299
  * from variable width components.
17858
18300
  */
17859
18301
  getUnitBarExtent() {
17860
- var _a, _b;
18302
+ var _a, _b, _c, _d;
17861
18303
  const stacked = this.isStacked();
17862
18304
  const vt = this.getVarianceType();
17863
18305
  const isVariance = vt !== VarianceType$1.NONE;
@@ -17867,8 +18309,9 @@ class StructureChart {
17867
18309
  // both sides of the axis; a relative stack is laid out on a span of 1, so its sides add up to 1 * ppu
17868
18310
  fixedDomain: stacked ? this.stackSides.positive + this.stackSides.negative : undefined,
17869
18311
  relativeVariance: vt === VarianceType$1.RELATIVE,
17870
- maxPositive: (_a = highest === null || highest === void 0 ? void 0 : highest.value) !== null && _a !== void 0 ? _a : 0,
17871
- minNegative: (_b = smallest === null || smallest === void 0 ? void 0 : smallest.value) !== null && _b !== void 0 ? _b : 0,
18312
+ // a reference line right of the longest bar needs its room too
18313
+ maxPositive: Math.max((_a = highest === null || highest === void 0 ? void 0 : highest.value) !== null && _a !== void 0 ? _a : 0, !stacked && !isVariance ? ((_c = (_b = this.referenceLine) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 0) : 0),
18314
+ minNegative: (_d = smallest === null || smallest === void 0 ? void 0 : smallest.value) !== null && _d !== void 0 ? _d : 0,
17872
18315
  });
17873
18316
  }
17874
18317
  /**
@@ -17902,6 +18345,8 @@ class StructureChart {
17902
18345
  return (this.position.getAxisEndPositionY() +
17903
18346
  this.position.spacings.labelToAxis +
17904
18347
  this.position.fontSize +
18348
+ // the 100% mark stands below the axis end
18349
+ (this.hasPercentMark() ? this.position.fontSize * 0.8 : 0) +
17905
18350
  this.styles.padding.bottom);
17906
18351
  }
17907
18352
  patternToString() {
@@ -17963,11 +18408,15 @@ class StructureChart {
17963
18408
  this.drawStackedScenarios(this.dataModel, svgContainer);
17964
18409
  this.drawStackedHeaders(this.dataModel, svgContainer);
17965
18410
  this.drawAxisAndLabels(this.dataModel, svgContainer, true);
18411
+ this.drawPercentMark(svgContainer);
17966
18412
  }
17967
18413
  else {
17968
18414
  this.drawScenarios(this.dataModel, svgContainer);
17969
18415
  this.drawAxisAndLabels(this.dataModel, svgContainer);
17970
18416
  }
18417
+ if (this.variancesDataModel.length === 0) {
18418
+ this.drawReferenceLine(svgContainer);
18419
+ }
17971
18420
  }
17972
18421
  setPattern(fc, fcPolygonPattern) {
17973
18422
  this.styles.pattern.set(fc, fcPolygonPattern);
@@ -18084,7 +18533,7 @@ class StructureChart {
18084
18533
  };
18085
18534
  return obj;
18086
18535
  }, {
18087
- id: 9999,
18536
+ id: REST_ROW_ID,
18088
18537
  category: "REST",
18089
18538
  type: VarianceType$1.NONE,
18090
18539
  scenario1: new DataPoint$1(NaN, selectedScenarios[0], this.pixelPerUnit, Scenario$1.NEU),
@@ -18271,7 +18720,7 @@ class StructureChart {
18271
18720
  // a 100 % stack prints no total
18272
18721
  const totalLabelRoom = (layout) => {
18273
18722
  var _a;
18274
- return ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) === withStyled.StackMode.RELATIVE
18723
+ return ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) === withStyled.StackMode.RELATIVE && this.stackConfig.labels !== "value"
18275
18724
  ? 0
18276
18725
  : (labelToBar + this.calculateTotalLabelWidth(layout.total)) / this.pixelPerUnit;
18277
18726
  };
@@ -18279,6 +18728,8 @@ class StructureChart {
18279
18728
  }
18280
18729
  /** Layouts of the stacks of a row that are drawn, back to front. */
18281
18730
  drawnStackLayouts(row) {
18731
+ if (this.isTextSum(row))
18732
+ return [];
18282
18733
  return this.stackGroups(row)
18283
18734
  .filter((group) => group.hasValue)
18284
18735
  .map((group) => group.layout);
@@ -18326,6 +18777,7 @@ class StructureChart {
18326
18777
  scenario2: new DataPoint$1(null, null, null, null),
18327
18778
  scenario3: new DataPoint$1(null, null, null, null),
18328
18779
  scenario4: new DataPoint$1(null, null, null, null),
18780
+ sum: dataModel[index].sum,
18329
18781
  });
18330
18782
  }
18331
18783
  }
@@ -18397,6 +18849,7 @@ class StructureChart {
18397
18849
  let isRelative = false;
18398
18850
  if (!this.hideCategories) {
18399
18851
  dataModel.forEach((elements, index) => {
18852
+ var _a;
18400
18853
  if (elements["type"] === VarianceType$1.RELATIVE) {
18401
18854
  isRelative = true;
18402
18855
  }
@@ -18418,9 +18871,23 @@ class StructureChart {
18418
18871
  new Label(axisLabelGroup, this.position.getCategoryPositionX(isPositive) + clearance, this.position.getBarCenterPositionY(index), "",
18419
18872
  // Category labels come from the data, but the synthetic "REST"
18420
18873
  // overflow bucket is engine-generated and translatable, as in bn-table.
18421
- this.i18n.get(elements.category) || elements.category, this.styles, HookLocation.Center, textHook).draw();
18874
+ this.i18n.get(elements.category) || elements.category, this.styles, HookLocation.Center, textHook)
18875
+ .setEmphasis(!!((_a = this.dataModel[index]) === null || _a === void 0 ? void 0 : _a.sum), this.isItalic(elements.category))
18876
+ .draw();
18422
18877
  });
18423
18878
  }
18879
+ // a thin line above a sum row, from the labels to the end of the row
18880
+ dataModel.forEach((_elements, index) => {
18881
+ const row = this.dataModel[index];
18882
+ if (!(row === null || row === void 0 ? void 0 : row.sum))
18883
+ return;
18884
+ const y = this.position.getBarCenterPositionY(index) - this.position.spacings.categoryWidth / 2;
18885
+ const left = this.hideCategories ? this.position.getAxisPositionX() : this.styles.padding.left;
18886
+ axisLabelGroup
18887
+ .line(left, y, this.position.getAxisPositionX() + this.sumRowExtent(row), y)
18888
+ .stroke({ color: "#000000", width: Math.max(0.5, this.position.spacings.axisLineWidth / 2) })
18889
+ .addClass("sum-line");
18890
+ });
18424
18891
  new Axis$1({
18425
18892
  scenarioType: this.axisScenario,
18426
18893
  labelText: this.title,
@@ -18429,20 +18896,60 @@ class StructureChart {
18429
18896
  }
18430
18897
  drawScenarios(dataModel, svgContainer) {
18431
18898
  const barsGroup = svgContainer.group().id("Scenarios");
18432
- const scenarioFactory = new ScenarioFactory$1(this.position, barsGroup, this.scenarioStyles(), dataModel.length, this.i18n);
18899
+ // the name of the scenario stands below the last bar, or above the first one
18900
+ let lastBar = -1;
18901
+ dataModel.forEach((row, index) => {
18902
+ if (!row.sum)
18903
+ lastBar = index;
18904
+ });
18905
+ const scenarioFactory = new ScenarioFactory$1(this.position, barsGroup, this.scenarioStyles(),
18906
+ // the factory names the last bar. The row layout leaves room for the name when a sum row follows.
18907
+ this.scenarioLabelTop ? 0 : lastBar + 1, this.i18n);
18433
18908
  scenarioFactory.setOverflowConfig(this.overflowConfig);
18434
18909
  dataModel.forEach((elements, index) => {
18910
+ if (elements.sum) {
18911
+ this.drawSumValue(elements, index, barsGroup);
18912
+ return;
18913
+ }
18435
18914
  scenarioFactory.createPrimaryBar(elements["scenario1"], index).draw(this.dataFormatDigits, this.measureScale);
18436
18915
  scenarioFactory.createSecondaryBar(elements["scenario2"], index).draw();
18437
18916
  scenarioFactory.createPrimaryMarker(elements["scenario3"], index).draw();
18438
18917
  scenarioFactory.createSecondaryMarker(elements["scenario4"], index).draw();
18439
18918
  });
18919
+ const first = dataModel.find((row) => !row.sum);
18920
+ if (this.scenarioLabelTop && first && !first.scenario1.isEmpty() && first.scenario1.scenario != null) {
18921
+ const scenario = first.scenario1.scenario;
18922
+ new Label(barsGroup,
18923
+ // from the axis on: the first bar can be shorter than the name
18924
+ this.position.getBarPositionX() + this.position.spacings.labelToAxis, this.position.getStackedHeaderPositionY(), "SCENARIO_HEADER", this.i18n.get(scenario) || scenario, this.styles, HookLocation.Bottom, HookLocation.Left).draw();
18925
+ }
18926
+ }
18927
+ /** The value of a sum row of a chart with plain bars or variances: a bold number at the axis, no bar. */
18928
+ drawSumValue(row, index, group) {
18929
+ const point = row.scenario1;
18930
+ if (point.isEmpty() || !Number.isFinite(point.value))
18931
+ return;
18932
+ const negative = point.value < 0;
18933
+ const label = new Label(group,
18934
+ // like the label of a bar without length: a negative number stands left of the axis
18935
+ this.position.getLabelPositionX(negative ? -1e-6 : 0), this.position.getBarCenterPositionY(index), "SUM_" + index, point.value, this.styles, HookLocation.Center, negative ? HookLocation.Right : HookLocation.Left)
18936
+ .setEmphasis(true, false)
18937
+ .setPoint(point.key);
18938
+ if (row.type === VarianceType$1.RELATIVE)
18939
+ label.setToRelativeVarianceLabel();
18940
+ else if (row.type === VarianceType$1.ABSOLUTE)
18941
+ label.setToVarianceLabel();
18942
+ label.draw(this.dataFormatDigits, this.measureScale);
18440
18943
  }
18441
18944
  drawVarianceScenario(dataModel, svgContainer) {
18442
18945
  const barsGroup = svgContainer.group().id("Scenarios");
18443
18946
  const scenarioFactory = new ScenarioFactory$1(this.position, barsGroup, this.scenarioStyles(), dataModel.length, this.i18n);
18444
18947
  scenarioFactory.setOverflowConfig(this.overflowConfig);
18445
18948
  dataModel.forEach((elements, index) => {
18949
+ if (elements.sum) {
18950
+ this.drawSumValue(elements, index, barsGroup);
18951
+ return;
18952
+ }
18446
18953
  if (elements["type"] === VarianceType$1.RELATIVE) {
18447
18954
  scenarioFactory.createRelativeVarianceBar(elements["scenario1"], index).draw(this.dataFormatDigits);
18448
18955
  }
@@ -18475,14 +18982,27 @@ class StructureChart {
18475
18982
  return;
18476
18983
  const stackGroup = svgContainer.group().id("StackedScenarios");
18477
18984
  const isScenarioStack = this.stackConfig.by === withStyled.StackBy.SCENARIOS;
18985
+ const relative = this.stackConfig.mode === withStyled.StackMode.RELATIVE;
18986
+ const valueLabels = relative && this.stackConfig.labels === "value";
18987
+ const label = valueLabels ? "value" : this.stackConfig.percentMark ? "plain-share" : "share";
18478
18988
  dataModel.forEach((elements, index) => {
18479
18989
  const groups = this.stackGroups(elements);
18990
+ if (this.isTextSum(elements)) {
18991
+ this.drawSumText(elements, index, stackGroup);
18992
+ return;
18993
+ }
18994
+ const options = {
18995
+ label,
18996
+ total: valueLabels,
18997
+ bold: !!elements.sum,
18998
+ italic: this.isItalic(elements.category),
18999
+ };
18480
19000
  groups.forEach((group, groupIdx) => {
18481
19001
  let lastBar = null;
18482
19002
  group.segments.forEach((seg, segIdx) => {
18483
19003
  const bar = new StackedBar(this.position, this.styles, seg.dataPoint, index, group.layout.segments[segIdx], seg.scenario,
18484
19004
  // overlay: one colour per group, back=lighter, front=darker
18485
- groups.length > 1 ? groups.length - 1 - groupIdx : segIdx, this.stackConfig.mode, group.layout, isScenarioStack, stackGroup);
19005
+ groups.length > 1 ? groups.length - 1 - groupIdx : segIdx, this.stackConfig.mode, group.layout, isScenarioStack, stackGroup, options);
18486
19006
  bar.draw(this.dataFormatDigits, this.measureScale);
18487
19007
  lastBar = bar;
18488
19008
  });
@@ -18500,9 +19020,10 @@ class StructureChart {
18500
19020
  * The headers take their place from the first row.
18501
19021
  */
18502
19022
  drawStackedHeaders(dataModel, svgContainer) {
19023
+ var _a;
18503
19024
  if (!this.stackConfig || dataModel.length === 0)
18504
19025
  return;
18505
- const firstRow = dataModel[0];
19026
+ const firstRow = (_a = dataModel.find((row) => !this.isTextSum(row))) !== null && _a !== void 0 ? _a : dataModel[0];
18506
19027
  // Dimension stacking without segments draws one plain bar: nothing to name
18507
19028
  if (this.stackConfig.by !== withStyled.StackBy.SCENARIOS && (!firstRow.stackSegments || firstRow.stackSegments.length === 0)) {
18508
19029
  return;
@@ -18527,6 +19048,11 @@ class StructureChart {
18527
19048
  }
18528
19049
  // Single group: one header per segment, centered on the segment
18529
19050
  const [group] = groups;
19051
+ const totalDrawn = this.stackConfig.mode !== withStyled.StackMode.RELATIVE || this.stackConfig.labels === "value";
19052
+ if (this.stackConfig.totalTitle && totalDrawn) {
19053
+ // above the total of the first bar, which starts behind the bar
19054
+ new Label(headerGroup, this.position.getLabelPositionX(group.layout.positive * this.pixelPerUnit), headerY, "STACK_TOTAL_HEADER", this.stackConfig.totalTitle, this.styles, HookLocation.Bottom, HookLocation.Left).draw();
19055
+ }
18530
19056
  group.segments.forEach((seg, segIdx) => {
18531
19057
  const { start, end } = group.layout.segments[segIdx];
18532
19058
  drawHeader(axisX + ((start + end) / 2) * seg.dataPoint.pixelPerUnit, this.i18n.get(seg.scenario) || seg.scenario);
@@ -18579,7 +19105,7 @@ class StructureChart {
18579
19105
  return width;
18580
19106
  }
18581
19107
  calculateRightSideWidth(varianceType) {
18582
- var _a, _b, _c;
19108
+ var _a, _b, _c, _d, _e, _f;
18583
19109
  // Stacked charts: width based on the positive side of the stacks, not individual max
18584
19110
  if (this.isStacked()) {
18585
19111
  const labelToBar = this.styles.fontStyles.size * this.styles.scaleFactors.labelToBar;
@@ -18591,28 +19117,42 @@ class StructureChart {
18591
19117
  this.position.getCategoryToAxisSpaceing() +
18592
19118
  this.calculateCategoryWidth());
18593
19119
  }
18594
- return Math.max(width, this.titleLength);
19120
+ if ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.totalTitle) {
19121
+ const title = CalculateSize(this.stackConfig.totalTitle, {
19122
+ font: this.styles.fontStyles.font,
19123
+ fontSize: this.styles.fontStyles.size + "px",
19124
+ }).width;
19125
+ width = Math.max(width, this.stackSides.positive * this.pixelPerUnit + labelToBar + title);
19126
+ }
19127
+ return Math.max(width, this.titleLength, (_c = (_b = this.sumColumns()) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0, this.referenceLineExtent());
18595
19128
  }
18596
19129
  let width = 0;
18597
19130
  const labelToBar = this.styles.fontStyles.size * this.styles.scaleFactors.labelToBar;
18598
19131
  if (VarianceType$1.NONE === varianceType &&
18599
- ((_a = this.highestDataPointValue) === null || _a === void 0 ? void 0 : _a.value) != null &&
19132
+ ((_d = this.highestDataPointValue) === null || _d === void 0 ? void 0 : _d.value) != null &&
18600
19133
  this.highestDataPointValue.value >= 0) {
18601
19134
  const sizeLabelValue = this.calculateTextBoxWidth(this.highestDataPointValue.value);
18602
19135
  width = Math.abs(this.highestDataPointValue.getScaledUnit()) + labelToBar + sizeLabelValue;
18603
19136
  }
18604
19137
  else if (VarianceType$1.RELATIVE === varianceType &&
18605
- ((_b = this.highestVarianceDataPointValue) === null || _b === void 0 ? void 0 : _b.value) != null &&
19138
+ ((_e = this.highestVarianceDataPointValue) === null || _e === void 0 ? void 0 : _e.value) != null &&
18606
19139
  this.highestVarianceDataPointValue.value >= 0) {
18607
19140
  const sizeLabelValue = this.calculatePercentageTextBoxWidth(this.highestVarianceDataPointValue.value);
18608
19141
  width = Math.abs(this.highestVarianceDataPointValue.getScaledPercentUnit()) + labelToBar + sizeLabelValue;
18609
19142
  }
18610
19143
  else if (VarianceType$1.ABSOLUTE === varianceType &&
18611
- ((_c = this.highestVarianceDataPointValue) === null || _c === void 0 ? void 0 : _c.value) != null &&
19144
+ ((_f = this.highestVarianceDataPointValue) === null || _f === void 0 ? void 0 : _f.value) != null &&
18612
19145
  this.highestVarianceDataPointValue.value >= 0) {
18613
19146
  const sizeLabelValue = this.calculateTextBoxWidth(this.highestVarianceDataPointValue.value);
18614
19147
  width = Math.abs(this.highestVarianceDataPointValue.getScaledUnit()) + labelToBar + sizeLabelValue;
18615
19148
  }
19149
+ width = Math.max(width, this.referenceLineExtent());
19150
+ // the bold number of a sum row stands at the axis
19151
+ for (const row of this.dataModel) {
19152
+ if (row.sum && VarianceType$1.NONE === varianceType && Number.isFinite(row.scenario1.value)) {
19153
+ width = Math.max(width, this.sumRowExtent(row));
19154
+ }
19155
+ }
18616
19156
  if (width <= this.titleLength) {
18617
19157
  return this.titleLength;
18618
19158
  }
@@ -18623,6 +19163,7 @@ class StructureChart {
18623
19163
  * at the stack dimension level and attach stackSegments to each dataModel row.
18624
19164
  */
18625
19165
  populateDimensionStackSegments(scenarios, _stackConfig, level) {
19166
+ var _a;
18626
19167
  if (this.rowCount === 0 || !this.fromExpr || scenarios.length === 0)
18627
19168
  return;
18628
19169
  // Derive stack column from level: stack by the next-lower hierarchy dimension
@@ -18641,6 +19182,7 @@ class StructureChart {
18641
19182
  let result;
18642
19183
  try {
18643
19184
  result = this.db.exec(`SELECT [${displayColumn}] as displayGroup, [${stackColumn}] as stackLabel, ` +
19185
+ `MIN([${stackColumn}Index]) as stackIndex, ` +
18644
19186
  `SUM([${scenario}] * transformOperator(operation)) as stackValue ` +
18645
19187
  `FROM ${this.fromExpr} GROUP BY [${displayColumn}], [${stackColumn}]`);
18646
19188
  }
@@ -18648,19 +19190,46 @@ class StructureChart {
18648
19190
  this.failQuery(e);
18649
19191
  return;
18650
19192
  }
19193
+ // The series of the chart: by the index column of the stack dimension, else in the order of the rows
19194
+ const series = new Map();
19195
+ for (const row of result) {
19196
+ if (row.stackValue == null || row.stackLabel == null)
19197
+ continue;
19198
+ const label = row.stackLabel;
19199
+ const index = Number.isFinite(Number(row.stackIndex)) && row.stackIndex != null ? Number(row.stackIndex) : NaN;
19200
+ const known = series.get(label);
19201
+ if (known === undefined || (Number.isNaN(known) && !Number.isNaN(index)) || index < known) {
19202
+ series.set(label, index);
19203
+ }
19204
+ }
19205
+ const order = [...series.keys()];
19206
+ if ([...series.values()].every((index) => !Number.isNaN(index))) {
19207
+ order.sort((a, b) => series.get(a) - series.get(b));
19208
+ }
18651
19209
  // Group results by displayGroup
18652
19210
  const groupMap = new Map();
18653
19211
  for (const row of result) {
18654
19212
  const key = row.displayGroup;
18655
19213
  if (!groupMap.has(key))
18656
- groupMap.set(key, []);
19214
+ groupMap.set(key, new Map());
18657
19215
  if (row.stackValue != null && row.stackLabel != null) {
18658
- groupMap.get(key).push({ label: row.stackLabel, value: row.stackValue });
19216
+ groupMap.get(key).set(row.stackLabel, row.stackValue);
18659
19217
  }
18660
19218
  }
18661
- // Attach stackSegments to each dataModel row
19219
+ // the REST row stands for the rows the limit cut off: it gets their sum per series
19220
+ const shown = new Set(this.dataModel.map((row) => row.category));
19221
+ const rest = new Map();
19222
+ for (const [category, values] of groupMap) {
19223
+ if (shown.has(category))
19224
+ continue;
19225
+ for (const [label, value] of values) {
19226
+ rest.set(label, ((_a = rest.get(label)) !== null && _a !== void 0 ? _a : 0) + value);
19227
+ }
19228
+ }
19229
+ // Attach stackSegments to each dataModel row: every row has every series, so place and colour stay
18662
19230
  for (const row of this.dataModel) {
18663
- const segments = groupMap.get(row.category);
19231
+ const values = row.id === REST_ROW_ID && !groupMap.has(row.category) ? rest : groupMap.get(row.category);
19232
+ const segments = values && values.size > 0 ? order.map((label) => { var _a; return ({ label, value: (_a = values.get(label)) !== null && _a !== void 0 ? _a : NaN }); }) : undefined;
18664
19233
  if (segments && segments.length > 0) {
18665
19234
  row.stackSegments = segments.map((seg) => {
18666
19235
  const dataPoint = new DataPoint$1(seg.value, scenario, this.pixelPerUnit, Scenario$1.NEU);
@@ -18673,6 +19242,342 @@ class StructureChart {
18673
19242
  }
18674
19243
  }
18675
19244
  }
19245
+ /** A sum row that is printed as numbers: every stack but a 100 % stack, where it is a bar of shares. */
19246
+ isTextSum(row) {
19247
+ return !!row.sum && !!this.stackConfig && this.stackConfig.mode !== withStyled.StackMode.RELATIVE;
19248
+ }
19249
+ isItalic(category) {
19250
+ return this.italicCategories.includes(category);
19251
+ }
19252
+ hasPercentMark() {
19253
+ var _a;
19254
+ return (!!((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.percentMark) &&
19255
+ this.stackConfig.mode === withStyled.StackMode.RELATIVE &&
19256
+ this.variancesDataModel.length === 0 &&
19257
+ this.isStacked());
19258
+ }
19259
+ /**
19260
+ * Adds the sum rows: one below the rows of each `rowGroup`, which keeps the rows of a
19261
+ * group together, and one over all rows at the end.
19262
+ */
19263
+ addSumRows(scenarios) {
19264
+ if (this.sums === "none" || this.dataModel.length === 0)
19265
+ return;
19266
+ // a cell without a value is left out, and a sum over no value stays NaN
19267
+ const add = (sum, value) => Number.isFinite(value) ? (Number.isFinite(sum) ? sum : 0) + value : sum;
19268
+ const sumRow = (members, category, sum) => {
19269
+ var _a, _b;
19270
+ const point = (key, index) => new DataPoint$1(scenarios[index] === undefined
19271
+ ? undefined
19272
+ : members.reduce((total, row) => add(total, row[key].value), NaN), scenarios[index], this.pixelPerUnit, Scenario$1.NEU);
19273
+ const row = {
19274
+ id: 10000 + this.dataModel.length,
19275
+ category,
19276
+ type: VarianceType$1.NONE,
19277
+ scenario1: point("scenario1", 0),
19278
+ scenario2: point("scenario2", 1),
19279
+ scenario3: point("scenario3", 2),
19280
+ scenario4: point("scenario4", 3),
19281
+ sum,
19282
+ };
19283
+ if (members.some((member) => member.stackSegments)) {
19284
+ const values = new Map();
19285
+ for (const member of members) {
19286
+ for (const segment of (_a = member.stackSegments) !== null && _a !== void 0 ? _a : []) {
19287
+ values.set(segment.label, add((_b = values.get(segment.label)) !== null && _b !== void 0 ? _b : NaN, segment.value));
19288
+ }
19289
+ }
19290
+ row.stackSegments = [...values].map(([label, value]) => {
19291
+ const dataPoint = new DataPoint$1(value, scenarios[0], this.pixelPerUnit, Scenario$1.NEU);
19292
+ return { label, value, dataPoint };
19293
+ });
19294
+ }
19295
+ return row;
19296
+ };
19297
+ const rows = this.dataModel;
19298
+ const result = [];
19299
+ const groups = this.sums === "total" ? new Map() : this.rowGroups();
19300
+ if (groups.size > 0) {
19301
+ const names = [...new Set([...groups.values()].sort((a, b) => a.index - b.index).map((group) => group.name))];
19302
+ for (const name of names) {
19303
+ const members = rows.filter((row) => { var _a; return ((_a = groups.get(row.category)) === null || _a === void 0 ? void 0 : _a.name) === name; });
19304
+ if (members.length === 0)
19305
+ continue;
19306
+ const sum = sumRow(members, name, "group");
19307
+ sum.gapAfter = true;
19308
+ result.push(...members, sum);
19309
+ }
19310
+ // a row without a group, like REST, comes last
19311
+ result.push(...rows.filter((row) => !groups.has(row.category)));
19312
+ }
19313
+ else {
19314
+ result.push(...rows);
19315
+ }
19316
+ if (this.sums === "total" || this.sums === "all") {
19317
+ result.push(sumRow(rows, this.sumTitle || "SUM_TOTAL", "total"));
19318
+ }
19319
+ this.dataModel = result;
19320
+ }
19321
+ /** The `rowGroup` of each row of a chart at level `category`, with the place of the group. */
19322
+ rowGroups() {
19323
+ const groups = new Map();
19324
+ if (this.level !== withStyled.AggregationLevel.CATEGORY && this.level !== withStyled.AggregationLevel.CATEGORYINDEX)
19325
+ return groups;
19326
+ let result;
19327
+ try {
19328
+ result = this.db.exec(`SELECT [category] as category, [rowGroup] as rowGroup, MIN([rowGroupIndex]) as rowGroupIndex ` +
19329
+ `FROM ${this.fromExpr} GROUP BY [category], [rowGroup]`);
19330
+ }
19331
+ catch (e) {
19332
+ this.failQuery(e);
19333
+ return groups;
19334
+ }
19335
+ const first = new Map();
19336
+ result.forEach((row, position) => {
19337
+ var _a;
19338
+ if (row.rowGroup == null || row.rowGroup === "")
19339
+ return;
19340
+ const name = String(row.rowGroup);
19341
+ const given = Number(row.rowGroupIndex);
19342
+ // without an index column the groups keep the order of the rows
19343
+ const index = row.rowGroupIndex != null && Number.isFinite(given) ? given : ((_a = first.get(name)) !== null && _a !== void 0 ? _a : position);
19344
+ if (!first.has(name))
19345
+ first.set(name, index);
19346
+ groups.set(String(row.category), { name, index: Math.min(index, first.get(name)) });
19347
+ });
19348
+ return groups;
19349
+ }
19350
+ /** Rows of different height (`stack.thickness: total`) and the room below a group. Null: all rows are equal. */
19351
+ rowLayout() {
19352
+ var _a;
19353
+ const rows = this.dataModel;
19354
+ // the component does not set it together with variances: a variance bar has one thickness
19355
+ const byTotal = ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.thickness) === "total";
19356
+ // the name of the scenario stands below the last bar: it needs room when a sum row follows
19357
+ const lastBar = rows.reduce((last, row, index) => (row.sum ? last : index), -1);
19358
+ const nameBelow = !this.stackConfig && !this.scenarioLabelTop && lastBar >= 0 && lastBar < rows.length - 1;
19359
+ if (!byTotal && !nameBelow && !rows.some((row) => row.gapAfter))
19360
+ return null;
19361
+ const totals = rows.map((row) => {
19362
+ if (!byTotal || row.sum)
19363
+ return null;
19364
+ const groups = this.stackGroups(row);
19365
+ const front = groups[groups.length - 1];
19366
+ return front ? Math.abs(front.layout.total) : 0;
19367
+ });
19368
+ const weights = this.rowWeights(totals);
19369
+ const start = [];
19370
+ const weight = [];
19371
+ let at = 0;
19372
+ rows.forEach((row, index) => {
19373
+ const rowWeight = weights[index];
19374
+ start.push(at);
19375
+ weight.push(rowWeight);
19376
+ at +=
19377
+ rowWeight + (row.gapAfter && index < rows.length - 1 ? 0.5 : 0) + (nameBelow && index === lastBar ? 0.8 : 0);
19378
+ });
19379
+ return { start, weight, total: at };
19380
+ }
19381
+ /**
19382
+ * The height of each row in units of a normal row: by its total, with the same height
19383
+ * over all. A row is at least one line of text high, and the others give up that room.
19384
+ * Null stands for a row that keeps the normal height.
19385
+ */
19386
+ rowWeights(totals) {
19387
+ const minimum = Math.min(1, 1 / this.styles.scaleFactors.categoryWidth);
19388
+ const weights = totals.map((total) => (total === null ? 1 : 0));
19389
+ const open = new Set(totals.flatMap((total, index) => (total === null ? [] : [index])));
19390
+ let room = open.size;
19391
+ // a row below the minimum is set to it, then the rest is shared again
19392
+ for (;;) {
19393
+ const sum = [...open].reduce((all, index) => all + totals[index], 0);
19394
+ if (sum <= 0) {
19395
+ open.forEach((index) => (weights[index] = room / open.size));
19396
+ break;
19397
+ }
19398
+ const small = [...open].filter((index) => (totals[index] / sum) * room < minimum);
19399
+ if (small.length === 0 || small.length === open.size) {
19400
+ open.forEach((index) => (weights[index] = (totals[index] / sum) * room));
19401
+ break;
19402
+ }
19403
+ for (const index of small) {
19404
+ weights[index] = minimum;
19405
+ room -= minimum;
19406
+ open.delete(index);
19407
+ }
19408
+ }
19409
+ return weights;
19410
+ }
19411
+ boldWidth(text) {
19412
+ return CalculateSize(text, {
19413
+ font: this.styles.fontStyles.font,
19414
+ fontSize: this.styles.fontStyles.size + "px",
19415
+ fontWeight: "bold",
19416
+ }).width;
19417
+ }
19418
+ sumText(value) {
19419
+ const digits = this.dataFormatDigits.decimal;
19420
+ return Formatter.number(value, "decimal", digits, digits, this.measureScale.value, this.styles.locale);
19421
+ }
19422
+ /**
19423
+ * Where the numbers of the text sum rows stand, as distance from the axis: one column
19424
+ * per series, the same for all sum rows, then the total. Null without such a row.
19425
+ */
19426
+ sumColumns() {
19427
+ const rows = this.dataModel.filter((row) => this.isTextSum(row));
19428
+ if (rows.length === 0)
19429
+ return null;
19430
+ const font = this.styles.fontStyles.size;
19431
+ const key = font * 0.6;
19432
+ const keyGap = font * 0.3;
19433
+ const columnGap = font * 1.4;
19434
+ const widths = [];
19435
+ let totalWidth = 0;
19436
+ for (const row of rows) {
19437
+ const groups = this.stackGroups(row);
19438
+ const front = groups[groups.length - 1];
19439
+ if (!front)
19440
+ continue;
19441
+ front.segments.forEach((segment, index) => {
19442
+ var _a;
19443
+ const width = Number.isFinite(segment.value) ? this.boldWidth(this.sumText(segment.value)) : 0;
19444
+ widths[index] = Math.max((_a = widths[index]) !== null && _a !== void 0 ? _a : 0, width);
19445
+ });
19446
+ totalWidth = Math.max(totalWidth, this.boldWidth(this.sumText(front.layout.total)));
19447
+ }
19448
+ const x = [];
19449
+ let at = font * 0.3;
19450
+ // one series: its sum is the total
19451
+ for (const width of widths.length > 1 ? widths : []) {
19452
+ x.push(at);
19453
+ at += key + keyGap + width + columnGap;
19454
+ }
19455
+ return { x, totalX: at, width: at + totalWidth, key, keyGap };
19456
+ }
19457
+ /** A sum row of a stack as numbers: per series a small square in its colour and the sum, then the total. */
19458
+ drawSumText(row, index, group) {
19459
+ const columns = this.sumColumns();
19460
+ const groups = this.stackGroups(row);
19461
+ const front = groups[groups.length - 1];
19462
+ if (!columns || !front)
19463
+ return;
19464
+ const axisX = this.position.getBarPositionX();
19465
+ const y = this.position.getBarCenterPositionY(index);
19466
+ const colors = this.styles.stackColors;
19467
+ const sumGroup = group.group().id(`stacked_sum_${index}`);
19468
+ front.segments.forEach((segment, segmentIndex) => {
19469
+ if (!Number.isFinite(segment.value) || columns.x[segmentIndex] === undefined)
19470
+ return;
19471
+ const x = axisX + columns.x[segmentIndex];
19472
+ sumGroup
19473
+ .rect(columns.key, columns.key)
19474
+ .fill({ color: colors[segmentIndex % colors.length] })
19475
+ .cy(y)
19476
+ .x(x);
19477
+ new Label(sumGroup, x + columns.key + columns.keyGap, y, `SUM_SEG_${segmentIndex}`, segment.value, this.styles, HookLocation.Center, HookLocation.Left)
19478
+ .setEmphasis(true, false)
19479
+ .setPoint(segment.dataPoint.key)
19480
+ .draw(this.dataFormatDigits, this.measureScale);
19481
+ });
19482
+ new Label(sumGroup, axisX + columns.totalX, y, "SUM_TOTAL", front.layout.total, this.styles, HookLocation.Center, HookLocation.Left)
19483
+ .setEmphasis(true, false)
19484
+ .setPoint(levelKey(this.level, row.category), "total")
19485
+ .draw(this.dataFormatDigits, this.measureScale);
19486
+ }
19487
+ /** How far a sum row reaches right of the axis, in px. */
19488
+ sumRowExtent(row) {
19489
+ var _a, _b, _c;
19490
+ const labelToBar = this.styles.fontStyles.size * this.styles.scaleFactors.labelToBar;
19491
+ if (this.variancesDataModel.length > 0)
19492
+ return 0;
19493
+ if (this.isTextSum(row))
19494
+ return (_b = (_a = this.sumColumns()) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0;
19495
+ if (this.stackConfig) {
19496
+ const total = this.stackConfig.labels === "value" ? labelToBar + this.boldWidth(this.sumText((_c = row.scenario1.value) !== null && _c !== void 0 ? _c : 0)) : 0;
19497
+ return this.stackSides.positive * this.pixelPerUnit + total;
19498
+ }
19499
+ return Number.isFinite(row.scenario1.value)
19500
+ ? labelToBar + this.boldWidth(this.sumText(row.scenario1.value))
19501
+ : 0;
19502
+ }
19503
+ /** Where the reference line stands, as distance from the axis in px. Null without a line in this chart. */
19504
+ referenceLineOffset() {
19505
+ var _a;
19506
+ const line = this.referenceLine;
19507
+ if (!line || !Number.isFinite(line.value) || this.variancesDataModel.length > 0)
19508
+ return null;
19509
+ const relative = ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) === withStyled.StackMode.RELATIVE;
19510
+ return (relative ? line.value / 100 : line.value) * this.pixelPerUnit;
19511
+ }
19512
+ /** The room right of the axis that the reference line and its label need. */
19513
+ referenceLineExtent() {
19514
+ var _a;
19515
+ const offset = this.referenceLineOffset();
19516
+ if (offset === null || offset <= 0)
19517
+ return 0;
19518
+ const label = ((_a = this.referenceLine) === null || _a === void 0 ? void 0 : _a.label)
19519
+ ? CalculateSize(this.referenceLine.label, {
19520
+ font: this.styles.fontStyles.font,
19521
+ fontSize: this.styles.fontStyles.size + "px",
19522
+ }).width
19523
+ : 0;
19524
+ return offset + Math.max(label / 2, this.styles.fontStyles.size * 0.25);
19525
+ }
19526
+ /** The end of a 100 % stack: a line along the bar ends and one `100%` below it. */
19527
+ drawPercentMark(svgContainer) {
19528
+ if (!this.hasPercentMark())
19529
+ return;
19530
+ const group = svgContainer.group().id("PercentMark");
19531
+ const font = this.styles.fontStyles.size;
19532
+ const x = this.position.getBarPositionX() + this.stackSides.positive * this.pixelPerUnit;
19533
+ const top = this.position.getAxisPositionY();
19534
+ const bottom = this.position.getAxisEndPositionY();
19535
+ const tip = bottom + font * 0.15;
19536
+ const base = tip + font * 0.5;
19537
+ group.line(x, top, x, bottom).stroke({ color: "#000000", width: this.position.spacings.axisLineWidth });
19538
+ group.polygon(`${x},${tip} ${x - font * 0.25},${base} ${x + font * 0.25},${base}`).fill("#000000");
19539
+ new Label(group, x, base + font * 0.1, "PERCENT_MARK", "100%", this.styles, HookLocation.Top, HookLocation.Center)
19540
+ .setEmphasis(true, false)
19541
+ .draw();
19542
+ }
19543
+ /** A line across the bars at one value, with its label above the first bar. In a 100 % stack the value is a percent. */
19544
+ drawReferenceLine(svgContainer) {
19545
+ const line = this.referenceLine;
19546
+ const offset = this.referenceLineOffset();
19547
+ if (!line || offset === null || this.dataModel.length === 0)
19548
+ return;
19549
+ const group = svgContainer.group().id("ReferenceLine");
19550
+ const font = this.styles.fontStyles.size;
19551
+ const color = `var(--bn-annotation-color, ${withHasError.SYSTEM_STYLE_DEFAULTS["bn-annotation"].color})`;
19552
+ const x = this.position.getBarPositionX() + offset;
19553
+ const top = this.position.getStackedHeaderPositionY() - (this.stackConfig || this.scenarioLabelTop ? font * 1.1 : 0);
19554
+ // down to the last row from the top that reaches the line, or over all rows when the first one does not
19555
+ const reaches = (row) => {
19556
+ var _a, _b;
19557
+ if (row.sum)
19558
+ return false;
19559
+ if (!this.stackConfig)
19560
+ return ((_a = row.scenario1.value) !== null && _a !== void 0 ? _a : 0) >= line.value;
19561
+ const first = (_b = this.stackGroups(row)[0]) === null || _b === void 0 ? void 0 : _b.layout.segments[0];
19562
+ return first != null && first.end * this.pixelPerUnit >= x - this.position.getBarPositionX();
19563
+ };
19564
+ let lastBar = this.dataModel.findIndex((row) => !reaches(row)) - 1;
19565
+ if (lastBar < 0)
19566
+ lastBar = this.dataModel.reduce((last, row, index) => (row.sum ? last : index), 0);
19567
+ const bottom = this.position.getBarCenterPositionY(lastBar) + this.position.getBarWidthAt(lastBar) / 2;
19568
+ group
19569
+ .line(x, top, x, bottom)
19570
+ .attr("style", `stroke: ${color}; stroke-width: ${Math.max(1, this.position.spacings.axisLineWidth)}px`);
19571
+ group
19572
+ .polygon(`${x},${top + font * 0.5} ${x - font * 0.25},${top} ${x + font * 0.25},${top}`)
19573
+ .attr("style", `fill: ${color}`);
19574
+ if (line.label) {
19575
+ group
19576
+ .plain(line.label)
19577
+ .attr({ x, y: top - font * 0.3, "text-anchor": "middle" })
19578
+ .attr("style", `fill: ${color}`);
19579
+ }
19580
+ }
18676
19581
  hasNoData() {
18677
19582
  return this.dataModel.length === 0;
18678
19583
  }
@@ -18822,6 +19727,16 @@ const BnChartStructureRenderer = class {
18822
19727
  /** @internal */
18823
19728
  this.stackConfig = null;
18824
19729
  /** @internal */
19730
+ this.sums = "none";
19731
+ /** @internal */
19732
+ this.sumTitle = "";
19733
+ /** @internal */
19734
+ this.scenarioLabelTop = false;
19735
+ /** @internal */
19736
+ this.referenceLine = null;
19737
+ /** @internal */
19738
+ this.italicCategories = [];
19739
+ /** @internal */
18825
19740
  this.parentDimensions = { width: 0, height: 0 };
18826
19741
  withHasError.withComponentStatus(this);
18827
19742
  }
@@ -19059,6 +19974,11 @@ const BnChartStructureRenderer = class {
19059
19974
  showMeasureScale: this.showMeasureScale,
19060
19975
  dataFormatDigits: this.dataFormatDigits,
19061
19976
  stackConfig: this.stackConfig,
19977
+ sums: this.sums,
19978
+ sumTitle: this.sumTitle,
19979
+ scenarioLabelTop: this.scenarioLabelTop,
19980
+ referenceLine: this.referenceLine,
19981
+ italicCategories: this.italicCategories,
19062
19982
  });
19063
19983
  }
19064
19984
  prepareStyle() {
@@ -25335,12 +26255,29 @@ const Context = class {
25335
26255
  constructor(hostRef) {
25336
26256
  index.registerInstance(this, hostRef);
25337
26257
  this.bnNotationChange = index.createEvent(this, "bnNotationChange", 7);
26258
+ /**
26259
+ * Group separator of every number in the document, in place of the one of
26260
+ * the locale: `thin-space`, `space`, `none`, or the separator itself. It
26261
+ * holds for the whole page, also for a context that does not set it.
26262
+ *
26263
+ * @default "" (the separator of the locale)
26264
+ * @example group-separator="thin-space"
26265
+ */
26266
+ this.groupSeparator = "";
26267
+ this.setsGroupSeparator = false;
25338
26268
  /** The page numbers this context wrote. A number that is not in here was set by the author and is left alone. */
25339
26269
  this.assignedPageNumbers = new WeakMap();
25340
26270
  this.notationSubscriptions = [];
25341
26271
  withHasError.withComponentStatus(this);
25342
26272
  this.errors = withHasError.withHasError(this);
25343
26273
  }
26274
+ setGroupSeparator(newValue) {
26275
+ var _a;
26276
+ const named = { "thin-space": "\u2009", space: "\u00a0", none: "" };
26277
+ // no value: the separator of the locale
26278
+ Formatter.groupSeparator = newValue ? ((_a = named[newValue]) !== null && _a !== void 0 ? _a : newValue) : null;
26279
+ this.setsGroupSeparator = !!newValue;
26280
+ }
25344
26281
  setLocale(newValue) {
25345
26282
  this.stores.context.state.locale = newValue;
25346
26283
  }
@@ -25352,6 +26289,9 @@ const Context = class {
25352
26289
  if (this.locale) {
25353
26290
  this.stores.context.state.locale = this.locale;
25354
26291
  }
26292
+ if (this.groupSeparator) {
26293
+ this.setGroupSeparator(this.groupSeparator);
26294
+ }
25355
26295
  // a removed scaling group is a "set" too: its entry is set to undefined
25356
26296
  const notify = () => this.bnNotationChange.emit();
25357
26297
  this.notationSubscriptions = [
@@ -25370,6 +26310,11 @@ const Context = class {
25370
26310
  }
25371
26311
  disconnectedCallback() {
25372
26312
  var _a, _b;
26313
+ // only the context that set it takes it back
26314
+ if (this.setsGroupSeparator) {
26315
+ Formatter.groupSeparator = null;
26316
+ this.setsGroupSeparator = false;
26317
+ }
25373
26318
  this.notationSubscriptions.forEach((unsubscribe) => unsubscribe());
25374
26319
  this.notationSubscriptions = [];
25375
26320
  (_a = this.pageObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
@@ -25522,10 +26467,13 @@ const Context = class {
25522
26467
  componentWillUpdate() { }
25523
26468
  componentDidUpdate() { }
25524
26469
  render() {
25525
- return (index.h(index.Host, { key: 'e2c985d07c329d796c37804f492907f0f49366d2' }, index.h("slot", { key: '90c11954a1a9365bc46ddacb2a3b8f72bbc4e523' })));
26470
+ return (index.h(index.Host, { key: '71bdc7dcbcadcae35b67f4d3fbb47e8ee204b3bb' }, index.h("slot", { key: 'c2fb4c85cb1a3b3af6ec013d0e558c0ef611358d' })));
25526
26471
  }
25527
26472
  get element() { return index.getElement(this); }
25528
26473
  static get watchers() { return {
26474
+ "groupSeparator": [{
26475
+ "setGroupSeparator": 0
26476
+ }],
25529
26477
  "locale": [{
25530
26478
  "setLocale": 0
25531
26479
  }]
@@ -27019,6 +27967,16 @@ const LayoutCard = class {
27019
27967
  * card-custom-template='"a a" "b c"'></bn-layout-card>
27020
27968
  */
27021
27969
  this.cardCustomTemplate = '"a b" "c d"';
27970
+ /**
27971
+ * Puts the child after the last slot of the template on top of the grid,
27972
+ * in the cells this CSS `grid-area` names by line numbers:
27973
+ * `row-start / column-start / row-end / column-end`. Use it for a text or a
27974
+ * comment list in the free part of a chart.
27975
+ *
27976
+ * @default "" (no overlay)
27977
+ * @example card-overlay-area="4 / 3 / 7 / 5"
27978
+ */
27979
+ this.cardOverlayArea = "";
27022
27980
  /**
27023
27981
  * Gap between grid cells in pixels.
27024
27982
  */
@@ -27099,7 +28057,20 @@ const LayoutCard = class {
27099
28057
  const items = this.createDivAreaStyles(slotNames);
27100
28058
  return (index.h(index.Fragment, null, items.map((value, index$1) => {
27101
28059
  return (index.h("div", { style: value }, index.h("slot", { name: "card-slot-" + index$1 })));
27102
- })));
28060
+ }), this.overlayArea() ? (index.h("div", { style: { display: "flex", overflow: "hidden", "grid-area": this.overlayArea(), "z-index": "1" } }, index.h("slot", { name: "card-slot-" + items.length }))) : null));
28061
+ }
28062
+ /** The overlay area when it is four line numbers inside the grid of the layout, else nothing. */
28063
+ overlayArea() {
28064
+ var _a, _b;
28065
+ const area = ((_a = this.cardOverlayArea) !== null && _a !== void 0 ? _a : "").trim();
28066
+ if (!/^\d+(\s*\/\s*\d+){3}$/.test(area))
28067
+ return undefined;
28068
+ const [rowStart, columnStart, rowEnd, columnEnd] = area.split("/").map((line) => Number(line.trim()));
28069
+ const rows = this.getRowCount(this.cardLayout);
28070
+ const columns = ((_b = templateRows(this.getTemplatePattern(this.cardLayout))[0]) === null || _b === void 0 ? void 0 : _b.length) || 1;
28071
+ // a line outside the template would add rows or columns to the grid
28072
+ const inside = rowStart >= 1 && columnStart >= 1 && rowEnd <= rows + 1 && columnEnd <= columns + 1;
28073
+ return inside && rowStart < rowEnd && columnStart < columnEnd ? area : undefined;
27103
28074
  }
27104
28075
  extractSlotNames(styleElement) {
27105
28076
  return templateSlotNames(styleElement);
@@ -27108,6 +28079,7 @@ const LayoutCard = class {
27108
28079
  return templateAreas(name, this.cardCustomTemplate);
27109
28080
  }
27110
28081
  componentWillRender() {
28082
+ var _a;
27111
28083
  const problem = this.cardLayout === CUSTOM_TEMPLATE ? templateProblem(this.cardCustomTemplate) : undefined;
27112
28084
  if (problem) {
27113
28085
  this.errors.addOrReplace({
@@ -27119,6 +28091,16 @@ const LayoutCard = class {
27119
28091
  else {
27120
28092
  this.errors.remove("WARN_cardCustomTemplate");
27121
28093
  }
28094
+ if (((_a = this.cardOverlayArea) !== null && _a !== void 0 ? _a : "").trim() !== "" && !this.overlayArea()) {
28095
+ this.errors.addOrReplace({
28096
+ id: "WARN_cardOverlayArea",
28097
+ type: "warning",
28098
+ message: `cardOverlayArea: '${this.cardOverlayArea}' is not 'row-start / column-start / row-end / column-end' in line numbers of the layout.`,
28099
+ });
28100
+ }
28101
+ else {
28102
+ this.errors.remove("WARN_cardOverlayArea");
28103
+ }
27122
28104
  }
27123
28105
  setCardClass() {
27124
28106
  if (this.cardShowBorder === true) {
@@ -27145,7 +28127,7 @@ const LayoutCard = class {
27145
28127
  var _a;
27146
28128
  const style = this.getLayoutStyle();
27147
28129
  const arrOfSlots = this.extractSlotNames(style["grid-template-areas"]);
27148
- return (index.h("bn-card", { key: '3db479047905de01ac517491f2d68a9bd0a3a576', styles: this.styles, "selected-style": this.selectedStyle, class: this.setCardClass() }, index.h("div", { key: 'fd9948acd84ce55badf87a7e03d733d1e75a1bea', class: "cardtitle" }, index.h("bn-title", { key: '21200c96fb03d403fa616b093d753ea4b746c6f2', "i18n-namespace": (_a = this.i18nNamespace) !== null && _a !== void 0 ? _a : this.titleNamespace, ruleset: this.titleProp("ruleset"), "title-font-size": this.componentStyle(($) => { var _a; return (_a = $ === null || $ === void 0 ? void 0 : $["bn-layout-card"]) === null || _a === void 0 ? void 0 : _a.titleFontSize; }), "business-unit": this.titleBusinessUnit, scenarios: this.titleProp("titleScenarios"), variances: this.titleProp("titleVariances"), order: this.titleProp("titleOrder"), "order-direction": this.titleProp("titleOrderDirection"), measures: this.titleMeasures, "date-start": this.titleDateStart, "date-end": this.titleDateEnd, "date-format": this.titleDateFormat, "date-link": this.titleDateLink }), this.titleImage != null && this.titleImage !== "" ? (index.h("img", { class: "image", src: this.prepareTitleImage(this.titleImage) })) : ("")), index.h("bn-body", { key: 'c5b1957822ff216d33084154afdf6deb3e4426cc' }, index.h("div", { key: 'bc17f6f73825894641f775137eaefd5059a25cf6', style: style, "data-bn-fit-content": this.cardFitToContent ? String(this.getRowCount(this.cardLayout)) : null }, this.getSlots(arrOfSlots))), index.h("bn-footer", { key: 'cfbeba76eaf11358e92002d309cafae19d2525e2', text: this.footerText, "page-number": "0", "display-page-number": "false" })));
28130
+ return (index.h("bn-card", { key: 'ef0b6da39a573f162c096c21803e4d647b2817c2', styles: this.styles, "selected-style": this.selectedStyle, class: this.setCardClass() }, index.h("div", { key: '9116df8c88198ebc922dc91d5f45a032a81d37d1', class: "cardtitle" }, index.h("bn-title", { key: '6d9645d5229c3bf32ef944c1f296a55dbe4b3bee', "i18n-namespace": (_a = this.i18nNamespace) !== null && _a !== void 0 ? _a : this.titleNamespace, ruleset: this.titleProp("ruleset"), "title-font-size": this.componentStyle(($) => { var _a; return (_a = $ === null || $ === void 0 ? void 0 : $["bn-layout-card"]) === null || _a === void 0 ? void 0 : _a.titleFontSize; }), "business-unit": this.titleBusinessUnit, scenarios: this.titleProp("titleScenarios"), variances: this.titleProp("titleVariances"), order: this.titleProp("titleOrder"), "order-direction": this.titleProp("titleOrderDirection"), measures: this.titleMeasures, "date-start": this.titleDateStart, "date-end": this.titleDateEnd, "date-format": this.titleDateFormat, "date-link": this.titleDateLink }), this.titleImage != null && this.titleImage !== "" ? (index.h("img", { class: "image", src: this.prepareTitleImage(this.titleImage) })) : ("")), index.h("bn-body", { key: '65803497adad305f02874acf441867e9ba200945' }, index.h("div", { key: '61a57b87b0ffb76c238b2e2facb7d5b855d5dc10', style: style, "data-bn-fit-content": this.cardFitToContent ? String(this.getRowCount(this.cardLayout)) : null }, this.getSlots(arrOfSlots))), index.h("bn-footer", { key: '8589da921d0f8dac8e9a2af23315ded3a3ee3d51', text: this.footerText, "page-number": "0", "display-page-number": "false" })));
27149
28131
  }
27150
28132
  get element() { return index.getElement(this); }
27151
28133
  };