@bino-bi/bn-template-engine 1.0.0-alpha.11 → 1.0.0-alpha.13
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-3c827826.entry.js +1 -0
- package/dist/bn-template-engine/p-46699464.entry.js +1 -0
- package/dist/bn-template-engine/{p-e783733e.entry.js → p-52097456.entry.js} +1 -1
- package/dist/bn-template-engine/p-637e3b8f.entry.js +1 -0
- package/dist/bn-template-engine/{p-c2cbb8ea.entry.js → p-67eae33e.entry.js} +1 -1
- package/dist/bn-template-engine/{p-fdb3e99a.entry.js → p-82023539.entry.js} +1 -1
- package/dist/bn-template-engine/p-BVFHvEXF.js +1 -0
- package/dist/bn-template-engine/p-BjBz5cSL.js +1 -0
- package/dist/bn-template-engine/p-CQnZV3JG.js +1 -0
- package/dist/bn-template-engine/p-DHheVOfP.js +1 -0
- package/dist/bn-template-engine/{p-e94b4e31.entry.js → p-ab3ea8cf.entry.js} +1 -1
- package/dist/cjs/bn-asset_21.cjs.entry.js +576 -730
- package/dist/cjs/bn-grid.cjs.entry.js +2 -2
- package/dist/cjs/bn-image.cjs.entry.js +2 -2
- package/dist/cjs/bn-internationalization.cjs.entry.js +2 -2
- package/dist/cjs/bn-template-engine.cjs.js +1 -1
- package/dist/cjs/bn-text.cjs.entry.js +3 -3
- package/dist/cjs/bn-tree.cjs.entry.js +2 -2
- package/dist/cjs/context-protocol-Op7uUwN3.js +9214 -0
- package/dist/cjs/editor-companion.cjs.entry.js +13 -6
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{scaling-eyzCrFB8.js → scaling-57N4Cxb_.js} +44 -40
- package/dist/cjs/{withBodyObserver-D7BKWN2N.js → withBodyObserver-BKUE_ypL.js} +12 -7
- package/dist/cjs/withStyled-C2kmGAK3.js +1405 -0
- package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +11 -6
- package/dist/collection/components/bn-chart-structure/ibcs-chart-structure.js +50 -22
- package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +51 -48
- package/dist/collection/components/bn-chart-structure/utils/model/StructureChartComponentConfig.js +5 -4
- package/dist/collection/components/bn-chart-time/bn-chart-time.js +11 -6
- package/dist/collection/components/bn-chart-time/ibcs-chart-time.js +47 -22
- package/dist/collection/components/bn-chart-time/utils/TimeChart.js +76 -60
- package/dist/collection/components/bn-chart-time/utils/model/TimeChartComponentConfig.js +5 -4
- package/dist/collection/components/bn-chart-time/utils/model/TimeChartDataRow.js +2 -0
- package/dist/collection/components/bn-dataset/bn-dataset.js +214 -23
- package/dist/collection/components/bn-datasource/bn-datasource.js +27 -9
- package/dist/collection/components/bn-table/bn-table.js +13 -5
- package/dist/collection/components/bn-table/ibcs-table.js +52 -25
- package/dist/collection/components/bn-table/utils/Table.js +27 -21
- package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +2 -2
- package/dist/collection/components/bn-table/utils/helper/DataQuery.js +52 -43
- package/dist/collection/components/bn-table/utils/helper/QueryGroup.js +4 -9
- package/dist/collection/components/bn-table/utils/model/TableComponentConfig.js +5 -4
- package/dist/collection/components/editor-companion/editor-companion.js +12 -5
- package/dist/collection/context/scopedDb.js +113 -0
- package/dist/collection/stores/createScopedStores.js +3 -4
- package/dist/collection/utils/dataAnalyzer.js +14 -8
- package/dist/collection/utils/withBodyObserver.js +12 -7
- package/dist/collection/utils/withDataset.js +43 -39
- package/dist/collection/utils/withDatasource.js +28 -18
- package/dist/components/DataFormatDigits.js +1 -1
- package/dist/components/DateStringFactory.js +1 -1
- package/dist/components/Order.js +1 -1
- package/dist/components/SVGVariancesStyleGroup.js +1 -1
- package/dist/components/bn-chart-structure.js +1 -1
- package/dist/components/bn-chart-time.js +1 -1
- package/dist/components/bn-dataset.js +1 -1
- package/dist/components/bn-datasource.js +1 -1
- package/dist/components/bn-table.js +1 -1
- package/dist/components/bn-title2.js +1 -1
- package/dist/components/context-protocol.js +1 -1
- package/dist/components/editor-companion.js +1 -1
- package/dist/components/ibcs-chart-structure2.js +1 -1
- package/dist/components/ibcs-chart-time2.js +1 -1
- package/dist/components/ibcs-table2.js +1 -1
- package/dist/components/ibcs-title2.js +1 -1
- package/dist/components/ibcsRuleSet.js +1 -1
- package/dist/components/luxon.js +1 -0
- package/dist/components/scaling.js +1 -1
- package/dist/components/withBodyObserver.js +1 -1
- package/dist/esm/bn-asset_21.entry.js +571 -725
- package/dist/esm/bn-grid.entry.js +2 -2
- package/dist/esm/bn-image.entry.js +2 -2
- package/dist/esm/bn-internationalization.entry.js +2 -2
- package/dist/esm/bn-template-engine.js +1 -1
- package/dist/esm/bn-text.entry.js +3 -3
- package/dist/esm/bn-tree.entry.js +2 -2
- package/dist/esm/context-protocol-BDhzNbeD.js +9204 -0
- package/dist/esm/editor-companion.entry.js +13 -6
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{scaling-BzbiBnuN.js → scaling-La1Ow72h.js} +44 -40
- package/dist/esm/{withBodyObserver-AFk2wwHT.js → withBodyObserver-IokS6fHD.js} +12 -7
- package/dist/esm/withStyled-Bl9cSoRW.js +1372 -0
- package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +4 -2
- package/dist/types/components/bn-chart-structure/ibcs-chart-structure.d.ts +7 -3
- package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +11 -12
- package/dist/types/components/bn-chart-structure/utils/model/StructureChartComponentConfig.d.ts +5 -3
- package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +4 -2
- package/dist/types/components/bn-chart-time/ibcs-chart-time.d.ts +7 -3
- package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +11 -12
- package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +5 -3
- package/dist/types/components/bn-dataset/bn-dataset.d.ts +39 -5
- package/dist/types/components/bn-datasource/bn-datasource.d.ts +5 -0
- package/dist/types/components/bn-table/bn-table.d.ts +4 -2
- package/dist/types/components/bn-table/ibcs-table.d.ts +11 -3
- package/dist/types/components/bn-table/utils/Table.d.ts +8 -6
- package/dist/types/components/bn-table/utils/factories/tableDataSetFactory.d.ts +2 -2
- package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +7 -3
- package/dist/types/components/bn-table/utils/helper/QueryGroup.d.ts +4 -5
- package/dist/types/components/bn-table/utils/model/TableComponentConfig.d.ts +5 -3
- package/dist/types/components/editor-companion/editor-companion.d.ts +2 -0
- package/dist/types/components.d.ts +105 -46
- package/dist/types/context/context-protocol.d.ts +4 -3
- package/dist/types/context/scopedDb.d.ts +37 -0
- package/dist/types/stores/createScopedStores.d.ts +1 -2
- package/dist/types/utils/DateStringFactory.d.ts +1 -1
- package/dist/types/utils/dataAnalyzer.d.ts +2 -1
- package/dist/types/utils/withDataset.d.ts +6 -2
- package/dist/types/utils/withDatasource.d.ts +3 -3
- package/package.json +2 -1
- package/dist/bn-template-engine/p-095f74d7.entry.js +0 -1
- package/dist/bn-template-engine/p-14318b0d.entry.js +0 -1
- package/dist/bn-template-engine/p-2133e02b.entry.js +0 -1
- package/dist/bn-template-engine/p-7HSTE79g.js +0 -1
- package/dist/bn-template-engine/p-Bi2wx-el.js +0 -1
- package/dist/bn-template-engine/p-CWiZks2h.js +0 -1
- package/dist/bn-template-engine/p-DSXNgKLa.js +0 -1
- package/dist/cjs/context-protocol-B_jipZpJ.js +0 -665
- package/dist/cjs/withStyled-V7xz_x1c.js +0 -9535
- package/dist/collection/stores/datasets.js +0 -14
- package/dist/collection/stores/datasources.js +0 -14
- package/dist/components/_commonjsHelpers.js +0 -1
- package/dist/components/alasql.min.js +0 -1
- package/dist/esm/context-protocol-D-o_UZ33.js +0 -658
- package/dist/esm/withStyled-5RqF8WBL.js +0 -9501
- package/dist/types/stores/datasets.d.ts +0 -14
- package/dist/types/stores/datasources.d.ts +0 -14
|
@@ -46,7 +46,10 @@ export class Table {
|
|
|
46
46
|
this.layoutObserver = null;
|
|
47
47
|
/** Last parent width seen, used to suppress ResizeObserver noise. */
|
|
48
48
|
this._lastScaledParentWidth = 0;
|
|
49
|
-
|
|
49
|
+
/** Active dataset name (the last subscribed dataset to fire `onUpdate`). */
|
|
50
|
+
this.datasetName = "";
|
|
51
|
+
/** Bumped on every data update so Stencil re-renders even when the name is unchanged. */
|
|
52
|
+
this.dataVersion = 0;
|
|
50
53
|
this.datasetMeta = null;
|
|
51
54
|
this.appliedScaleFactor = 1;
|
|
52
55
|
/**
|
|
@@ -273,8 +276,12 @@ export class Table {
|
|
|
273
276
|
this.errors = withHasError(this);
|
|
274
277
|
withScalingGroup(this);
|
|
275
278
|
this.componentStyle = withComponentStyle(this);
|
|
276
|
-
withDataset(this, (
|
|
277
|
-
|
|
279
|
+
withDataset(this, (name, _data) => {
|
|
280
|
+
// Helpers query the shared alasql database directly by name; we just
|
|
281
|
+
// record the active dataset and bump a version counter so Stencil
|
|
282
|
+
// re-renders when the data changes.
|
|
283
|
+
this.datasetName = (name === null || name === void 0 ? void 0 : name.startsWith("$")) ? name.substring(1) : name || "";
|
|
284
|
+
this.dataVersion = this.dataVersion + 1;
|
|
278
285
|
}, (_name, meta) => {
|
|
279
286
|
this.datasetMeta = meta;
|
|
280
287
|
});
|
|
@@ -986,7 +993,7 @@ export class Table {
|
|
|
986
993
|
render() {
|
|
987
994
|
const fontStyles = this.getFontStyles();
|
|
988
995
|
const effectiveFactor = this.getEffectiveScaleFactor();
|
|
989
|
-
return (h(Host, { key: '
|
|
996
|
+
return (h(Host, { key: '469aa0d5b00e111af96d33764640fa92eb5ed5cc', style: fontStyles }, h("div", { key: 'f02443601b7e644c243b48ad09af411a8460b659' }, h("ibcs-table", { key: '242ee74a5715c83a267e3f02daab09b9baca0c57', tableName: this.datasetName, dataVersion: this.dataVersion, "table-title": this.prepareTableTitle(), scenarios: this.prepareScenarios(), "scenarios-data-format": this.prepareDataFormat(), grouped: this.prepareGrouped(), limit: this.prepareLimit(), showGroupTitle: this.prepareShowGroupTitle(), thereof: this.prepareThereOf(), partof: this.preparePartOf(), order: this.prepareOrder(), categorythereof: this.prepareColumnThereOf(), type: this.prepareTableType(), "category-width": this.prepareCategoryWidth(), dataFormatDigits: this.prepareDataFormatDigits(), i18n: this.prepareI18n(), "i18n-mode": this.prepareI18nMode(), "measure-scale": this.prepareMeasureScale(), "measure-type": this.prepareMeasureType(), "measure-unit": this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(), filter: this.prepareFilter(), barColumns: this.prepareBarColumns(), barColumnMaxWidth: this.prepareBarColumnWidth(), unitScaling: this.prepareUnitScaling(), percentageScaling: this.preparePercentageScaling(), scaleFactor: effectiveFactor }))));
|
|
990
997
|
}
|
|
991
998
|
static get is() { return "bn-table"; }
|
|
992
999
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1537,7 +1544,8 @@ export class Table {
|
|
|
1537
1544
|
}
|
|
1538
1545
|
static get states() {
|
|
1539
1546
|
return {
|
|
1540
|
-
"
|
|
1547
|
+
"datasetName": {},
|
|
1548
|
+
"dataVersion": {},
|
|
1541
1549
|
"datasetMeta": {},
|
|
1542
1550
|
"appliedScaleFactor": {}
|
|
1543
1551
|
};
|
|
@@ -3,15 +3,14 @@ import { OrderDirection, TableRowType, TableType } from "./utils/model";
|
|
|
3
3
|
import { Table } from "./utils/Table";
|
|
4
4
|
import { TableComponentConfigAdapter } from "./utils/model/TableComponentConfig";
|
|
5
5
|
import { TableDrillGroupAdapter } from "./utils/model/TableDrillGroup";
|
|
6
|
-
import { TableDataRowAdapter } from "./utils/model/TableDataRow";
|
|
7
6
|
import { DataFormat, I18nMode, MeasureType, TableCategoryWidth } from "../../utils/constants";
|
|
8
|
-
import { AdapterUtils } from "../../utils/helper/AdapterUtils";
|
|
9
7
|
import { StringAdapter } from "../../utils/helper/StringAdapter";
|
|
10
8
|
import { IBCSRuleSet } from "../../utils/ibcsRuleSet";
|
|
11
9
|
import { DataFormatDigits, DataFormatDigitsAdapter } from "../../utils/model/DataFormatDigits";
|
|
12
10
|
import { OrderAdapter } from "../../utils/model/Order";
|
|
13
11
|
import { CellBarChart } from "./utils/elements/CellBarChart";
|
|
14
12
|
import withComponentStyle from "../../utils/withComponentStyle";
|
|
13
|
+
import { getStores } from "../../context/context-protocol";
|
|
15
14
|
/**
|
|
16
15
|
* Internal rendering engine for `bn-table`.
|
|
17
16
|
*
|
|
@@ -23,7 +22,16 @@ import withComponentStyle from "../../utils/withComponentStyle";
|
|
|
23
22
|
*/
|
|
24
23
|
export class IbcsTable {
|
|
25
24
|
constructor() {
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Name of the dataset (a table or view in the shared alasql database). The
|
|
27
|
+
* inner `Table` helper queries it directly — no array copy.
|
|
28
|
+
*/
|
|
29
|
+
this.tableName = "";
|
|
30
|
+
/**
|
|
31
|
+
* Bumped by the outer `bn-table` whenever the dataset's data changes. Triggers
|
|
32
|
+
* a re-render via Stencil's prop-change detection.
|
|
33
|
+
*/
|
|
34
|
+
this.dataVersion = 0;
|
|
27
35
|
this.tableTitle = "SUM_TOTAL";
|
|
28
36
|
this.scenarios = [];
|
|
29
37
|
this.scenariosDataFormat = DataFormat.DECIMAL;
|
|
@@ -69,15 +77,22 @@ export class IbcsTable {
|
|
|
69
77
|
return h(Host, null, helper());
|
|
70
78
|
}
|
|
71
79
|
componentWillRender() {
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
if (!this.stores)
|
|
81
|
+
this.stores = getStores(this.element);
|
|
82
|
+
const db = this.stores.db.db;
|
|
83
|
+
const config = this.prepareConfig(db);
|
|
74
84
|
this.componentDataFormatDigits = new DataFormatDigitsAdapter().adapt(this.dataFormatDigits);
|
|
75
|
-
this.table = new Table(new IBCSRuleSet(),
|
|
85
|
+
this.table = new Table(new IBCSRuleSet(), db, this.tableName, config);
|
|
76
86
|
this.table.setI18n(this.i18n);
|
|
77
87
|
this.barChartStyles = this.prepareBarChartStyles();
|
|
78
88
|
}
|
|
79
|
-
prepareConfig() {
|
|
80
|
-
const
|
|
89
|
+
prepareConfig(db) {
|
|
90
|
+
const fromExpr = this.tableName
|
|
91
|
+
? this.filter && this.filter.length > 0
|
|
92
|
+
? `(SELECT * FROM \`${this.tableName}\` WHERE ${this.filter}) AS __src`
|
|
93
|
+
: `\`${this.tableName}\``
|
|
94
|
+
: "";
|
|
95
|
+
const config = new TableComponentConfigAdapter(new TableDrillGroupAdapter(), new StringAdapter(), new OrderAdapter(new StringAdapter()), db, fromExpr).adapt({
|
|
81
96
|
title: this.tableTitle,
|
|
82
97
|
scenarios: this.scenarios,
|
|
83
98
|
scenariosUnitType: this.scenariosDataFormat,
|
|
@@ -100,9 +115,6 @@ export class IbcsTable {
|
|
|
100
115
|
});
|
|
101
116
|
return config;
|
|
102
117
|
}
|
|
103
|
-
prepareData() {
|
|
104
|
-
return AdapterUtils.adaptArray(this.data, new TableDataRowAdapter());
|
|
105
|
-
}
|
|
106
118
|
/**
|
|
107
119
|
* Prepares bar chart styles from componentStyle store.
|
|
108
120
|
* Uses the same variance styles as bn-chart-time for consistency.
|
|
@@ -251,30 +263,45 @@ export class IbcsTable {
|
|
|
251
263
|
}
|
|
252
264
|
static get properties() {
|
|
253
265
|
return {
|
|
254
|
-
"
|
|
255
|
-
"type": "
|
|
266
|
+
"tableName": {
|
|
267
|
+
"type": "string",
|
|
256
268
|
"mutable": false,
|
|
257
269
|
"complexType": {
|
|
258
|
-
"original": "
|
|
259
|
-
"resolved": "
|
|
260
|
-
"references": {
|
|
261
|
-
"TableDataRow": {
|
|
262
|
-
"location": "import",
|
|
263
|
-
"path": "./utils/model/TableDataRow",
|
|
264
|
-
"id": "src/components/bn-table/utils/model/TableDataRow.ts::TableDataRow",
|
|
265
|
-
"referenceLocation": "TableDataRow"
|
|
266
|
-
}
|
|
267
|
-
}
|
|
270
|
+
"original": "string",
|
|
271
|
+
"resolved": "string",
|
|
272
|
+
"references": {}
|
|
268
273
|
},
|
|
269
274
|
"required": false,
|
|
270
275
|
"optional": false,
|
|
271
276
|
"docs": {
|
|
272
277
|
"tags": [],
|
|
273
|
-
"text": ""
|
|
278
|
+
"text": "Name of the dataset (a table or view in the shared alasql database). The\ninner `Table` helper queries it directly \u2014 no array copy."
|
|
274
279
|
},
|
|
275
280
|
"getter": false,
|
|
276
281
|
"setter": false,
|
|
277
|
-
"
|
|
282
|
+
"reflect": false,
|
|
283
|
+
"attribute": "table-name",
|
|
284
|
+
"defaultValue": "\"\""
|
|
285
|
+
},
|
|
286
|
+
"dataVersion": {
|
|
287
|
+
"type": "number",
|
|
288
|
+
"mutable": false,
|
|
289
|
+
"complexType": {
|
|
290
|
+
"original": "number",
|
|
291
|
+
"resolved": "number",
|
|
292
|
+
"references": {}
|
|
293
|
+
},
|
|
294
|
+
"required": false,
|
|
295
|
+
"optional": false,
|
|
296
|
+
"docs": {
|
|
297
|
+
"tags": [],
|
|
298
|
+
"text": "Bumped by the outer `bn-table` whenever the dataset's data changes. Triggers\na re-render via Stencil's prop-change detection."
|
|
299
|
+
},
|
|
300
|
+
"getter": false,
|
|
301
|
+
"setter": false,
|
|
302
|
+
"reflect": false,
|
|
303
|
+
"attribute": "data-version",
|
|
304
|
+
"defaultValue": "0"
|
|
278
305
|
},
|
|
279
306
|
"tableTitle": {
|
|
280
307
|
"type": "string",
|
|
@@ -2,8 +2,8 @@ import { FactoryState } from "./model";
|
|
|
2
2
|
// import {IBCSRuleSet} from "../../../utils/ibcsRuleSet";
|
|
3
3
|
import { TableDataSetFactory } from "./factories/tableDataSetFactory";
|
|
4
4
|
// import { Order } from "../../../utils/model/Order";
|
|
5
|
-
import alasql from "alasql";
|
|
6
5
|
import { IBCSRuleSet } from "../../../utils/ibcsRuleSet";
|
|
6
|
+
import { buildFromExpr } from "../../../context/scopedDb";
|
|
7
7
|
/**
|
|
8
8
|
* High-level controller for IBCS table generation.
|
|
9
9
|
*
|
|
@@ -17,18 +17,20 @@ import { IBCSRuleSet } from "../../../utils/ibcsRuleSet";
|
|
|
17
17
|
*/
|
|
18
18
|
export class Table {
|
|
19
19
|
/**
|
|
20
|
-
* Initialises all Variables for the DataSet, created by the factory
|
|
21
|
-
*
|
|
20
|
+
* Initialises all Variables for the DataSet, created by the factory.
|
|
21
|
+
* Reads data directly from the shared alasql database (named by `tableName`).
|
|
22
22
|
*/
|
|
23
|
-
constructor(ruleSet,
|
|
24
|
-
this.
|
|
23
|
+
constructor(ruleSet, db, tableName, config) {
|
|
24
|
+
this.fromExpr = "";
|
|
25
|
+
this.rowCount = 0;
|
|
25
26
|
this.headerRows = [];
|
|
26
27
|
this.bodyRows = [];
|
|
27
28
|
this.ruleSet = ruleSet || new IBCSRuleSet();
|
|
29
|
+
this.db = db;
|
|
28
30
|
this.dataSetFactory = new TableDataSetFactory();
|
|
29
31
|
this.config = this.initConfig(config);
|
|
30
32
|
this.i18n = this.initI18n(new Map());
|
|
31
|
-
this.
|
|
33
|
+
this.setSource(tableName, config.filter);
|
|
32
34
|
this.state = FactoryState.DIRTY;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
@@ -105,31 +107,35 @@ export class Table {
|
|
|
105
107
|
setConfig(config) {
|
|
106
108
|
this.config = this.initConfig(config);
|
|
107
109
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
setSource(tableName, filter) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
if (!tableName) {
|
|
113
|
+
this.fromExpr = "";
|
|
114
|
+
this.rowCount = 0;
|
|
110
115
|
return;
|
|
111
116
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
catch (e) {
|
|
117
|
-
console.error("Table: filter query failed, using unfiltered data", filter, e);
|
|
118
|
-
this.data = data;
|
|
119
|
-
}
|
|
117
|
+
this.fromExpr = buildFromExpr(tableName, filter);
|
|
118
|
+
try {
|
|
119
|
+
const r = this.db.exec(`SELECT COUNT(*) AS cnt FROM ${this.fromExpr}`);
|
|
120
|
+
this.rowCount = ((_b = (_a = r[0]) === null || _a === void 0 ? void 0 : _a.cnt) !== null && _b !== void 0 ? _b : 0);
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
catch (_e) {
|
|
123
|
+
// Table may not exist yet (e.g. datasource hasn't loaded). Treat as empty.
|
|
124
|
+
this.rowCount = 0;
|
|
123
125
|
}
|
|
124
126
|
const normalizedScenarios = this.normalizeScenarios(this.config.scenarios, this.config.categoryThereOf, this.config.sortOrder);
|
|
125
127
|
this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale);
|
|
126
|
-
this.bodyRows =
|
|
128
|
+
this.bodyRows =
|
|
129
|
+
this.rowCount === 0 ? [] : this.dataSetFactory.createBodyRows(this.config, this.i18n, this.db, this.fromExpr);
|
|
127
130
|
this.state = FactoryState.UP_TO_DATE;
|
|
128
131
|
}
|
|
129
132
|
update() {
|
|
130
133
|
const normalizedScenarios = this.normalizeScenarios(this.config.scenarios, this.config.categoryThereOf, this.config.sortOrder);
|
|
131
134
|
this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale);
|
|
132
|
-
this.bodyRows =
|
|
135
|
+
this.bodyRows =
|
|
136
|
+
this.rowCount === 0 || !this.fromExpr
|
|
137
|
+
? []
|
|
138
|
+
: this.dataSetFactory.createBodyRows(this.config, this.i18n, this.db, this.fromExpr);
|
|
133
139
|
this.state = FactoryState.UP_TO_DATE;
|
|
134
140
|
}
|
|
135
141
|
getHeader() {
|
|
@@ -177,6 +183,6 @@ export class Table {
|
|
|
177
183
|
return normalizedScenarios;
|
|
178
184
|
}
|
|
179
185
|
hasNoData() {
|
|
180
|
-
return this.
|
|
186
|
+
return this.rowCount === 0;
|
|
181
187
|
}
|
|
182
188
|
}
|
|
@@ -91,10 +91,10 @@ export class TableDataSetFactory {
|
|
|
91
91
|
* eachh row consists of data columns and 'spacer' columns which are needed to seperate
|
|
92
92
|
* the columns correctyl (IBCS style)
|
|
93
93
|
*/
|
|
94
|
-
createBodyRows(config, i18n,
|
|
94
|
+
createBodyRows(config, i18n, db, fromExpr) {
|
|
95
95
|
const bodyRows = [];
|
|
96
96
|
let iGroupIndex = -1; // index used in detailRow JSON to count the current group
|
|
97
|
-
const queryData = new DataQuery(config, i18n).execute(
|
|
97
|
+
const queryData = new DataQuery(config, i18n).execute(db, fromExpr); // collection of all query results
|
|
98
98
|
// Calculate column statistics for bar columns
|
|
99
99
|
const columnStatsMap = this.calculateColumnStatistics(queryData, config.barColumns);
|
|
100
100
|
for (const groupData of queryData) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import alasql from "alasql";
|
|
2
1
|
import { OrderDirection, TableType } from "../model";
|
|
3
2
|
import { QueryGroups } from "./QueryGroup";
|
|
4
3
|
import { QueryColumnNames, VarianceScenario } from "../../../../utils/model";
|
|
@@ -30,12 +29,14 @@ export class DataQuery {
|
|
|
30
29
|
* 8. Calculate REST columns (parent minus drilled children)
|
|
31
30
|
* 9. Divide absolute variances by their denominator to produce relative variances
|
|
32
31
|
*
|
|
32
|
+
* @param db - The shared alasql database.
|
|
33
|
+
* @param fromExpr - SQL FROM-clause expression naming the source table or filtered view.
|
|
33
34
|
* @returns Array of row-group segments; each segment is an array of result rows.
|
|
34
35
|
*/
|
|
35
|
-
execute(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
execute(db, fromExpr) {
|
|
37
|
+
var _a;
|
|
38
|
+
this.db = db;
|
|
39
|
+
this.fromExpr = fromExpr;
|
|
39
40
|
const queries = [];
|
|
40
41
|
const sumGroupQueries = [];
|
|
41
42
|
const res = [];
|
|
@@ -55,9 +56,20 @@ export class DataQuery {
|
|
|
55
56
|
this.hasPartOf = this.checkConfigForPartOf();
|
|
56
57
|
// meta defines groups and the number detail rows in each group
|
|
57
58
|
// Bsp: 0: Object { totalrowcnt: 7, rowgroup: "Umsatz" }
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
let meta;
|
|
60
|
+
try {
|
|
61
|
+
meta = db.exec(`SELECT COUNT(DISTINCT ${QueryColumnNames.CATEGORY}) as ${QueryColumnNames.TOTALROWCOUNT} ${groupsAggregated.length > 0 ? "," + groupsAggregated : ""}
|
|
62
|
+
FROM ${fromExpr} ${groupsAggregated.length > 0 ? "GROUP BY " + groupsAggregated : ""}
|
|
63
|
+
ORDER BY ${order[0]}`);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error("DataQuery: meta query failed", e);
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
if (meta.length === 0 ||
|
|
70
|
+
(meta.length === 1 && ((_a = meta[0][QueryColumnNames.TOTALROWCOUNT]) !== null && _a !== void 0 ? _a : 0) === 0 && groupsAggregated.length === 0)) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
61
73
|
// Creates DataSelection for LIST
|
|
62
74
|
meta.forEach((rowGroupEntry) => {
|
|
63
75
|
// the following variables are 'helper sections' which are used to constuct dynamicly the sql statement depending of the given config
|
|
@@ -79,16 +91,16 @@ export class DataQuery {
|
|
|
79
91
|
// executes main queries
|
|
80
92
|
queries.forEach((query) => {
|
|
81
93
|
try {
|
|
82
|
-
res.push(
|
|
94
|
+
res.push(db.exec(query));
|
|
83
95
|
}
|
|
84
96
|
catch (err) {
|
|
85
97
|
console.error("DataQuery: SQL query execution failed", query, err);
|
|
86
98
|
}
|
|
87
99
|
});
|
|
88
100
|
this.detectNaNCells(this.config.scenarios, res);
|
|
89
|
-
this.createThereOfDrillRows(scenarios, order,
|
|
90
|
-
this.createPartOfDrillRows(scenarios, order, sumGroupQueries,
|
|
91
|
-
this.createThereOfDrillColumns(this.config.categoryThereOf,
|
|
101
|
+
this.createThereOfDrillRows(scenarios, order, res);
|
|
102
|
+
this.createPartOfDrillRows(scenarios, order, sumGroupQueries, res);
|
|
103
|
+
this.createThereOfDrillColumns(this.config.categoryThereOf, res);
|
|
92
104
|
this.calculateColumnGroupRest(res, this.config.categoryThereOf);
|
|
93
105
|
this.calculateRelativeVariances(res, relativeScenarios);
|
|
94
106
|
return res;
|
|
@@ -127,23 +139,20 @@ export class DataQuery {
|
|
|
127
139
|
* of its row group sum. Queries the drill subset, then divides each scenario
|
|
128
140
|
* value by the corresponding group sum to produce a percentage.
|
|
129
141
|
*/
|
|
130
|
-
createPartOfDrillRows(scenarios, order, sumGroupQueries,
|
|
131
|
-
if (this.config.partOf == null ||
|
|
132
|
-
this.config.partOf.length === 0 ||
|
|
133
|
-
this.config.type === TableType.LIST ||
|
|
134
|
-
data == null ||
|
|
135
|
-
data.length === 0) {
|
|
142
|
+
createPartOfDrillRows(scenarios, order, sumGroupQueries, res) {
|
|
143
|
+
if (this.config.partOf == null || this.config.partOf.length === 0 || this.config.type === TableType.LIST) {
|
|
136
144
|
return;
|
|
137
145
|
}
|
|
138
146
|
const drillQueries = this.createPartOfQuery(scenarios, order);
|
|
139
147
|
let resDrill = []; // set of drill (subquery result injected into resultset)
|
|
148
|
+
const db = this.db;
|
|
140
149
|
drillQueries.forEach(function (query) {
|
|
141
|
-
resDrill.push(...
|
|
150
|
+
resDrill.push(...db.exec(query));
|
|
142
151
|
});
|
|
143
152
|
const scenarioNames = this.exctractScenarioNames(scenarios);
|
|
144
153
|
const rowGroupSumResultRows = [];
|
|
145
154
|
sumGroupQueries.forEach(function (query) {
|
|
146
|
-
rowGroupSumResultRows.push(...
|
|
155
|
+
rowGroupSumResultRows.push(...db.exec(query));
|
|
147
156
|
});
|
|
148
157
|
const rowGroupSumResultMap = new Map();
|
|
149
158
|
rowGroupSumResultRows.forEach((row) => rowGroupSumResultMap.set(row[QueryColumnNames.ROWGROUP], row));
|
|
@@ -172,7 +181,7 @@ export class DataQuery {
|
|
|
172
181
|
if (rowGroupEntry.totalRowCnt - this.config.limit > 0 && this.config.limit !== 0) {
|
|
173
182
|
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)";
|
|
174
183
|
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` +
|
|
175
|
-
` (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
|
|
184
|
+
` (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 ${this.fromExpr} ${queryWhereSection} GROUP BY ${groups} ORDER BY ${order[0]})` +
|
|
176
185
|
` t WHERE t.rowNr > ${this.config.limit}`);
|
|
177
186
|
}
|
|
178
187
|
}
|
|
@@ -185,7 +194,7 @@ export class DataQuery {
|
|
|
185
194
|
'${rowGroupEntry.rowGroup || "NO_GROUP"}' as ${QueryColumnNames.ROWGROUP},
|
|
186
195
|
'${QueryColumnNames.CATEGORYINDEX}',
|
|
187
196
|
${groups} ${scenarios.length > 0 ? ",".concat(scenarios) : ""}
|
|
188
|
-
FROM
|
|
197
|
+
FROM ${this.fromExpr} ${queryWhereSection}
|
|
189
198
|
GROUP BY ${groups}
|
|
190
199
|
ORDER BY ${order[0]} ${queryLimitSection}`);
|
|
191
200
|
}
|
|
@@ -200,7 +209,7 @@ export class DataQuery {
|
|
|
200
209
|
${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
201
210
|
'GROUPHEAD' as ${QueryColumnNames.TYPE},
|
|
202
211
|
'${rowGroupEntry.rowGroup}' as ${QueryColumnNames.ROWGROUP} ${groupTitle}
|
|
203
|
-
FROM
|
|
212
|
+
FROM ${this.fromExpr}
|
|
204
213
|
GROUP BY '1'`);
|
|
205
214
|
}
|
|
206
215
|
}
|
|
@@ -217,7 +226,7 @@ export class DataQuery {
|
|
|
217
226
|
'${rowGroupEntry.rowGroup}' as ${QueryColumnNames.ROWGROUP},
|
|
218
227
|
ROWNUM() AS ${QueryColumnNames.ROWNR},
|
|
219
228
|
'GROUP_SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
220
|
-
FROM
|
|
229
|
+
FROM ${this.fromExpr}
|
|
221
230
|
WHERE ${QueryColumnNames.ROWGROUP} = '${rowGroupEntry.rowGroup}'
|
|
222
231
|
ORDER BY ${order[0]} `);
|
|
223
232
|
groupSumQuery.push(`SELECT ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
@@ -225,7 +234,7 @@ export class DataQuery {
|
|
|
225
234
|
'${rowGroupEntry.rowGroup}' as ${QueryColumnNames.ROWGROUP},
|
|
226
235
|
ROWNUM() AS ${QueryColumnNames.ROWNR},
|
|
227
236
|
'GROUP_SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
228
|
-
FROM
|
|
237
|
+
FROM ${this.fromExpr}
|
|
229
238
|
WHERE ${QueryColumnNames.ROWGROUP} = '${rowGroupEntry.rowGroup}'
|
|
230
239
|
ORDER BY ${order[0]} `);
|
|
231
240
|
}
|
|
@@ -238,13 +247,13 @@ export class DataQuery {
|
|
|
238
247
|
'${title}' as ${QueryColumnNames.ROWGROUP},
|
|
239
248
|
'=' as ${QueryColumnNames.OPERATION},
|
|
240
249
|
'SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
241
|
-
FROM
|
|
250
|
+
FROM ${this.fromExpr} `);
|
|
242
251
|
}
|
|
243
252
|
sumGroupQueries.push(`SELECT ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
|
|
244
253
|
'SUM_TOTAL' as ${QueryColumnNames.ROWGROUP},
|
|
245
254
|
'=' as ${QueryColumnNames.OPERATION},
|
|
246
255
|
'SUM' as ${QueryColumnNames.TYPE} ${scenariosSUMQuery.length > 0 ? ",".concat(scenariosSUMQuery) : ""}
|
|
247
|
-
FROM
|
|
256
|
+
FROM ${this.fromExpr} `);
|
|
248
257
|
}
|
|
249
258
|
/**
|
|
250
259
|
* Manually merges drill rows that AlaSQL fails to aggregate correctly.
|
|
@@ -330,7 +339,7 @@ export class DataQuery {
|
|
|
330
339
|
* beneath their parent category row. Each thereof config entry produces a
|
|
331
340
|
* filtered/grouped SQL query whose results are spliced into the result set.
|
|
332
341
|
*/
|
|
333
|
-
createThereOfDrillRows(scenarios, order,
|
|
342
|
+
createThereOfDrillRows(scenarios, order, res) {
|
|
334
343
|
// adds drill rows if setup in config
|
|
335
344
|
// if there of is set drilldown row is displayed with absolute numbers,
|
|
336
345
|
// if part of is also not null a relative percenatage based of the selected basis is displayed
|
|
@@ -366,15 +375,14 @@ export class DataQuery {
|
|
|
366
375
|
${QueryColumnNames.SUBCATEGORY},
|
|
367
376
|
${QueryColumnNames.ROWGROUP} as ${QueryColumnNames.ROWGROUP},
|
|
368
377
|
${scenarios}
|
|
369
|
-
FROM
|
|
378
|
+
FROM ${this.fromExpr}
|
|
370
379
|
WHERE ${fromString}
|
|
371
380
|
GROUP BY ${QueryColumnNames.ROWGROUP}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.SUBCATEGORY}
|
|
372
381
|
ORDER BY ${order[1]}`);
|
|
373
382
|
});
|
|
374
|
-
|
|
375
|
-
//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]}`);
|
|
383
|
+
const db = this.db;
|
|
376
384
|
drillQueries.forEach(function (query) {
|
|
377
|
-
resDrill.push(...
|
|
385
|
+
resDrill.push(...db.exec(query));
|
|
378
386
|
});
|
|
379
387
|
this.injectDrillRowsToResultRows(resDrill, res);
|
|
380
388
|
}
|
|
@@ -558,7 +566,7 @@ export class DataQuery {
|
|
|
558
566
|
${QueryColumnNames.CATEGORY},
|
|
559
567
|
${groupName},
|
|
560
568
|
${scenarios}
|
|
561
|
-
FROM
|
|
569
|
+
FROM ${this.fromExpr}
|
|
562
570
|
WHERE ${fromString}
|
|
563
571
|
GROUP BY ${QueryColumnNames.ROWGROUP}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.TYPE}
|
|
564
572
|
ORDER BY ${order[1]}`);
|
|
@@ -579,12 +587,13 @@ export class DataQuery {
|
|
|
579
587
|
* result rows using the `"##"` separator convention: `scenario##columnGroup` or
|
|
580
588
|
* `scenario##columnGroup##columnSubGroup`.
|
|
581
589
|
*/
|
|
582
|
-
createThereOfDrillColumns(categoryThereOf,
|
|
590
|
+
createThereOfDrillColumns(categoryThereOf, res) {
|
|
583
591
|
if (categoryThereOf == null || categoryThereOf.size === 0) {
|
|
584
592
|
return;
|
|
585
593
|
}
|
|
586
594
|
const drillQueries = [];
|
|
587
595
|
const resDrill = [];
|
|
596
|
+
const fromExpr = this.fromExpr;
|
|
588
597
|
categoryThereOf.forEach((value, key) => {
|
|
589
598
|
let whereClause = "1 <> 1 ";
|
|
590
599
|
value.forEach((drillColumn) => {
|
|
@@ -597,7 +606,7 @@ export class DataQuery {
|
|
|
597
606
|
columnGroup,
|
|
598
607
|
'${key}' as scenario,
|
|
599
608
|
sum(${key} * transformOperator(operation)) as val
|
|
600
|
-
FROM
|
|
609
|
+
FROM ${fromExpr}
|
|
601
610
|
WHERE ${whereClause}
|
|
602
611
|
GROUP BY rowlevel, rowGroup, category, columnGroup, scenario`);
|
|
603
612
|
drillQueries.push(`SELECT 'ENTRY' as rowlevel,
|
|
@@ -608,7 +617,7 @@ export class DataQuery {
|
|
|
608
617
|
columnSubGroup,
|
|
609
618
|
'${key}' as scenario,
|
|
610
619
|
sum(${key} * transformOperator(operation)) as val
|
|
611
|
-
FROM
|
|
620
|
+
FROM ${fromExpr}
|
|
612
621
|
WHERE ${whereClause}
|
|
613
622
|
GROUP BY rowlevel, rowGroup, category, columnGroup, columnSubGroup, scenario`);
|
|
614
623
|
drillQueries.push(`SELECT 'DRILLELEMENT' as rowlevel,
|
|
@@ -619,7 +628,7 @@ export class DataQuery {
|
|
|
619
628
|
columnGroup,
|
|
620
629
|
'${key}' as scenario,
|
|
621
630
|
sum(${key} * transformOperator(operation)) as val
|
|
622
|
-
FROM
|
|
631
|
+
FROM ${fromExpr}
|
|
623
632
|
WHERE ${whereClause}
|
|
624
633
|
GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, scenario`);
|
|
625
634
|
drillQueries.push(`SELECT 'DRILLELEMENT' as rowlevel,
|
|
@@ -631,7 +640,7 @@ export class DataQuery {
|
|
|
631
640
|
columnSubGroup,
|
|
632
641
|
'${key}' as scenario,
|
|
633
642
|
sum(${key} * transformOperator(operation)) as val
|
|
634
|
-
FROM
|
|
643
|
+
FROM ${fromExpr}
|
|
635
644
|
WHERE ${whereClause}
|
|
636
645
|
GROUP BY rowlevel, rowGroup, category, subCategory, columnGroup, columnSubGroup, scenario`);
|
|
637
646
|
drillQueries.push(`SELECT 'GROUP_SUM' as rowlevel,
|
|
@@ -640,7 +649,7 @@ export class DataQuery {
|
|
|
640
649
|
columnGroup,
|
|
641
650
|
'${key}' as scenario,
|
|
642
651
|
sum(${key} * transformOperator(operation)) as val
|
|
643
|
-
FROM
|
|
652
|
+
FROM ${fromExpr}
|
|
644
653
|
WHERE ${whereClause}
|
|
645
654
|
GROUP BY rowlevel, rowGroup, columnGroup, scenario`);
|
|
646
655
|
drillQueries.push(`SELECT 'GROUP_SUM' as rowlevel,
|
|
@@ -650,7 +659,7 @@ export class DataQuery {
|
|
|
650
659
|
columnSubGroup,
|
|
651
660
|
'${key}' as scenario,
|
|
652
661
|
sum(${key} * transformOperator(operation)) as val
|
|
653
|
-
FROM
|
|
662
|
+
FROM ${fromExpr}
|
|
654
663
|
WHERE ${whereClause}
|
|
655
664
|
GROUP BY rowlevel, rowGroup, columnGroup, columnSubGroup, scenario`);
|
|
656
665
|
drillQueries.push(`SELECT 'SUM' as rowlevel,
|
|
@@ -658,7 +667,7 @@ export class DataQuery {
|
|
|
658
667
|
columnGroup,
|
|
659
668
|
'${key}' as scenario,
|
|
660
669
|
sum(${key} * transformOperator(operation)) as val
|
|
661
|
-
FROM
|
|
670
|
+
FROM ${fromExpr}
|
|
662
671
|
WHERE ${whereClause}
|
|
663
672
|
GROUP BY rowlevel, columnGroup, scenario`);
|
|
664
673
|
drillQueries.push(`SELECT 'SUM' as rowlevel,
|
|
@@ -667,12 +676,12 @@ export class DataQuery {
|
|
|
667
676
|
columnSubGroup,
|
|
668
677
|
'${key}' as scenario,
|
|
669
678
|
sum(${key} * transformOperator(operation)) as val
|
|
670
|
-
FROM
|
|
679
|
+
FROM ${fromExpr}
|
|
671
680
|
WHERE ${whereClause}
|
|
672
681
|
GROUP BY rowlevel, columnGroup, columnSubGroup, scenario`);
|
|
673
682
|
});
|
|
674
683
|
for (const query of drillQueries) {
|
|
675
|
-
resDrill.push(...
|
|
684
|
+
resDrill.push(...this.db.exec(query));
|
|
676
685
|
}
|
|
677
686
|
this.injectDrillColumnsToResultRows(resDrill, res);
|
|
678
687
|
}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import alasql from "alasql";
|
|
2
1
|
import { TableType } from "../model";
|
|
3
2
|
import { QueryColumnNames } from "../../../../utils/model";
|
|
4
3
|
/**
|
|
5
|
-
* Manages the GROUP BY column list for DataQuery's SQL statements
|
|
6
|
-
* the `transformOperator` AlaSQL custom function.
|
|
4
|
+
* Manages the GROUP BY column list for DataQuery's SQL statements.
|
|
7
5
|
*
|
|
8
|
-
* `transformOperator`
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* The `transformOperator` AlaSQL UDF (which maps `"+"`/`"-"` to +1/-1 for
|
|
7
|
+
* sign-aware SUMs) is registered globally by `scopedDb.ts` when the shared
|
|
8
|
+
* database is created — no per-component registration is needed here.
|
|
11
9
|
*
|
|
12
10
|
* The GROUP BY columns are composed dynamically: always category + categoryIndex,
|
|
13
11
|
* plus operation for OPT types, plus rowGroup/rowGroupIndex when grouping is active.
|
|
14
12
|
*/
|
|
15
13
|
export class QueryGroups {
|
|
16
14
|
constructor(config) {
|
|
17
|
-
alasql.fn.transformOperator = function (a) {
|
|
18
|
-
return a === "-" ? -1 : 1;
|
|
19
|
-
};
|
|
20
15
|
this.groups = [QueryColumnNames.CATEGORY, QueryColumnNames.CATEGORYINDEX];
|
|
21
16
|
if (TableType.OPT === config.type || TableType.OPTNOTOTAL === config.type) {
|
|
22
17
|
this.groups.unshift(QueryColumnNames.OPERATION);
|
|
@@ -60,14 +60,15 @@ export class TableComponentConfig {
|
|
|
60
60
|
/**
|
|
61
61
|
* Converts untyped JSON into a validated {@link TableComponentConfig}.
|
|
62
62
|
*
|
|
63
|
-
*
|
|
63
|
+
* Reads from the shared alasql database for measure-scale auto-calculation when `measureScale` is set to "auto".
|
|
64
64
|
*/
|
|
65
65
|
export class TableComponentConfigAdapter {
|
|
66
|
-
constructor(tableDrillGroupAdapter, stringAdapter, orderAdapter,
|
|
66
|
+
constructor(tableDrillGroupAdapter, stringAdapter, orderAdapter, db, fromExpr) {
|
|
67
67
|
this.tableDrillGroupAdapter = tableDrillGroupAdapter;
|
|
68
68
|
this.stringAdapter = stringAdapter;
|
|
69
69
|
this.orderAdapter = orderAdapter;
|
|
70
|
-
this.
|
|
70
|
+
this.db = db;
|
|
71
|
+
this.fromExpr = fromExpr;
|
|
71
72
|
}
|
|
72
73
|
adapt(data) {
|
|
73
74
|
const config = new TableComponentConfig();
|
|
@@ -114,7 +115,7 @@ export class TableComponentConfigAdapter {
|
|
|
114
115
|
config.categoryWidth = data.categoryWidth;
|
|
115
116
|
}
|
|
116
117
|
if (CompareUtil.isExisting(data.measureScale)) {
|
|
117
|
-
config.measureScale = DataAnalyzer.calculateMeasureScale(this.
|
|
118
|
+
config.measureScale = DataAnalyzer.calculateMeasureScale(this.db, this.fromExpr, config.scenarios, data.measureScale);
|
|
118
119
|
}
|
|
119
120
|
if (CompareUtil.isExisting(data.measureType)) {
|
|
120
121
|
config.measureType = data.measureType;
|