@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.
Files changed (127) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/p-3c827826.entry.js +1 -0
  3. package/dist/bn-template-engine/p-46699464.entry.js +1 -0
  4. package/dist/bn-template-engine/{p-e783733e.entry.js → p-52097456.entry.js} +1 -1
  5. package/dist/bn-template-engine/p-637e3b8f.entry.js +1 -0
  6. package/dist/bn-template-engine/{p-c2cbb8ea.entry.js → p-67eae33e.entry.js} +1 -1
  7. package/dist/bn-template-engine/{p-fdb3e99a.entry.js → p-82023539.entry.js} +1 -1
  8. package/dist/bn-template-engine/p-BVFHvEXF.js +1 -0
  9. package/dist/bn-template-engine/p-BjBz5cSL.js +1 -0
  10. package/dist/bn-template-engine/p-CQnZV3JG.js +1 -0
  11. package/dist/bn-template-engine/p-DHheVOfP.js +1 -0
  12. package/dist/bn-template-engine/{p-e94b4e31.entry.js → p-ab3ea8cf.entry.js} +1 -1
  13. package/dist/cjs/bn-asset_21.cjs.entry.js +576 -730
  14. package/dist/cjs/bn-grid.cjs.entry.js +2 -2
  15. package/dist/cjs/bn-image.cjs.entry.js +2 -2
  16. package/dist/cjs/bn-internationalization.cjs.entry.js +2 -2
  17. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  18. package/dist/cjs/bn-text.cjs.entry.js +3 -3
  19. package/dist/cjs/bn-tree.cjs.entry.js +2 -2
  20. package/dist/cjs/context-protocol-Op7uUwN3.js +9214 -0
  21. package/dist/cjs/editor-companion.cjs.entry.js +13 -6
  22. package/dist/cjs/loader.cjs.js +1 -1
  23. package/dist/cjs/{scaling-eyzCrFB8.js → scaling-57N4Cxb_.js} +44 -40
  24. package/dist/cjs/{withBodyObserver-D7BKWN2N.js → withBodyObserver-BKUE_ypL.js} +12 -7
  25. package/dist/cjs/withStyled-C2kmGAK3.js +1405 -0
  26. package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +11 -6
  27. package/dist/collection/components/bn-chart-structure/ibcs-chart-structure.js +50 -22
  28. package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +51 -48
  29. package/dist/collection/components/bn-chart-structure/utils/model/StructureChartComponentConfig.js +5 -4
  30. package/dist/collection/components/bn-chart-time/bn-chart-time.js +11 -6
  31. package/dist/collection/components/bn-chart-time/ibcs-chart-time.js +47 -22
  32. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +76 -60
  33. package/dist/collection/components/bn-chart-time/utils/model/TimeChartComponentConfig.js +5 -4
  34. package/dist/collection/components/bn-chart-time/utils/model/TimeChartDataRow.js +2 -0
  35. package/dist/collection/components/bn-dataset/bn-dataset.js +214 -23
  36. package/dist/collection/components/bn-datasource/bn-datasource.js +27 -9
  37. package/dist/collection/components/bn-table/bn-table.js +13 -5
  38. package/dist/collection/components/bn-table/ibcs-table.js +52 -25
  39. package/dist/collection/components/bn-table/utils/Table.js +27 -21
  40. package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +2 -2
  41. package/dist/collection/components/bn-table/utils/helper/DataQuery.js +52 -43
  42. package/dist/collection/components/bn-table/utils/helper/QueryGroup.js +4 -9
  43. package/dist/collection/components/bn-table/utils/model/TableComponentConfig.js +5 -4
  44. package/dist/collection/components/editor-companion/editor-companion.js +12 -5
  45. package/dist/collection/context/scopedDb.js +113 -0
  46. package/dist/collection/stores/createScopedStores.js +3 -4
  47. package/dist/collection/utils/dataAnalyzer.js +14 -8
  48. package/dist/collection/utils/withBodyObserver.js +12 -7
  49. package/dist/collection/utils/withDataset.js +43 -39
  50. package/dist/collection/utils/withDatasource.js +28 -18
  51. package/dist/components/DataFormatDigits.js +1 -1
  52. package/dist/components/DateStringFactory.js +1 -1
  53. package/dist/components/Order.js +1 -1
  54. package/dist/components/SVGVariancesStyleGroup.js +1 -1
  55. package/dist/components/bn-chart-structure.js +1 -1
  56. package/dist/components/bn-chart-time.js +1 -1
  57. package/dist/components/bn-dataset.js +1 -1
  58. package/dist/components/bn-datasource.js +1 -1
  59. package/dist/components/bn-table.js +1 -1
  60. package/dist/components/bn-title2.js +1 -1
  61. package/dist/components/context-protocol.js +1 -1
  62. package/dist/components/editor-companion.js +1 -1
  63. package/dist/components/ibcs-chart-structure2.js +1 -1
  64. package/dist/components/ibcs-chart-time2.js +1 -1
  65. package/dist/components/ibcs-table2.js +1 -1
  66. package/dist/components/ibcs-title2.js +1 -1
  67. package/dist/components/ibcsRuleSet.js +1 -1
  68. package/dist/components/luxon.js +1 -0
  69. package/dist/components/scaling.js +1 -1
  70. package/dist/components/withBodyObserver.js +1 -1
  71. package/dist/esm/bn-asset_21.entry.js +571 -725
  72. package/dist/esm/bn-grid.entry.js +2 -2
  73. package/dist/esm/bn-image.entry.js +2 -2
  74. package/dist/esm/bn-internationalization.entry.js +2 -2
  75. package/dist/esm/bn-template-engine.js +1 -1
  76. package/dist/esm/bn-text.entry.js +3 -3
  77. package/dist/esm/bn-tree.entry.js +2 -2
  78. package/dist/esm/context-protocol-BDhzNbeD.js +9204 -0
  79. package/dist/esm/editor-companion.entry.js +13 -6
  80. package/dist/esm/loader.js +1 -1
  81. package/dist/esm/{scaling-BzbiBnuN.js → scaling-La1Ow72h.js} +44 -40
  82. package/dist/esm/{withBodyObserver-AFk2wwHT.js → withBodyObserver-IokS6fHD.js} +12 -7
  83. package/dist/esm/withStyled-Bl9cSoRW.js +1372 -0
  84. package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +4 -2
  85. package/dist/types/components/bn-chart-structure/ibcs-chart-structure.d.ts +7 -3
  86. package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +11 -12
  87. package/dist/types/components/bn-chart-structure/utils/model/StructureChartComponentConfig.d.ts +5 -3
  88. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +4 -2
  89. package/dist/types/components/bn-chart-time/ibcs-chart-time.d.ts +7 -3
  90. package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +11 -12
  91. package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +5 -3
  92. package/dist/types/components/bn-dataset/bn-dataset.d.ts +39 -5
  93. package/dist/types/components/bn-datasource/bn-datasource.d.ts +5 -0
  94. package/dist/types/components/bn-table/bn-table.d.ts +4 -2
  95. package/dist/types/components/bn-table/ibcs-table.d.ts +11 -3
  96. package/dist/types/components/bn-table/utils/Table.d.ts +8 -6
  97. package/dist/types/components/bn-table/utils/factories/tableDataSetFactory.d.ts +2 -2
  98. package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +7 -3
  99. package/dist/types/components/bn-table/utils/helper/QueryGroup.d.ts +4 -5
  100. package/dist/types/components/bn-table/utils/model/TableComponentConfig.d.ts +5 -3
  101. package/dist/types/components/editor-companion/editor-companion.d.ts +2 -0
  102. package/dist/types/components.d.ts +105 -46
  103. package/dist/types/context/context-protocol.d.ts +4 -3
  104. package/dist/types/context/scopedDb.d.ts +37 -0
  105. package/dist/types/stores/createScopedStores.d.ts +1 -2
  106. package/dist/types/utils/DateStringFactory.d.ts +1 -1
  107. package/dist/types/utils/dataAnalyzer.d.ts +2 -1
  108. package/dist/types/utils/withDataset.d.ts +6 -2
  109. package/dist/types/utils/withDatasource.d.ts +3 -3
  110. package/package.json +2 -1
  111. package/dist/bn-template-engine/p-095f74d7.entry.js +0 -1
  112. package/dist/bn-template-engine/p-14318b0d.entry.js +0 -1
  113. package/dist/bn-template-engine/p-2133e02b.entry.js +0 -1
  114. package/dist/bn-template-engine/p-7HSTE79g.js +0 -1
  115. package/dist/bn-template-engine/p-Bi2wx-el.js +0 -1
  116. package/dist/bn-template-engine/p-CWiZks2h.js +0 -1
  117. package/dist/bn-template-engine/p-DSXNgKLa.js +0 -1
  118. package/dist/cjs/context-protocol-B_jipZpJ.js +0 -665
  119. package/dist/cjs/withStyled-V7xz_x1c.js +0 -9535
  120. package/dist/collection/stores/datasets.js +0 -14
  121. package/dist/collection/stores/datasources.js +0 -14
  122. package/dist/components/_commonjsHelpers.js +0 -1
  123. package/dist/components/alasql.min.js +0 -1
  124. package/dist/esm/context-protocol-D-o_UZ33.js +0 -658
  125. package/dist/esm/withStyled-5RqF8WBL.js +0 -9501
  126. package/dist/types/stores/datasets.d.ts +0 -14
  127. package/dist/types/stores/datasources.d.ts +0 -14
@@ -221,7 +221,10 @@ export class Chart {
221
221
  }
222
222
  }
223
223
  constructor() {
224
- this.data = [];
224
+ /** Active dataset name (the last subscribed dataset to fire `onUpdate`). */
225
+ this.datasetName = "";
226
+ /** Bumped on every data update so Stencil re-renders even when the name is unchanged. */
227
+ this.dataVersion = 0;
225
228
  this.datasetMeta = null;
226
229
  this.appliedScaleFactor = 1;
227
230
  this.layoutObserver = null;
@@ -324,8 +327,9 @@ export class Chart {
324
327
  this._autoScaleGuard = false;
325
328
  withStyled(this);
326
329
  withComponentStatus(this);
327
- withDataset(this, (_name, data) => {
328
- this.data = (data || []);
330
+ withDataset(this, (name, _data) => {
331
+ this.datasetName = (name === null || name === void 0 ? void 0 : name.startsWith("$")) ? name.substring(1) : name || "";
332
+ this.dataVersion = this.dataVersion + 1;
329
333
  }, (_name, meta) => {
330
334
  this.datasetMeta = meta;
331
335
  });
@@ -791,7 +795,7 @@ export class Chart {
791
795
  const scenarios = this.prepareScenarios();
792
796
  // Dimension stacking uses only the first scenario
793
797
  const effectiveScenarios = (stackConfig === null || stackConfig === void 0 ? void 0 : stackConfig.by) === StackBy.DIMENSIONS ? scenarios.slice(0, 1) : scenarios;
794
- return (h("ibcs-chart-structure", { data: this.data, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideCategories: this.prepareHideCategories(idx), pixelPerUnit: ppu > 0 ? ppu * effectiveFactor : 0, pixelPerPercentage: ppp > 0 ? ppp * effectiveFactor : 0, limit: this.prepareLimit(), styles: this.prepareStyle(), i18n: this.prepareI18n(), order: this.prepareOrder(), level: this.prepareLevel(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(idx), stackConfig: stackConfig, parentDimensions: this.prepareDimension() }));
798
+ return (h("ibcs-chart-structure", { tableName: this.datasetName, dataVersion: this.dataVersion, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideCategories: this.prepareHideCategories(idx), pixelPerUnit: ppu > 0 ? ppu * effectiveFactor : 0, pixelPerPercentage: ppp > 0 ? ppp * effectiveFactor : 0, limit: this.prepareLimit(), styles: this.prepareStyle(), i18n: this.prepareI18n(), order: this.prepareOrder(), level: this.prepareLevel(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(idx), stackConfig: stackConfig, parentDimensions: this.prepareDimension() }));
795
799
  }
796
800
  getEffectiveScaleFactor() {
797
801
  const { mode, factor } = parseScaling(this.scale);
@@ -821,7 +825,7 @@ export class Chart {
821
825
  scenariosArray = [...scenariosArray, ...variancesArray];
822
826
  }
823
827
  const fontStyles = this.getFontStyles();
824
- return (h(Host, { key: '6e3c0b035ad3290f3b8ceb8ca7dc931ea30ae910', style: fontStyles }, h("div", { key: '89c5625eabe1b87648fba55f6642d7af0231449d', class: "container" }, scenariosArray.map(this.chartTemplate))));
828
+ return (h(Host, { key: '0af8bafa9e2e24eda4f09a9b1f9f9dfed9a34b0b', style: fontStyles }, h("div", { key: 'eb8b0337984e0207783b84d90438f0d32010fd21', class: "container" }, scenariosArray.map(this.chartTemplate))));
825
829
  }
826
830
  static get is() { return "bn-chart-structure"; }
827
831
  static get encapsulation() { return "shadow"; }
@@ -1234,7 +1238,8 @@ export class Chart {
1234
1238
  }
1235
1239
  static get states() {
1236
1240
  return {
1237
- "data": {},
1241
+ "datasetName": {},
1242
+ "dataVersion": {},
1238
1243
  "datasetMeta": {},
1239
1244
  "appliedScaleFactor": {}
1240
1245
  };
@@ -1,9 +1,11 @@
1
1
  import { h, Host } from "@stencil/core";
2
2
  import { StructureChart } from "./utils/StructureChart";
3
3
  import { CustomPattern } from "./utils/helper";
4
- import { StructureChartComponentConfigAdapter, } from "./utils/model";
4
+ import { StructureChartComponentConfigAdapter } from "./utils/model";
5
5
  import { StructureChartDataRowAdapter } from "./utils/model";
6
6
  import { ScaleFactorsStructureChartAdapter } from "./utils/model";
7
+ import { getStores } from "../../context/context-protocol";
8
+ import { buildFromExpr } from "../../context/scopedDb";
7
9
  //import { FontStyleAdapter } from "../../utils/model/styles/FontStyle";
8
10
  //import { SVGStyleGroupAdapter } from "../../utils/model/styles/SVGStyleGroup";
9
11
  //import { SVGVariancesStyleGroupAdapter } from "../../utils/model/styles/SVGVariancesStyleGroup";
@@ -24,7 +26,10 @@ import { SVGVariancesStyleGroupAdapter } from "../../utils/model/styles/SVGVaria
24
26
  //import { DataFormatDigitsAdapter } from "../../utils/model/DataFormatDigits";
25
27
  export class IbcsChartStructure {
26
28
  constructor() {
27
- this.data = [];
29
+ /** Name of the dataset (table or view in the shared alasql database). */
30
+ this.tableName = "";
31
+ /** Bumped by `bn-chart-structure` when the dataset changes; triggers re-render. */
32
+ this.dataVersion = 0;
28
33
  this.chartTitle = "";
29
34
  this.scenarios = [];
30
35
  this.variances = [];
@@ -46,6 +51,11 @@ export class IbcsChartStructure {
46
51
  this.stackConfig = null;
47
52
  this.parentDimensions = { width: 0, height: 0 };
48
53
  }
54
+ getDb() {
55
+ if (!this.stores)
56
+ this.stores = getStores(this.element);
57
+ return this.stores.db.db;
58
+ }
49
59
  render() {
50
60
  var _a, _b, _c;
51
61
  if (this.chart === undefined) {
@@ -59,9 +69,10 @@ export class IbcsChartStructure {
59
69
  }
60
70
  async componentWillLoad() {
61
71
  var _a;
72
+ const db = this.getDb();
62
73
  const config = this.prepareConfig();
63
74
  const styles = this.prepareStyle();
64
- this.chart = new StructureChart(new IBCSRuleSet(), config, styles);
75
+ this.chart = new StructureChart(new IBCSRuleSet(), db, this.tableName, config, styles);
65
76
  this.chart.setI18n(this.i18n);
66
77
  this.autoFitScaling(config, styles);
67
78
  this.chart.setAvailableWidth(((_a = this.parentDimensions) === null || _a === void 0 ? void 0 : _a.width) || 0);
@@ -98,12 +109,13 @@ export class IbcsChartStructure {
98
109
  return; // Both explicit — nothing to auto-fit
99
110
  }
100
111
  const targetWidth = (_a = this.parentDimensions) === null || _a === void 0 ? void 0 : _a.width;
112
+ const db = this.getDb();
101
113
  if (!targetWidth || targetWidth <= 0) {
102
114
  if (autoUnit)
103
115
  config.pixelPerUnit = 1;
104
116
  if (autoPercent)
105
117
  config.pixelPerPercentage = 50;
106
- this.chart = new StructureChart(new IBCSRuleSet(), config, styles);
118
+ this.chart = new StructureChart(new IBCSRuleSet(), db, this.tableName, config, styles);
107
119
  this.chart.setI18n(this.i18n);
108
120
  return;
109
121
  }
@@ -112,7 +124,7 @@ export class IbcsChartStructure {
112
124
  config.pixelPerUnit = 1;
113
125
  if (autoPercent)
114
126
  config.pixelPerPercentage = 1;
115
- this.chart = new StructureChart(new IBCSRuleSet(), config, styles);
127
+ this.chart = new StructureChart(new IBCSRuleSet(), db, this.tableName, config, styles);
116
128
  this.chart.setI18n(this.i18n);
117
129
  this.chart.toString();
118
130
  const svgWidth = this.chart.getAllocatedCanvasWidth();
@@ -137,7 +149,7 @@ export class IbcsChartStructure {
137
149
  config.pixelPerPercentage = (targetWidth * 0.9) / svgWidth;
138
150
  }
139
151
  // Second pass with the corrected scaling
140
- this.chart = new StructureChart(new IBCSRuleSet(), config, styles);
152
+ this.chart = new StructureChart(new IBCSRuleSet(), db, this.tableName, config, styles);
141
153
  this.chart.setI18n(this.i18n);
142
154
  }
143
155
  async componentWillRender() {
@@ -161,8 +173,9 @@ export class IbcsChartStructure {
161
173
  // }
162
174
  }
163
175
  prepareConfig() {
164
- return new StructureChartComponentConfigAdapter(new StructureChartDataRowAdapter(), new OrderAdapter(new StringAdapter()), new StringAdapter(), new DataFormatDigitsAdapter(), this.data).adapt({
165
- data: this.data,
176
+ const db = this.getDb();
177
+ const fromExpr = this.tableName ? buildFromExpr(this.tableName, this.filter) : "";
178
+ return new StructureChartComponentConfigAdapter(new StructureChartDataRowAdapter(), new OrderAdapter(new StringAdapter()), new StringAdapter(), new DataFormatDigitsAdapter(), db, fromExpr).adapt({
166
179
  scenarios: this.scenarios,
167
180
  variances: this.variances,
168
181
  title: this.chartTitle,
@@ -197,30 +210,45 @@ export class IbcsChartStructure {
197
210
  }
198
211
  static get properties() {
199
212
  return {
200
- "data": {
201
- "type": "unknown",
213
+ "tableName": {
214
+ "type": "string",
202
215
  "mutable": false,
203
216
  "complexType": {
204
- "original": "StructureChartDataRow[]",
205
- "resolved": "StructureChartDataRow[]",
206
- "references": {
207
- "StructureChartDataRow": {
208
- "location": "import",
209
- "path": "./utils/model",
210
- "id": "src/components/bn-chart-structure/utils/model/index.ts::StructureChartDataRow",
211
- "referenceLocation": "StructureChartDataRow"
212
- }
213
- }
217
+ "original": "string",
218
+ "resolved": "string",
219
+ "references": {}
214
220
  },
215
221
  "required": false,
216
222
  "optional": false,
217
223
  "docs": {
218
224
  "tags": [],
219
- "text": ""
225
+ "text": "Name of the dataset (table or view in the shared alasql database)."
220
226
  },
221
227
  "getter": false,
222
228
  "setter": false,
223
- "defaultValue": "[]"
229
+ "reflect": false,
230
+ "attribute": "table-name",
231
+ "defaultValue": "\"\""
232
+ },
233
+ "dataVersion": {
234
+ "type": "number",
235
+ "mutable": false,
236
+ "complexType": {
237
+ "original": "number",
238
+ "resolved": "number",
239
+ "references": {}
240
+ },
241
+ "required": false,
242
+ "optional": false,
243
+ "docs": {
244
+ "tags": [],
245
+ "text": "Bumped by `bn-chart-structure` when the dataset changes; triggers re-render."
246
+ },
247
+ "getter": false,
248
+ "setter": false,
249
+ "reflect": false,
250
+ "attribute": "data-version",
251
+ "defaultValue": "0"
224
252
  },
225
253
  "chartTitle": {
226
254
  "type": "string",
@@ -4,7 +4,6 @@ import { DataPoint, Scenario, } from "./model";
4
4
  // @ts-ignore
5
5
  import { Axis, HookLocation, Label, StackedBar } from "./elements";
6
6
  import { ScenarioFactory } from "./factories";
7
- import alasql from "alasql";
8
7
  import CalculateSize from "calculate-size";
9
8
  import { Formatter } from "../../../utils";
10
9
  import { AggregationLevel, StackBy, StackMode } from "../../../utils/constants";
@@ -13,6 +12,7 @@ import { IBCSRuleSet } from "../../../utils/ibcsRuleSet";
13
12
  import { VarianceScenario } from "../../../utils/model";
14
13
  import { OrderColumn } from "../../../utils/model/Order";
15
14
  import { SiPrefix } from "../../../utils/model/SiPrefix";
15
+ import { buildFromExpr } from "../../../context/scopedDb";
16
16
  /**
17
17
  * Orchestrates the full rendering pipeline for an IBCS structure (categorical) chart.
18
18
  *
@@ -35,7 +35,7 @@ import { SiPrefix } from "../../../utils/model/SiPrefix";
35
35
  * when bars exceed the container width.
36
36
  */
37
37
  export class StructureChart {
38
- constructor(ruleSet, config, styles) {
38
+ constructor(ruleSet, db, tableName, config, styles) {
39
39
  this.dataModel = [];
40
40
  this.variancesDataModel = [];
41
41
  this.title = "";
@@ -48,7 +48,6 @@ export class StructureChart {
48
48
  this.hideCategories = false;
49
49
  this.axisScenario = Scenario.AC1;
50
50
  this.CSS_CATEGORIES = "categories";
51
- this.preparedDataSet = [];
52
51
  this.state = FactoryState.DIRTY;
53
52
  this.titleLength = 0;
54
53
  this.leftSideOffsetForHorizontalSync = 0;
@@ -59,7 +58,10 @@ export class StructureChart {
59
58
  this.stackConfig = null;
60
59
  this.overflowConfig = null;
61
60
  this.highestStackedTotal = 0;
62
- this.initSQLFunctions();
61
+ this.fromExpr = "";
62
+ this.rowCount = 0;
63
+ this.db = db;
64
+ this.tableName = tableName;
63
65
  this.ruleSet = ruleSet || new IBCSRuleSet();
64
66
  this.i18n = this.createI18n(new Map());
65
67
  this.styles = styles;
@@ -78,11 +80,6 @@ export class StructureChart {
78
80
  }
79
81
  return new ElementPositions(new Padding(this.styles.padding), this.styles.scaleFactors, this.styles.fontStyles.size, this.dataModel.length, this.leftSideOffsetForHorizontalSync, this.titleLength, leftSideWidth, categoryWidth);
80
82
  }
81
- initSQLFunctions() {
82
- alasql.fn.transformOperator = function (a) {
83
- return a === "-" ? -1 : 1;
84
- };
85
- }
86
83
  setStyles(newStyle) {
87
84
  this.styles = newStyle;
88
85
  }
@@ -94,7 +91,7 @@ export class StructureChart {
94
91
  this.limit = config.limit;
95
92
  this.pixelPerUnit = config.pixelPerUnit || 1;
96
93
  this.pixelPerPercentage = config.pixelPerPercentage || 100;
97
- this.setData([...config.data], config.filter);
94
+ this.setSource(config.filter);
98
95
  this.dataModel = this.populateModel(config.scenarios, config.level, config.sortOrder);
99
96
  // Populate per-dimension stack segments when stacking by a data dimension
100
97
  if (config.stackConfig && config.stackConfig.by !== StackBy.SCENARIOS) {
@@ -174,31 +171,25 @@ export class StructureChart {
174
171
  return new Map([...defaultI18n, ...i18n]);
175
172
  }
176
173
  /**
177
- * Init load raw datasets the loaded dataset is
178
- * the base on which the filters defined in the config
179
- * are apllied on internaly it is called prepared DataSet
180
- *
181
- * @param data
182
- * @param filter - data filter
183
- * @param customColumnNameMap Custon ColumnNameMap can be used if data uses non standard columnames
174
+ * Resolves the dataset (a table or view in the shared alasql database) and
175
+ * caches its row count. All subsequent queries reference the source by name,
176
+ * so alasql doesn't have to ingest a fresh array per call.
184
177
  */
185
- setData(data, filter) {
186
- if (data == null) {
178
+ setSource(filter) {
179
+ var _a, _b;
180
+ this.state = FactoryState.DIRTY;
181
+ if (!this.tableName) {
182
+ this.fromExpr = "";
183
+ this.rowCount = 0;
187
184
  return;
188
185
  }
189
- this.state = FactoryState.DIRTY; // mark dataSet for update
190
- this.preparedDataSet.length = 0; // cleans formerly loaded and prepared dataset
191
- if (filter != null && filter.length > 0) {
192
- try {
193
- this.preparedDataSet = alasql(`SELECT * FROM ? WHERE ${filter}`, [data]);
194
- }
195
- catch (e) {
196
- console.error("StructureChart: filter query failed, using unfiltered data", filter, e);
197
- this.preparedDataSet = data;
198
- }
186
+ this.fromExpr = buildFromExpr(this.tableName, filter);
187
+ try {
188
+ const r = this.db.exec(`SELECT COUNT(*) AS cnt FROM ${this.fromExpr}`);
189
+ this.rowCount = ((_b = (_a = r[0]) === null || _a === void 0 ? void 0 : _a.cnt) !== null && _b !== void 0 ? _b : 0);
199
190
  }
200
- else {
201
- this.preparedDataSet = data;
191
+ catch (_e) {
192
+ this.rowCount = 0;
202
193
  }
203
194
  }
204
195
  /**
@@ -308,25 +299,31 @@ export class StructureChart {
308
299
  return result;
309
300
  }
310
301
  populateModel(selectedScenarios, level, sortOrder) {
311
- var _a;
312
- if (((_a = this.preparedDataSet) === null || _a === void 0 ? void 0 : _a.length) === 0) {
302
+ if (this.rowCount === 0 || !this.fromExpr) {
313
303
  return [];
314
304
  }
315
305
  const dataModel = [];
316
306
  const orderStr = this.createOrderStr(level, sortOrder);
317
307
  const select = this.createSelectString(level, sortOrder);
318
308
  const groupByStr = this.createGroupByStr(level, sortOrder);
319
- const result = alasql(`SELECT ${select} ${selectedScenarios.length > 0
320
- ? "," +
321
- selectedScenarios
322
- .map((scenario) => {
323
- return `SUM(${scenario} * transformOperator(operation)) as ${scenario}, COUNT(ISNULL(${scenario})) as ${scenario}_cnt`;
324
- })
325
- .join(",")
326
- : ""}
327
- FROM ?
309
+ let result;
310
+ try {
311
+ result = this.db.exec(`SELECT ${select} ${selectedScenarios.length > 0
312
+ ? "," +
313
+ selectedScenarios
314
+ .map((scenario) => {
315
+ return `SUM(${scenario} * transformOperator(operation)) as ${scenario}, COUNT(ISNULL(${scenario})) as ${scenario}_cnt`;
316
+ })
317
+ .join(",")
318
+ : ""}
319
+ FROM ${this.fromExpr}
328
320
  GROUP BY ${groupByStr}
329
- ORDER BY ${orderStr}`, [this.preparedDataSet]);
321
+ ORDER BY ${orderStr}`);
322
+ }
323
+ catch (e) {
324
+ console.error("StructureChart: populateModel query failed", e);
325
+ return [];
326
+ }
330
327
  this.detectNaNCells(selectedScenarios, result);
331
328
  this.createDataRows(result, dataModel, selectedScenarios);
332
329
  this.crateRESTRow(result, selectedScenarios, dataModel);
@@ -944,8 +941,7 @@ export class StructureChart {
944
941
  * at the stack dimension level and attach stackSegments to each dataModel row.
945
942
  */
946
943
  populateDimensionStackSegments(scenarios, _stackConfig, level) {
947
- var _a;
948
- if (((_a = this.preparedDataSet) === null || _a === void 0 ? void 0 : _a.length) === 0 || scenarios.length === 0)
944
+ if (this.rowCount === 0 || !this.fromExpr || scenarios.length === 0)
949
945
  return;
950
946
  // Derive stack column from level: stack by the next-lower hierarchy dimension
951
947
  const nextLowerDimension = {
@@ -960,9 +956,16 @@ export class StructureChart {
960
956
  // The display level column (what each bar represents)
961
957
  const displayColumn = level.toString(); // e.g. 'rowGroup', 'category', 'subCategory'
962
958
  const scenario = scenarios[0]; // dimension stacking uses first scenario
963
- const result = alasql(`SELECT [${displayColumn}] as displayGroup, [${stackColumn}] as stackLabel, ` +
964
- `SUM([${scenario}] * transformOperator(operation)) as stackValue ` +
965
- `FROM ? GROUP BY [${displayColumn}], [${stackColumn}]`, [this.preparedDataSet]);
959
+ let result;
960
+ try {
961
+ result = this.db.exec(`SELECT [${displayColumn}] as displayGroup, [${stackColumn}] as stackLabel, ` +
962
+ `SUM([${scenario}] * transformOperator(operation)) as stackValue ` +
963
+ `FROM ${this.fromExpr} GROUP BY [${displayColumn}], [${stackColumn}]`);
964
+ }
965
+ catch (e) {
966
+ console.error("StructureChart: dimension-stack query failed", e);
967
+ return;
968
+ }
966
969
  // Group results by displayGroup
967
970
  const groupMap = new Map();
968
971
  for (const row of result) {
@@ -41,15 +41,16 @@ export class StructureChartComponentConfig {
41
41
  /**
42
42
  * Converts untyped JSON into a validated {@link StructureChartComponentConfig}.
43
43
  *
44
- * Requires the raw dataset for measure scale auto-calculation.
44
+ * Reads from the shared alasql database for measure-scale auto-calculation.
45
45
  */
46
46
  export class StructureChartComponentConfigAdapter {
47
- constructor(dataRowAdapter, orderAdapter, stringAdapter, dataFormatDigitsAdapter, dataSet) {
47
+ constructor(dataRowAdapter, orderAdapter, stringAdapter, dataFormatDigitsAdapter, db, fromExpr) {
48
48
  this.dataRowAdapter = dataRowAdapter;
49
49
  this.orderAdapter = orderAdapter;
50
50
  this.stringAdapter = stringAdapter;
51
51
  this.dataFormatDigitsAdapter = dataFormatDigitsAdapter;
52
- this.dataSet = dataSet;
52
+ this.db = db;
53
+ this.fromExpr = fromExpr;
53
54
  }
54
55
  adapt(data) {
55
56
  const dataSet = AdapterUtils.adaptArray(data.data, this.dataRowAdapter);
@@ -84,7 +85,7 @@ export class StructureChartComponentConfigAdapter {
84
85
  config.filter = data.filter.trim();
85
86
  }
86
87
  if (CompareUtil.isExisting(data.measureScale)) {
87
- config.measureScale = DataAnalyzer.calculateMeasureScale(this.dataSet, config.scenarios, data.measureScale);
88
+ config.measureScale = DataAnalyzer.calculateMeasureScale(this.db, this.fromExpr, config.scenarios, data.measureScale);
88
89
  }
89
90
  if (CompareUtil.isString(data.measureUnit)) {
90
91
  config.measureUnit = data.measureUnit;
@@ -339,7 +339,10 @@ export class Chart {
339
339
  }
340
340
  }
341
341
  constructor() {
342
- this.data = [];
342
+ /** Active dataset name (the last subscribed dataset to fire `onUpdate`). */
343
+ this.datasetName = "";
344
+ /** Bumped on every data update so Stencil re-renders even when the name is unchanged. */
345
+ this.dataVersion = 0;
343
346
  this.datasetMeta = null;
344
347
  this.appliedScaleFactor = 1;
345
348
  this.layoutObserver = null;
@@ -482,8 +485,9 @@ export class Chart {
482
485
  this._lastObservedWidth = 0;
483
486
  withStyled(this);
484
487
  withComponentStatus(this);
485
- withDataset(this, (_name, data) => {
486
- this.data = (data || []);
488
+ withDataset(this, (name, _data) => {
489
+ this.datasetName = (name === null || name === void 0 ? void 0 : name.startsWith("$")) ? name.substring(1) : name || "";
490
+ this.dataVersion = this.dataVersion + 1;
487
491
  }, (_name, meta) => {
488
492
  this.datasetMeta = meta;
489
493
  });
@@ -992,7 +996,7 @@ export class Chart {
992
996
  const stackConfig = this.prepareStackConfig();
993
997
  const scenarios = this.prepareScenarios();
994
998
  const effectiveScenarios = (stackConfig === null || stackConfig === void 0 ? void 0 : stackConfig.by) === StackBy.DIMENSIONS ? scenarios.slice(0, 1) : scenarios;
995
- return (h("ibcs-chart-time", { data: this.data, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideAxisLabels: this.prepareHideAxisLabels(idx), pixelPerUnit: ppu > 0 ? ppu * effectiveFactor : 0, pixelPerPercentage: ppp > 0 ? ppp * effectiveFactor : 0, limit: this.prepareLimit(), leftSideOffsetForHorizontalSync: this.prepareLeftSideOffset(preparedI18n, preparedStyle), styles: preparedStyle, i18n: preparedI18n, order: this.prepareOrder(), level: this.prepareLevel(), dateInterval: this.prepareDateInterval(), intervalSpanLimit: this.prepareIntervalSpanLimit(), axisLabelsMode: this.prepareAxisLabelsMode(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showOverlayAvg: this.prepareAvg(), showOverlayMedian: this.prepareMedian(), showMeasureScale: this.prepareShowMeasureScale(idx), chartMode: this.prepareChartMode(), maxBars: this.prepareMaxBars(), stackConfig: stackConfig, lineFullWidth: this.prepareLineFullWidth(), containerWidth: fullParentWidth, parentDimensions: this.prepareDimension() }));
999
+ return (h("ibcs-chart-time", { tableName: this.datasetName, dataVersion: this.dataVersion, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideAxisLabels: this.prepareHideAxisLabels(idx), pixelPerUnit: ppu > 0 ? ppu * effectiveFactor : 0, pixelPerPercentage: ppp > 0 ? ppp * effectiveFactor : 0, limit: this.prepareLimit(), leftSideOffsetForHorizontalSync: this.prepareLeftSideOffset(preparedI18n, preparedStyle), styles: preparedStyle, i18n: preparedI18n, order: this.prepareOrder(), level: this.prepareLevel(), dateInterval: this.prepareDateInterval(), intervalSpanLimit: this.prepareIntervalSpanLimit(), axisLabelsMode: this.prepareAxisLabelsMode(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showOverlayAvg: this.prepareAvg(), showOverlayMedian: this.prepareMedian(), showMeasureScale: this.prepareShowMeasureScale(idx), chartMode: this.prepareChartMode(), maxBars: this.prepareMaxBars(), stackConfig: stackConfig, lineFullWidth: this.prepareLineFullWidth(), containerWidth: fullParentWidth, parentDimensions: this.prepareDimension() }));
996
1000
  }
997
1001
  getEffectiveScaleFactor() {
998
1002
  const { mode, factor } = parseScaling(this.scale);
@@ -1022,7 +1026,7 @@ export class Chart {
1022
1026
  scenariosArray = [...scenariosArray, ...variancesArray];
1023
1027
  }
1024
1028
  const fontStyles = this.getFontStyles();
1025
- return (h(Host, { key: 'b061b712f63444756de97d0e393ae6a5add489de', style: fontStyles }, h("div", { key: '8fadffb1b89d6dd3588028cb500f844a4ff8c5fa', class: "container" }, scenariosArray.map(this.chartTemplate))));
1029
+ return (h(Host, { key: 'fbef96ebdfa241564095c6def748082bfec0e6a4', style: fontStyles }, h("div", { key: '77d3168f126a779db1e0fbeed2f8a220a2f36792', class: "container" }, scenariosArray.map(this.chartTemplate))));
1026
1030
  }
1027
1031
  static get is() { return "bn-chart-time"; }
1028
1032
  static get encapsulation() { return "shadow"; }
@@ -1556,7 +1560,8 @@ export class Chart {
1556
1560
  }
1557
1561
  static get states() {
1558
1562
  return {
1559
- "data": {},
1563
+ "datasetName": {},
1564
+ "dataVersion": {},
1560
1565
  "datasetMeta": {},
1561
1566
  "appliedScaleFactor": {}
1562
1567
  };
@@ -3,6 +3,8 @@ import { TimeChart } from "./utils/TimeChart";
3
3
  import { CustomPattern } from "./utils/helper";
4
4
  import { TimeChartComponentConfigAdapter, } from "./utils/model/TimeChartComponentConfig";
5
5
  import { TimeChartDataRowAdapter } from "./utils/model/TimeChartDataRow";
6
+ import { getStores } from "../../context/context-protocol";
7
+ import { buildFromExpr } from "../../context/scopedDb";
6
8
  import { TimeChartStylesAdapter } from "./utils/model/styles/TimeChartStyle";
7
9
  import { ScaleFactorsTimeChartAdapter } from "./utils/model/styles/ScaleFactorsTimeChart";
8
10
  import { DateDistance } from "../../utils/DateStringFactory";
@@ -18,8 +20,10 @@ import { SVGStyleGroupAdapter } from "../../utils/model/styles/SVGStyleGroup";
18
20
  import { SVGVariancesStyleGroupAdapter } from "../../utils/model/styles/SVGVariancesStyleGroup";
19
21
  export class IbcsChartTime {
20
22
  constructor() {
21
- // @Prop() dimension: { height: number, width: number } = {height: 400, width: 450};
22
- this.data = [];
23
+ /** Name of the dataset (table or view in the shared alasql database). */
24
+ this.tableName = "";
25
+ /** Bumped by `bn-chart-time` when the dataset changes; triggers re-render. */
26
+ this.dataVersion = 0;
23
27
  this.scenarios = [];
24
28
  this.variances = []; //["dfc_ac_neg"]
25
29
  this.hideAxisLabels = false; //false
@@ -50,6 +54,11 @@ export class IbcsChartTime {
50
54
  this.dataFormatDigits = { percent: 2, decimal: 1 };
51
55
  this.parentDimensions = { width: 0, height: 0 };
52
56
  }
57
+ getDb() {
58
+ if (!this.stores)
59
+ this.stores = getStores(this.element);
60
+ return this.stores.db.db;
61
+ }
53
62
  render() {
54
63
  var _a, _b, _c;
55
64
  if (this.chart === undefined) {
@@ -66,7 +75,7 @@ export class IbcsChartTime {
66
75
  const config = this.prepareConfig();
67
76
  const styles = this.prepareStyle();
68
77
  const availableWidth = this.containerWidth || 0;
69
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
78
+ this.chart = new TimeChart(new IBCSRuleSet(), this.getDb(), this.tableName, config, styles, availableWidth);
70
79
  this.chart.setI18n(this.i18n);
71
80
  this.autoFitScaling(config, styles);
72
81
  this.chart.setAvailableHeight(((_a = this.parentDimensions) === null || _a === void 0 ? void 0 : _a.height) || 0);
@@ -109,7 +118,7 @@ export class IbcsChartTime {
109
118
  config.pixelPerUnit = 1;
110
119
  if (autoPercent)
111
120
  config.pixelPerPercentage = 50;
112
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
121
+ this.chart = new TimeChart(new IBCSRuleSet(), this.getDb(), this.tableName, config, styles, availableWidth);
113
122
  this.chart.setI18n(this.i18n);
114
123
  return;
115
124
  }
@@ -118,7 +127,7 @@ export class IbcsChartTime {
118
127
  config.pixelPerUnit = 1;
119
128
  if (autoPercent)
120
129
  config.pixelPerPercentage = 1;
121
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
130
+ this.chart = new TimeChart(new IBCSRuleSet(), this.getDb(), this.tableName, config, styles, availableWidth);
122
131
  this.chart.setI18n(this.i18n);
123
132
  this.chart.toString();
124
133
  const svgHeight = this.chart.getAllocatedCanvasHeight();
@@ -132,7 +141,7 @@ export class IbcsChartTime {
132
141
  if (autoPercent)
133
142
  config.pixelPerPercentage = ratio;
134
143
  // Second pass with the corrected scaling
135
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
144
+ this.chart = new TimeChart(new IBCSRuleSet(), this.getDb(), this.tableName, config, styles, availableWidth);
136
145
  this.chart.setI18n(this.i18n);
137
146
  }
138
147
  async componentWillRender() {
@@ -156,8 +165,9 @@ export class IbcsChartTime {
156
165
  //}
157
166
  }
158
167
  prepareConfig() {
159
- return new TimeChartComponentConfigAdapter(new TimeChartDataRowAdapter(), new OrderAdapter(new StringAdapter()), new StringAdapter(), new DataFormatDigitsAdapter(), this.data).adapt({
160
- data: this.data,
168
+ const db = this.getDb();
169
+ const fromExpr = this.tableName ? buildFromExpr(this.tableName, this.filter) : "";
170
+ return new TimeChartComponentConfigAdapter(new TimeChartDataRowAdapter(), new OrderAdapter(new StringAdapter()), new StringAdapter(), new DataFormatDigitsAdapter(), db, fromExpr).adapt({
161
171
  scenarios: this.scenarios,
162
172
  variances: this.variances,
163
173
  title: this.chartTitle,
@@ -201,30 +211,45 @@ export class IbcsChartTime {
201
211
  }
202
212
  static get properties() {
203
213
  return {
204
- "data": {
205
- "type": "unknown",
214
+ "tableName": {
215
+ "type": "string",
206
216
  "mutable": false,
207
217
  "complexType": {
208
- "original": "TimeChartDataRow[]",
209
- "resolved": "TimeChartDataRow[]",
210
- "references": {
211
- "TimeChartDataRow": {
212
- "location": "import",
213
- "path": "./utils/model/TimeChartDataRow",
214
- "id": "src/components/bn-chart-time/utils/model/TimeChartDataRow.ts::TimeChartDataRow",
215
- "referenceLocation": "TimeChartDataRow"
216
- }
217
- }
218
+ "original": "string",
219
+ "resolved": "string",
220
+ "references": {}
218
221
  },
219
222
  "required": false,
220
223
  "optional": false,
221
224
  "docs": {
222
225
  "tags": [],
223
- "text": ""
226
+ "text": "Name of the dataset (table or view in the shared alasql database)."
224
227
  },
225
228
  "getter": false,
226
229
  "setter": false,
227
- "defaultValue": "[]"
230
+ "reflect": false,
231
+ "attribute": "table-name",
232
+ "defaultValue": "\"\""
233
+ },
234
+ "dataVersion": {
235
+ "type": "number",
236
+ "mutable": false,
237
+ "complexType": {
238
+ "original": "number",
239
+ "resolved": "number",
240
+ "references": {}
241
+ },
242
+ "required": false,
243
+ "optional": false,
244
+ "docs": {
245
+ "tags": [],
246
+ "text": "Bumped by `bn-chart-time` when the dataset changes; triggers re-render."
247
+ },
248
+ "getter": false,
249
+ "setter": false,
250
+ "reflect": false,
251
+ "attribute": "data-version",
252
+ "defaultValue": "0"
228
253
  },
229
254
  "chartTitle": {
230
255
  "type": "string",