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

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 (23) 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 → p-e15ccc4a.entry.js} +1 -1
  3. package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +221 -53
  4. package/dist/collection/components/bn-table/bn-table-renderer/bn-table-renderer.js +55 -15
  5. package/dist/collection/components/bn-table/bn-table.js +5 -2
  6. package/dist/collection/components/bn-table/utils/elements/CellBarChart.js +25 -15
  7. package/dist/collection/components/bn-table/utils/elements/WaterfallBar.js +2 -2
  8. package/dist/collection/components/bn-table/utils/helper/DataQuery.js +24 -10
  9. package/dist/collection/components/bn-table/utils/helper/WaterfallCalculator.js +9 -3
  10. package/dist/collection/components/bn-table/utils/helper/barColumnGeometry.js +105 -10
  11. package/dist/components/bn-table-renderer.js +1 -1
  12. package/dist/components/bn-table.js +1 -1
  13. package/dist/components/p--HIZm_2v.js +1 -0
  14. package/dist/esm/bn-annotation-layer_30.entry.js +221 -53
  15. package/dist/types/components/bn-table/bn-table-renderer/bn-table-renderer.d.ts +5 -0
  16. package/dist/types/components/bn-table/bn-table.d.ts +3 -0
  17. package/dist/types/components/bn-table/utils/elements/CellBarChart.d.ts +7 -2
  18. package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +1 -0
  19. package/dist/types/components/bn-table/utils/helper/WaterfallCalculator.d.ts +5 -2
  20. package/dist/types/components/bn-table/utils/helper/barColumnGeometry.d.ts +31 -8
  21. package/dist/types/components.d.ts +2 -2
  22. package/package.json +1 -1
  23. package/dist/components/p-CLilvhjH.js +0 -1
@@ -1,4 +1,4 @@
1
- import { h, Host } from "@stencil/core";
1
+ import { forceUpdate, h, Host } from "@stencil/core";
2
2
  import { OrderDirection, TableRowType, TableType } from "../utils/model";
3
3
  import { dataPointAttributes, measure, measureContent, measureSign, readLayoutPoint, } from "../../../utils/layoutState";
4
4
  import { Table } from "../utils/Table";
@@ -15,7 +15,7 @@ import withComponentStatus from "../../../utils/withComponentStatus";
15
15
  import withComponentStyle from "../../../utils/withComponentStyle";
16
16
  import { getStores } from "../../../context/context-protocol";
17
17
  import { sourceExpr } from "../../../context/scopedDb";
18
- import { absoluteBarGeometry, BAR_LABEL_FONT_RATIO, estimateLabelWidth, PIN_HEAD_SIZE, pinLabelsFit, relativePinGeometry, } from "../utils/helper/barColumnGeometry";
18
+ import { absoluteBarGeometry, BAR_LABEL_FONT_RATIO, labelWidth, PIN_HEAD_SIZE, pinLabelsFit, relativePinGeometry, } from "../utils/helper/barColumnGeometry";
19
19
  import { NOT_AVAILABLE } from "../../../utils/relativeVariance";
20
20
  import { normalizeFillPattern } from "../../../utils/model/styles/SVGStyle";
21
21
  /**
@@ -109,9 +109,22 @@ export class BnTableRenderer {
109
109
  this.scaleFactor = 1;
110
110
  this.componentDataFormatDigits = new DataFormatDigits();
111
111
  this.barColumnLayouts = new Map();
112
+ // labels measured in the fallback font are too narrow or too wide once the web font is there: lay out again
113
+ this.relayout = () => {
114
+ if (this.barColumnLayouts.size > 0)
115
+ forceUpdate(this);
116
+ };
112
117
  withComponentStatus(this);
113
118
  this.componentStyle = withComponentStyle(this);
114
119
  }
120
+ connectedCallback() {
121
+ var _a;
122
+ (_a = document.fonts) === null || _a === void 0 ? void 0 : _a.addEventListener("loadingdone", this.relayout);
123
+ }
124
+ disconnectedCallback() {
125
+ var _a;
126
+ (_a = document.fonts) === null || _a === void 0 ? void 0 : _a.removeEventListener("loadingdone", this.relayout);
127
+ }
115
128
  /**
116
129
  * Collects the table's layout-state contribution: header/body regions,
117
130
  * counts, and - with `detail: "full"` - per-cell geometry paired with the
@@ -230,13 +243,15 @@ export class BnTableRenderer {
230
243
  }
231
244
  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;
232
245
  return (h("table", null, h("thead", null, this.table.getHeader().map((row) => (h("tr", { class: row.cssStyle }, row.getCells().map((cell) => (h("th", { colSpan: cell.colSpan, class: cell.cssStyle }, cell.getAsHeaderList().map((line, i, arr) => (h("span", null, i === arr.length - 1 ? (h("span", { class: line === " " ? "table-footer" : "" }, line, cell.drawPrefix(), " ")) : (h("span", null, line, cell.drawPrefix(), h("br", null))))))))))))), h("tbody", null, this.table.getBody().map((row) => (h("tr", Object.assign({ class: row.cssStyle }, dataPointAttributes(row.key, "element")), row === null || row === void 0 ? void 0 : row.getCells().map((cell) => {
233
- var _a, _b, _c, _d;
246
+ var _a, _b, _c, _d, _e;
234
247
  return (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 !== "-"
235
248
  ? dataPointAttributes(Object.assign(Object.assign({}, row.key), { date: cell.date, scenario: cell.key }), "element")
236
249
  : {})), cell.prefix != null ? (h("span", { class: cell.cssStyle + " " + cell.prefixStyle }, cell.drawPrefix())) : (""), cell.isBarChart &&
237
250
  cell.columnStats &&
238
251
  cell.value !== NOT_AVAILABLE &&
239
- (cell.waterfall !== undefined || row.type !== TableRowType.SUM) ? (cell.waterfall !== undefined ? (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 })) : (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))));
252
+ // an untitled group head is only a gap between list groups, a bar cell would print "-" in it
253
+ (this.showGroupTitle || row.type !== TableRowType.HEADER) &&
254
+ (cell.waterfall !== undefined || row.type !== TableRowType.SUM) ? (cell.waterfall !== undefined ? (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, decimalDigits: barLabelDigits(cell, this.componentDataFormatDigits), columnWidthEm: this.barColumnMaxWidth, styles: this.barChartStyles, waterfall: cell.waterfall })) : (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, decimalDigits: barLabelDigits(cell, this.componentDataFormatDigits), 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, sideMax: (_e = this.barColumnLayouts.get(cell.key)) === null || _e === void 0 ? void 0 : _e.sideMax, styles: this.barChartStyles }))) : (cell.draw(this.componentDataFormatDigits, locale))));
240
255
  })))))));
241
256
  };
242
257
  return h(Host, { class: { "no-data": ((_a = this.table) === null || _a === void 0 ? void 0 : _a.hasNoData()) === true } }, helper());
@@ -337,7 +352,7 @@ export class BnTableRenderer {
337
352
  });
338
353
  }
339
354
  return this.componentStyle(($) => {
340
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
355
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
341
356
  const varianceStyles = (_a = $["bn-chart-time"]) === null || _a === void 0 ? void 0 : _a["varianceStyles"];
342
357
  const barStyles = (_b = $["bn-chart-time"]) === null || _b === void 0 ? void 0 : _b["barStyles"];
343
358
  // Default variance styles with fillpattern
@@ -391,13 +406,17 @@ export class BnTableRenderer {
391
406
  fontColor: ((_z = $["global"]) === null || _z === void 0 ? void 0 : _z["fontColor"]) || "#000000",
392
407
  fontSize: (((_0 = $["global"]) === null || _0 === void 0 ? void 0 : _0["fontSizePx"]) || 13.3333) * BAR_LABEL_FONT_RATIO * this.scaleFactor,
393
408
  emPx: (((_1 = $["global"]) === null || _1 === void 0 ? void 0 : _1["fontSizePx"]) || 13.3333) * this.scaleFactor,
394
- fontFamily: ((_2 = $["global"]) === null || _2 === void 0 ? void 0 : _2["fontFamily"]) || "'Noto Sans', sans-serif",
409
+ fontFamily: this.labelFontFamily(),
395
410
  unitScaling: resolvedUnit,
396
411
  percentageScaling: resolvedPercent,
397
412
  scaleFactor: this.scaleFactor,
398
413
  };
399
414
  });
400
415
  }
416
+ /** Font family of the bar and pin labels, also used to measure them. */
417
+ labelFontFamily() {
418
+ return this.componentStyle(($) => { var _a; return ((_a = $["global"]) === null || _a === void 0 ? void 0 : _a["fontFamily"]) || "'Noto Sans', sans-serif"; });
419
+ }
401
420
  /** The table's true em in px - the unit `.category-wN` and the bar columns share. */
402
421
  emPx() {
403
422
  return this.componentStyle(($) => { var _a; return ((_a = $["global"]) === null || _a === void 0 ? void 0 : _a["fontSizePx"]) || 13.3333; }) * this.scaleFactor;
@@ -408,14 +427,21 @@ export class BnTableRenderer {
408
427
  * One scaling for all columns, so it is the smallest that fits every column.
409
428
  */
410
429
  autoUnitScaling() {
430
+ var _a;
411
431
  const emPx = this.emPx();
412
432
  const fs = emPx * BAR_LABEL_FONT_RATIO;
413
433
  let scaling = Infinity;
414
- for (const { isRelative, absMax, labels } of this.barColumnLayouts.values()) {
434
+ for (const { isRelative, absMax, labels, sideMax } of this.barColumnLayouts.values()) {
415
435
  if (isRelative || absMax <= 0)
416
436
  continue;
417
- const { maxBarWidth, cutWidth } = absoluteBarGeometry(this.barColumnMaxWidth, emPx, labels);
418
- scaling = Math.min(scaling, Math.min(maxBarWidth * 0.8, cutWidth) / (absMax * fs));
437
+ const geometry = absoluteBarGeometry(this.barColumnMaxWidth, emPx, labels, sideMax);
438
+ for (const side of ["neg", "pos"]) {
439
+ const max = (_a = sideMax[side]) !== null && _a !== void 0 ? _a : 0;
440
+ if (max <= 0)
441
+ continue;
442
+ const { maxBarWidth, cutWidth } = geometry[side];
443
+ scaling = Math.min(scaling, Math.min(maxBarWidth * 0.8, cutWidth) / (max * fs));
444
+ }
419
445
  }
420
446
  return Number.isFinite(scaling) && fs > 0 ? scaling : 0.01;
421
447
  }
@@ -424,15 +450,18 @@ export class BnTableRenderer {
424
450
  * its label exactly fill the column. One scaling for all columns, the smallest that fits.
425
451
  */
426
452
  autoPercentageScaling() {
453
+ var _a, _b;
427
454
  const emPx = this.emPx();
428
455
  const fs = emPx * BAR_LABEL_FONT_RATIO;
429
456
  let scaling = Infinity;
430
- for (const { isRelative, absMax, labels } of this.barColumnLayouts.values()) {
457
+ for (const { isRelative, absMax, labels, sideMax } of this.barColumnLayouts.values()) {
431
458
  if (!isRelative || absMax <= 0)
432
459
  continue;
433
460
  const headSize = PIN_HEAD_SIZE * this.scaleFactor;
434
- const { maxPinLength } = relativePinGeometry(this.barColumnMaxWidth, emPx, labels, headSize);
435
- scaling = Math.min(scaling, maxPinLength / (absMax * fs));
461
+ // the longest pins of both sides share the room, each side takes what its pins need
462
+ const { negPinLength, posPinLength } = relativePinGeometry(this.barColumnMaxWidth, emPx, labels, headSize);
463
+ const percent = (((_a = sideMax.neg) !== null && _a !== void 0 ? _a : 0) + ((_b = sideMax.pos) !== null && _b !== void 0 ? _b : 0)) * 100;
464
+ scaling = Math.min(scaling, (negPinLength + posPinLength) / (percent * fs));
436
465
  }
437
466
  return Number.isFinite(scaling) && fs > 0 ? scaling : 0.5;
438
467
  }
@@ -463,6 +492,7 @@ export class BnTableRenderer {
463
492
  const fs = emPx * BAR_LABEL_FONT_RATIO;
464
493
  const headSize = PIN_HEAD_SIZE * this.scaleFactor;
465
494
  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;
495
+ const fontFamily = this.labelFontFamily();
466
496
  for (const [key, cells] of cellsByKey) {
467
497
  const isRelative = key.startsWith("dr");
468
498
  const values = cells.map((cell) => cell.value);
@@ -476,8 +506,8 @@ export class BnTableRenderer {
476
506
  for (const cell of cells) {
477
507
  const value = cell.value;
478
508
  const side = value > 0 || (value === 0 && zeroPositive) ? "pos" : "neg";
479
- const text = formatValue(value, isRelative, barLabelMeasureScale(cell), locale, percentDigits, percentSign);
480
- labels[side] = Math.max((_a = labels[side]) !== null && _a !== void 0 ? _a : 0, estimateLabelWidth(text, fs));
509
+ const text = formatValue(value, isRelative, barLabelMeasureScale(cell), locale, percentDigits, percentSign, barLabelDigits(cell, this.componentDataFormatDigits));
510
+ labels[side] = Math.max((_a = labels[side]) !== null && _a !== void 0 ? _a : 0, labelWidth(text, fs, fontFamily, isRelative));
481
511
  }
482
512
  return labels;
483
513
  };
@@ -495,7 +525,11 @@ export class BnTableRenderer {
495
525
  labels = measure(percentDigits, percentSign);
496
526
  }
497
527
  const absMax = Math.max(...values.map(Math.abs)) * (isRelative ? 100 : 1);
498
- layouts.set(key, { isRelative, absMax, labels, percentDigits, percentSign });
528
+ const sideMax = {
529
+ neg: labels.neg === undefined ? undefined : Math.max(0, ...values.map((value) => -value)),
530
+ pos: labels.pos === undefined ? undefined : Math.max(0, ...values),
531
+ };
532
+ layouts.set(key, { isRelative, absMax, labels, sideMax, percentDigits, percentSign });
499
533
  }
500
534
  return layouts;
501
535
  }
@@ -1430,3 +1464,9 @@ export class BnTableRenderer {
1430
1464
  function barLabelMeasureScale(cell) {
1431
1465
  return cell.type === "percentpoint" ? 0.01 : cell.measureScale;
1432
1466
  }
1467
+ /** Fraction digits of the number cells of the column, so an absolute bar label prints like them. */
1468
+ function barLabelDigits(cell, digits) {
1469
+ if (cell.type === "percentpoint")
1470
+ return digits.percent;
1471
+ return cell.type === "decimal" ? digits.decimal : undefined;
1472
+ }
@@ -210,6 +210,9 @@ export class Table {
210
210
  * inside each group, the groups keep their rowgroupindex order. With a variance or `@`, rows without data
211
211
  * (and a relative variance with a zero reference) sort last.
212
212
  * <br /><br />
213
+ * A data row with the category `REST` is the rest row of its group: sorted by a scenario or variance it stays
214
+ * the last row of the group. Its label comes from the `REST` translation.
215
+ * <br /><br />
213
216
  * When set to ```auto```, order is detected from the dataset silently.
214
217
  */
215
218
  this.order = "category";
@@ -1339,7 +1342,7 @@ export class Table {
1339
1342
  render() {
1340
1343
  const fontStyles = this.getFontStyles();
1341
1344
  const effectiveFactor = this.getEffectiveScaleFactor();
1342
- return (h(Host, { key: '2f24deddc4e58f57ef27443a27b4706b5f1b90db', style: fontStyles }, h("div", { key: 'b6368e143f868d9c2a7ad8ec753a14813b60e197' }, 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 }))));
1345
+ return (h(Host, { key: '42974a4931f678c35e5c740bf6d630966368fb4b', style: fontStyles }, h("div", { key: '2c8f99a8bd155e2c93e55e9542090d04afe22a31' }, h("bn-table-renderer", { key: 'cae9e83bf297e730f12a8a390cbf279413c40b54', 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 }))));
1343
1346
  }
1344
1347
  static get is() { return "bn-table"; }
1345
1348
  static get encapsulation() { return "shadow"; }
@@ -1814,7 +1817,7 @@ export class Table {
1814
1817
  "optional": false,
1815
1818
  "docs": {
1816
1819
  "tags": [],
1817
- "text": "Comma list of the columns the rows are sorted by, left to right. `orderDirection` applies to all of them.\n<br /><br />\nvalues: <br />\n```category // categoryindex // rowgroup // rowgroupindex // subcategory // subcategoryindex // ac[1-4] // fc[1-4] // pp[1-4] // pl[1-4] // auto```\n<br />\nor a variance, written like a scenario column, the sentiment is optional and ignored: ```dac1_pp1```, ```drfc1_pp1_pos```\n<br /><br />\nWith `interval=\"setname\"` a scenario or variance can name one bucket after `@`: ```dac1_pp1@_November``` sorts\nby that block only. Without a bucket the sum over all buckets is used.\n<br /><br />\nThe scenario or variance does not have to be a shown column; the sort arrow appears only on a shown one.\nA plain scenario also sorts the row groups by their sum. A variance or a token with `@` sorts only the rows\ninside each group, the groups keep their rowgroupindex order. With a variance or `@`, rows without data\n(and a relative variance with a zero reference) sort last.\n<br /><br />\nWhen set to ```auto```, order is detected from the dataset silently."
1820
+ "text": "Comma list of the columns the rows are sorted by, left to right. `orderDirection` applies to all of them.\n<br /><br />\nvalues: <br />\n```category // categoryindex // rowgroup // rowgroupindex // subcategory // subcategoryindex // ac[1-4] // fc[1-4] // pp[1-4] // pl[1-4] // auto```\n<br />\nor a variance, written like a scenario column, the sentiment is optional and ignored: ```dac1_pp1```, ```drfc1_pp1_pos```\n<br /><br />\nWith `interval=\"setname\"` a scenario or variance can name one bucket after `@`: ```dac1_pp1@_November``` sorts\nby that block only. Without a bucket the sum over all buckets is used.\n<br /><br />\nThe scenario or variance does not have to be a shown column; the sort arrow appears only on a shown one.\nA plain scenario also sorts the row groups by their sum. A variance or a token with `@` sorts only the rows\ninside each group, the groups keep their rowgroupindex order. With a variance or `@`, rows without data\n(and a relative variance with a zero reference) sort last.\n<br /><br />\nA data row with the category `REST` is the rest row of its group: sorted by a scenario or variance it stays\nthe last row of the group. Its label comes from the `REST` translation.\n<br /><br />\nWhen set to ```auto```, order is detected from the dataset silently."
1818
1821
  },
1819
1822
  "getter": false,
1820
1823
  "setter": false,
@@ -1,7 +1,7 @@
1
1
  import { h } from "@stencil/core";
2
2
  import { Formatter } from "../../../../utils";
3
3
  import { VarianceScenario } from "../../../../utils/model/VarianceScenario";
4
- import { absoluteBarGeometry, BAR_LABEL_FONT_RATIO, estimateLabelWidth, PIN_HEAD_SIZE, relativePinGeometry, VARIANCE_AXIS_EM, } from "../helper/barColumnGeometry";
4
+ import { absoluteBarGeometry, BAR_LABEL_FONT_RATIO, labelWidth, PIN_HEAD_SIZE, relativePinGeometry, VARIANCE_AXIS_EM, } from "../helper/barColumnGeometry";
5
5
  /** Matches SYSTEM_STYLE_DEFAULTS.global.fontSizePx; only used when `styles` is omitted. */
6
6
  const DEFAULT_EM_PX = 13.3333;
7
7
  // Default fallback colors (should come from componentStyle)
@@ -53,9 +53,10 @@ export const PatternDefs = ({ styles }) => {
53
53
  /** Longest relative label that keeps all percent digits; a longer one drops digits so its gutter does not eat the pins. */
54
54
  const PIN_LABEL_CHARS = 7;
55
55
  /**
56
- * Formats a number for display with appropriate SI prefix.
56
+ * Formats a bar or pin label. An absolute value with `decimalDigits` prints like a number
57
+ * cell, without them it takes an SI suffix.
57
58
  */
58
- export function formatValue(value, isRelative, measureScale = 1, locale, percentDigits = 0, percentSign = true) {
59
+ export function formatValue(value, isRelative, measureScale = 1, locale, percentDigits = 0, percentSign = true, decimalDigits) {
59
60
  // IBCS prints a value that rounds to zero without a sign
60
61
  const signed = (text, zero) => (value > 0 && text !== zero ? "+" : "") + text;
61
62
  if (isRelative) {
@@ -73,6 +74,10 @@ export function formatValue(value, isRelative, measureScale = 1, locale, percent
73
74
  }
74
75
  // Absolute variance - apply measure scale and use SI prefixes
75
76
  const scaledValue = value / measureScale;
77
+ if (decimalDigits !== undefined) {
78
+ const number = (v) => Formatter.number(v, "decimal", decimalDigits, decimalDigits, 1, locale);
79
+ return signed(number(scaledValue), number(0));
80
+ }
76
81
  const absValue = Math.abs(scaledValue);
77
82
  let unit = 1;
78
83
  let suffix = "";
@@ -255,25 +260,28 @@ function renderZigzagBreak(breakX, breakGap, yTop, barHeight, s) {
255
260
  * exactly `columnWidthEm` em - see barColumnGeometry.ts.
256
261
  */
257
262
  const AbsoluteVarianceBar = (props) => {
258
- const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, columnWidthEm = 10, labelWidths, styles = DEFAULT_STYLES, } = props;
263
+ const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, decimalDigits, columnWidthEm = 10, labelWidths, sideMax, styles = DEFAULT_STYLES, } = props;
259
264
  const s = styles.scaleFactor;
260
265
  const fs = styles.fontSize;
261
- const displayValue = formattedValue || formatValue(value, false, measureScale, locale);
262
- const sides = labelWidths !== null && labelWidths !== void 0 ? labelWidths : ownLabelWidths(columnStats, estimateLabelWidth(displayValue, fs));
263
- const { totalWidth, axisX, breakGap, overdriveZoneWidth, cutWidth, labelGap } = absoluteBarGeometry(columnWidthEm, styles.emPx, sides);
266
+ const displayValue = formattedValue || formatValue(value, false, measureScale, locale, 0, true, decimalDigits);
267
+ const sides = labelWidths !== null && labelWidths !== void 0 ? labelWidths : ownLabelWidths(columnStats, labelWidth(displayValue, fs, styles.fontFamily, false));
268
+ const isPositive = value > 0 || (value === 0 && zeroOnPositiveSide(sides));
269
+ const { neg = Math.max(0, -columnStats.min), pos = Math.max(0, columnStats.max) } = sideMax !== null && sideMax !== void 0 ? sideMax : {};
270
+ const geometry = absoluteBarGeometry(columnWidthEm, styles.emPx, sides, { neg, pos });
271
+ const { totalWidth, axisX, labelGap } = geometry;
272
+ const { breakGap, overdriveZoneWidth, cutWidth } = isPositive ? geometry.pos : geometry.neg;
264
273
  // Direct unit scaling via fontSize
265
274
  const scaledWidth = Math.abs(value) * styles.unitScaling * fs;
266
275
  // auto scaling puts the largest bar on the cut, float rounding must not turn it into an overdrive bar
267
276
  const isExtreme = scaledWidth - cutWidth > 1e-6;
268
277
  // Compute proportional overdrive width across the column
269
- const maxScaledWidth = columnStats.absMax * styles.unitScaling * fs;
278
+ const maxScaledWidth = (isPositive ? pos : neg) * styles.unitScaling * fs;
270
279
  const maxOverflow = Math.max(0, maxScaledWidth - cutWidth);
271
280
  const overflowAmount = Math.max(0, scaledWidth - cutWidth);
272
281
  const overdriveWidth = maxOverflow > 0 ? (overflowAmount / maxOverflow) * overdriveZoneWidth : 0;
273
282
  const padding = 2 * s;
274
283
  const barHeight = height - padding * 2;
275
284
  const barY = padding;
276
- const isPositive = value > 0 || (value === 0 && zeroOnPositiveSide(sides));
277
285
  // Get style based on column type (scenario vs variance)
278
286
  const look = getVarianceLook(scenario, styles);
279
287
  const sentimentStyle = getBarStyle(scenario, value, isPositiveGood, styles);
@@ -317,21 +325,23 @@ const AbsoluteVarianceBar = (props) => {
317
325
  */
318
326
  const RelativeVariancePin = (props) => {
319
327
  var _a, _b;
320
- const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, percentDigits, percentSign, columnWidthEm = 10, labelWidths, styles = DEFAULT_STYLES, } = props;
328
+ const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, locale, percentDigits, percentSign, columnWidthEm = 10, labelWidths, sideMax, styles = DEFAULT_STYLES, } = props;
321
329
  const s = styles.scaleFactor;
322
330
  const fs = styles.fontSize;
323
331
  const headSize = PIN_HEAD_SIZE * s;
332
+ const pinPx = 100 * styles.percentageScaling * fs;
324
333
  const displayValue = formattedValue || formatValue(value, true, measureScale, locale, percentDigits, percentSign);
325
- const sides = labelWidths !== null && labelWidths !== void 0 ? labelWidths : ownLabelWidths(columnStats, estimateLabelWidth(displayValue, fs));
326
- const { totalWidth, maxPinLength, axisX, labelGap } = relativePinGeometry(columnWidthEm, styles.emPx, sides, headSize);
334
+ const sides = labelWidths !== null && labelWidths !== void 0 ? labelWidths : ownLabelWidths(columnStats, labelWidth(displayValue, fs, styles.fontFamily, true));
335
+ const { neg = Math.max(0, -columnStats.min), pos = Math.max(0, columnStats.max) } = sideMax !== null && sideMax !== void 0 ? sideMax : {};
336
+ const { totalWidth, negPinLength, posPinLength, axisX, labelGap } = relativePinGeometry(columnWidthEm, styles.emPx, sides, headSize, { neg: neg * pinPx, pos: pos * pinPx });
327
337
  const centerY = height / 2;
328
338
  // Direct unit scaling via fontSize
329
- const percentValue = Math.abs(value) * 100;
330
- const scaledLength = percentValue * styles.percentageScaling * fs;
339
+ const scaledLength = Math.abs(value) * pinPx;
340
+ const isPositive = value > 0 || (value === 0 && zeroOnPositiveSide(sides));
341
+ const maxPinLength = isPositive ? posPinLength : negPinLength;
331
342
  // auto scaling puts the longest pin on the limit, float rounding must not cut it
332
343
  const isExtreme = scaledLength - maxPinLength > 1e-6;
333
344
  const pinLength = Math.min(scaledLength, maxPinLength);
334
- const isPositive = value > 0 || (value === 0 && zeroOnPositiveSide(sides));
335
345
  const direction = isPositive ? 1 : -1;
336
346
  const pinEndX = axisX + direction * pinLength;
337
347
  // Get style based on column type (scenario vs variance)
@@ -16,7 +16,7 @@ import { waterfallGeometry } from "../helper/barColumnGeometry";
16
16
  * guides marking their parent bar's extent.
17
17
  */
18
18
  export const WaterfallBar = (props) => {
19
- const { value, scenario, height, measureScale, locale, columnWidthEm = 10, styles = DEFAULT_STYLES, waterfall, } = props;
19
+ const { value, scenario, height, measureScale, locale, decimalDigits, columnWidthEm = 10, styles = DEFAULT_STYLES, waterfall, } = props;
20
20
  const s = styles.scaleFactor;
21
21
  const fs = styles.fontSize;
22
22
  const range = waterfall.max - waterfall.min;
@@ -38,7 +38,7 @@ export const WaterfallBar = (props) => {
38
38
  const fillValue = getBarFill(barStyle, getScenarioType(scenario));
39
39
  const { stroke: barStroke, strokeWidth: barStrokeWidth } = getBarStroke(barStyle);
40
40
  // Scenario values carry no variance sentiment - labels are unsigned per IBCS
41
- const displayValue = formatValue(value, waterfall.kind === "partof", measureScale, locale).replace(/^\+/, "");
41
+ const displayValue = formatValue(value, waterfall.kind === "partof", measureScale, locale, 0, true, decimalDigits).replace(/^\+/, "");
42
42
  const pointsLeft = endX < startX;
43
43
  const labelX = pointsLeft ? barX - labelGap : barX + barWidth + labelGap;
44
44
  const labelAnchor = pointsLeft ? "end" : "start";
@@ -235,7 +235,8 @@ export class DataQuery {
235
235
  /** Generates a GROUPHEAD row used as a visual header when row grouping is active. */
236
236
  createGroupHeaderRow(rowGroupEntry, querys) {
237
237
  // Generates GroupHeader Row
238
- if (true === this.config.grouped) {
238
+ // Without a title the group sum row alone closes the group; only a list has no sum row and keeps the head as gap
239
+ if (true === this.config.grouped && (this.config.showGroupTitle || !this.hasGroupSum())) {
239
240
  const rowGroup = this.bind(String(rowGroupEntry.rowGroup));
240
241
  const title = rowGroupEntry.rowGroup === "" ? this.bind(BLANK_BUCKET_LABEL) : rowGroup;
241
242
  const groupTitle = this.config.showGroupTitle ? `,${title} as ${QueryColumnNames.CATEGORY}` : "";
@@ -247,14 +248,16 @@ export class DataQuery {
247
248
  GROUP BY '1'`);
248
249
  }
249
250
  }
251
+ hasGroupSum() {
252
+ return (TableType.SUM === this.config.type ||
253
+ TableType.SUMNOTOTAL === this.config.type ||
254
+ TableType.OPT === this.config.type ||
255
+ TableType.OPTNOTOTAL === this.config.type);
256
+ }
250
257
  /** Generates a GROUP_SUM row that aggregates all entries within a single row group. */
251
258
  createGroupSumRow(querys, groupSumQuery, rowGroupEntry, scenariosSUMQuery, queryWhereSection, order) {
252
259
  // Generates SUM Row; sumsup all rows of group
253
- if (true === this.config.grouped &&
254
- (TableType.SUM === this.config.type ||
255
- TableType.SUMNOTOTAL === this.config.type ||
256
- TableType.OPT === this.config.type ||
257
- TableType.OPTNOTOTAL === this.config.type)) {
260
+ if (true === this.config.grouped && this.hasGroupSum()) {
258
261
  const rowGroup = this.bind(String(rowGroupEntry.rowGroup));
259
262
  querys.push(`SELECT ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX},
260
263
  '=' as ${QueryColumnNames.OPERATION},
@@ -562,17 +565,19 @@ export class DataQuery {
562
565
  const entryRowsRaw = exec(`SELECT ${groups.select()}, __interval ${scenarios.length > 0 ? ",".concat(scenarios) : ""}
563
566
  FROM ${bucketSource}
564
567
  GROUP BY ${groups}, __interval`);
568
+ // only the generated REST row has restRowGroup; a data row with the category REST keeps its own values
569
+ const isGeneratedRest = (row) => row.type === "ENTRY" && row.restRowGroup != null;
565
570
  // REST rows first: the math needs the raw (not yet finalized) entry aliases
566
571
  if (this.config.limit > 0) {
567
572
  for (let segmentIndex = 0; segmentIndex < res.length; segmentIndex++) {
568
- const restRow = res[segmentIndex].find((row) => row.type === "ENTRY" && row.category === "REST");
573
+ const restRow = res[segmentIndex].find(isGeneratedRest);
569
574
  if (!restRow) {
570
575
  continue;
571
576
  }
572
577
  // nearest preceding segment holding the displayed ENTRY rows
573
578
  let entrySegment;
574
579
  for (let i = segmentIndex - 1; i >= 0 && !entrySegment; i--) {
575
- const candidate = res[i].filter((row) => row.type === "ENTRY" && row.category !== "REST");
580
+ const candidate = res[i].filter((row) => row.type === "ENTRY" && !isGeneratedRest(row));
576
581
  if (candidate.length > 0) {
577
582
  entrySegment = candidate;
578
583
  }
@@ -610,7 +615,7 @@ export class DataQuery {
610
615
  finalizeBucketRow(entryRow);
611
616
  for (const segment of res) {
612
617
  for (const row of segment) {
613
- if (row.type !== "ENTRY" || row.category === "REST" || row.category !== entryRow.category) {
618
+ if (row.type !== "ENTRY" || isGeneratedRest(row) || row.category !== entryRow.category) {
614
619
  continue;
615
620
  }
616
621
  if (this.config.grouped && row.rowGroup !== entryRow.rowGroup) {
@@ -884,11 +889,20 @@ export class DataQuery {
884
889
  }
885
890
  });
886
891
  this.sortSelect = [...sortKeys.values()].map((key) => `, ${key}`).join("");
892
+ // a data row with the reserved category REST stays last in its group when the rows are sorted by value
893
+ const sortsByValue = orderComponent.hierarchy.some((column) => {
894
+ var _a;
895
+ const kind = (_a = parseOrderToken(column)) === null || _a === void 0 ? void 0 : _a.kind;
896
+ return kind === "scenario" || kind === "variance";
897
+ });
898
+ if (sortsByValue) {
899
+ this.sortSelect += `, CASE WHEN ${QueryColumnNames.CATEGORY} = 'REST' THEN 1 ELSE 0 END as __sortrest`;
900
+ }
887
901
  // rows without a value sort last in both directions
888
902
  const orderBy = (column, i, direction) => sortKeys.has(i) ? `__sortnull${i} asc, __sort${i} ${direction}` : `${column} ${direction}`;
889
903
  const base = orderComponent.hierarchy.map((column, i) => orderBy(column, i, orderComponent.direction)).toString();
890
904
  const inverted = orderComponent.hierarchy.map((column, i) => orderBy(column, i, inverse)).toString();
891
- return [base, inverted];
905
+ return sortsByValue ? [`__sortrest asc, ${base}`, `__sortrest desc, ${inverted}`] : [base, inverted];
892
906
  }
893
907
  /**
894
908
  * Sort key `__sort<i>` of a scenario or variance order token, as printed in an entry cell
@@ -64,13 +64,16 @@ function signedValue(row, column, tableType) {
64
64
  * segmented query result once per column in display order.
65
65
  *
66
66
  * - ENTRY rows (incl. REST) cascade from the running total by their signed value.
67
- * - SUM / GROUP_SUM rows anchor at zero and reset the running total to their value.
67
+ * - SUM / GROUP_SUM rows anchor at zero. A SUM row resets the running total to its
68
+ * value, a GROUP_SUM row resets it to zero.
68
69
  * - DRILLELEMENT (thereof) rows form a sub-cascade from their parent bar's start in
69
70
  * the parent's direction; the running total is untouched.
70
71
  * - PARTELEMENT (partof) rows cascade a `share * parent width` segment the same way.
71
72
  * Note: the share denominator is the group sum (or SUM_TOTAL when ungrouped) per
72
73
  * `createPartOfDrillRows`, not literally the parent row's value.
73
- * - GROUPHEAD and NaN rows get no bar; a NaN parent orphans its drill children.
74
+ * - GROUPHEAD rows get no bar and restart the running total at zero: every row group
75
+ * is its own cascade that ends at its GROUP_SUM.
76
+ * - NaN rows get no bar; a NaN parent orphans its drill children.
74
77
  *
75
78
  * @param queryData - Segmented result rows from DataQuery.execute().
76
79
  * @param columns - Plain scenario column keys (ac1..pl4); no `##` composite keys.
@@ -91,6 +94,8 @@ export function computeWaterfall(queryData, columns, tableType) {
91
94
  for (const row of groupData) {
92
95
  const type = row[QueryColumnNames.TYPE];
93
96
  if (type === TableRowType.GROUPHEAD) {
97
+ // a group sum only totals its own rows, so the cascade must not carry over
98
+ running = 0;
94
99
  lastParent = undefined;
95
100
  continue;
96
101
  }
@@ -113,7 +118,8 @@ export function computeWaterfall(queryData, columns, tableType) {
113
118
  emit(row, { start: 0, end: value, min: 0, max: 0, kind: "anchor" });
114
119
  lastParent = { start: 0, end: value };
115
120
  subCursor = 0;
116
- running = value;
121
+ // a group sum closes its group (there may be no GROUPHEAD row when the title is hidden)
122
+ running = type === TableRowType.GROUPSUM ? 0 : value;
117
123
  }
118
124
  else if (type === TableRowType.DRILLELEMENT) {
119
125
  if (value === null || lastParent === undefined) {
@@ -64,6 +64,43 @@ export function estimateLabelWidth(text, fontSize) {
64
64
  }
65
65
  return em * fontSize * LABEL_WIDTH_MARGIN;
66
66
  }
67
+ /** Safety pad on a measured label, in label font size: covers subpixel rounding only. */
68
+ const MEASURE_PAD = 0.15;
69
+ const FONT_SENTINEL = "1px __bn_font_sentinel__";
70
+ let measureContext;
71
+ /** One shared 2D context; null where the document has no canvas (spec tests, mock-doc). */
72
+ function labelMeasureContext() {
73
+ var _a, _b, _c;
74
+ if (measureContext === undefined) {
75
+ try {
76
+ measureContext =
77
+ typeof document === "undefined" ? null : ((_c = (_b = (_a = document.createElement("canvas")).getContext) === null || _b === void 0 ? void 0 : _b.call(_a, "2d")) !== null && _c !== void 0 ? _c : null);
78
+ }
79
+ catch (_d) {
80
+ measureContext = null;
81
+ }
82
+ }
83
+ return measureContext;
84
+ }
85
+ /**
86
+ * Rendered width of a value label in px, measured with the font the SVG text uses. Falls
87
+ * back to estimateLabelWidth where no canvas can measure.
88
+ */
89
+ export function labelWidth(text, fontSize, fontFamily, italic) {
90
+ const ctx = labelMeasureContext();
91
+ if (ctx) {
92
+ // the canvas ignores a font it cannot parse and keeps the last one: the sentinel shows that
93
+ ctx.font = FONT_SENTINEL;
94
+ const sentinel = ctx.font;
95
+ ctx.font = `${italic ? "italic " : ""}${fontSize}px ${fontFamily}`;
96
+ if (ctx.font === sentinel)
97
+ return estimateLabelWidth(text, fontSize);
98
+ const width = ctx.measureText(text).width;
99
+ if (Number.isFinite(width) && (width > 0 || text === ""))
100
+ return width + MEASURE_PAD * fontSize;
101
+ }
102
+ return estimateLabelWidth(text, fontSize);
103
+ }
67
104
  /** The SVG fills the cell's content box: the requested column width minus the cell padding. */
68
105
  function contentWidth(widthEm, emPx) {
69
106
  return Math.max(0, (widthEm - BAR_CELL_PADDING_EM) * emPx);
@@ -97,28 +134,86 @@ export function pinLabelsFit(widthEm, emPx, labels, headSize) {
97
134
  const { sides, neg, pos } = sideNeeds(labels, headSize / 2, LABEL_GAP_EM * emPx);
98
135
  return neg + pos + sides * minExtent(totalWidth, emPx, sides) <= totalWidth + 1e-6;
99
136
  }
100
- export function absoluteBarGeometry(widthEm, emPx, labels) {
101
- const totalWidth = contentWidth(widthEm, emPx);
102
- const labelGap = LABEL_GAP_EM * emPx;
103
- // a variance bar starts at the outer edge of the thick axis
104
- const { extent: maxBarWidth, axisX } = splitSides(totalWidth, labels, (VARIANCE_AXIS_EM * emPx) / 2, labelGap);
105
- const breakGap = Math.min(BREAK_GAP_EM * emPx, maxBarWidth * 0.2);
137
+ function barSide(maxBarWidth, breakGap) {
106
138
  const overdriveZoneWidth = maxBarWidth * OVERDRIVE_FRACTION;
107
139
  return {
108
- totalWidth,
109
140
  maxBarWidth,
110
- axisX,
111
141
  breakGap,
112
142
  overdriveZoneWidth,
113
143
  cutWidth: Math.max(0, maxBarWidth - breakGap - overdriveZoneWidth),
144
+ };
145
+ }
146
+ /**
147
+ * `sideMax` is the largest absolute value per side of the axis. With it, the bar room is
148
+ * split so the uncut bar length of each side is in that ratio: the axis sits where the
149
+ * values need it, at any scale. Without it, both sides get the same extent.
150
+ */
151
+ export function absoluteBarGeometry(widthEm, emPx, labels, sideMax) {
152
+ var _a, _b;
153
+ const totalWidth = contentWidth(widthEm, emPx);
154
+ const labelGap = LABEL_GAP_EM * emPx;
155
+ // a variance bar starts at the outer edge of the thick axis
156
+ const { extent, axisX } = splitSides(totalWidth, labels, (VARIANCE_AXIS_EM * emPx) / 2, labelGap);
157
+ const breakGap = Math.min(BREAK_GAP_EM * emPx, extent * 0.2);
158
+ const hasNeg = labels.neg !== undefined;
159
+ const hasPos = labels.pos !== undefined || !hasNeg;
160
+ let neg = hasNeg ? extent : 0;
161
+ const maxNeg = Math.max(0, (_a = sideMax === null || sideMax === void 0 ? void 0 : sideMax.neg) !== null && _a !== void 0 ? _a : 0);
162
+ const maxPos = Math.max(0, (_b = sideMax === null || sideMax === void 0 ? void 0 : sideMax.pos) !== null && _b !== void 0 ? _b : 0);
163
+ if (hasNeg && hasPos && maxNeg + maxPos > 0) {
164
+ // every side keeps its break gap and overdrive stub, only the uncut length follows the values
165
+ const uncut = 2 * extent * (1 - OVERDRIVE_FRACTION) - 2 * breakGap;
166
+ neg = (breakGap + (uncut * maxNeg) / (maxNeg + maxPos)) / (1 - OVERDRIVE_FRACTION);
167
+ }
168
+ const pos = hasPos ? (hasNeg ? 2 * extent - neg : extent) : 0;
169
+ return {
170
+ totalWidth,
171
+ neg: barSide(neg, breakGap),
172
+ pos: barSide(pos, breakGap),
173
+ axisX: hasNeg ? axisX - extent + neg : 0,
114
174
  labelGap,
115
175
  };
116
176
  }
117
- export function relativePinGeometry(widthEm, emPx, labels, headSize) {
177
+ /**
178
+ * `reach` is the length in px the longest pin of each side wants at the column's scale.
179
+ * With it, the pin room is split by what each side needs, so a side with shorter pins
180
+ * gives its room to the other; room left after both is shared equally. Without it, both
181
+ * sides get the same extent.
182
+ */
183
+ export function relativePinGeometry(widthEm, emPx, labels, headSize, reach) {
184
+ var _a, _b;
118
185
  const totalWidth = contentWidth(widthEm, emPx);
119
186
  const labelGap = LABEL_GAP_EM * emPx;
120
187
  const { extent, axisX } = splitSides(totalWidth, labels, headSize / 2, labelGap);
121
- return { totalWidth, maxPinLength: extent, axisX, labelGap };
188
+ const hasNeg = labels.neg !== undefined;
189
+ const hasPos = labels.pos !== undefined || !hasNeg;
190
+ let neg = hasNeg ? extent : 0;
191
+ let pos = hasPos ? extent : 0;
192
+ if (reach && hasNeg && hasPos) {
193
+ const room = 2 * extent;
194
+ const wantNeg = Math.max(0, (_a = reach.neg) !== null && _a !== void 0 ? _a : 0);
195
+ const wantPos = Math.max(0, (_b = reach.pos) !== null && _b !== void 0 ? _b : 0);
196
+ if (wantNeg + wantPos <= room + 1e-6) {
197
+ neg = wantNeg + (room - wantNeg - wantPos) / 2;
198
+ pos = room - neg;
199
+ }
200
+ else if (wantNeg < extent) {
201
+ neg = wantNeg;
202
+ pos = room - neg;
203
+ }
204
+ else if (wantPos < extent) {
205
+ pos = wantPos;
206
+ neg = room - pos;
207
+ }
208
+ }
209
+ return {
210
+ totalWidth,
211
+ maxPinLength: Math.max(neg, pos),
212
+ negPinLength: neg,
213
+ posPinLength: pos,
214
+ axisX: hasNeg ? axisX - extent + neg : 0,
215
+ labelGap,
216
+ };
122
217
  }
123
218
  export function waterfallGeometry(widthEm, emPx) {
124
219
  const totalWidth = contentWidth(widthEm, emPx);
@@ -1 +1 @@
1
- import{B as o,d as s}from"./p-CLilvhjH.js";const p=o,r=s;export{p as BnTableRenderer,r as defineCustomElement}
1
+ import{B as o,d as s}from"./p--HIZm_2v.js";const m=o,p=s;export{m as BnTableRenderer,p as defineCustomElement}