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

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.
@@ -20741,6 +20741,7 @@ const Chart = class {
20741
20741
  * when a forecast is in its value and outlined for a plan.
20742
20742
  * - `dataset` - name of a dataset with one row per total (`date` and the
20743
20743
  * scenario columns). The chart takes the values from it and computes none.
20744
+ * With `average` or `last` the values of a row are one column.
20744
20745
  * - `label` - text under the column of `by: all`. The other columns take the name of their period.
20745
20746
  * - `width` - width in widths of a period column, default 1.
20746
20747
  *
@@ -21663,7 +21664,7 @@ const Chart = class {
21663
21664
  this.errors.remove("WARN_scenarios_none");
21664
21665
  }
21665
21666
  const fontStyles = this.getFontStyles();
21666
- return (h(Host, { key: '1b6a2c72252e0f0c437815ea71652bc6ca7bb90c', style: fontStyles }, h("div", { key: '1df2b96475b83b11c197a00efed98b2e60a05ed9', class: "container" }, segments.map(this.chartTemplate))));
21667
+ return (h(Host, { key: 'baa11d12a8dc2e01a487b02bcd68902890ceb85a', style: fontStyles }, h("div", { key: '40a33368366a59709c8a6c0354a6aca50445778f', class: "container" }, segments.map(this.chartTemplate))));
21667
21668
  }
21668
21669
  get element() { return getElement(this); }
21669
21670
  static get watchers() { return {
@@ -24909,13 +24910,15 @@ class TimeChart {
24909
24910
  return runs;
24910
24911
  }
24911
24912
  /** The start of the group of a date, null for one group over all periods. */
24912
- totalGroupStart(date) {
24913
+ totalGroupStart(date, period = false) {
24913
24914
  var _a, _b;
24914
24915
  const by = (_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.by) !== null && _b !== void 0 ? _b : "all";
24915
24916
  if (by === "all" || date == null || !date.isValid) {
24916
24917
  return null;
24917
24918
  }
24918
- return date.startOf(by);
24919
+ // a week belongs to the year, quarter or month of its Thursday, as its number does
24920
+ const day = period && this.dateInterval === DateDistance.WEEK && by !== "week" ? date.plus({ days: 3 }) : date;
24921
+ return day.startOf(by);
24919
24922
  }
24920
24923
  /** The name of a total column under the axis: the text of the config at the end, else the name of its period. */
24921
24924
  totalLabel(start) {
@@ -24954,7 +24957,7 @@ class TimeChart {
24954
24957
  }
24955
24958
  /** The rows of the totals dataset, one per group, with the scenario columns added up. */
24956
24959
  totalDatasetRows() {
24957
- var _a, _b, _c, _d;
24960
+ var _a, _b, _c, _d, _e;
24958
24961
  const name = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.dataset;
24959
24962
  if (!name) {
24960
24963
  return null;
@@ -24972,18 +24975,22 @@ class TimeChart {
24972
24975
  this.failQuery(e);
24973
24976
  return rows;
24974
24977
  }
24978
+ const periods = new Set(this.dataModel.map((row) => { var _a, _b, _c; return (_c = (_b = (_a = row.date) === null || _a === void 0 ? void 0 : _a.toISODate) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : ""; }));
24975
24979
  for (const row of result) {
24976
24980
  const date = TimeChart.parseDate(row.date);
24977
- const start = date ? this.totalGroupStart(date) : null;
24978
- const key = start ? ((_b = start.toISODate()) !== null && _b !== void 0 ? _b : "") : "";
24981
+ // a row with the date of a period of the chart belongs to the total of that period: a week can
24982
+ // count into another year than its first day
24983
+ const isPeriod = date != null && periods.has((_b = date.toISODate()) !== null && _b !== void 0 ? _b : "");
24984
+ const start = date ? this.totalGroupStart(date, isPeriod) : null;
24985
+ const key = start ? ((_c = start.toISODate()) !== null && _c !== void 0 ? _c : "") : "";
24979
24986
  if (this.totals.by !== "all" && key === "")
24980
24987
  continue;
24981
- const sums = (_c = rows.get(key)) !== null && _c !== void 0 ? _c : {};
24988
+ const sums = (_d = rows.get(key)) !== null && _d !== void 0 ? _d : {};
24982
24989
  for (const [column, raw] of Object.entries(row)) {
24983
24990
  // a value can come as a text, like in the dataset of the chart
24984
24991
  const value = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
24985
24992
  if (column !== "date" && typeof value === "number" && Number.isFinite(value)) {
24986
- sums[column] = ((_d = sums[column]) !== null && _d !== void 0 ? _d : 0) + value;
24993
+ sums[column] = ((_e = sums[column]) !== null && _e !== void 0 ? _e : 0) + value;
24987
24994
  }
24988
24995
  }
24989
24996
  rows.set(key, sums);
@@ -25030,7 +25037,7 @@ class TimeChart {
25030
25037
  // the groups: runs of periods with the same start
25031
25038
  const groups = [];
25032
25039
  this.dataModel.forEach((row, index) => {
25033
- const start = this.totalGroupStart(row.date);
25040
+ const start = this.totalGroupStart(row.date, true);
25034
25041
  const last = groups[groups.length - 1];
25035
25042
  if (last != null && (start == null || (last.start != null && +last.start === +start))) {
25036
25043
  last.to = index;
@@ -25049,6 +25056,7 @@ class TimeChart {
25049
25056
  let parts = [];
25050
25057
  let reference = null;
25051
25058
  let counted = [];
25059
+ let scenarios;
25052
25060
  if (fromData != null) {
25053
25061
  // the values as the dataset gives them: one part per scenario of the series
25054
25062
  const data = (_c = fromData.get(group.start ? ((_b = group.start.toISODate()) !== null && _b !== void 0 ? _b : "") : "")) !== null && _c !== void 0 ? _c : {};
@@ -25062,6 +25070,13 @@ class TimeChart {
25062
25070
  if (referenceScenario != null && Number.isFinite(data[referenceScenario])) {
25063
25071
  reference = { scenario: referenceScenario, value: data[referenceScenario] };
25064
25072
  }
25073
+ scenarios = parts.map((part) => part.scenario);
25074
+ if (this.totals.aggregation !== "sum" && parts.length > 1 && parts.every((part) => part.value > 0)) {
25075
+ // an average or a last value is one column: the dataset gives the value, not its parts
25076
+ parts = [
25077
+ { scenario: this.mixedScenario(scenarios), value: parts.reduce((sum, part) => sum + part.value, 0) },
25078
+ ];
25079
+ }
25065
25080
  }
25066
25081
  else {
25067
25082
  // the periods where the series has a value. The reference counts in the same periods only,
@@ -25072,6 +25087,7 @@ class TimeChart {
25072
25087
  return slot != null && Number.isFinite((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.value);
25073
25088
  });
25074
25089
  counted = used.map((row) => this.dataModel.indexOf(row));
25090
+ scenarios = [...new Set(used.map((row) => row[this.visibleSlot(row, followers)].scenario))];
25075
25091
  const visible = used.map((row) => row[this.visibleSlot(row, followers)]);
25076
25092
  // with `last` the one period that gives the value counts. A reference with a gap in
25077
25093
  // the counted periods is no reference: half a sum would stand against a full one.
@@ -25117,7 +25133,7 @@ class TimeChart {
25117
25133
  return [];
25118
25134
  }
25119
25135
  const total = parts.reduce((sum, part) => sum + part.value, 0);
25120
- columns.push(Object.assign(Object.assign({}, group), { label: this.totalLabel(group.start), parts, total, reference, counted }));
25136
+ columns.push(Object.assign(Object.assign({}, group), { label: this.totalLabel(group.start), parts, total, reference, counted, scenarios }));
25121
25137
  }
25122
25138
  return columns;
25123
25139
  }
@@ -25158,20 +25174,31 @@ class TimeChart {
25158
25174
  let delta;
25159
25175
  const notations = new Set();
25160
25176
  if (fromData != null) {
25161
- base = 0;
25162
25177
  const data = (_b = fromData.get(column.start ? ((_a = column.start.toISODate()) !== null && _a !== void 0 ? _a : "") : "")) !== null && _b !== void 0 ? _b : {};
25163
- // the bases of the row are the scenarios of the series, each counts once
25164
- for (const name of new Set(candidates.map((entry) => entry.variance.base))) {
25165
- // a 0 is a scenario without a value in this total, as for the parts
25166
- if (Number.isFinite(data[name]) && data[name] !== 0) {
25167
- base += data[name];
25168
- notations.add(name.slice(0, 2));
25169
- }
25178
+ // the scenarios of the series can stand on either side of a variance: that side is
25179
+ // added up, each scenario once, the other side is the one reference of the row
25180
+ const series = new Set(column.scenarios);
25181
+ const bases = [...new Set(candidates.map((entry) => entry.variance.base))];
25182
+ const deltas = [...new Set(candidates.map((entry) => entry.variance.delta))];
25183
+ // a row for a part of the series only has no total: the reference of the dataset is the one of the whole total
25184
+ const covered = new Set([...bases, ...deltas].filter((name) => series.has(name))).size;
25185
+ if (covered > 0 && covered < series.size) {
25186
+ return null;
25170
25187
  }
25171
- if (notations.size === 0 || !Number.isFinite(data[first.delta])) {
25188
+ // a 0 is a scenario without a value in this total, as for the parts
25189
+ const has = (name) => Number.isFinite(data[name]) && data[name] !== 0;
25190
+ const side = (names) => {
25191
+ const used = names.some((name) => series.has(name)) ? names.filter(has) : names.slice(0, 1).filter(has);
25192
+ return used.length > 0 ? used.reduce((sum, name) => sum + data[name], 0) : null;
25193
+ };
25194
+ const baseSide = side(bases);
25195
+ const deltaSide = side(deltas);
25196
+ if (baseSide == null || deltaSide == null) {
25172
25197
  return null;
25173
25198
  }
25174
- delta = data[first.delta];
25199
+ base = baseSide;
25200
+ delta = deltaSide;
25201
+ bases.filter(has).forEach((name) => notations.add(name.slice(0, 2)));
25175
25202
  }
25176
25203
  else {
25177
25204
  // the same periods as the column, so the two tell the same: with `last` the one
@@ -356,6 +356,7 @@ export declare class Chart {
356
356
  * when a forecast is in its value and outlined for a plan.
357
357
  * - `dataset` - name of a dataset with one row per total (`date` and the
358
358
  * scenario columns). The chart takes the values from it and computes none.
359
+ * With `average` or `last` the values of a row are one column.
359
360
  * - `label` - text under the column of `by: all`. The other columns take the name of their period.
360
361
  * - `width` - width in widths of a period column, default 1.
361
362
  *
@@ -1122,7 +1122,7 @@ export namespace Components {
1122
1122
  */
1123
1123
  "syncSpaceLeft": number;
1124
1124
  /**
1125
- * Total columns at their own scale, as JSON: `{"by":"all","aggregation":"sum","unitScaling":280,"label":"2025","width":1.6}`. - `unitScaling` - data units per em of column height, like `unit-scaling`. Required. - `by` - what a total covers. `all` (default): one column right of the last period for all periods. `year`, `quarter`, `month`, `week`: one column behind the periods of each of them, on the axis. - `aggregation` - `sum` (default), `average` or `last`. With `sum` a column stacks one part per scenario of the series: the first scenario, and with `scenario-switch` the ones that follow it. Else it is one column, hatched when a forecast is in its value and outlined for a plan. - `dataset` - name of a dataset with one row per total (`date` and the scenario columns). The chart takes the values from it and computes none. - `label` - text under the column of `by: all`. The other columns take the name of their period. - `width` - width in widths of a period column, default 1. The first other scenario is the reference behind a column. Each variance row gets the variance of each total at the scale of the row. With `scaling-indicator` a column has its own band, and with `by: all` a line links it to the band of the periods. Plain columns only: not with `stack` and not in line mode. The chart needs a fixed `unit-scaling`, and every part of a total must be positive.
1125
+ * Total columns at their own scale, as JSON: `{"by":"all","aggregation":"sum","unitScaling":280,"label":"2025","width":1.6}`. - `unitScaling` - data units per em of column height, like `unit-scaling`. Required. - `by` - what a total covers. `all` (default): one column right of the last period for all periods. `year`, `quarter`, `month`, `week`: one column behind the periods of each of them, on the axis. - `aggregation` - `sum` (default), `average` or `last`. With `sum` a column stacks one part per scenario of the series: the first scenario, and with `scenario-switch` the ones that follow it. Else it is one column, hatched when a forecast is in its value and outlined for a plan. - `dataset` - name of a dataset with one row per total (`date` and the scenario columns). The chart takes the values from it and computes none. With `average` or `last` the values of a row are one column. - `label` - text under the column of `by: all`. The other columns take the name of their period. - `width` - width in widths of a period column, default 1. The first other scenario is the reference behind a column. Each variance row gets the variance of each total at the scale of the row. With `scaling-indicator` a column has its own band, and with `by: all` a line links it to the band of the periods. Plain columns only: not with `stack` and not in line mode. The chart needs a fixed `unit-scaling`, and every part of a total must be positive.
1126
1126
  * @default ""
1127
1127
  */
1128
1128
  "totals": string;
@@ -3514,7 +3514,7 @@ declare namespace LocalJSX {
3514
3514
  */
3515
3515
  "syncSpaceLeft"?: number;
3516
3516
  /**
3517
- * Total columns at their own scale, as JSON: `{"by":"all","aggregation":"sum","unitScaling":280,"label":"2025","width":1.6}`. - `unitScaling` - data units per em of column height, like `unit-scaling`. Required. - `by` - what a total covers. `all` (default): one column right of the last period for all periods. `year`, `quarter`, `month`, `week`: one column behind the periods of each of them, on the axis. - `aggregation` - `sum` (default), `average` or `last`. With `sum` a column stacks one part per scenario of the series: the first scenario, and with `scenario-switch` the ones that follow it. Else it is one column, hatched when a forecast is in its value and outlined for a plan. - `dataset` - name of a dataset with one row per total (`date` and the scenario columns). The chart takes the values from it and computes none. - `label` - text under the column of `by: all`. The other columns take the name of their period. - `width` - width in widths of a period column, default 1. The first other scenario is the reference behind a column. Each variance row gets the variance of each total at the scale of the row. With `scaling-indicator` a column has its own band, and with `by: all` a line links it to the band of the periods. Plain columns only: not with `stack` and not in line mode. The chart needs a fixed `unit-scaling`, and every part of a total must be positive.
3517
+ * Total columns at their own scale, as JSON: `{"by":"all","aggregation":"sum","unitScaling":280,"label":"2025","width":1.6}`. - `unitScaling` - data units per em of column height, like `unit-scaling`. Required. - `by` - what a total covers. `all` (default): one column right of the last period for all periods. `year`, `quarter`, `month`, `week`: one column behind the periods of each of them, on the axis. - `aggregation` - `sum` (default), `average` or `last`. With `sum` a column stacks one part per scenario of the series: the first scenario, and with `scenario-switch` the ones that follow it. Else it is one column, hatched when a forecast is in its value and outlined for a plan. - `dataset` - name of a dataset with one row per total (`date` and the scenario columns). The chart takes the values from it and computes none. With `average` or `last` the values of a row are one column. - `label` - text under the column of `by: all`. The other columns take the name of their period. - `width` - width in widths of a period column, default 1. The first other scenario is the reference behind a column. Each variance row gets the variance of each total at the scale of the row. With `scaling-indicator` a column has its own band, and with `by: all` a line links it to the band of the periods. Plain columns only: not with `stack` and not in line mode. The chart needs a fixed `unit-scaling`, and every part of a total must be positive.
3518
3518
  * @default ""
3519
3519
  */
3520
3520
  "totals"?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bino-bi/bn-template-engine",
3
- "version": "1.0.0-next.63",
3
+ "version": "1.0.0-next.65",
4
4
  "description": "IBCS-compliant web components for business intelligence tables and charts",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",