@bino-bi/bn-template-engine 1.0.0-next.48 → 1.0.0-next.50

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 (110) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-b3f5eba0.entry.js → p-2de524d0.entry.js} +1 -1
  3. package/dist/bn-template-engine/{p-a6017fce.entry.js → p-510d2ee6.entry.js} +1 -1
  4. package/dist/bn-template-engine/{p-6ab684a9.entry.js → p-8fc90dc8.entry.js} +1 -1
  5. package/dist/bn-template-engine/p-BFl7OwcC.js +1 -0
  6. package/dist/bn-template-engine/{p-3ktFZb1x.js → p-Bxa4pX1M.js} +1 -1
  7. package/dist/bn-template-engine/p-c1d679af.entry.js +1 -0
  8. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +628 -108
  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-text.cjs.entry.js +2 -2
  12. package/dist/cjs/{withStyled-DHKHBdRb.js → withStyled-pkdctrK9.js} +18 -1
  13. package/dist/cjs/{withTranslation-CLwC9a8V.js → withTranslation-BIzTNYZM.js} +1 -1
  14. package/dist/collection/components/bn-annotation-layer/bn-annotation-layer.css +19 -0
  15. package/dist/collection/components/bn-annotation-layer/bn-annotation-layer.js +65 -8
  16. package/dist/collection/components/bn-annotation-layer/utils/marks.js +85 -5
  17. package/dist/collection/components/bn-annotation-layer/utils/matchPoint.js +7 -1
  18. package/dist/collection/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.js +20 -6
  19. package/dist/collection/components/bn-chart-time/bn-chart-time.js +55 -23
  20. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +329 -53
  21. package/dist/collection/components/bn-chart-time/utils/elements/Column.js +4 -1
  22. package/dist/collection/components/bn-chart-time/utils/elements/Label.js +2 -1
  23. package/dist/collection/components/bn-chart-time/utils/elements/StackedColumn.js +53 -11
  24. package/dist/collection/utils/annotations.js +1 -1
  25. package/dist/collection/utils/constants.js +2 -0
  26. package/dist/collection/utils/layoutState/svgChartElements.js +10 -0
  27. package/dist/collection/utils/validate.js +16 -1
  28. package/dist/components/bn-annotation-layer.js +1 -1
  29. package/dist/components/bn-annotation-list.js +1 -1
  30. package/dist/components/bn-chart-bubble-renderer.js +1 -1
  31. package/dist/components/bn-chart-bubble.js +1 -1
  32. package/dist/components/bn-chart-bullet-renderer.js +1 -1
  33. package/dist/components/bn-chart-bullet.js +1 -1
  34. package/dist/components/bn-chart-scatter-renderer.js +1 -1
  35. package/dist/components/bn-chart-scatter.js +1 -1
  36. package/dist/components/bn-chart-structure-renderer.js +1 -1
  37. package/dist/components/bn-chart-structure.js +1 -1
  38. package/dist/components/bn-chart-time-renderer.js +1 -1
  39. package/dist/components/bn-chart-time.js +1 -1
  40. package/dist/components/bn-grid.js +1 -1
  41. package/dist/components/bn-image.js +1 -1
  42. package/dist/components/bn-layout-card.js +1 -1
  43. package/dist/components/bn-layout-page.js +1 -1
  44. package/dist/components/bn-page.js +1 -1
  45. package/dist/components/bn-table-renderer.js +1 -1
  46. package/dist/components/bn-table.js +1 -1
  47. package/dist/components/bn-text.js +1 -1
  48. package/dist/components/bn-title-renderer.js +1 -1
  49. package/dist/components/bn-title.js +1 -1
  50. package/dist/components/bn-tree.js +1 -1
  51. package/dist/components/{p-CLjuZoiT.js → p-B11cXOLy.js} +1 -1
  52. package/dist/components/p-BBdzTx8V.js +1 -0
  53. package/dist/components/{p-B1_wkOLx.js → p-BVNOmHh4.js} +1 -1
  54. package/dist/components/p-BXP6aagM.js +1 -0
  55. package/dist/components/{p-CG-iY7pQ.js → p-Blre9f28.js} +1 -1
  56. package/dist/components/p-CHJ6WE0l.js +1 -0
  57. package/dist/components/{p-Do4GqlMV.js → p-CHhxQoF9.js} +1 -1
  58. package/dist/components/{p-C-3TOa6K.js → p-CJ0-xdfZ.js} +1 -1
  59. package/dist/components/{p-BFoRIqDi.js → p-CO6bgquz.js} +1 -1
  60. package/dist/components/{p-CytMTBFu.js → p-CSJCkHEL.js} +1 -1
  61. package/dist/components/p-CVfmhtEW.js +1 -0
  62. package/dist/components/{p-Zuxd3z0q.js → p-Cc0gaLwp.js} +1 -1
  63. package/dist/components/p-CuUfiEu0.js +1 -0
  64. package/dist/components/{p-DUZCLRVu.js → p-D362XOg2.js} +1 -1
  65. package/dist/components/p-DBj1Yd3M.js +1 -0
  66. package/dist/components/{p-BjgkgCAQ.js → p-DHX92KDP.js} +1 -1
  67. package/dist/components/p-DHloMyxV.js +1 -0
  68. package/dist/components/{p-Uc0zvXcQ.js → p-Dd1QOWDV.js} +1 -1
  69. package/dist/components/p-DguYWLBj.js +1 -0
  70. package/dist/components/p-Do-IGHJk.js +1 -0
  71. package/dist/components/{p-DDo-fu3v.js → p-DsC0ew4j.js} +1 -1
  72. package/dist/components/p-HVN8BNWN.js +1 -0
  73. package/dist/components/{p-Dyzb4ika.js → p-YSRTB0jS.js} +1 -1
  74. package/dist/components/{p-CrZ_O3DT.js → p-k7heRDPP.js} +1 -1
  75. package/dist/components/{p-dO0utE8m.js → p-keKnrAVS.js} +1 -1
  76. package/dist/components/p-x0W2_FAX.js +1 -0
  77. package/dist/components/p-y12CmIFS.js +1 -0
  78. package/dist/esm/bn-annotation-layer_30.entry.js +628 -108
  79. package/dist/esm/bn-grid.entry.js +1 -1
  80. package/dist/esm/bn-image.entry.js +1 -1
  81. package/dist/esm/bn-text.entry.js +2 -2
  82. package/dist/esm/{withStyled-CTZFjg4L.js → withStyled-B62R20Zx.js} +18 -1
  83. package/dist/esm/{withTranslation-BESW5BNq.js → withTranslation-BEseMLQ6.js} +1 -1
  84. package/dist/schemas/stack.schema.json +22 -0
  85. package/dist/types/components/bn-annotation-layer/utils/marks.d.ts +48 -0
  86. package/dist/types/components/bn-annotation-layer/utils/matchPoint.d.ts +4 -0
  87. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +29 -6
  88. package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +51 -2
  89. package/dist/types/components/bn-chart-time/utils/elements/StackedColumn.d.ts +5 -1
  90. package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +6 -0
  91. package/dist/types/components.d.ts +6 -6
  92. package/dist/types/schemas.d.ts +6 -0
  93. package/dist/types/utils/annotations.d.ts +11 -1
  94. package/dist/types/utils/constants.d.ts +3 -1
  95. package/dist/types/utils/layoutState/types.d.ts +2 -0
  96. package/package.json +1 -1
  97. package/dist/bn-template-engine/p-203e7d6a.entry.js +0 -1
  98. package/dist/bn-template-engine/p-DXtYQE4s.js +0 -1
  99. package/dist/components/p-6gET6YXc.js +0 -1
  100. package/dist/components/p-BFWvVe7v.js +0 -1
  101. package/dist/components/p-C8rpOS5t.js +0 -1
  102. package/dist/components/p-CUoPUIej.js +0 -1
  103. package/dist/components/p-ChpAMqbN.js +0 -1
  104. package/dist/components/p-D3hr9wra.js +0 -1
  105. package/dist/components/p-DFybNETX.js +0 -1
  106. package/dist/components/p-DRmphEA0.js +0 -1
  107. package/dist/components/p-D_K7tYhY.js +0 -1
  108. package/dist/components/p-Dw3rv_Y9.js +0 -1
  109. package/dist/components/p-TNX3alPU.js +0 -1
  110. package/dist/components/p-j42D1yrQ.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-DHKHBdRb.js');
6
- var withTranslation = require('./withTranslation-CLwC9a8V.js');
5
+ var withStyled = require('./withStyled-pkdctrK9.js');
6
+ var withTranslation = require('./withTranslation-BIzTNYZM.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');
@@ -35,7 +35,7 @@ function parseLayerItems(json) {
35
35
  var _a;
36
36
  return (_a = parseItems(json)) === null || _a === void 0 ? void 0 : _a.map((item) => {
37
37
  var _a;
38
- return (Object.assign(Object.assign({}, item), { label: text(item.label), color: text(item.color), target: (_a = text(item.target)) !== null && _a !== void 0 ? _a : "", to: text(item.to) }));
38
+ return (Object.assign(Object.assign({}, item), { label: text(item.label), color: text(item.color), target: (_a = text(item.target)) !== null && _a !== void 0 ? _a : "", to: text(item.to), text: text(item.text) }));
39
39
  });
40
40
  }
41
41
  /** The `items` of a list. `undefined` when it is not a JSON array of objects. */
@@ -131,6 +131,71 @@ function besideText(text, r, unit, options) {
131
131
  // the number in the circle must stay readable
132
132
  return { x, y, r: Math.min(r, Math.max(wider / 2, 0.3 * unit)) };
133
133
  }
134
+ /** A text cannot be measured here: the width of the digits and signs of a number, close enough for a frame. */
135
+ const textWidth = (text, em) => text.length * 0.6 * em;
136
+ const signed = (value, digits) => (value < 0 ? "-" : "+") + Math.abs(value).toFixed(digits);
137
+ /**
138
+ * The difference of two values of a chart. `box` and `toBox` are the bars of
139
+ * the two values, and the upper edge of each is its level. A thin line runs
140
+ * from each level to a bar behind the second value, which spans the
141
+ * difference. The label is `to - from`, and with `percent` also relative to
142
+ * `from`. A difference in the good direction has the colour `positive`, else
143
+ * `negative`. Without two values there is nothing to print. `levels` gives
144
+ * the y of the two values when it is not the upper edge of the boxes.
145
+ */
146
+ function buildDifference(item, box, toBox, fromValue, toValue, em, levels) {
147
+ var _a, _b, _c;
148
+ if (fromValue == null || toValue == null)
149
+ return undefined;
150
+ const difference = toValue - fromValue;
151
+ const digits = Number.isInteger(item.digits) && item.digits >= 0 ? item.digits : 1;
152
+ const good = item.sentiment === "good-down" ? difference <= 0 : difference >= 0;
153
+ // the bar stands behind the second value, away from the first one
154
+ const direction = toBox.x + toBox.width / 2 >= box.x + box.width / 2 ? 1 : -1;
155
+ const edge = (of) => (direction === 1 ? of.x + of.width : of.x);
156
+ const barX = edge(toBox) + direction * 0.9 * em;
157
+ const lineEnd = barX + direction * 0.125 * em;
158
+ // the upper edge is the level of a positive value only: the caller knows better for a negative one
159
+ const fromY = (_a = levels === null || levels === void 0 ? void 0 : levels.from) !== null && _a !== void 0 ? _a : box.y;
160
+ const toY = (_b = levels === null || levels === void 0 ? void 0 : levels.to) !== null && _b !== void 0 ? _b : toBox.y;
161
+ const barWidth = 0.25 * em;
162
+ const percent = item.percent && fromValue !== 0 ? `(${signed((difference / Math.abs(fromValue)) * 100, 0)}%)` : undefined;
163
+ const value = signed(difference, digits);
164
+ const textX = barX + direction * 0.6 * em;
165
+ const textY = (fromY + toY) / 2;
166
+ const percentWidth = percent ? textWidth(percent, 0.85 * em) : 0;
167
+ // digits and signs alone are narrower than a text with a percent sign
168
+ const valueWidth = value.length * 0.5 * em;
169
+ // the percent is the last part of the text, which ends at textX when it stands at the left
170
+ const percentX = direction === 1 ? textX + valueWidth + 0.35 * em : textX - percentWidth;
171
+ return {
172
+ kind: "difference",
173
+ color: (_c = item.color) !== null && _c !== void 0 ? _c : (good ? "positive" : "negative"),
174
+ lines: [
175
+ { x1: edge(box), y1: fromY, x2: lineEnd, y2: fromY },
176
+ { x1: edge(toBox), y1: toY, x2: lineEnd, y2: toY },
177
+ ],
178
+ bar: {
179
+ x: barX - barWidth / 2,
180
+ y: Math.min(fromY, toY),
181
+ width: barWidth,
182
+ height: Math.max(Math.abs(toY - fromY), 1),
183
+ },
184
+ text: { x: textX, y: textY, anchor: direction === 1 ? "start" : "end", value, percent },
185
+ frame: percent && item.highlight
186
+ ? {
187
+ x: percentX - 0.25 * em,
188
+ y: textY - 0.65 * em,
189
+ width: percentWidth + 0.5 * em,
190
+ height: 1.3 * em,
191
+ r: 0.65 * em,
192
+ }
193
+ : undefined,
194
+ badge: item.label != null
195
+ ? { cx: barX, cy: Math.min(fromY, toY) - 0.9 * em, r: 0.65 * em, label: item.label }
196
+ : undefined,
197
+ };
198
+ }
134
199
  /**
135
200
  * The geometry of one item. On a whole component a marker sits in the top-right
136
201
  * corner, and on a table cell next to the number. A frame goes around the text
@@ -139,7 +204,7 @@ function besideText(text, r, unit, options) {
139
204
  * two boxes with the same centre has no direction and gives `undefined`.
140
205
  */
141
206
  function buildMark(item, box, toBox, em, options = {}) {
142
- var _a;
207
+ var _a, _b, _c, _d;
143
208
  const { label, color } = item;
144
209
  const { whole, area, text } = options;
145
210
  // a table row has no text of its own, but the same font
@@ -183,9 +248,19 @@ function buildMark(item, box, toBox, em, options = {}) {
183
248
  };
184
249
  }
185
250
  if (item.mark === "frame") {
186
- const around = text !== null && text !== void 0 ? text : box;
187
- const part = (_a = item.point) === null || _a === void 0 ? void 0 : _a.part;
188
- const oval = !whole && (text != null || part === "label" || part === "total");
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;
255
+ const captionBox = caption && {
256
+ x: caption.x - textWidth(item.text, em) / 2,
257
+ y: caption.y - 0.6 * em,
258
+ width: textWidth(item.text, em),
259
+ height: 1.2 * em,
260
+ };
261
+ const around = (_a = captionBox !== null && captionBox !== void 0 ? captionBox : text) !== null && _a !== void 0 ? _a : box;
262
+ const part = (_b = item.point) === null || _b === void 0 ? void 0 : _b.part;
263
+ const oval = !whole && (captionBox != null || text != null || part === "label" || part === "total");
189
264
  const paddingX = (oval ? 0.45 : 0.2) * unit;
190
265
  const paddingY = (oval ? 0.1 : 0.2) * unit;
191
266
  // a single digit gets a circle and not a narrow upright oval
@@ -216,6 +291,7 @@ function buildMark(item, box, toBox, em, options = {}) {
216
291
  badge: label != null
217
292
  ? keepInside({ cx: x2 - rx * curve + outside, cy: top + ry * curve - outside, r: badgeR, label }, area)
218
293
  : undefined,
294
+ caption: caption && Object.assign(Object.assign({}, caption), { text: item.text }),
219
295
  };
220
296
  }
221
297
  // without a number the circle is only a dot
@@ -225,7 +301,11 @@ function buildMark(item, box, toBox, em, options = {}) {
225
301
  }
226
302
  const size = (label == null ? 0.4 : 0.75) * unit;
227
303
  const r = isRow ? Math.min(size, box.height / 2) : size;
228
- const at = whole ? { x: box.x + box.width - r, y: box.y + r } : centre(box);
304
+ 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") {
306
+ // on the upper right corner: the label in the middle and a name beside the segment stay free
307
+ at = { x: box.x + box.width, y: box.y + Math.min(0.5 * r, box.height / 2) };
308
+ }
229
309
  if (isRow) {
230
310
  // the middle of a row is free in a wide table. In a narrow one it is a number: then next to that number
231
311
  const circle = { x: at.x - r, y: at.y - r, width: 2 * r, height: 2 * r };
@@ -261,10 +341,16 @@ function matchPoint(state, point) {
261
341
  const noThereof = state.table != null && point.subCategory == null;
262
342
  return candidates
263
343
  .filter((candidate) => matches(candidate.point, point) && !(noThereof && candidate.point.subCategory != null))
264
- .map(({ rect, content, contentSign }) => ({ rect, content, contentSign }));
344
+ .map(({ rect, content, contentSign, value, scenario }) => ({
345
+ rect,
346
+ content,
347
+ contentSign,
348
+ value,
349
+ stacked: typeof scenario === "string" && scenario.startsWith("stack:"),
350
+ }));
265
351
  }
266
352
 
267
- 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}`;
353
+ 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}`;
268
354
 
269
355
  /** A chart can draw its data late: a point without a match is reported when the page has been quiet for two checks. */
270
356
  const REPORT_CHECK_MS = 200;
@@ -397,7 +483,7 @@ const AnnotationLayer = class {
397
483
  this.parsedItems = items !== null && items !== void 0 ? items : [];
398
484
  }
399
485
  async place() {
400
- var _a;
486
+ var _a, _b;
401
487
  const run = ++this.run;
402
488
  if (!this.element.isConnected || !this.svg)
403
489
  return;
@@ -458,7 +544,7 @@ const AnnotationLayer = class {
458
544
  }
459
545
  const content = found[0].content;
460
546
  if (!state.table)
461
- return { box, whole: false };
547
+ return { box, whole: false, stacked: found[0].stacked };
462
548
  const cells = ((_a = state.elements) !== null && _a !== void 0 ? _a : []).flatMap((element) => element.kind === "cell" && element.content
463
549
  ? [{ box: onScreen(element.content), sign: element.contentSign }]
464
550
  : []);
@@ -469,6 +555,38 @@ const AnnotationLayer = class {
469
555
  obstacles: cells,
470
556
  };
471
557
  };
558
+ // a difference takes all bars of a point: the segments of a stack together are its sum
559
+ const sumOf = (id, point) => {
560
+ const visual = id != null ? targets.get(id) : undefined;
561
+ if (!visual)
562
+ return { problem: `no target "${id}" on this page` };
563
+ const state = states.get(visual);
564
+ const found = state && point ? matchPoint(state, Object.assign(Object.assign({}, point), { part: "element" })) : [];
565
+ const bars = found.filter((match) => match.value != null);
566
+ if (bars.length === 0) {
567
+ return { problem: `no bar with a value matches the point ${JSON.stringify(point)} in "${id}"` };
568
+ }
569
+ // bars side by side or behind each other are no sum: the point must name one of them
570
+ if (bars.length > 1 && !bars.every((bar) => bar.stacked)) {
571
+ return { problem: `${bars.length} elements match the point ${JSON.stringify(point)} in "${id}"` };
572
+ }
573
+ const host = visual.getBoundingClientRect();
574
+ const left = Math.min(...bars.map((bar) => bar.rect.component.x));
575
+ const top = Math.min(...bars.map((bar) => bar.rect.component.y));
576
+ const right = Math.max(...bars.map((bar) => bar.rect.component.x + bar.rect.component.width));
577
+ const bottom = Math.max(...bars.map((bar) => bar.rect.component.y + bar.rect.component.height));
578
+ const screen = (rect) => ({
579
+ x: host.left + rect.x,
580
+ y: host.top + rect.y,
581
+ width: rect.width,
582
+ height: rect.height,
583
+ });
584
+ return {
585
+ box: { x: host.left + left, y: host.top + top, width: right - left, height: bottom - top },
586
+ negatives: bars.filter((bar) => bar.value < 0).map((bar) => screen(bar.rect.component)),
587
+ value: bars.reduce((sum, bar) => sum + bar.value, 0),
588
+ };
589
+ };
472
590
  const toLocal = this.toLocalSpace();
473
591
  // here the text runs along x and a layout px is a px, also on a rotated or scaled page
474
592
  const textToLocal = ({ box, sign = 0 }) => {
@@ -481,6 +599,26 @@ const AnnotationLayer = class {
481
599
  const marks = [];
482
600
  const problems = [];
483
601
  for (const item of this.parsedItems) {
602
+ if (item.mark === "difference") {
603
+ const first = sumOf(item.target, item.point);
604
+ const second = sumOf((_a = item.to) !== null && _a !== void 0 ? _a : item.target, item.toPoint);
605
+ const failed = "problem" in first ? first : "problem" in second ? second : undefined;
606
+ if (failed) {
607
+ problems.push({ item, problem: failed.problem });
608
+ continue;
609
+ }
610
+ const [a, b] = [first, second];
611
+ // the level of a sum: the top for positive values, and below it by the length of the negative ones.
612
+ // Measured in the space of the layer, so it holds on a turned page too.
613
+ const levelOf = (anchor) => toLocal(anchor.box).y + anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).height, 0);
614
+ const mark = buildDifference(item, toLocal(a.box), toLocal(b.box), a.value, b.value, em, {
615
+ from: levelOf(a),
616
+ to: levelOf(b),
617
+ });
618
+ if (mark)
619
+ marks.push(mark);
620
+ continue;
621
+ }
484
622
  const from = anchorOf(item.target, item.point);
485
623
  const to = item.mark === "arrow" ? anchorOf(item.to, item.toPoint) : undefined;
486
624
  const failed = "problem" in from ? from : to && "problem" in to ? to : undefined;
@@ -494,7 +632,8 @@ const AnnotationLayer = class {
494
632
  whole: start.whole,
495
633
  area,
496
634
  text: start.text && textToLocal(start.text),
497
- obstacles: (_a = start.obstacles) === null || _a === void 0 ? void 0 : _a.map(textToLocal),
635
+ obstacles: (_b = start.obstacles) === null || _b === void 0 ? void 0 : _b.map(textToLocal),
636
+ stacked: start.stacked,
498
637
  });
499
638
  if (mark) {
500
639
  marks.push(mark);
@@ -614,18 +753,22 @@ const AnnotationLayer = class {
614
753
  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));
615
754
  }
616
755
  renderMark(mark) {
617
- var _a, _b;
756
+ var _a, _b, _c;
618
757
  const color = annotationColor(mark.color, this.componentStyle(($) => $["bn-annotation"]));
619
758
  if (mark.kind === "marker") {
620
759
  return (index.h("g", { class: "mark marker", "data-label": mark.badge.label }, this.renderBadge(mark.badge, color)));
621
760
  }
622
761
  if (mark.kind === "frame") {
623
- return (index.h("g", { class: "mark frame", "data-label": (_a = mark.badge) === null || _a === void 0 ? void 0 : _a.label }, index.h("rect", { x: mark.x, y: mark.y, width: mark.width, height: mark.height, rx: mark.rx, ry: mark.ry, style: { fill: "none", stroke: color, strokeWidth: "1.5" } }), this.renderBadge(mark.badge, color)));
762
+ return (index.h("g", { class: "mark frame", "data-label": (_a = mark.badge) === null || _a === void 0 ? void 0 : _a.label }, index.h("rect", { x: mark.x, y: mark.y, width: mark.width, height: mark.height, rx: mark.rx, ry: mark.ry, style: { fill: mark.caption ? "#ffffff" : "none", stroke: color, strokeWidth: "1.5" } }), 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)));
763
+ }
764
+ if (mark.kind === "difference") {
765
+ const main = annotationColor(undefined, this.componentStyle(($) => $["bn-annotation"]));
766
+ 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)));
624
767
  }
625
- return (index.h("g", { class: "mark arrow", "data-label": (_b = mark.badge) === null || _b === void 0 ? void 0 : _b.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)));
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)));
626
769
  }
627
770
  render() {
628
- return (index.h(index.Host, { key: 'd4d027728ae578a5ced829a3f86f0137530551fc' }, index.h("svg", { key: 'a3813930e420db9fdd618bc38c38941295cf4c22', ref: (el) => (this.svg = el) }, this.marks.map((mark) => this.renderMark(mark)))));
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)))));
629
772
  }
630
773
  get element() { return index.getElement(this); }
631
774
  static get watchers() { return {
@@ -933,6 +1076,14 @@ function levelKey(level, value) {
933
1076
  const SCENARIO_GROUP_RE = /^Scenario([1-4])$/;
934
1077
  const STACK_SEGMENT_RE = /^stacked_(?:col|bar)_(\d+)_seg_\d+$/;
935
1078
  const STACK_SEGMENTS = 'g[id^="stacked_col_"], g[id^="stacked_bar_"]';
1079
+ /** The value a bar group carries in `data-bn-value`. */
1080
+ function readValue(group) {
1081
+ const raw = group.getAttribute("data-bn-value");
1082
+ if (raw == null || raw === "")
1083
+ return undefined;
1084
+ const value = Number(raw);
1085
+ return Number.isFinite(value) ? value : undefined;
1086
+ }
936
1087
  /** Nearest `#Scenario1..4` ancestor of an element, as "scenario1".."scenario4". */
937
1088
  function scenarioOf(el, root) {
938
1089
  var _a;
@@ -1005,6 +1156,7 @@ function collectChartSegmentElements(svgRoot, segment, origins) {
1005
1156
  index: (_a = indexOfGroup(group.id)) !== null && _a !== void 0 ? _a : walkIndex,
1006
1157
  rect: localFrame.measure(group, origins),
1007
1158
  point: readLayoutPoint(group),
1159
+ value: readValue(group),
1008
1160
  };
1009
1161
  elements.push(bar);
1010
1162
  });
@@ -1024,6 +1176,7 @@ function collectChartSegmentElements(svgRoot, segment, origins) {
1024
1176
  index: Number(match[1]),
1025
1177
  rect: localFrame.measure(group, origins),
1026
1178
  point,
1179
+ value: readValue(group),
1027
1180
  };
1028
1181
  elements.push(bar);
1029
1182
  });
@@ -9707,7 +9860,8 @@ let Label$1 = class Label {
9707
9860
  .stroke(background)
9708
9861
  .fill(background)
9709
9862
  .opacity(0.9)
9710
- .move(rectX - 1, rectY)
9863
+ // the box of a centred label is already centred with its margin
9864
+ .move(this.horizontalHookLocation === HookLocation$1.Center ? rectX : rectX - 1, rectY)
9711
9865
  .insertBefore(text);
9712
9866
  }
9713
9867
  return text;
@@ -19214,14 +19368,22 @@ const Chart = class {
19214
19368
  * {
19215
19369
  * "by": "scenarios" | "dimensions",
19216
19370
  * "mode": "absolute" | "relative" | "absolute-relative",
19217
- * "order": "asc" | "desc" | "dataset"
19371
+ * "order": "asc" | "desc" | "dataset",
19372
+ * "notation": "none" | "scenario",
19373
+ * "legend": "left" | "right" | "both" | "none",
19374
+ * "percentMark": true | false
19218
19375
  * }
19219
19376
  * ```
19220
19377
  *
19221
19378
  * - `by` (required): What a stack is made of.
19222
- * - `"scenarios"` - stack the scenarios from the `scenarios` prop as layers.
19223
- * - `"dimensions"` - only the first scenario is drawn. A time chart has one
19224
- * value per period, so each stack has one segment.
19379
+ * - `"scenarios"` - stack the scenarios from the `scenarios` prop as layers,
19380
+ * four at most.
19381
+ * - `"dimensions"` - one segment per value of the `category` column of the
19382
+ * dataset, ordered by `categoryIndex`, else by first appearance. There is
19383
+ * no limit on the number of series, and a series keeps its colour in
19384
+ * every period. The first scenario is drawn. With `scenario-switch` the
19385
+ * scenario that has values in the period is drawn, so one axis can go
19386
+ * from AC to FC to PL.
19225
19387
  * - `mode` (optional, default `"absolute"`):
19226
19388
  * - `"absolute"` - additive stacking, axis shows absolute units.
19227
19389
  * - `"relative"` - 100% stacking, axis shows 0%-100%. `unit-scaling` is
@@ -19232,6 +19394,17 @@ const Chart = class {
19232
19394
  * - `order` (optional, default `"dataset"`): Segment order within each stack.
19233
19395
  * `"asc"` / `"desc"` sort segments by value; `"dataset"` preserves the
19234
19396
  * original data/scenario order.
19397
+ * - `notation` (optional, default `"none"`): with `"scenario"` a segment takes
19398
+ * the look of its scenario. A forecast segment is hatched over the shade of
19399
+ * its series, a plan segment is outlined, and the first series takes the
19400
+ * fill of the scenario from `barStyles`.
19401
+ * - `legend` (optional, default `"left"`): where the series names stand. Left
19402
+ * of the first column, right of the last column with a value, at both, or
19403
+ * nowhere.
19404
+ * - `percentMark` (optional, default `false`): for `mode: "relative"`. The
19405
+ * shares are plain numbers without the % sign, with
19406
+ * `data-format-digits-percent` digits, and one `100%` mark stands at the
19407
+ * upper end of the stack, on the side of the series names.
19235
19408
  *
19236
19409
  * @default '' (empty - no stacking)
19237
19410
  *
@@ -19325,7 +19498,8 @@ const Chart = class {
19325
19498
  * has no value, the next scenario with a value is drawn in its place with
19326
19499
  * its value label. A vertical line marks the change, and the scenario names
19327
19500
  * stand under the axis. Variances with the same reference and type share
19328
- * one row. Bar mode without stack only.
19501
+ * one row. A chart with one scenario gets the name of that scenario under
19502
+ * the axis. Bar mode, without a stack or with a stack by dimensions.
19329
19503
  */
19330
19504
  this.scenarioSwitch = false;
19331
19505
  /**
@@ -19905,7 +20079,7 @@ const Chart = class {
19905
20079
  }
19906
20080
  prepareAxisLabelsMode() {
19907
20081
  var _a;
19908
- return withStyled.AxisLabelsMode[(_a = this.axisLabelsMode) === null || _a === void 0 ? void 0 : _a.toUpperCase()];
20082
+ return withStyled.AxisLabelsMode[(_a = this.axisLabelsMode) === null || _a === void 0 ? void 0 : _a.toUpperCase().replace("-", "_")];
19909
20083
  }
19910
20084
  prepareFilter() {
19911
20085
  if (this.filter.length === 0) {
@@ -19974,36 +20148,48 @@ const Chart = class {
19974
20148
  prepareStackConfig() {
19975
20149
  if (withStyled.isBlankInput(this.stack)) {
19976
20150
  this.errors.remove("WARN_stack_dimensions_scenarios");
20151
+ this.errors.remove("WARN_stack_scenarios_max");
19977
20152
  return null;
19978
20153
  }
19979
20154
  try {
19980
20155
  const parsed = JSON.parse(this.stack);
19981
20156
  const by = parsed.by;
19982
20157
  const errId = "WARN_stack_dimensions_scenarios";
19983
- if (by === withStyled.StackBy.DIMENSIONS) {
19984
- const scenarios = this.prepareScenarios();
19985
- if (scenarios.length > 1) {
19986
- this.errors.addOrReplace({
19987
- id: errId,
19988
- type: "warning",
19989
- message: `stack by dimensions: only the first scenario "${scenarios[0]}" is used, the rest (${scenarios.slice(1).join(", ")}) are discarded.`,
19990
- });
19991
- }
19992
- else {
19993
- this.errors.remove(errId);
19994
- }
20158
+ const maxId = "WARN_stack_scenarios_max";
20159
+ const scenarios = this.prepareScenarios();
20160
+ // with scenarioSwitch the further scenarios continue the first one along the time axis
20161
+ if (by === withStyled.StackBy.DIMENSIONS && scenarios.length > 1 && !this.scenarioSwitch) {
20162
+ this.errors.addOrReplace({
20163
+ id: errId,
20164
+ type: "warning",
20165
+ message: `stack by dimensions: only the first scenario "${scenarios[0]}" is used, the rest (${scenarios.slice(1).join(", ")}) are discarded.`,
20166
+ });
19995
20167
  }
19996
20168
  else {
19997
20169
  this.errors.remove(errId);
19998
20170
  }
20171
+ if (by === withStyled.StackBy.SCENARIOS && scenarios.length > 4) {
20172
+ this.errors.addOrReplace({
20173
+ id: maxId,
20174
+ type: "warning",
20175
+ message: `stack by scenarios: at most four scenarios are stacked, the rest (${scenarios.slice(4).join(", ")}) are discarded. Use stack by dimensions for more series.`,
20176
+ });
20177
+ }
20178
+ else {
20179
+ this.errors.remove(maxId);
20180
+ }
19999
20181
  return {
20000
20182
  by,
20001
20183
  mode: parsed.mode || withStyled.StackMode.ABSOLUTE,
20002
20184
  order: parsed.order || withStyled.StackOrder.DATASET,
20185
+ notation: parsed.notation === "scenario" ? "scenario" : "none",
20186
+ legend: ["right", "both", "none"].includes(parsed.legend) ? parsed.legend : "left",
20187
+ percentMark: parsed.percentMark === true,
20003
20188
  };
20004
20189
  }
20005
20190
  catch (_a) {
20006
20191
  this.errors.remove("WARN_stack_dimensions_scenarios");
20192
+ this.errors.remove("WARN_stack_scenarios_max");
20007
20193
  return null;
20008
20194
  }
20009
20195
  }
@@ -20034,7 +20220,7 @@ const Chart = class {
20034
20220
  const isBase = segmentVariances.length === 0;
20035
20221
  const scenarios = this.hidesScenarios() ? variancesScenarios(segmentVariances) : this.prepareScenarios();
20036
20222
  // only the base chart draws a stack, a variance needs both of its scenarios
20037
- const effectiveScenarios = isBase && (stackConfig === null || stackConfig === void 0 ? void 0 : stackConfig.by) === withStyled.StackBy.DIMENSIONS ? scenarios.slice(0, 1) : scenarios;
20223
+ const effectiveScenarios = isBase && (stackConfig === null || stackConfig === void 0 ? void 0 : stackConfig.by) === withStyled.StackBy.DIMENSIONS && !this.scenarioSwitch ? scenarios.slice(0, 1) : scenarios;
20038
20224
  return (index.h("bn-chart-time-renderer", { tableName: this.datasetName, dataVersion: this.dataVersion, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: segmentVariances.length > 0 ? segmentVariances : [""], hideAxisLabels: this.prepareHideAxisLabels(idx), pixelPerUnit: ppu, pixelPerPercentage: ppp, reportAutoScaling: this.handleAutoScalingReport, errors: this.errors, leftSideOffsetForHorizontalSync: this.prepareLeftSideOffset(preparedI18n, preparedStyle), styles: preparedStyle, i18n: preparedI18n, dateInterval: this.prepareDateInterval(), intervalSpanLimit: this.prepareIntervalSpanLimit(), axisLabelsMode: this.prepareAxisLabelsMode(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showOverlayAvg: this.prepareAvg(), showOverlayMedian: this.prepareMedian(), showMeasureScale: this.prepareShowMeasureScale(idx), chartMode: this.prepareChartMode(), maxBars: this.prepareMaxBars(), stackConfig: stackConfig, lineFullWidth: this.prepareLineFullWidth(), dataFormatDigits: { percent: this.dataFormatDigitsPercent, decimal: this.dataFormatDigitsDecimal }, axisLabelsStep: Math.max(1, Math.floor(Number(this.axisLabelsStep) || 1)), scenarioSwitch: this.scenarioSwitch, axisTitlePosition: this.prepareAxisTitlePosition(), containerWidth: fullParentWidth, parentDimensions: this.prepareDimension(), ruleSetConfig: this.ruleSetConfig() }));
20039
20225
  }
20040
20226
  /**
@@ -20167,7 +20353,7 @@ const Chart = class {
20167
20353
  this.errors.remove("WARN_scenarios_none");
20168
20354
  }
20169
20355
  const fontStyles = this.getFontStyles();
20170
- return (index.h(index.Host, { key: '530c7c27c23afc339ca03506f2cb608774e8a7ed', style: fontStyles }, index.h("div", { key: '99bbe8fa9d17ef14bbb6a3b5e2dce21025cdc40c', class: "container" }, segments.map(this.chartTemplate))));
20356
+ return (index.h(index.Host, { key: 'c998214052bad19811135a7c48e669d6ebfdb8cc', style: fontStyles }, index.h("div", { key: '8c877fda1575246a4cecc5610aa3b66d6b6f60ce', class: "container" }, segments.map(this.chartTemplate))));
20171
20357
  }
20172
20358
  get element() { return index.getElement(this); }
20173
20359
  static get watchers() { return {
@@ -21111,7 +21297,7 @@ class Column {
21111
21297
  return this;
21112
21298
  }
21113
21299
  draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
21114
- var _a, _b, _c;
21300
+ var _a, _b, _c, _d;
21115
21301
  // TODE: JHE: Remove DataFOrmatDigits Type Duplicates
21116
21302
  if (this.isEmpty()) {
21117
21303
  return this;
@@ -21127,6 +21313,9 @@ class Column {
21127
21313
  }
21128
21314
  this.scenarioGroup.attr(dataPointAttributes(this.dataPoint.key));
21129
21315
  (_c = this.columnGroup) === null || _c === void 0 ? void 0 : _c.attr(dataPointAttributes(this.dataPoint.key, "element"));
21316
+ if (this.dataPoint.key && Number.isFinite(this.dataPoint.value)) {
21317
+ (_d = this.columnGroup) === null || _d === void 0 ? void 0 : _d.attr("data-bn-value", this.dataPoint.value);
21318
+ }
21130
21319
  if (this.columnGroup != null) {
21131
21320
  if (this.isOverflowing && this.overflowConfig) {
21132
21321
  this.drawOverdriveBar(fillStyle, strokeStyle);
@@ -21881,7 +22070,9 @@ class LineSeries {
21881
22070
  * The last segment can draw the total label of the full stack via drawTotalLabel().
21882
22071
  */
21883
22072
  class StackedColumn {
21884
- constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup) {
22073
+ constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup, notation = false, plainShares = false) {
22074
+ this.notation = notation;
22075
+ this.plainShares = plainShares;
21885
22076
  this.hasData = false;
21886
22077
  this.position = position;
21887
22078
  this.styles = styles;
@@ -21898,6 +22089,7 @@ class StackedColumn {
21898
22089
  }
21899
22090
  }
21900
22091
  draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
22092
+ var _a, _b;
21901
22093
  // a segment without a value (NaN) keeps its place in the stack, so the colours stay, but draws nothing
21902
22094
  if (!this.hasData || !Number.isFinite(this.dataPoint.value)) {
21903
22095
  return;
@@ -21911,10 +22103,28 @@ class StackedColumn {
21911
22103
  const xPos = this.position.getColumnCenterPositionX(this.index);
21912
22104
  const columnWidth = this.position.getColumnWidth();
21913
22105
  const colors = this.styles.stackColors;
21914
- const fillColor = colors[this.segmentIndex % colors.length];
21915
- const fillStyle = { color: fillColor };
21916
- const strokeStyle = { color: fillColor, width: 0.5 };
22106
+ let fillColor = colors[this.segmentIndex % colors.length];
22107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22108
+ let fillStyle = { color: fillColor };
22109
+ let strokeStyle = { color: fillColor, width: 0.5 };
22110
+ let hatched = false;
22111
+ // FC and PL: the series keeps its shade, the scenario adds the hatching or the outline.
22112
+ // The first series is the darkest: it takes the fill of the scenario, as a plain column does.
22113
+ const family = getScenarioPrefix((_a = this.dataPoint.scenario) !== null && _a !== void 0 ? _a : "");
22114
+ if (this.notation && (family === "fc" || family === "pl")) {
22115
+ const look = this.styles.barStyles.getSVGStyle(family);
22116
+ if (this.segmentIndex === 0) {
22117
+ fillColor = look.fill;
22118
+ }
22119
+ fillStyle = { color: fillColor };
22120
+ strokeStyle = { color: look.stroke, width: 1 };
22121
+ if (look.fillpattern === "hatched") {
22122
+ hatched = true;
22123
+ fillStyle = (_b = this.hatchPattern(fillColor, look.stroke)) !== null && _b !== void 0 ? _b : fillStyle;
22124
+ }
22125
+ }
21917
22126
  this.columnGroup.attr(dataPointAttributes(this.dataPoint.key, "element"));
22127
+ this.columnGroup.attr("data-bn-value", value);
21918
22128
  // Draw rectangle
21919
22129
  this.columnGroup
21920
22130
  .rect(columnWidth, Math.max(segmentHeight, 0.5))
@@ -21922,26 +22132,46 @@ class StackedColumn {
21922
22132
  .stroke(strokeStyle)
21923
22133
  .y(yPos)
21924
22134
  .cx(xPos);
21925
- // Draw segment value label if segment is tall enough (min ~18px)
21926
- const MIN_SEGMENT_HEIGHT_FOR_LABEL = 18;
22135
+ // Draw segment value label if the segment is tall enough: 18px, less for a font that is smaller than that
22136
+ const MIN_SEGMENT_HEIGHT_FOR_LABEL = Math.min(18, (this.styles.fontStyles.size || 18) * 1.15);
21927
22137
  if (segmentHeight >= MIN_SEGMENT_HEIGHT_FOR_LABEL) {
21928
22138
  const labelY = yPos + segmentHeight / 2;
22139
+ // a label on a hatching keeps the background of a plain label
22140
+ const onFill = (label) => (hatched ? label : label.setSegmentFill(fillColor));
21929
22141
  if (this.stackMode === withStyled.StackMode.RELATIVE || this.stackMode === withStyled.StackMode.ABSOLUTE_RELATIVE) {
21930
- const labelValue = Formatter.number(this.segment.share, "percent", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale);
21931
- new Label$1(this.group, xPos, labelY, "STACK_SEG", labelValue, this.styles, HookLocation$1.Center, HookLocation$1.Center)
21932
- .setSegmentFill(fillColor)
22142
+ // with the 100 % mark the unit stands there once, and the shares are plain numbers
22143
+ const labelValue = this.plainShares
22144
+ ? Formatter.number(this.segment.share * 100, "decimal", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale)
22145
+ : Formatter.number(this.segment.share, "percent", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale);
22146
+ onFill(new Label$1(this.group, xPos, labelY, "STACK_SEG", labelValue, this.styles, HookLocation$1.Center, HookLocation$1.Center))
21933
22147
  .setPoint(this.dataPoint.key)
21934
22148
  .forceStringTypeDraw();
21935
22149
  }
21936
22150
  else {
21937
22151
  // Pass raw numeric value - Label.draw() formats with measureScale
21938
- new Label$1(this.group, xPos, labelY, "STACK_SEG", value, this.styles, HookLocation$1.Center, HookLocation$1.Center)
21939
- .setSegmentFill(fillColor)
22152
+ onFill(new Label$1(this.group, xPos, labelY, "STACK_SEG", value, this.styles, HookLocation$1.Center, HookLocation$1.Center))
21940
22153
  .setPoint(this.dataPoint.key)
21941
22154
  .draw(true, dataFormatDigits, measureScale);
21942
22155
  }
21943
22156
  }
21944
22157
  }
22158
+ /** The hatching of a forecast over the shade of the series. One pattern per shade in the SVG. */
22159
+ hatchPattern(background, color) {
22160
+ const root = this.group.root();
22161
+ if (!root)
22162
+ return null;
22163
+ const id = `pattern-stack-fc-${this.segmentIndex}`;
22164
+ const existing = root.findOne(`#${id}`);
22165
+ if (existing)
22166
+ return existing;
22167
+ return root
22168
+ .pattern(10, 10, (add) => {
22169
+ add.rect(10, 10).fill(background);
22170
+ add.line(0, 5, 5, 0).stroke({ width: 1, color, linecap: "square" });
22171
+ add.line(5, 10, 10, 5).stroke({ width: 1, color, linecap: "square" });
22172
+ })
22173
+ .id(id);
22174
+ }
21945
22175
  /**
21946
22176
  * Draw the signed total of the stack: above the positive side, or below the negative side for a negative total.
21947
22177
  */
@@ -22564,6 +22794,8 @@ class TimeChart {
22564
22794
  this.scenarioSwitch = (_b = config.scenarioSwitch) !== null && _b !== void 0 ? _b : false;
22565
22795
  this.axisTitlePosition = (_c = config.axisTitlePosition) !== null && _c !== void 0 ? _c : "left";
22566
22796
  this.dateInterval = this.findDateInterval(config.dateInterval);
22797
+ // the model of a stack by dimension holds the series
22798
+ this.stackConfig = config.stackConfig;
22567
22799
  this.dataModel = this.populateModel(scenarios, this.dateInterval);
22568
22800
  this.variancesDataModel = this.populateVarianceModel(config.variances, this.dataModel);
22569
22801
  this.configTitle = config.title;
@@ -22687,7 +22919,9 @@ class TimeChart {
22687
22919
  }).width;
22688
22920
  titleEnd = axisEnd + this.position.spacings.labelToColumn + titleWidth + this.styles.padding.right;
22689
22921
  }
22690
- return Math.max(axisEnd + labelBuffer, bboxTotal, titleEnd);
22922
+ const legendWidth = this.legendWidth("right");
22923
+ const legendEnd = legendWidth > 0 ? axisEnd + this.position.spacings.labelToColumn + legendWidth + this.styles.padding.right : 0;
22924
+ return Math.max(axisEnd + labelBuffer, bboxTotal, titleEnd, legendEnd);
22691
22925
  }
22692
22926
  getAllocatedCanvasHeight() {
22693
22927
  if (this.smallestVarianceDataPointValue.value == null ||
@@ -22720,9 +22954,71 @@ class TimeChart {
22720
22954
  : this.scenariosArea.height;
22721
22955
  return Math.max(analyticalHeight, bboxHeight) + this.switchNamesHeight();
22722
22956
  }
22723
- /** Room for the scenario names under the category labels of a series that changes its scenario. */
22957
+ /**
22958
+ * Room for the second row under the category labels: the scenario names of a
22959
+ * `scenarioSwitch` chart, and in `two-row` mode the parent periods.
22960
+ */
22724
22961
  switchNamesHeight() {
22725
- return !this.hideAxisLabels && this.switchRuns().length > 1 ? this.position.dataLabelHeight : 0;
22962
+ return !this.hideAxisLabels && this.contextRow().length > 0 ? this.position.dataLabelHeight : 0;
22963
+ }
22964
+ /** The parent period of a period in `two-row` mode: the year of a month, quarter or week, the month of a day. */
22965
+ parentPeriodLabel(date) {
22966
+ if (this.axisLabelsMode !== withStyled.AxisLabelsMode.TWO_ROW || date == null || !date.isValid) {
22967
+ return "";
22968
+ }
22969
+ switch (this.dateInterval) {
22970
+ case withStyled.DateDistance.MONTH:
22971
+ case withStyled.DateDistance.QUARTER:
22972
+ return date.setLocale(this.locale).toFormat("yyyy");
22973
+ case withStyled.DateDistance.WEEK:
22974
+ // week 1 can start in December: the week year, as the week labels use it
22975
+ return date.setLocale(this.locale).toFormat("kkkk");
22976
+ case withStyled.DateDistance.DAY:
22977
+ return date.setLocale(this.locale).toFormat("LLL yyyy");
22978
+ default:
22979
+ return "";
22980
+ }
22981
+ }
22982
+ /**
22983
+ * The texts of the second row under the category labels. `two-row` mode: the
22984
+ * parent period under the first period and where it changes, joined with the
22985
+ * scenario name where a run starts, each under its period. Else the scenario
22986
+ * names alone, each under the middle of its run.
22987
+ */
22988
+ contextRow() {
22989
+ const runs = this.switchRuns();
22990
+ if (this.axisLabelsMode !== withStyled.AxisLabelsMode.TWO_ROW) {
22991
+ return runs.map((run) => ({
22992
+ from: run.from,
22993
+ to: run.to,
22994
+ text: Formatter.translateScenarioLabel(run.scenario, this.i18n),
22995
+ scenario: run.scenario,
22996
+ }));
22997
+ }
22998
+ // the line chart writes its own labels and has no second row
22999
+ if (!this.isVarianceChart() && this.determineEffectiveChartMode() !== withStyled.ChartMode.BAR) {
23000
+ return [];
23001
+ }
23002
+ const model = this.isVarianceChart() ? this.variancesDataModel : this.dataModel;
23003
+ const entries = [];
23004
+ let lastParent = "";
23005
+ model.forEach((row, index) => {
23006
+ var _a;
23007
+ const run = runs.find((candidate) => candidate.from === index);
23008
+ const parent = this.parentPeriodLabel(row.date);
23009
+ const parts = [];
23010
+ if (parent !== "" && parent !== lastParent) {
23011
+ parts.push(parent);
23012
+ }
23013
+ lastParent = parent;
23014
+ if (run) {
23015
+ parts.push(Formatter.translateScenarioLabel(run.scenario, this.i18n));
23016
+ }
23017
+ if (parts.length > 0) {
23018
+ entries.push({ from: index, to: index, text: parts.join(" "), scenario: (_a = run === null || run === void 0 ? void 0 : run.scenario) !== null && _a !== void 0 ? _a : "parent" });
23019
+ }
23020
+ });
23021
+ return entries;
22726
23022
  }
22727
23023
  /** True for a scenario slot that has a value in this period. */
22728
23024
  static hasValue(dataPoint) {
@@ -22733,7 +23029,9 @@ class TimeChart {
22733
23029
  * periods where the first scenario has none. Empty without `scenarioSwitch`.
22734
23030
  */
22735
23031
  followerSlots() {
22736
- if (!this.scenarioSwitch || this.stackConfig != null || this.determineEffectiveChartMode() !== withStyled.ChartMode.BAR) {
23032
+ // a stack by scenario draws its scenarios on top of each other: nothing follows there
23033
+ const stacksScenarios = this.stackConfig != null && this.stackConfig.by !== withStyled.StackBy.DIMENSIONS;
23034
+ if (!this.scenarioSwitch || stacksScenarios || this.determineEffectiveChartMode() !== withStyled.ChartMode.BAR) {
22737
23035
  return [];
22738
23036
  }
22739
23037
  return ["scenario2", "scenario3", "scenario4"].filter((slot) => {
@@ -22759,8 +23057,13 @@ class TimeChart {
22759
23057
  }
22760
23058
  /** Runs of periods with the same visible scenario. A period without a value belongs to the run before it. */
22761
23059
  switchRuns() {
23060
+ const stacksScenarios = this.stackConfig != null && this.stackConfig.by !== withStyled.StackBy.DIMENSIONS;
23061
+ if (!this.scenarioSwitch || stacksScenarios || this.determineEffectiveChartMode() !== withStyled.ChartMode.BAR) {
23062
+ return [];
23063
+ }
22762
23064
  const followers = this.followerSlots();
22763
- if (followers.length === 0) {
23065
+ // a chart with one scenario is one run: its scenario still gets its name under the axis
23066
+ if (followers.length === 0 && this.scenarioPropOrder.length !== 1) {
22764
23067
  return [];
22765
23068
  }
22766
23069
  const runs = [];
@@ -22777,6 +23080,21 @@ class TimeChart {
22777
23080
  });
22778
23081
  return runs;
22779
23082
  }
23083
+ /**
23084
+ * Stack by dimensions with `scenarioSwitch`: the scenarios with values that
23085
+ * are not drawn, because they have values in periods of the first scenario
23086
+ * or because the chart is a stacked area. The component warns about them.
23087
+ */
23088
+ getIgnoredSwitchScenarios() {
23089
+ var _a;
23090
+ if (!this.scenarioSwitch || ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.by) !== withStyled.StackBy.DIMENSIONS || this.isVarianceChart()) {
23091
+ return [];
23092
+ }
23093
+ const followers = this.followerSlots();
23094
+ return ["scenario2", "scenario3", "scenario4"]
23095
+ .filter((slot) => !followers.includes(slot) && this.dataModel.some((row) => TimeChart.hasValue(row[slot])))
23096
+ .map((slot) => { var _a; return (_a = this.dataModel.find((row) => { var _a; return ((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.scenario) != null; })) === null || _a === void 0 ? void 0 : _a[slot].scenario; });
23097
+ }
22780
23098
  /** Number of periods where variances of one row overlap. The component warns about it. */
22781
23099
  getVarianceOverlaps() {
22782
23100
  return this.varianceOverlaps;
@@ -23010,6 +23328,8 @@ class TimeChart {
23010
23328
  if (this.leftSideOffsetForHorizontalSync > -1) {
23011
23329
  maxLabelLengthLeft = this.leftSideOffsetForHorizontalSync;
23012
23330
  }
23331
+ // the series names of a stack by dimension are not known to the component that hands in the offset
23332
+ maxLabelLengthLeft = Math.max(maxLabelLengthLeft, this.legendWidth("left"));
23013
23333
  let min;
23014
23334
  let max;
23015
23335
  if (this.isVarianceChart()) {
@@ -23099,6 +23419,7 @@ class TimeChart {
23099
23419
  return result;
23100
23420
  }
23101
23421
  populateModel(selectedScenarios, dateInterval) {
23422
+ var _a;
23102
23423
  if (this.rowCount === 0 || !this.fromExpr) {
23103
23424
  return [];
23104
23425
  }
@@ -23108,8 +23429,64 @@ class TimeChart {
23108
23429
  this.detectNaNCells(selectedScenarios, result);
23109
23430
  result = this.leftOuterJoinDates(result, dateInterval);
23110
23431
  const dataModel = this.createDataRows(result, selectedScenarios);
23432
+ if (((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.by) === withStyled.StackBy.DIMENSIONS) {
23433
+ this.populateSeries(dataModel, selectedScenarios, dateInterval);
23434
+ }
23111
23435
  return dataModel;
23112
23436
  }
23437
+ /**
23438
+ * Stack by dimension: one series per `category`, ordered by `categoryIndex`, else by first appearance.
23439
+ * Every period gets every series, so a series keeps its place and colour when a value is missing.
23440
+ */
23441
+ populateSeries(dataModel, selectedScenarios, dateInterval) {
23442
+ const rows = this.queryDataSet(dateInterval, ", [category]", ", [category]");
23443
+ this.detectNaNCells(selectedScenarios, rows);
23444
+ const keyOf = (row) => (row.category == null ? "" : String(row.category));
23445
+ const timeOf = (date) => { var _a, _b; return (_b = (_a = date === null || date === void 0 ? void 0 : date.toMillis) === null || _a === void 0 ? void 0 : _a.call(date)) !== null && _b !== void 0 ? _b : Number.NaN; };
23446
+ const order = [];
23447
+ const byPeriod = new Map();
23448
+ for (const row of rows) {
23449
+ const key = keyOf(row);
23450
+ if (!order.includes(key))
23451
+ order.push(key);
23452
+ const time = timeOf(row.calcdate);
23453
+ if (!byPeriod.has(time))
23454
+ byPeriod.set(time, new Map());
23455
+ byPeriod.get(time).set(key, row);
23456
+ }
23457
+ // `categoryIndex` gives the order when the dataset has it, as for the rows of a structure chart
23458
+ try {
23459
+ const indexRows = this.db.exec(`SELECT [category], MIN(categoryIndex) AS idx FROM ${this.fromExpr} GROUP BY [category]`);
23460
+ const indexOf = new Map(indexRows.map((row) => [row.category == null ? "" : String(row.category), row.idx]));
23461
+ if (order.every((key) => Number.isFinite(indexOf.get(key)))) {
23462
+ order.sort((a, b) => indexOf.get(a) - indexOf.get(b));
23463
+ }
23464
+ }
23465
+ catch (_a) {
23466
+ // no usable index: the order of first appearance stays
23467
+ }
23468
+ const slots = ["scenario1", "scenario2", "scenario3", "scenario4"];
23469
+ for (const entry of dataModel) {
23470
+ const period = byPeriod.get(timeOf(entry.date));
23471
+ entry.series = order.map((key) => {
23472
+ const row = period === null || period === void 0 ? void 0 : period.get(key);
23473
+ const points = {};
23474
+ slots.forEach((slot, index) => {
23475
+ const scenario = selectedScenarios[index];
23476
+ if (scenario == null)
23477
+ return;
23478
+ const raw = row === null || row === void 0 ? void 0 : row[scenario];
23479
+ const value = typeof raw === "number" ? raw : Number.NaN;
23480
+ const point = new DataPoint(value, scenario, this.pixelPerUnit, Scenario.NEU);
23481
+ if (Number.isFinite(value)) {
23482
+ point.key = { date: TimeChart.pointDate(entry.date), scenario, category: key };
23483
+ }
23484
+ points[slot] = point;
23485
+ });
23486
+ return { key, points };
23487
+ });
23488
+ }
23489
+ }
23113
23490
  detectNaNCells(scenarios, res) {
23114
23491
  res.forEach((row) => {
23115
23492
  scenarios.forEach((scenario) => {
@@ -23487,6 +23864,10 @@ class TimeChart {
23487
23864
  else if (this.axisLabelsMode === withStyled.AxisLabelsMode.SHORT) {
23488
23865
  datelabel = dateStringFactory.getShortDateString(elements.date, this.dateInterval);
23489
23866
  }
23867
+ else if (this.axisLabelsMode === withStyled.AxisLabelsMode.TWO_ROW && this.dateInterval !== withStyled.DateDistance.YEAR) {
23868
+ // the parent period stands in the second row
23869
+ datelabel = dateStringFactory.getShortDateString(elements.date, this.dateInterval);
23870
+ }
23490
23871
  new Label$1(axisLabelGroup, this.position.getColumnCenterPositionX(index), this.position.getAxisPositionY(isRelative) + offset, "", datelabel, this.styles, hookLocation, HookLocation$1.Center).forceStringTypeDraw();
23491
23872
  });
23492
23873
  }
@@ -23518,7 +23899,8 @@ class TimeChart {
23518
23899
  */
23519
23900
  drawScenarioSwitch(svgContainer) {
23520
23901
  const runs = this.switchRuns();
23521
- if (runs.length < 2) {
23902
+ const entries = this.contextRow();
23903
+ if (runs.length < 2 && entries.length === 0) {
23522
23904
  return;
23523
23905
  }
23524
23906
  const group = svgContainer.group().id("ScenarioSwitch");
@@ -23536,9 +23918,13 @@ class TimeChart {
23536
23918
  if (namesHeight === 0) {
23537
23919
  return;
23538
23920
  }
23539
- runs.forEach((run) => {
23540
- const center = (this.position.getColumnCenterPositionX(run.from) + this.position.getColumnCenterPositionX(run.to)) / 2;
23541
- new Label$1(group, center, bottom - namesHeight, "SWITCH_" + run.scenario, Formatter.translateScenarioLabel(run.scenario, this.i18n), this.styles, HookLocation$1.Top, HookLocation$1.Center).forceStringTypeDraw();
23921
+ // in two-row mode a text starts at the left edge of its period, like the parent period it carries
23922
+ const leftAligned = this.axisLabelsMode === withStyled.AxisLabelsMode.TWO_ROW;
23923
+ entries.forEach((entry) => {
23924
+ const x = leftAligned
23925
+ ? this.position.getColumnCenterPositionX(entry.from) - this.position.getColumnWidth() / 2
23926
+ : (this.position.getColumnCenterPositionX(entry.from) + this.position.getColumnCenterPositionX(entry.to)) / 2;
23927
+ new Label$1(group, x, bottom - namesHeight, "SWITCH_" + entry.scenario + "_" + entry.from, entry.text, this.styles, HookLocation$1.Top, leftAligned ? HookLocation$1.Left : HookLocation$1.Center).forceStringTypeDraw();
23542
23928
  });
23543
23929
  }
23544
23930
  drawScenarios(dataModel, svgContainer) {
@@ -23789,14 +24175,52 @@ class TimeChart {
23789
24175
  * single one. Line mode: the area stacks every scenario in one stack.
23790
24176
  */
23791
24177
  stackGroups(row) {
24178
+ var _a;
23792
24179
  if (!this.stackConfig)
23793
24180
  return [];
23794
24181
  const isScenarioStack = this.stackConfig.by === withStyled.StackBy.SCENARIOS;
23795
24182
  const isArea = this.determineEffectiveChartMode() === withStyled.ChartMode.LINE;
24183
+ const relativeSpan = this.stackConfig.mode === withStyled.StackMode.RELATIVE ? withStyled.RELATIVE_STACK_UNITS : 0;
24184
+ // a segment without a value sorts like 0: NaN in the comparison would leave the stack unsorted
24185
+ const sortValue = (segment) => (Number.isFinite(segment.value) ? segment.value : 0);
24186
+ const sortByValue = (list) => {
24187
+ if (this.stackConfig.order === "asc") {
24188
+ list.sort((a, b) => sortValue(a) - sortValue(b));
24189
+ }
24190
+ else if (this.stackConfig.order === "desc") {
24191
+ list.sort((a, b) => sortValue(b) - sortValue(a));
24192
+ }
24193
+ };
24194
+ if (!isScenarioStack && !isArea && row.series) {
24195
+ // one stack of the scenario that is visible in this period
24196
+ const slot = (_a = this.visibleSlot(row, this.followerSlots())) !== null && _a !== void 0 ? _a : "scenario1";
24197
+ const series = [];
24198
+ row.series.forEach((entry, index) => {
24199
+ const dataPoint = entry.points[slot];
24200
+ if (dataPoint) {
24201
+ series.push({
24202
+ value: dataPoint.value,
24203
+ scenario: dataPoint.scenario,
24204
+ dataPoint,
24205
+ colorIndex: index,
24206
+ label: entry.key,
24207
+ });
24208
+ }
24209
+ });
24210
+ if (!series.some((segment) => Number.isFinite(segment.value)))
24211
+ return [];
24212
+ sortByValue(series);
24213
+ return [
24214
+ {
24215
+ prefix: "",
24216
+ segments: series,
24217
+ layout: layoutStack(series.map((segment) => segment.value), relativeSpan),
24218
+ hasValue: true,
24219
+ },
24220
+ ];
24221
+ }
23796
24222
  const segments = [];
23797
- for (const key of isScenarioStack || isArea
23798
- ? ["scenario1", "scenario2", "scenario3", "scenario4"]
23799
- : ["scenario1"]) {
24223
+ for (const key of isScenarioStack ? ["scenario1", "scenario2", "scenario3", "scenario4"] : ["scenario1"]) {
23800
24224
  const dp = row[key];
23801
24225
  if (dp && !dp.isEmpty() && dp.value != null) {
23802
24226
  segments.push({ value: dp.value, scenario: dp.scenario, dataPoint: dp });
@@ -23804,7 +24228,6 @@ class TimeChart {
23804
24228
  }
23805
24229
  if (segments.length === 0)
23806
24230
  return [];
23807
- const relativeSpan = this.stackConfig.mode === withStyled.StackMode.RELATIVE ? withStyled.RELATIVE_STACK_UNITS : 0;
23808
24231
  const toGroup = (prefix, groupSegments) => ({
23809
24232
  prefix,
23810
24233
  segments: groupSegments,
@@ -23840,14 +24263,7 @@ class TimeChart {
23840
24263
  return groups;
23841
24264
  }
23842
24265
  }
23843
- // a segment without a value sorts like 0: NaN in the comparison would leave the stack unsorted
23844
- const sortValue = (segment) => (Number.isFinite(segment.value) ? segment.value : 0);
23845
- if (this.stackConfig.order === "asc") {
23846
- segments.sort((a, b) => sortValue(a) - sortValue(b));
23847
- }
23848
- else if (this.stackConfig.order === "desc") {
23849
- segments.sort((a, b) => sortValue(b) - sortValue(a));
23850
- }
24266
+ sortByValue(segments);
23851
24267
  return [toGroup("", segments)];
23852
24268
  }
23853
24269
  /**
@@ -23867,9 +24283,10 @@ class TimeChart {
23867
24283
  groups.forEach((group, groupIdx) => {
23868
24284
  let lastColumn = null;
23869
24285
  group.segments.forEach((seg, segIdx) => {
24286
+ var _a;
23870
24287
  const column = new StackedColumn(this.position, this.styles, seg.dataPoint, index, group.layout.segments[segIdx], seg.scenario,
23871
24288
  // overlay: one colour per group, back=lighter, front=darker
23872
- groups.length > 1 ? groups.length - 1 - groupIdx : segIdx, this.stackConfig.mode, group.layout, isScenarioStack, stackGroup);
24289
+ groups.length > 1 ? groups.length - 1 - groupIdx : ((_a = seg.colorIndex) !== null && _a !== void 0 ? _a : segIdx), this.stackConfig.mode, group.layout, isScenarioStack, stackGroup, this.stackConfig.notation === "scenario", this.hasPercentMark());
23873
24290
  column.draw(this.dataFormatDigits, this.measureScale);
23874
24291
  lastColumn = column;
23875
24292
  });
@@ -23888,49 +24305,137 @@ class TimeChart {
23888
24305
  width: stackBox.width + this.position.spacings.columnWidth,
23889
24306
  };
23890
24307
  }
24308
+ /** True for a 100 % stack that prints plain shares and one `100%` mark. */
24309
+ hasPercentMark() {
24310
+ var _a;
24311
+ return ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) === withStyled.StackMode.RELATIVE && this.stackConfig.percentMark === true;
24312
+ }
24313
+ /** The side of the `100%` mark: with the series names, at the left when they stand on both sides or nowhere. */
24314
+ percentMarkSide() {
24315
+ var _a;
24316
+ return ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.legend) === "right" ? "right" : "left";
24317
+ }
24318
+ /** The name of a series of a stack by dimension. A translation of the category wins. */
24319
+ seriesName(key) {
24320
+ return (this.i18n.get(key) || key);
24321
+ }
24322
+ /**
24323
+ * Width of the widest text the stack writes on one side of the columns, 0 when
24324
+ * there is none. The names of a stack by scenario at the left are part of the
24325
+ * left offset the component hands in, so they do not count here.
24326
+ */
24327
+ legendWidth(side) {
24328
+ var _a, _b;
24329
+ // the stacked area draws no names and no mark
24330
+ if (!this.stackConfig || this.determineEffectiveChartMode() !== withStyled.ChartMode.BAR)
24331
+ return 0;
24332
+ const legend = (_a = this.stackConfig.legend) !== null && _a !== void 0 ? _a : "left";
24333
+ const texts = [];
24334
+ if (legend === side || legend === "both") {
24335
+ const series = (_b = this.dataModel.find((row) => row.series != null)) === null || _b === void 0 ? void 0 : _b.series;
24336
+ if (series) {
24337
+ texts.push(...series.map((entry) => this.seriesName(entry.key)));
24338
+ }
24339
+ else if (side === "right" && this.stackConfig.by === withStyled.StackBy.SCENARIOS) {
24340
+ texts.push(...this.lastScenarios.map((scenario) => (this.i18n.get(scenario) || scenario)));
24341
+ }
24342
+ }
24343
+ if (this.hasPercentMark() && this.percentMarkSide() === side) {
24344
+ texts.push("100%");
24345
+ }
24346
+ let width = 0;
24347
+ for (const text of texts) {
24348
+ width = Math.max(width, CalculateSize(text, { font: this.styles.fontStyles.font, fontSize: this.styles.fontStyles.size + "px" }).width);
24349
+ }
24350
+ return width;
24351
+ }
23891
24352
  /**
23892
24353
  * Draw column headers next to stacked columns showing what each group/segment represents.
23893
24354
  * For overlay mode (multiple scenario types): shows one header per group.
23894
24355
  * For single-group: shows individual segment headers.
23895
- * The headers take their place from the first period.
24356
+ * The headers at the left take their place from the first period, the ones at
24357
+ * the right from the last period with a value.
23896
24358
  */
23897
24359
  drawStackedHeaders(dataModel, svgContainer) {
24360
+ var _a, _b, _c;
23898
24361
  if (!this.stackConfig || dataModel.length === 0)
23899
24362
  return;
23900
24363
  const isScenarioStack = this.stackConfig.by === withStyled.StackBy.SCENARIOS;
23901
- if (!isScenarioStack)
24364
+ const hasSeries = dataModel.some((row) => row.series != null);
24365
+ if (!isScenarioStack && !hasSeries)
23902
24366
  return;
23903
24367
  const headerGroup = svgContainer.group().id("StackedHeaders");
23904
- const groups = this.stackGroups(dataModel[0]);
23905
- if (groups.length === 0)
23906
- return;
23907
24368
  const axisY = this.position.getColumnPositionY();
23908
- const xBase = this.position.getColumnCenterPositionX(0) - this.position.getColumnWidth() / 2;
23909
- const labelX = xBase - this.position.spacings.labelToColumn;
23910
- const drawHeader = (centerY, labelText) => {
23911
- new Label$1(headerGroup, labelX, centerY, "STACK_HEADER", labelText, this.styles, HookLocation$1.Center, HookLocation$1.Right).forceStringTypeDraw();
23912
- };
23913
- if (groups.length > 1) {
23914
- // Overlay mode: one header per group
23915
- groups.forEach((group, groupIdx) => {
23916
- const { positive, negative, total } = group.layout;
23917
- const pixelPerUnit = group.segments[0].dataPoint.pixelPerUnit;
23918
- // The front-most group (drawn last, e.g. AC) is fully visible, so its
23919
- // label is centered on the bar. Back groups are mostly hidden behind it
23920
- // and only peek out at their outer end, so their labels align with that edge.
23921
- const isFrontGroup = groupIdx === groups.length - 1;
23922
- const outerEnd = total < 0 ? 0 - negative : positive;
23923
- const centerY = axisY - (isFrontGroup ? (positive - negative) / 2 : outerEnd) * pixelPerUnit;
23924
- drawHeader(centerY, (this.i18n.get(group.prefix + "1") || group.prefix.toUpperCase()));
24369
+ const halfColumn = this.position.getColumnWidth() / 2;
24370
+ const gap = this.position.spacings.labelToColumn;
24371
+ const withValue = dataModel.map((row, index) => (this.stackGroups(row).length > 0 ? index : -1));
24372
+ const filled = withValue.filter((index) => index >= 0);
24373
+ // a stack by scenario keeps the first period, also when it is empty
24374
+ const firstIndex = hasSeries ? ((_a = filled[0]) !== null && _a !== void 0 ? _a : 0) : 0;
24375
+ const lastIndex = (_b = filled[filled.length - 1]) !== null && _b !== void 0 ? _b : dataModel.length - 1;
24376
+ const drawSide = (side) => {
24377
+ const index = side === "left" ? firstIndex : lastIndex;
24378
+ const groups = this.stackGroups(dataModel[index]);
24379
+ if (groups.length === 0)
24380
+ return;
24381
+ const center = this.position.getColumnCenterPositionX(index);
24382
+ const labelX = side === "left" ? center - halfColumn - gap : center + halfColumn + gap;
24383
+ const drawHeader = (centerY, labelText) => {
24384
+ new Label$1(headerGroup, labelX, centerY, "STACK_HEADER", labelText, this.styles, HookLocation$1.Center, side === "left" ? HookLocation$1.Right : HookLocation$1.Left).forceStringTypeDraw();
24385
+ };
24386
+ if (groups.length > 1) {
24387
+ // Overlay mode: one header per group
24388
+ groups.forEach((group, groupIdx) => {
24389
+ const { positive, negative, total } = group.layout;
24390
+ const pixelPerUnit = group.segments[0].dataPoint.pixelPerUnit;
24391
+ // The front-most group (drawn last, e.g. AC) is fully visible, so its
24392
+ // label is centered on the bar. Back groups are mostly hidden behind it
24393
+ // and only peek out at their outer end, so their labels align with that edge.
24394
+ const isFrontGroup = groupIdx === groups.length - 1;
24395
+ const outerEnd = total < 0 ? 0 - negative : positive;
24396
+ const centerY = axisY - (isFrontGroup ? (positive - negative) / 2 : outerEnd) * pixelPerUnit;
24397
+ drawHeader(centerY, (this.i18n.get(group.prefix + "1") || group.prefix.toUpperCase()));
24398
+ });
24399
+ return;
24400
+ }
24401
+ // Single group: one header per segment, centered on the segment
24402
+ const [group] = groups;
24403
+ group.segments.forEach((seg, segIdx) => {
24404
+ // a series without a value in this period has no segment to stand next to
24405
+ if (seg.label != null && !Number.isFinite(seg.value))
24406
+ return;
24407
+ const { start, end } = group.layout.segments[segIdx];
24408
+ drawHeader(axisY - ((start + end) / 2) * seg.dataPoint.pixelPerUnit, seg.label != null ? this.seriesName(seg.label) : (this.i18n.get(seg.scenario) || seg.scenario));
23925
24409
  });
23926
- return;
23927
- }
23928
- // Single group: one header per segment, centered on the segment
23929
- const [group] = groups;
23930
- group.segments.forEach((seg, segIdx) => {
23931
- const { start, end } = group.layout.segments[segIdx];
23932
- drawHeader(axisY - ((start + end) / 2) * seg.dataPoint.pixelPerUnit, (this.i18n.get(seg.scenario) || seg.scenario));
23933
- });
24410
+ };
24411
+ const legend = (_c = this.stackConfig.legend) !== null && _c !== void 0 ? _c : "left";
24412
+ if (legend === "left" || legend === "both")
24413
+ drawSide("left");
24414
+ if (legend === "right" || legend === "both")
24415
+ drawSide("right");
24416
+ if (this.hasPercentMark() && filled.length > 0) {
24417
+ this.drawPercentMark(headerGroup, this.percentMarkSide() === "left" ? firstIndex : lastIndex);
24418
+ }
24419
+ }
24420
+ /** The `100%` label with a pointer at the upper end of a 100 % stack, on the side of the series names. */
24421
+ drawPercentMark(group, index) {
24422
+ const side = this.percentMarkSide();
24423
+ const direction = side === "left" ? -1 : 1;
24424
+ const top = this.position.getColumnPositionY() - withStyled.RELATIVE_STACK_UNITS * this.pixelPerUnit;
24425
+ const edge = this.position.getColumnCenterPositionX(index) + direction * (this.position.getColumnWidth() / 2);
24426
+ const size = this.styles.fontStyles.size * 0.45;
24427
+ const tip = edge + direction * 1;
24428
+ const base = tip + direction * size;
24429
+ group
24430
+ .polygon([
24431
+ [tip, top],
24432
+ [base, top - size / 2],
24433
+ [base, top + size / 2],
24434
+ ])
24435
+ .fill(this.styles.fontStyles.color || "#000000")
24436
+ .addClass("percent-mark");
24437
+ // above the pointer, so the name of the uppermost series keeps its place next to its segment
24438
+ new Label$1(group, base, top - size / 2, "STACK_PERCENT_MARK", "100%", this.styles, HookLocation$1.Bottom, side === "left" ? HookLocation$1.Right : HookLocation$1.Left).forceStringTypeDraw();
23934
24439
  }
23935
24440
  /**
23936
24441
  * Draw stacked area chart (line mode with stack).
@@ -23953,7 +24458,8 @@ class TimeChart {
23953
24458
  const layerScenarios = [];
23954
24459
  // Identify active layers
23955
24460
  const activeLayers = [];
23956
- for (const key of scenarioKeys) {
24461
+ // a stack by dimensions draws its first scenario only
24462
+ for (const key of isScenarioStack ? scenarioKeys : ["scenario1"]) {
23957
24463
  if (dataModel.some((el) => el[key] && !el[key].isEmpty())) {
23958
24464
  activeLayers.push(key);
23959
24465
  }
@@ -24400,25 +24906,39 @@ const BnChartTimeRenderer = class {
24400
24906
  }
24401
24907
  /** Reports a failed query as the wrapper's `ERR_sql` item. Without it the chart would only show "No Data". */
24402
24908
  syncQueryError() {
24403
- var _a, _b, _c, _d, _e, _f, _g;
24909
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
24404
24910
  this.queryError = (_a = this.measureScaleError) !== null && _a !== void 0 ? _a : (_b = this.chart) === null || _b === void 0 ? void 0 : _b.getQueryError();
24405
24911
  queryError.reportQueryError(this.errors, this.queryError);
24912
+ // the renderers of the variance rows share the error store: only the base chart reports
24913
+ if (this.variances.every((variance) => variance === "")) {
24914
+ const ignored = (_d = (_c = this.chart) === null || _c === void 0 ? void 0 : _c.getIgnoredSwitchScenarios()) !== null && _d !== void 0 ? _d : [];
24915
+ if (ignored.length > 0) {
24916
+ (_e = this.errors) === null || _e === void 0 ? void 0 : _e.addOrReplace({
24917
+ id: "WARN_stack_switch_ignored",
24918
+ type: "warning",
24919
+ message: `stack by dimensions with scenarioSwitch: ${ignored.join(", ")} is not drawn. A scenario continues the first one only where the first one has no value, and only in bar mode.`,
24920
+ });
24921
+ }
24922
+ else {
24923
+ (_f = this.errors) === null || _f === void 0 ? void 0 : _f.remove("WARN_stack_switch_ignored");
24924
+ }
24925
+ }
24406
24926
  const errId = `WARN_variances_overlap_${this.variances.join("_")}`;
24407
- const overlaps = (_d = (_c = this.chart) === null || _c === void 0 ? void 0 : _c.getVarianceOverlaps()) !== null && _d !== void 0 ? _d : 0;
24927
+ const overlaps = (_h = (_g = this.chart) === null || _g === void 0 ? void 0 : _g.getVarianceOverlaps()) !== null && _h !== void 0 ? _h : 0;
24408
24928
  // the row can get other variances: the warning of the old list has to go
24409
24929
  if (this.overlapErrId && this.overlapErrId !== errId) {
24410
- (_e = this.errors) === null || _e === void 0 ? void 0 : _e.remove(this.overlapErrId);
24930
+ (_j = this.errors) === null || _j === void 0 ? void 0 : _j.remove(this.overlapErrId);
24411
24931
  }
24412
24932
  this.overlapErrId = overlaps > 0 ? errId : undefined;
24413
24933
  if (overlaps > 0) {
24414
- (_f = this.errors) === null || _f === void 0 ? void 0 : _f.addOrReplace({
24934
+ (_k = this.errors) === null || _k === void 0 ? void 0 : _k.addOrReplace({
24415
24935
  id: errId,
24416
24936
  type: "warning",
24417
24937
  message: `scenarioSwitch: the variances ${this.variances.join(", ")} share a row, but ${overlaps} period(s) have more than one value. The first variance wins there.`,
24418
24938
  });
24419
24939
  }
24420
24940
  else {
24421
- (_g = this.errors) === null || _g === void 0 ? void 0 : _g.remove(errId);
24941
+ (_l = this.errors) === null || _l === void 0 ? void 0 : _l.remove(errId);
24422
24942
  }
24423
24943
  }
24424
24944
  async componentWillLoad() {