@bino-bi/bn-template-engine 1.0.0-next.38 → 1.0.0-next.40

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 (105) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-9a61f59d.entry.js → p-8b28c9bd.entry.js} +1 -1
  3. package/dist/bn-template-engine/{p-DyupX-Z-.js → p-BjozxTTW.js} +1 -1
  4. package/dist/bn-template-engine/p-EcC0qLtU.js +1 -0
  5. package/dist/bn-template-engine/{p-eea538f1.entry.js → p-a4b76176.entry.js} +1 -1
  6. package/dist/bn-template-engine/p-aa0fd797.entry.js +1 -0
  7. package/dist/bn-template-engine/{p-93b8387f.entry.js → p-ce764078.entry.js} +1 -1
  8. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +1067 -515
  9. package/dist/cjs/bn-grid.cjs.entry.js +1 -1
  10. package/dist/cjs/bn-image.cjs.entry.js +1 -1
  11. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  12. package/dist/cjs/bn-text.cjs.entry.js +2 -2
  13. package/dist/cjs/loader.cjs.js +1 -1
  14. package/dist/cjs/{withStyled-DfE0aW7D.js → withStyled-BZb6snOx.js} +74 -0
  15. package/dist/cjs/{withTranslation-0gkn9xoC.js → withTranslation-FxXGUB3H.js} +1 -1
  16. package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +4 -1
  17. package/dist/collection/components/bn-chart-structure/utils/elements/Label.js +3 -1
  18. package/dist/collection/components/bn-chart-time/utils/elements/Label.js +3 -1
  19. package/dist/collection/components/bn-table/bn-table-renderer/bn-table-renderer.css +22 -1
  20. package/dist/collection/components/bn-table/bn-table-renderer/bn-table-renderer.js +192 -12
  21. package/dist/collection/components/bn-table/bn-table.js +222 -8
  22. package/dist/collection/components/bn-table/utils/Table.js +33 -2
  23. package/dist/collection/components/bn-table/utils/elements/Cell.js +10 -1
  24. package/dist/collection/components/bn-table/utils/elements/CellBarChart.js +25 -10
  25. package/dist/collection/components/bn-table/utils/elements/WaterfallBar.js +50 -12
  26. package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +59 -21
  27. package/dist/collection/components/bn-table/utils/helper/DataQuery.js +63 -2
  28. package/dist/collection/components/bn-table/utils/helper/IntervalColumns.js +30 -6
  29. package/dist/collection/components/bn-table/utils/helper/WaterfallCalculator.js +123 -11
  30. package/dist/collection/components/bn-table/utils/helper/barColumnGeometry.js +57 -9
  31. package/dist/collection/components/bn-table/utils/model/TableComponentConfig.js +21 -1
  32. package/dist/collection/components/bn-table/utils/model/index.js +6 -0
  33. package/dist/collection/utils/layoutState/baseline.js +6 -5
  34. package/dist/collection/utils/validate.js +4 -0
  35. package/dist/components/bn-chart-bubble-renderer.js +1 -1
  36. package/dist/components/bn-chart-bubble.js +1 -1
  37. package/dist/components/bn-chart-bullet-renderer.js +1 -1
  38. package/dist/components/bn-chart-bullet.js +1 -1
  39. package/dist/components/bn-chart-scatter-renderer.js +1 -1
  40. package/dist/components/bn-chart-scatter.js +1 -1
  41. package/dist/components/bn-chart-structure-renderer.js +1 -1
  42. package/dist/components/bn-chart-structure.js +1 -1
  43. package/dist/components/bn-chart-time-renderer.js +1 -1
  44. package/dist/components/bn-chart-time.js +1 -1
  45. package/dist/components/bn-grid.js +1 -1
  46. package/dist/components/bn-image.js +1 -1
  47. package/dist/components/bn-layout-card.js +1 -1
  48. package/dist/components/bn-layout-page.js +1 -1
  49. package/dist/components/bn-page.js +1 -1
  50. package/dist/components/bn-table-renderer.js +1 -1
  51. package/dist/components/bn-table.js +1 -1
  52. package/dist/components/bn-text.js +1 -1
  53. package/dist/components/bn-title.js +1 -1
  54. package/dist/components/bn-tree.js +1 -1
  55. package/dist/components/p-1B_s8oPY.js +1 -0
  56. package/dist/components/{p-BqUB56k1.js → p-B4L069XF.js} +1 -1
  57. package/dist/components/p-BC4MwlnX.js +1 -0
  58. package/dist/components/p-BZXiWkDS.js +1 -0
  59. package/dist/components/p-BiSytXUy.js +1 -0
  60. package/dist/components/p-Bn7J1pgl.js +1 -0
  61. package/dist/components/{p-BmOWXYHF.js → p-CEf5X8MZ.js} +1 -1
  62. package/dist/components/{p-BhEdmPjm.js → p-CUSAlS2o.js} +1 -1
  63. package/dist/components/p-ChaSU4fh.js +1 -0
  64. package/dist/components/p-CvEdUq8i.js +1 -0
  65. package/dist/components/{p-OquycEMA.js → p-D40Am1Ap.js} +1 -1
  66. package/dist/components/{p-CQVAHG6w.js → p-DM4Up10X.js} +1 -1
  67. package/dist/components/{p-Bo_R7f_T.js → p-DwuXVo2h.js} +1 -1
  68. package/dist/components/{p-t4xPltK2.js → p-XFZYX7DZ.js} +1 -1
  69. package/dist/components/{p-DTmqMQpw.js → p-Y9bth2Y_.js} +1 -1
  70. package/dist/components/{p-C_6KHDYv.js → p-chnyMHJT.js} +1 -1
  71. package/dist/components/{p-BU_53KVT.js → p-xIWChKGS.js} +1 -1
  72. package/dist/esm/bn-annotation-layer_30.entry.js +1037 -485
  73. package/dist/esm/bn-grid.entry.js +1 -1
  74. package/dist/esm/bn-image.entry.js +1 -1
  75. package/dist/esm/bn-template-engine.js +1 -1
  76. package/dist/esm/bn-text.entry.js +2 -2
  77. package/dist/esm/loader.js +1 -1
  78. package/dist/esm/{withStyled-CIoJ86RM.js → withStyled-CzzXg64f.js} +77 -4
  79. package/dist/esm/{withTranslation-BX9T3dfm.js → withTranslation-Daq2JXkv.js} +1 -1
  80. package/dist/types/components/bn-table/bn-table-renderer/bn-table-renderer.d.ts +22 -1
  81. package/dist/types/components/bn-table/bn-table.d.ts +72 -1
  82. package/dist/types/components/bn-table/utils/Table.d.ts +11 -1
  83. package/dist/types/components/bn-table/utils/elements/Cell.d.ts +3 -0
  84. package/dist/types/components/bn-table/utils/elements/CellBarChart.d.ts +26 -0
  85. package/dist/types/components/bn-table/utils/elements/WaterfallBar.d.ts +22 -2
  86. package/dist/types/components/bn-table/utils/factories/tableDataSetFactory.d.ts +7 -4
  87. package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +13 -0
  88. package/dist/types/components/bn-table/utils/helper/IntervalColumns.d.ts +7 -0
  89. package/dist/types/components/bn-table/utils/helper/WaterfallCalculator.d.ts +30 -2
  90. package/dist/types/components/bn-table/utils/helper/barColumnGeometry.d.ts +24 -4
  91. package/dist/types/components/bn-table/utils/model/TableComponentConfig.d.ts +9 -1
  92. package/dist/types/components/bn-table/utils/model/index.d.ts +5 -0
  93. package/dist/types/components.d.ts +66 -6
  94. package/dist/types/utils/layoutState/baseline.d.ts +4 -2
  95. package/dist/types/utils/validate.d.ts +1 -0
  96. package/package.json +1 -1
  97. package/dist/bn-template-engine/p-BVU4bIsi.js +0 -1
  98. package/dist/bn-template-engine/p-e15ccc4a.entry.js +0 -1
  99. package/dist/components/p--HIZm_2v.js +0 -1
  100. package/dist/components/p-C-KX1_tw.js +0 -1
  101. package/dist/components/p-DCPLGEs_.js +0 -1
  102. package/dist/components/p-DT04Cka0.js +0 -1
  103. package/dist/components/p-Dm6EAaJ9.js +0 -1
  104. package/dist/components/p-sar8m7th.js +0 -1
  105. package/dist/components/p-tkB96Ena.js +0 -1
@@ -1,6 +1,14 @@
1
1
  import { h } from "@stencil/core";
2
- import { AXIS_COLOR, DEFAULT_STYLES, formatValue, getBarFill, getBarStroke, getBarStyle, getScenarioType, PatternDefs, } from "./CellBarChart";
3
- import { waterfallGeometry } from "../helper/barColumnGeometry";
2
+ import { AXIS_COLOR, DEFAULT_STYLES, formatValue, getBarFill, getBarStroke, getBarStyle, getScenarioType, getVarianceLook, PatternDefs, VarianceAxis, } from "./CellBarChart";
3
+ import { labelWidth, VARIANCE_AXIS_EM, waterfallGeometry } from "../helper/barColumnGeometry";
4
+ /**
5
+ * Label text of a waterfall bar. Scenario values carry no variance sentiment: unsigned per
6
+ * IBCS. A variance keeps its sign (`signed`).
7
+ */
8
+ export function waterfallLabelText(value, kind, measureScale, locale, decimalDigits, signed = false) {
9
+ const text = formatValue(value, kind === "partof", measureScale, locale, 0, true, decimalDigits);
10
+ return signed ? text : text.replace(/^\+/, "");
11
+ }
4
12
  /**
5
13
  * Renders one row of an IBCS waterfall for a scenario bar column.
6
14
  *
@@ -13,19 +21,27 @@ import { waterfallGeometry } from "../helper/barColumnGeometry";
13
21
  * Layout: [left label area][bar area][right label area]
14
22
  * The value label sits at the bar's free end (right of rightward bars,
15
23
  * left of leftward bars). thereof/partof rows additionally get dashed
16
- * guides marking their parent bar's extent.
24
+ * guides marking their parent bar's extent. A guide or axis line that would
25
+ * run through the label is left out in that row.
26
+ *
27
+ * An absolute variance column is drawn as a variance waterfall: the bar in the color of
28
+ * the sentiment and the pattern of the minuend, the axis in the look of the reference
29
+ * scenario in every row, a signed label, and thin connectors to the rows above and below
30
+ * in place of the dashed guides. The axis and the connectors join the rows, so where one
31
+ * meets the label it is only interrupted over the height of the text.
17
32
  */
18
33
  export const WaterfallBar = (props) => {
19
- const { value, scenario, height, measureScale, locale, decimalDigits, columnWidthEm = 10, styles = DEFAULT_STYLES, waterfall, } = props;
34
+ var _a;
35
+ const { value, scenario, height, isPositiveGood, measureScale, locale, decimalDigits, columnWidthEm = 10, styles = DEFAULT_STYLES, waterfall, geometry, bold, connectorReach = { top: 0, bottom: 0 }, } = props;
20
36
  const s = styles.scaleFactor;
21
37
  const fs = styles.fontSize;
22
38
  const range = waterfall.max - waterfall.min;
23
39
  if (value === null || value === undefined || isNaN(value) || range <= 0) {
24
40
  return (h("span", { class: "bar-chart-empty", style: { color: styles.fontColor, fontStyle: "italic" } }, "-"));
25
41
  }
26
- const { totalWidth, labelAreaWidth, barAreaWidth, labelGap } = waterfallGeometry(columnWidthEm, styles.emPx);
42
+ const { totalWidth, labelAreaLeft, barAreaWidth, labelGap } = geometry !== null && geometry !== void 0 ? geometry : waterfallGeometry(columnWidthEm, styles.emPx);
27
43
  const pxPerUnit = barAreaWidth / range;
28
- const xOf = (coordinate) => labelAreaWidth + (coordinate - waterfall.min) * pxPerUnit;
44
+ const xOf = (coordinate) => labelAreaLeft + (coordinate - waterfall.min) * pxPerUnit;
29
45
  const padding = 2 * s;
30
46
  const barHeight = height - padding * 2;
31
47
  const barY = padding;
@@ -34,13 +50,35 @@ export const WaterfallBar = (props) => {
34
50
  const endX = xOf(waterfall.end);
35
51
  const barX = Math.min(startX, endX);
36
52
  const barWidth = Math.abs(endX - startX);
37
- const barStyle = getBarStyle(scenario, value, false, styles);
38
- const fillValue = getBarFill(barStyle, getScenarioType(scenario));
39
- const { stroke: barStroke, strokeWidth: barStrokeWidth } = getBarStroke(barStyle);
40
- // Scenario values carry no variance sentiment - labels are unsigned per IBCS
41
- const displayValue = formatValue(value, waterfall.kind === "partof", measureScale, locale, 0, true, decimalDigits).replace(/^\+/, "");
53
+ // null for a scenario column, which ignores the sentiment
54
+ const look = getVarianceLook(scenario, styles);
55
+ const sentimentStyle = getBarStyle(scenario, value, isPositiveGood, styles);
56
+ const minuendPattern = look === null || look === void 0 ? void 0 : look.minuend.fillpattern;
57
+ const barStyle = minuendPattern === "hatched" || minuendPattern === "outlined"
58
+ ? Object.assign(Object.assign({}, sentimentStyle), { fillpattern: minuendPattern }) : sentimentStyle;
59
+ const patternPrefix = look ? (sentimentStyle === styles.positive ? "pos" : "neg") : getScenarioType(scenario);
60
+ const fillValue = getBarFill(barStyle, patternPrefix);
61
+ const { stroke: barStroke, strokeWidth: barStrokeWidth } = look && barStyle.fillpattern === "hatched" ? { stroke: barStyle.stroke, strokeWidth: 1 } : getBarStroke(barStyle);
62
+ const displayValue = waterfallLabelText(value, waterfall.kind, measureScale, locale, decimalDigits, look !== null);
42
63
  const pointsLeft = endX < startX;
43
64
  const labelX = pointsLeft ? barX - labelGap : barX + barWidth + labelGap;
44
65
  const labelAnchor = pointsLeft ? "end" : "start";
45
- return (h("svg", { width: totalWidth, height: height, class: "cell-bar-chart waterfall-bar", style: { overflow: "visible" } }, h(PatternDefs, { styles: styles }), h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), waterfall.parentStart !== undefined && waterfall.parentEnd !== undefined && (h("line", { x1: xOf(waterfall.parentStart), y1: 0, x2: xOf(waterfall.parentStart), y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s, "stroke-dasharray": `${2 * s},${2 * s}` })), waterfall.parentStart !== undefined && waterfall.parentEnd !== undefined && (h("line", { x1: xOf(waterfall.parentEnd), y1: 0, x2: xOf(waterfall.parentEnd), y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s, "stroke-dasharray": `${2 * s},${2 * s}` })), barWidth > 0 && (h("rect", { x: barX, y: barY, width: barWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": labelAnchor, fill: styles.fontColor, "font-size": fs, "font-family": styles.fontFamily }, displayValue)));
66
+ // a line through the label makes it unreadable, so the row drops it
67
+ const labelSize = labelWidth(displayValue, fs, styles.fontFamily, false, bold);
68
+ const labelPad = labelGap / 2;
69
+ const labelFrom = (pointsLeft ? labelX - labelSize : labelX) - labelPad;
70
+ const labelTo = (pointsLeft ? labelX : labelX + labelSize) + labelPad;
71
+ const meetsLabel = (x) => x > labelFrom && x < labelTo;
72
+ const parentEndX = waterfall.parentEnd !== undefined ? xOf(waterfall.parentEnd) : undefined;
73
+ // the parts of a vertical line of a variance waterfall that stay clear of the label text
74
+ const labelTop = height / 2 - fs / 2;
75
+ const labelBottom = height / 2 + fs / 2;
76
+ const clearOfLabel = (x, y1, y2, halfWidth = 0) => x + halfWidth > labelFrom && x - halfWidth < labelTo
77
+ ? [[y1, Math.min(y2, labelTop)], [Math.max(y1, labelBottom), y2]].filter(([from, to]) => to > from)
78
+ : [[y1, y2]];
79
+ const axisTop = -connectorReach.top;
80
+ const axisBottom = height + connectorReach.bottom;
81
+ return (h("svg", { width: totalWidth, height: height, class: `cell-bar-chart waterfall-bar${look ? " variance-waterfall" : ""}`, style: { overflow: "visible" } }, h(PatternDefs, { styles: styles }), !look && !meetsLabel(axisX) && (h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s })), waterfall.parentStart !== undefined && waterfall.parentEnd !== undefined && (h("line", { x1: xOf(waterfall.parentStart), y1: 0, x2: xOf(waterfall.parentStart), y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s, "stroke-dasharray": `${2 * s},${2 * s}` })), waterfall.parentStart !== undefined && parentEndX !== undefined && !meetsLabel(parentEndX) && (h("line", { x1: parentEndX, y1: 0, x2: parentEndX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s, "stroke-dasharray": `${2 * s},${2 * s}` })), (_a = waterfall.connectors) === null || _a === void 0 ? void 0 :
82
+ _a.map(({ at, part }) => clearOfLabel(xOf(at), part === "bottom" ? barY + barHeight : axisTop, part === "top" ? barY : axisBottom).map(([y1, y2]) => (h("line", { class: "waterfall-connector", x1: xOf(at), y1: y1, x2: xOf(at), y2: y2, stroke: AXIS_COLOR, "stroke-width": 1 * s })))), barWidth > 0 && (h("rect", { x: barX, y: barY, width: barWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), look &&
83
+ clearOfLabel(axisX, axisTop, axisBottom, (VARIANCE_AXIS_EM * styles.emPx) / 2).map(([y1, y2]) => (h("g", { transform: `translate(0,${y1})` }, h(VarianceAxis, { x: axisX, height: y2 - y1, look: look, styles: styles })))), h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": labelAnchor, fill: styles.fontColor, "font-size": fs, "font-family": styles.fontFamily }, displayValue)));
46
84
  };
@@ -1,5 +1,5 @@
1
1
  import { TableRow } from "../elements";
2
- import { TableRowType, TableType } from "../model";
2
+ import { TableRowType, TableType, ThereofPosition } from "../model";
3
3
  import { BLANK_BUCKET_LABEL, computeWaterfall, DataQuery, hasGroupingStructure, INTERVAL_NONE, isDateInterval, } from "../helper";
4
4
  import { Formatter } from "../../../../utils";
5
5
  import { I18nMode, DataFormat, Scenarios } from "../../../../utils/constants";
@@ -11,7 +11,7 @@ import { pointDate } from "../../../../utils/layoutState/dataPoint";
11
11
  /**
12
12
  * Transforms raw query results into structured TableRow collections for header and body.
13
13
  *
14
- * Header normalization: prepends fixed columns (operation, category) to the configured
14
+ * Header normalization: adds the fixed columns (operation, category) to the configured
15
15
  * scenarios, then translates labels via i18n and adds separator rows for IBCS-style borders.
16
16
  *
17
17
  * Body row creation: iterates DataQuery results grouped by rowGroup, creates detail rows
@@ -38,7 +38,7 @@ export class TableDataSetFactory {
38
38
  }
39
39
  return styleSlot(this.ruleSet.getScenarioColorIndex(type)) + type.slice(2);
40
40
  }
41
- /** Effective column list (category/operation + attributes + scenarios × buckets), set by createHeader(). */
41
+ /** Effective column list (category/operation + attributes + scenarios × buckets) in render order, set by createHeader(). */
42
42
  getNormalizedHeader() {
43
43
  return this.normalizedHeader;
44
44
  }
@@ -50,10 +50,10 @@ export class TableDataSetFactory {
50
50
  * visualise grouping.
51
51
  * finally a seperator header row is created for the header underlining (border)
52
52
  */
53
- createHeader(type, scenarios, i18n, measureScale, measureUnit, showMeasureScale, attributes = []) {
53
+ createHeader(type, scenarios, i18n, measureScale, measureUnit, showMeasureScale, attributes = [], leadingScenarioColumns = 0) {
54
54
  const header = [];
55
55
  this.attributesByAlias = new Map(attributes.map((attribute) => [attribute.alias, attribute]));
56
- this.normalizedHeader = this.normalizeHeader(type, scenarios, attributes);
56
+ this.normalizedHeader = this.normalizeHeader(type, scenarios, attributes, leadingScenarioColumns);
57
57
  const hasIntervalColumns = this.normalizedHeader.some((column) => column.bucket !== undefined);
58
58
  if (hasIntervalColumns) {
59
59
  header.push(this.createIntervalBandRow());
@@ -73,7 +73,7 @@ export class TableDataSetFactory {
73
73
  }
74
74
  /**
75
75
  * Creates the spanning interval band row (e.g. `2023 | 2024 | 2025`) rendered
76
- * above the scenario label row. Leading non-interval columns (category,
76
+ * above the scenario label row. Non-interval columns (category,
77
77
  * operation, attributes) receive borderless filler cells; each run of
78
78
  * consecutive columns of the same bucket is spanned by one label cell.
79
79
  */
@@ -114,8 +114,11 @@ export class TableDataSetFactory {
114
114
  * configured scenarios.
115
115
  * depending of table type operation column is used (OPT) or not (SUM | LIST)
116
116
  * in addition the headers are sorted based on the ruleset and duplicates are removed
117
+ *
118
+ * operation, category and the attribute columns are the row header block. It moves
119
+ * as one unit: `leadingScenarioColumns` scenario columns stand left of it.
117
120
  */
118
- normalizeHeader(type, scenarios, attributes) {
121
+ normalizeHeader(type, scenarios, attributes, leadingScenarioColumns = 0) {
119
122
  let header = [
120
123
  {
121
124
  name: QueryColumnNames.CATEGORY,
@@ -148,7 +151,12 @@ export class TableDataSetFactory {
148
151
  order: undefined,
149
152
  }));
150
153
  // NOTE: scenarios are already sorted in setConfig
151
- return [...header, ...attributeColumns, ...scenarios];
154
+ return [
155
+ ...scenarios.slice(0, leadingScenarioColumns),
156
+ ...header,
157
+ ...attributeColumns,
158
+ ...scenarios.slice(leadingScenarioColumns),
159
+ ];
152
160
  }
153
161
  /**
154
162
  * Creates table data colelction,
@@ -166,20 +174,24 @@ export class TableDataSetFactory {
166
174
  this.hasBlankRowGroup = dataQuery.hasBlankRowGroup;
167
175
  // Calculate column statistics for bar columns
168
176
  const columnStatsMap = this.calculateColumnStatistics(queryData, config.barColumns, config.interval !== INTERVAL_NONE);
169
- // Scenario bar columns render as a waterfall when grouping structure is present;
177
+ // Scenario bar columns render as a waterfall when grouping structure is present,
178
+ // absolute variance bar columns when varianceWaterfall is set;
170
179
  // interval/columnthereof composite columns are excluded and render as today
171
- const waterfallColumns = ((_a = config.barColumns) !== null && _a !== void 0 ? _a : []).filter((column) => column.toUpperCase().trim() in Scenarios);
172
- const waterfallResult = waterfallColumns.length > 0 &&
173
- config.interval === INTERVAL_NONE &&
174
- config.categoryThereOf.size === 0 &&
175
- hasGroupingStructure(queryData)
176
- ? computeWaterfall(queryData, waterfallColumns, config.type)
180
+ const thereOfAbove = config.thereOfPosition === ThereofPosition.ABOVE;
181
+ const barColumns = (_a = config.barColumns) !== null && _a !== void 0 ? _a : [];
182
+ const scenarioColumns = barColumns.filter((column) => column.toUpperCase().trim() in Scenarios);
183
+ const waterfallColumns = [
184
+ ...(scenarioColumns.length > 0 && hasGroupingStructure(queryData) ? scenarioColumns : []),
185
+ ...(config.varianceWaterfall ? barColumns.filter((column) => new VarianceScenario(column).type === "d") : []),
186
+ ];
187
+ const waterfallResult = waterfallColumns.length > 0 && config.interval === INTERVAL_NONE && config.categoryThereOf.size === 0
188
+ ? computeWaterfall(queryData, waterfallColumns, config.type, dataQuery.hasRunningSum(), thereOfAbove)
177
189
  : undefined;
178
190
  for (const groupData of queryData) {
179
191
  // groupData is a collection of dataRows, each group base on a query and represents a 'row' group
180
192
  iGroupIndex += 1;
181
193
  const iRowIndex = -1;
182
- bodyRows.push(...this.createRow(config.i18n, i18n, config.scenariosUnitType, groupData, iGroupIndex, iRowIndex, config.categoryWidth, config.measureScale, config.barColumns, columnStatsMap, waterfallResult));
194
+ bodyRows.push(...this.createRow(config.i18n, i18n, config.scenariosUnitType, groupData, iGroupIndex, iRowIndex, config.categoryWidth, config.measureScale, config.barColumns, columnStatsMap, waterfallResult, thereOfAbove));
183
195
  }
184
196
  return bodyRows;
185
197
  }
@@ -290,9 +302,12 @@ export class TableDataSetFactory {
290
302
  * @param barColumns
291
303
  * @param columnStatsMap
292
304
  */
293
- createRow(i18nMode, i18n, scenariosUnitType, groupData, iGroupIndex, iRowIndex, categoryWidth, measureScale, barColumns, columnStatsMap, waterfallResult) {
305
+ createRow(i18nMode, i18n, scenariosUnitType, groupData, iGroupIndex, iRowIndex, categoryWidth, measureScale, barColumns, columnStatsMap, waterfallResult, thereOfAbove = false) {
294
306
  var _a, _b, _c;
295
307
  const result = [];
308
+ // the last entry row and its index in result: the parent of the thereof rows that follow it
309
+ let parentIndex = -1;
310
+ let parent;
296
311
  // thereof and partof rows have no operation, they take the one of the row above
297
312
  let operation;
298
313
  for (const rawDataRow of groupData) {
@@ -304,20 +319,31 @@ export class TableDataSetFactory {
304
319
  const type = rawDataRow[QueryColumnNames.TYPE];
305
320
  const isSecondElement = rawDataRow[QueryColumnNames.ROWNR] >= 2;
306
321
  operation = ((_b = (_a = rawDataRow.operation) !== null && _a !== void 0 ? _a : rawDataRow.restOperation) !== null && _b !== void 0 ? _b : operation);
322
+ // a thereof row moves above the entry row before it only when that row is its parent
323
+ const moved = thereOfAbove &&
324
+ type === TableRowType.DRILLELEMENT &&
325
+ parent !== undefined &&
326
+ parent[QueryColumnNames.CATEGORY] === rawDataRow[QueryColumnNames.CATEGORY] &&
327
+ (parent[QueryColumnNames.ROWGROUP] === "NO_GROUP" || parent[QueryColumnNames.ROWGROUP] === rowGroup);
307
328
  const detailsRow = this.createDetailRow(type, iRowIndex, iGroupIndex, groupData.length);
308
329
  detailsRow.key = this.rowKey(rawDataRow);
309
330
  for (const scenario of this.normalizedHeader) {
310
331
  const value = this.getRawDataRowElement(rawDataRow, scenario);
311
- const isBarChart = (_c = barColumns === null || barColumns === void 0 ? void 0 : barColumns.includes(scenario.type)) !== null && _c !== void 0 ? _c : false;
312
- const columnStats = isBarChart ? columnStatsMap === null || columnStatsMap === void 0 ? void 0 : columnStatsMap.get(scenario.type) : undefined;
332
+ const isBarColumn = (_c = barColumns === null || barColumns === void 0 ? void 0 : barColumns.includes(scenario.type)) !== null && _c !== void 0 ? _c : false;
313
333
  // waterfall geometry only exists for plain scenario columns (no ## composites)
314
- const waterfall = isBarChart &&
334
+ const waterfall = isBarColumn &&
315
335
  scenario.bucket === undefined &&
316
336
  scenario.name === scenario.group &&
317
337
  scenario.name === scenario.type
318
338
  ? waterfallResult === null || waterfallResult === void 0 ? void 0 : waterfallResult.get(rawDataRow, scenario.type)
319
339
  : undefined;
320
- detailsRow.createElement(this.translateSumCellLabel(i18nMode, i18n, value, groupName, subCategory, type, scenario.type), scenario.type, this.createColumnType(scenario), this.setCellType(scenario.type, scenariosUnitType), this.translateCellPrefix(i18n, type, scenario.type), this.translateScenarioCSS(scenario.type, value, operation), isSecondElement, categoryWidth, measureScale === null || measureScale === void 0 ? void 0 : measureScale.value, isBarChart, columnStats, 1, waterfall);
340
+ // a share of a variance has no place in the walk of a variance waterfall: the row prints the number
341
+ const isBarChart = isBarColumn &&
342
+ !(type === TableRowType.PARTELEMENT &&
343
+ new VarianceScenario(scenario.type).isValid &&
344
+ (waterfallResult === null || waterfallResult === void 0 ? void 0 : waterfallResult.has(scenario.type)));
345
+ const columnStats = isBarChart ? columnStatsMap === null || columnStatsMap === void 0 ? void 0 : columnStatsMap.get(scenario.type) : undefined;
346
+ detailsRow.createElement(this.translateSumCellLabel(i18nMode, i18n, value, groupName, subCategory, type, scenario.type), scenario.type, this.createColumnType(scenario), this.setCellType(scenario.type, scenariosUnitType), moved ? null : this.translateCellPrefix(i18n, type, scenario.type), this.translateScenarioCSS(scenario.type, value, operation), isSecondElement, categoryWidth, measureScale === null || measureScale === void 0 ? void 0 : measureScale.value, isBarChart, columnStats, 1, waterfall);
321
347
  const cell = detailsRow.elements[detailsRow.elements.length - 1];
322
348
  if (this.dateBuckets && scenario.bucket !== undefined) {
323
349
  cell.date = pointDate(scenario.bucket);
@@ -327,6 +353,18 @@ export class TableDataSetFactory {
327
353
  cell.direction = this.resolveDirection(varianceScenario, operation);
328
354
  }
329
355
  }
356
+ // moved only here: the operation above and the waterfall geometry both rely on the parent coming first
357
+ if (moved) {
358
+ detailsRow.cssStyle = "ofit-above";
359
+ result[parentIndex].cssStyle = "ofit-sum";
360
+ result.splice(parentIndex, 0, detailsRow);
361
+ parentIndex += 1;
362
+ continue;
363
+ }
364
+ if (type === TableRowType.ENTRY) {
365
+ parentIndex = result.length;
366
+ parent = rawDataRow;
367
+ }
330
368
  result.push(detailsRow);
331
369
  }
332
370
  return result;
@@ -1,11 +1,16 @@
1
1
  import { OrderDirection, TableType } from "../model";
2
2
  import { BLANK_SAFE_ROWGROUP, QueryGroups } from "./QueryGroup";
3
+ import { restSignedAlias } from "./WaterfallCalculator";
3
4
  import { BLANK_BUCKET_LABEL, coerceBucketKey, INTERVAL_NONE, INTERVAL_SETNAME, intervalBucketSQL, } from "./IntervalColumns";
4
5
  import { FIELD_IDENTIFIER_REGEX } from "../model/TableAttribute";
5
6
  import { parseOrderToken } from "../../../../utils/model/Order";
6
7
  import { Scenarios } from "../../../../utils/constants";
7
8
  import { QueryColumnNames, VarianceScenario } from "../../../../utils/model";
8
9
  import { NOT_AVAILABLE, relativeVariance } from "../../../../utils/relativeVariance";
10
+ /** Adds a group sum to a running result; it stays missing as long as no group had a value. */
11
+ function addGroupSum(running, value) {
12
+ return running == null && value == null ? value : (running !== null && running !== void 0 ? running : 0) + (value !== null && value !== void 0 ? value : 0);
13
+ }
9
14
  /**
10
15
  * AlaSQL-based query builder that produces the complete table result set for bn-table.
11
16
  *
@@ -121,6 +126,9 @@ export class DataQuery {
121
126
  this.createTotalSumRow(queries, sumGroupQueries, scenariosSUMQuery);
122
127
  // executes main queries
123
128
  queries.forEach((query) => res.push(this.exec(query)));
129
+ if (this.hasRunningSum()) {
130
+ this.accumulateGroupSums(res, [...new Set(this.exctractScenarioNames(scenariosSUMQuery))]);
131
+ }
124
132
  this.detectNaNCells(this.config.scenarios, res);
125
133
  this.createThereOfDrillRows(scenarios, attributesSQL, order, res);
126
134
  this.createPartOfDrillRows(scenarios, order, sumGroupQueries, res);
@@ -211,8 +219,13 @@ export class DataQuery {
211
219
  .map((name) => `SUM(${name}) as ${name}`)
212
220
  .join(", ");
213
221
  // a REST row of only "-" rows counts as "-" for the op sentiment; not named operation, so it stays hidden
222
+ // the row prints the unsigned sum; the walk of a waterfall needs the signed sum of its bar columns
223
+ const restSigned = this.exctractScenarioNames(scenarios)
224
+ .filter((name) => { var _a; return (_a = this.config.barColumns) === null || _a === void 0 ? void 0 : _a.includes(name); })
225
+ .map((name) => `, SUM(${name} * transformOperator(operation)) as ${restSignedAlias(name)}`)
226
+ .join("");
214
227
  const restOperation = TableType.OPT === this.config.type || TableType.OPTNOTOTAL === this.config.type
215
- ? `, CASE WHEN MAX(transformOperator(operation)) = -1 THEN '-' ELSE '+' END as restOperation`
228
+ ? `, CASE WHEN MAX(transformOperator(operation)) = -1 THEN '-' ELSE '+' END as restOperation${restSigned}`
216
229
  : "";
217
230
  querys.push(`SELECT ${QueryColumnNames.ROWNR}, 1 as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, 'NO_GROUP' as ${QueryColumnNames.ROWGROUP}, ${this.bind(String((_a = rowGroupEntry.rowGroup) !== null && _a !== void 0 ? _a : ""))} as restRowGroup, 'REST' as ${QueryColumnNames.CATEGORY}${restOperation} ${restScenarios.length > 0 ? ", " + restScenarios : ""} FROM` +
218
231
  ` (SELECT ROWNUM() AS ${QueryColumnNames.ROWNR}, ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, ${this.bind(String(rowGroupEntry.rowGroup || "NO_GROUP"))} as ${QueryColumnNames.ROWGROUP}, ${groups.select()} ${scenarios.length > 0 ? ",".concat(scenarios) : ""}${this.sortSelect} FROM ${this.fromExpr} ${queryWhereSection} GROUP BY ${groups} ORDER BY ${order[0]})` +
@@ -254,6 +267,34 @@ export class DataQuery {
254
267
  TableType.OPT === this.config.type ||
255
268
  TableType.OPTNOTOTAL === this.config.type);
256
269
  }
270
+ /**
271
+ * True when the group sum rows are running results: only a grouped table with group sum
272
+ * rows has them. Column drill values of the group sum rows are not accumulated, so
273
+ * `runningSum` is off with columnthereof.
274
+ */
275
+ hasRunningSum() {
276
+ return (this.config.runningSum && this.config.grouped && this.hasGroupSum() && this.config.categoryThereOf.size === 0);
277
+ }
278
+ /**
279
+ * Turns the GROUP_SUM rows into running results: each one gets the raw aliases of all
280
+ * group sums before it added (scenarios, `_cnt`, variances and `dr_*` denominators).
281
+ * Runs before the NaN step and the relative variance division, where all of them are sums.
282
+ * A missing value stays missing until a group brings a real one.
283
+ */
284
+ accumulateGroupSums(res, aliases) {
285
+ const running = {};
286
+ for (const segment of res) {
287
+ for (const row of segment) {
288
+ if (row[QueryColumnNames.TYPE] !== "GROUP_SUM") {
289
+ continue;
290
+ }
291
+ for (const alias of aliases) {
292
+ running[alias] = addGroupSum(running[alias], row[alias]);
293
+ row[alias] = running[alias];
294
+ }
295
+ }
296
+ }
297
+ }
257
298
  /** Generates a GROUP_SUM row that aggregates all entries within a single row group. */
258
299
  createGroupSumRow(querys, groupSumQuery, rowGroupEntry, scenariosSUMQuery, queryWhereSection, order) {
259
300
  // Generates SUM Row; sumsup all rows of group
@@ -635,7 +676,27 @@ export class DataQuery {
635
676
  : [];
636
677
  const groupTotalsByKey = new Map();
637
678
  groupTotalRowsRaw.forEach((row) => groupTotalsByKey.set(`${row.rowGroup}${separator}${coerceBucketKey(row.__interval)}`, row));
638
- if (isSumTypeGrouped) {
679
+ if (isSumTypeGrouped && this.hasRunningSum()) {
680
+ // per bucket, each group sum row gets the totals of all groups up to its own
681
+ const sumAliases = [...new Set(this.exctractScenarioNames(scenariosSUMQuery))];
682
+ const groupSumRows = res.flat().filter((row) => row.type === "GROUP_SUM");
683
+ for (const bucketKey of new Set(groupTotalRowsRaw.map((row) => coerceBucketKey(row.__interval)))) {
684
+ let running;
685
+ for (const row of groupSumRows) {
686
+ const totalRow = groupTotalsByKey.get(`${row.rowGroup}${separator}${bucketKey}`);
687
+ if (totalRow) {
688
+ running !== null && running !== void 0 ? running : (running = {});
689
+ for (const alias of sumAliases) {
690
+ running[alias] = addGroupSum(running[alias], totalRow[alias]);
691
+ }
692
+ }
693
+ if (running) {
694
+ writeBucketValues(row, finalizeBucketRow(Object.assign({}, running)), bucketKey);
695
+ }
696
+ }
697
+ }
698
+ }
699
+ else if (isSumTypeGrouped) {
639
700
  for (const totalRow of groupTotalRowsRaw) {
640
701
  const bucketKey = coerceBucketKey(totalRow.__interval);
641
702
  const finalized = finalizeBucketRow(Object.assign({}, totalRow));
@@ -22,6 +22,16 @@ export function intervalBucketSQL(interval) {
22
22
  }
23
23
  return `normalizeDate([date], '${interval}')`;
24
24
  }
25
+ /** SQL expression reading the optional `setnameIndex` column, tolerant like `setname`. */
26
+ export const SETNAME_INDEX_SQL = "COALESCE([setnameIndex],[setNameIndex])";
27
+ /** A raw `setnameIndex` value as a number; undefined when it is blank or not numeric. */
28
+ export function coerceSetnameIndex(value) {
29
+ if (typeof value === "string" ? value.trim() === "" : typeof value !== "number") {
30
+ return undefined;
31
+ }
32
+ const index = Number(value);
33
+ return Number.isFinite(index) ? index : undefined;
34
+ }
25
35
  /** Coerces a raw bucket value (luxon DateTime, string, millis) to a stable string key. */
26
36
  export function coerceBucketKey(value) {
27
37
  if (value == null) {
@@ -68,22 +78,36 @@ export function resolveIntervalGranularity(db, fromExpr, interval) {
68
78
  * Date buckets are sorted chronologically ascending and labeled locale-aware;
69
79
  * setname buckets keep their order of first appearance in the data, blank
70
80
  * setnames are collected in a trailing-position "-" bucket where they occur.
81
+ * When rows carry a numeric `setnameIndex`, the setname buckets are sorted
82
+ * ascending by the smallest index of each setname. Buckets without an index
83
+ * follow, and ties keep the order of first appearance.
71
84
  */
72
85
  export function queryIntervalBuckets(db, fromExpr, interval, locale) {
73
- const rows = db.exec(`SELECT ${intervalBucketSQL(interval)} as __interval FROM ${fromExpr}`);
74
86
  if (interval === INTERVAL_SETNAME) {
87
+ const setRows = db.exec(`SELECT ${intervalBucketSQL(interval)} as __interval, ${SETNAME_INDEX_SQL} as __index FROM ${fromExpr}`);
75
88
  const seen = new Set();
89
+ const indexes = new Map();
76
90
  const buckets = [];
77
- for (const row of rows) {
91
+ for (const row of setRows) {
78
92
  const key = coerceBucketKey(row.__interval);
79
- if (seen.has(key)) {
80
- continue;
93
+ if (!seen.has(key)) {
94
+ seen.add(key);
95
+ buckets.push({ key, label: key.length === 0 ? BLANK_BUCKET_LABEL : key });
81
96
  }
82
- seen.add(key);
83
- buckets.push({ key, label: key.length === 0 ? BLANK_BUCKET_LABEL : key });
97
+ const index = coerceSetnameIndex(row.__index);
98
+ const known = indexes.get(key);
99
+ if (index !== undefined && (known === undefined || index < known)) {
100
+ indexes.set(key, index);
101
+ }
102
+ }
103
+ // without any index the order of first appearance stays as it is
104
+ if (indexes.size > 0) {
105
+ const rank = (bucket) => { var _a; return (_a = indexes.get(bucket.key)) !== null && _a !== void 0 ? _a : Number.POSITIVE_INFINITY; };
106
+ buckets.sort((a, b) => (rank(a) === rank(b) ? 0 : rank(a) < rank(b) ? -1 : 1));
84
107
  }
85
108
  return buckets;
86
109
  }
110
+ const rows = db.exec(`SELECT ${intervalBucketSQL(interval)} as __interval FROM ${fromExpr}`);
87
111
  const seen = new Set();
88
112
  const dates = [];
89
113
  for (const row of rows) {