@bino-bi/bn-template-engine 1.0.0-next.45 → 1.0.0-next.46

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 (169) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-8b28c9bd.entry.js → p-16623e0f.entry.js} +1 -1
  3. package/dist/bn-template-engine/p-17970e07.entry.js +1 -0
  4. package/dist/bn-template-engine/{p-48871742.entry.js → p-21930d0a.entry.js} +1 -1
  5. package/dist/bn-template-engine/{p-5a64f90f.entry.js → p-46c46067.entry.js} +1 -1
  6. package/dist/bn-template-engine/p-9caa7f46.entry.js +1 -0
  7. package/dist/bn-template-engine/p-B0MEAsAS.js +1 -0
  8. package/dist/bn-template-engine/{p-qpZjVnX5.js → p-BA-fydUt.js} +1 -1
  9. package/dist/bn-template-engine/p-BEGt_7Hr.js +1 -0
  10. package/dist/bn-template-engine/p-BRO1oW7m.js +1 -0
  11. package/dist/bn-template-engine/{p-DVE0-sOv.js → p-BnzIfgCq.js} +1 -1
  12. package/dist/bn-template-engine/{p-b0dfc113.entry.js → p-b0d528f2.entry.js} +1 -1
  13. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +608 -83
  14. package/dist/cjs/bn-grid.cjs.entry.js +161 -34
  15. package/dist/cjs/bn-image.cjs.entry.js +2 -2
  16. package/dist/cjs/bn-internationalization.cjs.entry.js +2 -2
  17. package/dist/cjs/bn-ruleset.cjs.entry.js +2 -2
  18. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  19. package/dist/cjs/bn-text.cjs.entry.js +3 -3
  20. package/dist/cjs/loader.cjs.js +1 -1
  21. package/dist/cjs/{localFrame-U3Qs0psw.js → localFrame-C27GGom1.js} +1 -1
  22. package/dist/cjs/{withBodyObserver-S-FGHpAX.js → withBodyObserver-B78wzw3f.js} +1 -1
  23. package/dist/cjs/{withHasError-BkBrsCpI.js → withHasError-0hW3-4mr.js} +11 -5
  24. package/dist/cjs/{withStyled-BZb6snOx.js → withStyled-D0hrcfE_.js} +25 -1
  25. package/dist/cjs/{withTranslation-1qTs5Fi7.js → withTranslation-B4WipL_5.js} +2 -2
  26. package/dist/collection/components/bn-annotation-layer/bn-annotation-layer.js +33 -2
  27. package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +112 -16
  28. package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +1 -1
  29. package/dist/collection/components/bn-chart-structure/utils/elements/Needle.js +3 -3
  30. package/dist/collection/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.js +113 -3
  31. package/dist/collection/components/bn-chart-time/bn-chart-time.js +261 -22
  32. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +221 -12
  33. package/dist/collection/components/bn-chart-time/utils/elements/Axis.js +9 -1
  34. package/dist/collection/components/bn-chart-time/utils/elements/Column.js +10 -4
  35. package/dist/collection/components/bn-chart-time/utils/elements/Needle.js +9 -3
  36. package/dist/collection/components/bn-chart-time/utils/factories/ScenarioFactory.js +2 -2
  37. package/dist/collection/components/bn-chart-time/utils/model/DataPoint.js +9 -6
  38. package/dist/collection/components/bn-chart-time/utils/model/TimeChartComponentConfig.js +15 -0
  39. package/dist/collection/components/bn-grid/bn-grid.js +118 -24
  40. package/dist/collection/components/bn-grid/utils/cellLayout.js +55 -9
  41. package/dist/collection/components/bn-layout-card/bn-layout-card.js +4 -2
  42. package/dist/collection/components/bn-layout-page/bn-layout-page.js +23 -1
  43. package/dist/collection/components/bn-title/bn-title-renderer/bn-title-renderer.css +10 -0
  44. package/dist/collection/components/bn-title/bn-title-renderer/bn-title-renderer.js +23 -1
  45. package/dist/collection/components/bn-title/bn-title.js +40 -2
  46. package/dist/collection/stores/componentStyles.js +9 -3
  47. package/dist/collection/stores/internationalization.js +2 -2
  48. package/dist/collection/utils/DateStringFactory.js +19 -0
  49. package/dist/collection/utils/model/DataFormatDigits.js +4 -2
  50. package/dist/collection/utils/model/VarianceScenario.js +13 -0
  51. package/dist/collection/utils/validate.js +4 -0
  52. package/dist/components/bn-annotation-layer.js +1 -1
  53. package/dist/components/bn-annotation-list.js +1 -1
  54. package/dist/components/bn-asset.js +1 -1
  55. package/dist/components/bn-body.js +1 -1
  56. package/dist/components/bn-card.js +1 -1
  57. package/dist/components/bn-chart-bubble-renderer.js +1 -1
  58. package/dist/components/bn-chart-bubble.js +1 -1
  59. package/dist/components/bn-chart-bullet-renderer.js +1 -1
  60. package/dist/components/bn-chart-bullet.js +1 -1
  61. package/dist/components/bn-chart-scatter-renderer.js +1 -1
  62. package/dist/components/bn-chart-scatter.js +1 -1
  63. package/dist/components/bn-chart-structure-renderer.js +1 -1
  64. package/dist/components/bn-chart-structure.js +1 -1
  65. package/dist/components/bn-chart-time-renderer.js +1 -1
  66. package/dist/components/bn-chart-time.js +1 -1
  67. package/dist/components/bn-component-style.js +1 -1
  68. package/dist/components/bn-context.js +1 -1
  69. package/dist/components/bn-dataset.js +1 -1
  70. package/dist/components/bn-datasource.js +1 -1
  71. package/dist/components/bn-footer.js +1 -1
  72. package/dist/components/bn-grid.js +1 -1
  73. package/dist/components/bn-image.js +1 -1
  74. package/dist/components/bn-internationalization.js +1 -1
  75. package/dist/components/bn-layout-card.js +1 -1
  76. package/dist/components/bn-layout-page.js +1 -1
  77. package/dist/components/bn-message.js +1 -1
  78. package/dist/components/bn-page.js +1 -1
  79. package/dist/components/bn-ruleset.js +1 -1
  80. package/dist/components/bn-scaling-group.js +1 -1
  81. package/dist/components/bn-table-renderer.js +1 -1
  82. package/dist/components/bn-table.js +1 -1
  83. package/dist/components/bn-text.js +1 -1
  84. package/dist/components/bn-title-renderer.js +1 -1
  85. package/dist/components/bn-title.js +1 -1
  86. package/dist/components/bn-tree.js +1 -1
  87. package/dist/components/p-9X5fVJqR.js +1 -0
  88. package/dist/components/p-B5GRtTLX.js +1 -0
  89. package/dist/components/{p-DJUffGeB.js → p-BKA15uoz.js} +1 -1
  90. package/dist/components/p-BKLq0Pbv.js +1 -0
  91. package/dist/components/p-BKTBdrEA.js +1 -0
  92. package/dist/components/p-Bd8cQiLx.js +1 -0
  93. package/dist/components/{p-CvEdUq8i.js → p-Be0Q3bvf.js} +1 -1
  94. package/dist/components/{p-xIWChKGS.js → p-Bj3RWsEx.js} +1 -1
  95. package/dist/components/{p-B4L069XF.js → p-BoBamuPt.js} +1 -1
  96. package/dist/components/{p-DaOm9YwQ.js → p-BrJZUp-K.js} +1 -1
  97. package/dist/components/{p-CyfGkLMh.js → p-BuWNCnvR.js} +1 -1
  98. package/dist/components/{p-M2k_I8lv.js → p-CFVoK5Rb.js} +1 -1
  99. package/dist/components/{p-fKJx8WtW.js → p-CgJB5mCu.js} +1 -1
  100. package/dist/components/p-Cxx0YNnl.js +1 -0
  101. package/dist/components/p-D9F5IBFT.js +1 -0
  102. package/dist/components/{p-BfUdaxZ9.js → p-DQFahsnV.js} +1 -1
  103. package/dist/components/p-DROj8gke.js +1 -0
  104. package/dist/components/p-D_Sbhd0L.js +1 -0
  105. package/dist/components/{p-Cel0a6ma.js → p-DbWh9W5D.js} +1 -1
  106. package/dist/components/{p-2eicD9rF.js → p-DkCeSWKR.js} +1 -1
  107. package/dist/components/{p-7ieJFBUk.js → p-DoOSXntC.js} +1 -1
  108. package/dist/components/p-Dxj_pf8s.js +1 -0
  109. package/dist/components/{p-DQl2K2Xl.js → p-DzYhS_9s.js} +1 -1
  110. package/dist/components/{p-B2bvM2Ig.js → p-EQNS13GN.js} +1 -1
  111. package/dist/components/{p-Y9bth2Y_.js → p-G56USTsQ.js} +1 -1
  112. package/dist/components/p-OgFFKehL.js +1 -0
  113. package/dist/components/{p-C2ycO60j.js → p-kvYRImZT.js} +1 -1
  114. package/dist/components/{p-Chuj-LpI.js → p-rEdNIgD8.js} +1 -1
  115. package/dist/components/{p-DwuXVo2h.js → p-uCpFBDF5.js} +1 -1
  116. package/dist/esm/bn-annotation-layer_30.entry.js +608 -83
  117. package/dist/esm/bn-grid.entry.js +161 -34
  118. package/dist/esm/bn-image.entry.js +2 -2
  119. package/dist/esm/bn-internationalization.entry.js +2 -2
  120. package/dist/esm/bn-ruleset.entry.js +2 -2
  121. package/dist/esm/bn-template-engine.js +1 -1
  122. package/dist/esm/bn-text.entry.js +3 -3
  123. package/dist/esm/loader.js +1 -1
  124. package/dist/esm/{localFrame-BNWPPaQa.js → localFrame-CEZ7-hBs.js} +1 -1
  125. package/dist/esm/{withBodyObserver-AHQAUV85.js → withBodyObserver-D9yIMxdr.js} +1 -1
  126. package/dist/esm/{withHasError-B6Lvj9Cq.js → withHasError-UGtkLrYT.js} +11 -5
  127. package/dist/esm/{withStyled-CzzXg64f.js → withStyled-BlMqEIfr.js} +25 -2
  128. package/dist/esm/{withTranslation-C1gL7wSU.js → withTranslation-Bc3bjHTb.js} +2 -2
  129. package/dist/schemas/theme.schema.json +18 -0
  130. package/dist/types/components/bn-annotation-layer/bn-annotation-layer.d.ts +11 -0
  131. package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +16 -0
  132. package/dist/types/components/bn-chart-structure/utils/elements/Needle.d.ts +2 -1
  133. package/dist/types/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.d.ts +8 -0
  134. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +46 -1
  135. package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +37 -0
  136. package/dist/types/components/bn-chart-time/utils/elements/Axis.d.ts +2 -0
  137. package/dist/types/components/bn-chart-time/utils/elements/Needle.d.ts +2 -1
  138. package/dist/types/components/bn-chart-time/utils/factories/ScenarioFactory.d.ts +1 -1
  139. package/dist/types/components/bn-chart-time/utils/model/DataPoint.d.ts +6 -1
  140. package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +6 -0
  141. package/dist/types/components/bn-grid/bn-grid.d.ts +23 -0
  142. package/dist/types/components/bn-grid/utils/cellLayout.d.ts +39 -3
  143. package/dist/types/components/bn-layout-card/bn-layout-card.d.ts +3 -1
  144. package/dist/types/components/bn-layout-page/bn-layout-page.d.ts +9 -0
  145. package/dist/types/components/bn-title/bn-title-renderer/bn-title-renderer.d.ts +2 -0
  146. package/dist/types/components/bn-title/bn-title.d.ts +10 -0
  147. package/dist/types/components.d.ts +173 -6
  148. package/dist/types/stores/componentStyles.d.ts +8 -0
  149. package/dist/types/utils/DateStringFactory.d.ts +4 -0
  150. package/dist/types/utils/layoutState/types.d.ts +3 -0
  151. package/dist/types/utils/model/VarianceScenario.d.ts +2 -0
  152. package/dist/types/utils/validate.d.ts +2 -0
  153. package/package.json +1 -1
  154. package/dist/bn-template-engine/p-1b002bd5.entry.js +0 -1
  155. package/dist/bn-template-engine/p-750b2c82.entry.js +0 -1
  156. package/dist/bn-template-engine/p-D0tNATZq.js +0 -1
  157. package/dist/bn-template-engine/p-DF9sfwBN.js +0 -1
  158. package/dist/bn-template-engine/p-EcC0qLtU.js +0 -1
  159. package/dist/components/p-1B_s8oPY.js +0 -1
  160. package/dist/components/p-AwH1w8Mu.js +0 -1
  161. package/dist/components/p-BiSytXUy.js +0 -1
  162. package/dist/components/p-C3gYq-HU.js +0 -1
  163. package/dist/components/p-CEf5X8MZ.js +0 -1
  164. package/dist/components/p-CniN8ALm.js +0 -1
  165. package/dist/components/p-D40Am1Ap.js +0 -1
  166. package/dist/components/p-DDvWTgk1.js +0 -1
  167. package/dist/components/p-DjPWZfry.js +0 -1
  168. package/dist/components/p-DnDL1pPc.js +0 -1
  169. package/dist/components/p-sLbQ7yZ1.js +0 -1
@@ -98,6 +98,11 @@ export class TimeChart {
98
98
  this.availableWidth = 0;
99
99
  this.overflowConfig = null;
100
100
  this.lastScenarios = [];
101
+ this.axisLabelsStep = 1;
102
+ this.scenarioSwitch = false;
103
+ this.axisTitlePosition = "left";
104
+ /** Periods in which more than one variance of a shared row has a value. */
105
+ this.varianceOverlaps = 0;
101
106
  this.db = db;
102
107
  this.tableName = tableName;
103
108
  this.ruleSet = ruleSet || new IBCSRuleSet();
@@ -152,7 +157,8 @@ export class TimeChart {
152
157
  this.position.padding.top +
153
158
  this.position.padding.bottom +
154
159
  this.position.spacings.labelToAxis +
155
- fontSize; // axis labels approximate height
160
+ fontSize + // axis labels approximate height
161
+ this.switchNamesHeight();
156
162
  const overdriveZoneHeight = fontSize * 1.5;
157
163
  const breakGap = fontSize * 0.3;
158
164
  const cutHeight = availableHeight - nonBarOverhead - overdriveZoneHeight - breakGap;
@@ -176,7 +182,7 @@ export class TimeChart {
176
182
  };
177
183
  }
178
184
  setConfig(config) {
179
- var _a;
185
+ var _a, _b, _c, _d;
180
186
  this.state = FactoryState.DIRTY;
181
187
  // Must precede setSource/populateModel: the locale is baked into the
182
188
  // normalizeDate() SQL as well as into the axis date labels.
@@ -189,11 +195,14 @@ export class TimeChart {
189
195
  this.pixelPerPercentage = config.pixelPerPercentage;
190
196
  this.axisLabelsMode = config.axisLabelsMode;
191
197
  this.intervalSpanLimit = config.intervalSpanLimit;
198
+ this.axisLabelsStep = (_a = config.axisLabelsStep) !== null && _a !== void 0 ? _a : 1;
199
+ this.scenarioSwitch = (_b = config.scenarioSwitch) !== null && _b !== void 0 ? _b : false;
200
+ this.axisTitlePosition = (_c = config.axisTitlePosition) !== null && _c !== void 0 ? _c : "left";
192
201
  this.dateInterval = this.findDateInterval(config.dateInterval);
193
202
  this.dataModel = this.populateModel(scenarios, this.dateInterval);
194
203
  this.variancesDataModel = this.populateVarianceModel(config.variances, this.dataModel);
195
204
  this.configTitle = config.title;
196
- this.configVariances = (_a = config === null || config === void 0 ? void 0 : config.variances) !== null && _a !== void 0 ? _a : [];
205
+ this.configVariances = (_d = config === null || config === void 0 ? void 0 : config.variances) !== null && _d !== void 0 ? _d : [];
197
206
  this.updateTitle();
198
207
  this.smallestDataPointValue = this.findSmallestDataPointValue(this.dataModel);
199
208
  this.smallestVarianceDataPointValue = this.findSmallestDataPointValue(this.variancesDataModel);
@@ -261,8 +270,10 @@ export class TimeChart {
261
270
  }
262
271
  /** Derives the variance title from the stored config and the current i18n map. */
263
272
  updateTitle() {
264
- var _a;
265
- this.title = this.configTitle || Formatter.translateScenarioLabel((_a = this.configVariances) === null || _a === void 0 ? void 0 : _a.toString(), this.i18n);
273
+ var _a, _b;
274
+ // variances that share a row have the same reference: the first one names the row
275
+ const variance = this.scenarioSwitch ? (_a = this.configVariances) === null || _a === void 0 ? void 0 : _a[0] : (_b = this.configVariances) === null || _b === void 0 ? void 0 : _b.toString();
276
+ this.title = this.configTitle || Formatter.translateScenarioLabel(variance, this.i18n);
266
277
  }
267
278
  /**
268
279
  * Resolves the dataset (a table or view in the shared alasql database) and
@@ -303,7 +314,15 @@ export class TimeChart {
303
314
  // Also consider bbox-based measurement as a fallback (works for rects)
304
315
  const bboxWidth = Math.max(this.axisCategoryArea.width, this.scenariosArea.width);
305
316
  const bboxTotal = bboxWidth > 0 ? bboxWidth + this.position.leftSideLabelLength : 0;
306
- return Math.max(axisEnd + labelBuffer, bboxTotal);
317
+ let titleEnd = 0;
318
+ if (this.axisTitlePosition === "right" && this.title) {
319
+ const titleWidth = CalculateSize(this.title, {
320
+ font: this.styles.fontStyles.font,
321
+ fontSize: this.styles.fontStyles.size + "px",
322
+ }).width;
323
+ titleEnd = axisEnd + this.position.spacings.labelToColumn + titleWidth + this.styles.padding.right;
324
+ }
325
+ return Math.max(axisEnd + labelBuffer, bboxTotal, titleEnd);
307
326
  }
308
327
  getAllocatedCanvasHeight() {
309
328
  if (this.smallestVarianceDataPointValue.value == null ||
@@ -334,7 +353,91 @@ export class TimeChart {
334
353
  const bboxHeight = isOnSameAxisSide
335
354
  ? this.axisCategoryArea.height + this.scenariosArea.height
336
355
  : this.scenariosArea.height;
337
- return Math.max(analyticalHeight, bboxHeight);
356
+ return Math.max(analyticalHeight, bboxHeight) + this.switchNamesHeight();
357
+ }
358
+ /** Room for the scenario names under the category labels of a series that changes its scenario. */
359
+ switchNamesHeight() {
360
+ return !this.hideAxisLabels && this.switchRuns().length > 1 ? this.position.dataLabelHeight : 0;
361
+ }
362
+ /** True for a scenario slot that has a value in this period. */
363
+ static hasValue(dataPoint) {
364
+ return dataPoint != null && !dataPoint.isEmpty() && dataPoint.value != null && !Number.isNaN(dataPoint.value);
365
+ }
366
+ /**
367
+ * The slots that continue the first scenario: they have values, and only in
368
+ * periods where the first scenario has none. Empty without `scenarioSwitch`.
369
+ */
370
+ followerSlots() {
371
+ if (!this.scenarioSwitch || this.stackConfig != null || this.determineEffectiveChartMode() !== ChartMode.BAR) {
372
+ return [];
373
+ }
374
+ return ["scenario2", "scenario3", "scenario4"].filter((slot) => {
375
+ let values = 0;
376
+ for (const row of this.dataModel) {
377
+ if (TimeChart.hasValue(row[slot])) {
378
+ if (TimeChart.hasValue(row.scenario1)) {
379
+ return false;
380
+ }
381
+ values++;
382
+ }
383
+ }
384
+ return values > 0;
385
+ });
386
+ }
387
+ /** The slot drawn as the column of a period: the first scenario, else the first follower with a value. */
388
+ visibleSlot(row, followers) {
389
+ var _a;
390
+ if (TimeChart.hasValue(row.scenario1)) {
391
+ return "scenario1";
392
+ }
393
+ return (_a = followers.find((slot) => TimeChart.hasValue(row[slot]))) !== null && _a !== void 0 ? _a : null;
394
+ }
395
+ /** Runs of periods with the same visible scenario. A period without a value belongs to the run before it. */
396
+ switchRuns() {
397
+ const followers = this.followerSlots();
398
+ if (followers.length === 0) {
399
+ return [];
400
+ }
401
+ const runs = [];
402
+ this.dataModel.forEach((row, index) => {
403
+ const slot = this.visibleSlot(row, followers);
404
+ const scenario = slot ? row[slot].scenario : null;
405
+ const last = runs[runs.length - 1];
406
+ if (scenario == null || (last === null || last === void 0 ? void 0 : last.scenario) === scenario) {
407
+ if (last)
408
+ last.to = index;
409
+ return;
410
+ }
411
+ runs.push({ scenario, from: index, to: index });
412
+ });
413
+ return runs;
414
+ }
415
+ /** Number of periods where variances of one row overlap. The component warns about it. */
416
+ getVarianceOverlaps() {
417
+ return this.varianceOverlaps;
418
+ }
419
+ /**
420
+ * Lifts the 145 % cut of relative variances when the uncut pins fit into
421
+ * `availableHeight`. Only for a fixed percentage scale: the author chose it,
422
+ * so a long pin is cut for lack of room only.
423
+ */
424
+ fitRelativeVariances(availableHeight) {
425
+ const points = this.variancesDataModel
426
+ .filter((entry) => entry.type === VarianceType.RELATIVE)
427
+ .map((entry) => entry.scenario1);
428
+ if (points.length === 0 || !points.some((point) => point.isClipped())) {
429
+ return;
430
+ }
431
+ const setClamp = (clamp) => {
432
+ points.forEach((point) => (point.percentClamp = clamp));
433
+ this.updatePosition(this.lastScenarios);
434
+ };
435
+ setClamp(Number.POSITIVE_INFINITY);
436
+ this.layout();
437
+ // an unknown height on either side keeps the cut
438
+ if (!(availableHeight > 0) || !(this.getAllocatedCanvasHeight() <= availableHeight)) {
439
+ setClamp(DataPoint.PERCENT_CLAMP);
440
+ }
338
441
  }
339
442
  /**
340
443
  * Total column extent (data units) proportional to pixelPerUnit, covering
@@ -837,6 +940,11 @@ export class TimeChart {
837
940
  if (dataModel != null && dataModel.length > 0) {
838
941
  firstRow = dataModel[0];
839
942
  }
943
+ this.varianceOverlaps = 0;
944
+ const parsed = variancesConfig.map((variance) => new VarianceScenario(variance));
945
+ if (this.scenarioSwitch && parsed.filter((variance) => variance.isValid).length > 1) {
946
+ return this.populateSharedVarianceRow(variancesConfig, parsed, dataModel, firstRow);
947
+ }
840
948
  for (const varianceScenario in variancesConfig) {
841
949
  const scenarios = new VarianceScenario(variancesConfig[varianceScenario]);
842
950
  if (scenarios.isValid) {
@@ -866,6 +974,47 @@ export class TimeChart {
866
974
  }
867
975
  return varianceModel;
868
976
  }
977
+ /**
978
+ * One row for several variances over the same reference: each period shows
979
+ * the first variance that has a value there, in the notation of its scenario.
980
+ */
981
+ populateSharedVarianceRow(variancesConfig, parsed, dataModel, firstRow) {
982
+ const varianceModel = [];
983
+ const valid = parsed.map((variance, index) => ({ variance, name: variancesConfig[index] }));
984
+ const candidates = valid.filter((entry) => entry.variance.isValid);
985
+ const isRelative = candidates[0].variance.type === "dr";
986
+ const pixelPerUnit = isRelative ? this.pixelPerPercentage : this.pixelPerUnit;
987
+ dataModel.forEach((row, index) => {
988
+ let point = null;
989
+ let values = 0;
990
+ for (const { variance, name } of candidates) {
991
+ const value = this.calculateVariance(variance, row, this.mapScenarios(variance, firstRow));
992
+ if (value === null || Number.isNaN(value)) {
993
+ continue;
994
+ }
995
+ values++;
996
+ if (point == null) {
997
+ point = new DataPoint(value, variance.delta, pixelPerUnit, variance.direction);
998
+ point.notation = variance.base.slice(0, 2);
999
+ point.key = { date: TimeChart.pointDate(row.date), scenario: name };
1000
+ }
1001
+ }
1002
+ if (values > 1) {
1003
+ this.varianceOverlaps++;
1004
+ }
1005
+ varianceModel.push({
1006
+ id: index,
1007
+ category: row.category,
1008
+ type: isRelative ? VarianceType.RELATIVE : VarianceType.ABSOLUTE,
1009
+ date: row.date,
1010
+ scenario1: point !== null && point !== void 0 ? point : new DataPoint(null, candidates[0].variance.delta, pixelPerUnit, candidates[0].variance.direction),
1011
+ scenario2: new DataPoint(null, null, null, null),
1012
+ scenario3: new DataPoint(null, null, null, null),
1013
+ scenario4: new DataPoint(null, null, null, null),
1014
+ });
1015
+ });
1016
+ return varianceModel;
1017
+ }
869
1018
  calculateVariance(scenarios, element, scenarioMap) {
870
1019
  const scenarioBase = scenarioMap.get(scenarios.base);
871
1020
  const scenarioDelta = scenarioMap.get(scenarios.delta);
@@ -908,6 +1057,11 @@ export class TimeChart {
908
1057
  createDateFactory() {
909
1058
  const factory = new DateStringFactory();
910
1059
  factory.setLocale(this.locale);
1060
+ // a Luxon pattern from the translations, for example ’yy
1061
+ const shortYear = this.i18n.get("date-format-short-year");
1062
+ if (typeof shortYear === "string" && /y/.test(shortYear) && !shortYear.includes("date-format")) {
1063
+ factory.patchDateFormatShort({ year: shortYear });
1064
+ }
911
1065
  return factory;
912
1066
  }
913
1067
  /**
@@ -952,6 +1106,12 @@ export class TimeChart {
952
1106
  if (elements["type"] === VarianceType.RELATIVE) {
953
1107
  isRelative = true;
954
1108
  }
1109
+ // in smart mode a period that starts a year or month carries that part alone, so it is never skipped
1110
+ const carriesBoundary = this.axisLabelsMode === AxisLabelsMode.SMART &&
1111
+ dateStringFactory.isSmartBoundary(elements.date, this.dateInterval);
1112
+ if (index % this.axisLabelsStep !== 0 && !carriesBoundary) {
1113
+ return;
1114
+ }
955
1115
  let datelabel = dateStringFactory.getDateString(elements.date, this.dateInterval);
956
1116
  if (this.axisLabelsMode === AxisLabelsMode.SMART) {
957
1117
  datelabel = dateStringFactory.getSmartDateString(elements.date, this.dateInterval);
@@ -975,6 +1135,7 @@ export class TimeChart {
975
1135
  scenarioType: this.axisScenario,
976
1136
  labelText: this.title,
977
1137
  isRelative: isRelative,
1138
+ titlePosition: this.axisTitlePosition,
978
1139
  }, this.position, axisLabelGroup).draw();
979
1140
  // svg.js's width()/height() getters each default to their own bbox() call,
980
1141
  // so reading both measures the group twice. Measure once.
@@ -983,17 +1144,65 @@ export class TimeChart {
983
1144
  height: axisBox.height,
984
1145
  width: axisBox.width,
985
1146
  };
1147
+ this.drawScenarioSwitch(svgContainer);
1148
+ }
1149
+ /**
1150
+ * A vertical line where the visible scenario of the series changes, and the
1151
+ * scenario names under the category labels. Drawn after the axis is
1152
+ * measured, so it does not change the allocated size by itself.
1153
+ */
1154
+ drawScenarioSwitch(svgContainer) {
1155
+ const runs = this.switchRuns();
1156
+ if (runs.length < 2) {
1157
+ return;
1158
+ }
1159
+ const group = svgContainer.group().id("ScenarioSwitch");
1160
+ const namesHeight = this.switchNamesHeight();
1161
+ const height = this.getAllocatedCanvasHeight();
1162
+ const bottom = namesHeight > 0 ? height - this.styles.padding.bottom : height;
1163
+ const lineWidth = Math.max(1, this.position.spacings.auxiliaryLineWidth);
1164
+ runs.slice(1).forEach((run) => {
1165
+ const x = (this.position.getColumnCenterPositionX(run.from - 1) + this.position.getColumnCenterPositionX(run.from)) / 2;
1166
+ group
1167
+ .line(x, 0, x, bottom)
1168
+ .stroke({ color: this.styles.fontStyles.color || "#000000", width: lineWidth })
1169
+ .addClass("scenario-switch");
1170
+ });
1171
+ if (namesHeight === 0) {
1172
+ return;
1173
+ }
1174
+ runs.forEach((run) => {
1175
+ const center = (this.position.getColumnCenterPositionX(run.from) + this.position.getColumnCenterPositionX(run.to)) / 2;
1176
+ new Label(group, center, bottom - namesHeight, "SWITCH_" + run.scenario, Formatter.translateScenarioLabel(run.scenario, this.i18n), this.styles, HookLocation.Top, HookLocation.Center).forceStringTypeDraw();
1177
+ });
986
1178
  }
987
1179
  drawScenarios(dataModel, svgContainer) {
988
1180
  const columnGroup = svgContainer.group().id("Scenarios");
989
1181
  const scenarioFactory = new ScenarioFactory(this.position, columnGroup, this.scenarioStyles(), dataModel.length, this.i18n);
990
1182
  scenarioFactory.setOverflowConfig(this.overflowConfig);
991
1183
  let hasValidPrim = false;
1184
+ const followers = this.followerSlots();
992
1185
  dataModel.forEach((elements, index) => {
993
- scenarioFactory.createPrimaryBar(elements["scenario1"], index).draw(this.dataFormatDigits, this.measureScale);
994
- scenarioFactory.createSecondaryBar(elements["scenario2"], index).draw();
995
- scenarioFactory.createPrimaryMarker(elements["scenario3"], index).draw();
996
- scenarioFactory.createSecondaryMarker(elements["scenario4"], index).draw();
1186
+ // a follower takes the place of the first scenario: full column with value label, named under the axis
1187
+ const visible = followers.length > 0 ? this.visibleSlot(elements, followers) : "scenario1";
1188
+ if (visible != null && visible !== "scenario1") {
1189
+ scenarioFactory
1190
+ .createPrimaryBar(elements[visible], index, false)
1191
+ .draw(this.dataFormatDigits, this.measureScale);
1192
+ hasValidPrim = true;
1193
+ }
1194
+ else {
1195
+ scenarioFactory.createPrimaryBar(elements["scenario1"], index).draw(this.dataFormatDigits, this.measureScale);
1196
+ }
1197
+ if (visible !== "scenario2") {
1198
+ scenarioFactory.createSecondaryBar(elements["scenario2"], index).draw();
1199
+ }
1200
+ if (visible !== "scenario3") {
1201
+ scenarioFactory.createPrimaryMarker(elements["scenario3"], index).draw();
1202
+ }
1203
+ if (visible !== "scenario4") {
1204
+ scenarioFactory.createSecondaryMarker(elements["scenario4"], index).draw();
1205
+ }
997
1206
  if (elements["scenario1"].isEmpty() === false) {
998
1207
  hasValidPrim = true;
999
1208
  }
@@ -1185,7 +1394,7 @@ export class TimeChart {
1185
1394
  scenarioFactory.setOverflowConfig(this.overflowConfig);
1186
1395
  dataModel.forEach((elements, index) => {
1187
1396
  if (elements["type"] === VarianceType.RELATIVE) {
1188
- scenarioFactory.createRelativeVarianceBar(elements["scenario1"], index).draw();
1397
+ scenarioFactory.createRelativeVarianceBar(elements["scenario1"], index).draw(this.dataFormatDigits);
1189
1398
  }
1190
1399
  else {
1191
1400
  scenarioFactory.createVarianceBar(elements["scenario1"], index).draw(this.dataFormatDigits, this.measureScale);
@@ -13,6 +13,7 @@ export class Axis {
13
13
  this.scenarioType = axis.scenarioType;
14
14
  this.labelText = axis.labelText || null;
15
15
  this.isRelative = axis.isRelative || false;
16
+ this.titlePosition = axis.titlePosition || "left";
16
17
  this.position = position;
17
18
  this.svgGroup = svgParentGroup.group().id(this.ID_AXIS);
18
19
  }
@@ -20,12 +21,19 @@ export class Axis {
20
21
  if (null == text) {
21
22
  text = "";
22
23
  }
24
+ if (this.titlePosition === "right") {
25
+ group
26
+ .text(text)
27
+ .addClass(this.CSS_AXIS_TITLE)
28
+ .move(this.position.getAxisEndPositionX() + this.position.spacings.labelToColumn, this.position.getAxisTitlePositionY(true, this.isRelative));
29
+ return;
30
+ }
23
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
32
  const title = group.text(text).addClass(this.CSS_AXIS_TITLE).attr("text-anchor", "middle");
25
33
  title.move(this.position.getAxisTitlePositionX(group), this.position.getAxisTitlePositionY(true, this.isRelative));
26
34
  }
27
35
  draw() {
28
- if (this.labelText) {
36
+ if (this.labelText && this.titlePosition !== "none") {
29
37
  this.drawAxisTitle(this.svgGroup, this.labelText);
30
38
  }
31
39
  this.svgGroup
@@ -70,16 +70,22 @@ export class Column {
70
70
  return this;
71
71
  }
72
72
  draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
73
- var _a;
73
+ var _a, _b, _c;
74
74
  // TODE: JHE: Remove DataFOrmatDigits Type Duplicates
75
75
  if (this.isEmpty()) {
76
76
  return this;
77
77
  }
78
78
  const scenarioStyle = this.getScenarioStyle();
79
- const strokeStyle = this.convertToSVGStyle(scenarioStyle, "stroke");
80
- const fillStyle = this.getFillStyle(scenarioStyle);
79
+ let strokeStyle = this.convertToSVGStyle(scenarioStyle, "stroke");
80
+ let fillStyle = this.getFillStyle(scenarioStyle);
81
+ if (this.isVarianceColumn && this.dataPoint.notation === "pl") {
82
+ // outlined like a plan column: the colour of the variance on the edge only
83
+ const planWidth = Number((_b = (_a = this.columnBarStyles) === null || _a === void 0 ? void 0 : _a.pl) === null || _b === void 0 ? void 0 : _b.width);
84
+ strokeStyle = { color: (scenarioStyle === null || scenarioStyle === void 0 ? void 0 : scenarioStyle.fill) || this.FALLBACK_COLOUR, width: planWidth > 0 ? planWidth : 1 };
85
+ fillStyle = this.styles.fontStyles.background || "#ffffff";
86
+ }
81
87
  this.scenarioGroup.attr(dataPointAttributes(this.dataPoint.key));
82
- (_a = this.columnGroup) === null || _a === void 0 ? void 0 : _a.attr(dataPointAttributes(this.dataPoint.key, "element"));
88
+ (_c = this.columnGroup) === null || _c === void 0 ? void 0 : _c.attr(dataPointAttributes(this.dataPoint.key, "element"));
83
89
  if (this.columnGroup != null) {
84
90
  if (this.isOverflowing && this.overflowConfig) {
85
91
  this.drawOverdriveBar(fillStyle, strokeStyle);
@@ -54,11 +54,11 @@ export class Needle {
54
54
  (_a = this.dataLabel) === null || _a === void 0 ? void 0 : _a.updateGroup(newGroup);
55
55
  return this;
56
56
  }
57
- draw() {
57
+ draw(dataFormatDigits = { percent: 2, decimal: 1 }) {
58
58
  var _a, _b, _c;
59
59
  if (((_a = this.dataPoint) === null || _a === void 0 ? void 0 : _a.value) === undefined) {
60
60
  // reference 0: the label says "n/a", there is no pin
61
- (_b = this.dataLabel) === null || _b === void 0 ? void 0 : _b.draw();
61
+ (_b = this.dataLabel) === null || _b === void 0 ? void 0 : _b.draw(true, dataFormatDigits);
62
62
  return this;
63
63
  }
64
64
  if (this.isEmpty()) {
@@ -78,6 +78,12 @@ export class Needle {
78
78
  fillStyle = polygonPattern.pattern;
79
79
  }
80
80
  }
81
+ if (this.dataPoint.notation === "pl") {
82
+ // outlined like a plan column: the colour of the variance on the edge only
83
+ strokeStyle.color = (scenarioStyle === null || scenarioStyle === void 0 ? void 0 : scenarioStyle.fill) || strokeStyle.color;
84
+ strokeStyle.width = Math.max(1, Number(strokeStyle.width) || 0);
85
+ fillStyle = this.styles.fontStyles.background || "#ffffff";
86
+ }
81
87
  if (this.dimensions.clipped) {
82
88
  this.createClippedNeedleHead(fillStyle, strokeStyle);
83
89
  }
@@ -90,7 +96,7 @@ export class Needle {
90
96
  .y(this.dimensions.yPos)
91
97
  .fill(fillStyle)
92
98
  .stroke(strokeStyle);
93
- (_c = this.dataLabel) === null || _c === void 0 ? void 0 : _c.draw();
99
+ (_c = this.dataLabel) === null || _c === void 0 ? void 0 : _c.draw(true, dataFormatDigits);
94
100
  }
95
101
  createDimensions(position, dataPoint, index) {
96
102
  if (dataPoint.getScaledPercentUnit() < 0) {
@@ -53,12 +53,12 @@ export class ScenarioFactory {
53
53
  }
54
54
  return new Line(this.position, this.styles, dataPoint, previousDataPoint, index, isPrimaryColumn, columnGroup, lineLabel).updateLabelGroup(labelGroup);
55
55
  }
56
- createPrimaryBar(dataPoint, index) {
56
+ createPrimaryBar(dataPoint, index, withScenarioLabel = true) {
57
57
  const isPrimaryColumn = true;
58
58
  const columnGroup = this.svgGroups.scenario1.group().id("" + index);
59
59
  const labelGroup = this.svgGroups.scenario1Label.group().id("" + index);
60
60
  let columnLabel = null;
61
- if (this.isLastDataPoint(index)) {
61
+ if (withScenarioLabel && this.isLastDataPoint(index)) {
62
62
  columnLabel = `${this.i18n.get(dataPoint.scenario) || dataPoint.scenario}`;
63
63
  }
64
64
  return new Column(this.position, this.styles, dataPoint, index, isPrimaryColumn, columnGroup, columnLabel, this.overflowConfig).updateLabelGroup(labelGroup);
@@ -12,6 +12,8 @@ import { resolveSentiment } from "../../../../utils/model/VarianceScenario";
12
12
  */
13
13
  export class DataPoint {
14
14
  constructor(value, scenario, pixelPerUnit, variance) {
15
+ /** Relative variances beyond this fraction are cut. Infinity when the chart has room for the full pin. */
16
+ this.percentClamp = DataPoint.PERCENT_CLAMP;
15
17
  this.value = value;
16
18
  this.scenario = scenario;
17
19
  this.pixelPerUnit = pixelPerUnit || 1;
@@ -38,7 +40,7 @@ export class DataPoint {
38
40
  return this.value * this.pixelPerUnit;
39
41
  }
40
42
  /**
41
- * Returns the percentage value scaled to pixel height, clipped at +/-145%.
43
+ * Returns the percentage value scaled to pixel height, clipped at +/-145% unless the clamp is lifted.
42
44
  *
43
45
  * Values beyond +/-1.45 (145%) are clamped to prevent extreme bars from
44
46
  * distorting the chart layout. Use {@link isClipped} to check if clipping occurred.
@@ -47,11 +49,11 @@ export class DataPoint {
47
49
  if (this.value == null) {
48
50
  return 0;
49
51
  }
50
- if (this.value > 1.45) {
51
- return 1.45 * this.pixelPerUnit;
52
+ if (this.value > this.percentClamp) {
53
+ return this.percentClamp * this.pixelPerUnit;
52
54
  }
53
- if (this.value < -1.45) {
54
- return -1.45 * this.pixelPerUnit;
55
+ if (this.value < -this.percentClamp) {
56
+ return -this.percentClamp * this.pixelPerUnit;
55
57
  }
56
58
  return this.value * this.pixelPerUnit;
57
59
  }
@@ -82,7 +84,7 @@ export class DataPoint {
82
84
  if (this.value == null) {
83
85
  return false;
84
86
  }
85
- return Math.abs(this.value) > 1.45;
87
+ return Math.abs(this.value) > this.percentClamp;
86
88
  }
87
89
  /** Returns the fixed display value (145) shown on clipped percentage bars. */
88
90
  getClippedValue() {
@@ -94,3 +96,4 @@ export class DataPoint {
94
96
  return (_a = this.scenario) === null || _a === void 0 ? void 0 : _a.slice(0, 2);
95
97
  }
96
98
  }
99
+ DataPoint.PERCENT_CLAMP = 1.45;
@@ -48,6 +48,12 @@ export class TimeChartComponentConfig {
48
48
  this.stackConfig = null;
49
49
  /** When true, line charts extend to the full width of the chart area. */
50
50
  this.lineFullWidth = true;
51
+ /** Print every n-th category label only. */
52
+ this.axisLabelsStep = 1;
53
+ /** One series that changes its scenario along the time axis, see `bn-chart-time`. */
54
+ this.scenarioSwitch = false;
55
+ /** Side of the axis title: left, right or none. */
56
+ this.axisTitlePosition = "left";
51
57
  /** Locale used for date-axis labels and SQL date normalization; set from the bn-context locale. */
52
58
  this.locale = "de";
53
59
  }
@@ -130,6 +136,15 @@ export class TimeChartComponentConfigAdapter {
130
136
  if (CompareUtil.isBoolean(data.lineFullWidth)) {
131
137
  config.lineFullWidth = data.lineFullWidth;
132
138
  }
139
+ if (CompareUtil.isNumber(data.axisLabelsStep) && data.axisLabelsStep >= 1) {
140
+ config.axisLabelsStep = data.axisLabelsStep;
141
+ }
142
+ if (CompareUtil.isBoolean(data.scenarioSwitch)) {
143
+ config.scenarioSwitch = data.scenarioSwitch;
144
+ }
145
+ if (CompareUtil.isString(data.axisTitlePosition)) {
146
+ config.axisTitlePosition = data.axisTitlePosition;
147
+ }
133
148
  if (CompareUtil.isString(data.locale)) {
134
149
  config.locale = data.locale;
135
150
  }