@bino-bi/bn-template-engine 1.0.0-next.62 → 1.0.0-next.64

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-07c55f50.entry.js} +1 -1
  3. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +687 -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 +116 -34
  8. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +532 -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-B8-9TksQ.js +1 -0
  14. package/dist/esm/bn-annotation-layer_30.entry.js +687 -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 +30 -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,33 @@ 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
+ * With `average` or `last` the values of a row are one column.
20747
+ * - `label` - text under the column of `by: all`. The other columns take the name of their period.
20675
20748
  * - `width` - width in widths of a period column, default 1.
20676
20749
  *
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.
20750
+ * The first other scenario is the reference behind a column. Each variance
20751
+ * row gets the variance of each total at the scale of the row. With
20752
+ * `scaling-indicator` a column has its own band, and with `by: all` a line
20753
+ * links it to the band of the periods. Plain columns only: not with `stack`
20754
+ * and not in line mode. The chart needs a fixed `unit-scaling`, and every
20755
+ * part of a total must be positive.
20684
20756
  */
20685
- this.totalColumn = "";
20757
+ this.totals = "";
20758
+ this.totalsDatasetUnsubscribe = null;
20759
+ this.totalsDatasetName = "";
20686
20760
  /**
20687
20761
  * For a series that changes its scenario along the time axis, for example
20688
20762
  * AC up to this year and PL after it. In a period where the first scenario
@@ -20787,7 +20861,7 @@ const Chart = class {
20787
20861
  this.validateDataFormatDigitsDecimal(this.dataFormatDigitsDecimal);
20788
20862
  this.validateDataFormatDigitsPercent(this.dataFormatDigitsPercent);
20789
20863
  this.validateAxisLabelsStep(this.axisLabelsStep);
20790
- this.validateTotalColumn(this.totalColumn);
20864
+ this.validateTotals(this.totals);
20791
20865
  this.validateAxisTitlePosition(this.axisTitlePosition);
20792
20866
  }
20793
20867
  /**
@@ -20998,9 +21072,16 @@ const Chart = class {
20998
21072
  };
20999
21073
  this._settleTimer = setTimeout(check, delays.shift());
21000
21074
  }
21075
+ connectedCallback() {
21076
+ // an element that is moved in the page comes back without its subscription
21077
+ this.bindTotalsDataset();
21078
+ }
21001
21079
  disconnectedCallback() {
21002
- var _a;
21003
- (_a = this.layoutObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
21080
+ var _a, _b;
21081
+ (_a = this.totalsDatasetUnsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
21082
+ this.totalsDatasetUnsubscribe = null;
21083
+ this.totalsDatasetName = "";
21084
+ (_b = this.layoutObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
21004
21085
  this.layoutObserver = null;
21005
21086
  if (this._settleTimer != null) {
21006
21087
  clearTimeout(this._settleTimer);
@@ -21453,7 +21534,7 @@ const Chart = class {
21453
21534
  percent: this.dataFormatDigitsPercent,
21454
21535
  decimal: this.dataFormatDigitsDecimal,
21455
21536
  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() }));
21537
+ }, 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
21538
  }
21458
21539
  /**
21459
21540
  * The line this chart wants to be aligned on, in CSS px from the host's
@@ -21585,7 +21666,7 @@ const Chart = class {
21585
21666
  this.errors.remove("WARN_scenarios_none");
21586
21667
  }
21587
21668
  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))));
21669
+ return (index.h(index.Host, { key: 'baa11d12a8dc2e01a487b02bcd68902890ceb85a', style: fontStyles }, index.h("div", { key: '40a33368366a59709c8a6c0354a6aca50445778f', class: "container" }, segments.map(this.chartTemplate))));
21589
21670
  }
21590
21671
  get element() { return index.getElement(this); }
21591
21672
  static get watchers() { return {
@@ -21634,8 +21715,8 @@ const Chart = class {
21634
21715
  "dataFormatDigitsPercent": [{
21635
21716
  "validateDataFormatDigitsPercent": 0
21636
21717
  }],
21637
- "totalColumn": [{
21638
- "validateTotalColumn": 0
21718
+ "totals": [{
21719
+ "validateTotals": 0
21639
21720
  }],
21640
21721
  "axisLabelsStep": [{
21641
21722
  "validateAxisLabelsStep": 0
@@ -21771,6 +21852,11 @@ class ElementPositions {
21771
21852
  width: 0,
21772
21853
  height: 0,
21773
21854
  };
21855
+ /**
21856
+ * Places on the axis in category widths, by index: the periods first, then
21857
+ * the total columns. Without it the place of an index is the index itself.
21858
+ */
21859
+ this.slots = null;
21774
21860
  this.padding = padding;
21775
21861
  this.scaleFactors = scaleFactors;
21776
21862
  this.fontStlye = fontstyle;
@@ -21794,10 +21880,27 @@ class ElementPositions {
21794
21880
  }).height;
21795
21881
  return height * 1.1;
21796
21882
  }
21883
+ setSlots(slots) {
21884
+ this.slots = slots;
21885
+ }
21886
+ /** The place of an index on the axis, in category widths. Between two indexes it lies between their places. */
21887
+ slotOf(index) {
21888
+ const slots = this.slots;
21889
+ if (slots == null || slots.length === 0) {
21890
+ return index;
21891
+ }
21892
+ const last = slots.length - 1;
21893
+ if (index <= 0)
21894
+ return slots[0] + index;
21895
+ if (index >= last)
21896
+ return slots[last] + (index - last);
21897
+ const low = Math.floor(index);
21898
+ return slots[low] + (slots[low + 1] - slots[low]) * (index - low);
21899
+ }
21797
21900
  getColumnCenterPositionX(index) {
21798
21901
  return (this.categoryPosition.y +
21799
21902
  this.spacings.scenarioOffset +
21800
- index * this.spacings.categoryWidth +
21903
+ this.slotOf(index) * this.spacings.categoryWidth +
21801
21904
  this.leftSideLabelLength +
21802
21905
  this.spacings.columnWidth * 0.5);
21803
21906
  }
@@ -23970,8 +24073,9 @@ class TimeChart {
23970
24073
  this.lastScenarios = [];
23971
24074
  this.axisLabelsStep = 1;
23972
24075
  this.scalingIndicator = 0;
23973
- this.totalColumn = null;
23974
- this.totalVariance = null;
24076
+ this.totals = null;
24077
+ this.totalColumns = [];
24078
+ this.totalVariances = [];
23975
24079
  this.highestColumnDataPointValue = new DataPoint(0, "default", 0, Scenario.NEU);
23976
24080
  this.highestPeriodVarianceDataPointValue = new DataPoint(0, "default", 0, Scenario.NEU);
23977
24081
  this.scenarioSwitch = false;
@@ -24074,7 +24178,7 @@ class TimeChart {
24074
24178
  this.intervalSpanLimit = config.intervalSpanLimit;
24075
24179
  this.axisLabelsStep = (_a = config.axisLabelsStep) !== null && _a !== void 0 ? _a : 1;
24076
24180
  this.scalingIndicator = (_b = config.scalingIndicator) !== null && _b !== void 0 ? _b : 0;
24077
- this.totalColumn = (_c = config.totalColumn) !== null && _c !== void 0 ? _c : null;
24181
+ this.totals = (_c = config.totals) !== null && _c !== void 0 ? _c : null;
24078
24182
  this.scenarioSwitch = (_d = config.scenarioSwitch) !== null && _d !== void 0 ? _d : false;
24079
24183
  this.axisTitlePosition = (_e = config.axisTitlePosition) !== null && _e !== void 0 ? _e : "left";
24080
24184
  this.dateInterval = this.findDateInterval(config.dateInterval);
@@ -24126,13 +24230,16 @@ class TimeChart {
24126
24230
  this.highestColumnDataPointValue = this.highestDataPointValue;
24127
24231
  // the highest period variance: a break mark is for a variance of a period, the total has its own cut
24128
24232
  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;
24233
+ this.totalColumns = this.computeTotalColumns();
24234
+ this.totalVariances = this.computeTotalVariances();
24235
+ for (const point of this.totalVariances) {
24236
+ if (point == null || !Number.isFinite(point.value))
24237
+ continue;
24238
+ if (point.value > Number(this.highestVarianceDataPointValue.value)) {
24239
+ this.highestVarianceDataPointValue = point;
24133
24240
  }
24134
- if (this.totalVariance.value < Number(this.smallestVarianceDataPointValue.value)) {
24135
- this.smallestVarianceDataPointValue = this.totalVariance;
24241
+ if (point.value < Number(this.smallestVarianceDataPointValue.value)) {
24242
+ this.smallestVarianceDataPointValue = point;
24136
24243
  }
24137
24244
  }
24138
24245
  if (this.hasScalingIndicator() && this.scalingIndicator > Number(this.highestDataPointValue.value)) {
@@ -24141,7 +24248,7 @@ class TimeChart {
24141
24248
  this.highestDataPointValue = new DataPoint(this.scalingIndicator, scenario, this.pixelPerUnit, variance);
24142
24249
  }
24143
24250
  // 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();
24251
+ const totalHeight = this.isVarianceChart() ? 0 : this.totalsHeight();
24145
24252
  if (totalHeight > this.highestDataPointValue.getScaledUnit() && this.pixelPerUnit > 0) {
24146
24253
  const { scenario, variance } = this.highestDataPointValue;
24147
24254
  this.highestDataPointValue = new DataPoint(totalHeight / this.pixelPerUnit, scenario, this.pixelPerUnit, variance);
@@ -24261,8 +24368,8 @@ class TimeChart {
24261
24368
  }).width;
24262
24369
  indicatorEnd = this.scalingIndicatorLabelX() + textWidth + this.styles.padding.right;
24263
24370
  }
24264
- const totalEnd = this.hasTotalColumn()
24265
- ? this.totalColumnGeometry().right + this.totalColumnTextWidth() + this.styles.padding.right
24371
+ const totalEnd = this.hasEndTotal()
24372
+ ? this.totalGeometry(0).right + this.endTotalTextWidth() + this.styles.padding.right
24266
24373
  : 0;
24267
24374
  return Math.max(axisEnd + labelBuffer, bboxTotal, titleEnd, legendEnd, indicatorEnd, totalEnd);
24268
24375
  }
@@ -24502,9 +24609,9 @@ class TimeChart {
24502
24609
  const points = this.variancesDataModel
24503
24610
  .filter((entry) => entry.type === VarianceType.RELATIVE)
24504
24611
  .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);
24612
+ if (points.length > 0) {
24613
+ // the pins of the total columns are pins of the row
24614
+ points.push(...this.totalVariances.filter((point) => point != null));
24508
24615
  }
24509
24616
  if (points.length === 0 || !points.some((point) => point.isClipped())) {
24510
24617
  return;
@@ -24605,7 +24712,7 @@ class TimeChart {
24605
24712
  if (this.isVarianceChart()) {
24606
24713
  this.drawVarianceScenario(this.variancesDataModel, svgContainer);
24607
24714
  // before the axis: the line of a scenario switch runs over the full height of the row
24608
- this.drawTotalVariance(svgContainer);
24715
+ this.drawTotalVariances(svgContainer);
24609
24716
  this.drawAxisAndLabels(this.variancesDataModel, svgContainer);
24610
24717
  }
24611
24718
  else if (this.stackConfig != null) {
@@ -24632,7 +24739,7 @@ class TimeChart {
24632
24739
  this.drawOverlayLayer(this.dataModel, svgContainer);
24633
24740
  this.drawAxisAndLabels(this.dataModel, svgContainer);
24634
24741
  this.drawScalingIndicator(svgContainer);
24635
- this.drawTotalColumn(svgContainer);
24742
+ this.drawTotalColumns(svgContainer);
24636
24743
  }
24637
24744
  }
24638
24745
  }
@@ -24662,7 +24769,11 @@ class TimeChart {
24662
24769
  scalingIndicatorLabelX() {
24663
24770
  const gap = this.position.spacings.labelToColumn;
24664
24771
  const half = this.position.getColumnWidth() / 2 + this.position.spacings.scenarioOffset;
24665
- const right = this.position.getColumnCenterPositionX(Math.max(0, this.dataModel.length - 1)) + half;
24772
+ let right = this.position.getColumnCenterPositionX(Math.max(0, this.dataModel.length - 1)) + half;
24773
+ if (this.hasTotals() && !this.hasEndTotal()) {
24774
+ // a total stands behind the last period: the value goes behind it
24775
+ right = Math.max(right, this.totalGeometry(this.totalColumns.length - 1).right);
24776
+ }
24666
24777
  const legendWidth = this.legendWidth("right");
24667
24778
  return right + gap + (legendWidth > 0 ? legendWidth + gap : 0);
24668
24779
  }
@@ -24695,154 +24806,448 @@ class TimeChart {
24695
24806
  const { left, right, height } = band;
24696
24807
  const axisY = this.position.getColumnPositionY();
24697
24808
  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);
24809
+ // totals on the axis have their own band at their own scale: the band of the periods leaves their place free
24810
+ const half = this.position.getColumnWidth() / 2 + this.position.spacings.scenarioOffset;
24811
+ const runs = this.hasTotals() && !this.hasEndTotal()
24812
+ ? this.totalRuns().map((run) => ({
24813
+ left: this.position.getColumnCenterPositionX(run.from) - half,
24814
+ right: this.position.getColumnCenterPositionX(run.to) + half,
24815
+ }))
24816
+ : [{ left, right }];
24817
+ for (const run of runs) {
24818
+ group
24819
+ .rect(run.right - run.left, height)
24820
+ .x(run.left)
24821
+ .y(axisY - height)
24822
+ .fill(SCALING_INDICATOR_FILL);
24823
+ }
24703
24824
  group.back();
24704
24825
  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
24826
  }
24706
- /** Where a title at the right starts when a total column stands there: behind the column and its texts. */
24827
+ /** Where a title at the right starts when a total column stands at the end: behind the column and its texts. */
24707
24828
  rightTitleX() {
24708
- if (!this.hasTotalColumn()) {
24829
+ if (!this.hasEndTotal()) {
24709
24830
  return undefined;
24710
24831
  }
24711
- return this.totalColumnGeometry().right + this.totalColumnTextWidth() + this.position.spacings.labelToColumn;
24832
+ return this.totalGeometry(0).right + this.endTotalTextWidth() + this.position.spacings.labelToColumn;
24833
+ }
24834
+ /** True for a chart with total columns. */
24835
+ hasTotals() {
24836
+ return this.totalColumns.length > 0;
24712
24837
  }
24713
- /** True for a chart with a total column: plain columns, no stack, no line. */
24714
- hasTotalColumn() {
24715
- return this.totalColumnParts() != null;
24838
+ /** True for the one total column of `by: all`: it stands apart at the end, with its own axis and its names. */
24839
+ hasEndTotal() {
24840
+ return this.hasTotals() && this.totals.by === "all";
24716
24841
  }
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() {
24842
+ /** The index of a total column for the positions: the totals follow the periods. */
24843
+ totalIndex(total) {
24844
+ // the index behind the last period stays what it is without totals: the end of the overlay lines
24845
+ return this.dataModel.length + 1 + total;
24846
+ }
24847
+ /** Place of a total column. `left` and `right` are the ends of its band, and of its own axis at the end. */
24848
+ totalGeometry(total) {
24719
24849
  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;
24850
+ const width = this.position.getColumnWidth() * ((_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 1);
24851
+ const center = this.position.getColumnCenterPositionX(this.totalIndex(total));
24724
24852
  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 };
24853
+ return { center, width, left: center - width / 2 - 2 * margin, right: center + width / 2 + margin };
24729
24854
  }
24730
24855
  /**
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.
24856
+ * The places of the periods and of the total columns on the axis, in category
24857
+ * widths, and the number of places the axis of the periods covers. A total of
24858
+ * `by: all` stands one period behind the last one, with its own axis. The
24859
+ * other totals stand right behind the last period of their group, and the
24860
+ * periods after them move on.
24737
24861
  */
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;
24862
+ totalSlots(columnWidth, categoryWidth, fontSize, scenarioOffset) {
24863
+ var _a, _b, _c;
24864
+ const count = this.dataModel.length;
24865
+ 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;
24866
+ const slots = [];
24867
+ const totals = [];
24868
+ if (this.totals.by === "all") {
24869
+ for (let index = 0; index < count; index++)
24870
+ slots.push(index);
24871
+ // the value of the band of the periods stands in the gap: the column moves right by its width.
24872
+ // Every tier of the chart knows the indicator, so the column has the same place in all of them.
24873
+ const shift = this.scalingIndicator > 0 && categoryWidth > 0
24874
+ ? (this.scalingIndicatorTextWidth() + scenarioOffset * fontSize) / (categoryWidth * fontSize)
24875
+ : 0;
24876
+ totals.push(count + 1 + extra / 2 + shift);
24877
+ return { slots: [...slots, count, ...totals], axisColumns: count };
24745
24878
  }
24879
+ // the names of the scenarios stand right of the last period: its total keeps one place of room for them.
24880
+ // A series with a scenario switch has its names under the axis.
24746
24881
  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);
24882
+ const lastRow = this.dataModel[count - 1];
24883
+ const lastIsFollower = followers.includes((_c = this.visibleSlot(lastRow, followers)) !== null && _c !== void 0 ? _c : "scenario1");
24884
+ // the second marker prints its name there too
24885
+ const markerName = !followers.includes("scenario4") && this.dataModel.some((row) => TimeChart.hasValue(row.scenario4));
24886
+ const namesRoom = lastIsFollower && !markerName ? 0 : 1;
24887
+ let offset = 0;
24888
+ let next = 0;
24889
+ for (let index = 0; index < count; index++) {
24890
+ slots.push(index + offset);
24891
+ const group = this.totalColumns[next];
24892
+ if (group != null && group.to === index) {
24893
+ const room = index === count - 1 ? namesRoom : 0;
24894
+ totals.push(index + offset + room + 1 + extra / 2);
24895
+ offset += room + 1 + extra;
24896
+ next++;
24897
+ }
24756
24898
  }
24757
- const parts = [...sums.values()];
24758
- if (parts.length === 0 || parts.some((part) => !(part.value > 0))) {
24899
+ return { slots: [...slots, count + offset, ...totals], axisColumns: count + offset };
24900
+ }
24901
+ /** The runs of periods between the total columns on the axis: each ends with the last period of a total, or of the chart. */
24902
+ totalRuns() {
24903
+ const runs = [];
24904
+ let from = 0;
24905
+ for (const column of this.totalColumns) {
24906
+ runs.push({ from, to: column.to });
24907
+ from = column.to + 1;
24908
+ }
24909
+ if (from < this.dataModel.length) {
24910
+ runs.push({ from, to: this.dataModel.length - 1 });
24911
+ }
24912
+ return runs;
24913
+ }
24914
+ /** The start of the group of a date, null for one group over all periods. */
24915
+ totalGroupStart(date, period = false) {
24916
+ var _a, _b;
24917
+ const by = (_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.by) !== null && _b !== void 0 ? _b : "all";
24918
+ if (by === "all" || date == null || !date.isValid) {
24759
24919
  return null;
24760
24920
  }
24761
- let reference = null;
24921
+ // a week belongs to the year, quarter or month of its Thursday, as its number does
24922
+ const day = period && this.dateInterval === withStyled.DateDistance.WEEK && by !== "week" ? date.plus({ days: 3 }) : date;
24923
+ return day.startOf(by);
24924
+ }
24925
+ /** The name of a total column under the axis: the text of the config at the end, else the name of its period. */
24926
+ totalLabel(start) {
24927
+ var _a, _b;
24928
+ if (start == null) {
24929
+ return (_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : "";
24930
+ }
24931
+ const interval = {
24932
+ year: withStyled.DateDistance.YEAR,
24933
+ quarter: withStyled.DateDistance.QUARTER,
24934
+ month: withStyled.DateDistance.MONTH,
24935
+ week: withStyled.DateDistance.WEEK,
24936
+ }[this.totals.by];
24937
+ return this.createDateFactory().getShortDateString(start, interval);
24938
+ }
24939
+ /** The scenarios of the series: the first one, and the ones that follow it. */
24940
+ seriesSlotKeys() {
24941
+ return ["scenario1", ...this.followerSlots()];
24942
+ }
24943
+ /** The slot of the reference of a total: the first scenario with values that is not part of the series. */
24944
+ referenceSlot() {
24945
+ const followers = this.followerSlots();
24762
24946
  for (const slot of ["scenario2", "scenario3", "scenario4"]) {
24763
24947
  if (followers.includes(slot))
24764
24948
  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;
24949
+ if (this.dataModel.some((row) => { var _a; return Number.isFinite((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.value); })) {
24950
+ return slot;
24772
24951
  }
24773
24952
  }
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
- };
24953
+ return null;
24780
24954
  }
24781
- /** Height of the total column in pixels: its parts, its reference and its band of the scaling indicator. 0 without one. */
24782
- totalColumnHeight() {
24955
+ /** The look of one column for several scenarios: a forecast wins, then a plan, then the first one. */
24956
+ mixedScenario(scenarios) {
24783
24957
  var _a, _b;
24784
- const total = this.totalColumnParts();
24785
- if (total == null) {
24958
+ 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]);
24959
+ }
24960
+ /** The rows of the totals dataset, one per group, with the scenario columns added up. */
24961
+ totalDatasetRows() {
24962
+ var _a, _b, _c, _d;
24963
+ const name = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.dataset;
24964
+ if (!name) {
24965
+ return null;
24966
+ }
24967
+ const from = withHasError.sourceExpr(this.db, name, "");
24968
+ const rows = new Map();
24969
+ if (!from) {
24970
+ return rows;
24971
+ }
24972
+ let result;
24973
+ try {
24974
+ result = this.db.exec(`SELECT * FROM ${from}`);
24975
+ }
24976
+ catch (e) {
24977
+ this.failQuery(e);
24978
+ return rows;
24979
+ }
24980
+ for (const row of result) {
24981
+ const date = TimeChart.parseDate(row.date);
24982
+ const start = date ? this.totalGroupStart(date) : null;
24983
+ const key = start ? ((_b = start.toISODate()) !== null && _b !== void 0 ? _b : "") : "";
24984
+ if (this.totals.by !== "all" && key === "")
24985
+ continue;
24986
+ const sums = (_c = rows.get(key)) !== null && _c !== void 0 ? _c : {};
24987
+ for (const [column, raw] of Object.entries(row)) {
24988
+ // a value can come as a text, like in the dataset of the chart
24989
+ const value = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
24990
+ if (column !== "date" && typeof value === "number" && Number.isFinite(value)) {
24991
+ sums[column] = ((_d = sums[column]) !== null && _d !== void 0 ? _d : 0) + value;
24992
+ }
24993
+ }
24994
+ rows.set(key, sums);
24995
+ }
24996
+ return rows;
24997
+ }
24998
+ static parseDate(value) {
24999
+ if (value instanceof Date) {
25000
+ return withHasError.DateTime.fromJSDate(value, { zone: "utc" });
25001
+ }
25002
+ if (typeof value === "string") {
25003
+ const date = withHasError.DateTime.fromISO(value, { zone: "utc" });
25004
+ return date.isValid ? date : null;
25005
+ }
25006
+ if (typeof value === "number") {
25007
+ return withHasError.DateTime.fromMillis(value, { zone: "utc" });
25008
+ }
25009
+ return null;
25010
+ }
25011
+ /**
25012
+ * The total columns of the chart. A group is the run of periods of one year,
25013
+ * quarter, month or week, or all periods. With `sum` a column stacks one part
25014
+ * per scenario of the series, else it is one column in the look of the
25015
+ * scenarios in it. The first other scenario is the reference behind. The
25016
+ * variance rows read the same list, for the same answer to "are there
25017
+ * totals". Empty without the config, with a stack, in line mode, and when a
25018
+ * part is not positive: a column cannot show that, so the chart has none.
25019
+ */
25020
+ computeTotalColumns() {
25021
+ var _a, _b, _c, _d, _e;
25022
+ if (this.totals == null ||
25023
+ this.stackConfig != null ||
25024
+ this.dataModel.length === 0 ||
25025
+ this.determineEffectiveChartMode() !== withStyled.ChartMode.BAR) {
25026
+ return [];
25027
+ }
25028
+ const followers = this.followerSlots();
25029
+ const series = this.seriesSlotKeys();
25030
+ const referenceSlot = this.referenceSlot();
25031
+ const referenceScenario = referenceSlot
25032
+ ? (_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
25033
+ : null;
25034
+ const fromData = this.totalDatasetRows();
25035
+ // the groups: runs of periods with the same start
25036
+ const groups = [];
25037
+ this.dataModel.forEach((row, index) => {
25038
+ const start = this.totalGroupStart(row.date, true);
25039
+ const last = groups[groups.length - 1];
25040
+ if (last != null && (start == null || (last.start != null && +last.start === +start))) {
25041
+ last.to = index;
25042
+ }
25043
+ else {
25044
+ groups.push({ from: index, to: index, start });
25045
+ }
25046
+ });
25047
+ // a total per period would repeat every column: `by` is not coarser than the periods of the chart
25048
+ if (this.totals.by !== "all" && groups.length === this.dataModel.length && groups.length > 1) {
25049
+ return [];
25050
+ }
25051
+ const columns = [];
25052
+ for (const group of groups) {
25053
+ const rows = this.dataModel.slice(group.from, group.to + 1);
25054
+ let parts = [];
25055
+ let reference = null;
25056
+ let counted = [];
25057
+ let scenarios;
25058
+ if (fromData != null) {
25059
+ // the values as the dataset gives them: one part per scenario of the series
25060
+ const data = (_c = fromData.get(group.start ? ((_b = group.start.toISODate()) !== null && _b !== void 0 ? _b : "") : "")) !== null && _c !== void 0 ? _c : {};
25061
+ for (const slot of series) {
25062
+ 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;
25063
+ // a 0 is a scenario without a value in this total
25064
+ if (scenario != null && Number.isFinite(data[scenario]) && data[scenario] !== 0) {
25065
+ parts.push({ scenario, value: data[scenario] });
25066
+ }
25067
+ }
25068
+ if (referenceScenario != null && Number.isFinite(data[referenceScenario])) {
25069
+ reference = { scenario: referenceScenario, value: data[referenceScenario] };
25070
+ }
25071
+ scenarios = parts.map((part) => part.scenario);
25072
+ if (this.totals.aggregation !== "sum" && parts.length > 1 && parts.every((part) => part.value > 0)) {
25073
+ // an average or a last value is one column: the dataset gives the value, not its parts
25074
+ parts = [
25075
+ { scenario: this.mixedScenario(scenarios), value: parts.reduce((sum, part) => sum + part.value, 0) },
25076
+ ];
25077
+ }
25078
+ }
25079
+ else {
25080
+ // the periods where the series has a value. The reference counts in the same periods only,
25081
+ // as the variance of the total does: else the two would not tell the same.
25082
+ const used = rows.filter((row) => {
25083
+ var _a;
25084
+ const slot = this.visibleSlot(row, followers);
25085
+ return slot != null && Number.isFinite((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.value);
25086
+ });
25087
+ counted = used.map((row) => this.dataModel.indexOf(row));
25088
+ scenarios = [...new Set(used.map((row) => row[this.visibleSlot(row, followers)].scenario))];
25089
+ const visible = used.map((row) => row[this.visibleSlot(row, followers)]);
25090
+ // with `last` the one period that gives the value counts. A reference with a gap in
25091
+ // the counted periods is no reference: half a sum would stand against a full one.
25092
+ const referenceRows = this.totals.aggregation === "last" ? used.slice(-1) : used;
25093
+ const found = referenceSlot
25094
+ ? referenceRows.map((row) => row[referenceSlot]).filter((point) => Number.isFinite(point === null || point === void 0 ? void 0 : point.value))
25095
+ : [];
25096
+ const references = found.length === referenceRows.length ? found : [];
25097
+ const sum = (points) => points.reduce((total, point) => total + point.value, 0);
25098
+ if (this.totals.aggregation === "sum") {
25099
+ const sums = new Map();
25100
+ for (const point of visible) {
25101
+ sums.set(point.scenario, ((_e = sums.get(point.scenario)) !== null && _e !== void 0 ? _e : 0) + point.value);
25102
+ }
25103
+ parts = [...sums.entries()].map(([scenario, value]) => ({ scenario, value }));
25104
+ if (references.length > 0) {
25105
+ reference = { scenario: referenceScenario, value: sum(references) };
25106
+ }
25107
+ }
25108
+ else if (visible.length > 0) {
25109
+ const last = this.totals.aggregation === "last";
25110
+ parts = [
25111
+ {
25112
+ scenario: last
25113
+ ? visible[visible.length - 1].scenario
25114
+ : this.mixedScenario(visible.map((point) => point.scenario)),
25115
+ value: last ? visible[visible.length - 1].value : sum(visible) / visible.length,
25116
+ },
25117
+ ];
25118
+ if (references.length > 0) {
25119
+ reference = {
25120
+ scenario: referenceScenario,
25121
+ value: last ? references[references.length - 1].value : sum(references) / references.length,
25122
+ };
25123
+ }
25124
+ }
25125
+ }
25126
+ if (parts.length === 0) {
25127
+ // a group without a value of the series has no total, the others keep theirs
25128
+ continue;
25129
+ }
25130
+ if (parts.some((part) => !(part.value > 0))) {
25131
+ return [];
25132
+ }
25133
+ const total = parts.reduce((sum, part) => sum + part.value, 0);
25134
+ columns.push(Object.assign(Object.assign({}, group), { label: this.totalLabel(group.start), parts, total, reference, counted, scenarios }));
25135
+ }
25136
+ return columns;
25137
+ }
25138
+ /** Height of the highest total column in pixels: its parts, its reference and its band of the scaling indicator. */
25139
+ totalsHeight() {
25140
+ if (!this.hasTotals()) {
24786
25141
  return 0;
24787
25142
  }
24788
25143
  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;
25144
+ 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); }));
25145
+ return Math.max(units, band) * this.totals.pixelPerUnit;
24790
25146
  }
24791
25147
  /**
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.
25148
+ * The variances of the total columns in a variance chart, one per column:
25149
+ * the series against the reference, put together the way the total is. With
25150
+ * a dataset the values come from its row. A total takes the notation of the
25151
+ * forecast when a forecast is part of it.
24795
25152
  */
24796
- totalVariancePoint() {
24797
- var _a, _b, _c, _d, _e, _f;
24798
- if (!this.hasTotalColumn() || !this.isVarianceChart()) {
24799
- return null;
25153
+ computeTotalVariances() {
25154
+ var _a, _b;
25155
+ if (!this.hasTotals() || !this.isVarianceChart()) {
25156
+ return [];
24800
25157
  }
24801
25158
  const firstRow = (_a = this.dataModel[0]) !== null && _a !== void 0 ? _a : null;
24802
25159
  const candidates = ((_b = this.configVariances) !== null && _b !== void 0 ? _b : [])
24803
25160
  .map((name) => ({ name, variance: new VarianceScenario(name) }))
24804
25161
  .filter((entry) => entry.variance.isValid);
24805
25162
  if (candidates.length === 0) {
24806
- return null;
25163
+ return [];
24807
25164
  }
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;
25165
+ const first = candidates[0].variance;
25166
+ const relative = first.type === VarianceType.RELATIVE;
25167
+ const fromData = this.totalDatasetRows();
25168
+ const aggregation = this.totals.aggregation;
25169
+ return this.totalColumns.map((column) => {
25170
+ var _a, _b, _c, _d, _e, _f;
25171
+ let base;
25172
+ let delta;
25173
+ const notations = new Set();
25174
+ if (fromData != null) {
25175
+ base = 0;
25176
+ const data = (_b = fromData.get(column.start ? ((_a = column.start.toISODate()) !== null && _a !== void 0 ? _a : "") : "")) !== null && _b !== void 0 ? _b : {};
25177
+ // the bases of the row are the scenarios of the series, each counts once
25178
+ const bases = new Set(candidates.map((entry) => entry.variance.base));
25179
+ // a row for a part of the series only has no total: the reference of the dataset is the one of the whole total
25180
+ const covered = column.scenarios.filter((scenario) => bases.has(scenario)).length;
25181
+ if (covered > 0 && covered < column.scenarios.length) {
25182
+ return null;
25183
+ }
25184
+ for (const name of bases) {
25185
+ // a 0 is a scenario without a value in this total, as for the parts
25186
+ if (Number.isFinite(data[name]) && data[name] !== 0) {
25187
+ base += data[name];
25188
+ notations.add(name.slice(0, 2));
25189
+ }
24821
25190
  }
25191
+ if (notations.size === 0 || !Number.isFinite(data[first.delta])) {
25192
+ return null;
25193
+ }
25194
+ delta = data[first.delta];
24822
25195
  }
25196
+ else {
25197
+ // the same periods as the column, so the two tell the same: with `last` the one
25198
+ // period of the value. Without both values in each of them there is no variance.
25199
+ const rows = (aggregation === "last" ? column.counted.slice(-1) : column.counted).map((index) => this.dataModel[index]);
25200
+ const pairs = [];
25201
+ for (const row of rows) {
25202
+ for (const { variance } of candidates) {
25203
+ const slots = this.mapScenarios(variance, firstRow);
25204
+ const baseValue = (_d = row[(_c = slots.get(variance.base)) !== null && _c !== void 0 ? _c : ""]) === null || _d === void 0 ? void 0 : _d.value;
25205
+ const deltaValue = (_f = row[(_e = slots.get(variance.delta)) !== null && _e !== void 0 ? _e : ""]) === null || _f === void 0 ? void 0 : _f.value;
25206
+ if (Number.isFinite(baseValue) && Number.isFinite(deltaValue)) {
25207
+ pairs.push({ base: baseValue, delta: deltaValue, notation: variance.base.slice(0, 2) });
25208
+ break;
25209
+ }
25210
+ }
25211
+ }
25212
+ if (pairs.length === 0 || pairs.length !== rows.length) {
25213
+ return null;
25214
+ }
25215
+ const divisor = aggregation === "average" ? pairs.length : 1;
25216
+ base = pairs.reduce((sum, pair) => sum + pair.base, 0) / divisor;
25217
+ delta = pairs.reduce((sum, pair) => sum + pair.delta, 0) / divisor;
25218
+ pairs.forEach((pair) => notations.add(pair.notation));
25219
+ }
25220
+ const point = new DataPoint(relative ? withStyled.relativeVariance(base - delta, delta) : base - delta, first.delta, relative ? this.pixelPerPercentage : this.pixelPerUnit, first.direction);
25221
+ if (this.scenarioSwitch) {
25222
+ point.notation = notations.has("fc") ? "fc" : notations.size === 1 ? [...notations][0] : "ac";
25223
+ }
25224
+ point.key = this.totalKey(column, candidates[0].name);
25225
+ return point;
25226
+ });
25227
+ }
25228
+ /** The point key of an element of a total column: `row: total`, and the start of its group when there are several. */
25229
+ totalKey(column, scenario) {
25230
+ const key = { row: "total" };
25231
+ if (column.start != null) {
25232
+ key.date = TimeChart.pointDate(column.start);
24823
25233
  }
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";
25234
+ if (scenario) {
25235
+ key.scenario = scenario;
24832
25236
  }
24833
- point.key = { row: "total", scenario: candidates[0].name };
24834
- return point;
25237
+ return key;
24835
25238
  }
24836
- /** Width of the texts right of the total column: the names of its parts, and the value of the scaling indicator. */
24837
- totalColumnTextWidth() {
25239
+ /** Width of the texts right of the total column at the end: the names of its parts, and the value of its band. */
25240
+ endTotalTextWidth() {
25241
+ if (!this.hasEndTotal()) {
25242
+ return 0;
25243
+ }
24838
25244
  const width = (text) => CalculateSize(text, { font: this.styles.fontStyles.font, fontSize: this.styles.fontStyles.size + "px" }).width;
24839
25245
  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;
25246
+ const parts = this.totalColumns[0].parts;
25247
+ const names = !this.isVarianceChart() && parts.length > 1
25248
+ ? gap + Math.max(...parts.map((part) => width(this.scenarioName(part.scenario))))
25249
+ : 0;
25250
+ const indicator = this.hasScalingIndicator() ? gap + width(this.scalingIndicatorText()) : 0;
24846
25251
  return names + indicator;
24847
25252
  }
24848
25253
  scenarioName(scenario) {
@@ -24863,131 +25268,137 @@ class TimeChart {
24863
25268
  solid: pattern ? null : color,
24864
25269
  };
24865
25270
  }
24866
- /** The axis of the total column: its own piece of line, in the look of the axis of the chart. */
25271
+ /** The axis of the total column at the end: its own piece of line, in the look of the axis of the chart. */
24867
25272
  drawTotalAxis(group, y) {
24868
- const { left, right } = this.totalColumnGeometry();
25273
+ const { left, right } = this.totalGeometry(0);
24869
25274
  const scenario = this.axisScenario == null ? "default" : `${this.axisScenario}`.slice(0, 2);
24870
25275
  group.line(left, y, right, y).addClass("axis-" + scenario);
24871
25276
  }
24872
25277
  /**
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.
25278
+ * The total columns of the base chart, at their own scale: the parts, the
25279
+ * reference behind, the total above and the name under the axis. With a
25280
+ * scaling indicator a column has its own band. The column at the end has its
25281
+ * own axis and the names of its parts at the right, and a line links its band
25282
+ * to the band of the periods.
24877
25283
  */
24878
- drawTotalColumn(svgContainer) {
24879
- const total = this.isVarianceChart() ? null : this.totalColumnParts();
24880
- if (total == null) {
25284
+ drawTotalColumns(svgContainer) {
25285
+ if (!this.hasTotals() || this.isVarianceChart()) {
24881
25286
  return;
24882
25287
  }
24883
- const { center, width, left, right } = this.totalColumnGeometry();
24884
- const scale = this.totalColumn.pixelPerUnit;
25288
+ const scale = this.totals.pixelPerUnit;
24885
25289
  const axisY = this.position.getColumnPositionY();
24886
25290
  const gap = this.position.spacings.labelToColumn;
25291
+ const atEnd = this.hasEndTotal();
24887
25292
  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
25293
  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);
25294
+ this.totalColumns.forEach((column, index) => {
25295
+ const { center, width, left, right } = this.totalGeometry(index);
25296
+ if (this.hasScalingIndicator()) {
25297
+ const height = this.scalingIndicator * scale;
25298
+ const periods = this.scalingIndicatorBand();
25299
+ const band = group
25300
+ .rect(right - left, height)
25301
+ .x(left)
25302
+ .y(axisY - height)
25303
+ .fill(SCALING_INDICATOR_FILL);
25304
+ // behind the columns of the periods that stand next to it
25305
+ band.back();
25306
+ if (atEnd && periods != null) {
25307
+ // the line starts behind the value of the band of the periods
25308
+ const from = this.scalingIndicatorLabelX() + this.scalingIndicatorTextWidth() + gap / 2;
25309
+ group
25310
+ .line(Math.min(from, left), axisY - periods.height, left, axisY - height)
25311
+ .stroke({ color: SCALING_INDICATOR_LINE, width: 1 })
25312
+ .id("ScalingIndicatorLink");
24937
25313
  }
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
25314
  }
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();
25315
+ if (column.reference != null && column.reference.value > 0) {
25316
+ const look = this.columnLook(column.reference.scenario);
25317
+ const height = column.reference.value * scale;
25318
+ group
25319
+ .rect(width, height)
25320
+ .cx(center - this.position.spacings.scenarioOffset)
25321
+ .y(axisY - height)
25322
+ .fill(look.fill)
25323
+ .stroke(look.stroke)
25324
+ .attr(dataPointAttributes(this.totalKey(column, column.reference.scenario), "element"))
25325
+ .attr("data-bn-value", column.reference.value);
25326
+ }
25327
+ let top = axisY;
25328
+ for (const part of column.parts) {
25329
+ const look = this.columnLook(part.scenario);
25330
+ const height = part.value * scale;
25331
+ top -= height;
25332
+ const key = this.totalKey(column, part.scenario);
25333
+ group
25334
+ .rect(width, height)
25335
+ .cx(center)
25336
+ .y(top)
25337
+ .fill(look.fill)
25338
+ .stroke(look.stroke)
25339
+ .attr(dataPointAttributes(key, "element"))
25340
+ .attr("data-bn-value", part.value);
25341
+ if (column.parts.length > 1) {
25342
+ if (height >= this.position.dataLabelHeight) {
25343
+ const label = new Label$1(labelGroup, center, top + height / 2, "TOTAL_PART", part.value, this.styles, HookLocation$1.Center, HookLocation$1.Center).setPoint(key);
25344
+ // a label on a hatching keeps the background of a plain label
25345
+ (look.solid ? label.setSegmentFill(look.solid) : label).draw(true, this.dataFormatDigits, this.measureScale);
25346
+ }
25347
+ if (atEnd) {
25348
+ new Label$1(labelGroup, center + width / 2 + gap,
25349
+ // the name of a thin top part stays below the total above the column
25350
+ 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();
25351
+ }
25352
+ }
25353
+ }
25354
+ new Label$1(labelGroup, center, top - gap, "TOTAL", column.total, this.styles, HookLocation$1.Bottom, HookLocation$1.Center)
25355
+ .setPoint(this.totalKey(column), "total")
25356
+ .draw(true, this.dataFormatDigits, this.measureScale);
25357
+ if (this.hideAxisLabels === false && column.label) {
25358
+ 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();
25359
+ }
25360
+ });
25361
+ if (atEnd) {
25362
+ this.drawTotalAxis(group, this.position.getAxisPositionY(false));
25363
+ if (this.hasScalingIndicator()) {
25364
+ 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();
25365
+ }
24957
25366
  }
24958
25367
  }
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) {
25368
+ /** The variances of the total columns, in the tier of their variance chart: columns or pins like the others. */
25369
+ drawTotalVariances(svgContainer) {
24961
25370
  var _a;
24962
- const point = this.totalVariance;
24963
- if (point == null) {
25371
+ if (!this.totalVariances.some((point) => point != null)) {
24964
25372
  return;
24965
25373
  }
24966
25374
  // inside the group of the variances: its box is the height of the row, also below the axis
24967
25375
  const scenarios = (_a = svgContainer.findOne("#Scenarios")) !== null && _a !== void 0 ? _a : svgContainer.group().id("Scenarios");
24968
25376
  const group = scenarios.group().id("TotalColumn");
24969
25377
  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
25378
  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 {
25379
+ this.totalVariances.forEach((point, total) => {
25380
+ if (point == null) {
25381
+ return;
25382
+ }
25383
+ const index = this.totalIndex(total);
25384
+ if (relative) {
25385
+ new Needle(this.position, this.scenarioStyles(), point, index, group.group())
25386
+ .updateLabelGroup(labelGroup.group())
25387
+ .draw(this.dataFormatDigits);
25388
+ return;
25389
+ }
24981
25390
  // 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.
25391
+ // break is scaled by the largest overflow: that can be the one of the total.
24983
25392
  const overflow = this.overflowConfig
24984
25393
  ? Object.assign(Object.assign({}, this.overflowConfig), { maxOverflow: Math.max(this.overflowConfig.maxOverflow, point.getScaledUnit() - (this.overflowConfig.cutHeight - this.overflowConfig.scenarioCutOffset)) }) : null;
24985
25394
  new Column(this.position, this.scenarioStyles(), point, index, true, group.group(), null, overflow)
24986
25395
  .updateLabelGroup(labelGroup.group())
24987
25396
  .setAsVariance()
24988
25397
  .draw(this.dataFormatDigits, this.measureScale);
25398
+ });
25399
+ if (this.hasEndTotal()) {
25400
+ this.drawTotalAxis(group, this.position.getAxisPositionY(relative));
24989
25401
  }
24990
- this.drawTotalAxis(group, this.position.getAxisPositionY(relative));
24991
25402
  const box = scenarios.bbox();
24992
25403
  this.scenariosArea = {
24993
25404
  height: box.height + this.styles.padding.top + this.styles.padding.bottom,
@@ -25064,6 +25475,7 @@ class TimeChart {
25064
25475
  return new Map([...defaultI18n, ...i18n]);
25065
25476
  }
25066
25477
  createElementPosition(scenarios) {
25478
+ var _a, _b;
25067
25479
  let maxLabelLengthLeft;
25068
25480
  // only need scenarios written on the leftside of bar/ marker
25069
25481
  const scenarioLabelLeft = CalculateSize(scenarios
@@ -25107,7 +25519,7 @@ class TimeChart {
25107
25519
  if (this.overflowConfig) {
25108
25520
  const { cutHeight, overdriveZoneHeight, breakGap } = this.overflowConfig;
25109
25521
  // 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());
25522
+ const virtualHeight = Math.max(cutHeight + overdriveZoneHeight + breakGap, this.isVarianceChart() ? 0 : this.totalsHeight());
25111
25523
  // Create a virtual DataPoint with pixelPerUnit=1 so getScaledUnit() returns virtualHeight directly
25112
25524
  max = new DataPoint(virtualHeight, max.scenario, 1, max.variance);
25113
25525
  }
@@ -25138,7 +25550,13 @@ class TimeChart {
25138
25550
  effectiveScaleFactors = cloned;
25139
25551
  }
25140
25552
  }
25141
- return new ElementPositions(new Padding(this.styles.padding), effectiveScaleFactors, this.styles.fontStyles, min, max, this.dataModel.length, maxLabelLengthLeft);
25553
+ // total columns take places on the axis: the periods behind them move on
25554
+ const places = this.hasTotals()
25555
+ ? this.totalSlots(effectiveScaleFactors.columnWidth, effectiveScaleFactors.categoryWidth, this.styles.fontStyles.size, effectiveScaleFactors.scenarioOffset)
25556
+ : null;
25557
+ 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);
25558
+ position.setSlots((_b = places === null || places === void 0 ? void 0 : places.slots) !== null && _b !== void 0 ? _b : null);
25559
+ return position;
25142
25560
  }
25143
25561
  calculateTitleLength(minWidth) {
25144
25562
  let tmpTitle = "_______"; // default width if this.title is sorther
@@ -25676,7 +26094,8 @@ class TimeChart {
25676
26094
  const bottom = namesHeight > 0 ? height - this.styles.padding.bottom : height;
25677
26095
  const lineWidth = Math.max(1, this.position.spacings.auxiliaryLineWidth);
25678
26096
  runs.slice(1).forEach((run) => {
25679
- const x = (this.position.getColumnCenterPositionX(run.from - 1) + this.position.getColumnCenterPositionX(run.from)) / 2;
26097
+ // half a period before the first period of the run: a total column can stand between the two runs
26098
+ const x = this.position.getColumnCenterPositionX(run.from) - this.position.spacings.categoryWidth / 2;
25680
26099
  group
25681
26100
  .line(x, 0, x, bottom)
25682
26101
  .stroke({ color: this.styles.fontStyles.color || "#000000", width: lineWidth })
@@ -26491,8 +26910,8 @@ class TimeChartComponentConfig {
26491
26910
  this.axisLabelsStep = 1;
26492
26911
  /** Value of the scaling indicator band, 0 for none. */
26493
26912
  this.scalingIndicator = 0;
26494
- /** The column for the total of all periods, null for none. */
26495
- this.totalColumn = null;
26913
+ /** The total columns, null for none. */
26914
+ this.totals = null;
26496
26915
  /** One series that changes its scenario along the time axis, see `bn-chart-time`. */
26497
26916
  this.scenarioSwitch = false;
26498
26917
  /** Side of the axis title: left, right or none. */
@@ -26585,12 +27004,19 @@ class TimeChartComponentConfigAdapter {
26585
27004
  if (withStyled.CompareUtil.isNumber(data.scalingIndicator) && data.scalingIndicator > 0) {
26586
27005
  config.scalingIndicator = data.scalingIndicator;
26587
27006
  }
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,
27007
+ const totals = data.totals;
27008
+ if (totals != null && withStyled.CompareUtil.isNumber(totals.pixelPerUnit) && totals.pixelPerUnit > 0) {
27009
+ const by = ["all", "year", "quarter", "month", "week"].includes(totals.by) ? totals.by : "all";
27010
+ const aggregation = ["sum", "average", "last"].includes(totals.aggregation)
27011
+ ? totals.aggregation
27012
+ : "sum";
27013
+ config.totals = {
27014
+ by,
27015
+ aggregation,
27016
+ pixelPerUnit: totals.pixelPerUnit,
27017
+ label: typeof totals.label === "string" ? totals.label : "",
27018
+ width: withStyled.CompareUtil.isNumber(totals.width) && totals.width > 0 ? totals.width : 1,
27019
+ dataset: typeof totals.dataset === "string" ? totals.dataset : "",
26594
27020
  };
26595
27021
  }
26596
27022
  if (withStyled.CompareUtil.isBoolean(data.scenarioSwitch)) {
@@ -26680,7 +27106,7 @@ const BnChartTimeRenderer = class {
26680
27106
  /** @internal */
26681
27107
  this.scalingIndicator = 0;
26682
27108
  /** @internal */
26683
- this.totalColumn = null;
27109
+ this.totals = null;
26684
27110
  /** @internal */
26685
27111
  this.scenarioSwitch = false;
26686
27112
  /** @internal */
@@ -26972,7 +27398,7 @@ const BnChartTimeRenderer = class {
26972
27398
  lineFullWidth: this.lineFullWidth,
26973
27399
  axisLabelsStep: this.axisLabelsStep,
26974
27400
  scalingIndicator: this.scalingIndicator,
26975
- totalColumn: this.totalColumn,
27401
+ totals: this.totals,
26976
27402
  scenarioSwitch: this.scenarioSwitch,
26977
27403
  axisTitlePosition: this.axisTitlePosition,
26978
27404
  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",