@bino-bi/bn-template-engine 1.0.0-next.61 → 1.0.0-next.63

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 (24) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-ac917d72.entry.js → p-7b74696e.entry.js} +1 -1
  3. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +688 -266
  4. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/collection/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.js +8 -8
  7. package/dist/collection/components/bn-chart-time/bn-chart-time.js +115 -34
  8. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +534 -221
  9. package/dist/collection/components/bn-chart-time/utils/helper/ElementPositions.js +23 -1
  10. package/dist/collection/components/bn-chart-time/utils/model/TimeChartComponentConfig.js +15 -8
  11. package/dist/components/bn-chart-time-renderer.js +1 -1
  12. package/dist/components/bn-chart-time.js +1 -1
  13. package/dist/components/p-C3-kXJUZ.js +1 -0
  14. package/dist/esm/bn-annotation-layer_30.entry.js +688 -266
  15. package/dist/esm/bn-template-engine.js +1 -1
  16. package/dist/esm/loader.js +1 -1
  17. package/dist/types/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.d.ts +2 -2
  18. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +29 -16
  19. package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +63 -30
  20. package/dist/types/components/bn-chart-time/utils/helper/ElementPositions.d.ts +8 -0
  21. package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +16 -7
  22. package/dist/types/components.d.ts +8 -8
  23. package/package.json +1 -1
  24. package/dist/components/p-D-JwLFMJ.js +0 -1
@@ -476,7 +476,7 @@ function matchPoint(state, point) {
476
476
 
477
477
  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}`;
478
478
 
479
- var __rest = (undefined && undefined.__rest) || function (s, e) {
479
+ var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
480
480
  var t = {};
481
481
  for (var p in s)
482
482
  if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -734,7 +734,7 @@ const AnnotationLayer = class {
734
734
  if (!visual || !state || !item.point)
735
735
  return undefined;
736
736
  const host = visual.getBoundingClientRect();
737
- const _a = item.point, series = __rest(_a, ["rowGroup", "category", "subCategory", "date"]);
737
+ const _a = item.point, series = __rest$1(_a, ["rowGroup", "category", "subCategory", "date"]);
738
738
  const bars = matchPoint(state, Object.assign(Object.assign({}, series), { part: "element" })).filter((bar) => bar.value != null);
739
739
  const all = bars.reduce((sum, bar) => sum + bar.value, 0);
740
740
  const inside = bars
@@ -20192,6 +20192,18 @@ function settleHeightBonus(current, measured) {
20192
20192
 
20193
20193
  const bnChartTimeCss = () => `:host(.no-data){display:block;box-sizing:border-box;width:100%;height:100%}:host(.no-data)>div{float:none;width:100%;height:100%}:host(.no-data) .no-data~.no-data{display:none}.empty-state{box-sizing:border-box;display:flex;align-items:center;justify-content:center;float:none;width:100%;height:100%;min-height:3em;margin:0;padding:0.5em;overflow:hidden;border:0.1em dashed #ddd;color:#808080;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);font-style:normal;text-align:center}:host{display:inline-block;position:relative;overflow:hidden;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);color:var(--bn-font-color, #000000)}.container{display:flex;flex-direction:column-reverse}.background-image{display:flex;flex-wrap:wrap;justify-content:flex-end}`;
20194
20194
 
20195
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
20196
+ var t = {};
20197
+ for (var p in s)
20198
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
20199
+ t[p] = s[p];
20200
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
20201
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
20202
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20203
+ t[p[i]] = s[p[i]];
20204
+ }
20205
+ return t;
20206
+ };
20195
20207
  const Chart = class {
20196
20208
  validateFilter(newValue) {
20197
20209
  const errId = "ERR_filter";
@@ -20415,38 +20427,79 @@ const Chart = class {
20415
20427
  this.errors.remove(errId);
20416
20428
  }
20417
20429
  }
20418
- validateTotalColumn(newValue) {
20419
- const errId = "WARN_totalColumn";
20420
- if (isBlankInput(newValue) || this.parseTotalColumn(newValue) != null) {
20430
+ validateTotals(newValue) {
20431
+ const errId = "WARN_totals";
20432
+ if (isBlankInput(newValue) || this.parseTotals(newValue) != null) {
20421
20433
  this.errors.remove(errId);
20422
20434
  }
20423
20435
  else {
20424
20436
  this.errors.addOrReplace({
20425
20437
  id: errId,
20426
20438
  type: "warning",
20427
- message: 'totalColumn: needs JSON with a unitScaling greater than 0, for example {"unitScaling":280}.',
20439
+ message: 'totals: needs JSON with a unitScaling greater than 0, by one of all, year, quarter, month, week, and aggregation one of sum, average, last. For example {"unitScaling":280}.',
20428
20440
  });
20429
20441
  }
20442
+ this.bindTotalsDataset();
20430
20443
  }
20431
- parseTotalColumn(value) {
20444
+ parseTotals(value) {
20445
+ var _a, _b;
20432
20446
  try {
20433
20447
  const parsed = JSON.parse(value);
20434
20448
  // the same values as `unit-scaling`: a number, with an SI suffix, or the name of a scaling group
20435
20449
  const scaling = resolveScalingValue(parsed === null || parsed === void 0 ? void 0 : parsed.unitScaling, this.pixelPerUnitGroupMap);
20436
20450
  if (scaling.kind !== "value" || !(scaling.value > 0))
20437
20451
  return null;
20452
+ const by = (_a = parsed.by) !== null && _a !== void 0 ? _a : "all";
20453
+ const aggregation = (_b = parsed.aggregation) !== null && _b !== void 0 ? _b : "sum";
20454
+ if (!["all", "year", "quarter", "month", "week"].includes(by))
20455
+ return null;
20456
+ if (!["sum", "average", "last"].includes(aggregation))
20457
+ return null;
20438
20458
  const width = Number(parsed.width);
20439
20459
  const label = typeof parsed.label === "string" || typeof parsed.label === "number" ? String(parsed.label) : "";
20440
- return { unitScaling: scaling.value, label, width: width > 0 ? width : 1 };
20460
+ return {
20461
+ unitScaling: scaling.value,
20462
+ by,
20463
+ aggregation,
20464
+ label,
20465
+ width: width > 0 ? width : 1,
20466
+ dataset: typeof parsed.dataset === "string" ? parsed.dataset.trim() : "",
20467
+ };
20441
20468
  }
20442
- catch (_a) {
20469
+ catch (_c) {
20443
20470
  return null;
20444
20471
  }
20445
20472
  }
20446
- /** The total column in the units of the inner chart: pixels for one data unit. */
20447
- prepareTotalColumn() {
20448
- const parsed = isBlankInput(this.totalColumn) ? null : this.parseTotalColumn(this.totalColumn);
20449
- const errId = "WARN_totalColumn_unitScaling";
20473
+ /** Draws the chart again when the dataset of the totals gets its rows. */
20474
+ bindTotalsDataset() {
20475
+ var _a, _b;
20476
+ // from the plain JSON: the name does not depend on a scaling group that may get its value later
20477
+ let name;
20478
+ try {
20479
+ const dataset = isBlankInput(this.totals) ? "" : (_a = JSON.parse(this.totals)) === null || _a === void 0 ? void 0 : _a.dataset;
20480
+ name = typeof dataset === "string" ? dataset.trim() : "";
20481
+ }
20482
+ catch (_c) {
20483
+ name = "";
20484
+ }
20485
+ // an element that is not in the page has no subscription: it binds when it connects
20486
+ if (!this.element.isConnected)
20487
+ return;
20488
+ if (name === this.totalsDatasetName)
20489
+ return;
20490
+ (_b = this.totalsDatasetUnsubscribe) === null || _b === void 0 ? void 0 : _b.call(this);
20491
+ this.totalsDatasetUnsubscribe = null;
20492
+ this.totalsDatasetName = name;
20493
+ if (name) {
20494
+ this.totalsDatasetUnsubscribe = getStores(this.element).db.subscribe(name, () => {
20495
+ this.dataVersion++;
20496
+ });
20497
+ }
20498
+ }
20499
+ /** The totals in the units of the inner chart: pixels for one data unit. */
20500
+ prepareTotals() {
20501
+ const parsed = isBlankInput(this.totals) ? null : this.parseTotals(this.totals);
20502
+ const errId = "WARN_totals_unitScaling";
20450
20503
  if (parsed == null) {
20451
20504
  this.errors.remove(errId);
20452
20505
  return null;
@@ -20456,12 +20509,22 @@ const Chart = class {
20456
20509
  this.errors.addOrReplace({
20457
20510
  id: errId,
20458
20511
  type: "warning",
20459
- message: "totalColumn: needs a fixed unitScaling of the chart, the total column is not drawn.",
20512
+ message: "totals: needs a fixed unitScaling of the chart, the total columns are not drawn.",
20513
+ });
20514
+ return null;
20515
+ }
20516
+ // without the columns each variance row would decide on its own which periods have a total
20517
+ if (this.hidesScenarios()) {
20518
+ this.errors.addOrReplace({
20519
+ id: errId,
20520
+ type: "warning",
20521
+ message: "totals: needs the columns of the chart, a chart with scenarios none draws no total columns.",
20460
20522
  });
20461
20523
  return null;
20462
20524
  }
20463
20525
  this.errors.remove(errId);
20464
- return { pixelPerUnit: this.getEffectiveFontPx() / parsed.unitScaling, label: parsed.label, width: parsed.width };
20526
+ const { unitScaling } = parsed, rest = __rest(parsed, ["unitScaling"]);
20527
+ return Object.assign(Object.assign({}, rest), { pixelPerUnit: this.getEffectiveFontPx() / unitScaling });
20465
20528
  }
20466
20529
  validateAxisLabelsStep(newValue) {
20467
20530
  const errId = "WARN_axisLabelsStep";
@@ -20665,22 +20728,32 @@ const Chart = class {
20665
20728
  */
20666
20729
  this.axisLabelsStep = 1;
20667
20730
  /**
20668
- * A column right of the last period for the total of all periods, at its own
20669
- * scale, as JSON: `{"unitScaling":280,"label":"2025","width":1.6}`.
20731
+ * Total columns at their own scale, as JSON:
20732
+ * `{"by":"all","aggregation":"sum","unitScaling":280,"label":"2025","width":1.6}`.
20670
20733
  *
20671
20734
  * - `unitScaling` - data units per em of column height, like `unit-scaling`. Required.
20672
- * - `label` - text under the column.
20735
+ * - `by` - what a total covers. `all` (default): one column right of the last
20736
+ * period for all periods. `year`, `quarter`, `month`, `week`: one column
20737
+ * behind the periods of each of them, on the axis.
20738
+ * - `aggregation` - `sum` (default), `average` or `last`. With `sum` a column
20739
+ * stacks one part per scenario of the series: the first scenario, and with
20740
+ * `scenario-switch` the ones that follow it. Else it is one column, hatched
20741
+ * when a forecast is in its value and outlined for a plan.
20742
+ * - `dataset` - name of a dataset with one row per total (`date` and the
20743
+ * scenario columns). The chart takes the values from it and computes none.
20744
+ * - `label` - text under the column of `by: all`. The other columns take the name of their period.
20673
20745
  * - `width` - width in widths of a period column, default 1.
20674
20746
  *
20675
- * The column stacks one part per scenario of the series: the first scenario,
20676
- * and with `scenario-switch` the ones that follow it. The first other
20677
- * scenario is the reference behind it. Each variance row gets the variance
20678
- * of the totals at the scale of the row. With `scaling-indicator` the column
20679
- * has its own band, and a line links the two bands. Plain columns only: not
20680
- * with `stack` and not in line mode. The chart needs a fixed `unit-scaling`,
20681
- * and every part of the total must be positive.
20747
+ * The first other scenario is the reference behind a column. Each variance
20748
+ * row gets the variance of each total at the scale of the row. With
20749
+ * `scaling-indicator` a column has its own band, and with `by: all` a line
20750
+ * links it to the band of the periods. Plain columns only: not with `stack`
20751
+ * and not in line mode. The chart needs a fixed `unit-scaling`, and every
20752
+ * part of a total must be positive.
20682
20753
  */
20683
- this.totalColumn = "";
20754
+ this.totals = "";
20755
+ this.totalsDatasetUnsubscribe = null;
20756
+ this.totalsDatasetName = "";
20684
20757
  /**
20685
20758
  * For a series that changes its scenario along the time axis, for example
20686
20759
  * AC up to this year and PL after it. In a period where the first scenario
@@ -20785,7 +20858,7 @@ const Chart = class {
20785
20858
  this.validateDataFormatDigitsDecimal(this.dataFormatDigitsDecimal);
20786
20859
  this.validateDataFormatDigitsPercent(this.dataFormatDigitsPercent);
20787
20860
  this.validateAxisLabelsStep(this.axisLabelsStep);
20788
- this.validateTotalColumn(this.totalColumn);
20861
+ this.validateTotals(this.totals);
20789
20862
  this.validateAxisTitlePosition(this.axisTitlePosition);
20790
20863
  }
20791
20864
  /**
@@ -20996,9 +21069,16 @@ const Chart = class {
20996
21069
  };
20997
21070
  this._settleTimer = setTimeout(check, delays.shift());
20998
21071
  }
21072
+ connectedCallback() {
21073
+ // an element that is moved in the page comes back without its subscription
21074
+ this.bindTotalsDataset();
21075
+ }
20999
21076
  disconnectedCallback() {
21000
- var _a;
21001
- (_a = this.layoutObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
21077
+ var _a, _b;
21078
+ (_a = this.totalsDatasetUnsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
21079
+ this.totalsDatasetUnsubscribe = null;
21080
+ this.totalsDatasetName = "";
21081
+ (_b = this.layoutObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
21002
21082
  this.layoutObserver = null;
21003
21083
  if (this._settleTimer != null) {
21004
21084
  clearTimeout(this._settleTimer);
@@ -21451,7 +21531,7 @@ const Chart = class {
21451
21531
  percent: this.dataFormatDigitsPercent,
21452
21532
  decimal: this.dataFormatDigitsDecimal,
21453
21533
  percentSign: this.dataFormatPercentSign !== false,
21454
- }, axisLabelsStep: Math.max(1, Math.floor(Number(this.axisLabelsStep) || 1)), scalingIndicator: Number(this.scalingIndicator) || 0, totalColumn: this.prepareTotalColumn(), scenarioSwitch: this.scenarioSwitch, axisTitlePosition: this.prepareAxisTitlePosition(), containerWidth: fullParentWidth, parentDimensions: this.prepareDimension(isBase), ruleSetConfig: this.ruleSetConfig() }));
21534
+ }, axisLabelsStep: Math.max(1, Math.floor(Number(this.axisLabelsStep) || 1)), scalingIndicator: Number(this.scalingIndicator) || 0, totals: this.prepareTotals(), scenarioSwitch: this.scenarioSwitch, axisTitlePosition: this.prepareAxisTitlePosition(), containerWidth: fullParentWidth, parentDimensions: this.prepareDimension(isBase), ruleSetConfig: this.ruleSetConfig() }));
21455
21535
  }
21456
21536
  /**
21457
21537
  * The line this chart wants to be aligned on, in CSS px from the host's
@@ -21583,7 +21663,7 @@ const Chart = class {
21583
21663
  this.errors.remove("WARN_scenarios_none");
21584
21664
  }
21585
21665
  const fontStyles = this.getFontStyles();
21586
- return (h(Host, { key: 'c54e501bbea51b366b8a07e578b6cdecec662477', style: fontStyles }, h("div", { key: 'c232324e6c09f86881f60b5af9e84d4a80e49bd2', class: "container" }, segments.map(this.chartTemplate))));
21666
+ return (h(Host, { key: '1b6a2c72252e0f0c437815ea71652bc6ca7bb90c', style: fontStyles }, h("div", { key: '1df2b96475b83b11c197a00efed98b2e60a05ed9', class: "container" }, segments.map(this.chartTemplate))));
21587
21667
  }
21588
21668
  get element() { return getElement(this); }
21589
21669
  static get watchers() { return {
@@ -21632,8 +21712,8 @@ const Chart = class {
21632
21712
  "dataFormatDigitsPercent": [{
21633
21713
  "validateDataFormatDigitsPercent": 0
21634
21714
  }],
21635
- "totalColumn": [{
21636
- "validateTotalColumn": 0
21715
+ "totals": [{
21716
+ "validateTotals": 0
21637
21717
  }],
21638
21718
  "axisLabelsStep": [{
21639
21719
  "validateAxisLabelsStep": 0
@@ -21769,6 +21849,11 @@ class ElementPositions {
21769
21849
  width: 0,
21770
21850
  height: 0,
21771
21851
  };
21852
+ /**
21853
+ * Places on the axis in category widths, by index: the periods first, then
21854
+ * the total columns. Without it the place of an index is the index itself.
21855
+ */
21856
+ this.slots = null;
21772
21857
  this.padding = padding;
21773
21858
  this.scaleFactors = scaleFactors;
21774
21859
  this.fontStlye = fontstyle;
@@ -21792,10 +21877,27 @@ class ElementPositions {
21792
21877
  }).height;
21793
21878
  return height * 1.1;
21794
21879
  }
21880
+ setSlots(slots) {
21881
+ this.slots = slots;
21882
+ }
21883
+ /** The place of an index on the axis, in category widths. Between two indexes it lies between their places. */
21884
+ slotOf(index) {
21885
+ const slots = this.slots;
21886
+ if (slots == null || slots.length === 0) {
21887
+ return index;
21888
+ }
21889
+ const last = slots.length - 1;
21890
+ if (index <= 0)
21891
+ return slots[0] + index;
21892
+ if (index >= last)
21893
+ return slots[last] + (index - last);
21894
+ const low = Math.floor(index);
21895
+ return slots[low] + (slots[low + 1] - slots[low]) * (index - low);
21896
+ }
21795
21897
  getColumnCenterPositionX(index) {
21796
21898
  return (this.categoryPosition.y +
21797
21899
  this.spacings.scenarioOffset +
21798
- index * this.spacings.categoryWidth +
21900
+ this.slotOf(index) * this.spacings.categoryWidth +
21799
21901
  this.leftSideLabelLength +
21800
21902
  this.spacings.columnWidth * 0.5);
21801
21903
  }
@@ -23968,8 +24070,9 @@ class TimeChart {
23968
24070
  this.lastScenarios = [];
23969
24071
  this.axisLabelsStep = 1;
23970
24072
  this.scalingIndicator = 0;
23971
- this.totalColumn = null;
23972
- this.totalVariance = null;
24073
+ this.totals = null;
24074
+ this.totalColumns = [];
24075
+ this.totalVariances = [];
23973
24076
  this.highestColumnDataPointValue = new DataPoint(0, "default", 0, Scenario.NEU);
23974
24077
  this.highestPeriodVarianceDataPointValue = new DataPoint(0, "default", 0, Scenario.NEU);
23975
24078
  this.scenarioSwitch = false;
@@ -24072,7 +24175,7 @@ class TimeChart {
24072
24175
  this.intervalSpanLimit = config.intervalSpanLimit;
24073
24176
  this.axisLabelsStep = (_a = config.axisLabelsStep) !== null && _a !== void 0 ? _a : 1;
24074
24177
  this.scalingIndicator = (_b = config.scalingIndicator) !== null && _b !== void 0 ? _b : 0;
24075
- this.totalColumn = (_c = config.totalColumn) !== null && _c !== void 0 ? _c : null;
24178
+ this.totals = (_c = config.totals) !== null && _c !== void 0 ? _c : null;
24076
24179
  this.scenarioSwitch = (_d = config.scenarioSwitch) !== null && _d !== void 0 ? _d : false;
24077
24180
  this.axisTitlePosition = (_e = config.axisTitlePosition) !== null && _e !== void 0 ? _e : "left";
24078
24181
  this.dateInterval = this.findDateInterval(config.dateInterval);
@@ -24124,13 +24227,16 @@ class TimeChart {
24124
24227
  this.highestColumnDataPointValue = this.highestDataPointValue;
24125
24228
  // the highest period variance: a break mark is for a variance of a period, the total has its own cut
24126
24229
  this.highestPeriodVarianceDataPointValue = this.highestVarianceDataPointValue;
24127
- this.totalVariance = this.totalVariancePoint();
24128
- if (this.totalVariance != null && Number.isFinite(this.totalVariance.value)) {
24129
- if (this.totalVariance.value > Number(this.highestVarianceDataPointValue.value)) {
24130
- this.highestVarianceDataPointValue = this.totalVariance;
24230
+ this.totalColumns = this.computeTotalColumns();
24231
+ this.totalVariances = this.computeTotalVariances();
24232
+ for (const point of this.totalVariances) {
24233
+ if (point == null || !Number.isFinite(point.value))
24234
+ continue;
24235
+ if (point.value > Number(this.highestVarianceDataPointValue.value)) {
24236
+ this.highestVarianceDataPointValue = point;
24131
24237
  }
24132
- if (this.totalVariance.value < Number(this.smallestVarianceDataPointValue.value)) {
24133
- this.smallestVarianceDataPointValue = this.totalVariance;
24238
+ if (point.value < Number(this.smallestVarianceDataPointValue.value)) {
24239
+ this.smallestVarianceDataPointValue = point;
24134
24240
  }
24135
24241
  }
24136
24242
  if (this.hasScalingIndicator() && this.scalingIndicator > Number(this.highestDataPointValue.value)) {
@@ -24139,7 +24245,7 @@ class TimeChart {
24139
24245
  this.highestDataPointValue = new DataPoint(this.scalingIndicator, scenario, this.pixelPerUnit, variance);
24140
24246
  }
24141
24247
  // the total column has its own scale: it counts for the height with the pixels it needs
24142
- const totalHeight = this.isVarianceChart() ? 0 : this.totalColumnHeight();
24248
+ const totalHeight = this.isVarianceChart() ? 0 : this.totalsHeight();
24143
24249
  if (totalHeight > this.highestDataPointValue.getScaledUnit() && this.pixelPerUnit > 0) {
24144
24250
  const { scenario, variance } = this.highestDataPointValue;
24145
24251
  this.highestDataPointValue = new DataPoint(totalHeight / this.pixelPerUnit, scenario, this.pixelPerUnit, variance);
@@ -24259,8 +24365,8 @@ class TimeChart {
24259
24365
  }).width;
24260
24366
  indicatorEnd = this.scalingIndicatorLabelX() + textWidth + this.styles.padding.right;
24261
24367
  }
24262
- const totalEnd = this.hasTotalColumn()
24263
- ? this.totalColumnGeometry().right + this.totalColumnTextWidth() + this.styles.padding.right
24368
+ const totalEnd = this.hasEndTotal()
24369
+ ? this.totalGeometry(0).right + this.endTotalTextWidth() + this.styles.padding.right
24264
24370
  : 0;
24265
24371
  return Math.max(axisEnd + labelBuffer, bboxTotal, titleEnd, legendEnd, indicatorEnd, totalEnd);
24266
24372
  }
@@ -24500,9 +24606,9 @@ class TimeChart {
24500
24606
  const points = this.variancesDataModel
24501
24607
  .filter((entry) => entry.type === VarianceType.RELATIVE)
24502
24608
  .map((entry) => entry.scenario1);
24503
- if (points.length > 0 && this.totalVariance != null) {
24504
- // the pin of the total column is one of the row
24505
- points.push(this.totalVariance);
24609
+ if (points.length > 0) {
24610
+ // the pins of the total columns are pins of the row
24611
+ points.push(...this.totalVariances.filter((point) => point != null));
24506
24612
  }
24507
24613
  if (points.length === 0 || !points.some((point) => point.isClipped())) {
24508
24614
  return;
@@ -24602,8 +24708,9 @@ class TimeChart {
24602
24708
  }
24603
24709
  if (this.isVarianceChart()) {
24604
24710
  this.drawVarianceScenario(this.variancesDataModel, svgContainer);
24711
+ // before the axis: the line of a scenario switch runs over the full height of the row
24712
+ this.drawTotalVariances(svgContainer);
24605
24713
  this.drawAxisAndLabels(this.variancesDataModel, svgContainer);
24606
- this.drawTotalVariance(svgContainer);
24607
24714
  }
24608
24715
  else if (this.stackConfig != null) {
24609
24716
  const effectiveChartMode = this.determineEffectiveChartMode();
@@ -24629,17 +24736,19 @@ class TimeChart {
24629
24736
  this.drawOverlayLayer(this.dataModel, svgContainer);
24630
24737
  this.drawAxisAndLabels(this.dataModel, svgContainer);
24631
24738
  this.drawScalingIndicator(svgContainer);
24632
- this.drawTotalColumn(svgContainer);
24739
+ this.drawTotalColumns(svgContainer);
24633
24740
  }
24634
24741
  }
24635
24742
  }
24636
24743
  /** True for a chart that draws the scaling indicator: columns or an absolute stack, no variance chart. */
24637
24744
  hasScalingIndicator() {
24638
- var _a;
24745
+ var _a, _b;
24639
24746
  return (this.scalingIndicator > 0 &&
24640
24747
  !this.isVarianceChart() &&
24748
+ // the segment of a variance that is not valid has no variance model, but it is no base chart
24749
+ ((_a = this.configVariances) !== null && _a !== void 0 ? _a : []).every((variance) => !variance) &&
24641
24750
  this.determineEffectiveChartMode() === ChartMode.BAR &&
24642
- ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) !== StackMode.RELATIVE);
24751
+ ((_b = this.stackConfig) === null || _b === void 0 ? void 0 : _b.mode) !== StackMode.RELATIVE);
24643
24752
  }
24644
24753
  /** The value of the scaling indicator, printed like a value label. */
24645
24754
  scalingIndicatorText() {
@@ -24657,7 +24766,11 @@ class TimeChart {
24657
24766
  scalingIndicatorLabelX() {
24658
24767
  const gap = this.position.spacings.labelToColumn;
24659
24768
  const half = this.position.getColumnWidth() / 2 + this.position.spacings.scenarioOffset;
24660
- const right = this.position.getColumnCenterPositionX(Math.max(0, this.dataModel.length - 1)) + half;
24769
+ let right = this.position.getColumnCenterPositionX(Math.max(0, this.dataModel.length - 1)) + half;
24770
+ if (this.hasTotals() && !this.hasEndTotal()) {
24771
+ // a total stands behind the last period: the value goes behind it
24772
+ right = Math.max(right, this.totalGeometry(this.totalColumns.length - 1).right);
24773
+ }
24661
24774
  const legendWidth = this.legendWidth("right");
24662
24775
  return right + gap + (legendWidth > 0 ? legendWidth + gap : 0);
24663
24776
  }
@@ -24690,154 +24803,431 @@ class TimeChart {
24690
24803
  const { left, right, height } = band;
24691
24804
  const axisY = this.position.getColumnPositionY();
24692
24805
  const group = svgContainer.group().id("ScalingIndicator");
24693
- group
24694
- .rect(right - left, height)
24695
- .x(left)
24696
- .y(axisY - height)
24697
- .fill(SCALING_INDICATOR_FILL);
24806
+ // totals on the axis have their own band at their own scale: the band of the periods leaves their place free
24807
+ const half = this.position.getColumnWidth() / 2 + this.position.spacings.scenarioOffset;
24808
+ const runs = this.hasTotals() && !this.hasEndTotal()
24809
+ ? this.totalRuns().map((run) => ({
24810
+ left: this.position.getColumnCenterPositionX(run.from) - half,
24811
+ right: this.position.getColumnCenterPositionX(run.to) + half,
24812
+ }))
24813
+ : [{ left, right }];
24814
+ for (const run of runs) {
24815
+ group
24816
+ .rect(run.right - run.left, height)
24817
+ .x(run.left)
24818
+ .y(axisY - height)
24819
+ .fill(SCALING_INDICATOR_FILL);
24820
+ }
24698
24821
  group.back();
24699
24822
  new Label$1(svgContainer.group().id("ScalingIndicatorLabel"), this.scalingIndicatorLabelX(), axisY - height, "SCALING_INDICATOR", this.scalingIndicatorText(), this.styles, HookLocation$1.Center, HookLocation$1.Left).forceStringTypeDraw();
24700
24823
  }
24701
- /** Where a title at the right starts when a total column stands there: behind the column and its texts. */
24824
+ /** Where a title at the right starts when a total column stands at the end: behind the column and its texts. */
24702
24825
  rightTitleX() {
24703
- if (!this.hasTotalColumn()) {
24826
+ if (!this.hasEndTotal()) {
24704
24827
  return undefined;
24705
24828
  }
24706
- return this.totalColumnGeometry().right + this.totalColumnTextWidth() + this.position.spacings.labelToColumn;
24829
+ return this.totalGeometry(0).right + this.endTotalTextWidth() + this.position.spacings.labelToColumn;
24830
+ }
24831
+ /** True for a chart with total columns. */
24832
+ hasTotals() {
24833
+ return this.totalColumns.length > 0;
24834
+ }
24835
+ /** True for the one total column of `by: all`: it stands apart at the end, with its own axis and its names. */
24836
+ hasEndTotal() {
24837
+ return this.hasTotals() && this.totals.by === "all";
24707
24838
  }
24708
- /** True for a chart with a total column: plain columns, no stack, no line. */
24709
- hasTotalColumn() {
24710
- return this.totalColumnParts() != null;
24839
+ /** The index of a total column for the positions: the totals follow the periods. */
24840
+ totalIndex(total) {
24841
+ // the index behind the last period stays what it is without totals: the end of the overlay lines
24842
+ return this.dataModel.length + 1 + total;
24711
24843
  }
24712
- /** Place of the total column: right of the last period, with a gap. `left` and `right` are the ends of its axis. */
24713
- totalColumnGeometry() {
24844
+ /** Place of a total column. `left` and `right` are the ends of its band, and of its own axis at the end. */
24845
+ totalGeometry(total) {
24714
24846
  var _a, _b;
24715
- const columnWidth = this.position.getColumnWidth();
24716
- const width = columnWidth * ((_b = (_a = this.totalColumn) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 1);
24717
- // one period of room between the last period and the column: the axis of the periods ends before it
24718
- const center = this.position.getColumnCenterPositionX(this.dataModel.length + 1) + (width - columnWidth) / 2;
24847
+ const width = this.position.getColumnWidth() * ((_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 1);
24848
+ const center = this.position.getColumnCenterPositionX(this.totalIndex(total));
24719
24849
  const margin = this.position.spacings.scenarioOffset;
24720
- // the value of the band of the periods stands in the gap: the column moves right by its width.
24721
- // Every tier of the chart knows the indicator, so the column has the same place in all of them.
24722
- const x = center + (this.scalingIndicator > 0 ? this.scalingIndicatorTextWidth() + margin : 0);
24723
- return { center: x, width, left: x - width / 2 - 2 * margin, right: x + width / 2 + margin };
24850
+ return { center, width, left: center - width / 2 - 2 * margin, right: center + width / 2 + margin };
24724
24851
  }
24725
24852
  /**
24726
- * What the total column of the base chart shows: one part per scenario of the
24727
- * series (the first scenario and the ones that follow it), from the sum of its
24728
- * periods, and the sum of the first other scenario as the reference behind.
24729
- * The variance rows read it too, for the same answer to "is there a total
24730
- * column". Null without one, and when a part is not positive: a stack cannot
24731
- * show a negative part, so such a chart has no total column at all.
24853
+ * The places of the periods and of the total columns on the axis, in category
24854
+ * widths, and the number of places the axis of the periods covers. A total of
24855
+ * `by: all` stands one period behind the last one, with its own axis. The
24856
+ * other totals stand right behind the last period of their group, and the
24857
+ * periods after them move on.
24732
24858
  */
24733
- totalColumnParts() {
24734
- var _a;
24735
- if (this.totalColumn == null ||
24736
- this.stackConfig != null ||
24737
- this.dataModel.length === 0 ||
24738
- this.determineEffectiveChartMode() !== ChartMode.BAR) {
24739
- return null;
24859
+ totalSlots(columnWidth, categoryWidth, fontSize, scenarioOffset) {
24860
+ var _a, _b, _c;
24861
+ const count = this.dataModel.length;
24862
+ const extra = categoryWidth > 0 ? ((((_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 1) - 1) * columnWidth) / categoryWidth : 0;
24863
+ const slots = [];
24864
+ const totals = [];
24865
+ if (this.totals.by === "all") {
24866
+ for (let index = 0; index < count; index++)
24867
+ slots.push(index);
24868
+ // the value of the band of the periods stands in the gap: the column moves right by its width.
24869
+ // Every tier of the chart knows the indicator, so the column has the same place in all of them.
24870
+ const shift = this.scalingIndicator > 0 && categoryWidth > 0
24871
+ ? (this.scalingIndicatorTextWidth() + scenarioOffset * fontSize) / (categoryWidth * fontSize)
24872
+ : 0;
24873
+ totals.push(count + 1 + extra / 2 + shift);
24874
+ return { slots: [...slots, count, ...totals], axisColumns: count };
24740
24875
  }
24876
+ // the names of the scenarios stand right of the last period: its total keeps one place of room for them.
24877
+ // A series with a scenario switch has its names under the axis.
24741
24878
  const followers = this.followerSlots();
24742
- const sums = new Map();
24743
- for (const row of this.dataModel) {
24744
- const slot = this.visibleSlot(row, followers);
24745
- const point = slot ? row[slot] : null;
24746
- if (slot == null || !Number.isFinite(point === null || point === void 0 ? void 0 : point.value))
24747
- continue;
24748
- const sum = (_a = sums.get(slot)) !== null && _a !== void 0 ? _a : { scenario: point.scenario, value: 0 };
24749
- sum.value += point.value;
24750
- sums.set(slot, sum);
24879
+ const lastRow = this.dataModel[count - 1];
24880
+ const lastIsFollower = followers.includes((_c = this.visibleSlot(lastRow, followers)) !== null && _c !== void 0 ? _c : "scenario1");
24881
+ // the second marker prints its name there too
24882
+ const markerName = !followers.includes("scenario4") && this.dataModel.some((row) => TimeChart.hasValue(row.scenario4));
24883
+ const namesRoom = lastIsFollower && !markerName ? 0 : 1;
24884
+ let offset = 0;
24885
+ let next = 0;
24886
+ for (let index = 0; index < count; index++) {
24887
+ slots.push(index + offset);
24888
+ const group = this.totalColumns[next];
24889
+ if (group != null && group.to === index) {
24890
+ const room = index === count - 1 ? namesRoom : 0;
24891
+ totals.push(index + offset + room + 1 + extra / 2);
24892
+ offset += room + 1 + extra;
24893
+ next++;
24894
+ }
24895
+ }
24896
+ return { slots: [...slots, count + offset, ...totals], axisColumns: count + offset };
24897
+ }
24898
+ /** The runs of periods between the total columns on the axis: each ends with the last period of a total, or of the chart. */
24899
+ totalRuns() {
24900
+ const runs = [];
24901
+ let from = 0;
24902
+ for (const column of this.totalColumns) {
24903
+ runs.push({ from, to: column.to });
24904
+ from = column.to + 1;
24905
+ }
24906
+ if (from < this.dataModel.length) {
24907
+ runs.push({ from, to: this.dataModel.length - 1 });
24751
24908
  }
24752
- const parts = [...sums.values()];
24753
- if (parts.length === 0 || parts.some((part) => !(part.value > 0))) {
24909
+ return runs;
24910
+ }
24911
+ /** The start of the group of a date, null for one group over all periods. */
24912
+ totalGroupStart(date) {
24913
+ var _a, _b;
24914
+ const by = (_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.by) !== null && _b !== void 0 ? _b : "all";
24915
+ if (by === "all" || date == null || !date.isValid) {
24754
24916
  return null;
24755
24917
  }
24756
- let reference = null;
24918
+ return date.startOf(by);
24919
+ }
24920
+ /** The name of a total column under the axis: the text of the config at the end, else the name of its period. */
24921
+ totalLabel(start) {
24922
+ var _a, _b;
24923
+ if (start == null) {
24924
+ return (_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : "";
24925
+ }
24926
+ const interval = {
24927
+ year: DateDistance.YEAR,
24928
+ quarter: DateDistance.QUARTER,
24929
+ month: DateDistance.MONTH,
24930
+ week: DateDistance.WEEK,
24931
+ }[this.totals.by];
24932
+ return this.createDateFactory().getShortDateString(start, interval);
24933
+ }
24934
+ /** The scenarios of the series: the first one, and the ones that follow it. */
24935
+ seriesSlotKeys() {
24936
+ return ["scenario1", ...this.followerSlots()];
24937
+ }
24938
+ /** The slot of the reference of a total: the first scenario with values that is not part of the series. */
24939
+ referenceSlot() {
24940
+ const followers = this.followerSlots();
24757
24941
  for (const slot of ["scenario2", "scenario3", "scenario4"]) {
24758
24942
  if (followers.includes(slot))
24759
24943
  continue;
24760
- const values = this.dataModel.map((row) => row[slot]).filter((point) => Number.isFinite(point === null || point === void 0 ? void 0 : point.value));
24761
- if (values.length > 0) {
24762
- reference = {
24763
- scenario: values[0].scenario,
24764
- value: values.reduce((sum, point) => sum + point.value, 0),
24765
- };
24766
- break;
24944
+ if (this.dataModel.some((row) => { var _a; return Number.isFinite((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.value); })) {
24945
+ return slot;
24767
24946
  }
24768
24947
  }
24769
- return {
24770
- parts,
24771
- height: parts.reduce((sum, part) => sum + part.value, 0),
24772
- total: parts.reduce((sum, part) => sum + part.value, 0),
24773
- reference,
24774
- };
24948
+ return null;
24775
24949
  }
24776
- /** Height of the total column in pixels: its parts, its reference and its band of the scaling indicator. 0 without one. */
24777
- totalColumnHeight() {
24950
+ /** The look of one column for several scenarios: a forecast wins, then a plan, then the first one. */
24951
+ mixedScenario(scenarios) {
24778
24952
  var _a, _b;
24779
- const total = this.totalColumnParts();
24780
- if (total == null) {
24953
+ return ((_b = (_a = scenarios.find((scenario) => getScenarioPrefix(scenario) === "fc")) !== null && _a !== void 0 ? _a : scenarios.find((scenario) => getScenarioPrefix(scenario) === "pl")) !== null && _b !== void 0 ? _b : scenarios[0]);
24954
+ }
24955
+ /** The rows of the totals dataset, one per group, with the scenario columns added up. */
24956
+ totalDatasetRows() {
24957
+ var _a, _b, _c, _d;
24958
+ const name = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.dataset;
24959
+ if (!name) {
24960
+ return null;
24961
+ }
24962
+ const from = sourceExpr(this.db, name, "");
24963
+ const rows = new Map();
24964
+ if (!from) {
24965
+ return rows;
24966
+ }
24967
+ let result;
24968
+ try {
24969
+ result = this.db.exec(`SELECT * FROM ${from}`);
24970
+ }
24971
+ catch (e) {
24972
+ this.failQuery(e);
24973
+ return rows;
24974
+ }
24975
+ for (const row of result) {
24976
+ const date = TimeChart.parseDate(row.date);
24977
+ const start = date ? this.totalGroupStart(date) : null;
24978
+ const key = start ? ((_b = start.toISODate()) !== null && _b !== void 0 ? _b : "") : "";
24979
+ if (this.totals.by !== "all" && key === "")
24980
+ continue;
24981
+ const sums = (_c = rows.get(key)) !== null && _c !== void 0 ? _c : {};
24982
+ for (const [column, raw] of Object.entries(row)) {
24983
+ // a value can come as a text, like in the dataset of the chart
24984
+ const value = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
24985
+ if (column !== "date" && typeof value === "number" && Number.isFinite(value)) {
24986
+ sums[column] = ((_d = sums[column]) !== null && _d !== void 0 ? _d : 0) + value;
24987
+ }
24988
+ }
24989
+ rows.set(key, sums);
24990
+ }
24991
+ return rows;
24992
+ }
24993
+ static parseDate(value) {
24994
+ if (value instanceof Date) {
24995
+ return DateTime.fromJSDate(value, { zone: "utc" });
24996
+ }
24997
+ if (typeof value === "string") {
24998
+ const date = DateTime.fromISO(value, { zone: "utc" });
24999
+ return date.isValid ? date : null;
25000
+ }
25001
+ if (typeof value === "number") {
25002
+ return DateTime.fromMillis(value, { zone: "utc" });
25003
+ }
25004
+ return null;
25005
+ }
25006
+ /**
25007
+ * The total columns of the chart. A group is the run of periods of one year,
25008
+ * quarter, month or week, or all periods. With `sum` a column stacks one part
25009
+ * per scenario of the series, else it is one column in the look of the
25010
+ * scenarios in it. The first other scenario is the reference behind. The
25011
+ * variance rows read the same list, for the same answer to "are there
25012
+ * totals". Empty without the config, with a stack, in line mode, and when a
25013
+ * part is not positive: a column cannot show that, so the chart has none.
25014
+ */
25015
+ computeTotalColumns() {
25016
+ var _a, _b, _c, _d, _e;
25017
+ if (this.totals == null ||
25018
+ this.stackConfig != null ||
25019
+ this.dataModel.length === 0 ||
25020
+ this.determineEffectiveChartMode() !== ChartMode.BAR) {
25021
+ return [];
25022
+ }
25023
+ const followers = this.followerSlots();
25024
+ const series = this.seriesSlotKeys();
25025
+ const referenceSlot = this.referenceSlot();
25026
+ const referenceScenario = referenceSlot
25027
+ ? (_a = this.dataModel.find((row) => { var _a; return ((_a = row[referenceSlot]) === null || _a === void 0 ? void 0 : _a.scenario) != null; })) === null || _a === void 0 ? void 0 : _a[referenceSlot].scenario
25028
+ : null;
25029
+ const fromData = this.totalDatasetRows();
25030
+ // the groups: runs of periods with the same start
25031
+ const groups = [];
25032
+ this.dataModel.forEach((row, index) => {
25033
+ const start = this.totalGroupStart(row.date);
25034
+ const last = groups[groups.length - 1];
25035
+ if (last != null && (start == null || (last.start != null && +last.start === +start))) {
25036
+ last.to = index;
25037
+ }
25038
+ else {
25039
+ groups.push({ from: index, to: index, start });
25040
+ }
25041
+ });
25042
+ // a total per period would repeat every column: `by` is not coarser than the periods of the chart
25043
+ if (this.totals.by !== "all" && groups.length === this.dataModel.length && groups.length > 1) {
25044
+ return [];
25045
+ }
25046
+ const columns = [];
25047
+ for (const group of groups) {
25048
+ const rows = this.dataModel.slice(group.from, group.to + 1);
25049
+ let parts = [];
25050
+ let reference = null;
25051
+ let counted = [];
25052
+ if (fromData != null) {
25053
+ // the values as the dataset gives them: one part per scenario of the series
25054
+ const data = (_c = fromData.get(group.start ? ((_b = group.start.toISODate()) !== null && _b !== void 0 ? _b : "") : "")) !== null && _c !== void 0 ? _c : {};
25055
+ for (const slot of series) {
25056
+ const scenario = (_d = this.dataModel.find((row) => { var _a; return ((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.scenario) != null; })) === null || _d === void 0 ? void 0 : _d[slot].scenario;
25057
+ // a 0 is a scenario without a value in this total
25058
+ if (scenario != null && Number.isFinite(data[scenario]) && data[scenario] !== 0) {
25059
+ parts.push({ scenario, value: data[scenario] });
25060
+ }
25061
+ }
25062
+ if (referenceScenario != null && Number.isFinite(data[referenceScenario])) {
25063
+ reference = { scenario: referenceScenario, value: data[referenceScenario] };
25064
+ }
25065
+ }
25066
+ else {
25067
+ // the periods where the series has a value. The reference counts in the same periods only,
25068
+ // as the variance of the total does: else the two would not tell the same.
25069
+ const used = rows.filter((row) => {
25070
+ var _a;
25071
+ const slot = this.visibleSlot(row, followers);
25072
+ return slot != null && Number.isFinite((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.value);
25073
+ });
25074
+ counted = used.map((row) => this.dataModel.indexOf(row));
25075
+ const visible = used.map((row) => row[this.visibleSlot(row, followers)]);
25076
+ // with `last` the one period that gives the value counts. A reference with a gap in
25077
+ // the counted periods is no reference: half a sum would stand against a full one.
25078
+ const referenceRows = this.totals.aggregation === "last" ? used.slice(-1) : used;
25079
+ const found = referenceSlot
25080
+ ? referenceRows.map((row) => row[referenceSlot]).filter((point) => Number.isFinite(point === null || point === void 0 ? void 0 : point.value))
25081
+ : [];
25082
+ const references = found.length === referenceRows.length ? found : [];
25083
+ const sum = (points) => points.reduce((total, point) => total + point.value, 0);
25084
+ if (this.totals.aggregation === "sum") {
25085
+ const sums = new Map();
25086
+ for (const point of visible) {
25087
+ sums.set(point.scenario, ((_e = sums.get(point.scenario)) !== null && _e !== void 0 ? _e : 0) + point.value);
25088
+ }
25089
+ parts = [...sums.entries()].map(([scenario, value]) => ({ scenario, value }));
25090
+ if (references.length > 0) {
25091
+ reference = { scenario: referenceScenario, value: sum(references) };
25092
+ }
25093
+ }
25094
+ else if (visible.length > 0) {
25095
+ const last = this.totals.aggregation === "last";
25096
+ parts = [
25097
+ {
25098
+ scenario: last
25099
+ ? visible[visible.length - 1].scenario
25100
+ : this.mixedScenario(visible.map((point) => point.scenario)),
25101
+ value: last ? visible[visible.length - 1].value : sum(visible) / visible.length,
25102
+ },
25103
+ ];
25104
+ if (references.length > 0) {
25105
+ reference = {
25106
+ scenario: referenceScenario,
25107
+ value: last ? references[references.length - 1].value : sum(references) / references.length,
25108
+ };
25109
+ }
25110
+ }
25111
+ }
25112
+ if (parts.length === 0) {
25113
+ // a group without a value of the series has no total, the others keep theirs
25114
+ continue;
25115
+ }
25116
+ if (parts.some((part) => !(part.value > 0))) {
25117
+ return [];
25118
+ }
25119
+ const total = parts.reduce((sum, part) => sum + part.value, 0);
25120
+ columns.push(Object.assign(Object.assign({}, group), { label: this.totalLabel(group.start), parts, total, reference, counted }));
25121
+ }
25122
+ return columns;
25123
+ }
25124
+ /** Height of the highest total column in pixels: its parts, its reference and its band of the scaling indicator. */
25125
+ totalsHeight() {
25126
+ if (!this.hasTotals()) {
24781
25127
  return 0;
24782
25128
  }
24783
25129
  const band = this.hasScalingIndicator() ? this.scalingIndicator : 0;
24784
- return Math.max(total.height, (_b = (_a = total.reference) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0, band) * this.totalColumn.pixelPerUnit;
25130
+ const units = Math.max(...this.totalColumns.map((column) => { var _a, _b; return Math.max(column.total, (_b = (_a = column.reference) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0); }));
25131
+ return Math.max(units, band) * this.totals.pixelPerUnit;
24785
25132
  }
24786
25133
  /**
24787
- * The variance of the total column in a variance chart: the sum of the series
24788
- * against the sum of the reference, over the periods where both have a value.
24789
- * It takes the notation of the forecast when a forecast is part of the sum.
25134
+ * The variances of the total columns in a variance chart, one per column:
25135
+ * the series against the reference, put together the way the total is. With
25136
+ * a dataset the values come from its row. A total takes the notation of the
25137
+ * forecast when a forecast is part of it.
24790
25138
  */
24791
- totalVariancePoint() {
24792
- var _a, _b, _c, _d, _e, _f;
24793
- if (!this.hasTotalColumn() || !this.isVarianceChart()) {
24794
- return null;
25139
+ computeTotalVariances() {
25140
+ var _a, _b;
25141
+ if (!this.hasTotals() || !this.isVarianceChart()) {
25142
+ return [];
24795
25143
  }
24796
25144
  const firstRow = (_a = this.dataModel[0]) !== null && _a !== void 0 ? _a : null;
24797
25145
  const candidates = ((_b = this.configVariances) !== null && _b !== void 0 ? _b : [])
24798
25146
  .map((name) => ({ name, variance: new VarianceScenario(name) }))
24799
25147
  .filter((entry) => entry.variance.isValid);
24800
25148
  if (candidates.length === 0) {
24801
- return null;
25149
+ return [];
24802
25150
  }
24803
- let base = 0;
24804
- let delta = 0;
24805
- const notations = new Set();
24806
- for (const row of this.dataModel) {
24807
- for (const { variance } of candidates) {
24808
- const slots = this.mapScenarios(variance, firstRow);
24809
- const baseValue = (_d = row[(_c = slots.get(variance.base)) !== null && _c !== void 0 ? _c : ""]) === null || _d === void 0 ? void 0 : _d.value;
24810
- const deltaValue = (_f = row[(_e = slots.get(variance.delta)) !== null && _e !== void 0 ? _e : ""]) === null || _f === void 0 ? void 0 : _f.value;
24811
- if (Number.isFinite(baseValue) && Number.isFinite(deltaValue)) {
24812
- base += baseValue;
24813
- delta += deltaValue;
24814
- notations.add(variance.base.slice(0, 2));
24815
- break;
25151
+ const first = candidates[0].variance;
25152
+ const relative = first.type === VarianceType.RELATIVE;
25153
+ const fromData = this.totalDatasetRows();
25154
+ const aggregation = this.totals.aggregation;
25155
+ return this.totalColumns.map((column) => {
25156
+ var _a, _b, _c, _d, _e, _f;
25157
+ let base;
25158
+ let delta;
25159
+ const notations = new Set();
25160
+ if (fromData != null) {
25161
+ base = 0;
25162
+ const data = (_b = fromData.get(column.start ? ((_a = column.start.toISODate()) !== null && _a !== void 0 ? _a : "") : "")) !== null && _b !== void 0 ? _b : {};
25163
+ // the bases of the row are the scenarios of the series, each counts once
25164
+ for (const name of new Set(candidates.map((entry) => entry.variance.base))) {
25165
+ // a 0 is a scenario without a value in this total, as for the parts
25166
+ if (Number.isFinite(data[name]) && data[name] !== 0) {
25167
+ base += data[name];
25168
+ notations.add(name.slice(0, 2));
25169
+ }
25170
+ }
25171
+ if (notations.size === 0 || !Number.isFinite(data[first.delta])) {
25172
+ return null;
24816
25173
  }
25174
+ delta = data[first.delta];
24817
25175
  }
25176
+ else {
25177
+ // the same periods as the column, so the two tell the same: with `last` the one
25178
+ // period of the value. Without both values in each of them there is no variance.
25179
+ const rows = (aggregation === "last" ? column.counted.slice(-1) : column.counted).map((index) => this.dataModel[index]);
25180
+ const pairs = [];
25181
+ for (const row of rows) {
25182
+ for (const { variance } of candidates) {
25183
+ const slots = this.mapScenarios(variance, firstRow);
25184
+ const baseValue = (_d = row[(_c = slots.get(variance.base)) !== null && _c !== void 0 ? _c : ""]) === null || _d === void 0 ? void 0 : _d.value;
25185
+ const deltaValue = (_f = row[(_e = slots.get(variance.delta)) !== null && _e !== void 0 ? _e : ""]) === null || _f === void 0 ? void 0 : _f.value;
25186
+ if (Number.isFinite(baseValue) && Number.isFinite(deltaValue)) {
25187
+ pairs.push({ base: baseValue, delta: deltaValue, notation: variance.base.slice(0, 2) });
25188
+ break;
25189
+ }
25190
+ }
25191
+ }
25192
+ if (pairs.length === 0 || pairs.length !== rows.length) {
25193
+ return null;
25194
+ }
25195
+ const divisor = aggregation === "average" ? pairs.length : 1;
25196
+ base = pairs.reduce((sum, pair) => sum + pair.base, 0) / divisor;
25197
+ delta = pairs.reduce((sum, pair) => sum + pair.delta, 0) / divisor;
25198
+ pairs.forEach((pair) => notations.add(pair.notation));
25199
+ }
25200
+ const point = new DataPoint(relative ? relativeVariance(base - delta, delta) : base - delta, first.delta, relative ? this.pixelPerPercentage : this.pixelPerUnit, first.direction);
25201
+ if (this.scenarioSwitch) {
25202
+ point.notation = notations.has("fc") ? "fc" : notations.size === 1 ? [...notations][0] : "ac";
25203
+ }
25204
+ point.key = this.totalKey(column, candidates[0].name);
25205
+ return point;
25206
+ });
25207
+ }
25208
+ /** The point key of an element of a total column: `row: total`, and the start of its group when there are several. */
25209
+ totalKey(column, scenario) {
25210
+ const key = { row: "total" };
25211
+ if (column.start != null) {
25212
+ key.date = TimeChart.pointDate(column.start);
24818
25213
  }
24819
- if (notations.size === 0) {
24820
- return null;
24821
- }
24822
- const first = candidates[0].variance;
24823
- const relative = first.type === VarianceType.RELATIVE;
24824
- const point = new DataPoint(relative ? relativeVariance(base - delta, delta) : base - delta, first.delta, relative ? this.pixelPerPercentage : this.pixelPerUnit, first.direction);
24825
- if (this.scenarioSwitch) {
24826
- point.notation = notations.has("fc") ? "fc" : notations.size === 1 ? [...notations][0] : "ac";
25214
+ if (scenario) {
25215
+ key.scenario = scenario;
24827
25216
  }
24828
- point.key = { row: "total", scenario: candidates[0].name };
24829
- return point;
25217
+ return key;
24830
25218
  }
24831
- /** Width of the texts right of the total column: the names of its parts, and the value of the scaling indicator. */
24832
- totalColumnTextWidth() {
25219
+ /** Width of the texts right of the total column at the end: the names of its parts, and the value of its band. */
25220
+ endTotalTextWidth() {
25221
+ if (!this.hasEndTotal()) {
25222
+ return 0;
25223
+ }
24833
25224
  const width = (text) => CalculateSize(text, { font: this.styles.fontStyles.font, fontSize: this.styles.fontStyles.size + "px" }).width;
24834
25225
  const gap = this.position.spacings.labelToColumn;
24835
- const total = this.totalColumnParts();
24836
- let names = 0;
24837
- if (total != null && total.parts.length > 1) {
24838
- names = gap + Math.max(...total.parts.map((part) => width(this.scenarioName(part.scenario))));
24839
- }
24840
- const indicator = total != null && this.hasScalingIndicator() ? gap + width(this.scalingIndicatorText()) : 0;
25226
+ const parts = this.totalColumns[0].parts;
25227
+ const names = !this.isVarianceChart() && parts.length > 1
25228
+ ? gap + Math.max(...parts.map((part) => width(this.scenarioName(part.scenario))))
25229
+ : 0;
25230
+ const indicator = this.hasScalingIndicator() ? gap + width(this.scalingIndicatorText()) : 0;
24841
25231
  return names + indicator;
24842
25232
  }
24843
25233
  scenarioName(scenario) {
@@ -24858,125 +25248,142 @@ class TimeChart {
24858
25248
  solid: pattern ? null : color,
24859
25249
  };
24860
25250
  }
24861
- /** The axis of the total column: its own piece of line, in the look of the axis of the chart. */
25251
+ /** The axis of the total column at the end: its own piece of line, in the look of the axis of the chart. */
24862
25252
  drawTotalAxis(group, y) {
24863
- const { left, right } = this.totalColumnGeometry();
25253
+ const { left, right } = this.totalGeometry(0);
24864
25254
  const scenario = this.axisScenario == null ? "default" : `${this.axisScenario}`.slice(0, 2);
24865
25255
  group.line(left, y, right, y).addClass("axis-" + scenario);
24866
25256
  }
24867
25257
  /**
24868
- * The total column of the base chart: a stack of the parts at the scale of the
24869
- * column, the reference behind it, the total above and the names of the parts
24870
- * at the right. With a scaling indicator the column has its own band, and a
24871
- * line links it to the band of the periods.
25258
+ * The total columns of the base chart, at their own scale: the parts, the
25259
+ * reference behind, the total above and the name under the axis. With a
25260
+ * scaling indicator a column has its own band. The column at the end has its
25261
+ * own axis and the names of its parts at the right, and a line links its band
25262
+ * to the band of the periods.
24872
25263
  */
24873
- drawTotalColumn(svgContainer) {
24874
- const total = this.isVarianceChart() ? null : this.totalColumnParts();
24875
- if (total == null) {
25264
+ drawTotalColumns(svgContainer) {
25265
+ if (!this.hasTotals() || this.isVarianceChart()) {
24876
25266
  return;
24877
25267
  }
24878
- const { center, width, left, right } = this.totalColumnGeometry();
24879
- const scale = this.totalColumn.pixelPerUnit;
25268
+ const scale = this.totals.pixelPerUnit;
24880
25269
  const axisY = this.position.getColumnPositionY();
24881
25270
  const gap = this.position.spacings.labelToColumn;
25271
+ const atEnd = this.hasEndTotal();
24882
25272
  const group = svgContainer.group().id("TotalColumn");
24883
- if (this.hasScalingIndicator()) {
24884
- const height = this.scalingIndicator * scale;
24885
- const periods = this.scalingIndicatorBand();
24886
- group
24887
- .rect(right - left, height)
24888
- .x(left)
24889
- .y(axisY - height)
24890
- .fill(SCALING_INDICATOR_FILL);
24891
- if (periods != null) {
24892
- // the line starts behind the value of the band of the periods
24893
- const from = this.scalingIndicatorLabelX() + this.scalingIndicatorTextWidth() + gap / 2;
24894
- group
24895
- .line(Math.min(from, left), axisY - periods.height, left, axisY - height)
24896
- .stroke({ color: SCALING_INDICATOR_LINE, width: 1 })
24897
- .id("ScalingIndicatorLink");
24898
- }
24899
- }
24900
- if (total.reference != null && total.reference.value > 0) {
24901
- const look = this.columnLook(total.reference.scenario);
24902
- const height = total.reference.value * scale;
24903
- group
24904
- .rect(width, height)
24905
- .cx(center - this.position.spacings.scenarioOffset)
24906
- .y(axisY - height)
24907
- .fill(look.fill)
24908
- .stroke(look.stroke)
24909
- .attr(dataPointAttributes({ row: "total", scenario: total.reference.scenario }, "element"))
24910
- .attr("data-bn-value", total.reference.value);
24911
- }
24912
- let top = axisY;
24913
25273
  const labelGroup = svgContainer.group().id("TotalColumnLabels");
24914
- for (const part of total.parts) {
24915
- const look = this.columnLook(part.scenario);
24916
- const height = part.value * scale;
24917
- top -= height;
24918
- const key = { row: "total", scenario: part.scenario };
24919
- group
24920
- .rect(width, height)
24921
- .cx(center)
24922
- .y(top)
24923
- .fill(look.fill)
24924
- .stroke(look.stroke)
24925
- .attr(dataPointAttributes(key, "element"))
24926
- .attr("data-bn-value", part.value);
24927
- if (total.parts.length > 1) {
24928
- if (height >= this.position.dataLabelHeight) {
24929
- const label = new Label$1(labelGroup, center, top + height / 2, "TOTAL_PART", part.value, this.styles, HookLocation$1.Center, HookLocation$1.Center).setPoint(key);
24930
- // a label on a hatching keeps the background of a plain label
24931
- (look.solid ? label.setSegmentFill(look.solid) : label).draw(true, this.dataFormatDigits, this.measureScale);
25274
+ this.totalColumns.forEach((column, index) => {
25275
+ const { center, width, left, right } = this.totalGeometry(index);
25276
+ if (this.hasScalingIndicator()) {
25277
+ const height = this.scalingIndicator * scale;
25278
+ const periods = this.scalingIndicatorBand();
25279
+ const band = group
25280
+ .rect(right - left, height)
25281
+ .x(left)
25282
+ .y(axisY - height)
25283
+ .fill(SCALING_INDICATOR_FILL);
25284
+ // behind the columns of the periods that stand next to it
25285
+ band.back();
25286
+ if (atEnd && periods != null) {
25287
+ // the line starts behind the value of the band of the periods
25288
+ const from = this.scalingIndicatorLabelX() + this.scalingIndicatorTextWidth() + gap / 2;
25289
+ group
25290
+ .line(Math.min(from, left), axisY - periods.height, left, axisY - height)
25291
+ .stroke({ color: SCALING_INDICATOR_LINE, width: 1 })
25292
+ .id("ScalingIndicatorLink");
24932
25293
  }
24933
- new Label$1(labelGroup, center + width / 2 + gap,
24934
- // the name of a thin top part stays below the total above the column
24935
- Math.max(top + height / 2, axisY - total.height * scale + this.position.dataLabelHeight / 2), "TOTAL_NAME", this.scenarioName(part.scenario), this.styles, HookLocation$1.Center, HookLocation$1.Left).forceStringTypeDraw();
24936
25294
  }
24937
- }
24938
- new Label$1(labelGroup, center, top - gap, "TOTAL", total.total, this.styles, HookLocation$1.Bottom, HookLocation$1.Center)
24939
- .setPoint({ row: "total" }, "total")
24940
- .draw(true, this.dataFormatDigits, this.measureScale);
24941
- this.drawTotalAxis(group, this.position.getAxisPositionY(false));
24942
- if (this.hasScalingIndicator()) {
24943
- new Label$1(labelGroup, right +
24944
- this.totalColumnTextWidth() -
24945
- CalculateSize(this.scalingIndicatorText(), {
24946
- font: this.styles.fontStyles.font,
24947
- fontSize: this.styles.fontStyles.size + "px",
24948
- }).width, axisY - this.scalingIndicator * scale, "SCALING_INDICATOR_TOTAL", this.scalingIndicatorText(), this.styles, HookLocation$1.Center, HookLocation$1.Left).forceStringTypeDraw();
24949
- }
24950
- if (this.hideAxisLabels === false && this.totalColumn.label) {
24951
- new Label$1(labelGroup, center, this.position.getAxisPositionY(false) + this.position.spacings.labelToAxis, "TOTAL_LABEL", this.totalColumn.label, this.styles, HookLocation$1.Top, HookLocation$1.Center).forceStringTypeDraw();
25295
+ if (column.reference != null && column.reference.value > 0) {
25296
+ const look = this.columnLook(column.reference.scenario);
25297
+ const height = column.reference.value * scale;
25298
+ group
25299
+ .rect(width, height)
25300
+ .cx(center - this.position.spacings.scenarioOffset)
25301
+ .y(axisY - height)
25302
+ .fill(look.fill)
25303
+ .stroke(look.stroke)
25304
+ .attr(dataPointAttributes(this.totalKey(column, column.reference.scenario), "element"))
25305
+ .attr("data-bn-value", column.reference.value);
25306
+ }
25307
+ let top = axisY;
25308
+ for (const part of column.parts) {
25309
+ const look = this.columnLook(part.scenario);
25310
+ const height = part.value * scale;
25311
+ top -= height;
25312
+ const key = this.totalKey(column, part.scenario);
25313
+ group
25314
+ .rect(width, height)
25315
+ .cx(center)
25316
+ .y(top)
25317
+ .fill(look.fill)
25318
+ .stroke(look.stroke)
25319
+ .attr(dataPointAttributes(key, "element"))
25320
+ .attr("data-bn-value", part.value);
25321
+ if (column.parts.length > 1) {
25322
+ if (height >= this.position.dataLabelHeight) {
25323
+ const label = new Label$1(labelGroup, center, top + height / 2, "TOTAL_PART", part.value, this.styles, HookLocation$1.Center, HookLocation$1.Center).setPoint(key);
25324
+ // a label on a hatching keeps the background of a plain label
25325
+ (look.solid ? label.setSegmentFill(look.solid) : label).draw(true, this.dataFormatDigits, this.measureScale);
25326
+ }
25327
+ if (atEnd) {
25328
+ new Label$1(labelGroup, center + width / 2 + gap,
25329
+ // the name of a thin top part stays below the total above the column
25330
+ Math.max(top + height / 2, axisY - column.total * scale + this.position.dataLabelHeight / 2), "TOTAL_NAME", this.scenarioName(part.scenario), this.styles, HookLocation$1.Center, HookLocation$1.Left).forceStringTypeDraw();
25331
+ }
25332
+ }
25333
+ }
25334
+ new Label$1(labelGroup, center, top - gap, "TOTAL", column.total, this.styles, HookLocation$1.Bottom, HookLocation$1.Center)
25335
+ .setPoint(this.totalKey(column), "total")
25336
+ .draw(true, this.dataFormatDigits, this.measureScale);
25337
+ if (this.hideAxisLabels === false && column.label) {
25338
+ new Label$1(labelGroup, center, this.position.getAxisPositionY(false) + this.position.spacings.labelToAxis, "TOTAL_LABEL", column.label, this.styles, HookLocation$1.Top, HookLocation$1.Center).forceStringTypeDraw();
25339
+ }
25340
+ });
25341
+ if (atEnd) {
25342
+ this.drawTotalAxis(group, this.position.getAxisPositionY(false));
25343
+ if (this.hasScalingIndicator()) {
25344
+ new Label$1(labelGroup, this.totalGeometry(0).right + this.endTotalTextWidth() - this.scalingIndicatorTextWidth(), axisY - this.scalingIndicator * scale, "SCALING_INDICATOR_TOTAL", this.scalingIndicatorText(), this.styles, HookLocation$1.Center, HookLocation$1.Left).forceStringTypeDraw();
25345
+ }
24952
25346
  }
24953
25347
  }
24954
- /** The variance of the total column, in the tier of its variance chart: a column or a pin like the others. */
24955
- drawTotalVariance(svgContainer) {
24956
- const point = this.totalVariance;
24957
- if (point == null) {
25348
+ /** The variances of the total columns, in the tier of their variance chart: columns or pins like the others. */
25349
+ drawTotalVariances(svgContainer) {
25350
+ var _a;
25351
+ if (!this.totalVariances.some((point) => point != null)) {
24958
25352
  return;
24959
25353
  }
24960
- const group = svgContainer.group().id("TotalColumn");
24961
- const labelGroup = svgContainer.group().id("TotalColumnLabels");
24962
- const { center } = this.totalColumnGeometry();
24963
- // the elements take their place from an index: the one of the centre of the total column
24964
- const index = (center - this.position.getColumnCenterPositionX(0)) /
24965
- (this.position.getColumnCenterPositionX(1) - this.position.getColumnCenterPositionX(0));
25354
+ // inside the group of the variances: its box is the height of the row, also below the axis
25355
+ const scenarios = (_a = svgContainer.findOne("#Scenarios")) !== null && _a !== void 0 ? _a : svgContainer.group().id("Scenarios");
25356
+ const group = scenarios.group().id("TotalColumn");
25357
+ const labelGroup = scenarios.group().id("TotalColumnLabels");
24966
25358
  const relative = this.variancesDataModel.some((entry) => entry.type === VarianceType.RELATIVE);
24967
- if (relative) {
24968
- new Needle(this.position, this.scenarioStyles(), point, index, group.group())
24969
- .updateLabelGroup(labelGroup.group())
24970
- .draw(this.dataFormatDigits);
24971
- }
24972
- else {
24973
- // a row whose period variances are cut cuts the total the same way
24974
- new Column(this.position, this.scenarioStyles(), point, index, true, group.group(), null, this.overflowConfig)
25359
+ this.totalVariances.forEach((point, total) => {
25360
+ if (point == null) {
25361
+ return;
25362
+ }
25363
+ const index = this.totalIndex(total);
25364
+ if (relative) {
25365
+ new Needle(this.position, this.scenarioStyles(), point, index, group.group())
25366
+ .updateLabelGroup(labelGroup.group())
25367
+ .draw(this.dataFormatDigits);
25368
+ return;
25369
+ }
25370
+ // a row whose period variances are cut cuts the total the same way. The part above the
25371
+ // break is scaled by the largest overflow: that can be the one of the total.
25372
+ const overflow = this.overflowConfig
25373
+ ? Object.assign(Object.assign({}, this.overflowConfig), { maxOverflow: Math.max(this.overflowConfig.maxOverflow, point.getScaledUnit() - (this.overflowConfig.cutHeight - this.overflowConfig.scenarioCutOffset)) }) : null;
25374
+ new Column(this.position, this.scenarioStyles(), point, index, true, group.group(), null, overflow)
24975
25375
  .updateLabelGroup(labelGroup.group())
24976
25376
  .setAsVariance()
24977
25377
  .draw(this.dataFormatDigits, this.measureScale);
25378
+ });
25379
+ if (this.hasEndTotal()) {
25380
+ this.drawTotalAxis(group, this.position.getAxisPositionY(relative));
24978
25381
  }
24979
- this.drawTotalAxis(group, this.position.getAxisPositionY(relative));
25382
+ const box = scenarios.bbox();
25383
+ this.scenariosArea = {
25384
+ height: box.height + this.styles.padding.top + this.styles.padding.bottom,
25385
+ width: box.width + this.position.spacings.columnWidth,
25386
+ };
24980
25387
  }
24981
25388
  determineEffectiveChartMode() {
24982
25389
  if (this.chartMode === ChartMode.LINE) {
@@ -25048,6 +25455,7 @@ class TimeChart {
25048
25455
  return new Map([...defaultI18n, ...i18n]);
25049
25456
  }
25050
25457
  createElementPosition(scenarios) {
25458
+ var _a, _b;
25051
25459
  let maxLabelLengthLeft;
25052
25460
  // only need scenarios written on the leftside of bar/ marker
25053
25461
  const scenarioLabelLeft = CalculateSize(scenarios
@@ -25091,7 +25499,7 @@ class TimeChart {
25091
25499
  if (this.overflowConfig) {
25092
25500
  const { cutHeight, overdriveZoneHeight, breakGap } = this.overflowConfig;
25093
25501
  // the total column is not cut: it keeps its room above the cut columns
25094
- const virtualHeight = Math.max(cutHeight + overdriveZoneHeight + breakGap, this.isVarianceChart() ? 0 : this.totalColumnHeight());
25502
+ const virtualHeight = Math.max(cutHeight + overdriveZoneHeight + breakGap, this.isVarianceChart() ? 0 : this.totalsHeight());
25095
25503
  // Create a virtual DataPoint with pixelPerUnit=1 so getScaledUnit() returns virtualHeight directly
25096
25504
  max = new DataPoint(virtualHeight, max.scenario, 1, max.variance);
25097
25505
  }
@@ -25122,7 +25530,13 @@ class TimeChart {
25122
25530
  effectiveScaleFactors = cloned;
25123
25531
  }
25124
25532
  }
25125
- return new ElementPositions(new Padding(this.styles.padding), effectiveScaleFactors, this.styles.fontStyles, min, max, this.dataModel.length, maxLabelLengthLeft);
25533
+ // total columns take places on the axis: the periods behind them move on
25534
+ const places = this.hasTotals()
25535
+ ? this.totalSlots(effectiveScaleFactors.columnWidth, effectiveScaleFactors.categoryWidth, this.styles.fontStyles.size, effectiveScaleFactors.scenarioOffset)
25536
+ : null;
25537
+ const position = new ElementPositions(new Padding(this.styles.padding), effectiveScaleFactors, this.styles.fontStyles, min, max, (_a = places === null || places === void 0 ? void 0 : places.axisColumns) !== null && _a !== void 0 ? _a : this.dataModel.length, maxLabelLengthLeft);
25538
+ position.setSlots((_b = places === null || places === void 0 ? void 0 : places.slots) !== null && _b !== void 0 ? _b : null);
25539
+ return position;
25126
25540
  }
25127
25541
  calculateTitleLength(minWidth) {
25128
25542
  let tmpTitle = "_______"; // default width if this.title is sorther
@@ -25660,7 +26074,8 @@ class TimeChart {
25660
26074
  const bottom = namesHeight > 0 ? height - this.styles.padding.bottom : height;
25661
26075
  const lineWidth = Math.max(1, this.position.spacings.auxiliaryLineWidth);
25662
26076
  runs.slice(1).forEach((run) => {
25663
- const x = (this.position.getColumnCenterPositionX(run.from - 1) + this.position.getColumnCenterPositionX(run.from)) / 2;
26077
+ // half a period before the first period of the run: a total column can stand between the two runs
26078
+ const x = this.position.getColumnCenterPositionX(run.from) - this.position.spacings.categoryWidth / 2;
25664
26079
  group
25665
26080
  .line(x, 0, x, bottom)
25666
26081
  .stroke({ color: this.styles.fontStyles.color || "#000000", width: lineWidth })
@@ -26475,8 +26890,8 @@ class TimeChartComponentConfig {
26475
26890
  this.axisLabelsStep = 1;
26476
26891
  /** Value of the scaling indicator band, 0 for none. */
26477
26892
  this.scalingIndicator = 0;
26478
- /** The column for the total of all periods, null for none. */
26479
- this.totalColumn = null;
26893
+ /** The total columns, null for none. */
26894
+ this.totals = null;
26480
26895
  /** One series that changes its scenario along the time axis, see `bn-chart-time`. */
26481
26896
  this.scenarioSwitch = false;
26482
26897
  /** Side of the axis title: left, right or none. */
@@ -26569,12 +26984,19 @@ class TimeChartComponentConfigAdapter {
26569
26984
  if (CompareUtil.isNumber(data.scalingIndicator) && data.scalingIndicator > 0) {
26570
26985
  config.scalingIndicator = data.scalingIndicator;
26571
26986
  }
26572
- const total = data.totalColumn;
26573
- if (total != null && CompareUtil.isNumber(total.pixelPerUnit) && total.pixelPerUnit > 0) {
26574
- config.totalColumn = {
26575
- pixelPerUnit: total.pixelPerUnit,
26576
- label: typeof total.label === "string" ? total.label : "",
26577
- width: CompareUtil.isNumber(total.width) && total.width > 0 ? total.width : 1,
26987
+ const totals = data.totals;
26988
+ if (totals != null && CompareUtil.isNumber(totals.pixelPerUnit) && totals.pixelPerUnit > 0) {
26989
+ const by = ["all", "year", "quarter", "month", "week"].includes(totals.by) ? totals.by : "all";
26990
+ const aggregation = ["sum", "average", "last"].includes(totals.aggregation)
26991
+ ? totals.aggregation
26992
+ : "sum";
26993
+ config.totals = {
26994
+ by,
26995
+ aggregation,
26996
+ pixelPerUnit: totals.pixelPerUnit,
26997
+ label: typeof totals.label === "string" ? totals.label : "",
26998
+ width: CompareUtil.isNumber(totals.width) && totals.width > 0 ? totals.width : 1,
26999
+ dataset: typeof totals.dataset === "string" ? totals.dataset : "",
26578
27000
  };
26579
27001
  }
26580
27002
  if (CompareUtil.isBoolean(data.scenarioSwitch)) {
@@ -26664,7 +27086,7 @@ const BnChartTimeRenderer = class {
26664
27086
  /** @internal */
26665
27087
  this.scalingIndicator = 0;
26666
27088
  /** @internal */
26667
- this.totalColumn = null;
27089
+ this.totals = null;
26668
27090
  /** @internal */
26669
27091
  this.scenarioSwitch = false;
26670
27092
  /** @internal */
@@ -26956,7 +27378,7 @@ const BnChartTimeRenderer = class {
26956
27378
  lineFullWidth: this.lineFullWidth,
26957
27379
  axisLabelsStep: this.axisLabelsStep,
26958
27380
  scalingIndicator: this.scalingIndicator,
26959
- totalColumn: this.totalColumn,
27381
+ totals: this.totals,
26960
27382
  scenarioSwitch: this.scenarioSwitch,
26961
27383
  axisTitlePosition: this.axisTitlePosition,
26962
27384
  locale: ((_c = (_b = (_a = this.stores) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.locale) || "de",