@bino-bi/bn-template-engine 1.0.0-alpha.4 → 1.0.0-alpha.6
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.
- package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
- package/dist/bn-template-engine/p-06946f44.entry.js +1 -0
- package/dist/bn-template-engine/p-0fabe296.entry.js +1 -0
- package/dist/bn-template-engine/p-1164c0b0.entry.js +1 -0
- package/dist/bn-template-engine/p-355abdf0.entry.js +1 -0
- package/dist/bn-template-engine/p-79KuA4Ox.js +1 -0
- package/dist/bn-template-engine/p-859cc06d.entry.js +1 -0
- package/dist/bn-template-engine/p-8acec99e.entry.js +1 -0
- package/dist/bn-template-engine/p-8f490c45.entry.js +1 -0
- package/dist/bn-template-engine/p-98cf512f.entry.js +1 -0
- package/dist/bn-template-engine/p-9a564f8f.entry.js +1 -0
- package/dist/bn-template-engine/{p-CL1RYuNU.js → p-B0lsgVuN.js} +1 -1
- package/dist/bn-template-engine/p-B7p8beYH.js +1 -0
- package/dist/bn-template-engine/p-BDh7GfC5.js +1 -0
- package/dist/bn-template-engine/p-BoMtoHJB.js +1 -0
- package/dist/bn-template-engine/p-Bs8BqBsb.js +1 -0
- package/dist/bn-template-engine/p-CYjZRKdI.js +1 -0
- package/dist/bn-template-engine/{p-P7pGJBgc.js → p-DG-1MR_T.js} +1 -1
- package/dist/bn-template-engine/p-bdd2b243.entry.js +1 -0
- package/dist/bn-template-engine/p-e6b24f15.entry.js +1 -0
- package/dist/bn-template-engine/p-f27995c9.entry.js +1 -0
- package/dist/bn-template-engine/{p-Bnhh02CF.js → p-sRO-lj7X.js} +1 -1
- package/dist/bn-template-engine/p-tzFCK9qn.js +1 -0
- package/dist/cjs/{Order-iG11HI4R.js → Order-BGx39pS5.js} +448 -0
- package/dist/cjs/{alasql.min-C_nHTuEQ.js → SVGVariancesStyleGroup-BqAdPYtL.js} +8228 -3
- package/dist/cjs/bn-asset_16.cjs.entry.js +9018 -0
- package/dist/cjs/bn-card.cjs.entry.js +3 -4
- package/dist/cjs/bn-chart-time.cjs.entry.js +11 -16
- package/dist/cjs/bn-grid.cjs.entry.js +5 -8
- package/dist/cjs/bn-image.cjs.entry.js +5 -8
- package/dist/cjs/bn-internationalization.cjs.entry.js +3 -4
- package/dist/cjs/bn-layout-card.cjs.entry.js +125 -6
- package/dist/cjs/bn-template-engine.cjs.js +1 -1
- package/dist/cjs/bn-template.cjs.entry.js +2 -3
- package/dist/cjs/bn-text.cjs.entry.js +7 -11
- package/dist/cjs/bn-tree.cjs.entry.js +5 -8
- package/dist/cjs/{formatter-DIJL_crx.js → formatter-4XCS0d2B.js} +8 -2
- package/dist/cjs/ibcs-chart-time.cjs.entry.js +37 -42
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{scaling-9Tz595RQ.js → scaling-BidPsO53.js} +115 -12
- package/dist/cjs/{withBodyObserver-CKpSD8UT.js → withBodyObserver-C6gLgq_e.js} +3 -3
- package/dist/cjs/{withComponentStatus-Bw70BhO0.js → withComponentStatus-_x4LQZ0N.js} +5 -5
- package/dist/cjs/{withComponentStyle-aIbTCtfj.js → withComponentStyle-ClSJfCku.js} +4 -4
- package/dist/cjs/{utils-CwHIVbbL.js → withHasError-B8gHkfV2.js} +69 -1
- package/dist/cjs/{withStyled-CS1Yp4sv.js → withStyled-9tG024gQ.js} +62 -9
- package/dist/collection/components/bn-chart-structure/utils/elements/Label.js +11 -0
- package/dist/collection/components/bn-chart-structure/utils/elements/StackedBar.js +5 -2
- package/dist/collection/components/bn-layout-card/bn-layout-card.css +1 -0
- package/dist/collection/components/bn-layout-card/bn-layout-card.js +162 -27
- package/dist/collection/components/bn-layout-page/bn-layout-page.css +1 -0
- package/dist/collection/components/bn-layout-page/bn-layout-page.js +151 -33
- package/dist/collection/components/bn-table/bn-table.js +12 -10
- package/dist/collection/components/bn-table/ibcs-table.js +2 -2
- package/dist/collection/utils/parentDimensions.js +38 -6
- package/dist/components/bn-layout-card.js +1 -1
- package/dist/components/bn-layout-page.js +1 -1
- package/dist/components/bn-table.js +1 -1
- package/dist/components/ibcs-chart-structure2.js +1 -1
- package/dist/components/ibcs-table2.js +1 -1
- package/dist/components/scaling.js +1 -1
- package/dist/esm/{Order-Bnhh02CF.js → Order-sRO-lj7X.js} +448 -1
- package/dist/esm/{alasql.min-CWu4NkIt.js → SVGVariancesStyleGroup-DOIT-zvI.js} +8212 -2
- package/dist/esm/bn-asset_16.entry.js +9001 -0
- package/dist/esm/bn-card.entry.js +4 -5
- package/dist/esm/bn-chart-time.entry.js +8 -13
- package/dist/esm/bn-grid.entry.js +6 -9
- package/dist/esm/bn-image.entry.js +6 -9
- package/dist/esm/bn-internationalization.entry.js +4 -5
- package/dist/esm/bn-layout-card.entry.js +126 -7
- package/dist/esm/bn-template-engine.js +1 -1
- package/dist/esm/bn-template.entry.js +2 -3
- package/dist/esm/bn-text.entry.js +7 -11
- package/dist/esm/bn-tree.entry.js +6 -9
- package/dist/esm/{context-protocol-BHnQsVsr.js → context-protocol-2peaD4y8.js} +1 -1
- package/dist/esm/editor-companion.entry.js +1 -1
- package/dist/esm/{formatter-DTMEZ6d8.js → formatter-BDh7GfC5.js} +6 -2
- package/dist/esm/ibcs-chart-time.entry.js +3 -8
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{scaling-Cehc74IE.js → scaling-BOcjT8M0.js} +112 -10
- package/dist/esm/{withBodyObserver-FQ8NwCIz.js → withBodyObserver-DczL5ia8.js} +1 -1
- package/dist/esm/{withComponentStatus-DWjDYtZ7.js → withComponentStatus-DodoSXe-.js} +1 -1
- package/dist/esm/{withComponentStyle-9uP_hcDq.js → withComponentStyle-D3VWOsto.js} +2 -2
- package/dist/esm/{utils-DvvwfRQG.js → withHasError-B3QX2emi.js} +69 -1
- package/dist/esm/{withStyled--qQWquTH.js → withStyled-CE3_3taP.js} +57 -5
- package/dist/types/components/bn-chart-structure/utils/elements/Label.d.ts +2 -0
- package/dist/types/components/bn-layout-card/bn-layout-card.d.ts +139 -0
- package/dist/types/components/bn-layout-page/bn-layout-page.d.ts +154 -0
- package/dist/types/components/bn-table/bn-table.d.ts +7 -5
- package/dist/types/components.d.ts +170 -2
- package/dist/types/utils/parentDimensions.d.ts +6 -1
- package/package.json +1 -1
- package/dist/bn-template-engine/p-1265d8d3.entry.js +0 -1
- package/dist/bn-template-engine/p-15516dac.entry.js +0 -1
- package/dist/bn-template-engine/p-1c716641.entry.js +0 -1
- package/dist/bn-template-engine/p-1jFf17Vj.js +0 -1
- package/dist/bn-template-engine/p-27cc8dc0.entry.js +0 -1
- package/dist/bn-template-engine/p-4426d484.entry.js +0 -1
- package/dist/bn-template-engine/p-51f8dc9e.entry.js +0 -1
- package/dist/bn-template-engine/p-53d4e690.entry.js +0 -1
- package/dist/bn-template-engine/p-5KQYRQLK.js +0 -1
- package/dist/bn-template-engine/p-745f4596.entry.js +0 -1
- package/dist/bn-template-engine/p-75e97c87.entry.js +0 -1
- package/dist/bn-template-engine/p-7a560278.entry.js +0 -1
- package/dist/bn-template-engine/p-7ea7c325.entry.js +0 -1
- package/dist/bn-template-engine/p-945cc95d.entry.js +0 -1
- package/dist/bn-template-engine/p-BFTU3MAI.js +0 -1
- package/dist/bn-template-engine/p-BYBpC0EO.js +0 -1
- package/dist/bn-template-engine/p-BYmPQYxx.js +0 -1
- package/dist/bn-template-engine/p-BfXY5dsy.js +0 -1
- package/dist/bn-template-engine/p-BgnHJQ9Q.js +0 -1
- package/dist/bn-template-engine/p-Bhd_WSML.js +0 -1
- package/dist/bn-template-engine/p-Bka-Z6jo.js +0 -1
- package/dist/bn-template-engine/p-C7dQL8CS.js +0 -1
- package/dist/bn-template-engine/p-CYwd_ZNM.js +0 -1
- package/dist/bn-template-engine/p-ChlK-T9I.js +0 -1
- package/dist/bn-template-engine/p-DHezf8pZ.js +0 -1
- package/dist/bn-template-engine/p-DlppAFq9.js +0 -1
- package/dist/bn-template-engine/p-DvDDgmcV.js +0 -1
- package/dist/bn-template-engine/p-DvvwfRQG.js +0 -1
- package/dist/bn-template-engine/p-b34eaf86.entry.js +0 -1
- package/dist/bn-template-engine/p-bdb8b44c.entry.js +0 -1
- package/dist/bn-template-engine/p-c44fcb8e.entry.js +0 -1
- package/dist/bn-template-engine/p-c7e1a49b.entry.js +0 -1
- package/dist/bn-template-engine/p-d9003041.entry.js +0 -1
- package/dist/bn-template-engine/p-daa7ffa3.entry.js +0 -1
- package/dist/bn-template-engine/p-e084f50a.entry.js +0 -1
- package/dist/bn-template-engine/p-eaba6658.entry.js +0 -1
- package/dist/bn-template-engine/p-u8igQLRZ.js +0 -1
- package/dist/cjs/DataFormatDigits-DKcOeLNK.js +0 -142
- package/dist/cjs/DateStringFactory-CSKvbS8K.js +0 -452
- package/dist/cjs/SVGVariancesStyleGroup-K-Tw6lOD.js +0 -7960
- package/dist/cjs/_commonjsHelpers-BJu3ubxk.js +0 -10
- package/dist/cjs/bn-asset.cjs.entry.js +0 -42
- package/dist/cjs/bn-body_4.cjs.entry.js +0 -748
- package/dist/cjs/bn-chart-structure_5.cjs.entry.js +0 -3934
- package/dist/cjs/bn-component-style.cjs.entry.js +0 -44
- package/dist/cjs/bn-dataset.cjs.entry.js +0 -306
- package/dist/cjs/bn-layout-page.cjs.entry.js +0 -143
- package/dist/cjs/bn-message.cjs.entry.js +0 -52
- package/dist/cjs/bn-table.cjs.entry.js +0 -979
- package/dist/cjs/contentDecoder-JxOldq1e.js +0 -419
- package/dist/cjs/emotion-hash.esm-nbbEQ0Dn.js +0 -57
- package/dist/cjs/ibcs-table.cjs.entry.js +0 -2276
- package/dist/cjs/ibcsRuleSet-DgUoXOfd.js +0 -136
- package/dist/cjs/index-Dm85hG6t.js +0 -65
- package/dist/cjs/withHasError-D7ue5vAv.js +0 -72
- package/dist/cjs/withTranslation-rwgyITqe.js +0 -77
- package/dist/esm/DataFormatDigits-oSZ1hBKE.js +0 -137
- package/dist/esm/DateStringFactory-CSGz6TDk.js +0 -450
- package/dist/esm/SVGVariancesStyleGroup-CqTjrZYg.js +0 -7950
- package/dist/esm/_commonjsHelpers-BFTU3MAI.js +0 -7
- package/dist/esm/bn-asset.entry.js +0 -40
- package/dist/esm/bn-body_4.entry.js +0 -743
- package/dist/esm/bn-chart-structure_5.entry.js +0 -3928
- package/dist/esm/bn-component-style.entry.js +0 -42
- package/dist/esm/bn-dataset.entry.js +0 -304
- package/dist/esm/bn-layout-page.entry.js +0 -141
- package/dist/esm/bn-message.entry.js +0 -50
- package/dist/esm/bn-table.entry.js +0 -977
- package/dist/esm/contentDecoder-oMmxz6nJ.js +0 -416
- package/dist/esm/emotion-hash.esm-BYBpC0EO.js +0 -55
- package/dist/esm/ibcs-table.entry.js +0 -2274
- package/dist/esm/ibcsRuleSet-K4ytuA1f.js +0 -133
- package/dist/esm/index-DHezf8pZ.js +0 -65
- package/dist/esm/withHasError-FyY5mQ_3.js +0 -70
- package/dist/esm/withTranslation-BqD0Kp7b.js +0 -75
|
@@ -1,2274 +0,0 @@
|
|
|
1
|
-
import { h, r as registerInstance, H as Host, g as getElement } from './index-JNHhIe7t.js';
|
|
2
|
-
import { a as TableRowType, T as TableType, O as OrderDirection, F as FactoryState } from './index-DHezf8pZ.js';
|
|
3
|
-
import { F as Formatter, Q as QueryColumnNames, V as VarianceScenario } from './formatter-DTMEZ6d8.js';
|
|
4
|
-
import { I as I18nMode, d as DataFormat, g as CompareUtil, f as AdapterUtils, l as OrderAdapter, T as TableCategoryWidth, M as MeasureType } from './Order-Bnhh02CF.js';
|
|
5
|
-
import { a as alasql } from './alasql.min-CWu4NkIt.js';
|
|
6
|
-
import { I as IBCSRuleSet, S as StringAdapter } from './ibcsRuleSet-K4ytuA1f.js';
|
|
7
|
-
import { D as DataAnalyzer, S as SiPrefix, a as DataFormatDigits, b as DataFormatDigitsAdapter } from './DataFormatDigits-oSZ1hBKE.js';
|
|
8
|
-
import { w as withComponentStyle } from './withComponentStyle-9uP_hcDq.js';
|
|
9
|
-
import './_commonjsHelpers-BFTU3MAI.js';
|
|
10
|
-
import './context-protocol-BHnQsVsr.js';
|
|
11
|
-
import './utils-DvvwfRQG.js';
|
|
12
|
-
|
|
13
|
-
// import {Formatter} from "../../../../utils/formatter";
|
|
14
|
-
// import {DataFormatDigits} from "../../../../utils/model/DataFormatDigits";
|
|
15
|
-
/**
|
|
16
|
-
* Represents a single table cell with formatting and rendering capabilities.
|
|
17
|
-
*
|
|
18
|
-
* The draw() method implements a formatting pipeline:
|
|
19
|
-
* 1. Checks for undefined/null/NaN values -- returns empty string for missing data
|
|
20
|
-
* 2. Non-numeric values (category labels) are returned as-is
|
|
21
|
-
* 3. Numeric values are routed through Formatter.number() with the cell's type
|
|
22
|
-
* (decimal or percent) and configured digit precision
|
|
23
|
-
* 4. For decimal type, the raw value is divided by measureScale before formatting,
|
|
24
|
-
* enabling SI prefix display (e.g. "in Mio EUR")
|
|
25
|
-
*/
|
|
26
|
-
class Cell {
|
|
27
|
-
constructor(scenario, index, value, cssStyle, type, prefix, prefixStyle, colSpan, measureScale) {
|
|
28
|
-
this.prefixStyle = "prefix";
|
|
29
|
-
this.isBarChart = false;
|
|
30
|
-
this.key = scenario;
|
|
31
|
-
this.index = index;
|
|
32
|
-
this.value = value;
|
|
33
|
-
this.prefix = prefix || "";
|
|
34
|
-
this.cssStyle = cssStyle || "";
|
|
35
|
-
this.prefixStyle = prefixStyle || "prefix";
|
|
36
|
-
this.type = type;
|
|
37
|
-
this.mark = undefined;
|
|
38
|
-
this.colSpan = colSpan || 1;
|
|
39
|
-
this.measureScale = measureScale || 1;
|
|
40
|
-
}
|
|
41
|
-
getAsHeaderList() {
|
|
42
|
-
if (this.value == null) {
|
|
43
|
-
return [""];
|
|
44
|
-
}
|
|
45
|
-
const result = [];
|
|
46
|
-
for (const line of this.value.toString().split("<br/>")) {
|
|
47
|
-
result.push(line);
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
draw(dataFormatDigits) {
|
|
52
|
-
let cellValue = this.value;
|
|
53
|
-
if (cellValue === "undefined" || cellValue === undefined || cellValue == null) {
|
|
54
|
-
return "";
|
|
55
|
-
}
|
|
56
|
-
if (Number.isNaN(Number(cellValue))) {
|
|
57
|
-
return cellValue;
|
|
58
|
-
}
|
|
59
|
-
if (this.type === "" || this.type === undefined || this.type == null) {
|
|
60
|
-
return cellValue;
|
|
61
|
-
}
|
|
62
|
-
let digitsMin = dataFormatDigits.percent;
|
|
63
|
-
let scale = dataFormatDigits.percent;
|
|
64
|
-
if (this.type === "decimal") {
|
|
65
|
-
cellValue = +cellValue / this.measureScale;
|
|
66
|
-
digitsMin = dataFormatDigits.decimal;
|
|
67
|
-
scale = dataFormatDigits.decimal;
|
|
68
|
-
}
|
|
69
|
-
return Formatter.number(Number(cellValue), this.type, digitsMin, scale);
|
|
70
|
-
}
|
|
71
|
-
drawPrefix() {
|
|
72
|
-
if (this.prefix == null) {
|
|
73
|
-
return "";
|
|
74
|
-
}
|
|
75
|
-
return this.prefix;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Represents a single row in an IBCS table, containing an ordered list of Cells.
|
|
81
|
-
*
|
|
82
|
-
* The CSS class is determined by the TableRowType:
|
|
83
|
-
* - HEADER -> "groupheader"
|
|
84
|
-
* - SEPERATORLINE -> "" (styled via cell-level scenario classes)
|
|
85
|
-
* - DRILLELEMENT -> "ofit" (thereof rows)
|
|
86
|
-
* - PARTELEMENT -> "partof" (percentage-of-parent rows)
|
|
87
|
-
* - SUM -> "sum"
|
|
88
|
-
* - STANDARD -> ""
|
|
89
|
-
*
|
|
90
|
-
* createElement() applies type-specific overrides:
|
|
91
|
-
* - HEADER rows force "headerlabel" CSS on all cells
|
|
92
|
-
* - SEPERATORLINE rows use the scenario name as CSS class for border styling
|
|
93
|
-
* - PARTELEMENT rows show "-" for percent cells and force percent type on data cells
|
|
94
|
-
*/
|
|
95
|
-
class TableRow {
|
|
96
|
-
constructor(index, groupIndex, type) {
|
|
97
|
-
this.index = index;
|
|
98
|
-
this.groupindex = groupIndex;
|
|
99
|
-
this.type = type;
|
|
100
|
-
this.cssStyle = this.initCssStyle();
|
|
101
|
-
this.elements = [];
|
|
102
|
-
}
|
|
103
|
-
initCssStyle() {
|
|
104
|
-
switch (this.type) {
|
|
105
|
-
case TableRowType.HEADER: {
|
|
106
|
-
return "groupheader";
|
|
107
|
-
}
|
|
108
|
-
case TableRowType.SEPERATORLINE: {
|
|
109
|
-
return "";
|
|
110
|
-
}
|
|
111
|
-
case TableRowType.DRILLELEMENT: {
|
|
112
|
-
return "ofit";
|
|
113
|
-
}
|
|
114
|
-
case TableRowType.PARTELEMENT: {
|
|
115
|
-
return "partof";
|
|
116
|
-
}
|
|
117
|
-
case TableRowType.STANDARD: {
|
|
118
|
-
return "";
|
|
119
|
-
}
|
|
120
|
-
case TableRowType.SUM: {
|
|
121
|
-
return "sum";
|
|
122
|
-
}
|
|
123
|
-
default: {
|
|
124
|
-
return "";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
getCells() {
|
|
129
|
-
return this.elements;
|
|
130
|
-
}
|
|
131
|
-
createElement(value, scenario, columnType, cellType, prefix, cellStyle, isSecondaryElement, categoryWidth, measureScale, isBarChart = false, columnStats) {
|
|
132
|
-
let cssStyle = cellStyle;
|
|
133
|
-
if (scenario === "category" && categoryWidth != null) {
|
|
134
|
-
cssStyle = `category-${categoryWidth.toString()}`;
|
|
135
|
-
}
|
|
136
|
-
if (this.type === TableRowType.HEADER) {
|
|
137
|
-
cssStyle = "headerlabel";
|
|
138
|
-
}
|
|
139
|
-
else if (this.type === TableRowType.SEPERATORLINE) {
|
|
140
|
-
cssStyle = scenario;
|
|
141
|
-
}
|
|
142
|
-
if (this.type === TableRowType.PARTELEMENT) {
|
|
143
|
-
if (cellType === "percent") {
|
|
144
|
-
value = "-";
|
|
145
|
-
}
|
|
146
|
-
if (scenario !== "category" && scenario !== "operation") {
|
|
147
|
-
cellType = "percent";
|
|
148
|
-
cssStyle = "";
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (value === "-") {
|
|
152
|
-
cssStyle = "";
|
|
153
|
-
}
|
|
154
|
-
let prefixStyle = "prefix-first";
|
|
155
|
-
if (isSecondaryElement) {
|
|
156
|
-
prefixStyle = "prefix-second";
|
|
157
|
-
}
|
|
158
|
-
if (columnType) {
|
|
159
|
-
cssStyle = `${cssStyle} ${columnType}`;
|
|
160
|
-
}
|
|
161
|
-
const cell = new Cell(scenario, this.elements.length, value, cssStyle, cellType, prefix, prefixStyle, 1, measureScale);
|
|
162
|
-
cell.isBarChart = isBarChart;
|
|
163
|
-
cell.columnStats = columnStats;
|
|
164
|
-
this.elements.push(cell);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Default fallback colors (should come from componentStyle)
|
|
169
|
-
const DEFAULT_STYLES = {
|
|
170
|
-
positive: { stroke: "#008f96", fill: "#008f96", fillpattern: "solid" },
|
|
171
|
-
negative: { stroke: "#ff0000", fill: "#ff0000", fillpattern: "solid" },
|
|
172
|
-
neutral: { stroke: "#808080", fill: "#808080", fillpattern: "outlined" },
|
|
173
|
-
scenarios: {
|
|
174
|
-
ac: { stroke: "#404040", fill: "#404040", fillpattern: "solid" },
|
|
175
|
-
pp: { stroke: "#A6A6A6", fill: "#A6A6A6", fillpattern: "solid" },
|
|
176
|
-
fc: { stroke: "#404040", fill: "#ffffff", fillpattern: "hatched" },
|
|
177
|
-
pl: { stroke: "#404040", fill: "#ffffff", fillpattern: "outlined" },
|
|
178
|
-
},
|
|
179
|
-
fontColor: "#000000",
|
|
180
|
-
fontSize: 11,
|
|
181
|
-
fontFamily: "'Noto Sans', sans-serif",
|
|
182
|
-
unitScaling: 0.01, // Default: 1000 units = 10 pixels
|
|
183
|
-
percentageScaling: 0.5, // Default: 100% = 50 pixels
|
|
184
|
-
scaleFactor: 1,
|
|
185
|
-
};
|
|
186
|
-
const AXIS_COLOR = "#666666";
|
|
187
|
-
/**
|
|
188
|
-
* Creates a unique pattern ID for the SVG defs
|
|
189
|
-
*/
|
|
190
|
-
function getPatternId(prefix, color) {
|
|
191
|
-
return `pattern-${prefix}-${color.replace("#", "")}`;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Renders SVG pattern definitions for hatched fills
|
|
195
|
-
*/
|
|
196
|
-
const PatternDefs = ({ styles }) => {
|
|
197
|
-
const s = styles.scaleFactor;
|
|
198
|
-
const patternSize = 6 * s;
|
|
199
|
-
const patterns = [
|
|
200
|
-
{ id: getPatternId("pos", styles.positive.stroke), stroke: styles.positive.stroke, fill: styles.positive.fill },
|
|
201
|
-
{ id: getPatternId("neg", styles.negative.stroke), stroke: styles.negative.stroke, fill: styles.negative.fill },
|
|
202
|
-
{ id: getPatternId("neu", styles.neutral.stroke), stroke: styles.neutral.stroke, fill: styles.neutral.fill },
|
|
203
|
-
];
|
|
204
|
-
return (h("defs", null, patterns.map((p) => (h("pattern", { id: p.id, patternUnits: "userSpaceOnUse", width: patternSize, height: patternSize }, h("rect", { width: patternSize, height: patternSize, fill: "#ffffff" }), h("line", { x1: "0", y1: patternSize, x2: patternSize, y2: "0", stroke: p.stroke, "stroke-width": 1.5 * s }))))));
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Formats a number for display with appropriate SI prefix.
|
|
208
|
-
*/
|
|
209
|
-
function formatValue(value, isRelative, measureScale = 1) {
|
|
210
|
-
let scaledValue;
|
|
211
|
-
let absValue;
|
|
212
|
-
const prefix = value >= 0 ? "+" : "";
|
|
213
|
-
if (isRelative) {
|
|
214
|
-
// Relative variance is stored as decimal (e.g., -2.0 = -200%)
|
|
215
|
-
// Multiply by 100 to get percentage value for display
|
|
216
|
-
scaledValue = value * 100;
|
|
217
|
-
// Show as integer percentage with % suffix
|
|
218
|
-
return prefix + Math.round(scaledValue).toString() + "%";
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
// Absolute variance - apply measure scale and use SI prefixes
|
|
222
|
-
scaledValue = value / measureScale;
|
|
223
|
-
absValue = Math.abs(scaledValue);
|
|
224
|
-
let formatted;
|
|
225
|
-
if (absValue >= 1000000000) {
|
|
226
|
-
formatted = (scaledValue / 1000000000).toFixed(absValue >= 10000000000 ? 0 : 1) + "B";
|
|
227
|
-
}
|
|
228
|
-
else if (absValue >= 1000000) {
|
|
229
|
-
formatted = (scaledValue / 1000000).toFixed(absValue >= 10000000 ? 0 : 1) + "M";
|
|
230
|
-
}
|
|
231
|
-
else if (absValue >= 1000) {
|
|
232
|
-
formatted = (scaledValue / 1000).toFixed(absValue >= 10000 ? 0 : 1) + "K";
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
formatted = scaledValue.toFixed(absValue >= 10 ? 0 : 1);
|
|
236
|
-
}
|
|
237
|
-
// Remove trailing .0 if present
|
|
238
|
-
formatted = formatted.replace(/\.0([KMB]?)$/, "$1");
|
|
239
|
-
return prefix + formatted;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Checks if the column is a scenario column (ac, pp, fc, pl) vs variance (d_, dr_).
|
|
244
|
-
*/
|
|
245
|
-
function isScenarioColumn(scenario) {
|
|
246
|
-
const scenarioPrefix = scenario.slice(0, 2).toLowerCase();
|
|
247
|
-
return ["ac", "pp", "fc", "pl"].includes(scenarioPrefix);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Gets the scenario type from the column name (ac, pp, fc, pl).
|
|
251
|
-
*/
|
|
252
|
-
function getScenarioType(scenario) {
|
|
253
|
-
const scenarioPrefix = scenario.slice(0, 2).toLowerCase();
|
|
254
|
-
if (scenarioPrefix === "pp")
|
|
255
|
-
return "pp";
|
|
256
|
-
if (scenarioPrefix === "fc")
|
|
257
|
-
return "fc";
|
|
258
|
-
if (scenarioPrefix === "pl")
|
|
259
|
-
return "pl";
|
|
260
|
-
return "ac"; // default
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Gets the style for a scenario column (ac, pp, fc, pl).
|
|
264
|
-
*/
|
|
265
|
-
function getScenarioStyle(scenario, styles) {
|
|
266
|
-
const type = getScenarioType(scenario);
|
|
267
|
-
return styles.scenarios[type];
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Gets the variance style based on value and sentiment direction.
|
|
271
|
-
* pos suffix = positive values are good (green), negative are bad (red)
|
|
272
|
-
* neg suffix = negative values are good (green), positive are bad (red)
|
|
273
|
-
*/
|
|
274
|
-
function getVarianceStyle(value, isPositiveGood, styles) {
|
|
275
|
-
const isPositive = value >= 0;
|
|
276
|
-
if (isPositiveGood) {
|
|
277
|
-
return isPositive ? styles.positive : styles.negative;
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
return isPositive ? styles.negative : styles.positive;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Gets the appropriate style for a bar based on column type.
|
|
285
|
-
* Scenarios (ac, pp, fc, pl) use scenario styles.
|
|
286
|
-
* Variances (d_, dr_) use variance styles with pos/neg/neu coloring.
|
|
287
|
-
*/
|
|
288
|
-
function getBarStyle(scenario, value, isPositiveGood, styles) {
|
|
289
|
-
if (isScenarioColumn(scenario)) {
|
|
290
|
-
return getScenarioStyle(scenario, styles);
|
|
291
|
-
}
|
|
292
|
-
return getVarianceStyle(value, isPositiveGood, styles);
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Gets the fill value for a bar - either solid color, pattern URL, or transparent with stroke.
|
|
296
|
-
*/
|
|
297
|
-
function getBarFill(varianceStyle, patternPrefix) {
|
|
298
|
-
const pattern = varianceStyle.fillpattern;
|
|
299
|
-
if (pattern === "hatched") {
|
|
300
|
-
return `url(#${getPatternId(patternPrefix, varianceStyle.stroke)})`;
|
|
301
|
-
}
|
|
302
|
-
if (pattern === "outlined") {
|
|
303
|
-
return "transparent";
|
|
304
|
-
}
|
|
305
|
-
// Default: solid fill
|
|
306
|
-
return varianceStyle.fill;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Gets the stroke for a bar based on pattern type.
|
|
310
|
-
*/
|
|
311
|
-
function getBarStroke(varianceStyle) {
|
|
312
|
-
const pattern = varianceStyle.fillpattern;
|
|
313
|
-
if (pattern === "outlined") {
|
|
314
|
-
return { stroke: varianceStyle.stroke, strokeWidth: 1.5 }; // scaled by caller via * s
|
|
315
|
-
}
|
|
316
|
-
// Solid and hatched bars don't need visible stroke
|
|
317
|
-
return { stroke: "none", strokeWidth: 0 };
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Renders a zigzag break indicator at a given x position, matching the structure chart style.
|
|
321
|
-
* Two mirrored zigzag lines with a white background covering the break gap.
|
|
322
|
-
*/
|
|
323
|
-
function renderZigzagBreak(breakX, breakGap, yTop, barHeight, s) {
|
|
324
|
-
const midX = breakX + breakGap / 2;
|
|
325
|
-
const halfGap = breakGap * 0.35;
|
|
326
|
-
const zigCount = 3;
|
|
327
|
-
const segHeight = barHeight / zigCount;
|
|
328
|
-
const amplitude = breakGap * 0.3;
|
|
329
|
-
let leftPath = `M ${midX - halfGap} ${yTop}`;
|
|
330
|
-
for (let i = 0; i < zigCount; i++) {
|
|
331
|
-
const y1 = yTop + segHeight * (i + 0.5);
|
|
332
|
-
const y2 = yTop + segHeight * (i + 1);
|
|
333
|
-
leftPath += ` L ${midX - halfGap - amplitude} ${y1} L ${midX - halfGap} ${y2}`;
|
|
334
|
-
}
|
|
335
|
-
let rightPath = `M ${midX + halfGap} ${yTop}`;
|
|
336
|
-
for (let i = 0; i < zigCount; i++) {
|
|
337
|
-
const y1 = yTop + segHeight * (i + 0.5);
|
|
338
|
-
const y2 = yTop + segHeight * (i + 1);
|
|
339
|
-
rightPath += ` L ${midX + halfGap + amplitude} ${y1} L ${midX + halfGap} ${y2}`;
|
|
340
|
-
}
|
|
341
|
-
return [
|
|
342
|
-
h("rect", { x: breakX, y: yTop - 1, width: breakGap, height: barHeight + 2, fill: "#ffffff" }),
|
|
343
|
-
h("path", { d: leftPath, fill: "none", stroke: "#000000", "stroke-width": 1 * s }),
|
|
344
|
-
h("path", { d: rightPath, fill: "none", stroke: "#000000", "stroke-width": 1 * s }),
|
|
345
|
-
];
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Renders an absolute variance bar chart (d_ prefix).
|
|
349
|
-
* Horizontal bar with centered axis, green for positive, red for negative.
|
|
350
|
-
* When a bar exceeds maxBarWidth it is drawn as an overdrive bar:
|
|
351
|
-
* base segment + zigzag break + proportional overdrive stub (like structure chart).
|
|
352
|
-
*
|
|
353
|
-
* Layout: [left label area][bar area with axis][right label area]
|
|
354
|
-
*/
|
|
355
|
-
const AbsoluteVarianceBar = (props) => {
|
|
356
|
-
const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, maxBarWidth: maxBarWidthEm = 10, styles = DEFAULT_STYLES, } = props;
|
|
357
|
-
const s = styles.scaleFactor;
|
|
358
|
-
const fs = styles.fontSize;
|
|
359
|
-
const labelAreaWidth = 38 * s;
|
|
360
|
-
const maxBarWidth = maxBarWidthEm * fs;
|
|
361
|
-
// Overdrive layout constants
|
|
362
|
-
const breakGap = 4 * s;
|
|
363
|
-
const overdriveZoneWidth = maxBarWidth * 0.15;
|
|
364
|
-
const cutWidth = maxBarWidth - breakGap - overdriveZoneWidth;
|
|
365
|
-
// Direct unit scaling via fontSize
|
|
366
|
-
const scaledWidth = Math.abs(value) * styles.unitScaling * fs;
|
|
367
|
-
const isExtreme = scaledWidth > cutWidth;
|
|
368
|
-
// Compute proportional overdrive width across the column
|
|
369
|
-
const maxScaledWidth = columnStats.absMax * styles.unitScaling * fs;
|
|
370
|
-
const maxOverflow = Math.max(0, maxScaledWidth - cutWidth);
|
|
371
|
-
const overflowAmount = Math.max(0, scaledWidth - cutWidth);
|
|
372
|
-
const overdriveWidth = maxOverflow > 0 ? (overflowAmount / maxOverflow) * overdriveZoneWidth : 0;
|
|
373
|
-
// Adaptive axis placement based on data range
|
|
374
|
-
const hasNeg = columnStats.min < 0;
|
|
375
|
-
const hasPos = columnStats.max > 0;
|
|
376
|
-
const negBarWidth = hasNeg ? maxBarWidth : 0;
|
|
377
|
-
const posBarWidth = hasPos ? maxBarWidth : 0;
|
|
378
|
-
const barAreaWidth = negBarWidth + posBarWidth;
|
|
379
|
-
const totalWidth = (hasNeg ? labelAreaWidth : 0) + barAreaWidth + (hasPos ? labelAreaWidth : 0);
|
|
380
|
-
const padding = 2 * s;
|
|
381
|
-
const barHeight = height - padding * 2;
|
|
382
|
-
const axisX = (hasNeg ? labelAreaWidth : 0) + negBarWidth;
|
|
383
|
-
const barY = padding;
|
|
384
|
-
const isPositive = value >= 0;
|
|
385
|
-
// Get style based on column type (scenario vs variance)
|
|
386
|
-
const barStyle = getBarStyle(scenario, value, isPositiveGood, styles);
|
|
387
|
-
const patternPrefix = isScenarioColumn(scenario)
|
|
388
|
-
? getScenarioType(scenario)
|
|
389
|
-
: isPositiveGood
|
|
390
|
-
? isPositive
|
|
391
|
-
? "pos"
|
|
392
|
-
: "neg"
|
|
393
|
-
: isPositive
|
|
394
|
-
? "neg"
|
|
395
|
-
: "pos";
|
|
396
|
-
const fillValue = getBarFill(barStyle, patternPrefix);
|
|
397
|
-
const { stroke: barStroke, strokeWidth: barStrokeWidth } = getBarStroke(barStyle);
|
|
398
|
-
const displayValue = formattedValue || formatValue(value, false, measureScale);
|
|
399
|
-
// Normal bar width (clamped to cutWidth when extreme)
|
|
400
|
-
const baseBarWidth = isExtreme ? cutWidth : scaledWidth;
|
|
401
|
-
// Label position accounts for overdrive
|
|
402
|
-
const totalVisualWidth = isExtreme ? cutWidth + breakGap + overdriveWidth : scaledWidth;
|
|
403
|
-
const labelX = isPositive ? axisX + totalVisualWidth + 4 * s : axisX - totalVisualWidth - 4 * s;
|
|
404
|
-
const labelAnchor = isPositive ? "start" : "end";
|
|
405
|
-
return (h("svg", { width: totalWidth, height: height, class: "cell-bar-chart absolute-variance", style: { overflow: "visible" } }, h(PatternDefs, { styles: styles }), h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), baseBarWidth > 0 && (h("rect", { x: isPositive ? axisX : axisX - baseBarWidth, y: barY, width: baseBarWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme && overdriveWidth > 0 && (h("rect", { x: isPositive ? axisX + cutWidth + breakGap : axisX - cutWidth - breakGap - overdriveWidth, y: barY, width: overdriveWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme &&
|
|
406
|
-
renderZigzagBreak(isPositive ? axisX + cutWidth : axisX - cutWidth - breakGap, breakGap, barY, barHeight, 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)));
|
|
407
|
-
};
|
|
408
|
-
/**
|
|
409
|
-
* Renders a relative variance pin chart (dr_ prefix).
|
|
410
|
-
* Thin horizontal line from axis with dot at end and value label.
|
|
411
|
-
*
|
|
412
|
-
* Layout: [pin area with axis][label area on right]
|
|
413
|
-
* Uses percentageScaling to determine pin length (pixels per percentage point).
|
|
414
|
-
*/
|
|
415
|
-
const RelativeVariancePin = (props) => {
|
|
416
|
-
const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, maxBarWidth: maxBarWidthEm = 10, styles = DEFAULT_STYLES, } = props;
|
|
417
|
-
const s = styles.scaleFactor;
|
|
418
|
-
const fs = styles.fontSize;
|
|
419
|
-
// Pin length is ~2/3 of bar width for visual balance
|
|
420
|
-
const maxPinLength = Math.round(maxBarWidthEm * 0.67 * fs);
|
|
421
|
-
const pinPadding = 5 * s;
|
|
422
|
-
// Adaptive axis placement based on data range
|
|
423
|
-
const hasNeg = columnStats.min < 0;
|
|
424
|
-
const hasPos = columnStats.max > 0;
|
|
425
|
-
const negPinWidth = hasNeg ? maxPinLength + pinPadding : 0;
|
|
426
|
-
const posPinWidth = hasPos ? maxPinLength + pinPadding : 0;
|
|
427
|
-
const pinAreaWidth = negPinWidth + posPinWidth;
|
|
428
|
-
const labelAreaWidth = 45 * s;
|
|
429
|
-
const totalWidth = pinAreaWidth + labelAreaWidth;
|
|
430
|
-
const axisX = negPinWidth;
|
|
431
|
-
const centerY = height / 2;
|
|
432
|
-
// Direct unit scaling via fontSize
|
|
433
|
-
const percentValue = Math.abs(value) * 100;
|
|
434
|
-
const scaledLength = percentValue * styles.percentageScaling * fs;
|
|
435
|
-
const isExtreme = scaledLength > maxPinLength;
|
|
436
|
-
const pinLength = Math.min(scaledLength, maxPinLength);
|
|
437
|
-
const isPositive = value >= 0;
|
|
438
|
-
const pinEndX = isPositive ? axisX + pinLength : axisX - pinLength;
|
|
439
|
-
// Get style based on column type (scenario vs variance)
|
|
440
|
-
const barStyle = getBarStyle(scenario, value, isPositiveGood, styles);
|
|
441
|
-
const dotRadius = 3 * s;
|
|
442
|
-
const displayValue = formattedValue || formatValue(value, true, measureScale);
|
|
443
|
-
// Label always on the right side after the pin area
|
|
444
|
-
const labelX = pinAreaWidth + 4 * s;
|
|
445
|
-
return (h("svg", { width: totalWidth, height: height, class: "cell-bar-chart relative-variance", style: { overflow: "visible" } }, h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), !isExtreme && h("circle", { cx: pinEndX, cy: centerY, r: dotRadius, fill: styles.fontColor }), h("line", { x1: axisX, y1: centerY, x2: pinEndX, y2: centerY, stroke: barStyle.fill, "stroke-width": 2 * s }), isExtreme && isPositive && (h("polygon", { points: `${axisX + maxPinLength},${centerY} ${axisX + maxPinLength - 6 * s},${centerY - 3 * s} ${axisX + maxPinLength - 6 * s},${centerY + 3 * s}`, fill: barStyle.fill })), isExtreme && !isPositive && (h("polygon", { points: `${axisX - maxPinLength},${centerY} ${axisX - maxPinLength + 6 * s},${centerY - 3 * s} ${axisX - maxPinLength + 6 * s},${centerY + 3 * s}`, fill: barStyle.fill })), h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": "start", fill: styles.fontColor, "font-size": fs, "font-style": "italic", "font-family": styles.fontFamily }, displayValue)));
|
|
446
|
-
};
|
|
447
|
-
/**
|
|
448
|
-
* CellBarChart - Renders IBCS-compliant variance bar charts.
|
|
449
|
-
*
|
|
450
|
-
* Absolute variance (d_ prefix): Horizontal bars with centered axis
|
|
451
|
-
* Relative variance (dr_ prefix): Pin/dot charts with value indication
|
|
452
|
-
*
|
|
453
|
-
* Uses componentStyle patterns from chart components for consistent styling.
|
|
454
|
-
*/
|
|
455
|
-
const CellBarChart = (props) => {
|
|
456
|
-
const { value, columnStats, isRelative, styles = DEFAULT_STYLES } = props;
|
|
457
|
-
// Handle invalid values
|
|
458
|
-
if (value === null || value === undefined || isNaN(value) || !columnStats || columnStats.absMax === 0) {
|
|
459
|
-
return (h("span", { class: "bar-chart-empty", style: { color: styles.fontColor, fontStyle: "italic" } }, "-"));
|
|
460
|
-
}
|
|
461
|
-
if (isRelative) {
|
|
462
|
-
return h(RelativeVariancePin, Object.assign({}, props));
|
|
463
|
-
}
|
|
464
|
-
return h(AbsoluteVarianceBar, Object.assign({}, props));
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Manages the GROUP BY column list for DataQuery's SQL statements and registers
|
|
469
|
-
* the `transformOperator` AlaSQL custom function.
|
|
470
|
-
*
|
|
471
|
-
* `transformOperator` converts the dataset's `operation` field (`"+"` or `"-"`)
|
|
472
|
-
* into a numeric multiplier (+1 / -1) so that SUM aggregations correctly add
|
|
473
|
-
* or subtract rows based on their sign.
|
|
474
|
-
*
|
|
475
|
-
* The GROUP BY columns are composed dynamically: always category + categoryIndex,
|
|
476
|
-
* plus operation for OPT types, plus rowGroup/rowGroupIndex when grouping is active.
|
|
477
|
-
*/
|
|
478
|
-
class QueryGroups {
|
|
479
|
-
constructor(config) {
|
|
480
|
-
alasql.fn.transformOperator = function (a) {
|
|
481
|
-
return a === "-" ? -1 : 1;
|
|
482
|
-
};
|
|
483
|
-
this.groups = [QueryColumnNames.CATEGORY, QueryColumnNames.CATEGORYINDEX];
|
|
484
|
-
if (TableType.OPT === config.type || TableType.OPTNOTOTAL === config.type) {
|
|
485
|
-
this.groups.unshift(QueryColumnNames.OPERATION);
|
|
486
|
-
}
|
|
487
|
-
if (config.grouped) {
|
|
488
|
-
this.groups.push(QueryColumnNames.ROWGROUP);
|
|
489
|
-
this.groups.push(QueryColumnNames.ROWGROUPINDEX);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
toString() {
|
|
493
|
-
return this.groups.map((s) => `${s}`).toString();
|
|
494
|
-
}
|
|
495
|
-
noCategory() {
|
|
496
|
-
return this.groups.filter((element) => element !== QueryColumnNames.CATEGORY);
|
|
497
|
-
}
|
|
498
|
-
toArray() {
|
|
499
|
-
return this.groups;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* AlaSQL-based query builder that produces the complete table result set for bn-table.
|
|
505
|
-
*
|
|
506
|
-
* Translates a {@link TableComponentConfig} into a series of SQL statements executed
|
|
507
|
-
* against in-memory data rows. The pipeline handles scenario aggregation, row/column
|
|
508
|
-
* grouping, drill-down expansion (thereof / partof), REST rows, sum rows, NaN detection,
|
|
509
|
-
* column-level drill columns, and relative variance calculation.
|
|
510
|
-
*/
|
|
511
|
-
class DataQuery {
|
|
512
|
-
constructor(config, i18n) {
|
|
513
|
-
this.hasPartOf = false;
|
|
514
|
-
this.config = config;
|
|
515
|
-
this.i18n = i18n;
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Executes the full query pipeline and returns a segmented result set.
|
|
519
|
-
*
|
|
520
|
-
* Pipeline steps:
|
|
521
|
-
* 1. Translate scenario columns into SQL aggregation expressions
|
|
522
|
-
* 2. Run a meta query to discover row groups and their category counts
|
|
523
|
-
* 3. For each group: generate header row, data rows, REST overflow row, and group sum row
|
|
524
|
-
* 4. Append a total sum row (if table type requires it)
|
|
525
|
-
* 5. Execute all accumulated SQL statements against the input data
|
|
526
|
-
* 6. Detect NaN cells (aggregated cells with zero contributing rows)
|
|
527
|
-
* 7. Inject thereof/partof drill rows and column-level drill columns
|
|
528
|
-
* 8. Calculate REST columns (parent minus drilled children)
|
|
529
|
-
* 9. Divide absolute variances by their denominator to produce relative variances
|
|
530
|
-
*
|
|
531
|
-
* @returns Array of row-group segments; each segment is an array of result rows.
|
|
532
|
-
*/
|
|
533
|
-
execute(data) {
|
|
534
|
-
if (data.length === 0) {
|
|
535
|
-
return [];
|
|
536
|
-
}
|
|
537
|
-
const queries = [];
|
|
538
|
-
const sumGroupQueries = [];
|
|
539
|
-
const res = [];
|
|
540
|
-
const scenarios = this.config.scenarios
|
|
541
|
-
.map((s) => this.translateScenarioSQL(s, false, this.config.type))
|
|
542
|
-
.toString();
|
|
543
|
-
const scenariosSUMQuery = this.config.scenarios
|
|
544
|
-
.map((s) => this.translateScenarioSQL(s, true, this.config.type))
|
|
545
|
-
.toString();
|
|
546
|
-
const relativeScenarios = this.getRelativeScenarios();
|
|
547
|
-
const groups = new QueryGroups(this.config);
|
|
548
|
-
const groupsAggregated = this.config.grouped ? [QueryColumnNames.ROWGROUP, QueryColumnNames.ROWGROUPINDEX] : [];
|
|
549
|
-
let order = ["", ""];
|
|
550
|
-
if (this.config.sortOrder.hierarchy.length > 0) {
|
|
551
|
-
order = this.createOrderString(this.config.sortOrder);
|
|
552
|
-
}
|
|
553
|
-
this.hasPartOf = this.checkConfigForPartOf();
|
|
554
|
-
// meta defines groups and the number detail rows in each group
|
|
555
|
-
// Bsp: 0: Object { totalrowcnt: 7, rowgroup: "Umsatz" }
|
|
556
|
-
const meta = alasql(`SELECT COUNT(DISTINCT ${QueryColumnNames.CATEGORY}) as ${QueryColumnNames.TOTALROWCOUNT} ${groupsAggregated.length > 0 ? "," + groupsAggregated : ""}
|
|
557
|
-
FROM ? ${groupsAggregated.length > 0 ? "GROUP BY " + groupsAggregated : ""}
|
|
558
|
-
ORDER BY ${order[0]}`, [data]);
|
|
559
|
-
// Creates DataSelection for LIST
|
|
560
|
-
meta.forEach((rowGroupEntry) => {
|
|
561
|
-
// the following variables are 'helper sections' which are used to constuct dynamicly the sql statement depending of the given config
|
|
562
|
-
// is grouping active?
|
|
563
|
-
const queryWhereSection = rowGroupEntry.rowGroup && rowGroupEntry.rowGroup.length > 0
|
|
564
|
-
? `WHERE ${QueryColumnNames.ROWGROUP} = '${rowGroupEntry.rowGroup}'`
|
|
565
|
-
: ``;
|
|
566
|
-
// is limit active?
|
|
567
|
-
let queryLimitSection = "";
|
|
568
|
-
if (this.config.limit) {
|
|
569
|
-
queryLimitSection = `LIMIT ${this.config.limit}`;
|
|
570
|
-
}
|
|
571
|
-
this.createGroupHeaderRow(rowGroupEntry, queries);
|
|
572
|
-
this.createDataRow(queries, rowGroupEntry, groups, scenarios, queryWhereSection, order, queryLimitSection);
|
|
573
|
-
this.createRestRow(rowGroupEntry, queries, groups, scenarios, queryWhereSection, order);
|
|
574
|
-
this.createGroupSumRow(queries, sumGroupQueries, rowGroupEntry, scenariosSUMQuery, order);
|
|
575
|
-
});
|
|
576
|
-
this.createTotalSumRow(queries, sumGroupQueries, scenariosSUMQuery);
|
|
577
|
-
// executes main queries
|
|
578
|
-
queries.forEach((query) => {
|
|
579
|
-
try {
|
|
580
|
-
res.push(alasql(query, [data]));
|
|
581
|
-
}
|
|
582
|
-
catch (err) {
|
|
583
|
-
console.error("DataQuery: SQL query execution failed", query, err);
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
this.detectNaNCells(this.config.scenarios, res);
|
|
587
|
-
this.createThereOfDrillRows(scenarios, order, data, res);
|
|
588
|
-
this.createPartOfDrillRows(scenarios, order, sumGroupQueries, data, res);
|
|
589
|
-
this.createThereOfDrillColumns(this.config.categoryThereOf, data, res);
|
|
590
|
-
this.calculateColumnGroupRest(res, this.config.categoryThereOf);
|
|
591
|
-
this.calculateRelativeVariances(res, relativeScenarios);
|
|
592
|
-
return res;
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* Marks aggregated cells as NaN when no source rows contributed to the sum.
|
|
596
|
-
*
|
|
597
|
-
* Without this step, SUM() over zero matching rows would produce 0, which is
|
|
598
|
-
* misleading -- it would be indistinguishable from an actual zero value.
|
|
599
|
-
* Each scenario column has a companion `_cnt` counter; when that counter is 0
|
|
600
|
-
* the cell is overwritten with NaN. For variance scenarios, both base and delta
|
|
601
|
-
* counters must be non-zero.
|
|
602
|
-
*/
|
|
603
|
-
detectNaNCells(scenarios, res) {
|
|
604
|
-
res.forEach((group) => {
|
|
605
|
-
group.map((row) => {
|
|
606
|
-
scenarios.forEach((scenario) => {
|
|
607
|
-
const varianceScenario = new VarianceScenario(scenario);
|
|
608
|
-
if (varianceScenario.isValid === true) {
|
|
609
|
-
if (row[varianceScenario.base + "_cnt"] === 0 || row[varianceScenario.delta + "_cnt"] === 0) {
|
|
610
|
-
row[scenario] = Number.NaN;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
if (row[scenario + "_cnt"] === 0) {
|
|
615
|
-
row[scenario] = Number.NaN;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
return row;
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* Creates "part-of" drill rows that express each category's value as a fraction
|
|
625
|
-
* of its row group sum. Queries the drill subset, then divides each scenario
|
|
626
|
-
* value by the corresponding group sum to produce a percentage.
|
|
627
|
-
*/
|
|
628
|
-
createPartOfDrillRows(scenarios, order, sumGroupQueries, data, res) {
|
|
629
|
-
if (this.config.partOf == null ||
|
|
630
|
-
this.config.partOf.length === 0 ||
|
|
631
|
-
this.config.type === TableType.LIST ||
|
|
632
|
-
data == null ||
|
|
633
|
-
data.length === 0) {
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
const drillQueries = this.createPartOfQuery(scenarios, order);
|
|
637
|
-
let resDrill = []; // set of drill (subquery result injected into resultset)
|
|
638
|
-
drillQueries.forEach(function (query) {
|
|
639
|
-
resDrill.push(...alasql(query, [data]));
|
|
640
|
-
});
|
|
641
|
-
const scenarioNames = this.exctractScenarioNames(scenarios);
|
|
642
|
-
const rowGroupSumResultRows = [];
|
|
643
|
-
sumGroupQueries.forEach(function (query) {
|
|
644
|
-
rowGroupSumResultRows.push(...alasql(query, [data]));
|
|
645
|
-
});
|
|
646
|
-
const rowGroupSumResultMap = new Map();
|
|
647
|
-
rowGroupSumResultRows.forEach((row) => rowGroupSumResultMap.set(row[QueryColumnNames.ROWGROUP], row));
|
|
648
|
-
resDrill = this.reduceResDrillByCategoryGroups(resDrill, scenarioNames);
|
|
649
|
-
resDrill.forEach(function (drillItem) {
|
|
650
|
-
scenarioNames.forEach((key) => {
|
|
651
|
-
try {
|
|
652
|
-
drillItem[key] =
|
|
653
|
-
drillItem[key] /
|
|
654
|
-
rowGroupSumResultMap.get(drillItem[QueryColumnNames.ROWGROUP])[key];
|
|
655
|
-
}
|
|
656
|
-
catch (err) {
|
|
657
|
-
console.error("DataQuery: partOf drill row calculation failed", key, err);
|
|
658
|
-
drillItem[key] = Number.NaN;
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
});
|
|
662
|
-
this.injectDrillRowsToResultRows(resDrill, res);
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Generates a REST row that aggregates all data rows beyond the configured limit.
|
|
666
|
-
* Only emitted when a limit is set and the group has more rows than the limit.
|
|
667
|
-
*/
|
|
668
|
-
createRestRow(rowGroupEntry, querys, groups, scenarios, queryWhereSection, order) {
|
|
669
|
-
// Generates REST Row; sumsup the Bottom (total number of rows - limit)
|
|
670
|
-
if (rowGroupEntry.totalRowCnt - this.config.limit > 0 && this.config.limit !== 0) {
|
|
671
|
-
const rest_scenarios = ", SUM(ac1) as ac1, SUM(pp1) as pp1, SUM(dpp1_ac1_pos) as dpp1_ac1_pos, SUM(drpp1_ac1_pos) as drpp1_ac1_pos, SUM(dr_pp1)";
|
|
672
|
-
querys.push(`SELECT ${QueryColumnNames.ROWNR}, 1 as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, 'NO_GROUP' as ${QueryColumnNames.ROWGROUP}, 'REST' as ${QueryColumnNames.CATEGORY} ${rest_scenarios} as dr_pp1 FROM` +
|
|
673
|
-
` (SELECT ROWNUM() AS ${QueryColumnNames.ROWNR}, ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, '${rowGroupEntry.rowGroup || "NO_GROUP"}' as ${QueryColumnNames.ROWGROUP}, ${groups} ${scenarios.length > 0 ? ",".concat(scenarios) : ""} FROM ? ${queryWhereSection} GROUP BY ${groups} ORDER BY ${order[0]})` +
|
|
674
|
-
` t WHERE t.rowNr > ${this.config.limit}`);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
/** Generates the main data rows for a single row group, applying GROUP BY, ORDER, and LIMIT. */
|
|
678
|
-
createDataRow(querys, rowGroupEntry, groups, scenarios, queryWhereSection, order, queryLimitSection) {
|
|
679
|
-
// Generates DataRows
|
|
680
|
-
querys.push(`SELECT ROWNUM() AS ${QueryColumnNames.ROWNR},
|
|
681
|
-
${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
682
|
-
'ENTRY' as ${QueryColumnNames.TYPE},
|
|
683
|
-
'${rowGroupEntry.rowGroup || "NO_GROUP"}' as ${QueryColumnNames.ROWGROUP},
|
|
684
|
-
'${QueryColumnNames.CATEGORYINDEX}',
|
|
685
|
-
${groups} ${scenarios.length > 0 ? ",".concat(scenarios) : ""}
|
|
686
|
-
FROM ? ${queryWhereSection}
|
|
687
|
-
GROUP BY ${groups}
|
|
688
|
-
ORDER BY ${order[0]} ${queryLimitSection}`);
|
|
689
|
-
}
|
|
690
|
-
/** Generates a GROUPHEAD row used as a visual header when row grouping is active. */
|
|
691
|
-
createGroupHeaderRow(rowGroupEntry, querys) {
|
|
692
|
-
// Generates GroupHeader Row
|
|
693
|
-
if (true === this.config.grouped) {
|
|
694
|
-
const groupTitle = this.config.showGroupTitle
|
|
695
|
-
? `,'${rowGroupEntry.rowGroup}' as ${QueryColumnNames.CATEGORY}`
|
|
696
|
-
: "";
|
|
697
|
-
querys.push(`SELECT ROWNUM() AS ${QueryColumnNames.ROWNR},
|
|
698
|
-
${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
699
|
-
'GROUPHEAD' as ${QueryColumnNames.TYPE},
|
|
700
|
-
'${rowGroupEntry.rowGroup}' as ${QueryColumnNames.ROWGROUP} ${groupTitle}
|
|
701
|
-
FROM ?
|
|
702
|
-
GROUP BY '1'`);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
/** Generates a GROUP_SUM row that aggregates all entries within a single row group. */
|
|
706
|
-
createGroupSumRow(querys, groupSumQuery, rowGroupEntry, scenariosSUMQuery, order) {
|
|
707
|
-
// Generates SUM Row; sumsup all rows of group
|
|
708
|
-
if (true === this.config.grouped &&
|
|
709
|
-
(TableType.SUM === this.config.type ||
|
|
710
|
-
TableType.SUMNOTOTAL === this.config.type ||
|
|
711
|
-
TableType.OPT === this.config.type ||
|
|
712
|
-
TableType.OPTNOTOTAL === this.config.type)) {
|
|
713
|
-
querys.push(`SELECT ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
714
|
-
'=' as ${QueryColumnNames.OPERATION},
|
|
715
|
-
'${rowGroupEntry.rowGroup}' as ${QueryColumnNames.ROWGROUP},
|
|
716
|
-
ROWNUM() AS ${QueryColumnNames.ROWNR},
|
|
717
|
-
'GROUP_SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
718
|
-
FROM ?
|
|
719
|
-
WHERE ${QueryColumnNames.ROWGROUP} = '${rowGroupEntry.rowGroup}'
|
|
720
|
-
ORDER BY ${order[0]} `);
|
|
721
|
-
groupSumQuery.push(`SELECT ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
722
|
-
'=' as ${QueryColumnNames.OPERATION},
|
|
723
|
-
'${rowGroupEntry.rowGroup}' as ${QueryColumnNames.ROWGROUP},
|
|
724
|
-
ROWNUM() AS ${QueryColumnNames.ROWNR},
|
|
725
|
-
'GROUP_SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
726
|
-
FROM ?
|
|
727
|
-
WHERE ${QueryColumnNames.ROWGROUP} = '${rowGroupEntry.rowGroup}'
|
|
728
|
-
ORDER BY ${order[0]} `);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
/** Generates a total SUM row across all groups (only for SUM / OPT table types). */
|
|
732
|
-
createTotalSumRow(querys, sumGroupQueries, scenariosSUMQuery) {
|
|
733
|
-
if (TableType.SUM === this.config.type || TableType.OPT === this.config.type) {
|
|
734
|
-
const title = `${this.hasPartOf && this.config.grouped === false ? `${this.i18n.get("SUM_TOTAL") || "SUM_TOTAL"} ` : ""}${this.config.title}`;
|
|
735
|
-
querys.push(`SELECT ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
736
|
-
'${title}' as ${QueryColumnNames.ROWGROUP},
|
|
737
|
-
'=' as ${QueryColumnNames.OPERATION},
|
|
738
|
-
'SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
739
|
-
FROM ? `);
|
|
740
|
-
}
|
|
741
|
-
sumGroupQueries.push(`SELECT ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
742
|
-
'SUM_TOTAL' as ${QueryColumnNames.ROWGROUP},
|
|
743
|
-
'=' as ${QueryColumnNames.OPERATION},
|
|
744
|
-
'SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
745
|
-
FROM ? `);
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Manually merges drill rows that AlaSQL fails to aggregate correctly.
|
|
749
|
-
* Groups by composite key (rowNr + rowGroup + type + category) and sums scenario values.
|
|
750
|
-
*/
|
|
751
|
-
reduceResDrillByCategoryGroups(resDrill, scenarioNames) {
|
|
752
|
-
// This is workarround because alasql is not merging the rows as expected.
|
|
753
|
-
const tmpSumMap = new Map();
|
|
754
|
-
resDrill.forEach(function (drillItem) {
|
|
755
|
-
const key = drillItem.rowNr + drillItem.rowGroup + drillItem.type + drillItem.category;
|
|
756
|
-
if (tmpSumMap.has(key)) {
|
|
757
|
-
const element = tmpSumMap.get(key);
|
|
758
|
-
scenarioNames.forEach((key) => {
|
|
759
|
-
try {
|
|
760
|
-
element[key] += drillItem[key];
|
|
761
|
-
}
|
|
762
|
-
catch (e) {
|
|
763
|
-
console.error("DataQuery: drill row aggregation failed", key, e);
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
else {
|
|
768
|
-
tmpSumMap.set(key, drillItem);
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
return [...tmpSumMap.values()];
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Inserts drill (thereof/partof) rows into the result set directly after their
|
|
775
|
-
* parent category row. Handles both grouped and ungrouped modes, disambiguating
|
|
776
|
-
* duplicate subCategory names by appending the rowGroup in parentheses.
|
|
777
|
-
*/
|
|
778
|
-
injectDrillRowsToResultRows(resDrill, res) {
|
|
779
|
-
// resDrill = resDrill.reverse();
|
|
780
|
-
const numberOfElement = new Map();
|
|
781
|
-
if (this.config.grouped === true) {
|
|
782
|
-
// finds ParentElement of Drill Element and injects into result arra
|
|
783
|
-
resDrill.forEach(function (drillItem) {
|
|
784
|
-
res.forEach(function (resSegment) {
|
|
785
|
-
const index = resSegment.findIndex((e) => e.category === drillItem.category && e.rowGroup === drillItem.rowGroup);
|
|
786
|
-
if (index >= 0) {
|
|
787
|
-
if (numberOfElement.has(`${drillItem.category}_${drillItem.rowGroup}`)) {
|
|
788
|
-
const num = numberOfElement.get(`${drillItem.category}_${drillItem.rowGroup}`) || 0;
|
|
789
|
-
numberOfElement.set(`${drillItem.category}_${drillItem.rowGroup}`, num + 1);
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
numberOfElement.set(`${drillItem.category}_${drillItem.rowGroup}`, 1);
|
|
793
|
-
}
|
|
794
|
-
drillItem[QueryColumnNames.ROWNR] = numberOfElement.get(`${drillItem.category}_${drillItem.rowGroup}`);
|
|
795
|
-
resSegment.splice(index + drillItem[QueryColumnNames.ROWNR], 0, drillItem);
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
else {
|
|
801
|
-
// if no grouped mode selected matching only searching for category not for groupname
|
|
802
|
-
const duplicateSubCategoriesList = this.findDuplicateSubCategories(resDrill);
|
|
803
|
-
resDrill.forEach(function (drillItem) {
|
|
804
|
-
res.forEach(function (resSegment) {
|
|
805
|
-
const index = resSegment.findIndex((e) => e.category != null && e.category === drillItem.category);
|
|
806
|
-
if (index >= 0) {
|
|
807
|
-
if (numberOfElement.has(`${drillItem.category}`)) {
|
|
808
|
-
const num = numberOfElement.get(`${drillItem.category}`) || 0;
|
|
809
|
-
numberOfElement.set(`${drillItem.category}`, num + 1);
|
|
810
|
-
}
|
|
811
|
-
else {
|
|
812
|
-
numberOfElement.set(`${drillItem.category}`, 1);
|
|
813
|
-
}
|
|
814
|
-
if (drillItem[QueryColumnNames.ROWNR] === 1) {
|
|
815
|
-
drillItem.subCategory = `${drillItem.subCategory} (${drillItem.rowGroup})`;
|
|
816
|
-
}
|
|
817
|
-
else if (duplicateSubCategoriesList.includes(drillItem.subCategory)) {
|
|
818
|
-
drillItem.subCategory = `${drillItem.subCategory} (${drillItem.rowGroup})`;
|
|
819
|
-
}
|
|
820
|
-
resSegment.splice(index + drillItem[QueryColumnNames.ROWNR], 0, drillItem);
|
|
821
|
-
}
|
|
822
|
-
});
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Creates "thereof" drill rows -- sub-breakdowns shown with absolute values
|
|
828
|
-
* beneath their parent category row. Each thereof config entry produces a
|
|
829
|
-
* filtered/grouped SQL query whose results are spliced into the result set.
|
|
830
|
-
*/
|
|
831
|
-
createThereOfDrillRows(scenarios, order, data, res) {
|
|
832
|
-
// adds drill rows if setup in config
|
|
833
|
-
// if there of is set drilldown row is displayed with absolute numbers,
|
|
834
|
-
// if part of is also not null a relative percenatage based of the selected basis is displayed
|
|
835
|
-
if (this.config.thereOf === undefined || this.config.thereOf.length === 0) {
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
const drillQueries = [];
|
|
839
|
-
const resDrill = []; // set of drill (subquery result injected into resultset)
|
|
840
|
-
// let rollgroups = ['category']; // frage wo kommt das her ?
|
|
841
|
-
// create drill queryies based on config
|
|
842
|
-
this.config.thereOf.forEach((element) => {
|
|
843
|
-
let isFirst = true;
|
|
844
|
-
let fromString = "1 <> 1 OR ( "; // helper for strin concat 1<>1 OR ... OR ...
|
|
845
|
-
if (!(null == element.category || 0 === element.category.length || !element.category.trim())) {
|
|
846
|
-
// if not empty
|
|
847
|
-
fromString += ` ${QueryColumnNames.CATEGORY} = '${element.category}'`;
|
|
848
|
-
isFirst = false;
|
|
849
|
-
}
|
|
850
|
-
if (!(null == element.rowGroup || 0 === element.rowGroup.length || !element.rowGroup.trim())) {
|
|
851
|
-
// if not empty
|
|
852
|
-
fromString += ` ${isFirst ? "" : "AND"} ${QueryColumnNames.ROWGROUP} = '${element.rowGroup}'`;
|
|
853
|
-
isFirst = false;
|
|
854
|
-
}
|
|
855
|
-
if (!(null == element.subCategory || 0 === element.subCategory.length || !element.subCategory.trim())) {
|
|
856
|
-
// if not empty
|
|
857
|
-
fromString += ` ${isFirst ? "" : "AND"} ${QueryColumnNames.SUBCATEGORY} = '${element.subCategory}'`;
|
|
858
|
-
}
|
|
859
|
-
fromString += `)`;
|
|
860
|
-
drillQueries.push(`SELECT ROWNUM() AS ${QueryColumnNames.ROWNR},
|
|
861
|
-
null as operation,
|
|
862
|
-
'DRILLELEMENT' as ${QueryColumnNames.TYPE},
|
|
863
|
-
${QueryColumnNames.CATEGORY},
|
|
864
|
-
${QueryColumnNames.SUBCATEGORY},
|
|
865
|
-
${QueryColumnNames.ROWGROUP} as ${QueryColumnNames.ROWGROUP},
|
|
866
|
-
${scenarios}
|
|
867
|
-
FROM ?
|
|
868
|
-
WHERE ${fromString}
|
|
869
|
-
GROUP BY ${QueryColumnNames.ROWGROUP}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.SUBCATEGORY}
|
|
870
|
-
ORDER BY ${order[1]}`);
|
|
871
|
-
});
|
|
872
|
-
// invertet Sort directon because the later used insertion which results into expected order direction
|
|
873
|
-
//drillQueries.push(`SELECT ROWNUM() AS ${QueryColumnNames.ROWNR}, null as operation, 'DRILLELEMENT' as ${QueryColumnNames.TYPE}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.SUBCATEGORY}, ${QueryColumnNames.ROWGROUP} as ${QueryColumnNames.ROWGROUP} , ${scenarios} FROM ? WHERE ${fromString} GROUP BY ${QueryColumnNames.ROWGROUP}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.SUBCATEGORY} ORDER BY ${order[1]}`);
|
|
874
|
-
drillQueries.forEach(function (query) {
|
|
875
|
-
resDrill.push(...alasql(query, [data]));
|
|
876
|
-
});
|
|
877
|
-
this.injectDrillRowsToResultRows(resDrill, res);
|
|
878
|
-
}
|
|
879
|
-
/**
|
|
880
|
-
* Converts absolute variance columns into relative (percentage) variances by dividing
|
|
881
|
-
* each `dr_*` cell by its denominator column (the delta scenario's aggregated value).
|
|
882
|
-
*/
|
|
883
|
-
calculateRelativeVariances(res, relativeScenarios) {
|
|
884
|
-
res.forEach((group) => {
|
|
885
|
-
group.forEach((row) => {
|
|
886
|
-
if (row[QueryColumnNames.TYPE] !== "GROUPHEAD") {
|
|
887
|
-
relativeScenarios.forEach((value, key) => {
|
|
888
|
-
row[key] = row[key] / row[value];
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
});
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Calculates REST columns for column-level thereof drills.
|
|
896
|
-
* REST = parent scenario value minus sum of all drilled child columns.
|
|
897
|
-
* Columns where REST is zero across all rows are removed entirely.
|
|
898
|
-
*/
|
|
899
|
-
calculateColumnGroupRest(res, categoryThereOf) {
|
|
900
|
-
if (categoryThereOf == null || categoryThereOf.size === 0) {
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
const scenarioRestMap = new Map();
|
|
904
|
-
const scenarioRestHasValuesMap = new Map();
|
|
905
|
-
categoryThereOf.forEach((value, key) => {
|
|
906
|
-
const categoryDrills = value;
|
|
907
|
-
const columnsList = [];
|
|
908
|
-
for (const drillElement of categoryDrills) {
|
|
909
|
-
columnsList.push(`${key}##${drillElement.name}`);
|
|
910
|
-
}
|
|
911
|
-
scenarioRestMap.set(key, columnsList);
|
|
912
|
-
scenarioRestHasValuesMap.set(`${key}##REST`, false);
|
|
913
|
-
});
|
|
914
|
-
res.forEach((group) => {
|
|
915
|
-
group.forEach((row) => {
|
|
916
|
-
if (row[QueryColumnNames.TYPE] !== "GROUPHEAD") {
|
|
917
|
-
scenarioRestMap.forEach((values, key) => {
|
|
918
|
-
let minuent = 0;
|
|
919
|
-
values.forEach((value) => {
|
|
920
|
-
if (row[value] !== undefined) {
|
|
921
|
-
minuent += row[value];
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
row[`${key}##REST`] = row[key] - minuent;
|
|
925
|
-
if (row[`${key}##REST`] !== 0) {
|
|
926
|
-
scenarioRestHasValuesMap.set(`${key}##REST`, true);
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
});
|
|
931
|
-
});
|
|
932
|
-
const emptyRestColumns = Array.from(scenarioRestHasValuesMap.entries())
|
|
933
|
-
.filter(([_key, value]) => !value)
|
|
934
|
-
.map(([key]) => key);
|
|
935
|
-
res.forEach((group) => {
|
|
936
|
-
group.forEach((row) => {
|
|
937
|
-
for (const deleteColumn of emptyRestColumns) {
|
|
938
|
-
delete row[deleteColumn];
|
|
939
|
-
}
|
|
940
|
-
});
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
/** Collects all relative variance scenarios and maps each to its denominator column name. */
|
|
944
|
-
getRelativeScenarios() {
|
|
945
|
-
const relativeScenarios = new Map();
|
|
946
|
-
this.config.scenarios.forEach((s) => {
|
|
947
|
-
const tmp = this.createRelativeScenario(s);
|
|
948
|
-
if (tmp != null) {
|
|
949
|
-
relativeScenarios.set(tmp.key, tmp.value);
|
|
950
|
-
}
|
|
951
|
-
});
|
|
952
|
-
return relativeScenarios;
|
|
953
|
-
}
|
|
954
|
-
/**
|
|
955
|
-
* Translates a scenario identifier into a SQL aggregation expression.
|
|
956
|
-
*
|
|
957
|
-
* - **OPT/OPTNOTOTAL types**: Values are summed without `transformOperator` (the
|
|
958
|
-
* operation sign is already baked into the data). Variance scenarios produce
|
|
959
|
-
* `SUM(base - delta)`.
|
|
960
|
-
* - **Other types**: Each value is multiplied by `transformOperator(operation)` which
|
|
961
|
-
* converts the `"+"` / `"-"` operation field into +1 / -1, so rows with negative
|
|
962
|
-
* operation are subtracted from the aggregate.
|
|
963
|
-
* - **Relative variances** (`dr_*`): additionally select the delta denominator column
|
|
964
|
-
* so `calculateRelativeVariances` can divide later.
|
|
965
|
-
* - A companion `_cnt` column (COUNT of non-null values) is emitted for NaN detection.
|
|
966
|
-
*/
|
|
967
|
-
translateScenarioSQL(scenario, isSumRow, type) {
|
|
968
|
-
const scenarios = new VarianceScenario(scenario);
|
|
969
|
-
if (TableType.OPT === type || TableType.OPTNOTOTAL === type) {
|
|
970
|
-
if (scenarios.isValid) {
|
|
971
|
-
if (scenarios.type === "dr") {
|
|
972
|
-
return `SUM(${scenarios.base} - ${scenarios.delta}) as ${scenario}, SUM(${scenarios.delta}) as dr_${scenarios.delta}`;
|
|
973
|
-
}
|
|
974
|
-
else {
|
|
975
|
-
return `SUM(${scenarios.base} - ${scenarios.delta}) as ${scenario}`;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
if (isSumRow) {
|
|
979
|
-
return `SUM(${scenario} * transformOperator(operation)) as ${scenario}, COUNT(ISNULL(${scenario})) as ${scenario}_cnt`;
|
|
980
|
-
}
|
|
981
|
-
return `SUM(${scenario}) as ${scenario}, COUNT(ISNULL(${scenario})) as ${scenario}_cnt`;
|
|
982
|
-
}
|
|
983
|
-
if (scenarios.isValid) {
|
|
984
|
-
if (scenarios.type === "dr") {
|
|
985
|
-
return `SUM((${scenarios.base} * transformOperator(operation)) - (${scenarios.delta} * transformOperator(operation))) as ${scenario}, SUM(${scenarios.delta} * transformOperator(operation)) as dr_${scenarios.delta}`;
|
|
986
|
-
}
|
|
987
|
-
else {
|
|
988
|
-
return `SUM((${scenarios.base} * transformOperator(operation))- (${scenarios.delta} * transformOperator(operation))) as ${scenario}`;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
return `SUM(${scenario} * transformOperator(operation)) as ${scenario}, COUNT(ISNULL(${scenario})) as ${scenario}_cnt`;
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* generates Tuple
|
|
995
|
-
* [0] orderby string example: category asc
|
|
996
|
-
* [1] inverted order example: category desc
|
|
997
|
-
* @param orderComponent
|
|
998
|
-
*/
|
|
999
|
-
createOrderString(orderComponent) {
|
|
1000
|
-
const base = `${orderComponent.hierarchy.toString()} ${orderComponent.direction}`;
|
|
1001
|
-
const inverted = `${orderComponent.hierarchy.toString()} ${OrderDirection.ASC === orderComponent.direction ? OrderDirection.DESC : OrderDirection.ASC}`;
|
|
1002
|
-
return [base, inverted];
|
|
1003
|
-
}
|
|
1004
|
-
/** Returns a key/value pair mapping a relative variance column to its denominator, or null for non-relative scenarios. */
|
|
1005
|
-
createRelativeScenario(scenario) {
|
|
1006
|
-
const scenarios = new VarianceScenario(scenario);
|
|
1007
|
-
if (scenarios.isValid && scenarios.type === "dr") {
|
|
1008
|
-
return { key: `${scenario}`, value: `dr_${scenarios.delta}` };
|
|
1009
|
-
}
|
|
1010
|
-
return null;
|
|
1011
|
-
}
|
|
1012
|
-
/** Parses the comma-separated SQL scenario fragment to extract the alias names (the part after `as`). */
|
|
1013
|
-
exctractScenarioNames(scenarios) {
|
|
1014
|
-
const scenarioNames = [];
|
|
1015
|
-
scenarios.split(",").forEach((item) => (item.length >= 2 ? scenarioNames.push(item.split("as")[1].trim()) : null));
|
|
1016
|
-
return scenarioNames;
|
|
1017
|
-
}
|
|
1018
|
-
/** Identifies subCategory values that appear more than once in the drill set, requiring disambiguation. */
|
|
1019
|
-
findDuplicateSubCategories(resDrill) {
|
|
1020
|
-
const uniq = resDrill
|
|
1021
|
-
.map((element) => {
|
|
1022
|
-
return {
|
|
1023
|
-
count: 1,
|
|
1024
|
-
subCategory: element.subCategory,
|
|
1025
|
-
};
|
|
1026
|
-
})
|
|
1027
|
-
.reduce((a, b) => {
|
|
1028
|
-
a[b.subCategory] = (a[b.subCategory] || 0) + b.count;
|
|
1029
|
-
return a;
|
|
1030
|
-
}, {});
|
|
1031
|
-
return Object.keys(uniq).filter((a) => uniq[a] > 1);
|
|
1032
|
-
}
|
|
1033
|
-
/** Builds the SQL query for partof drill rows, filtering to configured partOf categories. */
|
|
1034
|
-
createPartOfQuery(scenarios, order) {
|
|
1035
|
-
var _a;
|
|
1036
|
-
const drillQueries = [];
|
|
1037
|
-
let fromString = "1 <> 1 "; // helper for strin concat 1<>1 OR ... OR ...
|
|
1038
|
-
let groupName = ` ${QueryColumnNames.ROWGROUP}`;
|
|
1039
|
-
let rowNum = "ROWNUM()";
|
|
1040
|
-
(_a = this.config.partOf) === null || _a === void 0 ? void 0 : _a.forEach((element) => {
|
|
1041
|
-
fromString += `OR (${QueryColumnNames.CATEGORY} = '${element.category}'`;
|
|
1042
|
-
if (!(null == element.rowGroup || 0 === element.rowGroup.length || !element.rowGroup.trim())) {
|
|
1043
|
-
// if not empty
|
|
1044
|
-
fromString += `and ${QueryColumnNames.ROWGROUP} = '${element.rowGroup}'`;
|
|
1045
|
-
}
|
|
1046
|
-
if (this.config.grouped === false) {
|
|
1047
|
-
groupName = ` 'SUM_TOTAL' as ${QueryColumnNames.ROWGROUP} `;
|
|
1048
|
-
rowNum = "1";
|
|
1049
|
-
}
|
|
1050
|
-
fromString += `)`;
|
|
1051
|
-
});
|
|
1052
|
-
// let dimensionGroups = `${QueryColumnNames.CATEGORY}, ${QueryColumnNames.SUBCATEGORY}, ${QueryColumnNames.ROWGROUP}`;
|
|
1053
|
-
// invertet Sort directon because the later used insertion which results into expected order direction
|
|
1054
|
-
drillQueries.push(`SELECT ${rowNum} AS ${QueryColumnNames.ROWNR},
|
|
1055
|
-
'PARTELEMENT' as ${QueryColumnNames.TYPE},
|
|
1056
|
-
${QueryColumnNames.CATEGORY},
|
|
1057
|
-
${groupName},
|
|
1058
|
-
${scenarios}
|
|
1059
|
-
FROM ?
|
|
1060
|
-
WHERE ${fromString}
|
|
1061
|
-
GROUP BY ${QueryColumnNames.ROWGROUP}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.TYPE}
|
|
1062
|
-
ORDER BY ${order[1]}`);
|
|
1063
|
-
return drillQueries;
|
|
1064
|
-
}
|
|
1065
|
-
checkConfigForPartOf() {
|
|
1066
|
-
if (this.config.partOf == null || this.config.partOf.length === 0) {
|
|
1067
|
-
return false;
|
|
1068
|
-
}
|
|
1069
|
-
return true;
|
|
1070
|
-
}
|
|
1071
|
-
/**
|
|
1072
|
-
* Creates column-level thereof drill breakdowns for the configured `categoryThereOf` map.
|
|
1073
|
-
*
|
|
1074
|
-
* For each scenario key, queries are generated at multiple aggregation levels
|
|
1075
|
-
* (ENTRY, DRILLELEMENT, GROUP_SUM, SUM) crossed with column dimensions
|
|
1076
|
-
* (COLUMNGROUP, SUBGROUP). Results are stored as new properties on existing
|
|
1077
|
-
* result rows using the `"##"` separator convention: `scenario##columnGroup` or
|
|
1078
|
-
* `scenario##columnGroup##columnSubGroup`.
|
|
1079
|
-
*/
|
|
1080
|
-
createThereOfDrillColumns(categoryThereOf, data, res) {
|
|
1081
|
-
if (categoryThereOf == null || categoryThereOf.size === 0) {
|
|
1082
|
-
return;
|
|
1083
|
-
}
|
|
1084
|
-
const drillQueries = [];
|
|
1085
|
-
const resDrill = [];
|
|
1086
|
-
categoryThereOf.forEach((value, key) => {
|
|
1087
|
-
let whereClause = "1 <> 1 ";
|
|
1088
|
-
value.forEach((drillColumn) => {
|
|
1089
|
-
whereClause += ` or columnGroup = '${drillColumn.name}' `;
|
|
1090
|
-
});
|
|
1091
|
-
drillQueries.push(`SELECT 'ENTRY' as rowlevel,
|
|
1092
|
-
'COLUMNGROUP' as columnlevel,
|
|
1093
|
-
rowGroup,
|
|
1094
|
-
category,
|
|
1095
|
-
columnGroup,
|
|
1096
|
-
'${key}' as scenario,
|
|
1097
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1098
|
-
FROM ?
|
|
1099
|
-
WHERE ${whereClause}
|
|
1100
|
-
GROUP BY rowlevel, rowGroup, category, columnGroup, scenario`);
|
|
1101
|
-
drillQueries.push(`SELECT 'ENTRY' as rowlevel,
|
|
1102
|
-
'SUBGROUP' as columnlevel,
|
|
1103
|
-
rowGroup,
|
|
1104
|
-
category,
|
|
1105
|
-
columnGroup,
|
|
1106
|
-
columnSubGroup,
|
|
1107
|
-
'${key}' as scenario,
|
|
1108
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1109
|
-
FROM ?
|
|
1110
|
-
WHERE ${whereClause}
|
|
1111
|
-
GROUP BY rowlevel, rowGroup, category, columnGroup, columnSubGroup, scenario`);
|
|
1112
|
-
drillQueries.push(`SELECT 'DRILLELEMENT' as rowlevel,
|
|
1113
|
-
'COLUMNGROUP' as columnlevel,
|
|
1114
|
-
rowGroup,
|
|
1115
|
-
category,
|
|
1116
|
-
subCategory,
|
|
1117
|
-
columnGroup,
|
|
1118
|
-
'${key}' as scenario,
|
|
1119
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1120
|
-
FROM ?
|
|
1121
|
-
WHERE ${whereClause}
|
|
1122
|
-
GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, scenario`);
|
|
1123
|
-
drillQueries.push(`SELECT 'DRILLELEMENT' as rowlevel,
|
|
1124
|
-
'SUBGROUP' as columnlevel,
|
|
1125
|
-
rowGroup,
|
|
1126
|
-
category,
|
|
1127
|
-
subCategory,
|
|
1128
|
-
columnGroup,
|
|
1129
|
-
columnSubGroup,
|
|
1130
|
-
'${key}' as scenario,
|
|
1131
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1132
|
-
FROM ?
|
|
1133
|
-
WHERE ${whereClause}
|
|
1134
|
-
GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, columnSubGroup, scenario`);
|
|
1135
|
-
drillQueries.push(`SELECT 'GROUP_SUM' as rowlevel,
|
|
1136
|
-
'COLUMNGROUP' as columnlevel,
|
|
1137
|
-
rowGroup,
|
|
1138
|
-
columnGroup,
|
|
1139
|
-
'${key}' as scenario,
|
|
1140
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1141
|
-
FROM ?
|
|
1142
|
-
WHERE ${whereClause}
|
|
1143
|
-
GROUP BY rowlevel, rowGroup, columnGroup, scenario`);
|
|
1144
|
-
drillQueries.push(`SELECT 'GROUP_SUM' as rowlevel,
|
|
1145
|
-
'SUBGROUP' as columnlevel,
|
|
1146
|
-
rowGroup,
|
|
1147
|
-
columnGroup,
|
|
1148
|
-
columnSubGroup,
|
|
1149
|
-
'${key}' as scenario,
|
|
1150
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1151
|
-
FROM ?
|
|
1152
|
-
WHERE ${whereClause}
|
|
1153
|
-
GROUP BY rowlevel, rowGroup, columnGroup, columnSubGroup, scenario`);
|
|
1154
|
-
drillQueries.push(`SELECT 'SUM' as rowlevel,
|
|
1155
|
-
'COLUMNGROUP' as columnlevel,
|
|
1156
|
-
columnGroup,
|
|
1157
|
-
'${key}' as scenario,
|
|
1158
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1159
|
-
FROM ?
|
|
1160
|
-
WHERE ${whereClause}
|
|
1161
|
-
GROUP BY rowlevel, columnGroup, scenario`);
|
|
1162
|
-
drillQueries.push(`SELECT 'SUM' as rowlevel,
|
|
1163
|
-
'SUBGROUP' as columnlevel,
|
|
1164
|
-
columnGroup,
|
|
1165
|
-
columnSubGroup,
|
|
1166
|
-
'${key}' as scenario,
|
|
1167
|
-
sum(${key} * transformOperator(operation)) as val
|
|
1168
|
-
FROM ?
|
|
1169
|
-
WHERE ${whereClause}
|
|
1170
|
-
GROUP BY rowlevel, columnGroup, columnSubGroup, scenario`);
|
|
1171
|
-
});
|
|
1172
|
-
for (const query of drillQueries) {
|
|
1173
|
-
resDrill.push(...alasql(query, [data]));
|
|
1174
|
-
}
|
|
1175
|
-
this.injectDrillColumnsToResultRows(resDrill, res);
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* Merges column-drill query results into existing result rows by matching
|
|
1179
|
-
* row type, category, subCategory, and rowGroup. Uses the `"##"` separator
|
|
1180
|
-
* to form composite property keys for drill column values.
|
|
1181
|
-
*/
|
|
1182
|
-
injectDrillColumnsToResultRows(resDrill, res) {
|
|
1183
|
-
const separator = "##";
|
|
1184
|
-
for (const drillElement of resDrill) {
|
|
1185
|
-
for (const tableSegment of res) {
|
|
1186
|
-
for (const row of tableSegment) {
|
|
1187
|
-
if (row.type !== drillElement.rowlevel) {
|
|
1188
|
-
continue;
|
|
1189
|
-
}
|
|
1190
|
-
if ("ENTRY" === drillElement.rowlevel) {
|
|
1191
|
-
if (drillElement.columnlevel === "COLUMNGROUP" && row.category === drillElement.category) {
|
|
1192
|
-
row[drillElement.scenario + separator + drillElement.columnGroup] = drillElement.val;
|
|
1193
|
-
}
|
|
1194
|
-
else if (drillElement.columnlevel === "SUBGROUP" && row.category === drillElement.category) {
|
|
1195
|
-
row[drillElement.scenario + separator + drillElement.columnGroup + separator + drillElement.columnSubGroup] = drillElement.val;
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
else if ("DRILLELEMENT" === drillElement.rowlevel) {
|
|
1199
|
-
if (drillElement.columnlevel === "COLUMNGROUP" &&
|
|
1200
|
-
row.category === drillElement.category &&
|
|
1201
|
-
row.subCategory === drillElement.subCategory) {
|
|
1202
|
-
row[drillElement.scenario + separator + drillElement.columnGroup] = drillElement.val;
|
|
1203
|
-
}
|
|
1204
|
-
else if (drillElement.columnlevel === "SUBGROUP" &&
|
|
1205
|
-
row.category === drillElement.category &&
|
|
1206
|
-
row.subCategory === drillElement.subCategory) {
|
|
1207
|
-
row[drillElement.scenario + separator + drillElement.columnGroup + separator + drillElement.columnSubGroup] = drillElement.val;
|
|
1208
|
-
}
|
|
1209
|
-
else if (drillElement.columnlevel === "COLUMNGROUP" &&
|
|
1210
|
-
row.category === drillElement.category &&
|
|
1211
|
-
row.subCategory === `${drillElement.subCategory} (${drillElement.rowGroup})`) {
|
|
1212
|
-
row[drillElement.scenario + separator + drillElement.columnGroup] = drillElement.val;
|
|
1213
|
-
}
|
|
1214
|
-
else if (drillElement.columnlevel === "SUBGROUP" &&
|
|
1215
|
-
row.category === drillElement.category &&
|
|
1216
|
-
row.subCategory === `${drillElement.subCategory} (${drillElement.rowGroup})`) {
|
|
1217
|
-
row[drillElement.scenario + separator + drillElement.columnGroup + separator + drillElement.columnSubGroup] = drillElement.val;
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
else if ("SUM" === drillElement.rowlevel) {
|
|
1221
|
-
if (drillElement.columnlevel === "COLUMNGROUP" &&
|
|
1222
|
-
row.category === drillElement.category &&
|
|
1223
|
-
row.subCategory === drillElement.subCategory) {
|
|
1224
|
-
row[drillElement.scenario + separator + drillElement.columnGroup] = drillElement.val;
|
|
1225
|
-
}
|
|
1226
|
-
if (drillElement.columnlevel === "SUBGROUP" &&
|
|
1227
|
-
row.category === drillElement.category &&
|
|
1228
|
-
row.subCategory === drillElement.subCategory) {
|
|
1229
|
-
row[drillElement.scenario + separator + drillElement.columnGroup + separator + drillElement.columnSubGroup] = drillElement.val;
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
else if ("GROUP_SUM" === drillElement.rowlevel) {
|
|
1233
|
-
if (drillElement.columnlevel === "COLUMNGROUP" &&
|
|
1234
|
-
row.category === drillElement.category &&
|
|
1235
|
-
row.subCategory === drillElement.subCategory) {
|
|
1236
|
-
row[drillElement.scenario + separator + drillElement.columnGroup] = drillElement.val;
|
|
1237
|
-
}
|
|
1238
|
-
if (drillElement.columnlevel === "SUBGROUP" &&
|
|
1239
|
-
row.category === drillElement.category &&
|
|
1240
|
-
row.subCategory === drillElement.subCategory) {
|
|
1241
|
-
row[drillElement.scenario + separator + drillElement.columnGroup + separator + drillElement.columnSubGroup] = drillElement.val;
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
* Transforms raw query results into structured TableRow collections for header and body.
|
|
1252
|
-
*
|
|
1253
|
-
* Header normalization: prepends fixed columns (operation, category) to the configured
|
|
1254
|
-
* scenarios, then translates labels via i18n and adds separator rows for IBCS-style borders.
|
|
1255
|
-
*
|
|
1256
|
-
* Body row creation: iterates DataQuery results grouped by rowGroup, creates detail rows
|
|
1257
|
-
* with type-specific logic (GROUPHEAD, SUM, DRILLELEMENT, PARTELEMENT, ENTRY), and
|
|
1258
|
-
* translates cell values/prefixes via i18n. Supports inline bar chart columns via
|
|
1259
|
-
* columnStats calculation.
|
|
1260
|
-
*/
|
|
1261
|
-
class TableDataSetFactory {
|
|
1262
|
-
constructor() {
|
|
1263
|
-
this.normalizedHeader = [];
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Creates Tableheader based on the configured scenarios (in config)
|
|
1267
|
-
* the created header is stored in the dataset json
|
|
1268
|
-
* the lables are translated based on the used i18n map
|
|
1269
|
-
* based on the structure of the scenarios 'spacer'coulumns are added, to
|
|
1270
|
-
* visualise grouping.
|
|
1271
|
-
* finally a seperator header row is created for the header underlining (border)
|
|
1272
|
-
*/
|
|
1273
|
-
createHeader(type, scenarios, i18n, measureScale, measureUnit, showMeasureScale) {
|
|
1274
|
-
const header = [];
|
|
1275
|
-
this.normalizedHeader = this.normalizeHeader(type, scenarios);
|
|
1276
|
-
const headerRow = new TableRow(0, 0, TableRowType.HEADER);
|
|
1277
|
-
const separatorRow = new TableRow(1, 0, TableRowType.SEPERATORLINE);
|
|
1278
|
-
for (const scenario of this.normalizedHeader) {
|
|
1279
|
-
headerRow.createElement(Formatter.translateScenarioLabel(scenario.name, i18n), scenario.type, this.createColumnType(scenario), null, this.setHeaderPrefix(scenario, i18n, measureScale, measureUnit, showMeasureScale), null, null, null, null);
|
|
1280
|
-
separatorRow.createElement(null, scenario.type, this.createColumnType(scenario), null, null, null, null, null, null);
|
|
1281
|
-
}
|
|
1282
|
-
header.push(headerRow);
|
|
1283
|
-
header.push(separatorRow);
|
|
1284
|
-
return header;
|
|
1285
|
-
}
|
|
1286
|
-
setHeaderPrefix(scenario, i18n, measureScale, measureUnit, showMeasureScale) {
|
|
1287
|
-
let prefix = "";
|
|
1288
|
-
if (scenario.name === "category" && showMeasureScale) {
|
|
1289
|
-
if (measureScale.prefix.length !== 0 || measureUnit.length !== 0) {
|
|
1290
|
-
prefix = Formatter.translateScenarioLabel("in", i18n) + " " + measureScale.prefix + measureUnit;
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
if (scenario.order) {
|
|
1294
|
-
prefix += Formatter.translateScenarioLabel("ORDER_" + scenario.order, i18n);
|
|
1295
|
-
}
|
|
1296
|
-
return prefix;
|
|
1297
|
-
}
|
|
1298
|
-
/**
|
|
1299
|
-
* combines the default columnnames (operation and category) with the
|
|
1300
|
-
* configured scenarios.
|
|
1301
|
-
* depending of table type operation column is used (OPT) or not (SUM | LIST)
|
|
1302
|
-
* in addition the headers are sorted based on the ruleset and duplicates are removed
|
|
1303
|
-
*/
|
|
1304
|
-
normalizeHeader(type, scenarios) {
|
|
1305
|
-
let header = [
|
|
1306
|
-
{
|
|
1307
|
-
name: QueryColumnNames.CATEGORY,
|
|
1308
|
-
group: QueryColumnNames.CATEGORY,
|
|
1309
|
-
type: QueryColumnNames.CATEGORY,
|
|
1310
|
-
order: undefined,
|
|
1311
|
-
},
|
|
1312
|
-
];
|
|
1313
|
-
if (TableType.OPT === type || TableType.OPTNOTOTAL === type) {
|
|
1314
|
-
header = [
|
|
1315
|
-
{
|
|
1316
|
-
name: QueryColumnNames.OPERATION,
|
|
1317
|
-
group: QueryColumnNames.OPERATION,
|
|
1318
|
-
type: QueryColumnNames.OPERATION,
|
|
1319
|
-
order: undefined,
|
|
1320
|
-
},
|
|
1321
|
-
{
|
|
1322
|
-
name: QueryColumnNames.CATEGORY,
|
|
1323
|
-
group: QueryColumnNames.CATEGORY,
|
|
1324
|
-
type: QueryColumnNames.CATEGORY,
|
|
1325
|
-
order: undefined,
|
|
1326
|
-
},
|
|
1327
|
-
];
|
|
1328
|
-
}
|
|
1329
|
-
// NOTE: scenarios are already sorted in setConfig
|
|
1330
|
-
return [...header, ...scenarios];
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* Creates table data colelction,
|
|
1334
|
-
* eachh row consists of data columns and 'spacer' columns which are needed to seperate
|
|
1335
|
-
* the columns correctyl (IBCS style)
|
|
1336
|
-
*/
|
|
1337
|
-
createBodyRows(config, i18n, data) {
|
|
1338
|
-
const bodyRows = [];
|
|
1339
|
-
let iGroupIndex = -1; // index used in detailRow JSON to count the current group
|
|
1340
|
-
const queryData = new DataQuery(config, i18n).execute(data); // collection of all query results
|
|
1341
|
-
// Calculate column statistics for bar columns
|
|
1342
|
-
const columnStatsMap = this.calculateColumnStatistics(queryData, config.barColumns);
|
|
1343
|
-
for (const groupData of queryData) {
|
|
1344
|
-
// groupData is a collection of dataRows, each group base on a query and represents a 'row' group
|
|
1345
|
-
iGroupIndex += 1;
|
|
1346
|
-
const iRowIndex = -1;
|
|
1347
|
-
bodyRows.push(...this.createRow(config.i18n, i18n, config.scenariosUnitType, groupData, iGroupIndex, iRowIndex, config.categoryWidth, config.measureScale, config.barColumns, columnStatsMap));
|
|
1348
|
-
}
|
|
1349
|
-
return bodyRows;
|
|
1350
|
-
}
|
|
1351
|
-
/**
|
|
1352
|
-
* Calculate min/max statistics for bar chart columns across all query data.
|
|
1353
|
-
*/
|
|
1354
|
-
calculateColumnStatistics(queryData, barColumns) {
|
|
1355
|
-
const statsMap = new Map();
|
|
1356
|
-
if (!barColumns || barColumns.length === 0) {
|
|
1357
|
-
return statsMap;
|
|
1358
|
-
}
|
|
1359
|
-
// Collect all values per column for median calculation
|
|
1360
|
-
const valuesMap = new Map();
|
|
1361
|
-
for (const column of barColumns) {
|
|
1362
|
-
statsMap.set(column, { min: Infinity, max: -Infinity, absMax: 0, median: 0 });
|
|
1363
|
-
valuesMap.set(column, []);
|
|
1364
|
-
}
|
|
1365
|
-
// Iterate through all groups and rows
|
|
1366
|
-
for (const groupData of queryData) {
|
|
1367
|
-
for (const row of groupData) {
|
|
1368
|
-
for (const column of barColumns) {
|
|
1369
|
-
const value = this.extractColumnValue(row, column);
|
|
1370
|
-
if (value !== null && !isNaN(value)) {
|
|
1371
|
-
const stats = statsMap.get(column);
|
|
1372
|
-
stats.min = Math.min(stats.min, value);
|
|
1373
|
-
stats.max = Math.max(stats.max, value);
|
|
1374
|
-
valuesMap.get(column).push(Math.abs(value));
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
// Finalize absMax and median values
|
|
1380
|
-
for (const [column, stats] of statsMap) {
|
|
1381
|
-
if (stats.min === Infinity || stats.max === -Infinity) {
|
|
1382
|
-
stats.min = 0;
|
|
1383
|
-
stats.max = 0;
|
|
1384
|
-
}
|
|
1385
|
-
stats.absMax = Math.max(Math.abs(stats.min), Math.abs(stats.max));
|
|
1386
|
-
const absValues = valuesMap.get(column);
|
|
1387
|
-
if (absValues.length > 0) {
|
|
1388
|
-
absValues.sort((a, b) => a - b);
|
|
1389
|
-
const mid = Math.floor(absValues.length / 2);
|
|
1390
|
-
stats.median = absValues.length % 2 === 0 ? (absValues[mid - 1] + absValues[mid]) / 2 : absValues[mid];
|
|
1391
|
-
}
|
|
1392
|
-
statsMap.set(column, stats);
|
|
1393
|
-
}
|
|
1394
|
-
return statsMap;
|
|
1395
|
-
}
|
|
1396
|
-
/**
|
|
1397
|
-
* Extract a numeric value from a row for a given column name.
|
|
1398
|
-
* Handles the various naming conventions used in the table data.
|
|
1399
|
-
*/
|
|
1400
|
-
extractColumnValue(row, column) {
|
|
1401
|
-
// Try direct access
|
|
1402
|
-
if (row[column] !== undefined) {
|
|
1403
|
-
const val = Number(row[column]);
|
|
1404
|
-
return isNaN(val) ? null : val;
|
|
1405
|
-
}
|
|
1406
|
-
// Search for keys that match the column (handles scenario## prefix patterns)
|
|
1407
|
-
for (const key of Object.keys(row)) {
|
|
1408
|
-
if (key === column || key.endsWith("##" + column) || key === column + "##" + column) {
|
|
1409
|
-
const val = Number(row[key]);
|
|
1410
|
-
if (!isNaN(val)) {
|
|
1411
|
-
return val;
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
return null;
|
|
1416
|
-
}
|
|
1417
|
-
/**
|
|
1418
|
-
* Helper funciton to generate a new Table Row,
|
|
1419
|
-
* it calls itsself recursive if a drilldown is set by the config file.
|
|
1420
|
-
* a drilldown is detected if there is a colection of rows in .drill
|
|
1421
|
-
*
|
|
1422
|
-
* @param i18nMode
|
|
1423
|
-
* @param i18n
|
|
1424
|
-
* @param scenariosUnitType
|
|
1425
|
-
* @param groupData
|
|
1426
|
-
* @param iGroupIndex
|
|
1427
|
-
* @param iRowIndex
|
|
1428
|
-
* @param categoryWidth
|
|
1429
|
-
* @param measureScale
|
|
1430
|
-
* @param barColumns
|
|
1431
|
-
* @param columnStatsMap
|
|
1432
|
-
*/
|
|
1433
|
-
createRow(i18nMode, i18n, scenariosUnitType, groupData, iGroupIndex, iRowIndex, categoryWidth, measureScale, barColumns, columnStatsMap) {
|
|
1434
|
-
var _a;
|
|
1435
|
-
const result = [];
|
|
1436
|
-
for (const rawDataRow of groupData) {
|
|
1437
|
-
iRowIndex += 1;
|
|
1438
|
-
// create next table row
|
|
1439
|
-
const groupName = rawDataRow[QueryColumnNames.ROWGROUP];
|
|
1440
|
-
const subCategory = rawDataRow[QueryColumnNames.SUBCATEGORY];
|
|
1441
|
-
const type = rawDataRow[QueryColumnNames.TYPE];
|
|
1442
|
-
const isSecondElement = rawDataRow[QueryColumnNames.ROWNR] >= 2;
|
|
1443
|
-
const detailsRow = this.createDetailRow(type, iRowIndex, iGroupIndex, groupData.length);
|
|
1444
|
-
for (const scenario of this.normalizedHeader) {
|
|
1445
|
-
const value = this.getRawDataRowElement(rawDataRow, scenario);
|
|
1446
|
-
const isBarChart = (_a = barColumns === null || barColumns === void 0 ? void 0 : barColumns.includes(scenario.type)) !== null && _a !== void 0 ? _a : false;
|
|
1447
|
-
const columnStats = isBarChart ? columnStatsMap === null || columnStatsMap === void 0 ? void 0 : columnStatsMap.get(scenario.type) : undefined;
|
|
1448
|
-
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), isSecondElement, categoryWidth, measureScale === null || measureScale === void 0 ? void 0 : measureScale.value, isBarChart, columnStats);
|
|
1449
|
-
}
|
|
1450
|
-
result.push(detailsRow);
|
|
1451
|
-
}
|
|
1452
|
-
return result;
|
|
1453
|
-
}
|
|
1454
|
-
getRawDataRowElement(rawDataRow, scenario) {
|
|
1455
|
-
if (scenario.name === scenario.group && scenario.name === scenario.type) {
|
|
1456
|
-
// Default Sum Scenario (e.g. AC)
|
|
1457
|
-
return rawDataRow[scenario.name];
|
|
1458
|
-
}
|
|
1459
|
-
else if (scenario.name === scenario.group && scenario.name !== scenario.type) {
|
|
1460
|
-
return rawDataRow[scenario.type + "##" + scenario.name];
|
|
1461
|
-
}
|
|
1462
|
-
return rawDataRow[scenario.type + "##" + scenario.group + "##" + scenario.name];
|
|
1463
|
-
}
|
|
1464
|
-
/**
|
|
1465
|
-
* Crates a detail row depending on the radDataRow Type
|
|
1466
|
-
* it switches between header, sum and standard,
|
|
1467
|
-
*
|
|
1468
|
-
* @param type valid values GROUPHEADER, SUM other values are interpreted as standard
|
|
1469
|
-
* @param rowIndex
|
|
1470
|
-
* @param groupIndex
|
|
1471
|
-
* @param maxIndex total number of rows
|
|
1472
|
-
*/
|
|
1473
|
-
createDetailRow(type, rowIndex, groupIndex, maxIndex) {
|
|
1474
|
-
switch (type) {
|
|
1475
|
-
case TableRowType.GROUPHEAD:
|
|
1476
|
-
return new TableRow(rowIndex, groupIndex, TableRowType.HEADER);
|
|
1477
|
-
case TableRowType.SUM:
|
|
1478
|
-
return new TableRow(maxIndex + 2, groupIndex, TableRowType.SUM);
|
|
1479
|
-
case TableRowType.GROUPSUM:
|
|
1480
|
-
return new TableRow(maxIndex + 2, groupIndex, TableRowType.SUM);
|
|
1481
|
-
case TableRowType.DRILLELEMENT:
|
|
1482
|
-
return new TableRow(maxIndex + 2, groupIndex, TableRowType.DRILLELEMENT);
|
|
1483
|
-
case TableRowType.PARTELEMENT:
|
|
1484
|
-
return new TableRow(maxIndex + 2, groupIndex, TableRowType.PARTELEMENT);
|
|
1485
|
-
default:
|
|
1486
|
-
return new TableRow(rowIndex, groupIndex, TableRowType.STANDARD);
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
/**
|
|
1490
|
-
* Translates Cell-Value (value) if possible,
|
|
1491
|
-
* Numbers are not translated, just category names,
|
|
1492
|
-
* if it is a SUM ROW rowGroup is used
|
|
1493
|
-
* if it is a variance in OPT mode the absolute value is used
|
|
1494
|
-
*
|
|
1495
|
-
* @param value
|
|
1496
|
-
* @param rowGroup
|
|
1497
|
-
* @param type
|
|
1498
|
-
* @param scenario
|
|
1499
|
-
* @param subCategory
|
|
1500
|
-
*/
|
|
1501
|
-
translateSumCellLabel(i18nMode, i18n, value, rowGroup, subCategory, type, scenario) {
|
|
1502
|
-
if (Number.isNaN(Number(value)) === false) {
|
|
1503
|
-
return value;
|
|
1504
|
-
}
|
|
1505
|
-
if (this.isOperationColumn(scenario)) {
|
|
1506
|
-
return value;
|
|
1507
|
-
}
|
|
1508
|
-
if (this.isGroupHeadCategory(type, scenario)) {
|
|
1509
|
-
if (i18nMode === I18nMode.ALL) {
|
|
1510
|
-
return `${i18n.get(value) || value}`;
|
|
1511
|
-
}
|
|
1512
|
-
return value;
|
|
1513
|
-
}
|
|
1514
|
-
if (this.isEntryCategory(type, scenario)) {
|
|
1515
|
-
if (i18nMode === I18nMode.ALL) {
|
|
1516
|
-
return `${i18n.get(value) || value}`;
|
|
1517
|
-
}
|
|
1518
|
-
return value;
|
|
1519
|
-
}
|
|
1520
|
-
if (this.isDrillElementCategory(type, scenario)) {
|
|
1521
|
-
if (i18nMode === I18nMode.ALL) {
|
|
1522
|
-
return `${i18n.get(subCategory) || subCategory}`;
|
|
1523
|
-
}
|
|
1524
|
-
return `${subCategory}`;
|
|
1525
|
-
}
|
|
1526
|
-
if (this.isPartElementCategory(type, scenario)) {
|
|
1527
|
-
// translate allways because of default sum symbol.
|
|
1528
|
-
if (i18nMode === I18nMode.ALL || rowGroup === "SUM_TOTAL") {
|
|
1529
|
-
return `${i18n.get(rowGroup) || rowGroup}`;
|
|
1530
|
-
}
|
|
1531
|
-
return `${rowGroup}`;
|
|
1532
|
-
}
|
|
1533
|
-
if (this.isSumElementCategory(type, scenario)) {
|
|
1534
|
-
if (i18nMode === I18nMode.ALL || rowGroup === "SUM_TOTAL") {
|
|
1535
|
-
return `${i18n.get(rowGroup) || rowGroup}`;
|
|
1536
|
-
}
|
|
1537
|
-
return rowGroup;
|
|
1538
|
-
}
|
|
1539
|
-
if ("GROUPHEAD" === type && value == null) {
|
|
1540
|
-
return value;
|
|
1541
|
-
}
|
|
1542
|
-
if (Number.isNaN(Number(value))) {
|
|
1543
|
-
return "-";
|
|
1544
|
-
}
|
|
1545
|
-
else {
|
|
1546
|
-
return Number(value);
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
isOperationColumn(scenario) {
|
|
1550
|
-
return scenario === "operation";
|
|
1551
|
-
}
|
|
1552
|
-
/**
|
|
1553
|
-
* converts Scenario to CSS class
|
|
1554
|
-
*
|
|
1555
|
-
* @param scenario
|
|
1556
|
-
* @param value
|
|
1557
|
-
*/
|
|
1558
|
-
translateScenarioCSS(scenario, value) {
|
|
1559
|
-
const scenarios = new VarianceScenario(scenario);
|
|
1560
|
-
let prefix = "pos";
|
|
1561
|
-
if (value < 0) {
|
|
1562
|
-
prefix = "neg";
|
|
1563
|
-
}
|
|
1564
|
-
if (scenarios.isValid) {
|
|
1565
|
-
return prefix + "_" + scenarios.direction + (scenarios.type === "dr" ? " relative_variance" : "");
|
|
1566
|
-
}
|
|
1567
|
-
return scenario;
|
|
1568
|
-
}
|
|
1569
|
-
setCellType(scenario, scenariosUnitType) {
|
|
1570
|
-
if (scenario === "category") {
|
|
1571
|
-
return "";
|
|
1572
|
-
}
|
|
1573
|
-
let unitType;
|
|
1574
|
-
const scenarios = new VarianceScenario(scenario);
|
|
1575
|
-
if (scenariosUnitType === DataFormat.PERCENT) {
|
|
1576
|
-
unitType = "percent";
|
|
1577
|
-
if (scenarios.isValid && scenarios.type === "d") {
|
|
1578
|
-
unitType = "decimal";
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
else {
|
|
1582
|
-
unitType = "decimal";
|
|
1583
|
-
if (scenarios.isValid && scenarios.type === "dr") {
|
|
1584
|
-
unitType = "percent";
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
return unitType;
|
|
1588
|
-
}
|
|
1589
|
-
isDrillElementCategory(type, scenario) {
|
|
1590
|
-
return "DRILLELEMENT" === type && "category" === scenario;
|
|
1591
|
-
}
|
|
1592
|
-
isPartElementCategory(type, scenario) {
|
|
1593
|
-
return "PARTELEMENT" === type && "category" === scenario;
|
|
1594
|
-
}
|
|
1595
|
-
isSumElementCategory(type, scenario) {
|
|
1596
|
-
return ("GROUP_SUM" === type || "SUM" === type) && "category" === scenario;
|
|
1597
|
-
}
|
|
1598
|
-
isEntryCategory(type, scenario) {
|
|
1599
|
-
return "ENTRY" === type && "category" === scenario;
|
|
1600
|
-
}
|
|
1601
|
-
isGroupHeadCategory(type, scenario) {
|
|
1602
|
-
return "GROUPHEAD" === type && "category" === scenario;
|
|
1603
|
-
}
|
|
1604
|
-
translateCellPrefix(i18n, type, scenario) {
|
|
1605
|
-
if (this.isOperationColumn(scenario)) {
|
|
1606
|
-
return null;
|
|
1607
|
-
}
|
|
1608
|
-
if (this.isGroupHeadCategory(type, scenario)) {
|
|
1609
|
-
return null;
|
|
1610
|
-
}
|
|
1611
|
-
if (this.isEntryCategory(type, scenario)) {
|
|
1612
|
-
return null;
|
|
1613
|
-
}
|
|
1614
|
-
if (this.isDrillElementCategory(type, scenario)) {
|
|
1615
|
-
return `${i18n.get("there_of")} `;
|
|
1616
|
-
}
|
|
1617
|
-
if (this.isPartElementCategory(type, scenario)) {
|
|
1618
|
-
// translate allways because of default sum symbol.
|
|
1619
|
-
return `${i18n.get("part_of")} `;
|
|
1620
|
-
}
|
|
1621
|
-
return null;
|
|
1622
|
-
}
|
|
1623
|
-
createColumnType(scenario) {
|
|
1624
|
-
if (scenario.name === scenario.group && scenario.name === scenario.type) {
|
|
1625
|
-
return "base";
|
|
1626
|
-
}
|
|
1627
|
-
if (scenario.name === scenario.group) {
|
|
1628
|
-
return "columnGroup";
|
|
1629
|
-
}
|
|
1630
|
-
return "columnSubGroup";
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
/**
|
|
1635
|
-
* High-level controller for IBCS table generation.
|
|
1636
|
-
*
|
|
1637
|
-
* Coordinates the data pipeline: raw data is filtered via AlaSQL, scenarios are
|
|
1638
|
-
* sorted by the visualization rule set, and TableDataSetFactory produces the
|
|
1639
|
-
* header rows (with i18n-translated labels) and body rows (with grouped/drilled data).
|
|
1640
|
-
*
|
|
1641
|
-
* Uses a dirty-flag pattern (FactoryState) to lazily regenerate header/body rows
|
|
1642
|
-
* only when configuration, data, or i18n changes. getHeader() and getBody() trigger
|
|
1643
|
-
* regeneration if the state is dirty.
|
|
1644
|
-
*/
|
|
1645
|
-
class Table {
|
|
1646
|
-
/**
|
|
1647
|
-
* Initialises all Variables for the DataSet, created by the factory
|
|
1648
|
-
* @param ruleSet
|
|
1649
|
-
*/
|
|
1650
|
-
constructor(ruleSet, data, config) {
|
|
1651
|
-
this.data = [];
|
|
1652
|
-
this.headerRows = [];
|
|
1653
|
-
this.bodyRows = [];
|
|
1654
|
-
this.ruleSet = ruleSet || new IBCSRuleSet();
|
|
1655
|
-
this.dataSetFactory = new TableDataSetFactory();
|
|
1656
|
-
this.config = this.initConfig(config);
|
|
1657
|
-
this.i18n = this.initI18n(new Map());
|
|
1658
|
-
this.setData(data, config.filter);
|
|
1659
|
-
this.state = FactoryState.DIRTY;
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* Init load of translation dictionary map
|
|
1663
|
-
* map is used to translate lables in the table
|
|
1664
|
-
*
|
|
1665
|
-
* example:
|
|
1666
|
-
* ```
|
|
1667
|
-
* let i18n: Map<string, string> = new Map();
|
|
1668
|
-
* [{key: 'ac',value: 'AC'}].forEach(function(entry){
|
|
1669
|
-
* i18n.set(entry.key, entry.value);
|
|
1670
|
-
* })
|
|
1671
|
-
* ```
|
|
1672
|
-
* @param i18n
|
|
1673
|
-
*/
|
|
1674
|
-
setI18n(i18n) {
|
|
1675
|
-
this.i18n = this.initI18n(i18n);
|
|
1676
|
-
}
|
|
1677
|
-
initI18n(i18n) {
|
|
1678
|
-
const defaultI18n = new Map([
|
|
1679
|
-
["", ""],
|
|
1680
|
-
["SEPERATOR_WS", ", "],
|
|
1681
|
-
["in", "in"],
|
|
1682
|
-
["ORDER_asc", "↑"],
|
|
1683
|
-
["ORDER_desc", "↓"],
|
|
1684
|
-
["ac1", "AC"],
|
|
1685
|
-
["pp1", "PY"],
|
|
1686
|
-
["fc1", "FC"],
|
|
1687
|
-
["pl1", "PL"],
|
|
1688
|
-
["ac2", "AC2"],
|
|
1689
|
-
["pp2", "PY2"],
|
|
1690
|
-
["fc2", "FC2"],
|
|
1691
|
-
["pl2", "PL2"],
|
|
1692
|
-
["ac3", "AC3"],
|
|
1693
|
-
["pp3", "PY3"],
|
|
1694
|
-
["fc3", "FC3"],
|
|
1695
|
-
["pl3", "PL3"],
|
|
1696
|
-
["ac4", "AC4"],
|
|
1697
|
-
["pp4", "PY4"],
|
|
1698
|
-
["fc4", "FC4"],
|
|
1699
|
-
["pl4", "PL4"],
|
|
1700
|
-
["in", "in"],
|
|
1701
|
-
["category", " "],
|
|
1702
|
-
["operation", " "],
|
|
1703
|
-
["there_of", "davon"],
|
|
1704
|
-
["part_of", "in % von"],
|
|
1705
|
-
["ibcssymbol_delta_ac", "Δ{%}"],
|
|
1706
|
-
["ibcssymbol_delta_generic", "Δ({%})"],
|
|
1707
|
-
["ibcssymbol_delta_ac_relative", "Δ{%}%"],
|
|
1708
|
-
["ibcssymbol_delta_generic_relative", "Δ({%})%"],
|
|
1709
|
-
["SUM_TOTAL", "❖"],
|
|
1710
|
-
]);
|
|
1711
|
-
this.state = FactoryState.DIRTY; // mark dataSet for update
|
|
1712
|
-
return new Map([...defaultI18n, ...(i18n || new Map())]);
|
|
1713
|
-
}
|
|
1714
|
-
initConfig(config) {
|
|
1715
|
-
this.state = FactoryState.DIRTY; // mark dataSet for update
|
|
1716
|
-
const tmpConfig = config;
|
|
1717
|
-
// sorting scenario order based on Ruleset
|
|
1718
|
-
const self = this;
|
|
1719
|
-
config.scenarios.sort((n1, n2) => {
|
|
1720
|
-
return self.ruleSet.getScenarioSorIndex(n1) - self.ruleSet.getScenarioSorIndex(n2);
|
|
1721
|
-
});
|
|
1722
|
-
return tmpConfig;
|
|
1723
|
-
}
|
|
1724
|
-
/**
|
|
1725
|
-
* loads and varifies configuration which describes
|
|
1726
|
-
* the filte for the to be generated dataset
|
|
1727
|
-
*
|
|
1728
|
-
* missing but necessary attributes are replaced by default values
|
|
1729
|
-
*
|
|
1730
|
-
* @param config
|
|
1731
|
-
*/
|
|
1732
|
-
setConfig(config) {
|
|
1733
|
-
this.config = this.initConfig(config);
|
|
1734
|
-
}
|
|
1735
|
-
setData(data, filter) {
|
|
1736
|
-
if (data == null) {
|
|
1737
|
-
return;
|
|
1738
|
-
}
|
|
1739
|
-
if (filter != null && filter.length > 0) {
|
|
1740
|
-
try {
|
|
1741
|
-
this.data = alasql(`SELECT * FROM ? WHERE ${filter}`, [data]);
|
|
1742
|
-
}
|
|
1743
|
-
catch (e) {
|
|
1744
|
-
console.error("Table: filter query failed, using unfiltered data", filter, e);
|
|
1745
|
-
this.data = data;
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
else {
|
|
1749
|
-
this.data = data;
|
|
1750
|
-
}
|
|
1751
|
-
const normalizedScenarios = this.normalizeScenarios(this.config.scenarios, this.config.categoryThereOf, this.config.sortOrder);
|
|
1752
|
-
this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale);
|
|
1753
|
-
this.bodyRows = this.dataSetFactory.createBodyRows(this.config, this.i18n, this.data);
|
|
1754
|
-
this.state = FactoryState.UP_TO_DATE;
|
|
1755
|
-
}
|
|
1756
|
-
update() {
|
|
1757
|
-
const normalizedScenarios = this.normalizeScenarios(this.config.scenarios, this.config.categoryThereOf, this.config.sortOrder);
|
|
1758
|
-
this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale);
|
|
1759
|
-
this.bodyRows = this.dataSetFactory.createBodyRows(this.config, this.i18n, this.data);
|
|
1760
|
-
this.state = FactoryState.UP_TO_DATE;
|
|
1761
|
-
}
|
|
1762
|
-
getHeader() {
|
|
1763
|
-
if (this.state === FactoryState.DIRTY) {
|
|
1764
|
-
this.update();
|
|
1765
|
-
}
|
|
1766
|
-
return this.headerRows;
|
|
1767
|
-
}
|
|
1768
|
-
getBody() {
|
|
1769
|
-
if (this.state === FactoryState.DIRTY) {
|
|
1770
|
-
this.update();
|
|
1771
|
-
}
|
|
1772
|
-
return this.bodyRows;
|
|
1773
|
-
}
|
|
1774
|
-
normalizeScenarios(scenarios, categoryThereOf, order) {
|
|
1775
|
-
var _a;
|
|
1776
|
-
const normalizedScenarios = [];
|
|
1777
|
-
for (const scenario of scenarios) {
|
|
1778
|
-
if (categoryThereOf === null || categoryThereOf === void 0 ? void 0 : categoryThereOf.has(scenario)) {
|
|
1779
|
-
const categoryDrills = categoryThereOf.get(scenario);
|
|
1780
|
-
for (const drillElement of categoryDrills) {
|
|
1781
|
-
normalizedScenarios.push({
|
|
1782
|
-
name: drillElement.name,
|
|
1783
|
-
group: drillElement.name,
|
|
1784
|
-
type: scenario,
|
|
1785
|
-
order: undefined,
|
|
1786
|
-
});
|
|
1787
|
-
for (const drillSubElement of drillElement.subGroups) {
|
|
1788
|
-
normalizedScenarios.push({
|
|
1789
|
-
name: drillSubElement,
|
|
1790
|
-
group: drillElement.name,
|
|
1791
|
-
type: scenario,
|
|
1792
|
-
order: undefined,
|
|
1793
|
-
});
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
normalizedScenarios.push({ name: "REST", group: "REST", type: scenario, order: undefined });
|
|
1797
|
-
}
|
|
1798
|
-
let orderDirection = undefined;
|
|
1799
|
-
if (((_a = order === null || order === void 0 ? void 0 : order.hierarchy) === null || _a === void 0 ? void 0 : _a.at(0)) === scenario) {
|
|
1800
|
-
orderDirection = order.direction;
|
|
1801
|
-
}
|
|
1802
|
-
normalizedScenarios.push({ name: scenario, group: scenario, type: scenario, order: orderDirection });
|
|
1803
|
-
}
|
|
1804
|
-
return normalizedScenarios;
|
|
1805
|
-
}
|
|
1806
|
-
hasNoData() {
|
|
1807
|
-
return this.data.length === 0;
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
/**
|
|
1812
|
-
* Configuration for an IBCS table component.
|
|
1813
|
-
*
|
|
1814
|
-
* Controls table behavior including drill-down groups, data formatting, and display modes.
|
|
1815
|
-
*
|
|
1816
|
-
* Drill-down concepts:
|
|
1817
|
-
* - **thereOf** -- Sub-rows that break down a parent row's total (e.g. "thereof: domestic / international").
|
|
1818
|
-
* Configured as an array of {@link TableDrillGroup} filters.
|
|
1819
|
-
* - **partOf** -- Rows shown as a percentage share of a parent total.
|
|
1820
|
-
* Also configured via {@link TableDrillGroup} filters.
|
|
1821
|
-
* - **categoryThereOf** -- Column-level drill-down using the `##` separator convention in category names
|
|
1822
|
-
* (e.g. `"Revenue##Product A"`) to expand a single category column into detail sub-columns.
|
|
1823
|
-
* The Map key is the parent category, values are the detail records.
|
|
1824
|
-
*/
|
|
1825
|
-
class TableComponentConfig {
|
|
1826
|
-
constructor() {
|
|
1827
|
-
this.title = "";
|
|
1828
|
-
/** Active scenario column names (e.g. `["ac1", "pl1"]`). */
|
|
1829
|
-
this.scenarios = [];
|
|
1830
|
-
/** Number format for scenario values (decimal, percent, etc.). */
|
|
1831
|
-
this.scenariosUnitType = DataFormat.DECIMAL;
|
|
1832
|
-
/** When true, rows are visually grouped by rowGroup. */
|
|
1833
|
-
this.grouped = false;
|
|
1834
|
-
this.showGroupTitle = true;
|
|
1835
|
-
/** Drill-down sub-row definitions -- "thereof" breakdowns within a category. */
|
|
1836
|
-
this.thereOf = [];
|
|
1837
|
-
/** Column-level drill-down using `##` separator in category names. */
|
|
1838
|
-
this.categoryThereOf = new Map();
|
|
1839
|
-
/** Percentage-of-total sub-row definitions. */
|
|
1840
|
-
this.partOf = [];
|
|
1841
|
-
this.sortOrder = new OrderAdapter(new StringAdapter()).default();
|
|
1842
|
-
/** Table aggregation mode: LIST (flat), SUM (with totals), OPT (with optional totals), etc. */
|
|
1843
|
-
this.type = TableType.LIST;
|
|
1844
|
-
/** Maximum rows to display; 0 means unlimited. */
|
|
1845
|
-
this.limit = 0;
|
|
1846
|
-
this.i18n = I18nMode.ALL;
|
|
1847
|
-
/** Proportion of table width allocated to the category label column. */
|
|
1848
|
-
this.categoryWidth = TableCategoryWidth.W25;
|
|
1849
|
-
/** SI prefix for measure scaling (e.g. "k" for thousands, "M" for millions). */
|
|
1850
|
-
this.measureScale = new SiPrefix();
|
|
1851
|
-
/** Unit label displayed in the table header (e.g. "EUR", "USD"). */
|
|
1852
|
-
this.measureUnit = "";
|
|
1853
|
-
/** Whether the measure represents a volume or a ratio, affecting formatting. */
|
|
1854
|
-
this.measureType = MeasureType.VOLUME;
|
|
1855
|
-
this.showMeasureScale = true;
|
|
1856
|
-
/** AlaSQL WHERE clause for additional row filtering. */
|
|
1857
|
-
this.filter = "";
|
|
1858
|
-
/** Scenario columns to render as inline bar charts instead of numbers. */
|
|
1859
|
-
this.barColumns = [];
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
/**
|
|
1863
|
-
* Converts untyped JSON into a validated {@link TableComponentConfig}.
|
|
1864
|
-
*
|
|
1865
|
-
* Requires the raw dataset for measure scale auto-calculation when `measureScale` is set to "auto".
|
|
1866
|
-
*/
|
|
1867
|
-
class TableComponentConfigAdapter {
|
|
1868
|
-
constructor(tableDrillGroupAdapter, stringAdapter, orderAdapter, dataSet) {
|
|
1869
|
-
this.tableDrillGroupAdapter = tableDrillGroupAdapter;
|
|
1870
|
-
this.stringAdapter = stringAdapter;
|
|
1871
|
-
this.orderAdapter = orderAdapter;
|
|
1872
|
-
this.dataSet = dataSet;
|
|
1873
|
-
}
|
|
1874
|
-
adapt(data) {
|
|
1875
|
-
const config = new TableComponentConfig();
|
|
1876
|
-
if (CompareUtil.isString(data.title)) {
|
|
1877
|
-
config.title = data.title;
|
|
1878
|
-
}
|
|
1879
|
-
if (CompareUtil.isArray(data.scenarios)) {
|
|
1880
|
-
config.scenarios = AdapterUtils.adaptArray(data.scenarios, this.stringAdapter);
|
|
1881
|
-
}
|
|
1882
|
-
if (CompareUtil.isExisting(data.scenariosUnitType)) {
|
|
1883
|
-
config.scenariosUnitType = data.scenariosUnitType;
|
|
1884
|
-
}
|
|
1885
|
-
if (CompareUtil.isBoolean(data.grouped)) {
|
|
1886
|
-
config.grouped = data.grouped;
|
|
1887
|
-
}
|
|
1888
|
-
if (CompareUtil.isBoolean(data.showGroupTitle)) {
|
|
1889
|
-
config.showGroupTitle = data.showGroupTitle;
|
|
1890
|
-
}
|
|
1891
|
-
if (CompareUtil.isBoolean(data.showMeasureScale)) {
|
|
1892
|
-
config.showMeasureScale = data.showMeasureScale;
|
|
1893
|
-
}
|
|
1894
|
-
if (CompareUtil.isArray(data.thereOf)) {
|
|
1895
|
-
config.thereOf = AdapterUtils.adaptArray(data.thereOf, this.tableDrillGroupAdapter);
|
|
1896
|
-
}
|
|
1897
|
-
if (CompareUtil.isExisting(data.categoryThereOf)) {
|
|
1898
|
-
config.categoryThereOf = data.categoryThereOf;
|
|
1899
|
-
}
|
|
1900
|
-
if (CompareUtil.isArray(data.partOf)) {
|
|
1901
|
-
config.partOf = AdapterUtils.adaptArray(data.partOf, this.tableDrillGroupAdapter);
|
|
1902
|
-
}
|
|
1903
|
-
if (CompareUtil.isExisting(data.order)) {
|
|
1904
|
-
config.sortOrder = this.orderAdapter.adapt(data.order);
|
|
1905
|
-
}
|
|
1906
|
-
if (CompareUtil.isExisting(data.type)) {
|
|
1907
|
-
config.type = data.type;
|
|
1908
|
-
}
|
|
1909
|
-
if (CompareUtil.isNumber(data.limit)) {
|
|
1910
|
-
config.limit = data.limit;
|
|
1911
|
-
}
|
|
1912
|
-
if (CompareUtil.isExisting(data.i18n)) {
|
|
1913
|
-
config.i18n = data.i18n;
|
|
1914
|
-
}
|
|
1915
|
-
if (CompareUtil.isExisting(data.categoryWidth)) {
|
|
1916
|
-
config.categoryWidth = data.categoryWidth;
|
|
1917
|
-
}
|
|
1918
|
-
if (CompareUtil.isExisting(data.measureScale)) {
|
|
1919
|
-
config.measureScale = DataAnalyzer.calculateMeasureScale(this.dataSet, config.scenarios, data.measureScale);
|
|
1920
|
-
}
|
|
1921
|
-
if (CompareUtil.isExisting(data.measureType)) {
|
|
1922
|
-
config.measureType = data.measureType;
|
|
1923
|
-
}
|
|
1924
|
-
if (CompareUtil.isString(data.measureUnit)) {
|
|
1925
|
-
config.measureUnit = data.measureUnit;
|
|
1926
|
-
}
|
|
1927
|
-
if (CompareUtil.isString(data.filter)) {
|
|
1928
|
-
config.filter = data.filter.trim();
|
|
1929
|
-
}
|
|
1930
|
-
if (CompareUtil.isArray(data.barColumns)) {
|
|
1931
|
-
config.barColumns = data.barColumns;
|
|
1932
|
-
}
|
|
1933
|
-
return config;
|
|
1934
|
-
}
|
|
1935
|
-
default() {
|
|
1936
|
-
return new TableComponentConfig();
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
// import { IAdapter } from "../../../../utils/helper/IAdapter";
|
|
1941
|
-
// import { CompareUtil } from "../../../../utils/helper/CompareUtil";
|
|
1942
|
-
/**
|
|
1943
|
-
* Filter definition for a table drill-down operation (thereOf or partOf).
|
|
1944
|
-
*
|
|
1945
|
-
* Identifies which rows in the dataset participate in a drill-down group by matching
|
|
1946
|
-
* on the three-level row hierarchy. For partOf drill-downs, the {@link partOf} field
|
|
1947
|
-
* names the parent category whose total is used as the 100% reference.
|
|
1948
|
-
*/
|
|
1949
|
-
class TableDrillGroup {
|
|
1950
|
-
constructor() {
|
|
1951
|
-
this.rowGroup = "";
|
|
1952
|
-
this.category = "";
|
|
1953
|
-
this.subCategory = "";
|
|
1954
|
-
/** Parent category name for percentage-of-total (partOf) calculations. Empty for thereOf groups. */
|
|
1955
|
-
this.partOf = "";
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
/** Converts untyped JSON into a validated {@link TableDrillGroup}. */
|
|
1959
|
-
class TableDrillGroupAdapter {
|
|
1960
|
-
constructor() { }
|
|
1961
|
-
adapt(data) {
|
|
1962
|
-
const group = new TableDrillGroup();
|
|
1963
|
-
if (CompareUtil.isString(data.rowGroup)) {
|
|
1964
|
-
group.rowGroup = data.rowGroup;
|
|
1965
|
-
}
|
|
1966
|
-
if (CompareUtil.isString(data.category)) {
|
|
1967
|
-
group.category = data.category;
|
|
1968
|
-
}
|
|
1969
|
-
if (CompareUtil.isString(data.subCategory)) {
|
|
1970
|
-
group.subCategory = data.subCategory;
|
|
1971
|
-
}
|
|
1972
|
-
if (CompareUtil.isString(data.partOf)) {
|
|
1973
|
-
group.partOf = data.partOf;
|
|
1974
|
-
}
|
|
1975
|
-
return group;
|
|
1976
|
-
}
|
|
1977
|
-
default() {
|
|
1978
|
-
return new TableDrillGroup();
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
// import { IAdapter } from "../../../../utils/helper/IAdapter";
|
|
1983
|
-
// import { CompareUtil } from "../../../../utils/helper/CompareUtil";
|
|
1984
|
-
/**
|
|
1985
|
-
* IBCS-compliant data row for table visualizations.
|
|
1986
|
-
*
|
|
1987
|
-
* Represents a single record with a three-level row hierarchy (rowGroup > category > subCategory),
|
|
1988
|
-
* a two-level column hierarchy (columnGroup > columnSubGroup), and 16 scenario value slots across
|
|
1989
|
-
* four scenario types: actual (ac1-4), previous period (pp1-4), forecast (fc1-4), and plan (pl1-4).
|
|
1990
|
-
*
|
|
1991
|
-
* The {@link operation} field controls how this row participates in aggregations:
|
|
1992
|
-
* `"+"` adds and `"-"` subtracts the row's values. This is converted to a numeric multiplier
|
|
1993
|
-
* by `transformOperator()` in the SQL query engine.
|
|
1994
|
-
*/
|
|
1995
|
-
class TableDataRow {
|
|
1996
|
-
constructor() {
|
|
1997
|
-
/** Aggregation operator: `"+"` adds values, `"-"` subtracts them in SUM/OPT roll-ups. */
|
|
1998
|
-
this.operation = "+";
|
|
1999
|
-
}
|
|
2000
|
-
addRowGroup(name, index) {
|
|
2001
|
-
this.rowGroup = name;
|
|
2002
|
-
this.rowGroupIndex = index;
|
|
2003
|
-
}
|
|
2004
|
-
addCategory(name, index) {
|
|
2005
|
-
this.category = name;
|
|
2006
|
-
this.categoryIndex = index;
|
|
2007
|
-
}
|
|
2008
|
-
addSubCategory(name, index) {
|
|
2009
|
-
this.subCategory = name;
|
|
2010
|
-
this.subCategoryIndex = index;
|
|
2011
|
-
}
|
|
2012
|
-
addColumnGroup(name, index) {
|
|
2013
|
-
this.columnGroup = name;
|
|
2014
|
-
this.columnGroupIndex = index;
|
|
2015
|
-
}
|
|
2016
|
-
addSubColumnGroup(name, index) {
|
|
2017
|
-
this.columnSubGroup = name;
|
|
2018
|
-
this.columnSubGroupIndex = index;
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
/**
|
|
2022
|
-
* Converts untyped JSON records into validated {@link TableDataRow} instances.
|
|
2023
|
-
*
|
|
2024
|
-
* Only assigns fields that pass type validation via {@link CompareUtil}, so malformed
|
|
2025
|
-
* input data is silently dropped and defaults are preserved.
|
|
2026
|
-
*/
|
|
2027
|
-
class TableDataRowAdapter {
|
|
2028
|
-
constructor() { }
|
|
2029
|
-
adapt(data) {
|
|
2030
|
-
const dataRow = new TableDataRow();
|
|
2031
|
-
if (CompareUtil.isOperator(data.operation)) {
|
|
2032
|
-
dataRow.operation = data.operation;
|
|
2033
|
-
}
|
|
2034
|
-
if (CompareUtil.isNumber(data.rowGroupIndex) && CompareUtil.isString(data.rowGroup)) {
|
|
2035
|
-
dataRow.addRowGroup(data.rowGroup, data.rowGroupIndex);
|
|
2036
|
-
}
|
|
2037
|
-
if (CompareUtil.isNumber(data.categoryIndex) && CompareUtil.isString(data.category)) {
|
|
2038
|
-
dataRow.addCategory(data.category, data.categoryIndex);
|
|
2039
|
-
}
|
|
2040
|
-
if (CompareUtil.isNumber(data.subCategoryIndex) && CompareUtil.isString(data.subCategory)) {
|
|
2041
|
-
dataRow.addSubCategory(data.subCategory, data.subCategoryIndex);
|
|
2042
|
-
}
|
|
2043
|
-
if (CompareUtil.isNumber(data.columnGroupIndex) && CompareUtil.isString(data.columnGroup)) {
|
|
2044
|
-
dataRow.addColumnGroup(data.columnGroup, data.columnGroupIndex);
|
|
2045
|
-
}
|
|
2046
|
-
if (CompareUtil.isNumber(data.columnSubGroupIndex) && CompareUtil.isString(data.columnSubGroup)) {
|
|
2047
|
-
dataRow.addSubColumnGroup(data.columnSubGroup, data.columnSubGroupIndex);
|
|
2048
|
-
}
|
|
2049
|
-
this.setActualValues(data, dataRow);
|
|
2050
|
-
this.setPlanValues(data, dataRow);
|
|
2051
|
-
this.setPreviousPeriodValues(data, dataRow);
|
|
2052
|
-
this.setForecastValues(data, dataRow);
|
|
2053
|
-
return dataRow;
|
|
2054
|
-
}
|
|
2055
|
-
default() {
|
|
2056
|
-
return new TableDataRow();
|
|
2057
|
-
}
|
|
2058
|
-
setActualValues(data, dataRow) {
|
|
2059
|
-
if (CompareUtil.isNumber(data.ac1)) {
|
|
2060
|
-
dataRow.ac1 = data.ac1;
|
|
2061
|
-
}
|
|
2062
|
-
if (CompareUtil.isNumber(data.ac2)) {
|
|
2063
|
-
dataRow.ac2 = data.ac2;
|
|
2064
|
-
}
|
|
2065
|
-
if (CompareUtil.isNumber(data.ac3)) {
|
|
2066
|
-
dataRow.ac3 = data.ac3;
|
|
2067
|
-
}
|
|
2068
|
-
if (CompareUtil.isNumber(data.ac4)) {
|
|
2069
|
-
dataRow.ac4 = data.ac4;
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
setPlanValues(data, dataRow) {
|
|
2073
|
-
if (CompareUtil.isNumber(data.pp1)) {
|
|
2074
|
-
dataRow.pp1 = data.pp1;
|
|
2075
|
-
}
|
|
2076
|
-
if (CompareUtil.isNumber(data.pp2)) {
|
|
2077
|
-
dataRow.pp2 = data.pp2;
|
|
2078
|
-
}
|
|
2079
|
-
if (CompareUtil.isNumber(data.pp3)) {
|
|
2080
|
-
dataRow.pp3 = data.pp3;
|
|
2081
|
-
}
|
|
2082
|
-
if (CompareUtil.isNumber(data.pp4)) {
|
|
2083
|
-
dataRow.pp4 = data.pp4;
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
setPreviousPeriodValues(data, dataRow) {
|
|
2087
|
-
if (CompareUtil.isNumber(data.pl1)) {
|
|
2088
|
-
dataRow.pl1 = data.pl1;
|
|
2089
|
-
}
|
|
2090
|
-
if (CompareUtil.isNumber(data.pl2)) {
|
|
2091
|
-
dataRow.pl2 = data.pl2;
|
|
2092
|
-
}
|
|
2093
|
-
if (CompareUtil.isNumber(data.pl3)) {
|
|
2094
|
-
dataRow.pl3 = data.pl3;
|
|
2095
|
-
}
|
|
2096
|
-
if (CompareUtil.isNumber(data.pl4)) {
|
|
2097
|
-
dataRow.pl4 = data.pl4;
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
setForecastValues(data, dataRow) {
|
|
2101
|
-
if (CompareUtil.isNumber(data.fc1)) {
|
|
2102
|
-
dataRow.fc1 = data.fc1;
|
|
2103
|
-
}
|
|
2104
|
-
if (CompareUtil.isNumber(data.fc2)) {
|
|
2105
|
-
dataRow.fc2 = data.fc2;
|
|
2106
|
-
}
|
|
2107
|
-
if (CompareUtil.isNumber(data.fc3)) {
|
|
2108
|
-
dataRow.fc3 = data.fc3;
|
|
2109
|
-
}
|
|
2110
|
-
if (CompareUtil.isNumber(data.fc4)) {
|
|
2111
|
-
dataRow.fc4 = data.fc4;
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
const ibcsTableCss = () => `:host{position:relative;display:inline-block}table{background-color:var(--bn-font-background, white);font-size:var(--bn-font-size, 1em);color:var(--bn-font-color, black);font-family:var(--bn-font-family, "Noto Sans", "Helvetica Neue", Helvetica, sans-serif);border-spacing:0.3em 0}thead{border-style:none}tr:first-child td{border-top:none;padding-top:0.5em}td.ac1,td.ac2,td.ac3,td.ac4,td.pp1,td.pp2,td.pp3,td.pp4,td.pl1,td.pl2,td.pl3,td.pl4,td.fc1,td.fc2,td.fc3,td.fc4,td.share,td.variance,td.pos_pos,td.pos_neg,td.neg_pos,td.neg_neg,td.pos_neutral,td.neg_neutral{text-align:right}.category-w100{min-width:100em;max-width:100em}.category-w50{min-width:50em;max-width:50em}.category-w25{min-width:25em;max-width:25em}.category-w20{min-width:20em;max-width:20em}.category-w15{min-width:15em;max-width:15em}.category-w10{min-width:10em;max-width:10em}.category-w5{min-width:5em;max-width:5em}.prefix-second{color:transparent;font-style:normal}.prefix-first{font-style:normal}th{border-bottom:0.1em solid black;text-align:right;font-weight:normal;vertical-align:text-top}td.columnGroup,th.columnGroup{font-size:0.6em}td.columnSubGroup,th.columnSubGroup{font-size:0.6em;border-spacing:0em 0;font-style:italic}td.base,th.base{font-style:normal}th.ofit,td.ofit,tr.ofit,th.partof,td.partof,tr.partof{font-size:0.6em;font-style:italic}td.ofit,td.partof{font-size:0.6em;font-style:italic}th.ofit td,tr.ofit td,th.partof td,tr.partof td{border-top:0em solid black;padding-left:1em}th.ofit share,th.partof share,tr.share td{border-top:0em solid black}th.share,tr.share,td.share{font-size:0.6em;font-style:italic}th.filler{border-bottom:0em solid black;text-align:right}td.filler{border-top:0em none !important;border-bottom:0em none;text-align:right}th.group{text-align:center;border-spacing:1em 0}th.headerlabel{border-bottom:0em none black;padding-bottom:0em}td.variance:after{content:"%"}td.relative_variance{font-style:italic}td.percent{font-style:italic;text-align:right}td.decimal{text-align:right}td.pos_pos{color:#008f96}td.neg_pos{color:#ff0000}td.pos_neg{color:#ff0000}td.neg_neg{color:#008f96}td.pos_pos:before{content:"+"}td.pos_neg:before{content:"+"}td.pos_neu:before{content:"+"}th.ac1,th.ac2,th.ac3,th.ac4{padding-top:0em;border-bottom:0.3em solid black}th.pp1,th.pp2,th.pp3,th.pp4{padding-top:0em;border-bottom:0.3em solid grey}th.pl1,th.pl2,th.pl3,th.pl4{padding-top:0em;border-bottom:0.3em double black}th.fc1,th.fc2,th.fc3,th.fc4{border-bottom:0.3em solid;border-image:repeating-linear-gradient(-45deg, white, white, black, white, white 0.3em) 2}td.colsum{font-weight:bold}th.colsum{padding-top:0em;font-weight:bold}tr.sum td{border-top:0.1em solid black;font-weight:bold;padding-bottom:0.5em}tr.groupheader td{border-top:0em dotted #ddd;padding-top:0.5em;font-weight:bold;font-style:italic}tr.begingroup td{border-top:0em dotted #ddd;padding-top:0.5em}th.begin-group{padding-left:0.75em}th.end-group{padding-left:0.75em}td{box-sizing:border-box;-webkit-box-sizing:border-box;border-top:0.1em dashed #ddd;padding-left:0.5em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.table-footer{font-size:0.6em}.cell-bar-chart{display:inline-block;vertical-align:middle}.bar-chart-empty{color:#999}td:has(.cell-bar-chart){padding:0 0.25em;vertical-align:middle}td:has(.cell-bar-chart).pos_pos:before,td:has(.cell-bar-chart).pos_neg:before,td:has(.cell-bar-chart).pos_neu:before{content:none}td:has(.cell-bar-chart).variance:after{content:none}`;
|
|
2117
|
-
|
|
2118
|
-
const IbcsTable = class {
|
|
2119
|
-
constructor(hostRef) {
|
|
2120
|
-
registerInstance(this, hostRef);
|
|
2121
|
-
this.data = [];
|
|
2122
|
-
this.tableTitle = "SUM_TOTAL";
|
|
2123
|
-
this.scenarios = [];
|
|
2124
|
-
this.scenariosDataFormat = DataFormat.DECIMAL;
|
|
2125
|
-
this.grouped = false;
|
|
2126
|
-
this.limit = 0;
|
|
2127
|
-
this.showGroupTitle = true;
|
|
2128
|
-
this.thereof = [];
|
|
2129
|
-
this.partof = [];
|
|
2130
|
-
this.order = {
|
|
2131
|
-
hierarchy: [],
|
|
2132
|
-
direction: OrderDirection.ASC,
|
|
2133
|
-
};
|
|
2134
|
-
this.categorythereof = new Map();
|
|
2135
|
-
this.type = TableType.LIST;
|
|
2136
|
-
this.categoryWidth = TableCategoryWidth.INF;
|
|
2137
|
-
this.dataFormatDigits = { percent: 2, decimal: 1 };
|
|
2138
|
-
this.i18n = new Map();
|
|
2139
|
-
this.i18nMode = I18nMode.ALL;
|
|
2140
|
-
this.measureScale = "_";
|
|
2141
|
-
this.measureUnit = "";
|
|
2142
|
-
this.showMeasureScale = true;
|
|
2143
|
-
this.measureType = MeasureType.VOLUME;
|
|
2144
|
-
this.filter = "";
|
|
2145
|
-
this.barColumns = [];
|
|
2146
|
-
this.barColumnMaxWidth = 30;
|
|
2147
|
-
this.unitScaling = 0.01;
|
|
2148
|
-
this.percentageScaling = 0.5;
|
|
2149
|
-
this.scaleFactor = 1;
|
|
2150
|
-
this.componentDataFormatDigits = new DataFormatDigits();
|
|
2151
|
-
this.componentStyle = withComponentStyle(this);
|
|
2152
|
-
}
|
|
2153
|
-
render() {
|
|
2154
|
-
const helper = () => {
|
|
2155
|
-
if (this.table === undefined) {
|
|
2156
|
-
return;
|
|
2157
|
-
}
|
|
2158
|
-
if (this.table.hasNoData()) {
|
|
2159
|
-
const errorMsg = this.i18n.get("NO_DATA") || "==No Data==";
|
|
2160
|
-
return h("p", { class: "warning" }, errorMsg);
|
|
2161
|
-
}
|
|
2162
|
-
return (h("table", null, h("thead", null, this.table.getHeader().map((row) => (h("tr", { class: row.cssStyle }, row.getCells().map((cell) => (h("th", { colSpan: cell.colSpan, class: cell.cssStyle }, cell.getAsHeaderList().map((line, i, arr) => (h("span", null, i === arr.length - 1 ? (h("span", { class: line === " " ? "table-footer" : "" }, line, cell.drawPrefix(), " ")) : (h("span", null, line, cell.drawPrefix(), h("br", null))))))))))))), h("tbody", null, this.table.getBody().map((row) => (h("tr", { class: row.cssStyle }, row === null || row === void 0 ? void 0 : row.getCells().map((cell) => (h("td", { colSpan: cell.colSpan, class: cell.type ? `${cell.cssStyle} ${cell.type}` : cell.cssStyle }, cell.prefix != null ? (h("span", { class: cell.cssStyle + " " + cell.prefixStyle }, cell.drawPrefix())) : (""), cell.isBarChart && cell.columnStats ? (h(CellBarChart, { value: cell.value, scenario: cell.key, columnStats: cell.columnStats, height: 18 * this.scaleFactor, isRelative: cell.key.startsWith("dr"), isPositiveGood: cell.key.endsWith("_pos"), measureScale: cell.measureScale, maxBarWidth: this.barColumnMaxWidth, styles: this.barChartStyles })) : (cell.draw(this.componentDataFormatDigits)))))))))));
|
|
2163
|
-
};
|
|
2164
|
-
return h(Host, null, helper());
|
|
2165
|
-
}
|
|
2166
|
-
componentWillRender() {
|
|
2167
|
-
const config = this.prepareConfig();
|
|
2168
|
-
const data = this.prepareData();
|
|
2169
|
-
this.componentDataFormatDigits = new DataFormatDigitsAdapter().adapt(this.dataFormatDigits);
|
|
2170
|
-
this.barChartStyles = this.prepareBarChartStyles();
|
|
2171
|
-
this.table = new Table(new IBCSRuleSet(), data, config);
|
|
2172
|
-
this.table.setI18n(this.i18n);
|
|
2173
|
-
}
|
|
2174
|
-
prepareConfig() {
|
|
2175
|
-
const config = new TableComponentConfigAdapter(new TableDrillGroupAdapter(), new StringAdapter(), new OrderAdapter(new StringAdapter()), this.data).adapt({
|
|
2176
|
-
title: this.tableTitle,
|
|
2177
|
-
scenarios: this.scenarios,
|
|
2178
|
-
scenariosUnitType: this.scenariosDataFormat,
|
|
2179
|
-
grouped: this.grouped,
|
|
2180
|
-
showGroupTitle: this.showGroupTitle,
|
|
2181
|
-
thereOf: this.thereof,
|
|
2182
|
-
partOf: this.partof,
|
|
2183
|
-
categoryThereOf: this.categorythereof,
|
|
2184
|
-
order: this.order,
|
|
2185
|
-
type: this.type,
|
|
2186
|
-
limit: this.limit,
|
|
2187
|
-
i18n: this.i18nMode,
|
|
2188
|
-
categoryWidth: this.categoryWidth,
|
|
2189
|
-
measureScale: this.measureScale,
|
|
2190
|
-
measureUnit: this.measureUnit,
|
|
2191
|
-
measureType: this.measureType,
|
|
2192
|
-
showMeasureScale: this.showMeasureScale,
|
|
2193
|
-
filter: this.filter,
|
|
2194
|
-
barColumns: this.barColumns,
|
|
2195
|
-
});
|
|
2196
|
-
return config;
|
|
2197
|
-
}
|
|
2198
|
-
prepareData() {
|
|
2199
|
-
return AdapterUtils.adaptArray(this.data, new TableDataRowAdapter());
|
|
2200
|
-
}
|
|
2201
|
-
/**
|
|
2202
|
-
* Prepares bar chart styles from componentStyle store.
|
|
2203
|
-
* Uses the same variance styles as bn-chart-time for consistency.
|
|
2204
|
-
* Supports fillpattern for different visual treatments (solid, hatched, outlined).
|
|
2205
|
-
* Scenario styles (ac, pp, fc, pl) use barStyles for IBCS-compliant grayscale coloring.
|
|
2206
|
-
*/
|
|
2207
|
-
prepareBarChartStyles() {
|
|
2208
|
-
return this.componentStyle(($) => {
|
|
2209
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
|
|
2210
|
-
const varianceStyles = (_a = $["bn-chart-time"]) === null || _a === void 0 ? void 0 : _a["varianceStyles"];
|
|
2211
|
-
const barStyles = (_b = $["bn-chart-time"]) === null || _b === void 0 ? void 0 : _b["barStyles"];
|
|
2212
|
-
// Default variance styles with fillpattern
|
|
2213
|
-
const defaultPos = { stroke: "#008f96", fill: "#008f96", fillpattern: "solid" };
|
|
2214
|
-
const defaultNeg = { stroke: "#ff0000", fill: "#ff0000", fillpattern: "solid" };
|
|
2215
|
-
const defaultNeu = { stroke: "#808080", fill: "#808080", fillpattern: "outlined" };
|
|
2216
|
-
// Default scenario styles (IBCS grayscale)
|
|
2217
|
-
const defaultAc = { stroke: "#404040", fill: "#404040", fillpattern: "solid" };
|
|
2218
|
-
const defaultPp = { stroke: "#A6A6A6", fill: "#A6A6A6", fillpattern: "solid" };
|
|
2219
|
-
const defaultFc = { stroke: "#404040", fill: "#ffffff", fillpattern: "hatched" };
|
|
2220
|
-
const defaultPl = { stroke: "#404040", fill: "#ffffff", fillpattern: "outlined" };
|
|
2221
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2222
|
-
return {
|
|
2223
|
-
positive: {
|
|
2224
|
-
stroke: ((_c = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.pos) === null || _c === void 0 ? void 0 : _c.stroke) || defaultPos.stroke,
|
|
2225
|
-
fill: ((_d = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.pos) === null || _d === void 0 ? void 0 : _d.fill) || defaultPos.fill,
|
|
2226
|
-
fillpattern: ((_e = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.pos) === null || _e === void 0 ? void 0 : _e.fillpattern) || defaultPos.fillpattern,
|
|
2227
|
-
},
|
|
2228
|
-
negative: {
|
|
2229
|
-
stroke: ((_f = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.neg) === null || _f === void 0 ? void 0 : _f.stroke) || defaultNeg.stroke,
|
|
2230
|
-
fill: ((_g = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.neg) === null || _g === void 0 ? void 0 : _g.fill) || defaultNeg.fill,
|
|
2231
|
-
fillpattern: ((_h = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.neg) === null || _h === void 0 ? void 0 : _h.fillpattern) || defaultNeg.fillpattern,
|
|
2232
|
-
},
|
|
2233
|
-
neutral: {
|
|
2234
|
-
stroke: ((_j = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.neu) === null || _j === void 0 ? void 0 : _j.stroke) || defaultNeu.stroke,
|
|
2235
|
-
fill: ((_k = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.neu) === null || _k === void 0 ? void 0 : _k.fill) || defaultNeu.fill,
|
|
2236
|
-
fillpattern: ((_l = varianceStyles === null || varianceStyles === void 0 ? void 0 : varianceStyles.neu) === null || _l === void 0 ? void 0 : _l.fillpattern) || defaultNeu.fillpattern,
|
|
2237
|
-
},
|
|
2238
|
-
scenarios: {
|
|
2239
|
-
ac: {
|
|
2240
|
-
stroke: ((_m = barStyles === null || barStyles === void 0 ? void 0 : barStyles.ac) === null || _m === void 0 ? void 0 : _m.stroke) || defaultAc.stroke,
|
|
2241
|
-
fill: ((_o = barStyles === null || barStyles === void 0 ? void 0 : barStyles.ac) === null || _o === void 0 ? void 0 : _o.fill) || defaultAc.fill,
|
|
2242
|
-
fillpattern: ((_p = barStyles === null || barStyles === void 0 ? void 0 : barStyles.ac) === null || _p === void 0 ? void 0 : _p.fillpattern) || defaultAc.fillpattern,
|
|
2243
|
-
},
|
|
2244
|
-
pp: {
|
|
2245
|
-
stroke: ((_q = barStyles === null || barStyles === void 0 ? void 0 : barStyles.pp) === null || _q === void 0 ? void 0 : _q.stroke) || defaultPp.stroke,
|
|
2246
|
-
fill: ((_r = barStyles === null || barStyles === void 0 ? void 0 : barStyles.pp) === null || _r === void 0 ? void 0 : _r.fill) || defaultPp.fill,
|
|
2247
|
-
fillpattern: ((_s = barStyles === null || barStyles === void 0 ? void 0 : barStyles.pp) === null || _s === void 0 ? void 0 : _s.fillpattern) || defaultPp.fillpattern,
|
|
2248
|
-
},
|
|
2249
|
-
fc: {
|
|
2250
|
-
stroke: ((_t = barStyles === null || barStyles === void 0 ? void 0 : barStyles.fc) === null || _t === void 0 ? void 0 : _t.stroke) || defaultFc.stroke,
|
|
2251
|
-
fill: ((_u = barStyles === null || barStyles === void 0 ? void 0 : barStyles.fc) === null || _u === void 0 ? void 0 : _u.fill) || defaultFc.fill,
|
|
2252
|
-
fillpattern: ((_v = barStyles === null || barStyles === void 0 ? void 0 : barStyles.fc) === null || _v === void 0 ? void 0 : _v.fillpattern) || defaultFc.fillpattern,
|
|
2253
|
-
},
|
|
2254
|
-
pl: {
|
|
2255
|
-
stroke: ((_w = barStyles === null || barStyles === void 0 ? void 0 : barStyles.pl) === null || _w === void 0 ? void 0 : _w.stroke) || defaultPl.stroke,
|
|
2256
|
-
fill: ((_x = barStyles === null || barStyles === void 0 ? void 0 : barStyles.pl) === null || _x === void 0 ? void 0 : _x.fill) || defaultPl.fill,
|
|
2257
|
-
fillpattern: ((_y = barStyles === null || barStyles === void 0 ? void 0 : barStyles.pl) === null || _y === void 0 ? void 0 : _y.fillpattern) || defaultPl.fillpattern,
|
|
2258
|
-
},
|
|
2259
|
-
},
|
|
2260
|
-
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
2261
|
-
fontColor: ((_z = $["global"]) === null || _z === void 0 ? void 0 : _z["fontColor"]) || "#000000",
|
|
2262
|
-
fontSize: (((_0 = $["global"]) === null || _0 === void 0 ? void 0 : _0["fontSizePx"]) || 13.3333) * 0.85 * this.scaleFactor,
|
|
2263
|
-
fontFamily: ((_1 = $["global"]) === null || _1 === void 0 ? void 0 : _1["fontFamily"]) || "'Noto Sans', sans-serif",
|
|
2264
|
-
unitScaling: this.unitScaling,
|
|
2265
|
-
percentageScaling: this.percentageScaling,
|
|
2266
|
-
scaleFactor: this.scaleFactor,
|
|
2267
|
-
};
|
|
2268
|
-
});
|
|
2269
|
-
}
|
|
2270
|
-
get element() { return getElement(this); }
|
|
2271
|
-
};
|
|
2272
|
-
IbcsTable.style = ibcsTableCss();
|
|
2273
|
-
|
|
2274
|
-
export { IbcsTable as ibcs_table };
|