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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-ac917d72.entry.js → p-7b74696e.entry.js} +1 -1
  3. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +688 -266
  4. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/collection/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.js +8 -8
  7. package/dist/collection/components/bn-chart-time/bn-chart-time.js +115 -34
  8. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +534 -221
  9. package/dist/collection/components/bn-chart-time/utils/helper/ElementPositions.js +23 -1
  10. package/dist/collection/components/bn-chart-time/utils/model/TimeChartComponentConfig.js +15 -8
  11. package/dist/components/bn-chart-time-renderer.js +1 -1
  12. package/dist/components/bn-chart-time.js +1 -1
  13. package/dist/components/p-C3-kXJUZ.js +1 -0
  14. package/dist/esm/bn-annotation-layer_30.entry.js +688 -266
  15. package/dist/esm/bn-template-engine.js +1 -1
  16. package/dist/esm/loader.js +1 -1
  17. package/dist/types/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.d.ts +2 -2
  18. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +29 -16
  19. package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +63 -30
  20. package/dist/types/components/bn-chart-time/utils/helper/ElementPositions.d.ts +8 -0
  21. package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +16 -7
  22. package/dist/types/components.d.ts +8 -8
  23. package/package.json +1 -1
  24. package/dist/components/p-D-JwLFMJ.js +0 -1
@@ -1,3 +1,15 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s)
4
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
1
13
  import { forceUpdate, h, Host, writeTask } from "@stencil/core";
2
14
  import { hasInlineJs } from "../../context/scopedDb";
3
15
  import { isBlankInput, isValidAxisLabelsMode, isValidDateFormat, isValidInteger, isValidMeasureScale, isNoScenarios, isValidNumber, validateScenarioList, validateStackConfig, validateVariancesList, } from "../../utils/validate";
@@ -19,6 +31,7 @@ import { observeParentResize } from "../../utils/layoutObserver";
19
31
  import { VarianceScenario, variancesScenarios } from "../../utils/model/VarianceScenario";
20
32
  import { Formatter } from "../../utils/formatter";
21
33
  import { AxisLabelsMode, ChartMode, StackBy, StackMode, StackOrder } from "../../utils/constants";
34
+ import { getStores } from "../../context/context-protocol";
22
35
  import { DateDistance } from "../../utils/DateStringFactory";
23
36
  import { LAYOUT_STATE_VERSION, collectChartFacadeLayout, measure, originsFor, readDiagnostics, readChartBaseline, resolveStandaloneId, } from "../../utils/layoutState";
24
37
  import { syncEmptyState } from "../../utils/emptyState";
@@ -255,38 +268,79 @@ export class Chart {
255
268
  this.errors.remove(errId);
256
269
  }
257
270
  }
258
- validateTotalColumn(newValue) {
259
- const errId = "WARN_totalColumn";
260
- if (isBlankInput(newValue) || this.parseTotalColumn(newValue) != null) {
271
+ validateTotals(newValue) {
272
+ const errId = "WARN_totals";
273
+ if (isBlankInput(newValue) || this.parseTotals(newValue) != null) {
261
274
  this.errors.remove(errId);
262
275
  }
263
276
  else {
264
277
  this.errors.addOrReplace({
265
278
  id: errId,
266
279
  type: "warning",
267
- message: 'totalColumn: needs JSON with a unitScaling greater than 0, for example {"unitScaling":280}.',
280
+ 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}.',
268
281
  });
269
282
  }
283
+ this.bindTotalsDataset();
270
284
  }
271
- parseTotalColumn(value) {
285
+ parseTotals(value) {
286
+ var _a, _b;
272
287
  try {
273
288
  const parsed = JSON.parse(value);
274
289
  // the same values as `unit-scaling`: a number, with an SI suffix, or the name of a scaling group
275
290
  const scaling = resolveScalingValue(parsed === null || parsed === void 0 ? void 0 : parsed.unitScaling, this.pixelPerUnitGroupMap);
276
291
  if (scaling.kind !== "value" || !(scaling.value > 0))
277
292
  return null;
293
+ const by = (_a = parsed.by) !== null && _a !== void 0 ? _a : "all";
294
+ const aggregation = (_b = parsed.aggregation) !== null && _b !== void 0 ? _b : "sum";
295
+ if (!["all", "year", "quarter", "month", "week"].includes(by))
296
+ return null;
297
+ if (!["sum", "average", "last"].includes(aggregation))
298
+ return null;
278
299
  const width = Number(parsed.width);
279
300
  const label = typeof parsed.label === "string" || typeof parsed.label === "number" ? String(parsed.label) : "";
280
- return { unitScaling: scaling.value, label, width: width > 0 ? width : 1 };
301
+ return {
302
+ unitScaling: scaling.value,
303
+ by,
304
+ aggregation,
305
+ label,
306
+ width: width > 0 ? width : 1,
307
+ dataset: typeof parsed.dataset === "string" ? parsed.dataset.trim() : "",
308
+ };
281
309
  }
282
- catch (_a) {
310
+ catch (_c) {
283
311
  return null;
284
312
  }
285
313
  }
286
- /** The total column in the units of the inner chart: pixels for one data unit. */
287
- prepareTotalColumn() {
288
- const parsed = isBlankInput(this.totalColumn) ? null : this.parseTotalColumn(this.totalColumn);
289
- const errId = "WARN_totalColumn_unitScaling";
314
+ /** Draws the chart again when the dataset of the totals gets its rows. */
315
+ bindTotalsDataset() {
316
+ var _a, _b;
317
+ // from the plain JSON: the name does not depend on a scaling group that may get its value later
318
+ let name;
319
+ try {
320
+ const dataset = isBlankInput(this.totals) ? "" : (_a = JSON.parse(this.totals)) === null || _a === void 0 ? void 0 : _a.dataset;
321
+ name = typeof dataset === "string" ? dataset.trim() : "";
322
+ }
323
+ catch (_c) {
324
+ name = "";
325
+ }
326
+ // an element that is not in the page has no subscription: it binds when it connects
327
+ if (!this.element.isConnected)
328
+ return;
329
+ if (name === this.totalsDatasetName)
330
+ return;
331
+ (_b = this.totalsDatasetUnsubscribe) === null || _b === void 0 ? void 0 : _b.call(this);
332
+ this.totalsDatasetUnsubscribe = null;
333
+ this.totalsDatasetName = name;
334
+ if (name) {
335
+ this.totalsDatasetUnsubscribe = getStores(this.element).db.subscribe(name, () => {
336
+ this.dataVersion++;
337
+ });
338
+ }
339
+ }
340
+ /** The totals in the units of the inner chart: pixels for one data unit. */
341
+ prepareTotals() {
342
+ const parsed = isBlankInput(this.totals) ? null : this.parseTotals(this.totals);
343
+ const errId = "WARN_totals_unitScaling";
290
344
  if (parsed == null) {
291
345
  this.errors.remove(errId);
292
346
  return null;
@@ -296,12 +350,22 @@ export class Chart {
296
350
  this.errors.addOrReplace({
297
351
  id: errId,
298
352
  type: "warning",
299
- message: "totalColumn: needs a fixed unitScaling of the chart, the total column is not drawn.",
353
+ message: "totals: needs a fixed unitScaling of the chart, the total columns are not drawn.",
354
+ });
355
+ return null;
356
+ }
357
+ // without the columns each variance row would decide on its own which periods have a total
358
+ if (this.hidesScenarios()) {
359
+ this.errors.addOrReplace({
360
+ id: errId,
361
+ type: "warning",
362
+ message: "totals: needs the columns of the chart, a chart with scenarios none draws no total columns.",
300
363
  });
301
364
  return null;
302
365
  }
303
366
  this.errors.remove(errId);
304
- return { pixelPerUnit: this.getEffectiveFontPx() / parsed.unitScaling, label: parsed.label, width: parsed.width };
367
+ const { unitScaling } = parsed, rest = __rest(parsed, ["unitScaling"]);
368
+ return Object.assign(Object.assign({}, rest), { pixelPerUnit: this.getEffectiveFontPx() / unitScaling });
305
369
  }
306
370
  validateAxisLabelsStep(newValue) {
307
371
  const errId = "WARN_axisLabelsStep";
@@ -504,22 +568,32 @@ export class Chart {
504
568
  */
505
569
  this.axisLabelsStep = 1;
506
570
  /**
507
- * A column right of the last period for the total of all periods, at its own
508
- * scale, as JSON: `{"unitScaling":280,"label":"2025","width":1.6}`.
571
+ * Total columns at their own scale, as JSON:
572
+ * `{"by":"all","aggregation":"sum","unitScaling":280,"label":"2025","width":1.6}`.
509
573
  *
510
574
  * - `unitScaling` - data units per em of column height, like `unit-scaling`. Required.
511
- * - `label` - text under the column.
575
+ * - `by` - what a total covers. `all` (default): one column right of the last
576
+ * period for all periods. `year`, `quarter`, `month`, `week`: one column
577
+ * behind the periods of each of them, on the axis.
578
+ * - `aggregation` - `sum` (default), `average` or `last`. With `sum` a column
579
+ * stacks one part per scenario of the series: the first scenario, and with
580
+ * `scenario-switch` the ones that follow it. Else it is one column, hatched
581
+ * when a forecast is in its value and outlined for a plan.
582
+ * - `dataset` - name of a dataset with one row per total (`date` and the
583
+ * scenario columns). The chart takes the values from it and computes none.
584
+ * - `label` - text under the column of `by: all`. The other columns take the name of their period.
512
585
  * - `width` - width in widths of a period column, default 1.
513
586
  *
514
- * The column stacks one part per scenario of the series: the first scenario,
515
- * and with `scenario-switch` the ones that follow it. The first other
516
- * scenario is the reference behind it. Each variance row gets the variance
517
- * of the totals at the scale of the row. With `scaling-indicator` the column
518
- * has its own band, and a line links the two bands. Plain columns only: not
519
- * with `stack` and not in line mode. The chart needs a fixed `unit-scaling`,
520
- * and every part of the total must be positive.
587
+ * The first other scenario is the reference behind a column. Each variance
588
+ * row gets the variance of each total at the scale of the row. With
589
+ * `scaling-indicator` a column has its own band, and with `by: all` a line
590
+ * links it to the band of the periods. Plain columns only: not with `stack`
591
+ * and not in line mode. The chart needs a fixed `unit-scaling`, and every
592
+ * part of a total must be positive.
521
593
  */
522
- this.totalColumn = "";
594
+ this.totals = "";
595
+ this.totalsDatasetUnsubscribe = null;
596
+ this.totalsDatasetName = "";
523
597
  /**
524
598
  * For a series that changes its scenario along the time axis, for example
525
599
  * AC up to this year and PL after it. In a period where the first scenario
@@ -624,7 +698,7 @@ export class Chart {
624
698
  this.validateDataFormatDigitsDecimal(this.dataFormatDigitsDecimal);
625
699
  this.validateDataFormatDigitsPercent(this.dataFormatDigitsPercent);
626
700
  this.validateAxisLabelsStep(this.axisLabelsStep);
627
- this.validateTotalColumn(this.totalColumn);
701
+ this.validateTotals(this.totals);
628
702
  this.validateAxisTitlePosition(this.axisTitlePosition);
629
703
  }
630
704
  /**
@@ -835,9 +909,16 @@ export class Chart {
835
909
  };
836
910
  this._settleTimer = setTimeout(check, delays.shift());
837
911
  }
912
+ connectedCallback() {
913
+ // an element that is moved in the page comes back without its subscription
914
+ this.bindTotalsDataset();
915
+ }
838
916
  disconnectedCallback() {
839
- var _a;
840
- (_a = this.layoutObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
917
+ var _a, _b;
918
+ (_a = this.totalsDatasetUnsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
919
+ this.totalsDatasetUnsubscribe = null;
920
+ this.totalsDatasetName = "";
921
+ (_b = this.layoutObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
841
922
  this.layoutObserver = null;
842
923
  if (this._settleTimer != null) {
843
924
  clearTimeout(this._settleTimer);
@@ -1290,7 +1371,7 @@ export class Chart {
1290
1371
  percent: this.dataFormatDigitsPercent,
1291
1372
  decimal: this.dataFormatDigitsDecimal,
1292
1373
  percentSign: this.dataFormatPercentSign !== false,
1293
- }, 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() }));
1374
+ }, 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() }));
1294
1375
  }
1295
1376
  /**
1296
1377
  * The line this chart wants to be aligned on, in CSS px from the host's
@@ -1422,7 +1503,7 @@ export class Chart {
1422
1503
  this.errors.remove("WARN_scenarios_none");
1423
1504
  }
1424
1505
  const fontStyles = this.getFontStyles();
1425
- return (h(Host, { key: 'c54e501bbea51b366b8a07e578b6cdecec662477', style: fontStyles }, h("div", { key: 'c232324e6c09f86881f60b5af9e84d4a80e49bd2', class: "container" }, segments.map(this.chartTemplate))));
1506
+ return (h(Host, { key: '1b6a2c72252e0f0c437815ea71652bc6ca7bb90c', style: fontStyles }, h("div", { key: '1df2b96475b83b11c197a00efed98b2e60a05ed9', class: "container" }, segments.map(this.chartTemplate))));
1426
1507
  }
1427
1508
  static get is() { return "bn-chart-time"; }
1428
1509
  static get encapsulation() { return "shadow"; }
@@ -2050,7 +2131,7 @@ export class Chart {
2050
2131
  "reflect": false,
2051
2132
  "attribute": "scaling-indicator"
2052
2133
  },
2053
- "totalColumn": {
2134
+ "totals": {
2054
2135
  "type": "string",
2055
2136
  "mutable": false,
2056
2137
  "complexType": {
@@ -2062,12 +2143,12 @@ export class Chart {
2062
2143
  "optional": false,
2063
2144
  "docs": {
2064
2145
  "tags": [],
2065
- "text": "A column right of the last period for the total of all periods, at its own\nscale, as JSON: `{\"unitScaling\":280,\"label\":\"2025\",\"width\":1.6}`.\n\n- `unitScaling` - data units per em of column height, like `unit-scaling`. Required.\n- `label` - text under the column.\n- `width` - width in widths of a period column, default 1.\n\nThe column stacks one part per scenario of the series: the first scenario,\nand with `scenario-switch` the ones that follow it. The first other\nscenario is the reference behind it. Each variance row gets the variance\nof the totals at the scale of the row. With `scaling-indicator` the column\nhas its own band, and a line links the two bands. Plain columns only: not\nwith `stack` and not in line mode. The chart needs a fixed `unit-scaling`,\nand every part of the total must be positive."
2146
+ "text": "Total columns at their own scale, as JSON:\n`{\"by\":\"all\",\"aggregation\":\"sum\",\"unitScaling\":280,\"label\":\"2025\",\"width\":1.6}`.\n\n- `unitScaling` - data units per em of column height, like `unit-scaling`. Required.\n- `by` - what a total covers. `all` (default): one column right of the last\n period for all periods. `year`, `quarter`, `month`, `week`: one column\n behind the periods of each of them, on the axis.\n- `aggregation` - `sum` (default), `average` or `last`. With `sum` a column\n stacks one part per scenario of the series: the first scenario, and with\n `scenario-switch` the ones that follow it. Else it is one column, hatched\n when a forecast is in its value and outlined for a plan.\n- `dataset` - name of a dataset with one row per total (`date` and the\n scenario columns). The chart takes the values from it and computes none.\n- `label` - text under the column of `by: all`. The other columns take the name of their period.\n- `width` - width in widths of a period column, default 1.\n\nThe first other scenario is the reference behind a column. Each variance\nrow gets the variance of each total at the scale of the row. With\n`scaling-indicator` a column has its own band, and with `by: all` a line\nlinks it to the band of the periods. Plain columns only: not with `stack`\nand not in line mode. The chart needs a fixed `unit-scaling`, and every\npart of a total must be positive."
2066
2147
  },
2067
2148
  "getter": false,
2068
2149
  "setter": false,
2069
2150
  "reflect": false,
2070
- "attribute": "total-column",
2151
+ "attribute": "totals",
2071
2152
  "defaultValue": "\"\""
2072
2153
  },
2073
2154
  "scenarioSwitch": {
@@ -2231,8 +2312,8 @@ export class Chart {
2231
2312
  "propName": "dataFormatDigitsPercent",
2232
2313
  "methodName": "validateDataFormatDigitsPercent"
2233
2314
  }, {
2234
- "propName": "totalColumn",
2235
- "methodName": "validateTotalColumn"
2315
+ "propName": "totals",
2316
+ "methodName": "validateTotals"
2236
2317
  }, {
2237
2318
  "propName": "axisLabelsStep",
2238
2319
  "methodName": "validateAxisLabelsStep"