@bino-bi/bn-template-engine 1.0.0-alpha.13 → 1.0.0-alpha.15

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 (93) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/{p-637e3b8f.entry.js → p-19f49fbc.entry.js} +1 -1
  3. package/dist/bn-template-engine/p-209b3fd9.entry.js +1 -0
  4. package/dist/bn-template-engine/{p-67eae33e.entry.js → p-3465fcdc.entry.js} +1 -1
  5. package/dist/bn-template-engine/{p-82023539.entry.js → p-67746414.entry.js} +1 -1
  6. package/dist/bn-template-engine/p-BPDZcex5.js +1 -0
  7. package/dist/bn-template-engine/{p-DHheVOfP.js → p-Tx6omDWp.js} +1 -1
  8. package/dist/bn-template-engine/{p-52097456.entry.js → p-d724ab88.entry.js} +1 -1
  9. package/dist/bn-template-engine/p-efd3b67a.entry.js +1 -0
  10. package/dist/bn-template-engine/{p-46699464.entry.js → p-ff659485.entry.js} +1 -1
  11. package/dist/bn-template-engine/p-z9bPNFYF.js +1 -0
  12. package/dist/cjs/bn-asset_21.cjs.entry.js +348 -75
  13. package/dist/cjs/bn-grid.cjs.entry.js +2 -2
  14. package/dist/cjs/bn-image.cjs.entry.js +2 -2
  15. package/dist/cjs/bn-internationalization.cjs.entry.js +1 -1
  16. package/dist/cjs/bn-template-engine.cjs.js +1 -1
  17. package/dist/cjs/bn-text.cjs.entry.js +3 -3
  18. package/dist/cjs/bn-tree.cjs.entry.js +2 -2
  19. package/dist/cjs/{context-protocol-Op7uUwN3.js → context-protocol-Cn5PL928.js} +14 -0
  20. package/dist/cjs/editor-companion.cjs.entry.js +1 -1
  21. package/dist/cjs/loader.cjs.js +1 -1
  22. package/dist/cjs/{scaling-57N4Cxb_.js → scaling-DM2UILdF.js} +58 -17
  23. package/dist/cjs/{withStyled-C2kmGAK3.js → withStyled-Dx3uRw9g.js} +72 -1
  24. package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +28 -10
  25. package/dist/collection/components/bn-chart-structure/utils/helper/ElementPositions.js +46 -4
  26. package/dist/collection/components/bn-chart-time/bn-chart-time.js +39 -1
  27. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +40 -10
  28. package/dist/collection/components/bn-dataset/bn-dataset.js +25 -13
  29. package/dist/collection/components/bn-datasource/bn-datasource.js +23 -12
  30. package/dist/collection/components/bn-layout-card/bn-layout-card.css +5 -0
  31. package/dist/collection/components/bn-layout-card/bn-layout-card.js +6 -3
  32. package/dist/collection/components/bn-layout-page/bn-layout-page.css +5 -0
  33. package/dist/collection/components/bn-layout-page/bn-layout-page.js +6 -3
  34. package/dist/collection/components/bn-table/bn-table.js +75 -7
  35. package/dist/collection/components/bn-table/ibcs-table.js +27 -0
  36. package/dist/collection/components/bn-table/utils/Table.js +2 -2
  37. package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +28 -5
  38. package/dist/collection/components/bn-table/utils/helper/DataQuery.js +46 -6
  39. package/dist/collection/components/bn-table/utils/model/TableAttribute.js +46 -0
  40. package/dist/collection/components/bn-table/utils/model/TableComponentConfig.js +5 -0
  41. package/dist/collection/context/scopedDb.js +14 -0
  42. package/dist/collection/utils/parentDimensions.js +57 -16
  43. package/dist/collection/utils/validate.js +23 -0
  44. package/dist/components/DateStringFactory.js +1 -1
  45. package/dist/components/Order.js +1 -1
  46. package/dist/components/bn-chart-structure.js +1 -1
  47. package/dist/components/bn-chart-time.js +1 -1
  48. package/dist/components/bn-dataset.js +1 -1
  49. package/dist/components/bn-datasource.js +1 -1
  50. package/dist/components/bn-layout-card.js +1 -1
  51. package/dist/components/bn-layout-page.js +1 -1
  52. package/dist/components/bn-table.js +1 -1
  53. package/dist/components/bn-title2.js +1 -1
  54. package/dist/components/context-protocol.js +1 -1
  55. package/dist/components/ibcs-chart-structure2.js +1 -1
  56. package/dist/components/ibcs-chart-time2.js +1 -1
  57. package/dist/components/ibcs-table2.js +1 -1
  58. package/dist/components/ibcs-title2.js +1 -1
  59. package/dist/components/scaling.js +1 -1
  60. package/dist/components/validate.js +1 -1
  61. package/dist/esm/bn-asset_21.entry.js +348 -75
  62. package/dist/esm/bn-grid.entry.js +2 -2
  63. package/dist/esm/bn-image.entry.js +2 -2
  64. package/dist/esm/bn-internationalization.entry.js +1 -1
  65. package/dist/esm/bn-template-engine.js +1 -1
  66. package/dist/esm/bn-text.entry.js +3 -3
  67. package/dist/esm/bn-tree.entry.js +2 -2
  68. package/dist/esm/{context-protocol-BDhzNbeD.js → context-protocol-BB-4Onmw.js} +14 -0
  69. package/dist/esm/editor-companion.entry.js +1 -1
  70. package/dist/esm/loader.js +1 -1
  71. package/dist/esm/{scaling-La1Ow72h.js → scaling-h4KcBet3.js} +58 -17
  72. package/dist/esm/{withStyled-Bl9cSoRW.js → withStyled-BBvU2f-A.js} +71 -2
  73. package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +4 -0
  74. package/dist/types/components/bn-chart-structure/utils/helper/ElementPositions.d.ts +16 -1
  75. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +13 -0
  76. package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +4 -0
  77. package/dist/types/components/bn-dataset/bn-dataset.d.ts +15 -7
  78. package/dist/types/components/bn-datasource/bn-datasource.d.ts +13 -6
  79. package/dist/types/components/bn-layout-card/bn-layout-card.d.ts +1 -0
  80. package/dist/types/components/bn-layout-page/bn-layout-page.d.ts +1 -0
  81. package/dist/types/components/bn-table/bn-table.d.ts +13 -0
  82. package/dist/types/components/bn-table/ibcs-table.d.ts +2 -0
  83. package/dist/types/components/bn-table/utils/factories/tableDataSetFactory.d.ts +3 -1
  84. package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +11 -0
  85. package/dist/types/components/bn-table/utils/model/TableAttribute.d.ts +22 -0
  86. package/dist/types/components/bn-table/utils/model/TableComponentConfig.d.ts +3 -0
  87. package/dist/types/components.d.ts +45 -20
  88. package/dist/types/utils/validate.d.ts +6 -0
  89. package/package.json +1 -1
  90. package/dist/bn-template-engine/p-3c827826.entry.js +0 -1
  91. package/dist/bn-template-engine/p-BVFHvEXF.js +0 -1
  92. package/dist/bn-template-engine/p-CQnZV3JG.js +0 -1
  93. package/dist/bn-template-engine/p-ab3ea8cf.entry.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import { forceUpdate, h, Host, writeTask } from "@stencil/core";
2
- import { isBlankInput, isTableBarColumnWidth, isTableCategoryWidth, isValidBoolean, isValidDataFormat, isValidDirection, isValidInteger, isValidMeasureScale, isValidMeasureType, isValidNumber, isValidTableType, validateColumnThereOfJsonStr, validateOrderList, validatePartOfJsonStr, validateScenarioList, validateThereOfJsonStr, validateVariancesList, } from "../../utils/validate";
2
+ import { isBlankInput, isTableBarColumnWidth, isTableCategoryWidth, isValidBoolean, isValidDataFormat, isValidDirection, isValidInteger, isValidMeasureScale, isValidMeasureType, isValidNumber, isValidTableType, validateAttributesJsonStr, validateColumnThereOfJsonStr, validateOrderList, validatePartOfJsonStr, validateScenarioList, validateThereOfJsonStr, validateVariancesList, } from "../../utils/validate";
3
3
  import withDataset from "../../utils/withDataset";
4
4
  import withComponentStatus from "../../utils/withComponentStatus";
5
5
  import withScalingGroup from "../../utils/withScalingGroup";
@@ -14,6 +14,7 @@ import { parseScaling } from "../../utils/scaling";
14
14
  import { observeParentResize } from "../../utils/layoutObserver";
15
15
  import { BAR_COLUMN_WIDTH_EM, DataFormat, I18nMode, MeasureType, TableBarColumnWidth, TableCategoryWidth, } from "../../utils/constants";
16
16
  import { TableType } from "./utils/model";
17
+ import { parseTableAttributeExpression } from "./utils/model/TableAttribute";
17
18
  import { OrderColumn, OrderDirection } from "../../utils/model/Order";
18
19
  /**
19
20
  * Public-facing wrapper for the IBCS table component.
@@ -270,6 +271,17 @@ export class Table {
270
271
  * ```
271
272
  */
272
273
  this.columnthereof = null;
274
+ /**
275
+ * Stringified JSON object defining custom columns computed from dataset fields.<br />
276
+ * Keys are column labels, values are aggregate expressions over the rows that
277
+ * make up each table row.<br /><br />
278
+ * Functions: ```set // first // last // min // max // avg // sum // lit```<br />
279
+ * Fields can be standard dataset fields (e.g. ```ac1```) or custom fields
280
+ * prefixed with ```_``` (e.g. ```_leiter```); ```lit``` takes a constant value.<br /><br />
281
+ * example:<br />
282
+ * ```{"Verkaufsleiter": "set(_leiter)", "Umsatz gesamt": "sum(ac1)"}```
283
+ */
284
+ this.tableAttributes = "";
273
285
  this._autoScaleGuard = false;
274
286
  withStyled(this);
275
287
  withComponentStatus(this);
@@ -608,6 +620,20 @@ export class Table {
608
620
  this.errors.remove(errId);
609
621
  }
610
622
  }
623
+ validateTableAttributes(newValue) {
624
+ const errId = "ERR_attributes";
625
+ const invalidElements = validateAttributesJsonStr(newValue);
626
+ if (invalidElements.length > 0) {
627
+ this.errors.addOrReplace({
628
+ id: errId,
629
+ type: "warning",
630
+ message: "attributes: invalid value(s) '" + JSON.stringify(invalidElements) + "' are not supported.",
631
+ });
632
+ }
633
+ else {
634
+ this.errors.remove(errId);
635
+ }
636
+ }
611
637
  componentWillLoad() {
612
638
  this.validateScenario(this.scenarios);
613
639
  this.validateVariances(this.variances);
@@ -626,6 +652,7 @@ export class Table {
626
652
  this.validateMeasureType(this.measureType);
627
653
  this.validateMeasureScale(this.measureScale);
628
654
  this.validateColumnThereOf(this.columnthereof);
655
+ this.validateTableAttributes(this.tableAttributes);
629
656
  this.validateShowMeasureScale(this.showMeasureScale);
630
657
  this.validateBarColumns(this.barColumns);
631
658
  this.validateBarColumnWidth(this.barColumnWidth);
@@ -774,7 +801,7 @@ export class Table {
774
801
  return formatDigits;
775
802
  }
776
803
  prepareScenarios() {
777
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
804
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k;
778
805
  const inheritedScenarios = this.resolveInherited("scenarios", this.scenarios);
779
806
  const inheritedVariances = this.resolveInherited("variances", this.variances);
780
807
  if (inheritedScenarios !== undefined || inheritedVariances !== undefined) {
@@ -813,7 +840,7 @@ export class Table {
813
840
  }
814
841
  let scenarios = [];
815
842
  if (isAuto || isBlankInput(this.scenarios)) {
816
- if (((_f = (_e = this.datasetMeta) === null || _e === void 0 ? void 0 : _e.availableScenarios) === null || _f === void 0 ? void 0 : _f.length) > 0) {
843
+ if (((_g = (_f = this.datasetMeta) === null || _f === void 0 ? void 0 : _f.availableScenarios) === null || _g === void 0 ? void 0 : _g.length) > 0) {
817
844
  if (!isAuto) {
818
845
  this.errors.addOrReplace({
819
846
  id: "AUTO_scenarios",
@@ -829,10 +856,10 @@ export class Table {
829
856
  }
830
857
  else {
831
858
  this.errors.remove("AUTO_scenarios");
832
- scenarios = scenarios.concat((_g = this.scenarios) === null || _g === void 0 ? void 0 : _g.split(","));
859
+ scenarios = scenarios.concat((_h = this.scenarios) === null || _h === void 0 ? void 0 : _h.split(","));
833
860
  }
834
- if (((_h = this.variances) === null || _h === void 0 ? void 0 : _h.trim().length) > 0) {
835
- scenarios = scenarios.concat((_j = this.variances) === null || _j === void 0 ? void 0 : _j.split(","));
861
+ if (((_j = this.variances) === null || _j === void 0 ? void 0 : _j.trim().length) > 0) {
862
+ scenarios = scenarios.concat((_k = this.variances) === null || _k === void 0 ? void 0 : _k.split(","));
836
863
  }
837
864
  return scenarios.map((entry) => entry.trim());
838
865
  }
@@ -876,6 +903,24 @@ export class Table {
876
903
  }
877
904
  return map;
878
905
  }
906
+ prepareAttributes() {
907
+ if (this.tableAttributes == null || this.tableAttributes.trim() === "") {
908
+ return [];
909
+ }
910
+ try {
911
+ const parsedString = JSON.parse(this.tableAttributes);
912
+ if (parsedString === null || typeof parsedString !== "object" || parsedString instanceof Array) {
913
+ return [];
914
+ }
915
+ return Object.entries(parsedString)
916
+ .map(([label, expression], index) => typeof expression === "string" ? parseTableAttributeExpression(label, `attr_${index}`, expression) : null)
917
+ .filter((attribute) => attribute !== null);
918
+ }
919
+ catch (_e) {
920
+ // invalid JSON already reported by validateTableAttributes
921
+ return [];
922
+ }
923
+ }
879
924
  prepareTableTitle() {
880
925
  if (this.tableTitle === "" || this.tableTitle == null) {
881
926
  return "SUM_TOTAL";
@@ -993,7 +1038,7 @@ export class Table {
993
1038
  render() {
994
1039
  const fontStyles = this.getFontStyles();
995
1040
  const effectiveFactor = this.getEffectiveScaleFactor();
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 }))));
1041
+ return (h(Host, { key: 'ed9804ea731fbaa0ec730c0392bcd18bb0ac278a', style: fontStyles }, h("div", { key: '011a543cca60ec8c871db6a6280999047437ce98' }, h("ibcs-table", { key: '4b7d717c3a7c9ed4c44b90dc66b4b8e6c9359cb0', 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(), attributeColumns: this.prepareAttributes(), 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 }))));
997
1042
  }
998
1043
  static get is() { return "bn-table"; }
999
1044
  static get encapsulation() { return "shadow"; }
@@ -1539,6 +1584,26 @@ export class Table {
1539
1584
  "reflect": false,
1540
1585
  "attribute": "columnthereof",
1541
1586
  "defaultValue": "null"
1587
+ },
1588
+ "tableAttributes": {
1589
+ "type": "string",
1590
+ "mutable": false,
1591
+ "complexType": {
1592
+ "original": "string",
1593
+ "resolved": "string",
1594
+ "references": {}
1595
+ },
1596
+ "required": false,
1597
+ "optional": false,
1598
+ "docs": {
1599
+ "tags": [],
1600
+ "text": "Stringified JSON object defining custom columns computed from dataset fields.<br />\nKeys are column labels, values are aggregate expressions over the rows that\nmake up each table row.<br /><br />\nFunctions: ```set // first // last // min // max // avg // sum // lit```<br />\nFields can be standard dataset fields (e.g. ```ac1```) or custom fields\nprefixed with ```_``` (e.g. ```_leiter```); ```lit``` takes a constant value.<br /><br />\nexample:<br />\n```{\"Verkaufsleiter\": \"set(_leiter)\", \"Umsatz gesamt\": \"sum(ac1)\"}```"
1601
+ },
1602
+ "getter": false,
1603
+ "setter": false,
1604
+ "reflect": false,
1605
+ "attribute": "attributes",
1606
+ "defaultValue": "\"\""
1542
1607
  }
1543
1608
  };
1544
1609
  }
@@ -1621,6 +1686,9 @@ export class Table {
1621
1686
  }, {
1622
1687
  "propName": "columnthereof",
1623
1688
  "methodName": "validateColumnThereOf"
1689
+ }, {
1690
+ "propName": "tableAttributes",
1691
+ "methodName": "validateTableAttributes"
1624
1692
  }];
1625
1693
  }
1626
1694
  }
@@ -45,6 +45,7 @@ export class IbcsTable {
45
45
  direction: OrderDirection.ASC,
46
46
  };
47
47
  this.categorythereof = new Map();
48
+ this.attributeColumns = [];
48
49
  this.type = TableType.LIST;
49
50
  this.categoryWidth = TableCategoryWidth.INF;
50
51
  this.dataFormatDigits = { percent: 2, decimal: 1 };
@@ -101,6 +102,7 @@ export class IbcsTable {
101
102
  thereOf: this.thereof,
102
103
  partOf: this.partof,
103
104
  categoryThereOf: this.categorythereof,
105
+ attributes: this.attributeColumns,
104
106
  order: this.order,
105
107
  type: this.type,
106
108
  limit: this.limit,
@@ -530,6 +532,31 @@ export class IbcsTable {
530
532
  "setter": false,
531
533
  "defaultValue": "new Map()"
532
534
  },
535
+ "attributeColumns": {
536
+ "type": "unknown",
537
+ "mutable": false,
538
+ "complexType": {
539
+ "original": "TableAttribute[]",
540
+ "resolved": "TableAttribute[]",
541
+ "references": {
542
+ "TableAttribute": {
543
+ "location": "import",
544
+ "path": "./utils/model/TableAttribute",
545
+ "id": "src/components/bn-table/utils/model/TableAttribute.ts::TableAttribute",
546
+ "referenceLocation": "TableAttribute"
547
+ }
548
+ }
549
+ },
550
+ "required": false,
551
+ "optional": false,
552
+ "docs": {
553
+ "tags": [],
554
+ "text": ""
555
+ },
556
+ "getter": false,
557
+ "setter": false,
558
+ "defaultValue": "[]"
559
+ },
533
560
  "type": {
534
561
  "type": "string",
535
562
  "mutable": false,
@@ -124,14 +124,14 @@ export class Table {
124
124
  this.rowCount = 0;
125
125
  }
126
126
  const normalizedScenarios = this.normalizeScenarios(this.config.scenarios, this.config.categoryThereOf, this.config.sortOrder);
127
- this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale);
127
+ this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale, this.config.attributes);
128
128
  this.bodyRows =
129
129
  this.rowCount === 0 ? [] : this.dataSetFactory.createBodyRows(this.config, this.i18n, this.db, this.fromExpr);
130
130
  this.state = FactoryState.UP_TO_DATE;
131
131
  }
132
132
  update() {
133
133
  const normalizedScenarios = this.normalizeScenarios(this.config.scenarios, this.config.categoryThereOf, this.config.sortOrder);
134
- this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale);
134
+ this.headerRows = this.dataSetFactory.createHeader(this.config.type, normalizedScenarios, this.i18n, this.config.measureScale, this.config.measureUnit, this.config.showMeasureScale, this.config.attributes);
135
135
  this.bodyRows =
136
136
  this.rowCount === 0 || !this.fromExpr
137
137
  ? []
@@ -18,6 +18,7 @@ import { QueryColumnNames, VarianceScenario } from "../../../../utils/model";
18
18
  export class TableDataSetFactory {
19
19
  constructor() {
20
20
  this.normalizedHeader = [];
21
+ this.attributesByAlias = new Map();
21
22
  }
22
23
  /**
23
24
  * Creates Tableheader based on the configured scenarios (in config)
@@ -27,13 +28,17 @@ export class TableDataSetFactory {
27
28
  * visualise grouping.
28
29
  * finally a seperator header row is created for the header underlining (border)
29
30
  */
30
- createHeader(type, scenarios, i18n, measureScale, measureUnit, showMeasureScale) {
31
+ createHeader(type, scenarios, i18n, measureScale, measureUnit, showMeasureScale, attributes = []) {
31
32
  const header = [];
32
- this.normalizedHeader = this.normalizeHeader(type, scenarios);
33
+ this.attributesByAlias = new Map(attributes.map((attribute) => [attribute.alias, attribute]));
34
+ this.normalizedHeader = this.normalizeHeader(type, scenarios, attributes);
33
35
  const headerRow = new TableRow(0, 0, TableRowType.HEADER);
34
36
  const separatorRow = new TableRow(1, 0, TableRowType.SEPERATORLINE);
35
37
  for (const scenario of this.normalizedHeader) {
36
- headerRow.createElement(Formatter.translateScenarioLabel(scenario.name, i18n), scenario.type, this.createColumnType(scenario), null, this.setHeaderPrefix(scenario, i18n, measureScale, measureUnit, showMeasureScale), null, null, null, null);
38
+ const attribute = this.attributesByAlias.get(scenario.name);
39
+ headerRow.createElement(attribute
40
+ ? i18n.get(attribute.label) || attribute.label
41
+ : Formatter.translateScenarioLabel(scenario.name, i18n), scenario.type, this.createColumnType(scenario), null, this.setHeaderPrefix(scenario, i18n, measureScale, measureUnit, showMeasureScale), null, null, null, null);
37
42
  separatorRow.createElement(null, scenario.type, this.createColumnType(scenario), null, null, null, null, null, null);
38
43
  }
39
44
  header.push(headerRow);
@@ -58,7 +63,7 @@ export class TableDataSetFactory {
58
63
  * depending of table type operation column is used (OPT) or not (SUM | LIST)
59
64
  * in addition the headers are sorted based on the ruleset and duplicates are removed
60
65
  */
61
- normalizeHeader(type, scenarios) {
66
+ normalizeHeader(type, scenarios, attributes) {
62
67
  let header = [
63
68
  {
64
69
  name: QueryColumnNames.CATEGORY,
@@ -83,8 +88,15 @@ export class TableDataSetFactory {
83
88
  },
84
89
  ];
85
90
  }
91
+ // attribute columns sit between the category column and the scenario columns
92
+ const attributeColumns = attributes.map((attribute) => ({
93
+ name: attribute.alias,
94
+ group: attribute.alias,
95
+ type: attribute.alias,
96
+ order: undefined,
97
+ }));
86
98
  // NOTE: scenarios are already sorted in setConfig
87
- return [...header, ...scenarios];
99
+ return [...header, ...attributeColumns, ...scenarios];
88
100
  }
89
101
  /**
90
102
  * Creates table data colelction,
@@ -256,6 +268,10 @@ export class TableDataSetFactory {
256
268
  * @param subCategory
257
269
  */
258
270
  translateSumCellLabel(i18nMode, i18n, value, rowGroup, subCategory, type, scenario) {
271
+ if (this.attributesByAlias.has(scenario)) {
272
+ // attribute values render verbatim; rows without the column (e.g. SUM) stay blank
273
+ return value;
274
+ }
259
275
  if (Number.isNaN(Number(value)) === false) {
260
276
  return value;
261
277
  }
@@ -313,6 +329,9 @@ export class TableDataSetFactory {
313
329
  * @param value
314
330
  */
315
331
  translateScenarioCSS(scenario, value) {
332
+ if (this.attributesByAlias.has(scenario)) {
333
+ return "attribute";
334
+ }
316
335
  const scenarios = new VarianceScenario(scenario);
317
336
  let prefix = "pos";
318
337
  if (value < 0) {
@@ -327,6 +346,10 @@ export class TableDataSetFactory {
327
346
  if (scenario === "category") {
328
347
  return "";
329
348
  }
349
+ const attribute = this.attributesByAlias.get(scenario);
350
+ if (attribute) {
351
+ return attribute.isNumeric ? "decimal" : "";
352
+ }
330
353
  let unitType;
331
354
  const scenarios = new VarianceScenario(scenario);
332
355
  if (scenariosUnitType === DataFormat.PERCENT) {
@@ -47,6 +47,7 @@ export class DataQuery {
47
47
  .map((s) => this.translateScenarioSQL(s, true, this.config.type))
48
48
  .toString();
49
49
  const relativeScenarios = this.getRelativeScenarios();
50
+ const attributesSQL = this.config.attributes.map((attribute) => this.translateAttributeSQL(attribute)).toString();
50
51
  const groups = new QueryGroups(this.config);
51
52
  const groupsAggregated = this.config.grouped ? [QueryColumnNames.ROWGROUP, QueryColumnNames.ROWGROUPINDEX] : [];
52
53
  let order = ["", ""];
@@ -83,7 +84,7 @@ export class DataQuery {
83
84
  queryLimitSection = `LIMIT ${this.config.limit}`;
84
85
  }
85
86
  this.createGroupHeaderRow(rowGroupEntry, queries);
86
- this.createDataRow(queries, rowGroupEntry, groups, scenarios, queryWhereSection, order, queryLimitSection);
87
+ this.createDataRow(queries, rowGroupEntry, groups, scenarios, attributesSQL, queryWhereSection, order, queryLimitSection);
87
88
  this.createRestRow(rowGroupEntry, queries, groups, scenarios, queryWhereSection, order);
88
89
  this.createGroupSumRow(queries, sumGroupQueries, rowGroupEntry, scenariosSUMQuery, order);
89
90
  });
@@ -98,7 +99,7 @@ export class DataQuery {
98
99
  }
99
100
  });
100
101
  this.detectNaNCells(this.config.scenarios, res);
101
- this.createThereOfDrillRows(scenarios, order, res);
102
+ this.createThereOfDrillRows(scenarios, attributesSQL, order, res);
102
103
  this.createPartOfDrillRows(scenarios, order, sumGroupQueries, res);
103
104
  this.createThereOfDrillColumns(this.config.categoryThereOf, res);
104
105
  this.calculateColumnGroupRest(res, this.config.categoryThereOf);
@@ -186,14 +187,14 @@ export class DataQuery {
186
187
  }
187
188
  }
188
189
  /** Generates the main data rows for a single row group, applying GROUP BY, ORDER, and LIMIT. */
189
- createDataRow(querys, rowGroupEntry, groups, scenarios, queryWhereSection, order, queryLimitSection) {
190
+ createDataRow(querys, rowGroupEntry, groups, scenarios, attributes, queryWhereSection, order, queryLimitSection) {
190
191
  // Generates DataRows
191
192
  querys.push(`SELECT ROWNUM() AS ${QueryColumnNames.ROWNR},
192
193
  ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
193
194
  'ENTRY' as ${QueryColumnNames.TYPE},
194
195
  '${rowGroupEntry.rowGroup || "NO_GROUP"}' as ${QueryColumnNames.ROWGROUP},
195
196
  '${QueryColumnNames.CATEGORYINDEX}',
196
- ${groups} ${scenarios.length > 0 ? ",".concat(scenarios) : ""}
197
+ ${groups} ${scenarios.length > 0 ? ",".concat(scenarios) : ""} ${attributes.length > 0 ? ",".concat(attributes) : ""}
197
198
  FROM ${this.fromExpr} ${queryWhereSection}
198
199
  GROUP BY ${groups}
199
200
  ORDER BY ${order[0]} ${queryLimitSection}`);
@@ -339,7 +340,7 @@ export class DataQuery {
339
340
  * beneath their parent category row. Each thereof config entry produces a
340
341
  * filtered/grouped SQL query whose results are spliced into the result set.
341
342
  */
342
- createThereOfDrillRows(scenarios, order, res) {
343
+ createThereOfDrillRows(scenarios, attributes, order, res) {
343
344
  // adds drill rows if setup in config
344
345
  // if there of is set drilldown row is displayed with absolute numbers,
345
346
  // if part of is also not null a relative percenatage based of the selected basis is displayed
@@ -374,7 +375,7 @@ export class DataQuery {
374
375
  ${QueryColumnNames.CATEGORY},
375
376
  ${QueryColumnNames.SUBCATEGORY},
376
377
  ${QueryColumnNames.ROWGROUP} as ${QueryColumnNames.ROWGROUP},
377
- ${scenarios}
378
+ ${scenarios} ${attributes.length > 0 ? ",".concat(attributes) : ""}
378
379
  FROM ${this.fromExpr}
379
380
  WHERE ${fromString}
380
381
  GROUP BY ${QueryColumnNames.ROWGROUP}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.SUBCATEGORY}
@@ -500,6 +501,45 @@ export class DataQuery {
500
501
  }
501
502
  return `SUM(${scenario} * transformOperator(operation)) as ${scenario}, COUNT(ISNULL(${scenario})) as ${scenario}_cnt`;
502
503
  }
504
+ /**
505
+ * Translates an attribute definition into a SQL aggregate expression aliased
506
+ * to the attribute's safe column alias (`attr_N`).
507
+ *
508
+ * `sum`/`avg` on scenario fields respect the row operation sign via
509
+ * `transformOperator`, consistent with {@link translateScenarioSQL}; for
510
+ * OPT/OPTNOTOTAL types the sign is already baked into the data.
511
+ */
512
+ translateAttributeSQL(attribute) {
513
+ const field = `[${attribute.arg}]`;
514
+ const isScenarioField = /^(ac|pp|fc|pl)[1-4]$/.test(attribute.arg);
515
+ const useOperator = isScenarioField && this.config.type !== TableType.OPT && this.config.type !== TableType.OPTNOTOTAL;
516
+ switch (attribute.fn) {
517
+ case "set":
518
+ return `SETAGG(${field}) as ${attribute.alias}`;
519
+ case "first":
520
+ return `FIRST(${field}) as ${attribute.alias}`;
521
+ case "last":
522
+ return `LAST(${field}) as ${attribute.alias}`;
523
+ case "min":
524
+ return `MIN(${field}) as ${attribute.alias}`;
525
+ case "max":
526
+ return `MAX(${field}) as ${attribute.alias}`;
527
+ case "avg":
528
+ return useOperator
529
+ ? `AVG(${field} * transformOperator(operation)) as ${attribute.alias}`
530
+ : `AVG(${field}) as ${attribute.alias}`;
531
+ case "sum":
532
+ return useOperator
533
+ ? `SUM(${field} * transformOperator(operation)) as ${attribute.alias}`
534
+ : `SUM(${field}) as ${attribute.alias}`;
535
+ case "lit":
536
+ return `${this.sqlLiteral(attribute.arg)} as ${attribute.alias}`;
537
+ }
538
+ }
539
+ /** Emits a raw lit() argument as a SQL literal: numeric when parseable, quoted string otherwise. */
540
+ sqlLiteral(raw) {
541
+ return raw !== "" && !Number.isNaN(Number(raw)) ? raw : `'${raw.replace(/'/g, "''")}'`;
542
+ }
503
543
  /**
504
544
  * generates Tuple
505
545
  * [0] orderby string example: category asc
@@ -0,0 +1,46 @@
1
+ const EXPRESSION_REGEX = /^\s*(set|first|last|min|max|avg|sum|lit)\(\s*(.*?)\s*\)\s*$/;
2
+ /** Field arguments must be plain identifiers — keeps user input out of SQL syntax. */
3
+ const FIELD_IDENTIFIER_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;
4
+ const NUMERIC_FNS = ["min", "max", "avg", "sum"];
5
+ /**
6
+ * A custom table column computed from dataset fields via an aggregate expression,
7
+ * e.g. `set(_leiter)` or `sum(ac1)` (see the `attributes` prop on bn-table).
8
+ *
9
+ * The {@link label} is the user-facing header text and never enters SQL; queries
10
+ * use the positional {@link alias} (`attr_0`, `attr_1`, ...) instead.
11
+ */
12
+ export class TableAttribute {
13
+ constructor(label, alias, fn, arg) {
14
+ this.label = label;
15
+ this.alias = alias;
16
+ this.fn = fn;
17
+ this.arg = arg;
18
+ }
19
+ /** Numeric aggregates are formatted like scenario cells (measure scale + decimals). */
20
+ get isNumeric() {
21
+ return NUMERIC_FNS.includes(this.fn);
22
+ }
23
+ }
24
+ /** Checks a single attribute expression string like "set(_leiter)" or "lit(Fix)". */
25
+ export function isValidAttributeExpression(expression) {
26
+ if (typeof expression !== "string") {
27
+ return false;
28
+ }
29
+ const match = EXPRESSION_REGEX.exec(expression);
30
+ if (!match) {
31
+ return false;
32
+ }
33
+ const [, fn, arg] = match;
34
+ if (fn === "lit") {
35
+ return arg.length > 0;
36
+ }
37
+ return FIELD_IDENTIFIER_REGEX.test(arg);
38
+ }
39
+ /** Parses an attribute expression into a {@link TableAttribute}; null when invalid. */
40
+ export function parseTableAttributeExpression(label, alias, expression) {
41
+ if (!isValidAttributeExpression(expression)) {
42
+ return null;
43
+ }
44
+ const [, fn, arg] = EXPRESSION_REGEX.exec(expression);
45
+ return new TableAttribute(label, alias, fn, arg);
46
+ }
@@ -36,6 +36,8 @@ export class TableComponentConfig {
36
36
  this.categoryThereOf = new Map();
37
37
  /** Percentage-of-total sub-row definitions. */
38
38
  this.partOf = [];
39
+ /** Custom columns computed from dataset fields via aggregate expressions (see bn-table `attributes` prop). */
40
+ this.attributes = [];
39
41
  this.sortOrder = new OrderAdapter(new StringAdapter()).default();
40
42
  /** Table aggregation mode: LIST (flat), SUM (with totals), OPT (with optional totals), etc. */
41
43
  this.type = TableType.LIST;
@@ -99,6 +101,9 @@ export class TableComponentConfigAdapter {
99
101
  if (CompareUtil.isArray(data.partOf)) {
100
102
  config.partOf = AdapterUtils.adaptArray(data.partOf, this.tableDrillGroupAdapter);
101
103
  }
104
+ if (CompareUtil.isArray(data.attributes)) {
105
+ config.attributes = data.attributes;
106
+ }
102
107
  if (CompareUtil.isExisting(data.order)) {
103
108
  config.sortOrder = this.orderAdapter.adapt(data.order);
104
109
  }
@@ -62,6 +62,20 @@ function registerUdfs() {
62
62
  return undefined;
63
63
  return dt.startOf(normalizationLevel);
64
64
  });
65
+ // Custom aggregate collecting unique values per group, used by bn-table attribute
66
+ // expressions like set(_leiter). alasql stages: 1 = init, 2 = accumulate, 3 = finalize.
67
+ alasql.aggr.SETAGG = (value, accumulator, stage) => {
68
+ if (stage === 1) {
69
+ return value == null ? [] : [value];
70
+ }
71
+ const acc = accumulator;
72
+ if (stage === 2) {
73
+ if (value != null && !acc.includes(value))
74
+ acc.push(value);
75
+ return acc;
76
+ }
77
+ return acc.join(", ");
78
+ };
65
79
  }
66
80
  /** Creates a fresh isolated database with its own subscriber map. */
67
81
  export function createScopedDb() {
@@ -43,49 +43,90 @@ function findLayoutParent(element) {
43
43
  return lightParent;
44
44
  }
45
45
  /**
46
- * Returns the visual parent, crossing shadow DOM boundaries via assignedSlot.
46
+ * Returns the visual parent, crossing shadow DOM boundaries in both
47
+ * directions: via assignedSlot for slotted elements (light → shadow) and
48
+ * via the shadow host when the element is a top-level child of a shadow
49
+ * root (shadow → host). Without the host crossing, the ancestor walk dies
50
+ * at the top of a component's shadow tree (e.g. inside bn-layout-card)
51
+ * and never sees outer constraints.
47
52
  */
48
53
  function getVisualParent(element) {
49
54
  var _a;
50
55
  if ((_a = element.assignedSlot) === null || _a === void 0 ? void 0 : _a.parentElement) {
51
56
  return element.assignedSlot.parentElement;
52
57
  }
53
- return element.parentElement;
58
+ if (element.parentElement) {
59
+ return element.parentElement;
60
+ }
61
+ const root = element.getRootNode();
62
+ return root instanceof ShadowRoot ? root.host : null;
54
63
  }
55
64
  /**
56
65
  * Walks up the ancestor chain to find a height that is actually constrained
57
66
  * (not just "whatever my content needs"). Crosses shadow DOM boundaries
58
67
  * via assignedSlot when encountering slotted elements. Returns viewport
59
68
  * height as a last resort.
69
+ *
70
+ * Ancestors inside a fit-content layout region (marked with
71
+ * `data-bn-fit-content` by bn-layout-page / bn-layout-card) are skipped
72
+ * even when they clip overflow: their height is derived from their own
73
+ * content — including the measuring component itself — so using it for
74
+ * auto-scaling creates a feedback loop where the chart inflates the cell
75
+ * and then reads the inflated cell back as "available height". The marker
76
+ * value carries the grid's row count; the constraint found above the
77
+ * fit-content region is divided by it, approximating the equal-share cell
78
+ * height the same layout would produce with fit-to-content disabled.
60
79
  */
61
80
  function findConstrainedHeight(element, debug = false) {
62
81
  let current = findLayoutParent(element);
63
82
  let depth = 0;
83
+ let candidate = null;
84
+ let rowShareDivisor = 1;
64
85
  while (current) {
86
+ // A fit-content region sizes itself from its content — every height
87
+ // measured below this point is circular. Discard inner candidates and
88
+ // keep walking for a content-independent constraint further up.
89
+ if (current.hasAttribute("data-bn-fit-content")) {
90
+ if (debug)
91
+ console.log(`[height:${depth}]`, current.tagName, "fit-content region → discarding inner candidate");
92
+ candidate = null;
93
+ const rows = parseInt(current.getAttribute("data-bn-fit-content"), 10);
94
+ if (!isNaN(rows) && rows > 1) {
95
+ rowShareDivisor *= rows;
96
+ }
97
+ current = getVisualParent(current);
98
+ depth++;
99
+ continue;
100
+ }
65
101
  const style = getComputedStyle(current);
66
102
  const overflow = style.overflowY;
67
103
  if (debug) {
68
104
  console.log(`[height:${depth}]`, current.tagName, current.className || "(no class)", `overflow=${overflow} clientH=${current.clientHeight} h=${style.height}`);
69
105
  }
70
- // An ancestor that clips / scrolls its content has a meaningful height
71
- if (overflow === "hidden" || overflow === "scroll" || overflow === "auto") {
72
- const h = current.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
73
- if (debug)
74
- console.log(`[height] FOUND constrained at depth ${depth}: ${Math.round(h)}px`);
75
- return h;
76
- }
77
- // An explicit max-height constrains the available space
78
- if (style.maxHeight !== "none") {
79
- const mh = parseFloat(style.maxHeight);
80
- if (!isNaN(mh) && mh > 0) {
81
- return Math.min(mh, current.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom));
106
+ if (candidate === null) {
107
+ // An ancestor that clips / scrolls its content has a meaningful height
108
+ if (overflow === "hidden" || overflow === "scroll" || overflow === "auto") {
109
+ candidate = current.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
110
+ if (debug)
111
+ console.log(`[height] candidate at depth ${depth}: ${Math.round(candidate)}px`);
112
+ }
113
+ else if (style.maxHeight !== "none") {
114
+ // An explicit max-height constrains the available space
115
+ const mh = parseFloat(style.maxHeight);
116
+ if (!isNaN(mh) && mh > 0) {
117
+ candidate = Math.min(mh, current.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom));
118
+ }
82
119
  }
83
120
  }
84
121
  current = getVisualParent(current);
85
122
  depth++;
86
123
  }
124
+ if (candidate !== null) {
125
+ return candidate / rowShareDivisor;
126
+ }
87
127
  if (debug)
88
128
  console.log("[height] NO constrained ancestor → viewport fallback");
89
- // No constrained ancestor found — use viewport
90
- return typeof window !== "undefined" ? window.innerHeight : 0;
129
+ // No constrained ancestor found — use viewport, applying the same
130
+ // equal-share division a marked fit-content region demands
131
+ return typeof window !== "undefined" ? window.innerHeight / rowShareDivisor : 0;
91
132
  }