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