@bino-bi/bn-template-engine 1.0.0-next.64 → 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.
@@ -24957,7 +24957,7 @@ class TimeChart {
24957
24957
  }
24958
24958
  /** The rows of the totals dataset, one per group, with the scenario columns added up. */
24959
24959
  totalDatasetRows() {
24960
- var _a, _b, _c, _d;
24960
+ var _a, _b, _c, _d, _e;
24961
24961
  const name = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.dataset;
24962
24962
  if (!name) {
24963
24963
  return null;
@@ -24975,18 +24975,22 @@ class TimeChart {
24975
24975
  this.failQuery(e);
24976
24976
  return rows;
24977
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 : ""; }));
24978
24979
  for (const row of result) {
24979
24980
  const date = TimeChart.parseDate(row.date);
24980
- const start = date ? this.totalGroupStart(date) : null;
24981
- 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 : "") : "";
24982
24986
  if (this.totals.by !== "all" && key === "")
24983
24987
  continue;
24984
- const sums = (_c = rows.get(key)) !== null && _c !== void 0 ? _c : {};
24988
+ const sums = (_d = rows.get(key)) !== null && _d !== void 0 ? _d : {};
24985
24989
  for (const [column, raw] of Object.entries(row)) {
24986
24990
  // a value can come as a text, like in the dataset of the chart
24987
24991
  const value = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
24988
24992
  if (column !== "date" && typeof value === "number" && Number.isFinite(value)) {
24989
- 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;
24990
24994
  }
24991
24995
  }
24992
24996
  rows.set(key, sums);
@@ -25170,26 +25174,31 @@ class TimeChart {
25170
25174
  let delta;
25171
25175
  const notations = new Set();
25172
25176
  if (fromData != null) {
25173
- base = 0;
25174
25177
  const data = (_b = fromData.get(column.start ? ((_a = column.start.toISODate()) !== null && _a !== void 0 ? _a : "") : "")) !== null && _b !== void 0 ? _b : {};
25175
- // the bases of the row are the scenarios of the series, each counts once
25176
- const bases = new Set(candidates.map((entry) => entry.variance.base));
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))];
25177
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
25178
- const covered = column.scenarios.filter((scenario) => bases.has(scenario)).length;
25179
- if (covered > 0 && covered < column.scenarios.length) {
25184
+ const covered = new Set([...bases, ...deltas].filter((name) => series.has(name))).size;
25185
+ if (covered > 0 && covered < series.size) {
25180
25186
  return null;
25181
25187
  }
25182
- for (const name of bases) {
25183
- // a 0 is a scenario without a value in this total, as for the parts
25184
- if (Number.isFinite(data[name]) && data[name] !== 0) {
25185
- base += data[name];
25186
- notations.add(name.slice(0, 2));
25187
- }
25188
- }
25189
- 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) {
25190
25197
  return null;
25191
25198
  }
25192
- delta = data[first.delta];
25199
+ base = baseSide;
25200
+ delta = deltaSide;
25201
+ bases.filter(has).forEach((name) => notations.add(name.slice(0, 2)));
25193
25202
  }
25194
25203
  else {
25195
25204
  // the same periods as the column, so the two tell the same: with `last` the one
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bino-bi/bn-template-engine",
3
- "version": "1.0.0-next.64",
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",