@bino-bi/bn-template-engine 1.0.0-next.34 → 1.0.0-next.36

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 (146) hide show
  1. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  2. package/dist/bn-template-engine/p-2dcdac86.entry.js +1 -0
  3. package/dist/bn-template-engine/{p-7d475277.entry.js → p-5a64f90f.entry.js} +1 -1
  4. package/dist/bn-template-engine/{p-789bfd06.entry.js → p-93b8387f.entry.js} +1 -1
  5. package/dist/bn-template-engine/{p-66ed6259.entry.js → p-9a61f59d.entry.js} +1 -1
  6. package/dist/bn-template-engine/p-BVU4bIsi.js +1 -0
  7. package/dist/bn-template-engine/{p-CJfJQT0m.js → p-D0tNATZq.js} +1 -1
  8. package/dist/bn-template-engine/p-DF9sfwBN.js +1 -0
  9. package/dist/bn-template-engine/{p-CAvWZ3a5.js → p-DyupX-Z-.js} +1 -1
  10. package/dist/bn-template-engine/{p-14d021be.entry.js → p-b0dfc113.entry.js} +1 -1
  11. package/dist/bn-template-engine/{p-dec6837c.entry.js → p-eea538f1.entry.js} +1 -1
  12. package/dist/bn-template-engine/{p-CHZ50kEY.js → p-qpZjVnX5.js} +1 -1
  13. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +378 -135
  14. package/dist/cjs/bn-grid.cjs.entry.js +3 -3
  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-ruleset.cjs.entry.js +2 -2
  18. package/dist/cjs/bn-text.cjs.entry.js +3 -3
  19. package/dist/cjs/{localFrame-P5SDUOto.js → localFrame-U3Qs0psw.js} +1 -1
  20. package/dist/cjs/{withBodyObserver-B1_hmuUz.js → withBodyObserver-S-FGHpAX.js} +1 -1
  21. package/dist/cjs/{withHasError-3kR2tdhJ.js → withHasError-BkBrsCpI.js} +8 -7
  22. package/dist/cjs/{withStyled-eHD8Yt2K.js → withStyled-DfE0aW7D.js} +63 -3
  23. package/dist/cjs/{withTranslation-yJ-j0lsu.js → withTranslation-0gkn9xoC.js} +2 -2
  24. package/dist/collection/components/bn-table/bn-table-renderer/bn-table-renderer.js +97 -48
  25. package/dist/collection/components/bn-table/bn-table.js +19 -10
  26. package/dist/collection/components/bn-table/utils/Table.js +34 -8
  27. package/dist/collection/components/bn-table/utils/elements/CellBarChart.js +103 -32
  28. package/dist/collection/components/bn-table/utils/helper/DataQuery.js +57 -10
  29. package/dist/collection/components/bn-table/utils/helper/barColumnGeometry.js +73 -30
  30. package/dist/collection/stores/ruleSets.js +8 -7
  31. package/dist/collection/utils/ibcsRuleSet.js +2 -1
  32. package/dist/collection/utils/model/Order.js +49 -2
  33. package/dist/collection/utils/validate.js +11 -1
  34. package/dist/components/bn-annotation-layer.js +1 -1
  35. package/dist/components/bn-annotation-list.js +1 -1
  36. package/dist/components/bn-asset.js +1 -1
  37. package/dist/components/bn-body.js +1 -1
  38. package/dist/components/bn-card.js +1 -1
  39. package/dist/components/bn-chart-bubble-renderer.js +1 -1
  40. package/dist/components/bn-chart-bubble.js +1 -1
  41. package/dist/components/bn-chart-bullet-renderer.js +1 -1
  42. package/dist/components/bn-chart-bullet.js +1 -1
  43. package/dist/components/bn-chart-scatter-renderer.js +1 -1
  44. package/dist/components/bn-chart-scatter.js +1 -1
  45. package/dist/components/bn-chart-structure-renderer.js +1 -1
  46. package/dist/components/bn-chart-structure.js +1 -1
  47. package/dist/components/bn-chart-time-renderer.js +1 -1
  48. package/dist/components/bn-chart-time.js +1 -1
  49. package/dist/components/bn-component-style.js +1 -1
  50. package/dist/components/bn-context.js +1 -1
  51. package/dist/components/bn-dataset.js +1 -1
  52. package/dist/components/bn-datasource.js +1 -1
  53. package/dist/components/bn-footer.js +1 -1
  54. package/dist/components/bn-grid.js +1 -1
  55. package/dist/components/bn-image.js +1 -1
  56. package/dist/components/bn-internationalization.js +1 -1
  57. package/dist/components/bn-layout-card.js +1 -1
  58. package/dist/components/bn-layout-page.js +1 -1
  59. package/dist/components/bn-message.js +1 -1
  60. package/dist/components/bn-page.js +1 -1
  61. package/dist/components/bn-ruleset.js +1 -1
  62. package/dist/components/bn-scaling-group.js +1 -1
  63. package/dist/components/bn-table-renderer.js +1 -1
  64. package/dist/components/bn-table.js +1 -1
  65. package/dist/components/bn-text.js +1 -1
  66. package/dist/components/bn-title-renderer.js +1 -1
  67. package/dist/components/bn-title.js +1 -1
  68. package/dist/components/bn-tree.js +1 -1
  69. package/dist/components/p-16rjcQ0t.js +1 -0
  70. package/dist/components/{p-8a2-IS-y.js → p-2eicD9rF.js} +1 -1
  71. package/dist/components/p-4vVbchX2.js +1 -0
  72. package/dist/components/{p-VIw66ez1.js → p-7ieJFBUk.js} +1 -1
  73. package/dist/components/{p-Dn3DJxQQ.js → p-9mUU4itF.js} +1 -1
  74. package/dist/components/{p-D5LDmR4u.js → p-B5tixDPM.js} +1 -1
  75. package/dist/components/p-BPGLOHUe.js +1 -0
  76. package/dist/components/{p-B3F_c9GB.js → p-BU_53KVT.js} +1 -1
  77. package/dist/components/p-BXXjh6We.js +1 -0
  78. package/dist/components/{p-C-oNdJj9.js → p-BXg3v5AO.js} +1 -1
  79. package/dist/components/{p-B7UDMyar.js → p-BhEdmPjm.js} +1 -1
  80. package/dist/components/{p-nHZ8466v.js → p-BmOWXYHF.js} +1 -1
  81. package/dist/components/{p-DLLljAll.js → p-Bo_R7f_T.js} +1 -1
  82. package/dist/components/{p-DdG2Ylar.js → p-BqUB56k1.js} +1 -1
  83. package/dist/components/{p-DHAoxu6M.js → p-BzjGUtYh.js} +1 -1
  84. package/dist/components/{p-BtH2oezK.js → p-C-KX1_tw.js} +1 -1
  85. package/dist/components/{p-BldMZbAf.js → p-C3gYq-HU.js} +1 -1
  86. package/dist/components/p-CLilvhjH.js +1 -0
  87. package/dist/components/{p-CPC9Vkmg.js → p-CQVAHG6w.js} +1 -1
  88. package/dist/components/{p-4BanAktr.js → p-C_6KHDYv.js} +1 -1
  89. package/dist/components/{p-ClGOhg6P.js → p-Cel0a6ma.js} +1 -1
  90. package/dist/components/{p-Ku08TQL1.js → p-Chuj-LpI.js} +1 -1
  91. package/dist/components/{p-M6hn0BuZ.js → p-CniN8ALm.js} +1 -1
  92. package/dist/components/{p-BcOud3dQ.js → p-DDvWTgk1.js} +1 -1
  93. package/dist/components/p-DJUffGeB.js +1 -0
  94. package/dist/components/p-DQl2K2Xl.js +1 -0
  95. package/dist/components/p-DT04Cka0.js +1 -0
  96. package/dist/components/{p-BVnYDfb8.js → p-DTmqMQpw.js} +1 -1
  97. package/dist/components/{p-DSkyHSIL.js → p-DaOm9YwQ.js} +1 -1
  98. package/dist/components/p-DjPWZfry.js +1 -0
  99. package/dist/components/{p-BXt0ers2.js → p-Dm6EAaJ9.js} +1 -1
  100. package/dist/components/p-Do4oPrkE.js +1 -0
  101. package/dist/components/{p-DEHnizot.js → p-Dq9dG0Kr.js} +1 -1
  102. package/dist/components/{p-D6cWoDk1.js → p-M2k_I8lv.js} +1 -1
  103. package/dist/components/{p-B4pmO5QQ.js → p-NBaq67dL.js} +1 -1
  104. package/dist/components/p-OquycEMA.js +1 -0
  105. package/dist/components/{p-CJtE8Pyr.js → p-eWxolPDU.js} +1 -1
  106. package/dist/components/{p-De82WP7z.js → p-fKJx8WtW.js} +1 -1
  107. package/dist/components/{p-xhiPDAZa.js → p-sLbQ7yZ1.js} +1 -1
  108. package/dist/components/{p-GrpYAVHb.js → p-sar8m7th.js} +1 -1
  109. package/dist/components/{p-CYqHwYgQ.js → p-tkB96Ena.js} +1 -1
  110. package/dist/esm/bn-annotation-layer_30.entry.js +378 -135
  111. package/dist/esm/bn-grid.entry.js +3 -3
  112. package/dist/esm/bn-image.entry.js +2 -2
  113. package/dist/esm/bn-internationalization.entry.js +2 -2
  114. package/dist/esm/bn-ruleset.entry.js +2 -2
  115. package/dist/esm/bn-text.entry.js +3 -3
  116. package/dist/esm/{localFrame-IW84cmdb.js → localFrame-BNWPPaQa.js} +1 -1
  117. package/dist/esm/{withBodyObserver-CAnnvrE_.js → withBodyObserver-AHQAUV85.js} +1 -1
  118. package/dist/esm/{withHasError-Cj_MzZ8Q.js → withHasError-B6Lvj9Cq.js} +8 -7
  119. package/dist/esm/{withStyled-Cxua0iTP.js → withStyled-CIoJ86RM.js} +61 -4
  120. package/dist/esm/{withTranslation-BeAbw2--.js → withTranslation-BX9T3dfm.js} +2 -2
  121. package/dist/types/components/bn-table/bn-table-renderer/bn-table-renderer.d.ts +8 -12
  122. package/dist/types/components/bn-table/bn-table.d.ts +17 -4
  123. package/dist/types/components/bn-table/utils/Table.d.ts +2 -0
  124. package/dist/types/components/bn-table/utils/elements/CellBarChart.d.ts +9 -2
  125. package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +8 -0
  126. package/dist/types/components/bn-table/utils/helper/barColumnGeometry.d.ts +18 -9
  127. package/dist/types/components.d.ts +4 -4
  128. package/dist/types/stores/ruleSets.d.ts +2 -1
  129. package/dist/types/utils/ibcsRuleSet.d.ts +2 -1
  130. package/dist/types/utils/model/Order.d.ts +18 -1
  131. package/dist/types/utils/validate.d.ts +2 -0
  132. package/package.json +1 -1
  133. package/dist/bn-template-engine/p-BNCLKXjM.js +0 -1
  134. package/dist/bn-template-engine/p-_SKPuKfK.js +0 -1
  135. package/dist/bn-template-engine/p-dc12ff1b.entry.js +0 -1
  136. package/dist/components/p-BNWZoAip.js +0 -1
  137. package/dist/components/p-BT2WH_CP.js +0 -1
  138. package/dist/components/p-BVtD8O36.js +0 -1
  139. package/dist/components/p-BWRE5w0i.js +0 -1
  140. package/dist/components/p-C6XrNN2m.js +0 -1
  141. package/dist/components/p-CGI6XIaK.js +0 -1
  142. package/dist/components/p-CLkpoHdg.js +0 -1
  143. package/dist/components/p-CYv_8LrR.js +0 -1
  144. package/dist/components/p-Ckl1aEvn.js +0 -1
  145. package/dist/components/p-CurWSJkH.js +0 -1
  146. package/dist/components/p-D7X69xMg.js +0 -1
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-DGis1BzT.js');
4
- var withHasError = require('./withHasError-3kR2tdhJ.js');
5
- var withStyled = require('./withStyled-eHD8Yt2K.js');
6
- var withTranslation = require('./withTranslation-yJ-j0lsu.js');
7
- var withBodyObserver = require('./withBodyObserver-B1_hmuUz.js');
8
- var localFrame = require('./localFrame-P5SDUOto.js');
4
+ var withHasError = require('./withHasError-BkBrsCpI.js');
5
+ var withStyled = require('./withStyled-DfE0aW7D.js');
6
+ var withTranslation = require('./withTranslation-0gkn9xoC.js');
7
+ var withBodyObserver = require('./withBodyObserver-S-FGHpAX.js');
8
+ var localFrame = require('./localFrame-U3Qs0psw.js');
9
9
  var index$1 = require('./index.cjs.js');
10
10
  var queryError = require('./queryError-BZjnIW_w.js');
11
11
 
@@ -2641,7 +2641,8 @@ function ruleSetLabels(config) {
2641
2641
  * - 50 = PL: outlined (no fill)
2642
2642
  *
2643
2643
  * Sort indices determine column display order: PP(100s) < PL(200s) < FC(300s) < AC(400s).
2644
- * Variance columns add +1000 (absolute) or +2000 (relative) to the base sort index.
2644
+ * Variance columns add +1000 (absolute) or +1005 (relative) to the base sort index,
2645
+ * so a relative variance sorts directly after the absolute variance with the same reference.
2645
2646
  * Within each group, variant number (1-4) adds multiples of 10.
2646
2647
  *
2647
2648
  * The built-in rules live in `SYSTEM_RULESET_DEFAULTS` (stores/ruleSets); an
@@ -26903,11 +26904,20 @@ const Table$1 = class Table {
26903
26904
  * ```[{"rowGroup": "Umsatz", "category": "Applications"}]```
26904
26905
  */
26905
26906
  this.partof = "[]";
26906
- /** List of the primary scenarios on which the order direction are applied valid scenarios are
26907
- * If order is set to a scenario it has also exists in scenariolist
26907
+ /** Comma list of the columns the rows are sorted by, left to right. `orderDirection` applies to all of them.
26908
26908
  * <br /><br />
26909
26909
  * values: <br />
26910
- * ```category // categoryindex // rowgroup // rowgroup // rowgroupindex // ac[1-4] // fc[1-4] // pp[1-4] // pl[1-4] // auto```
26910
+ * ```category // categoryindex // rowgroup // rowgroupindex // subcategory // subcategoryindex // ac[1-4] // fc[1-4] // pp[1-4] // pl[1-4] // auto```
26911
+ * <br />
26912
+ * or a variance, written like a scenario column, the sentiment is optional and ignored: ```dac1_pp1```, ```drfc1_pp1_pos```
26913
+ * <br /><br />
26914
+ * With `interval="setname"` a scenario or variance can name one bucket after `@`: ```dac1_pp1@_November``` sorts
26915
+ * by that block only. Without a bucket the sum over all buckets is used.
26916
+ * <br /><br />
26917
+ * The scenario or variance does not have to be a shown column; the sort arrow appears only on a shown one.
26918
+ * A plain scenario also sorts the row groups by their sum. A variance or a token with `@` sorts only the rows
26919
+ * inside each group, the groups keep their rowgroupindex order. With a variance or `@`, rows without data
26920
+ * (and a relative variance with a zero reference) sort last.
26911
26921
  * <br /><br />
26912
26922
  * When set to ```auto```, order is detected from the dataset silently.
26913
26923
  */
@@ -27262,7 +27272,7 @@ const Table$1 = class Table {
27262
27272
  this.errors.remove(errId);
27263
27273
  return;
27264
27274
  }
27265
- const invalidElements = withStyled.validateOrderList(newValue);
27275
+ const invalidElements = withStyled.validateTableOrderList(newValue);
27266
27276
  if (invalidElements.length > 0) {
27267
27277
  this.errors.addOrReplace({
27268
27278
  id: errId,
@@ -27590,7 +27600,7 @@ const Table$1 = class Table {
27590
27600
  orderStr = this.datasetMeta.suggestedOrder;
27591
27601
  }
27592
27602
  const tableOrder = {
27593
- hierarchy: orderStr.split(",").map((entry) => withStyled.OrderColumn[entry === null || entry === void 0 ? void 0 : entry.toUpperCase()]),
27603
+ hierarchy: orderStr.split(",").map((entry) => withStyled.normalizeOrderToken(entry)),
27594
27604
  direction: withStyled.OrderDirection[effectiveDirection === null || effectiveDirection === void 0 ? void 0 : effectiveDirection.toUpperCase()],
27595
27605
  };
27596
27606
  return tableOrder;
@@ -28038,7 +28048,7 @@ const Table$1 = class Table {
28038
28048
  render() {
28039
28049
  const fontStyles = this.getFontStyles();
28040
28050
  const effectiveFactor = this.getEffectiveScaleFactor();
28041
- return (index.h(index.Host, { key: '2c70b811354760fd12ac968f7ed3ace210b104a7', style: fontStyles }, index.h("div", { key: '992b077e5e627d067d1199d0ff8434d2216fa107' }, index.h("bn-table-renderer", { key: 'f765e647c7f3d303ba7297f54d9b3a387ed4c160', tableName: this.datasetName, dataVersion: this.dataVersion, sumTitle: this.prepareSumTitle(), scenarios: this.prepareScenarios(), scenariosDataFormat: 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(), categoryWidth: this.prepareCategoryWidth(), dataFormatDigits: this.prepareDataFormatDigits(), i18n: this.prepareI18n(), i18nMode: this.prepareI18nMode(), measureScale: this.prepareMeasureScale(), measureType: this.prepareMeasureType(), measureUnit: this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(), filter: this.prepareFilter(), barColumns: this.prepareBarColumns(), interval: this.prepareInterval(), barColumnMaxWidth: this.prepareBarColumnWidth(), unitScaling: this.prepareUnitScaling(), percentageScaling: this.preparePercentageScaling(), reportAutoScaling: this.handleAutoScalingReport, errors: this.errors, scaleFactor: effectiveFactor, ruleSetConfig: this.ruleSetConfig(), selectedStyle: this.selectedStyle }))));
28051
+ return (index.h(index.Host, { key: '2f24deddc4e58f57ef27443a27b4706b5f1b90db', style: fontStyles }, index.h("div", { key: 'b6368e143f868d9c2a7ad8ec753a14813b60e197' }, index.h("bn-table-renderer", { key: '399b2dc8d5cf3e7a8093a9a486635ea4d1bb74b9', tableName: this.datasetName, dataVersion: this.dataVersion, sumTitle: this.prepareSumTitle(), scenarios: this.prepareScenarios(), scenariosDataFormat: 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(), categoryWidth: this.prepareCategoryWidth(), dataFormatDigits: this.prepareDataFormatDigits(), i18n: this.prepareI18n(), i18nMode: this.prepareI18nMode(), measureScale: this.prepareMeasureScale(), measureType: this.prepareMeasureType(), measureUnit: this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(), filter: this.prepareFilter(), barColumns: this.prepareBarColumns(), interval: this.prepareInterval(), barColumnMaxWidth: this.prepareBarColumnWidth(), unitScaling: this.prepareUnitScaling(), percentageScaling: this.preparePercentageScaling(), reportAutoScaling: this.handleAutoScalingReport, errors: this.errors, scaleFactor: effectiveFactor, ruleSetConfig: this.ruleSetConfig(), selectedStyle: this.selectedStyle }))));
28042
28052
  }
28043
28053
  get element() { return index.getElement(this); }
28044
28054
  static get watchers() { return {
@@ -28301,60 +28311,103 @@ const BAR_LABEL_FONT_RATIO = 0.85;
28301
28311
  * `.category-wN` (bn-table-renderer.scss:50-83) produces.
28302
28312
  */
28303
28313
  const BAR_CELL_PADDING_EM = 0.5;
28304
- /** Value-label gutter beside a bar, in em (was a hardcoded 38 px at the 13.3333 px em). */
28314
+ /** Value-label gutter beside a waterfall bar, in em (was a hardcoded 38 px at the 13.3333 px em). */
28305
28315
  const BAR_LABEL_EM = 2.85;
28306
- /** Value-label gutter beside a pin, in em (was 45 px). */
28307
- const PIN_LABEL_EM = 3.375;
28308
- /** Gap between the axis and the start of a pin's reserved side, in em (was 5 px). */
28309
- const PIN_PADDING_EM = 0.375;
28310
28316
  /** Zigzag break gap of an overdrive bar, in em (was 4 px). */
28311
28317
  const BREAK_GAP_EM = 0.3;
28312
28318
  /** Gap between a bar/pin end and its value label, in em (was 4 px). */
28313
28319
  const LABEL_GAP_EM = 0.3;
28320
+ /** Pin extent per side kept before a pin column drops label digits, in em. */
28321
+ const MIN_EXTENT_EM = 1;
28314
28322
  /** Share of the per-side bar extent reserved for the overdrive stub. */
28315
28323
  const OVERDRIVE_FRACTION = 0.15;
28324
+ /** Width of the axis of a variance bar or pin, in em: near the 0.3em scenario marker in the header. */
28325
+ const VARIANCE_AXIS_EM = 0.25;
28326
+ /** Side of the square pin head, in px before scaleFactor. */
28327
+ const PIN_HEAD_SIZE = 10;
28328
+ /**
28329
+ * Advance widths in em, the larger of Noto Sans and Arial. The engine ships no font, so a
28330
+ * wider fallback (DejaVu Sans, Verdana) is possible: LABEL_WIDTH_MARGIN and the cell
28331
+ * padding cover it. Any glyph not listed counts as a wide letter.
28332
+ */
28333
+ const GLYPH_EM = {
28334
+ ".": 0.28,
28335
+ ",": 0.28,
28336
+ "-": 0.34,
28337
+ "%": 0.89,
28338
+ " ": 0.28,
28339
+ "\u00a0": 0.28,
28340
+ "\u202f": 0.28,
28341
+ M: 0.9,
28342
+ };
28343
+ const DIGIT_EM = 0.59;
28344
+ const OTHER_EM = 0.72;
28345
+ /** Labels fill the cell to the edge, so the estimate keeps room for a wider fallback font. */
28346
+ const LABEL_WIDTH_MARGIN = 1.1;
28347
+ /** Estimated rendered width of a value label in px, with a margin for wider fonts. */
28348
+ function estimateLabelWidth(text, fontSize) {
28349
+ var _a;
28350
+ let em = 0;
28351
+ for (const char of text) {
28352
+ em += (_a = GLYPH_EM[char]) !== null && _a !== void 0 ? _a : (/[0-9+]/.test(char) ? DIGIT_EM : OTHER_EM);
28353
+ }
28354
+ return em * fontSize * LABEL_WIDTH_MARGIN;
28355
+ }
28316
28356
  /** The SVG fills the cell's content box: the requested column width minus the cell padding. */
28317
28357
  function contentWidth(widthEm, emPx) {
28318
28358
  return Math.max(0, (widthEm - BAR_CELL_PADDING_EM) * emPx);
28319
28359
  }
28320
- /** Sides the axis serves. Clamped to 1 so a hypothetical all-zero column never divides by 0. */
28321
- function sideCount(hasNeg, hasPos) {
28322
- return Math.max(1, (hasNeg ? 1 : 0) + (hasPos ? 1 : 0));
28360
+ /** `outerReserve` covers what sticks out beyond the bar or pin end, e.g. the half head. */
28361
+ function sideNeeds(labels, outerReserve, labelGap) {
28362
+ const hasNeg = labels.neg !== undefined;
28363
+ const hasPos = labels.pos !== undefined || !hasNeg;
28364
+ const need = (has, width) => (has ? outerReserve + labelGap + (width !== null && width !== void 0 ? width : 0) : 0);
28365
+ return { sides: (hasNeg ? 1 : 0) + (hasPos ? 1 : 0), neg: need(hasNeg, labels.neg), pos: need(hasPos, labels.pos) };
28366
+ }
28367
+ /** Bar or pin extent per side that a column keeps as long as its labels allow. */
28368
+ function minExtent(totalWidth, emPx, sides) {
28369
+ return Math.min(MIN_EXTENT_EM * emPx, totalWidth / (2 * sides));
28323
28370
  }
28324
- function absoluteBarGeometry(widthEm, emPx, hasNeg, hasPos) {
28371
+ /**
28372
+ * Reserves per side only what its widest label needs and gives the rest to the bars or
28373
+ * pins. A column too narrow for that shortens the bars or pins first, down to zero, so a
28374
+ * label keeps its sign. Only a column narrower than its labels alone shrinks the
28375
+ * reserves, and then the labels overflow. wN stays wN in every case.
28376
+ */
28377
+ function splitSides(totalWidth, labels, outerReserve, labelGap) {
28378
+ const { sides, neg, pos } = sideNeeds(labels, outerReserve, labelGap);
28379
+ const shrink = neg + pos > 0 ? Math.min(1, totalWidth / (neg + pos)) : 1;
28380
+ const extent = Math.max(0, (totalWidth - (neg + pos) * shrink) / sides);
28381
+ return { extent, axisX: labels.neg !== undefined ? neg * shrink + extent : 0 };
28382
+ }
28383
+ /** True when the labels fit beside pins of at least the minimum extent; else the caller drops digits. */
28384
+ function pinLabelsFit(widthEm, emPx, labels, headSize) {
28385
+ const totalWidth = contentWidth(widthEm, emPx);
28386
+ const { sides, neg, pos } = sideNeeds(labels, headSize / 2, LABEL_GAP_EM * emPx);
28387
+ return neg + pos + sides * minExtent(totalWidth, emPx, sides) <= totalWidth + 1e-6;
28388
+ }
28389
+ function absoluteBarGeometry(widthEm, emPx, labels) {
28325
28390
  const totalWidth = contentWidth(widthEm, emPx);
28326
- const sides = sideCount(hasNeg, hasPos);
28327
- // Narrow columns shrink the gutters rather than the total, so wN stays wN.
28328
- const labelAreaWidth = Math.min(BAR_LABEL_EM * emPx, totalWidth / (2 * sides));
28329
- const maxBarWidth = (totalWidth - labelAreaWidth * sides) / sides;
28391
+ const labelGap = LABEL_GAP_EM * emPx;
28392
+ // a variance bar starts at the outer edge of the thick axis
28393
+ const { extent: maxBarWidth, axisX } = splitSides(totalWidth, labels, (VARIANCE_AXIS_EM * emPx) / 2, labelGap);
28330
28394
  const breakGap = Math.min(BREAK_GAP_EM * emPx, maxBarWidth * 0.2);
28331
28395
  const overdriveZoneWidth = maxBarWidth * OVERDRIVE_FRACTION;
28332
28396
  return {
28333
28397
  totalWidth,
28334
- labelAreaWidth,
28335
28398
  maxBarWidth,
28336
- axisX: hasNeg ? labelAreaWidth + maxBarWidth : 0,
28399
+ axisX,
28337
28400
  breakGap,
28338
28401
  overdriveZoneWidth,
28339
28402
  cutWidth: Math.max(0, maxBarWidth - breakGap - overdriveZoneWidth),
28340
- labelGap: LABEL_GAP_EM * emPx,
28403
+ labelGap,
28341
28404
  };
28342
28405
  }
28343
- function relativePinGeometry(widthEm, emPx, hasNeg, hasPos) {
28406
+ function relativePinGeometry(widthEm, emPx, labels, headSize) {
28344
28407
  const totalWidth = contentWidth(widthEm, emPx);
28345
- const sides = sideCount(hasNeg, hasPos);
28346
- const labelAreaWidth = Math.min(PIN_LABEL_EM * emPx, totalWidth / 2);
28347
- const pinAreaWidth = totalWidth - labelAreaWidth;
28348
- const sideWidth = pinAreaWidth / sides;
28349
- const pinPadding = Math.min(PIN_PADDING_EM * emPx, sideWidth * 0.2);
28350
- return {
28351
- totalWidth,
28352
- labelAreaWidth,
28353
- maxPinLength: Math.max(0, sideWidth - pinPadding),
28354
- pinPadding,
28355
- axisX: hasNeg ? sideWidth : 0,
28356
- labelX: pinAreaWidth + LABEL_GAP_EM * emPx,
28357
- };
28408
+ const labelGap = LABEL_GAP_EM * emPx;
28409
+ const { extent, axisX } = splitSides(totalWidth, labels, headSize / 2, labelGap);
28410
+ return { totalWidth, maxPinLength: extent, axisX, labelGap };
28358
28411
  }
28359
28412
  function waterfallGeometry(widthEm, emPx) {
28360
28413
  const totalWidth = contentWidth(widthEm, emPx);
@@ -28389,6 +28442,8 @@ const DEFAULT_STYLES = {
28389
28442
  scaleFactor: 1,
28390
28443
  };
28391
28444
  const AXIS_COLOR = "#666666";
28445
+ /** Width of the pin line, in px before scaleFactor. */
28446
+ const PIN_LINE_WIDTH = 3;
28392
28447
  /**
28393
28448
  * Creates a unique pattern ID for the SVG defs
28394
28449
  */
@@ -28413,16 +28468,20 @@ const PatternDefs = ({ styles }) => {
28413
28468
  ];
28414
28469
  return (index.h("defs", null, patterns.map((p) => (index.h("pattern", { id: p.id, patternUnits: "userSpaceOnUse", width: patternSize, height: patternSize }, index.h("rect", { width: patternSize, height: patternSize, fill: "#ffffff" }), index.h("line", { x1: "0", y1: patternSize, x2: patternSize, y2: "0", stroke: p.stroke, "stroke-width": 1.5 * s }))))));
28415
28470
  };
28416
- /** Characters that fit the pin label gutter (PIN_LABEL_EM), the cell cuts off the rest. */
28471
+ /** Longest relative label that keeps all percent digits; a longer one drops digits so its gutter does not eat the pins. */
28417
28472
  const PIN_LABEL_CHARS = 7;
28418
28473
  /**
28419
28474
  * Formats a number for display with appropriate SI prefix.
28420
28475
  */
28421
- function formatValue(value, isRelative, measureScale = 1, locale, percentDigits = 0) {
28422
- const prefix = value >= 0 ? "+" : "";
28476
+ function formatValue(value, isRelative, measureScale = 1, locale, percentDigits = 0, percentSign = true) {
28477
+ // IBCS prints a value that rounds to zero without a sign
28478
+ const signed = (text, zero) => (value > 0 && text !== zero ? "+" : "") + text;
28423
28479
  if (isRelative) {
28424
28480
  // Relative variance is stored as decimal (e.g., -2.0 = -200%)
28425
- const format = (digits) => prefix + Formatter.number(value, "percent", digits, digits, 1, locale);
28481
+ const number = (v, digits) => percentSign
28482
+ ? Formatter.number(v, "percent", digits, digits, 1, locale)
28483
+ : Formatter.number(v * 100, "decimal", digits, digits, 1, locale);
28484
+ const format = (digits) => signed(number(value, digits), number(0, digits));
28426
28485
  // Intl throws on a digit count outside 0 to 20
28427
28486
  let digits = Math.min(20, Math.max(0, Math.trunc(percentDigits) || 0));
28428
28487
  while (digits > 0 && format(digits).length > PIN_LABEL_CHARS) {
@@ -28449,7 +28508,7 @@ function formatValue(value, isRelative, measureScale = 1, locale, percentDigits
28449
28508
  suffix = "K";
28450
28509
  }
28451
28510
  const digits = absValue >= unit * 10 ? 0 : 1;
28452
- return prefix + Formatter.number(scaledValue / unit, "decimal", digits, 0, 1, locale) + suffix;
28511
+ return (signed(Formatter.number(scaledValue / unit, "decimal", digits, 0, 1, locale), Formatter.number(0, "decimal", digits, 0, 1, locale)) + suffix);
28453
28512
  }
28454
28513
  /**
28455
28514
  * Checks if the column is a scenario column (ac, pp, fc, pl) vs variance (d_, dr_).
@@ -28478,6 +28537,54 @@ function getScenarioStyle(scenario, styles) {
28478
28537
  const type = getScenarioType(scenario);
28479
28538
  return styles.scenarios[type];
28480
28539
  }
28540
+ function getVarianceLook(scenario, styles) {
28541
+ if (isScenarioColumn(scenario))
28542
+ return null;
28543
+ const variance = new VarianceScenario(scenario);
28544
+ if (!variance.isValid)
28545
+ return null;
28546
+ const minuendSlot = getScenarioType(variance.base);
28547
+ const referenceSlot = getScenarioType(variance.delta);
28548
+ return {
28549
+ minuend: styles.scenarios[minuendSlot],
28550
+ minuendSlot,
28551
+ reference: styles.scenarios[referenceSlot],
28552
+ referenceSlot,
28553
+ };
28554
+ }
28555
+ /**
28556
+ * Axis of a variance bar or pin in the look of the reference scenario: solid (AC, PY),
28557
+ * a double line (PL, outlined) or dashed (FC, hatched). Lines only, so the bar stays the
28558
+ * one direct-child rect of the svg.
28559
+ */
28560
+ const VarianceAxis = ({ x, height, look, styles }) => {
28561
+ const s = styles.scaleFactor;
28562
+ const width = VARIANCE_AXIS_EM * styles.emPx;
28563
+ const { reference, referenceSlot } = look;
28564
+ let lines;
28565
+ if (reference.fillpattern === "outlined") {
28566
+ const offset = width / 2 - 0.5 * s;
28567
+ lines = [x - offset, x + offset].map((lineX) => (index.h("line", { x1: lineX, y1: 0, x2: lineX, y2: height, stroke: reference.stroke, "stroke-width": 1 * s })));
28568
+ }
28569
+ else if (reference.fillpattern === "hatched") {
28570
+ lines = (index.h("line", { x1: x, y1: 0, x2: x, y2: height, stroke: reference.stroke, "stroke-width": width, "stroke-dasharray": `${2 * s}` }));
28571
+ }
28572
+ else {
28573
+ lines = index.h("line", { x1: x, y1: 0, x2: x, y2: height, stroke: reference.fill, "stroke-width": width });
28574
+ }
28575
+ return index.h("g", { class: `variance-axis axis-${referenceSlot}` }, lines);
28576
+ };
28577
+ /** A zero value is drawn on the positive side, unless the column only has negative values. */
28578
+ function zeroOnPositiveSide(labels) {
28579
+ return labels.pos !== undefined || labels.neg === undefined;
28580
+ }
28581
+ /** Side coverage from the column statistics, with only this cell's label as the width. */
28582
+ function ownLabelWidths(columnStats, width) {
28583
+ return {
28584
+ neg: columnStats.min < 0 ? width : undefined,
28585
+ pos: columnStats.max > 0 ? width : undefined,
28586
+ };
28587
+ }
28481
28588
  /**
28482
28589
  * Gets the variance style based on value and sentiment direction.
28483
28590
  * pos suffix = positive values are good (green), negative are bad (red)
@@ -28566,13 +28673,12 @@ function renderZigzagBreak(breakX, breakGap, yTop, barHeight, s) {
28566
28673
  * exactly `columnWidthEm` em - see barColumnGeometry.ts.
28567
28674
  */
28568
28675
  const AbsoluteVarianceBar = (props) => {
28569
- const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, columnWidthEm = 10, styles = DEFAULT_STYLES, } = props;
28676
+ const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, columnWidthEm = 10, labelWidths, styles = DEFAULT_STYLES, } = props;
28570
28677
  const s = styles.scaleFactor;
28571
28678
  const fs = styles.fontSize;
28572
- // Adaptive axis placement based on data range
28573
- const hasNeg = columnStats.min < 0;
28574
- const hasPos = columnStats.max > 0;
28575
- const { totalWidth, axisX, breakGap, overdriveZoneWidth, cutWidth, labelGap } = absoluteBarGeometry(columnWidthEm, styles.emPx, hasNeg, hasPos);
28679
+ const displayValue = formattedValue || formatValue(value, false, measureScale, locale);
28680
+ const sides = labelWidths !== null && labelWidths !== void 0 ? labelWidths : ownLabelWidths(columnStats, estimateLabelWidth(displayValue, fs));
28681
+ const { totalWidth, axisX, breakGap, overdriveZoneWidth, cutWidth, labelGap } = absoluteBarGeometry(columnWidthEm, styles.emPx, sides);
28576
28682
  // Direct unit scaling via fontSize
28577
28683
  const scaledWidth = Math.abs(value) * styles.unitScaling * fs;
28578
28684
  // auto scaling puts the largest bar on the cut, float rounding must not turn it into an overdrive bar
@@ -28585,9 +28691,14 @@ const AbsoluteVarianceBar = (props) => {
28585
28691
  const padding = 2 * s;
28586
28692
  const barHeight = height - padding * 2;
28587
28693
  const barY = padding;
28588
- const isPositive = value >= 0;
28694
+ const isPositive = value > 0 || (value === 0 && zeroOnPositiveSide(sides));
28589
28695
  // Get style based on column type (scenario vs variance)
28590
- const barStyle = getBarStyle(scenario, value, isPositiveGood, styles);
28696
+ const look = getVarianceLook(scenario, styles);
28697
+ const sentimentStyle = getBarStyle(scenario, value, isPositiveGood, styles);
28698
+ const minuendPattern = look === null || look === void 0 ? void 0 : look.minuend.fillpattern;
28699
+ // the colour stays the sentiment, the pattern follows the minuend (AC solid, FC hatched, PL outlined)
28700
+ const barStyle = minuendPattern === "hatched" || minuendPattern === "outlined"
28701
+ ? Object.assign(Object.assign({}, sentimentStyle), { fillpattern: minuendPattern }) : sentimentStyle;
28591
28702
  const patternPrefix = isScenarioColumn(scenario)
28592
28703
  ? getScenarioType(scenario)
28593
28704
  : isPositiveGood
@@ -28598,52 +28709,64 @@ const AbsoluteVarianceBar = (props) => {
28598
28709
  ? "neg"
28599
28710
  : "pos";
28600
28711
  const fillValue = getBarFill(barStyle, patternPrefix);
28601
- const { stroke: barStroke, strokeWidth: barStrokeWidth } = getBarStroke(barStyle);
28602
- const displayValue = formattedValue || formatValue(value, false, measureScale, locale);
28712
+ // a hatched variance bar keeps an outline, the shared getBarStroke also serves the waterfall
28713
+ const { stroke: barStroke, strokeWidth: barStrokeWidth } = look && barStyle.fillpattern === "hatched" ? { stroke: barStyle.stroke, strokeWidth: 1 } : getBarStroke(barStyle);
28714
+ // bars start at the outer edge of the thick variance axis
28715
+ const axisOffset = look ? (VARIANCE_AXIS_EM * styles.emPx) / 2 : 0;
28716
+ const rootX = isPositive ? axisX + axisOffset : axisX - axisOffset;
28603
28717
  // Normal bar width (clamped to cutWidth when extreme)
28604
28718
  const baseBarWidth = isExtreme ? cutWidth : scaledWidth;
28605
28719
  // Label position accounts for overdrive
28606
28720
  const totalVisualWidth = isExtreme ? cutWidth + breakGap + overdriveWidth : scaledWidth;
28607
- const labelX = isPositive ? axisX + totalVisualWidth + labelGap : axisX - totalVisualWidth - labelGap;
28721
+ const labelX = isPositive ? rootX + totalVisualWidth + labelGap : rootX - totalVisualWidth - labelGap;
28608
28722
  const labelAnchor = isPositive ? "start" : "end";
28609
- return (index.h("svg", { width: totalWidth, height: height, class: "cell-bar-chart absolute-variance", style: { overflow: "visible" } }, index.h(PatternDefs, { styles: styles }), index.h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), baseBarWidth > 0 && (index.h("rect", { x: isPositive ? axisX : axisX - baseBarWidth, y: barY, width: baseBarWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme && overdriveWidth > 0 && (index.h("rect", { x: isPositive ? axisX + cutWidth + breakGap : axisX - cutWidth - breakGap - overdriveWidth, y: barY, width: overdriveWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme &&
28610
- renderZigzagBreak(isPositive ? axisX + cutWidth : axisX - cutWidth - breakGap, breakGap, barY, barHeight, s), index.h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": labelAnchor, fill: styles.fontColor, "font-size": fs, "font-family": styles.fontFamily }, displayValue)));
28723
+ return (index.h("svg", { width: totalWidth, height: height, class: "cell-bar-chart absolute-variance", style: { overflow: "visible" } }, index.h(PatternDefs, { styles: styles }), !look && index.h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), baseBarWidth > 0 && (index.h("rect", { x: isPositive ? rootX : rootX - baseBarWidth, y: barY, width: baseBarWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme && overdriveWidth > 0 && (index.h("rect", { x: isPositive ? rootX + cutWidth + breakGap : rootX - cutWidth - breakGap - overdriveWidth, y: barY, width: overdriveWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme &&
28724
+ renderZigzagBreak(isPositive ? rootX + cutWidth : rootX - cutWidth - breakGap, breakGap, barY, barHeight, s), look && index.h(VarianceAxis, { x: axisX, height: height, look: look, styles: styles }), index.h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": labelAnchor, fill: styles.fontColor, "font-size": fs, "font-family": styles.fontFamily }, displayValue)));
28611
28725
  };
28612
28726
  /**
28613
28727
  * Renders a relative variance pin chart (dr_ prefix).
28614
- * Thin horizontal line from axis with dot at end and value label.
28728
+ * Line from the axis in the sentiment colour, ending in a square head in the look of the
28729
+ * minuend, with the value label beside the head like an absolute bar label. A pin beyond
28730
+ * the pin area is cut and ends in an arrow, its label after the arrow tip.
28615
28731
  *
28616
- * Layout: [pin area with axis][label area on right], summing to exactly
28732
+ * Layout: [left label area][pin area with axis][right label area], summing to exactly
28617
28733
  * `columnWidthEm` em - see barColumnGeometry.ts.
28618
28734
  * Uses percentageScaling to determine pin length (pixels per percentage point).
28619
28735
  */
28620
28736
  const RelativeVariancePin = (props) => {
28621
- const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, percentDigits, columnWidthEm = 10, styles = DEFAULT_STYLES, } = props;
28737
+ var _a, _b;
28738
+ const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, percentDigits, percentSign, columnWidthEm = 10, labelWidths, styles = DEFAULT_STYLES, } = props;
28622
28739
  const s = styles.scaleFactor;
28623
28740
  const fs = styles.fontSize;
28624
- // Adaptive axis placement based on data range
28625
- const hasNeg = columnStats.min < 0;
28626
- const hasPos = columnStats.max > 0;
28627
- const { totalWidth, maxPinLength, axisX, labelX } = relativePinGeometry(columnWidthEm, styles.emPx, hasNeg, hasPos);
28741
+ const headSize = PIN_HEAD_SIZE * s;
28742
+ const displayValue = formattedValue || formatValue(value, true, measureScale, locale, percentDigits, percentSign);
28743
+ const sides = labelWidths !== null && labelWidths !== void 0 ? labelWidths : ownLabelWidths(columnStats, estimateLabelWidth(displayValue, fs));
28744
+ const { totalWidth, maxPinLength, axisX, labelGap } = relativePinGeometry(columnWidthEm, styles.emPx, sides, headSize);
28628
28745
  const centerY = height / 2;
28629
28746
  // Direct unit scaling via fontSize
28630
28747
  const percentValue = Math.abs(value) * 100;
28631
28748
  const scaledLength = percentValue * styles.percentageScaling * fs;
28632
- const isExtreme = scaledLength > maxPinLength;
28749
+ // auto scaling puts the longest pin on the limit, float rounding must not cut it
28750
+ const isExtreme = scaledLength - maxPinLength > 1e-6;
28633
28751
  const pinLength = Math.min(scaledLength, maxPinLength);
28634
- const isPositive = value >= 0;
28635
- const pinEndX = isPositive ? axisX + pinLength : axisX - pinLength;
28752
+ const isPositive = value > 0 || (value === 0 && zeroOnPositiveSide(sides));
28753
+ const direction = isPositive ? 1 : -1;
28754
+ const pinEndX = axisX + direction * pinLength;
28636
28755
  // Get style based on column type (scenario vs variance)
28637
28756
  const barStyle = getBarStyle(scenario, value, isPositiveGood, styles);
28638
- const dotRadius = 3 * s;
28639
- const displayValue = formattedValue || formatValue(value, true, measureScale, locale, percentDigits);
28640
- return (index.h("svg", { width: totalWidth, height: height, class: "cell-bar-chart relative-variance", style: { overflow: "visible" } }, index.h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), !isExtreme && index.h("circle", { cx: pinEndX, cy: centerY, r: dotRadius, fill: styles.fontColor }), index.h("line", { x1: axisX, y1: centerY, x2: pinEndX, y2: centerY, stroke: barStyle.fill, "stroke-width": 2 * s }), isExtreme && isPositive && (index.h("polygon", { points: `${axisX + maxPinLength},${centerY} ${axisX + maxPinLength - 6 * s},${centerY - 3 * s} ${axisX + maxPinLength - 6 * s},${centerY + 3 * s}`, fill: barStyle.fill })), isExtreme && !isPositive && (index.h("polygon", { points: `${axisX - maxPinLength},${centerY} ${axisX - maxPinLength + 6 * s},${centerY - 3 * s} ${axisX - maxPinLength + 6 * s},${centerY + 3 * s}`, fill: barStyle.fill })), index.h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": "start", fill: styles.fontColor, "font-size": fs, "font-style": "italic", "font-family": styles.fontFamily }, displayValue)));
28757
+ const look = getVarianceLook(scenario, styles);
28758
+ const headStyle = (_a = look === null || look === void 0 ? void 0 : look.minuend) !== null && _a !== void 0 ? _a : styles.scenarios.ac;
28759
+ // the arrow tip lands on the outer edge of a full-length head, so the label after it stays in the cell
28760
+ const tipX = axisX + direction * (maxPinLength + headSize / 2);
28761
+ const arrowBaseX = tipX - direction * headSize;
28762
+ const labelX = (isExtreme ? tipX : pinEndX + direction * (headSize / 2)) + direction * labelGap;
28763
+ return (index.h("svg", { width: totalWidth, height: height, class: "cell-bar-chart relative-variance", style: { overflow: "visible" } }, index.h(PatternDefs, { styles: styles }), look ? (index.h(VarianceAxis, { x: axisX, height: height, look: look, styles: styles })) : (index.h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s })), index.h("line", { x1: axisX, y1: centerY, x2: isExtreme ? arrowBaseX : pinEndX, y2: centerY, stroke: barStyle.fill, "stroke-width": PIN_LINE_WIDTH * s }), isExtreme ? (index.h("polygon", { points: `${tipX},${centerY} ${arrowBaseX},${centerY - headSize / 2} ${arrowBaseX},${centerY + headSize / 2}`, fill: barStyle.fill })) : (index.h("rect", { x: pinEndX - headSize / 2, y: centerY - headSize / 2, width: headSize, height: headSize, fill: headStyle.fillpattern === "outlined" ? "#ffffff" : getBarFill(headStyle, (_b = look === null || look === void 0 ? void 0 : look.minuendSlot) !== null && _b !== void 0 ? _b : "ac"), stroke: headStyle.stroke, "stroke-width": 1 * s })), index.h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": isPositive ? "start" : "end", fill: styles.fontColor, "font-size": fs, "font-style": "italic", "font-family": styles.fontFamily }, displayValue)));
28641
28764
  };
28642
28765
  /**
28643
28766
  * CellBarChart - Renders IBCS-compliant variance bar charts.
28644
28767
  *
28645
28768
  * Absolute variance (d_ prefix): Horizontal bars with centered axis
28646
- * Relative variance (dr_ prefix): Pin/dot charts with value indication
28769
+ * Relative variance (dr_ prefix): Pin charts with a square head and value indication
28647
28770
  *
28648
28771
  * Uses componentStyle patterns from chart components for consistent styling.
28649
28772
  */
@@ -28755,6 +28878,8 @@ class DataQuery {
28755
28878
  this.hasPartOf = false;
28756
28879
  /** Values bound as AlaSQL parameters ($0, $1, ...): row values and free-text config never become SQL text. */
28757
28880
  this.params = [];
28881
+ /** Select fragment (leading comma) of the sort keys for variance and bucketed order tokens. */
28882
+ this.sortSelect = "";
28758
28883
  /** Set by execute: the grouped table has rows with a blank rowGroup (null, '' or missing). */
28759
28884
  this.hasBlankRowGroup = false;
28760
28885
  this.config = config;
@@ -28800,15 +28925,22 @@ class DataQuery {
28800
28925
  const relativeScenarios = this.getRelativeScenarios();
28801
28926
  const attributesSQL = this.config.attributes.map((attribute) => this.translateAttributeSQL(attribute)).toString();
28802
28927
  const groups = new QueryGroups(this.config);
28928
+ // a bucket only applies under interval setname, else the token sorts like its bare column
28929
+ const sortOrder = this.config.interval === INTERVAL_SETNAME
28930
+ ? this.config.sortOrder
28931
+ : {
28932
+ hierarchy: this.config.sortOrder.hierarchy.map((column) => { var _a, _b; return (_b = (_a = withStyled.parseOrderToken(column)) === null || _a === void 0 ? void 0 : _a.column) !== null && _b !== void 0 ? _b : column; }),
28933
+ direction: this.config.sortOrder.direction,
28934
+ };
28803
28935
  let order = ["", ""];
28804
- if (this.config.sortOrder.hierarchy.length > 0) {
28805
- order = this.createOrderString(this.config.sortOrder);
28936
+ if (sortOrder.hierarchy.length > 0) {
28937
+ order = this.createOrderString(sortOrder);
28806
28938
  }
28807
28939
  this.hasPartOf = this.checkConfigForPartOf();
28808
28940
  // meta defines groups and the number detail rows in each group
28809
28941
  // Bsp: 0: Object { totalrowcnt: 7, rowgroup: "Umsatz" }
28810
28942
  // groups follow the order entries that exist per group (rowGroup, rowGroupIndex, scenario sum), else rowGroupIndex
28811
- const { hierarchy, direction } = this.config.sortOrder;
28943
+ const { hierarchy, direction } = sortOrder;
28812
28944
  const groupOrderColumns = hierarchy.filter((column) => column === QueryColumnNames.ROWGROUP ||
28813
28945
  column === QueryColumnNames.ROWGROUPINDEX ||
28814
28946
  column.toUpperCase() in withStyled.Scenarios);
@@ -28942,7 +29074,7 @@ class DataQuery {
28942
29074
  ? `, CASE WHEN MAX(transformOperator(operation)) = -1 THEN '-' ELSE '+' END as restOperation`
28943
29075
  : "";
28944
29076
  querys.push(`SELECT ${QueryColumnNames.ROWNR}, 1 as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, 'NO_GROUP' as ${QueryColumnNames.ROWGROUP}, ${this.bind(String((_a = rowGroupEntry.rowGroup) !== null && _a !== void 0 ? _a : ""))} as restRowGroup, 'REST' as ${QueryColumnNames.CATEGORY}${restOperation} ${restScenarios.length > 0 ? ", " + restScenarios : ""} FROM` +
28945
- ` (SELECT ROWNUM() AS ${QueryColumnNames.ROWNR}, ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, ${this.bind(String(rowGroupEntry.rowGroup || "NO_GROUP"))} as ${QueryColumnNames.ROWGROUP}, ${groups.select()} ${scenarios.length > 0 ? ",".concat(scenarios) : ""} FROM ${this.fromExpr} ${queryWhereSection} GROUP BY ${groups} ORDER BY ${order[0]})` +
29077
+ ` (SELECT ROWNUM() AS ${QueryColumnNames.ROWNR}, ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, ${this.bind(String(rowGroupEntry.rowGroup || "NO_GROUP"))} as ${QueryColumnNames.ROWGROUP}, ${groups.select()} ${scenarios.length > 0 ? ",".concat(scenarios) : ""}${this.sortSelect} FROM ${this.fromExpr} ${queryWhereSection} GROUP BY ${groups} ORDER BY ${order[0]})` +
28946
29078
  ` t WHERE t.rowNr > ${this.config.limit}`);
28947
29079
  }
28948
29080
  }
@@ -28954,7 +29086,7 @@ class DataQuery {
28954
29086
  'ENTRY' as ${QueryColumnNames.TYPE},
28955
29087
  ${this.bind(String(rowGroupEntry.rowGroup || "NO_GROUP"))} as ${QueryColumnNames.ROWGROUP},
28956
29088
  '${QueryColumnNames.CATEGORYINDEX}',
28957
- ${groups.select()} ${scenarios.length > 0 ? ",".concat(scenarios) : ""} ${attributes.length > 0 ? ",".concat(attributes) : ""}
29089
+ ${groups.select()} ${scenarios.length > 0 ? ",".concat(scenarios) : ""} ${attributes.length > 0 ? ",".concat(attributes) : ""}${this.sortSelect}
28958
29090
  FROM ${this.fromExpr} ${queryWhereSection}
28959
29091
  GROUP BY ${groups}
28960
29092
  ORDER BY ${order[0]} ${queryLimitSection}`);
@@ -29144,7 +29276,7 @@ class DataQuery {
29144
29276
  ${QueryColumnNames.CATEGORY},
29145
29277
  ${QueryColumnNames.SUBCATEGORY},
29146
29278
  ${this.drillRowGroup} as ${QueryColumnNames.ROWGROUP},
29147
- ${scenarios} ${attributes.length > 0 ? ",".concat(attributes) : ""}
29279
+ ${scenarios} ${attributes.length > 0 ? ",".concat(attributes) : ""}${this.sortSelect}
29148
29280
  FROM ${this.fromExpr}
29149
29281
  WHERE ${fromString}
29150
29282
  GROUP BY ${this.drillRowGroup}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.SUBCATEGORY}
@@ -29602,10 +29734,47 @@ class DataQuery {
29602
29734
  */
29603
29735
  createOrderString(orderComponent) {
29604
29736
  const inverse = OrderDirection.ASC === orderComponent.direction ? OrderDirection.DESC : OrderDirection.ASC;
29605
- const base = orderComponent.hierarchy.map((column) => `${column} ${orderComponent.direction}`).toString();
29606
- const inverted = orderComponent.hierarchy.map((column) => `${column} ${inverse}`).toString();
29737
+ const sortKeys = new Map();
29738
+ orderComponent.hierarchy.forEach((column, i) => {
29739
+ const token = withStyled.parseOrderToken(column);
29740
+ const bucket = token === null || token === void 0 ? void 0 : token.bucket;
29741
+ if ((token === null || token === void 0 ? void 0 : token.kind) === "variance" || ((token === null || token === void 0 ? void 0 : token.kind) === "scenario" && bucket !== undefined)) {
29742
+ sortKeys.set(i, this.translateSortKeySQL(token, bucket, i));
29743
+ }
29744
+ });
29745
+ this.sortSelect = [...sortKeys.values()].map((key) => `, ${key}`).join("");
29746
+ // rows without a value sort last in both directions
29747
+ const orderBy = (column, i, direction) => sortKeys.has(i) ? `__sortnull${i} asc, __sort${i} ${direction}` : `${column} ${direction}`;
29748
+ const base = orderComponent.hierarchy.map((column, i) => orderBy(column, i, orderComponent.direction)).toString();
29749
+ const inverted = orderComponent.hierarchy.map((column, i) => orderBy(column, i, inverse)).toString();
29607
29750
  return [base, inverted];
29608
29751
  }
29752
+ /**
29753
+ * Sort key `__sort<i>` of a scenario or variance order token, as printed in an entry cell
29754
+ * (OPT entry rows unsigned), restricted to one setname bucket when given.
29755
+ * `__sortnull<i>` is 1 when the cell has no value: no data, or a relative variance with a zero reference.
29756
+ */
29757
+ translateSortKeySQL(token, bucket, i) {
29758
+ const isOpt = TableType.OPT === this.config.type || TableType.OPTNOTOTAL === this.config.type;
29759
+ const sign = isOpt ? "" : " * transformOperator(operation)";
29760
+ const inBucket = bucket === undefined ? "" : `TRIM(CAST(${intervalBucketSQL(INTERVAL_SETNAME)} AS STRING)) = ${this.bind(bucket)}`;
29761
+ const value = (x) => `SUM(${inBucket ? `(CASE WHEN ${inBucket} THEN ${x} ELSE 0 END)` : x}${sign})`;
29762
+ const missing = (x) => `SUM(CASE WHEN ${inBucket ? `${inBucket} AND ` : ""}${x} IS NOT NULL THEN 1 ELSE 0 END) = 0`;
29763
+ if (token.kind === "scenario") {
29764
+ return `${value(token.column)} as __sort${i}, CASE WHEN ${missing(token.column)} THEN 1 ELSE 0 END as __sortnull${i}`;
29765
+ }
29766
+ const difference = `(${value(token.base)} - ${value(token.delta)})`;
29767
+ let key = difference;
29768
+ let noValue = `${missing(token.base)} OR ${missing(token.delta)}`;
29769
+ if (token.type === "dr") {
29770
+ const reference = value(token.delta);
29771
+ // same rule as relativeVariance(); a decimal literal, alasql reads 1e-9 as a column name
29772
+ const zeroReference = `ABS(${reference}) <= ABS(${difference}) * 0.000000001`;
29773
+ key = `CASE WHEN ${zeroReference} THEN 0 ELSE ${difference} / ABS(${reference}) END`;
29774
+ noValue += ` OR ${zeroReference}`;
29775
+ }
29776
+ return `${key} as __sort${i}, CASE WHEN ${noValue} THEN 1 ELSE 0 END as __sortnull${i}`;
29777
+ }
29609
29778
  /** Returns a key/value pair mapping a relative variance column to its denominator, or null for non-relative scenarios. */
29610
29779
  createRelativeScenario(scenario) {
29611
29780
  const scenarios = new VarianceScenario(scenario);
@@ -29660,7 +29829,7 @@ class DataQuery {
29660
29829
  'PARTELEMENT' as ${QueryColumnNames.TYPE},
29661
29830
  ${QueryColumnNames.CATEGORY},
29662
29831
  ${groupName},
29663
- ${scenarios}
29832
+ ${scenarios}${this.sortSelect}
29664
29833
  FROM ${this.fromExpr}
29665
29834
  WHERE ${fromString}
29666
29835
  GROUP BY ${this.drillRowGroup}, ${QueryColumnNames.CATEGORY}, ${QueryColumnNames.TYPE}
@@ -30744,8 +30913,19 @@ class Table {
30744
30913
  }
30745
30914
  }
30746
30915
  normalizeScenarios(scenarios, categoryThereOf, order, intervalBuckets = []) {
30747
- var _a, _b;
30916
+ var _a;
30748
30917
  const normalizedScenarios = [];
30918
+ // the arrow marks the first scenario or variance token; a bucket only counts under interval setname
30919
+ const sortToken = (_a = order === null || order === void 0 ? void 0 : order.hierarchy) === null || _a === void 0 ? void 0 : _a.map((entry) => withStyled.parseOrderToken(entry)).find((token) => (token === null || token === void 0 ? void 0 : token.kind) !== "dim");
30920
+ const sortBucket = this.config.interval === INTERVAL_SETNAME ? sortToken === null || sortToken === void 0 ? void 0 : sortToken.bucket : undefined;
30921
+ const sortDirection = (scenario, bucket) => {
30922
+ var _a;
30923
+ return sortToken != null &&
30924
+ ((_a = withStyled.parseOrderToken(scenario)) === null || _a === void 0 ? void 0 : _a.column) === sortToken.column &&
30925
+ (sortBucket === undefined || sortBucket === bucket)
30926
+ ? order.direction
30927
+ : undefined;
30928
+ };
30749
30929
  if (intervalBuckets.length > 0) {
30750
30930
  for (const bucket of intervalBuckets) {
30751
30931
  for (const scenario of scenarios) {
@@ -30753,7 +30933,7 @@ class Table {
30753
30933
  name: scenario,
30754
30934
  group: scenario,
30755
30935
  type: scenario,
30756
- order: ((_a = order === null || order === void 0 ? void 0 : order.hierarchy) === null || _a === void 0 ? void 0 : _a.at(0)) === scenario ? order.direction : undefined,
30936
+ order: sortDirection(scenario, bucket.key),
30757
30937
  bucket: bucket.key,
30758
30938
  bucketLabel: bucket.label,
30759
30939
  });
@@ -30782,17 +30962,31 @@ class Table {
30782
30962
  }
30783
30963
  normalizedScenarios.push({ name: "REST", group: "REST", type: scenario, order: undefined });
30784
30964
  }
30785
- let orderDirection = undefined;
30786
- if (((_b = order === null || order === void 0 ? void 0 : order.hierarchy) === null || _b === void 0 ? void 0 : _b.at(0)) === scenario) {
30787
- orderDirection = order.direction;
30788
- }
30789
- normalizedScenarios.push({ name: scenario, group: scenario, type: scenario, order: orderDirection });
30965
+ normalizedScenarios.push({ name: scenario, group: scenario, type: scenario, order: sortDirection(scenario) });
30790
30966
  }
30791
30967
  return normalizedScenarios;
30792
30968
  }
30793
30969
  hasNoData() {
30794
30970
  return this.rowCount === 0;
30795
30971
  }
30972
+ /** Warning for an order `@bucket` that cannot apply, once the body was built; undefined when all apply. */
30973
+ orderBucketWarning() {
30974
+ var _a, _b;
30975
+ if (this.hasNoData() || this.state !== FactoryState$1.UP_TO_DATE) {
30976
+ return undefined;
30977
+ }
30978
+ const buckets = ((_b = (_a = this.config.sortOrder) === null || _a === void 0 ? void 0 : _a.hierarchy) !== null && _b !== void 0 ? _b : [])
30979
+ .map((entry) => { var _a; return (_a = withStyled.parseOrderToken(entry)) === null || _a === void 0 ? void 0 : _a.bucket; })
30980
+ .filter((bucket) => bucket !== undefined);
30981
+ if (buckets.length === 0) {
30982
+ return undefined;
30983
+ }
30984
+ if (this.config.interval !== INTERVAL_SETNAME) {
30985
+ return `order: '@${buckets[0]}' needs interval setname, the bucket is ignored.`;
30986
+ }
30987
+ const unknown = buckets.find((bucket) => !this.intervalBuckets.some((b) => b.key === bucket));
30988
+ return unknown === undefined ? undefined : `order: setname '${unknown}' not found, the rows are not sorted by it.`;
30989
+ }
30796
30990
  /** True once the body was built and the grouped table has rows with a blank rowGroup. */
30797
30991
  hasBlankRowGroup() {
30798
30992
  return this.dataSetFactory.hasBlankRowGroup;
@@ -31070,6 +31264,7 @@ const BnTableRenderer = class {
31070
31264
  /** @internal */
31071
31265
  this.scaleFactor = 1;
31072
31266
  this.componentDataFormatDigits = new DataFormatDigits();
31267
+ this.barColumnLayouts = new Map();
31073
31268
  withHasError.withComponentStatus(this);
31074
31269
  this.componentStyle = withStyled.withComponentStyle(this);
31075
31270
  }
@@ -31190,19 +31385,20 @@ const BnTableRenderer = class {
31190
31385
  return index.h("div", { class: "empty-state" }, errorMsg);
31191
31386
  }
31192
31387
  const locale = (_d = (_c = (_b = this.stores) === null || _b === void 0 ? void 0 : _b.context) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.locale;
31193
- return (index.h("table", null, index.h("thead", null, this.table.getHeader().map((row) => (index.h("tr", { class: row.cssStyle }, row.getCells().map((cell) => (index.h("th", { colSpan: cell.colSpan, class: cell.cssStyle }, cell.getAsHeaderList().map((line, i, arr) => (index.h("span", null, i === arr.length - 1 ? (index.h("span", { class: line === " " ? "table-footer" : "" }, line, cell.drawPrefix(), " ")) : (index.h("span", null, line, cell.drawPrefix(), index.h("br", null))))))))))))), index.h("tbody", null, this.table.getBody().map((row) => (index.h("tr", Object.assign({ class: row.cssStyle }, dataPointAttributes(row.key, "element")), row === null || row === void 0 ? void 0 : row.getCells().map((cell) => (index.h("td", Object.assign({ colSpan: cell.colSpan, class: cell.type ? `${cell.cssStyle} ${cell.type}` : cell.cssStyle }, (row.key && cell.value != null && cell.value !== "" && cell.value !== "-"
31194
- ? dataPointAttributes(Object.assign(Object.assign({}, row.key), { date: cell.date, scenario: cell.key }), "element")
31195
- : {})), cell.prefix != null ? (index.h("span", { class: cell.cssStyle + " " + cell.prefixStyle }, cell.drawPrefix())) : (""), cell.isBarChart &&
31196
- cell.columnStats &&
31197
- cell.value !== withStyled.NOT_AVAILABLE &&
31198
- (cell.waterfall !== undefined || row.type !== TableRowType.SUM) ? (cell.waterfall !== undefined ? (index.h(WaterfallBar, { value: cell.value, scenario: cell.key, columnStats: cell.columnStats, height: 18 * this.scaleFactor, isRelative: false, isPositiveGood: cell.direction === "pos", measureScale: cell.measureScale, locale: locale, columnWidthEm: this.barColumnMaxWidth, styles: this.barChartStyles, waterfall: cell.waterfall })) : (index.h(CellBarChart, { value: cell.value, scenario: cell.key, columnStats: cell.columnStats, height: 18 * this.scaleFactor, isRelative: cell.key.startsWith("dr"), isPositiveGood: cell.direction === "pos",
31199
- // percentage points: the fraction times 100, no measure scale
31200
- measureScale: cell.type === "percentpoint" ? 0.01 : cell.measureScale, locale: locale, percentDigits: this.componentDataFormatDigits.percent, columnWidthEm: this.barColumnMaxWidth, styles: this.barChartStyles }))) : (cell.draw(this.componentDataFormatDigits, locale)))))))))));
31388
+ return (index.h("table", null, index.h("thead", null, this.table.getHeader().map((row) => (index.h("tr", { class: row.cssStyle }, row.getCells().map((cell) => (index.h("th", { colSpan: cell.colSpan, class: cell.cssStyle }, cell.getAsHeaderList().map((line, i, arr) => (index.h("span", null, i === arr.length - 1 ? (index.h("span", { class: line === " " ? "table-footer" : "" }, line, cell.drawPrefix(), " ")) : (index.h("span", null, line, cell.drawPrefix(), index.h("br", null))))))))))))), index.h("tbody", null, this.table.getBody().map((row) => (index.h("tr", Object.assign({ class: row.cssStyle }, dataPointAttributes(row.key, "element")), row === null || row === void 0 ? void 0 : row.getCells().map((cell) => {
31389
+ var _a, _b, _c, _d;
31390
+ return (index.h("td", Object.assign({ colSpan: cell.colSpan, class: cell.type ? `${cell.cssStyle} ${cell.type}` : cell.cssStyle }, (row.key && cell.value != null && cell.value !== "" && cell.value !== "-"
31391
+ ? dataPointAttributes(Object.assign(Object.assign({}, row.key), { date: cell.date, scenario: cell.key }), "element")
31392
+ : {})), cell.prefix != null ? (index.h("span", { class: cell.cssStyle + " " + cell.prefixStyle }, cell.drawPrefix())) : (""), cell.isBarChart &&
31393
+ cell.columnStats &&
31394
+ cell.value !== withStyled.NOT_AVAILABLE &&
31395
+ (cell.waterfall !== undefined || row.type !== TableRowType.SUM) ? (cell.waterfall !== undefined ? (index.h(WaterfallBar, { value: cell.value, scenario: cell.key, columnStats: cell.columnStats, height: 18 * this.scaleFactor, isRelative: false, isPositiveGood: cell.direction === "pos", measureScale: cell.measureScale, locale: locale, columnWidthEm: this.barColumnMaxWidth, styles: this.barChartStyles, waterfall: cell.waterfall })) : (index.h(CellBarChart, { value: cell.value, scenario: cell.key, columnStats: cell.columnStats, height: 18 * this.scaleFactor, isRelative: cell.key.startsWith("dr"), isPositiveGood: cell.direction === "pos", measureScale: barLabelMeasureScale(cell), locale: locale, percentDigits: (_b = (_a = this.barColumnLayouts.get(cell.key)) === null || _a === void 0 ? void 0 : _a.percentDigits) !== null && _b !== void 0 ? _b : this.componentDataFormatDigits.percent, percentSign: (_c = this.barColumnLayouts.get(cell.key)) === null || _c === void 0 ? void 0 : _c.percentSign, columnWidthEm: this.barColumnMaxWidth, labelWidths: (_d = this.barColumnLayouts.get(cell.key)) === null || _d === void 0 ? void 0 : _d.labels, styles: this.barChartStyles }))) : (cell.draw(this.componentDataFormatDigits, locale))));
31396
+ })))))));
31201
31397
  };
31202
31398
  return index.h(index.Host, { class: { "no-data": ((_a = this.table) === null || _a === void 0 ? void 0 : _a.hasNoData()) === true } }, helper());
31203
31399
  }
31204
31400
  componentWillRender() {
31205
- var _a, _b, _c, _d, _e;
31401
+ var _a, _b, _c, _d, _e, _f, _g, _h;
31206
31402
  if (!this.stores)
31207
31403
  this.stores = withHasError.getStores(this.element);
31208
31404
  const db = this.stores.db.db;
@@ -31235,12 +31431,20 @@ const BnTableRenderer = class {
31235
31431
  else {
31236
31432
  (_e = this.errors) === null || _e === void 0 ? void 0 : _e.remove("WARN_blankRowGroup");
31237
31433
  }
31434
+ const orderBucketWarning = (_f = this.table) === null || _f === void 0 ? void 0 : _f.orderBucketWarning();
31435
+ if (orderBucketWarning) {
31436
+ (_g = this.errors) === null || _g === void 0 ? void 0 : _g.addOrReplace({ id: "WARN_orderBucket", type: "warning", message: orderBucketWarning });
31437
+ }
31438
+ else {
31439
+ (_h = this.errors) === null || _h === void 0 ? void 0 : _h.remove("WARN_orderBucket");
31440
+ }
31441
+ this.barColumnLayouts = this.collectBarColumnLayouts();
31238
31442
  this.barChartStyles = this.prepareBarChartStyles();
31239
31443
  }
31240
31444
  prepareConfig(db) {
31241
31445
  var _a, _b, _c;
31242
31446
  const fromExpr = withHasError.sourceExpr(db, this.tableName, this.filter);
31243
- const config = new TableComponentConfigAdapter(new TableDrillGroupAdapter(), new StringAdapter(), new withStyled.OrderAdapter(new StringAdapter()), db, fromExpr,
31447
+ const config = new TableComponentConfigAdapter(new TableDrillGroupAdapter(), new StringAdapter(), new withStyled.OrderAdapter(new StringAdapter(), true), db, fromExpr,
31244
31448
  // a failed measure-scale query ends in the ERR_sql of componentWillRender
31245
31449
  (e) => {
31246
31450
  throw e;
@@ -31357,67 +31561,106 @@ const BnTableRenderer = class {
31357
31561
  /**
31358
31562
  * Auto-calculate unitScaling so the largest absolute variance bar
31359
31563
  * fills ~80% of its side of the bar area, without tripping the overdrive break.
31564
+ * One scaling for all columns, so it is the smallest that fits every column.
31360
31565
  */
31361
31566
  autoUnitScaling() {
31362
31567
  const emPx = this.emPx();
31363
31568
  const fs = emPx * BAR_LABEL_FONT_RATIO;
31364
- const { absMax, hasNeg, hasPos } = this.getAbsBarColumnStats();
31365
- if (absMax <= 0 || fs <= 0) {
31366
- return 0.01;
31569
+ let scaling = Infinity;
31570
+ for (const { isRelative, absMax, labels } of this.barColumnLayouts.values()) {
31571
+ if (isRelative || absMax <= 0)
31572
+ continue;
31573
+ const { maxBarWidth, cutWidth } = absoluteBarGeometry(this.barColumnMaxWidth, emPx, labels);
31574
+ scaling = Math.min(scaling, Math.min(maxBarWidth * 0.8, cutWidth) / (absMax * fs));
31367
31575
  }
31368
- const { maxBarWidth, cutWidth } = absoluteBarGeometry(this.barColumnMaxWidth, emPx, hasNeg, hasPos);
31369
- const targetWidth = Math.min(maxBarWidth * 0.8, cutWidth);
31370
- return targetWidth / (absMax * fs);
31576
+ return Number.isFinite(scaling) && fs > 0 ? scaling : 0.01;
31371
31577
  }
31372
31578
  /**
31373
- * Auto-calculate percentageScaling so the largest relative variance pin
31374
- * fills ~80% of the pin area.
31579
+ * Auto-calculate percentageScaling so the longest relative variance pin, its head and
31580
+ * its label exactly fill the column. One scaling for all columns, the smallest that fits.
31375
31581
  */
31376
31582
  autoPercentageScaling() {
31377
31583
  const emPx = this.emPx();
31378
31584
  const fs = emPx * BAR_LABEL_FONT_RATIO;
31379
- const { absMax: maxPct, hasNeg, hasPos } = this.getRelativeBarColumnStats();
31380
- if (maxPct <= 0 || fs <= 0) {
31381
- return 0.5;
31585
+ let scaling = Infinity;
31586
+ for (const { isRelative, absMax, labels } of this.barColumnLayouts.values()) {
31587
+ if (!isRelative || absMax <= 0)
31588
+ continue;
31589
+ const headSize = PIN_HEAD_SIZE * this.scaleFactor;
31590
+ const { maxPinLength } = relativePinGeometry(this.barColumnMaxWidth, emPx, labels, headSize);
31591
+ scaling = Math.min(scaling, maxPinLength / (absMax * fs));
31382
31592
  }
31383
- const { maxPinLength } = relativePinGeometry(this.barColumnMaxWidth, emPx, hasNeg, hasPos);
31384
- return (maxPinLength * 0.8) / (maxPct * fs);
31593
+ return Number.isFinite(scaling) && fs > 0 ? scaling : 0.5;
31385
31594
  }
31386
31595
  /**
31387
- * Maximum value and sign coverage across all absolute variance columns (d_*) in the table body.
31388
- * Sign coverage decides how much of the column the bar area gets (see barColumnGeometry.ts);
31389
- * OR-ing it across columns keeps the single shared scaling inside the narrowest bar area.
31596
+ * Largest value and widest label per side of every bar and pin column, from the cells
31597
+ * that draw one: total rows and n/a draw none. Interval buckets share the column key,
31598
+ * so they share the layout and the axis.
31390
31599
  */
31391
- getAbsBarColumnStats() {
31392
- // waterfall cells scale independently and must not skew variance auto-scaling
31393
- return this.collectBarColumnStats((cell) => !cell.key.startsWith("dr") && !cell.waterfall, 1);
31394
- }
31395
- /**
31396
- * Same for the relative variance columns (dr_*). Values are stored as decimals
31397
- * (e.g. 0.2 = 20%), returned as percentage (20).
31398
- */
31399
- getRelativeBarColumnStats() {
31400
- return this.collectBarColumnStats((cell) => cell.key.startsWith("dr"), 100);
31401
- }
31402
- collectBarColumnStats(accept, valueFactor) {
31403
- const stats = { absMax: 0, hasNeg: false, hasPos: false };
31404
- if (!this.table)
31405
- return stats;
31600
+ collectBarColumnLayouts() {
31601
+ var _a, _b, _c, _d;
31602
+ const layouts = new Map();
31603
+ if (!this.table || this.table.hasNoData())
31604
+ return layouts;
31605
+ const cellsByKey = new Map();
31406
31606
  for (const row of this.table.getBody()) {
31407
31607
  if (row.type === TableRowType.SUM)
31408
31608
  continue;
31409
31609
  for (const cell of row.getCells()) {
31410
- if (!cell.isBarChart || !cell.columnStats || !accept(cell))
31610
+ // waterfall cells scale independently
31611
+ if (!cell.isBarChart || !cell.columnStats || cell.waterfall !== undefined)
31612
+ continue;
31613
+ if (typeof cell.value !== "number" || isNaN(cell.value))
31411
31614
  continue;
31412
- stats.absMax = Math.max(stats.absMax, cell.columnStats.absMax * valueFactor);
31413
- stats.hasNeg = stats.hasNeg || cell.columnStats.min < 0;
31414
- stats.hasPos = stats.hasPos || cell.columnStats.max > 0;
31615
+ cellsByKey.set(cell.key, [...((_a = cellsByKey.get(cell.key)) !== null && _a !== void 0 ? _a : []), cell]);
31415
31616
  }
31416
31617
  }
31417
- return stats;
31618
+ const emPx = this.emPx();
31619
+ const fs = emPx * BAR_LABEL_FONT_RATIO;
31620
+ const headSize = PIN_HEAD_SIZE * this.scaleFactor;
31621
+ const locale = (_d = (_c = (_b = this.stores) === null || _b === void 0 ? void 0 : _b.context) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.locale;
31622
+ for (const [key, cells] of cellsByKey) {
31623
+ const isRelative = key.startsWith("dr");
31624
+ const values = cells.map((cell) => cell.value);
31625
+ const measure = (percentDigits, percentSign) => {
31626
+ var _a;
31627
+ const labels = {
31628
+ neg: values.some((value) => value < 0) ? 0 : undefined,
31629
+ pos: values.some((value) => value > 0) ? 0 : undefined,
31630
+ };
31631
+ const zeroPositive = zeroOnPositiveSide(labels);
31632
+ for (const cell of cells) {
31633
+ const value = cell.value;
31634
+ const side = value > 0 || (value === 0 && zeroPositive) ? "pos" : "neg";
31635
+ const text = formatValue(value, isRelative, barLabelMeasureScale(cell), locale, percentDigits, percentSign);
31636
+ labels[side] = Math.max((_a = labels[side]) !== null && _a !== void 0 ? _a : 0, estimateLabelWidth(text, fs));
31637
+ }
31638
+ return labels;
31639
+ };
31640
+ // a narrow pin column drops percent digits, then the %, so every label keeps its sign
31641
+ let percentDigits = Math.min(20, Math.max(0, Math.trunc(this.componentDataFormatDigits.percent) || 0));
31642
+ let percentSign = true;
31643
+ let labels = measure(percentDigits, percentSign);
31644
+ while (isRelative && (percentDigits > 0 || percentSign)) {
31645
+ if (pinLabelsFit(this.barColumnMaxWidth, emPx, labels, headSize))
31646
+ break;
31647
+ if (percentDigits > 0)
31648
+ percentDigits--;
31649
+ else
31650
+ percentSign = false;
31651
+ labels = measure(percentDigits, percentSign);
31652
+ }
31653
+ const absMax = Math.max(...values.map(Math.abs)) * (isRelative ? 100 : 1);
31654
+ layouts.set(key, { isRelative, absMax, labels, percentDigits, percentSign });
31655
+ }
31656
+ return layouts;
31418
31657
  }
31419
31658
  get element() { return index.getElement(this); }
31420
31659
  };
31660
+ /** Percentage points: the fraction times 100, no measure scale. */
31661
+ function barLabelMeasureScale(cell) {
31662
+ return cell.type === "percentpoint" ? 0.01 : cell.measureScale;
31663
+ }
31421
31664
  BnTableRenderer.style = bnTableRendererCss();
31422
31665
 
31423
31666
  const bnTitleCss = () => `:host{padding:0.5em;margin-bottom:0.5em;box-sizing:border-box;-webkit-box-sizing:border-box;width:100%;display:block;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px);color:var(--bn-font-color, #000000)}`;