@bino-bi/bn-template-engine 1.0.0-next.50 → 1.0.0-next.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
- package/dist/bn-template-engine/{p-2de524d0.entry.js → p-150bdb68.entry.js} +1 -1
- package/dist/bn-template-engine/p-4d99f1bb.entry.js +1 -0
- package/dist/bn-template-engine/{p-Bxa4pX1M.js → p-Bvunba5p.js} +1 -1
- package/dist/bn-template-engine/p-NxJ6P79y.js +1 -0
- package/dist/bn-template-engine/{p-8fc90dc8.entry.js → p-b75a4b52.entry.js} +1 -1
- package/dist/bn-template-engine/{p-510d2ee6.entry.js → p-fdf42a77.entry.js} +1 -1
- package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +1114 -63
- package/dist/cjs/bn-grid.cjs.entry.js +1 -1
- package/dist/cjs/bn-image.cjs.entry.js +1 -1
- package/dist/cjs/bn-template-engine.cjs.js +1 -1
- package/dist/cjs/bn-text.cjs.entry.js +2 -2
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{withStyled-pkdctrK9.js → withStyled-BISQLGLe.js} +9 -0
- package/dist/cjs/{withTranslation-BIzTNYZM.js → withTranslation-B7T30EVU.js} +1 -1
- package/dist/collection/components/bn-annotation-layer/bn-annotation-layer.js +109 -11
- package/dist/collection/components/bn-annotation-layer/utils/marks.js +126 -4
- package/dist/collection/components/bn-annotation-layer/utils/matchPoint.js +2 -1
- package/dist/collection/components/bn-chart-structure/bn-chart-structure-renderer/bn-chart-structure-renderer.js +133 -0
- package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +258 -2
- package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +549 -27
- package/dist/collection/components/bn-chart-structure/utils/elements/Bar.js +9 -1
- package/dist/collection/components/bn-chart-structure/utils/elements/Label.js +12 -0
- package/dist/collection/components/bn-chart-structure/utils/elements/Needle.js +6 -0
- package/dist/collection/components/bn-chart-structure/utils/elements/StackedBar.js +23 -8
- package/dist/collection/components/bn-chart-structure/utils/helper/ElementPositions.js +22 -3
- package/dist/collection/components/bn-chart-structure/utils/model/StructureChartComponentConfig.js +23 -0
- package/dist/collection/components/bn-context/bn-context.js +68 -1
- package/dist/collection/components/bn-layout-card/bn-layout-card.js +62 -2
- package/dist/collection/utils/formatter.js +13 -2
- package/dist/collection/utils/validate.js +9 -0
- package/dist/components/bn-annotation-layer.js +1 -1
- package/dist/components/bn-chart-bubble-renderer.js +1 -1
- package/dist/components/bn-chart-bubble.js +1 -1
- package/dist/components/bn-chart-bullet-renderer.js +1 -1
- package/dist/components/bn-chart-bullet.js +1 -1
- package/dist/components/bn-chart-scatter-renderer.js +1 -1
- package/dist/components/bn-chart-scatter.js +1 -1
- package/dist/components/bn-chart-structure-renderer.js +1 -1
- package/dist/components/bn-chart-structure.js +1 -1
- package/dist/components/bn-chart-time-renderer.js +1 -1
- package/dist/components/bn-chart-time.js +1 -1
- package/dist/components/bn-context.js +1 -1
- package/dist/components/bn-grid.js +1 -1
- package/dist/components/bn-image.js +1 -1
- package/dist/components/bn-layout-card.js +1 -1
- package/dist/components/bn-layout-page.js +1 -1
- package/dist/components/bn-page.js +1 -1
- package/dist/components/bn-table-renderer.js +1 -1
- package/dist/components/bn-table.js +1 -1
- package/dist/components/bn-text.js +1 -1
- package/dist/components/bn-title-renderer.js +1 -1
- package/dist/components/bn-title.js +1 -1
- package/dist/components/bn-tree.js +1 -1
- package/dist/components/p-BOwmXBm-.js +1 -0
- package/dist/components/p-Bs5V6Ibu.js +1 -0
- package/dist/components/{p-CVfmhtEW.js → p-CU9CdEBF.js} +1 -1
- package/dist/components/{p-Cc0gaLwp.js → p-CZSp0rSS.js} +1 -1
- package/dist/components/p-CcfvGlBq.js +1 -0
- package/dist/components/p-CiljAoC5.js +1 -0
- package/dist/components/p-D0v9GMIf.js +1 -0
- package/dist/components/{p-DBj1Yd3M.js → p-D65TnLS9.js} +1 -1
- package/dist/components/p-DKcw-1ot.js +1 -0
- package/dist/components/{p-k7heRDPP.js → p-DLmQ_mi7.js} +1 -1
- package/dist/components/p-DOKqRsAu.js +1 -0
- package/dist/components/p-LHIKI9Dp.js +1 -0
- package/dist/components/{p-Blre9f28.js → p-NdDdfez6.js} +1 -1
- package/dist/components/p-Zz3fAPcH.js +1 -0
- package/dist/components/{p-y12CmIFS.js → p-dSUX43yf.js} +1 -1
- package/dist/components/p-iJP2X4dc.js +1 -0
- package/dist/components/p-jEqo8YD5.js +1 -0
- package/dist/esm/bn-annotation-layer_30.entry.js +1114 -63
- package/dist/esm/bn-grid.entry.js +1 -1
- package/dist/esm/bn-image.entry.js +1 -1
- package/dist/esm/bn-template-engine.js +1 -1
- package/dist/esm/bn-text.entry.js +2 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{withStyled-B62R20Zx.js → withStyled-CrTxIZ0Q.js} +9 -0
- package/dist/esm/{withTranslation-BEseMLQ6.js → withTranslation-BtSJmx1J.js} +1 -1
- package/dist/schemas/stack.schema.json +21 -1
- package/dist/types/components/bn-annotation-layer/utils/marks.d.ts +53 -0
- package/dist/types/components/bn-annotation-layer/utils/matchPoint.d.ts +2 -0
- package/dist/types/components/bn-chart-structure/bn-chart-structure-renderer/bn-chart-structure-renderer.d.ts +11 -1
- package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +49 -0
- package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +52 -0
- package/dist/types/components/bn-chart-structure/utils/elements/Bar.d.ts +2 -0
- package/dist/types/components/bn-chart-structure/utils/elements/Label.d.ts +4 -0
- package/dist/types/components/bn-chart-structure/utils/elements/Needle.d.ts +2 -0
- package/dist/types/components/bn-chart-structure/utils/elements/StackedBar.d.ts +13 -1
- package/dist/types/components/bn-chart-structure/utils/helper/ElementPositions.d.ts +15 -1
- package/dist/types/components/bn-chart-structure/utils/model/StructureChartComponentConfig.d.ts +23 -0
- package/dist/types/components/bn-context/bn-context.d.ts +12 -0
- package/dist/types/components/bn-layout-card/bn-layout-card.d.ts +12 -0
- package/dist/types/components.d.ts +113 -2
- package/dist/types/schemas.d.ts +7 -1
- package/dist/types/utils/annotations.d.ts +1 -1
- package/dist/types/utils/formatter.d.ts +5 -0
- package/package.json +1 -1
- package/dist/bn-template-engine/p-BFl7OwcC.js +0 -1
- package/dist/bn-template-engine/p-c1d679af.entry.js +0 -1
- package/dist/components/p-B11cXOLy.js +0 -1
- package/dist/components/p-BVNOmHh4.js +0 -1
- package/dist/components/p-CHhxQoF9.js +0 -1
- package/dist/components/p-CO6bgquz.js +0 -1
- package/dist/components/p-CmvpJzLd.js +0 -1
- package/dist/components/p-CuUfiEu0.js +0 -1
- package/dist/components/p-DHloMyxV.js +0 -1
- package/dist/components/p-Dd1QOWDV.js +0 -1
- package/dist/components/p-HVN8BNWN.js +0 -1
- package/dist/components/p-x0W2_FAX.js +0 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var index = require('./index-DwBbheYB.js');
|
|
4
4
|
var withHasError = require('./withHasError-CZFrIJw0.js');
|
|
5
|
-
var withStyled = require('./withStyled-
|
|
6
|
-
var withTranslation = require('./withTranslation-
|
|
5
|
+
var withStyled = require('./withStyled-BISQLGLe.js');
|
|
6
|
+
var withTranslation = require('./withTranslation-B7T30EVU.js');
|
|
7
7
|
var withBodyObserver = require('./withBodyObserver-CIGVLQEB.js');
|
|
8
8
|
var localFrame = require('./localFrame-C4RBw_zT.js');
|
|
9
9
|
var types = require('./types-BngAWYMW.js');
|
|
@@ -249,9 +249,12 @@ function buildMark(item, box, toBox, em, options = {}) {
|
|
|
249
249
|
}
|
|
250
250
|
if (item.mark === "frame") {
|
|
251
251
|
// a text of its own stands in the upper part of the target, above a value label in its middle
|
|
252
|
-
const caption = item.text
|
|
253
|
-
?
|
|
254
|
-
:
|
|
252
|
+
const caption = item.text == null || whole
|
|
253
|
+
? undefined
|
|
254
|
+
: options.label
|
|
255
|
+
? // right of a value label, so both can be read
|
|
256
|
+
{ x: box.x + box.width + 0.7 * em + textWidth(item.text, em) / 2, y: box.y + box.height / 2 }
|
|
257
|
+
: { x: box.x + box.width / 2, y: box.y + Math.min(box.height / 2, Math.max(0.9 * em, 0.3 * box.height)) };
|
|
255
258
|
const captionBox = caption && {
|
|
256
259
|
x: caption.x - textWidth(item.text, em) / 2,
|
|
257
260
|
y: caption.y - 0.6 * em,
|
|
@@ -302,7 +305,20 @@ function buildMark(item, box, toBox, em, options = {}) {
|
|
|
302
305
|
const size = (label == null ? 0.4 : 0.75) * unit;
|
|
303
306
|
const r = isRow ? Math.min(size, box.height / 2) : size;
|
|
304
307
|
let at = whole ? { x: box.x + box.width - r, y: box.y + r } : centre(box);
|
|
305
|
-
if (!whole && options.
|
|
308
|
+
if (!whole && options.label) {
|
|
309
|
+
// right of the label of a chart, not on it
|
|
310
|
+
at = { x: box.x + box.width + 0.25 * unit + r, y: box.y + box.height / 2 };
|
|
311
|
+
}
|
|
312
|
+
else if (!whole && options.stacked && options.horizontal) {
|
|
313
|
+
// in a wide segment right of its label, like in a table. Else on the upper edge at its end.
|
|
314
|
+
// The total behind the bar stays free in both cases.
|
|
315
|
+
const beside = 1.3 * unit + r;
|
|
316
|
+
at =
|
|
317
|
+
box.width / 2 >= beside + r
|
|
318
|
+
? { x: box.x + box.width / 2 + beside, y: box.y + box.height / 2 }
|
|
319
|
+
: { x: box.x + box.width - Math.min(r, box.width / 2), y: box.y };
|
|
320
|
+
}
|
|
321
|
+
else if (!whole && options.stacked && ((_c = item.point) === null || _c === void 0 ? void 0 : _c.part) !== "label" && ((_d = item.point) === null || _d === void 0 ? void 0 : _d.part) !== "total") {
|
|
306
322
|
// on the upper right corner: the label in the middle and a name beside the segment stay free
|
|
307
323
|
at = { x: box.x + box.width, y: box.y + Math.min(0.5 * r, box.height / 2) };
|
|
308
324
|
}
|
|
@@ -317,6 +333,112 @@ function buildMark(item, box, toBox, em, options = {}) {
|
|
|
317
333
|
}
|
|
318
334
|
return { kind: "marker", color, badge: keepInside({ cx: at.x, cy: at.y, r, label }, area) };
|
|
319
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* The difference of two bars that run from left to right. `levels` are the x of the
|
|
338
|
+
* two values. The bar of the difference lies in the gap below the second row, or above
|
|
339
|
+
* it when that row is the upper one. A thin line runs from each value to it, and the
|
|
340
|
+
* label stands right of it.
|
|
341
|
+
*/
|
|
342
|
+
function buildHorizontalDifference(item, box, toBox, fromValue, toValue, em, levels) {
|
|
343
|
+
var _a;
|
|
344
|
+
if (fromValue == null || toValue == null)
|
|
345
|
+
return undefined;
|
|
346
|
+
const difference = toValue - fromValue;
|
|
347
|
+
const digits = Number.isInteger(item.digits) && item.digits >= 0 ? item.digits : 1;
|
|
348
|
+
const good = item.sentiment === "good-down" ? difference <= 0 : difference >= 0;
|
|
349
|
+
const direction = toBox.y + toBox.height / 2 >= box.y + box.height / 2 ? 1 : -1;
|
|
350
|
+
const edge = (of) => (direction === 1 ? of.y + of.height : of.y);
|
|
351
|
+
const barHeight = 0.25 * em;
|
|
352
|
+
const barY = edge(toBox) + direction * 0.25 * em;
|
|
353
|
+
const left = Math.min(levels.from, levels.to);
|
|
354
|
+
const right = Math.max(levels.from, levels.to);
|
|
355
|
+
const percent = item.percent && fromValue !== 0 ? `(${signed((difference / Math.abs(fromValue)) * 100, 0)}%)` : undefined;
|
|
356
|
+
const value = signed(difference, digits);
|
|
357
|
+
const textX = right + 0.5 * em;
|
|
358
|
+
const valueWidth = value.length * 0.5 * em;
|
|
359
|
+
const percentWidth = percent ? textWidth(percent, 0.85 * em) : 0;
|
|
360
|
+
const percentX = textX + valueWidth + 0.35 * em;
|
|
361
|
+
return {
|
|
362
|
+
kind: "difference",
|
|
363
|
+
color: (_a = item.color) !== null && _a !== void 0 ? _a : (good ? "positive" : "negative"),
|
|
364
|
+
lines: [
|
|
365
|
+
{ x1: levels.from, y1: edge(box), x2: levels.from, y2: barY },
|
|
366
|
+
{ x1: levels.to, y1: edge(toBox), x2: levels.to, y2: barY },
|
|
367
|
+
],
|
|
368
|
+
bar: { x: left, y: barY - barHeight / 2, width: Math.max(right - left, 1), height: barHeight },
|
|
369
|
+
text: { x: textX, y: barY, anchor: "start", value, percent },
|
|
370
|
+
frame: percent && item.highlight
|
|
371
|
+
? {
|
|
372
|
+
x: percentX - 0.25 * em,
|
|
373
|
+
y: barY - 0.65 * em,
|
|
374
|
+
width: percentWidth + 0.5 * em,
|
|
375
|
+
height: 1.3 * em,
|
|
376
|
+
r: 0.65 * em,
|
|
377
|
+
}
|
|
378
|
+
: undefined,
|
|
379
|
+
badge: item.label != null ? { cx: left - 0.9 * em, cy: barY, r: 0.65 * em, label: item.label } : undefined,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
/** A thick arrow that points down at `tip`: the value end of a bar, or the top of a column. */
|
|
383
|
+
function buildPointer(item, at, em) {
|
|
384
|
+
const x = at.x;
|
|
385
|
+
const tip = at.y - 0.15 * em;
|
|
386
|
+
const neck = tip - 0.7 * em;
|
|
387
|
+
const top = tip - 1.9 * em;
|
|
388
|
+
const head = 0.55 * em;
|
|
389
|
+
const shaft = 0.22 * em;
|
|
390
|
+
const points = [
|
|
391
|
+
[x, tip],
|
|
392
|
+
[x - head, neck],
|
|
393
|
+
[x - shaft, neck],
|
|
394
|
+
[x - shaft, top],
|
|
395
|
+
[x + shaft, top],
|
|
396
|
+
[x + shaft, neck],
|
|
397
|
+
[x + head, neck],
|
|
398
|
+
];
|
|
399
|
+
return {
|
|
400
|
+
kind: "pointer",
|
|
401
|
+
color: item.color,
|
|
402
|
+
shape: points.map(([px, py]) => `${px},${py}`).join(" "),
|
|
403
|
+
badge: item.label != null ? { cx: x + 1.1 * em, cy: top + 0.65 * em, r: 0.65 * em, label: item.label } : undefined,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* A bracket around a range of rows of a chart with bars from left to right. A line
|
|
408
|
+
* runs below the last row from `left` to the end of its bar, and from there up to the
|
|
409
|
+
* end of the bar of the first row. `ends` are the x of the two values. `text` stands
|
|
410
|
+
* in a frame at the left, above the first row.
|
|
411
|
+
*/
|
|
412
|
+
function buildBracket(item, first, last, ends, left, text, em) {
|
|
413
|
+
const firstIsUpper = first.y <= last.y;
|
|
414
|
+
const [upper, lower] = firstIsUpper ? [first, last] : [last, first];
|
|
415
|
+
const [upperEnd, lowerEnd] = firstIsUpper ? [ends.first, ends.last] : [ends.last, ends.first];
|
|
416
|
+
const bottom = lower.y + lower.height + 0.2 * em;
|
|
417
|
+
const points = [
|
|
418
|
+
[left, bottom],
|
|
419
|
+
[lowerEnd, bottom],
|
|
420
|
+
[upperEnd, upper.y - 0.1 * em],
|
|
421
|
+
];
|
|
422
|
+
const width = text ? textWidth(text, em) : 0;
|
|
423
|
+
const captionY = upper.y - 0.9 * em;
|
|
424
|
+
const caption = text ? { x: left + 0.5 * em + width / 2, y: captionY, text } : undefined;
|
|
425
|
+
// the number stands behind the text, or in its place
|
|
426
|
+
const badgeX = caption ? caption.x + width / 2 + 1.2 * em : left + 0.65 * em;
|
|
427
|
+
return {
|
|
428
|
+
kind: "bracket",
|
|
429
|
+
color: item.color,
|
|
430
|
+
path: points.map(([px, py]) => `${px},${py}`).join(" "),
|
|
431
|
+
caption,
|
|
432
|
+
frame: caption && {
|
|
433
|
+
x: caption.x - width / 2 - 0.45 * em,
|
|
434
|
+
y: caption.y - 0.7 * em,
|
|
435
|
+
width: width + 0.9 * em,
|
|
436
|
+
height: 1.4 * em,
|
|
437
|
+
r: 0.7 * em,
|
|
438
|
+
},
|
|
439
|
+
badge: item.label != null ? { cx: badgeX, cy: captionY, r: 0.65 * em, label: item.label } : undefined,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
320
442
|
|
|
321
443
|
const KEY_FIELDS = ["rowGroup", "category", "subCategory", "date", "scenario", "row"];
|
|
322
444
|
/** A point without a field, or no point at all, means the component as a whole. */
|
|
@@ -341,17 +463,30 @@ function matchPoint(state, point) {
|
|
|
341
463
|
const noThereof = state.table != null && point.subCategory == null;
|
|
342
464
|
return candidates
|
|
343
465
|
.filter((candidate) => matches(candidate.point, point) && !(noThereof && candidate.point.subCategory != null))
|
|
344
|
-
.map(({ rect, content, contentSign, value, scenario }) => ({
|
|
466
|
+
.map(({ rect, content, contentSign, value, scenario, kind }) => ({
|
|
345
467
|
rect,
|
|
346
468
|
content,
|
|
347
469
|
contentSign,
|
|
348
470
|
value,
|
|
349
471
|
stacked: typeof scenario === "string" && scenario.startsWith("stack:"),
|
|
472
|
+
label: kind === "label",
|
|
350
473
|
}));
|
|
351
474
|
}
|
|
352
475
|
|
|
353
476
|
const bnAnnotationLayerCss = () => `:host{position:absolute;inset:0;z-index:1;display:block;pointer-events:none;font-family:var(--bn-font-family, "Noto Sans", sans-serif);font-size:var(--bn-font-size, 13.3333px)}svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}.badge-text{fill:#ffffff;font-weight:bold;text-anchor:middle;dominant-baseline:central}.mark-text{fill:#000000;dominant-baseline:central}.mark-text.caption{text-anchor:middle;font-size:0.9em}.mark-text .percent{font-size:0.85em}.difference-line{stroke:#000000;stroke-width:0.75}`;
|
|
354
477
|
|
|
478
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
479
|
+
var t = {};
|
|
480
|
+
for (var p in s)
|
|
481
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
482
|
+
t[p] = s[p];
|
|
483
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
484
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
485
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
486
|
+
t[p[i]] = s[p[i]];
|
|
487
|
+
}
|
|
488
|
+
return t;
|
|
489
|
+
};
|
|
355
490
|
/** A chart can draw its data late: a point without a match is reported when the page has been quiet for two checks. */
|
|
356
491
|
const REPORT_CHECK_MS = 200;
|
|
357
492
|
const REPORT_MAX_CHECKS = 50;
|
|
@@ -453,12 +588,12 @@ const AnnotationLayer = class {
|
|
|
453
588
|
(_a = document.fonts) === null || _a === void 0 ? void 0 : _a.addEventListener("loadingdone", this.schedule);
|
|
454
589
|
}
|
|
455
590
|
disconnectedCallback() {
|
|
456
|
-
var _a, _b,
|
|
591
|
+
var _a, _b, _e, _f;
|
|
457
592
|
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
458
593
|
(_b = this.mutationObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
459
|
-
(
|
|
594
|
+
(_e = document.fonts) === null || _e === void 0 ? void 0 : _e.removeEventListener("loadingdone", this.schedule);
|
|
460
595
|
this.run++;
|
|
461
|
-
if ((
|
|
596
|
+
if ((_f = this.stores) === null || _f === void 0 ? void 0 : _f.annotationsUnplaced.state[this.pageKey]) {
|
|
462
597
|
this.stores.annotationsUnplaced.set(this.pageKey, undefined);
|
|
463
598
|
}
|
|
464
599
|
}
|
|
@@ -483,7 +618,7 @@ const AnnotationLayer = class {
|
|
|
483
618
|
this.parsedItems = items !== null && items !== void 0 ? items : [];
|
|
484
619
|
}
|
|
485
620
|
async place() {
|
|
486
|
-
var _a, _b;
|
|
621
|
+
var _a, _b, _e, _f;
|
|
487
622
|
const run = ++this.run;
|
|
488
623
|
if (!this.element.isConnected || !this.svg)
|
|
489
624
|
return;
|
|
@@ -543,8 +678,9 @@ const AnnotationLayer = class {
|
|
|
543
678
|
return { problem: `the point ${JSON.stringify(point)} in "${id}" is cut off` };
|
|
544
679
|
}
|
|
545
680
|
const content = found[0].content;
|
|
546
|
-
if (!state.table)
|
|
547
|
-
return { box, whole: false, stacked: found[0].stacked };
|
|
681
|
+
if (!state.table) {
|
|
682
|
+
return { box, whole: false, stacked: found[0].stacked, label: found[0].label, horizontal: isHorizontal(state) };
|
|
683
|
+
}
|
|
548
684
|
const cells = ((_a = state.elements) !== null && _a !== void 0 ? _a : []).flatMap((element) => element.kind === "cell" && element.content
|
|
549
685
|
? [{ box: onScreen(element.content), sign: element.contentSign }]
|
|
550
686
|
: []);
|
|
@@ -555,6 +691,8 @@ const AnnotationLayer = class {
|
|
|
555
691
|
obstacles: cells,
|
|
556
692
|
};
|
|
557
693
|
};
|
|
694
|
+
// the bars of a structure chart run from left to right: its value axis is an upright line
|
|
695
|
+
const isHorizontal = (state) => { var _a; return ((_a = state === null || state === void 0 ? void 0 : state.elements) !== null && _a !== void 0 ? _a : []).some((element) => element.kind === "axis" && element.orientation === "vertical"); };
|
|
558
696
|
// a difference takes all bars of a point: the segments of a stack together are its sum
|
|
559
697
|
const sumOf = (id, point) => {
|
|
560
698
|
const visual = id != null ? targets.get(id) : undefined;
|
|
@@ -585,8 +723,27 @@ const AnnotationLayer = class {
|
|
|
585
723
|
box: { x: host.left + left, y: host.top + top, width: right - left, height: bottom - top },
|
|
586
724
|
negatives: bars.filter((bar) => bar.value < 0).map((bar) => screen(bar.rect.component)),
|
|
587
725
|
value: bars.reduce((sum, bar) => sum + bar.value, 0),
|
|
726
|
+
horizontal: isHorizontal(state),
|
|
588
727
|
};
|
|
589
728
|
};
|
|
729
|
+
// the share of the rows from one point to another in all rows of the chart, for the bars the points name
|
|
730
|
+
const shareOf = (item, upper, lower) => {
|
|
731
|
+
const visual = targets.get(item.target);
|
|
732
|
+
const state = visual && states.get(visual);
|
|
733
|
+
if (!visual || !state || !item.point)
|
|
734
|
+
return undefined;
|
|
735
|
+
const host = visual.getBoundingClientRect();
|
|
736
|
+
const _a = item.point, series = __rest(_a, ["rowGroup", "category", "subCategory", "date"]);
|
|
737
|
+
const bars = matchPoint(state, Object.assign(Object.assign({}, series), { part: "element" })).filter((bar) => bar.value != null);
|
|
738
|
+
const all = bars.reduce((sum, bar) => sum + bar.value, 0);
|
|
739
|
+
const inside = bars
|
|
740
|
+
.filter((bar) => {
|
|
741
|
+
const middle = host.top + bar.rect.component.y + bar.rect.component.height / 2;
|
|
742
|
+
return middle >= upper.y && middle <= lower.y + lower.height;
|
|
743
|
+
})
|
|
744
|
+
.reduce((sum, bar) => sum + bar.value, 0);
|
|
745
|
+
return all !== 0 ? inside / all : undefined;
|
|
746
|
+
};
|
|
590
747
|
const toLocal = this.toLocalSpace();
|
|
591
748
|
// here the text runs along x and a layout px is a px, also on a rotated or scaled page
|
|
592
749
|
const textToLocal = ({ box, sign = 0 }) => {
|
|
@@ -608,6 +765,20 @@ const AnnotationLayer = class {
|
|
|
608
765
|
continue;
|
|
609
766
|
}
|
|
610
767
|
const [a, b] = [first, second];
|
|
768
|
+
if (a.horizontal) {
|
|
769
|
+
// the level of a sum is the right end, and left of it by the length of the negative values
|
|
770
|
+
const endOf = (anchor) => {
|
|
771
|
+
const local = toLocal(anchor.box);
|
|
772
|
+
return local.x + local.width - anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).width, 0);
|
|
773
|
+
};
|
|
774
|
+
const mark = buildHorizontalDifference(item, toLocal(a.box), toLocal(b.box), a.value, b.value, em, {
|
|
775
|
+
from: endOf(a),
|
|
776
|
+
to: endOf(b),
|
|
777
|
+
});
|
|
778
|
+
if (mark)
|
|
779
|
+
marks.push(mark);
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
611
782
|
// the level of a sum: the top for positive values, and below it by the length of the negative ones.
|
|
612
783
|
// Measured in the space of the layer, so it holds on a turned page too.
|
|
613
784
|
const levelOf = (anchor) => toLocal(anchor.box).y + anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).height, 0);
|
|
@@ -619,6 +790,48 @@ const AnnotationLayer = class {
|
|
|
619
790
|
marks.push(mark);
|
|
620
791
|
continue;
|
|
621
792
|
}
|
|
793
|
+
if (item.mark === "pointer" || item.mark === "bracket") {
|
|
794
|
+
const first = sumOf(item.target, item.point);
|
|
795
|
+
const second = item.mark === "bracket" ? sumOf((_b = item.to) !== null && _b !== void 0 ? _b : item.target, item.toPoint) : first;
|
|
796
|
+
const failed = "problem" in first ? first : "problem" in second ? second : undefined;
|
|
797
|
+
if (failed) {
|
|
798
|
+
problems.push({ item, problem: failed.problem });
|
|
799
|
+
continue;
|
|
800
|
+
}
|
|
801
|
+
const [a, b] = [first, second];
|
|
802
|
+
// the end of a value: the right end of a bar or the top of a column, moved by the negative values
|
|
803
|
+
const endOf = (anchor) => {
|
|
804
|
+
const local = toLocal(anchor.box);
|
|
805
|
+
return anchor.horizontal
|
|
806
|
+
? {
|
|
807
|
+
x: local.x + local.width - anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).width, 0),
|
|
808
|
+
y: local.y,
|
|
809
|
+
}
|
|
810
|
+
: {
|
|
811
|
+
x: local.x + local.width / 2,
|
|
812
|
+
y: local.y + anchor.negatives.reduce((sum, bar) => sum + toLocal(bar).height, 0),
|
|
813
|
+
};
|
|
814
|
+
};
|
|
815
|
+
if (item.mark === "pointer") {
|
|
816
|
+
marks.push(buildPointer(item, endOf(a), em));
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
819
|
+
if (!a.horizontal) {
|
|
820
|
+
problems.push({ item, problem: "a bracket needs bars that run from left to right" });
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
if (item.to != null && item.to !== item.target) {
|
|
824
|
+
problems.push({ item, problem: "both ends of a bracket must be in one chart" });
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
const [upper, lower] = a.box.y <= b.box.y ? [a.box, b.box] : [b.box, a.box];
|
|
828
|
+
const share = item.percent ? shareOf(item, upper, lower) : undefined;
|
|
829
|
+
const host = targets.get(item.target).getBoundingClientRect();
|
|
830
|
+
const hostBox = toLocal({ x: host.left, y: host.top, width: host.width, height: host.height });
|
|
831
|
+
const caption = (_e = item.text) !== null && _e !== void 0 ? _e : (share != null ? `${Math.round(share * 100)}%` : undefined);
|
|
832
|
+
marks.push(buildBracket(item, toLocal(a.box), toLocal(b.box), { first: endOf(a).x, last: endOf(b).x }, hostBox.x, caption, em));
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
622
835
|
const from = anchorOf(item.target, item.point);
|
|
623
836
|
const to = item.mark === "arrow" ? anchorOf(item.to, item.toPoint) : undefined;
|
|
624
837
|
const failed = "problem" in from ? from : to && "problem" in to ? to : undefined;
|
|
@@ -632,8 +845,10 @@ const AnnotationLayer = class {
|
|
|
632
845
|
whole: start.whole,
|
|
633
846
|
area,
|
|
634
847
|
text: start.text && textToLocal(start.text),
|
|
635
|
-
obstacles: (
|
|
848
|
+
obstacles: (_f = start.obstacles) === null || _f === void 0 ? void 0 : _f.map(textToLocal),
|
|
636
849
|
stacked: start.stacked,
|
|
850
|
+
label: start.label,
|
|
851
|
+
horizontal: start.horizontal,
|
|
637
852
|
});
|
|
638
853
|
if (mark) {
|
|
639
854
|
marks.push(mark);
|
|
@@ -753,7 +968,7 @@ const AnnotationLayer = class {
|
|
|
753
968
|
return (index.h("g", null, index.h("circle", { cx: badge.cx, cy: badge.cy, r: badge.r, style: { fill: color } }), badge.label != null ? (index.h("text", { class: "badge-text", x: badge.cx, y: badge.cy, style: { fontSize: `${badge.r * 1.1}px` } }, badge.label)) : null));
|
|
754
969
|
}
|
|
755
970
|
renderMark(mark) {
|
|
756
|
-
var _a, _b,
|
|
971
|
+
var _a, _b, _e, _f, _g;
|
|
757
972
|
const color = annotationColor(mark.color, this.componentStyle(($) => $["bn-annotation"]));
|
|
758
973
|
if (mark.kind === "marker") {
|
|
759
974
|
return (index.h("g", { class: "mark marker", "data-label": mark.badge.label }, this.renderBadge(mark.badge, color)));
|
|
@@ -765,10 +980,16 @@ const AnnotationLayer = class {
|
|
|
765
980
|
const main = annotationColor(undefined, this.componentStyle(($) => $["bn-annotation"]));
|
|
766
981
|
return (index.h("g", { class: "mark difference", "data-label": (_b = mark.badge) === null || _b === void 0 ? void 0 : _b.label }, mark.lines.map((line) => (index.h("line", { class: "difference-line", x1: line.x1, y1: line.y1, x2: line.x2, y2: line.y2 }))), index.h("rect", { x: mark.bar.x, y: mark.bar.y, width: mark.bar.width, height: mark.bar.height, style: { fill: color } }), index.h("text", { class: "mark-text", x: mark.text.x, y: mark.text.y, style: { textAnchor: mark.text.anchor } }, mark.text.value, mark.text.percent ? (index.h("tspan", { class: "percent", dx: "0.35em" }, mark.text.percent)) : null), mark.frame ? (index.h("rect", { x: mark.frame.x, y: mark.frame.y, width: mark.frame.width, height: mark.frame.height, rx: mark.frame.r, ry: mark.frame.r, style: { fill: "none", stroke: main, strokeWidth: "1.5" } })) : null, this.renderBadge(mark.badge, main)));
|
|
767
982
|
}
|
|
768
|
-
|
|
983
|
+
if (mark.kind === "pointer") {
|
|
984
|
+
return (index.h("g", { class: "mark pointer", "data-label": (_e = mark.badge) === null || _e === void 0 ? void 0 : _e.label }, index.h("polygon", { points: mark.shape, style: { fill: color } }), this.renderBadge(mark.badge, color)));
|
|
985
|
+
}
|
|
986
|
+
if (mark.kind === "bracket") {
|
|
987
|
+
return (index.h("g", { class: "mark bracket", "data-label": (_f = mark.badge) === null || _f === void 0 ? void 0 : _f.label }, index.h("polyline", { points: mark.path, style: { fill: "none", stroke: color, strokeWidth: "1.5" } }), mark.frame ? (index.h("rect", { x: mark.frame.x, y: mark.frame.y, width: mark.frame.width, height: mark.frame.height, rx: mark.frame.r, ry: mark.frame.r, style: { fill: "#ffffff", stroke: color, strokeWidth: "1.5" } })) : null, mark.caption ? (index.h("text", { class: "mark-text caption", x: mark.caption.x, y: mark.caption.y }, mark.caption.text)) : null, this.renderBadge(mark.badge, color)));
|
|
988
|
+
}
|
|
989
|
+
return (index.h("g", { class: "mark arrow", "data-label": (_g = mark.badge) === null || _g === void 0 ? void 0 : _g.label }, index.h("line", { x1: mark.x1, y1: mark.y1, x2: mark.x2, y2: mark.y2, style: { stroke: color, strokeWidth: "1.5" } }), index.h("polygon", { points: mark.head, style: { fill: color } }), this.renderBadge(mark.badge, color)));
|
|
769
990
|
}
|
|
770
991
|
render() {
|
|
771
|
-
return (index.h(index.Host, { key: '
|
|
992
|
+
return (index.h(index.Host, { key: '3b82cff435bdbabe51cdb7581afef428a16716b0' }, index.h("svg", { key: '0613bd3ecb59150c6959c9f96322b0f3eafc6164', ref: (el) => (this.svg = el) }, this.marks.map((mark) => this.renderMark(mark)))));
|
|
772
993
|
}
|
|
773
994
|
get element() { return index.getElement(this); }
|
|
774
995
|
static get watchers() { return {
|
|
@@ -9464,9 +9685,15 @@ class Formatter {
|
|
|
9464
9685
|
}
|
|
9465
9686
|
this.formats.set(key, format);
|
|
9466
9687
|
}
|
|
9467
|
-
const
|
|
9688
|
+
const print = (number) => this.groupSeparator === null
|
|
9689
|
+
? format.format(number)
|
|
9690
|
+
: format
|
|
9691
|
+
.formatToParts(number)
|
|
9692
|
+
.map((part) => (part.type === "group" ? this.groupSeparator : part.value))
|
|
9693
|
+
.join("");
|
|
9694
|
+
const text = print(value / scale);
|
|
9468
9695
|
// a small negative that rounds to zero would print "-0"
|
|
9469
|
-
return (text ===
|
|
9696
|
+
return (text === print(-0) ? print(0) : text).replace(/\s+(%)/g, "$1");
|
|
9470
9697
|
}
|
|
9471
9698
|
/**
|
|
9472
9699
|
* Translates a technical scenario identifier into a human-readable IBCS label.
|
|
@@ -9524,6 +9751,11 @@ class Formatter {
|
|
|
9524
9751
|
}
|
|
9525
9752
|
/** One formatter per locale, style and digits: building one per cell is slow. */
|
|
9526
9753
|
Formatter.formats = new Map();
|
|
9754
|
+
/**
|
|
9755
|
+
* Replaces the group separator of the locale in every number, for example by a thin
|
|
9756
|
+
* space. Null: the separator of the locale. One setting for the page: `bn-context` sets it.
|
|
9757
|
+
*/
|
|
9758
|
+
Formatter.groupSeparator = null;
|
|
9527
9759
|
|
|
9528
9760
|
/** Most decimals a label gets: a double has about 15 significant digits. */
|
|
9529
9761
|
const MAX_DECIMALS = 15;
|
|
@@ -14596,6 +14828,55 @@ const Chart$1 = class Chart {
|
|
|
14596
14828
|
this.errors.remove(errId);
|
|
14597
14829
|
}
|
|
14598
14830
|
}
|
|
14831
|
+
validateSums(newValue) {
|
|
14832
|
+
this.warnUnless("sums", ["none", "groups", "total", "all"].includes(newValue), newValue);
|
|
14833
|
+
}
|
|
14834
|
+
validateScenarioLabelPosition(newValue) {
|
|
14835
|
+
this.warnUnless("scenarioLabelPosition", ["bottom", "top"].includes(newValue), newValue);
|
|
14836
|
+
}
|
|
14837
|
+
validateReferenceLine(newValue) {
|
|
14838
|
+
this.warnUnless("referenceLine", withStyled.isBlankInput(newValue) || this.prepareReferenceLine() !== null, newValue);
|
|
14839
|
+
}
|
|
14840
|
+
validateItalicCategories(newValue) {
|
|
14841
|
+
this.warnUnless("italicCategories", withStyled.isBlankInput(newValue) || this.prepareItalicCategories() !== null, newValue);
|
|
14842
|
+
}
|
|
14843
|
+
warnUnless(name, valid, value) {
|
|
14844
|
+
const errId = `WARN_${name}`;
|
|
14845
|
+
if (valid) {
|
|
14846
|
+
this.errors.remove(errId);
|
|
14847
|
+
}
|
|
14848
|
+
else {
|
|
14849
|
+
this.errors.addOrReplace({
|
|
14850
|
+
id: errId,
|
|
14851
|
+
type: "warning",
|
|
14852
|
+
message: name + ": invalid value '" + value + "' is not supported.",
|
|
14853
|
+
});
|
|
14854
|
+
}
|
|
14855
|
+
}
|
|
14856
|
+
prepareReferenceLine() {
|
|
14857
|
+
if (withStyled.isBlankInput(this.referenceLine))
|
|
14858
|
+
return null;
|
|
14859
|
+
try {
|
|
14860
|
+
const parsed = JSON.parse(this.referenceLine);
|
|
14861
|
+
if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.value) !== "number" || !Number.isFinite(parsed.value))
|
|
14862
|
+
return null;
|
|
14863
|
+
return { value: parsed.value, label: typeof parsed.label === "string" ? parsed.label : undefined };
|
|
14864
|
+
}
|
|
14865
|
+
catch (_a) {
|
|
14866
|
+
return null;
|
|
14867
|
+
}
|
|
14868
|
+
}
|
|
14869
|
+
prepareItalicCategories() {
|
|
14870
|
+
if (withStyled.isBlankInput(this.italicCategories))
|
|
14871
|
+
return [];
|
|
14872
|
+
try {
|
|
14873
|
+
const parsed = JSON.parse(this.italicCategories);
|
|
14874
|
+
return Array.isArray(parsed) && parsed.every((entry) => typeof entry === "string") ? parsed : null;
|
|
14875
|
+
}
|
|
14876
|
+
catch (_a) {
|
|
14877
|
+
return null;
|
|
14878
|
+
}
|
|
14879
|
+
}
|
|
14599
14880
|
validateStack(newValue) {
|
|
14600
14881
|
const errId = "WARN_stack";
|
|
14601
14882
|
const errors = withStyled.validateStackConfig(newValue);
|
|
@@ -14709,6 +14990,48 @@ const Chart$1 = class Chart {
|
|
|
14709
14990
|
* Number of decimal digits of the percent labels (relative variances, shares of a 100 % stack)
|
|
14710
14991
|
*/
|
|
14711
14992
|
this.dataFormatDigitsPercent = 2;
|
|
14993
|
+
/**
|
|
14994
|
+
* Sum rows. `groups` adds a row below the rows of each `rowGroup` (level
|
|
14995
|
+
* `category`), `total` a row over all rows, `all` both. A sum row has no
|
|
14996
|
+
* bar: it prints the sum in bold, in a stack one number per series with a
|
|
14997
|
+
* small square in the colour of the series. In a 100 % stack it is a bar
|
|
14998
|
+
* of shares. A sum row does not count for the scale.
|
|
14999
|
+
*
|
|
15000
|
+
* @default "none"
|
|
15001
|
+
* @example sums="all"
|
|
15002
|
+
*/
|
|
15003
|
+
this.sums = "none";
|
|
15004
|
+
/**
|
|
15005
|
+
* Label of the sum row over all rows.
|
|
15006
|
+
*
|
|
15007
|
+
* @default "" (the `SUM_TOTAL` text)
|
|
15008
|
+
* @example sum-title="World"
|
|
15009
|
+
*/
|
|
15010
|
+
this.sumTitle = "";
|
|
15011
|
+
/**
|
|
15012
|
+
* Where the name of the scenario of a chart with plain bars stands:
|
|
15013
|
+
* `bottom` below the last bar, `top` above the first one.
|
|
15014
|
+
*
|
|
15015
|
+
* @default "bottom"
|
|
15016
|
+
* @example scenario-label-position="top"
|
|
15017
|
+
*/
|
|
15018
|
+
this.scenarioLabelPosition = "bottom";
|
|
15019
|
+
/**
|
|
15020
|
+
* A line across the bars at one value of the axis, as a JSON string:
|
|
15021
|
+
* `value` and an optional `label`. In a 100 % stack the value is a percent.
|
|
15022
|
+
*
|
|
15023
|
+
* @default "" (no line)
|
|
15024
|
+
* @example reference-line='{"value":50,"label":"50%"}'
|
|
15025
|
+
*/
|
|
15026
|
+
this.referenceLine = "";
|
|
15027
|
+
/**
|
|
15028
|
+
* Rows that are printed in italics, as a JSON array of values of the
|
|
15029
|
+
* level column, for example the rest rows.
|
|
15030
|
+
*
|
|
15031
|
+
* @default "" (none)
|
|
15032
|
+
* @example italic-categories='["Rest of world"]'
|
|
15033
|
+
*/
|
|
15034
|
+
this.italicCategories = "";
|
|
14712
15035
|
/**
|
|
14713
15036
|
* Stacking configuration as a JSON string. When set, bars are drawn as
|
|
14714
15037
|
* stacked segments instead of side-by-side.
|
|
@@ -14811,6 +15134,10 @@ const Chart$1 = class Chart {
|
|
|
14811
15134
|
this.validateOrderList(this.order);
|
|
14812
15135
|
this.validateMeasureScale(this.measureScale);
|
|
14813
15136
|
this.validateStack(this.stack);
|
|
15137
|
+
this.validateSums(this.sums);
|
|
15138
|
+
this.validateScenarioLabelPosition(this.scenarioLabelPosition);
|
|
15139
|
+
this.validateReferenceLine(this.referenceLine);
|
|
15140
|
+
this.validateItalicCategories(this.italicCategories);
|
|
14814
15141
|
this.validateScaling(this.scale);
|
|
14815
15142
|
}
|
|
14816
15143
|
componentDidRender() {
|
|
@@ -15211,6 +15538,7 @@ const Chart$1 = class Chart {
|
|
|
15211
15538
|
prepareStackConfig() {
|
|
15212
15539
|
if (withStyled.isBlankInput(this.stack)) {
|
|
15213
15540
|
this.errors.remove("WARN_stack_dimensions_scenarios");
|
|
15541
|
+
this.errors.remove("WARN_stack_thickness_variances");
|
|
15214
15542
|
return null;
|
|
15215
15543
|
}
|
|
15216
15544
|
try {
|
|
@@ -15233,10 +15561,27 @@ const Chart$1 = class Chart {
|
|
|
15233
15561
|
else {
|
|
15234
15562
|
this.errors.remove(errId);
|
|
15235
15563
|
}
|
|
15564
|
+
// rows of different height are for the base chart alone: a variance bar has one thickness
|
|
15565
|
+
const byTotal = parsed.thickness === "total";
|
|
15566
|
+
const withVariances = byTotal && this.prepareVariances().length > 0;
|
|
15567
|
+
if (withVariances) {
|
|
15568
|
+
this.errors.addOrReplace({
|
|
15569
|
+
id: "WARN_stack_thickness_variances",
|
|
15570
|
+
type: "warning",
|
|
15571
|
+
message: "stack thickness total: not used together with variances, the rows keep one height.",
|
|
15572
|
+
});
|
|
15573
|
+
}
|
|
15574
|
+
else {
|
|
15575
|
+
this.errors.remove("WARN_stack_thickness_variances");
|
|
15576
|
+
}
|
|
15236
15577
|
return {
|
|
15237
15578
|
by,
|
|
15238
15579
|
mode: parsed.mode || withStyled.StackMode.ABSOLUTE,
|
|
15239
15580
|
order: parsed.order || withStyled.StackOrder.DATASET,
|
|
15581
|
+
percentMark: parsed.percentMark === true,
|
|
15582
|
+
labels: parsed.labels === "value" ? "value" : "share",
|
|
15583
|
+
thickness: byTotal && !withVariances ? "total" : "equal",
|
|
15584
|
+
totalTitle: typeof parsed.totalTitle === "string" ? parsed.totalTitle : undefined,
|
|
15240
15585
|
};
|
|
15241
15586
|
}
|
|
15242
15587
|
catch (_a) {
|
|
@@ -15310,6 +15655,7 @@ const Chart$1 = class Chart {
|
|
|
15310
15655
|
return this.measureUnit;
|
|
15311
15656
|
}
|
|
15312
15657
|
chartTemplate(localScenarioString, idx) {
|
|
15658
|
+
var _a;
|
|
15313
15659
|
const ppu = this.preparePixelPerUnit();
|
|
15314
15660
|
const ppp = this.preparePixelPerPercentage();
|
|
15315
15661
|
const stackConfig = this.prepareStackConfig();
|
|
@@ -15317,7 +15663,7 @@ const Chart$1 = class Chart {
|
|
|
15317
15663
|
const scenarios = this.hidesScenarios() ? variancesScenarios([localScenarioString]) : this.prepareScenarios();
|
|
15318
15664
|
// Dimension stacking uses only the first scenario. Only the base chart draws a stack, a variance needs both of its scenarios
|
|
15319
15665
|
const effectiveScenarios = isBase && (stackConfig === null || stackConfig === void 0 ? void 0 : stackConfig.by) === withStyled.StackBy.DIMENSIONS ? scenarios.slice(0, 1) : scenarios;
|
|
15320
|
-
return (index.h("bn-chart-structure-renderer", { tableName: this.datasetName, dataVersion: this.dataVersion, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideCategories: this.prepareHideCategories(idx), pixelPerUnit: ppu, pixelPerPercentage: ppp, reportAutoScaling: this.handleAutoScalingReport, errors: this.errors, limit: this.prepareLimit(), styles: this.prepareStyle(), i18n: this.prepareI18n(), order: this.prepareOrder(), level: this.prepareLevel(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(idx), stackConfig: stackConfig, dataFormatDigits: { percent: this.dataFormatDigitsPercent, decimal: this.dataFormatDigitsDecimal }, parentDimensions: this.prepareDimension(), ruleSetConfig: this.ruleSetConfig() }));
|
|
15666
|
+
return (index.h("bn-chart-structure-renderer", { tableName: this.datasetName, dataVersion: this.dataVersion, chartTitle: this.prepareChartTitle(idx), scenarios: effectiveScenarios, variances: [localScenarioString], hideCategories: this.prepareHideCategories(idx), pixelPerUnit: ppu, pixelPerPercentage: ppp, reportAutoScaling: this.handleAutoScalingReport, errors: this.errors, limit: this.prepareLimit(), styles: this.prepareStyle(), i18n: this.prepareI18n(), order: this.prepareOrder(), level: this.prepareLevel(), filter: this.prepareFilter(), "measure-scale": this.prepareMeasureScale(), "measure-unit": this.prepareMeasureUnit(), showMeasureScale: this.prepareShowMeasureScale(idx), stackConfig: stackConfig, sums: ["groups", "total", "all"].includes(this.sums) ? this.sums : "none", sumTitle: this.sumTitle, scenarioLabelTop: this.scenarioLabelPosition === "top", referenceLine: isBase ? this.prepareReferenceLine() : null, italicCategories: (_a = this.prepareItalicCategories()) !== null && _a !== void 0 ? _a : [], dataFormatDigits: { percent: this.dataFormatDigitsPercent, decimal: this.dataFormatDigitsDecimal }, parentDimensions: this.prepareDimension(), ruleSetConfig: this.ruleSetConfig() }));
|
|
15321
15667
|
}
|
|
15322
15668
|
/**
|
|
15323
15669
|
* The line this chart wants to be aligned on, in CSS px from the host's
|
|
@@ -15447,7 +15793,7 @@ const Chart$1 = class Chart {
|
|
|
15447
15793
|
this.errors.remove("WARN_scenarios_none");
|
|
15448
15794
|
}
|
|
15449
15795
|
const fontStyles = this.getFontStyles();
|
|
15450
|
-
return (index.h(index.Host, { key: '
|
|
15796
|
+
return (index.h(index.Host, { key: 'eb0b081632a3d8e9475f280357c0b22b17b23df3', style: fontStyles }, index.h("div", { key: '8ecaea33bcd96b312e39868f008aa630e12077c2', class: "container" }, scenariosArray.map(this.chartTemplate))));
|
|
15451
15797
|
}
|
|
15452
15798
|
get element() { return index.getElement(this); }
|
|
15453
15799
|
static get watchers() { return {
|
|
@@ -15487,6 +15833,18 @@ const Chart$1 = class Chart {
|
|
|
15487
15833
|
"dataFormatDigitsPercent": [{
|
|
15488
15834
|
"validateDataFormatDigitsPercent": 0
|
|
15489
15835
|
}],
|
|
15836
|
+
"sums": [{
|
|
15837
|
+
"validateSums": 0
|
|
15838
|
+
}],
|
|
15839
|
+
"scenarioLabelPosition": [{
|
|
15840
|
+
"validateScenarioLabelPosition": 0
|
|
15841
|
+
}],
|
|
15842
|
+
"referenceLine": [{
|
|
15843
|
+
"validateReferenceLine": 0
|
|
15844
|
+
}],
|
|
15845
|
+
"italicCategories": [{
|
|
15846
|
+
"validateItalicCategories": 0
|
|
15847
|
+
}],
|
|
15490
15848
|
"stack": [{
|
|
15491
15849
|
"validateStack": 0
|
|
15492
15850
|
}],
|
|
@@ -15514,7 +15872,7 @@ Chart$1.style = bnChartStructureCss$1();
|
|
|
15514
15872
|
*/
|
|
15515
15873
|
let ElementPositions$1 = class ElementPositions {
|
|
15516
15874
|
// private smallestDataPoint: DataPoint;
|
|
15517
|
-
constructor(padding, scaleFactors, fontSize, numberOfColumns, leftSideLengthSync, titleLength, leftSideWidth, categoryWidth, hasStackedHeaders = false) {
|
|
15875
|
+
constructor(padding, scaleFactors, fontSize, numberOfColumns, leftSideLengthSync, titleLength, leftSideWidth, categoryWidth, hasStackedHeaders = false, rows = null) {
|
|
15518
15876
|
this.categoryPosition = { x: 0, y: 0 };
|
|
15519
15877
|
this.spacings = {
|
|
15520
15878
|
scenarioOffset: 0,
|
|
@@ -15545,6 +15903,7 @@ let ElementPositions$1 = class ElementPositions {
|
|
|
15545
15903
|
this.leftSideLengthSync = leftSideLengthSync;
|
|
15546
15904
|
this.topSideLabelHeight = titleLength > 0 ? this.fontSize : 0;
|
|
15547
15905
|
this.hasStackedHeaders = hasStackedHeaders;
|
|
15906
|
+
this.rows = rows;
|
|
15548
15907
|
this.leftSideLabelLength = this.calculateSideLabelLength(titleLength, leftSideWidth, categoryWidth);
|
|
15549
15908
|
this.calculateSpacings();
|
|
15550
15909
|
this.calculateCategoryPosition();
|
|
@@ -15554,8 +15913,22 @@ let ElementPositions$1 = class ElementPositions {
|
|
|
15554
15913
|
return this.axisPosition.x;
|
|
15555
15914
|
}
|
|
15556
15915
|
getBarCenterPositionY(index) {
|
|
15916
|
+
if (this.rows && index < this.rows.start.length) {
|
|
15917
|
+
const middle = this.rows.start[index] + this.rows.weight[index] / 2;
|
|
15918
|
+
return this.getAxisPositionY() + this.spacings.scenarioOffset + middle * this.spacings.categoryWidth;
|
|
15919
|
+
}
|
|
15557
15920
|
return this.categoryPosition.y + this.spacings.scenarioOffset + index * this.spacings.categoryWidth;
|
|
15558
15921
|
}
|
|
15922
|
+
/** Upper edge of the room of a row. */
|
|
15923
|
+
getRowTopPositionY(index) {
|
|
15924
|
+
const start = this.rows && index < this.rows.start.length ? this.rows.start[index] : index;
|
|
15925
|
+
return this.getAxisPositionY() + this.spacings.scenarioOffset + start * this.spacings.categoryWidth;
|
|
15926
|
+
}
|
|
15927
|
+
/** Thickness of the bar of a row. Rows have one thickness unless the chart sets a row layout. */
|
|
15928
|
+
getBarWidthAt(index) {
|
|
15929
|
+
const weight = this.rows && index < this.rows.weight.length ? this.rows.weight[index] : 1;
|
|
15930
|
+
return this.spacings.barWidth * weight;
|
|
15931
|
+
}
|
|
15559
15932
|
getBarPositionY(index, isPrimaryMarker) {
|
|
15560
15933
|
if (isPrimaryMarker) {
|
|
15561
15934
|
return this.getBarCenterPositionY(index);
|
|
@@ -15576,7 +15949,7 @@ let ElementPositions$1 = class ElementPositions {
|
|
|
15576
15949
|
return this.axisPosition.y - this.spacings.labelToAxis - this.getTopLabelOverhang();
|
|
15577
15950
|
}
|
|
15578
15951
|
getStackedHeaderPositionY() {
|
|
15579
|
-
return this.getBarCenterPositionY(0) - this.
|
|
15952
|
+
return this.getBarCenterPositionY(0) - this.getBarWidthAt(0) * 0.5 - this.spacings.scenarioLabelToBar;
|
|
15580
15953
|
}
|
|
15581
15954
|
getNeedleWidth() {
|
|
15582
15955
|
return this.spacings.needleWidth;
|
|
@@ -15628,14 +16001,18 @@ let ElementPositions$1 = class ElementPositions {
|
|
|
15628
16001
|
return this.spacings.scenarioOffset; // this.categoryOffset;
|
|
15629
16002
|
}
|
|
15630
16003
|
getAxisEndPositionY() {
|
|
15631
|
-
|
|
16004
|
+
const rows = this.rows ? this.rows.total : this.numberOfColumns;
|
|
16005
|
+
return this.getAxisPositionY() + (rows + 1 / 2) * this.spacings.categoryWidth;
|
|
15632
16006
|
}
|
|
15633
16007
|
getScenarioLabelPositionOffsetY(isPrimaryBar) {
|
|
16008
|
+
var _a;
|
|
15634
16009
|
if (isPrimaryBar) {
|
|
15635
16010
|
// The label belongs to the last bar, but the axis line runs past that bar's
|
|
15636
16011
|
// center by (categoryWidth - scenarioOffset); place the label below the axis
|
|
15637
16012
|
// end so the line does not strike through it.
|
|
15638
16013
|
const belowBar = this.getBarWidth() * 0.5 + this.spacings.scenarioLabelToBar;
|
|
16014
|
+
if ((_a = this.rows) === null || _a === void 0 ? void 0 : _a.nameBelowBar)
|
|
16015
|
+
return belowBar;
|
|
15639
16016
|
const belowAxisEnd = this.spacings.categoryWidth - this.spacings.scenarioOffset + this.spacings.labelToAxis;
|
|
15640
16017
|
return Math.max(belowBar, belowAxisEnd);
|
|
15641
16018
|
}
|
|
@@ -16023,6 +16400,14 @@ class StructureChartComponentConfig {
|
|
|
16023
16400
|
this.showMeasureScale = true;
|
|
16024
16401
|
this.dataFormatDigits = { decimal: 1, percent: 2 };
|
|
16025
16402
|
this.stackConfig = null;
|
|
16403
|
+
this.sums = "none";
|
|
16404
|
+
/** Label of the row over all rows. Empty: the `SUM_TOTAL` text. */
|
|
16405
|
+
this.sumTitle = "";
|
|
16406
|
+
/** The name of the scenario stands above the first bar and not below the last one. */
|
|
16407
|
+
this.scenarioLabelTop = false;
|
|
16408
|
+
this.referenceLine = null;
|
|
16409
|
+
/** Values of the level column whose row is printed in italics. */
|
|
16410
|
+
this.italicCategories = [];
|
|
16026
16411
|
}
|
|
16027
16412
|
}
|
|
16028
16413
|
/**
|
|
@@ -16086,6 +16471,21 @@ class StructureChartComponentConfigAdapter {
|
|
|
16086
16471
|
if (withStyled.CompareUtil.isExisting(data.stackConfig)) {
|
|
16087
16472
|
config.stackConfig = data.stackConfig;
|
|
16088
16473
|
}
|
|
16474
|
+
if (withStyled.CompareUtil.isString(data.sums) && ["groups", "total", "all"].includes(data.sums)) {
|
|
16475
|
+
config.sums = data.sums;
|
|
16476
|
+
}
|
|
16477
|
+
if (withStyled.CompareUtil.isString(data.sumTitle)) {
|
|
16478
|
+
config.sumTitle = data.sumTitle;
|
|
16479
|
+
}
|
|
16480
|
+
if (withStyled.CompareUtil.isBoolean(data.scenarioLabelTop)) {
|
|
16481
|
+
config.scenarioLabelTop = data.scenarioLabelTop;
|
|
16482
|
+
}
|
|
16483
|
+
if (withStyled.CompareUtil.isExisting(data.referenceLine)) {
|
|
16484
|
+
config.referenceLine = data.referenceLine;
|
|
16485
|
+
}
|
|
16486
|
+
if (withStyled.CompareUtil.isArray(data.italicCategories)) {
|
|
16487
|
+
config.italicCategories = withStyled.AdapterUtils.adaptArray(data.italicCategories, this.stringAdapter);
|
|
16488
|
+
}
|
|
16089
16489
|
return config;
|
|
16090
16490
|
}
|
|
16091
16491
|
default() {
|
|
@@ -16555,6 +16955,8 @@ class Label {
|
|
|
16555
16955
|
this.group = null;
|
|
16556
16956
|
this.segmentFillColor = null;
|
|
16557
16957
|
this.maxWidth = null;
|
|
16958
|
+
this.bold = false;
|
|
16959
|
+
this.italic = false;
|
|
16558
16960
|
this.ID_SCENARIOLABEL = "Label";
|
|
16559
16961
|
this.CSS_CATEGORIES = "categories";
|
|
16560
16962
|
this.pointPart = "label";
|
|
@@ -16583,6 +16985,12 @@ class Label {
|
|
|
16583
16985
|
this.segmentFillColor = color;
|
|
16584
16986
|
return this;
|
|
16585
16987
|
}
|
|
16988
|
+
/** Bold for a sum row, italic for a rest row. */
|
|
16989
|
+
setEmphasis(bold, italic) {
|
|
16990
|
+
this.bold = bold;
|
|
16991
|
+
this.italic = italic;
|
|
16992
|
+
return this;
|
|
16993
|
+
}
|
|
16586
16994
|
setMaxWidth(width) {
|
|
16587
16995
|
this.maxWidth = width;
|
|
16588
16996
|
return this;
|
|
@@ -16638,6 +17046,10 @@ class Label {
|
|
|
16638
17046
|
}
|
|
16639
17047
|
// @ts-ignore
|
|
16640
17048
|
const text = label.text(prefix + valueStr);
|
|
17049
|
+
if (this.bold)
|
|
17050
|
+
text.font({ weight: "bold" });
|
|
17051
|
+
if (this.italic)
|
|
17052
|
+
text.font({ style: "italic" });
|
|
16641
17053
|
text.move(this.x, this.y);
|
|
16642
17054
|
// One bbox() per label, not two: svg.js caches nothing, and on a detached
|
|
16643
17055
|
// tree each call clones the subtree into the document to measure it.
|
|
@@ -16798,6 +17210,12 @@ class Bar {
|
|
|
16798
17210
|
(_a = this.label) === null || _a === void 0 ? void 0 : _a.setToRelativeVarianceLabel();
|
|
16799
17211
|
return this;
|
|
16800
17212
|
}
|
|
17213
|
+
/** Prints the value in bold: the bar of a sum row. */
|
|
17214
|
+
emphasize() {
|
|
17215
|
+
var _a;
|
|
17216
|
+
(_a = this.label) === null || _a === void 0 ? void 0 : _a.setEmphasis(true, false);
|
|
17217
|
+
return this;
|
|
17218
|
+
}
|
|
16801
17219
|
updateLabelGroup(newGroup) {
|
|
16802
17220
|
var _a;
|
|
16803
17221
|
if (this.isEmpty() || newGroup == null) {
|
|
@@ -16807,7 +17225,7 @@ class Bar {
|
|
|
16807
17225
|
return this;
|
|
16808
17226
|
}
|
|
16809
17227
|
draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
|
|
16810
|
-
var _a, _b;
|
|
17228
|
+
var _a, _b, _c;
|
|
16811
17229
|
if (this.isEmpty() || this.dataPoint.getScenario() == null) {
|
|
16812
17230
|
return this;
|
|
16813
17231
|
}
|
|
@@ -16827,6 +17245,8 @@ class Bar {
|
|
|
16827
17245
|
}
|
|
16828
17246
|
(_a = this.scenarioGroup) === null || _a === void 0 ? void 0 : _a.attr(dataPointAttributes(this.dataPoint.key));
|
|
16829
17247
|
(_b = this.barGroup) === null || _b === void 0 ? void 0 : _b.attr(dataPointAttributes(this.dataPoint.key, "element"));
|
|
17248
|
+
if (!this.isVarianceBar)
|
|
17249
|
+
(_c = this.barGroup) === null || _c === void 0 ? void 0 : _c.attr("data-bn-value", this.dataPoint.value);
|
|
16830
17250
|
if (this.barGroup != null) {
|
|
16831
17251
|
if (this.isOverflowing && this.overflowConfig) {
|
|
16832
17252
|
this.drawOverdriveBar(fillStyle, strokeStyle);
|
|
@@ -17188,6 +17608,12 @@ let Needle$1 = class Needle {
|
|
|
17188
17608
|
this.label.setToRelativeVarianceLabel().setPoint(dataPoint.key);
|
|
17189
17609
|
}
|
|
17190
17610
|
}
|
|
17611
|
+
/** Prints the value in bold: the bar of a sum row. */
|
|
17612
|
+
emphasize() {
|
|
17613
|
+
var _a;
|
|
17614
|
+
(_a = this.label) === null || _a === void 0 ? void 0 : _a.setEmphasis(true, false);
|
|
17615
|
+
return this;
|
|
17616
|
+
}
|
|
17191
17617
|
updateLabelGroup(newGroup) {
|
|
17192
17618
|
var _a;
|
|
17193
17619
|
if (this.isEmpty() || newGroup == null) {
|
|
@@ -17303,7 +17729,7 @@ let Needle$1 = class Needle {
|
|
|
17303
17729
|
* Renders a single horizontal stacked bar segment for the structure chart.
|
|
17304
17730
|
*/
|
|
17305
17731
|
class StackedBar {
|
|
17306
|
-
constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup) {
|
|
17732
|
+
constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup, options = {}) {
|
|
17307
17733
|
this.hasData = false;
|
|
17308
17734
|
this.position = position;
|
|
17309
17735
|
this.styles = styles;
|
|
@@ -17313,6 +17739,7 @@ class StackedBar {
|
|
|
17313
17739
|
this.segmentIndex = segmentIndex;
|
|
17314
17740
|
this.stackMode = stackMode;
|
|
17315
17741
|
this.stack = stack;
|
|
17742
|
+
this.options = options;
|
|
17316
17743
|
this.group = parentGroup;
|
|
17317
17744
|
this.barGroup = parentGroup.group().id(`stacked_bar_${index}_seg_${segmentIndex}`);
|
|
17318
17745
|
if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true && dataPoint.value != null) {
|
|
@@ -17320,6 +17747,7 @@ class StackedBar {
|
|
|
17320
17747
|
}
|
|
17321
17748
|
}
|
|
17322
17749
|
draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
|
|
17750
|
+
var _a;
|
|
17323
17751
|
// a segment without a value (NaN) keeps its place in the stack, so the colours stay, but draws nothing
|
|
17324
17752
|
if (!this.hasData || !Number.isFinite(this.dataPoint.value)) {
|
|
17325
17753
|
return;
|
|
@@ -17327,7 +17755,7 @@ class StackedBar {
|
|
|
17327
17755
|
const value = this.dataPoint.value;
|
|
17328
17756
|
const pixelPerUnit = this.dataPoint.pixelPerUnit;
|
|
17329
17757
|
const axisX = this.position.getBarPositionX();
|
|
17330
|
-
const barWidth = this.position.
|
|
17758
|
+
const barWidth = this.position.getBarWidthAt(this.index);
|
|
17331
17759
|
// a negative segment ends left of its start: the rect begins at the edge that is further left
|
|
17332
17760
|
const segmentLength = Math.abs(this.segment.end - this.segment.start) * pixelPerUnit;
|
|
17333
17761
|
const xPos = axisX + Math.min(this.segment.start, this.segment.end) * pixelPerUnit;
|
|
@@ -17337,16 +17765,24 @@ class StackedBar {
|
|
|
17337
17765
|
const fillStyle = { color: fillColor };
|
|
17338
17766
|
const strokeStyle = { color: fillColor, width: 0.5 };
|
|
17339
17767
|
this.barGroup.attr(dataPointAttributes(this.dataPoint.key, "element"));
|
|
17768
|
+
this.barGroup.attr("data-bn-value", value);
|
|
17340
17769
|
this.barGroup.rect(Math.max(segmentLength, 0.5), barWidth).fill(fillStyle).stroke(strokeStyle).cy(yPos).x(xPos);
|
|
17341
17770
|
// Draw segment value label centered on bar if wide enough
|
|
17342
|
-
|
|
17343
|
-
const
|
|
17771
|
+
// 6 px at the base font of 16 px, less with a smaller font
|
|
17772
|
+
const labelPadding = Math.min(6, this.styles.fontStyles.size * 0.375);
|
|
17773
|
+
const availableWidth = segmentLength - labelPadding;
|
|
17774
|
+
const { bold = false, italic = false } = this.options;
|
|
17775
|
+
const relative = this.stackMode === withStyled.StackMode.RELATIVE || this.stackMode === withStyled.StackMode.ABSOLUTE_RELATIVE;
|
|
17776
|
+
const labelKind = this.stackMode === withStyled.StackMode.RELATIVE ? ((_a = this.options.label) !== null && _a !== void 0 ? _a : "share") : "share";
|
|
17344
17777
|
if (availableWidth > 0) {
|
|
17345
17778
|
const labelX = xPos + segmentLength / 2;
|
|
17346
|
-
if (
|
|
17347
|
-
const labelValue =
|
|
17779
|
+
if (relative && labelKind !== "value") {
|
|
17780
|
+
const labelValue = labelKind === "plain-share"
|
|
17781
|
+
? Formatter.number(this.segment.share * 100, "decimal", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale)
|
|
17782
|
+
: Formatter.number(this.segment.share, "percent", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale);
|
|
17348
17783
|
new Label(this.group, labelX, yPos, "STACK_SEG", labelValue, this.styles, HookLocation.Center, HookLocation.Center)
|
|
17349
17784
|
.setSegmentFill(fillColor)
|
|
17785
|
+
.setEmphasis(bold, italic)
|
|
17350
17786
|
.setMaxWidth(availableWidth)
|
|
17351
17787
|
.setPoint(this.dataPoint.key)
|
|
17352
17788
|
.draw();
|
|
@@ -17355,6 +17791,7 @@ class StackedBar {
|
|
|
17355
17791
|
// Pass raw numeric value - Label.draw() formats with measureScale
|
|
17356
17792
|
new Label(this.group, labelX, yPos, "STACK_SEG", value, this.styles, HookLocation.Center, HookLocation.Center)
|
|
17357
17793
|
.setSegmentFill(fillColor)
|
|
17794
|
+
.setEmphasis(bold, italic)
|
|
17358
17795
|
.setMaxWidth(availableWidth)
|
|
17359
17796
|
.setPoint(this.dataPoint.key)
|
|
17360
17797
|
.draw(dataFormatDigits, measureScale);
|
|
@@ -17362,7 +17799,8 @@ class StackedBar {
|
|
|
17362
17799
|
}
|
|
17363
17800
|
}
|
|
17364
17801
|
drawTotalLabel(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix(), key) {
|
|
17365
|
-
|
|
17802
|
+
var _a, _b;
|
|
17803
|
+
if (this.stackMode === withStyled.StackMode.RELATIVE && !this.options.total) {
|
|
17366
17804
|
return;
|
|
17367
17805
|
}
|
|
17368
17806
|
// like a plain bar: the label of a negative total sits left of the negative side
|
|
@@ -17371,7 +17809,10 @@ class StackedBar {
|
|
|
17371
17809
|
const labelX = this.position.getLabelPositionX(end * this.dataPoint.pixelPerUnit);
|
|
17372
17810
|
const yPos = this.position.getBarPositionY(this.index, true);
|
|
17373
17811
|
const label = new Label(this.group, labelX, yPos, "STACK_TOTAL", this.stack.total, this.styles, HookLocation.Center, isNegative ? HookLocation.Right : HookLocation.Left);
|
|
17374
|
-
label
|
|
17812
|
+
label
|
|
17813
|
+
.setEmphasis((_a = this.options.bold) !== null && _a !== void 0 ? _a : false, (_b = this.options.italic) !== null && _b !== void 0 ? _b : false)
|
|
17814
|
+
.setPoint(key, "total")
|
|
17815
|
+
.draw(dataFormatDigits, measureScale);
|
|
17375
17816
|
}
|
|
17376
17817
|
}
|
|
17377
17818
|
|
|
@@ -17628,6 +18069,8 @@ function stackLabelSide(layouts, totalLabelRoom = () => 0) {
|
|
|
17628
18069
|
return { flipped, clearance: Math.max(0, ...clearance) };
|
|
17629
18070
|
}
|
|
17630
18071
|
|
|
18072
|
+
/** The id of the row that sums the rows a limit cut off. */
|
|
18073
|
+
const REST_ROW_ID = 9999;
|
|
17631
18074
|
/**
|
|
17632
18075
|
* Orchestrates the full rendering pipeline for an IBCS structure (categorical) chart.
|
|
17633
18076
|
*
|
|
@@ -17684,6 +18127,11 @@ class StructureChart {
|
|
|
17684
18127
|
this.stackLabelClearance = { left: 0, right: 0 };
|
|
17685
18128
|
this.fromExpr = "";
|
|
17686
18129
|
this.rowCount = 0;
|
|
18130
|
+
this.sums = "none";
|
|
18131
|
+
this.sumTitle = "";
|
|
18132
|
+
this.scenarioLabelTop = false;
|
|
18133
|
+
this.referenceLine = null;
|
|
18134
|
+
this.italicCategories = [];
|
|
17687
18135
|
this.db = db;
|
|
17688
18136
|
this.tableName = tableName;
|
|
17689
18137
|
this.ruleSet = ruleSet || new IBCSRuleSet();
|
|
@@ -17702,7 +18150,7 @@ class StructureChart {
|
|
|
17702
18150
|
if (this.titleLength > leftSideWidth) {
|
|
17703
18151
|
leftSideWidth = this.titleLength;
|
|
17704
18152
|
}
|
|
17705
|
-
return new ElementPositions$1(new Padding$1(this.styles.padding), this.styles.scaleFactors, this.styles.fontStyles.size, this.dataModel.length, this.leftSideOffsetForHorizontalSync, this.titleLength, leftSideWidth, categoryWidth, !!this.stackConfig && this.variancesDataModel.length === 0);
|
|
18153
|
+
return new ElementPositions$1(new Padding$1(this.styles.padding), this.styles.scaleFactors, this.styles.fontStyles.size, this.dataModel.length, this.leftSideOffsetForHorizontalSync, this.titleLength, leftSideWidth, categoryWidth, (!!this.stackConfig && this.variancesDataModel.length === 0) || this.scenarioLabelTop, this.rowLayout());
|
|
17706
18154
|
}
|
|
17707
18155
|
setStyles(newStyle) {
|
|
17708
18156
|
this.styles = newStyle;
|
|
@@ -17721,7 +18169,17 @@ class StructureChart {
|
|
|
17721
18169
|
this.pixelPerPercentage = config.pixelPerPercentage || 100;
|
|
17722
18170
|
this.setSource(config.filter);
|
|
17723
18171
|
this.level = config.level;
|
|
18172
|
+
this.sums = config.sums;
|
|
18173
|
+
this.sumTitle = config.sumTitle;
|
|
18174
|
+
this.scenarioLabelTop = config.scenarioLabelTop;
|
|
18175
|
+
this.referenceLine = config.referenceLine;
|
|
18176
|
+
this.italicCategories = config.italicCategories;
|
|
17724
18177
|
this.dataModel = this.populateModel(scenarios, config.level, config.sortOrder);
|
|
18178
|
+
// Populate per-dimension stack segments when stacking by a data dimension
|
|
18179
|
+
if (config.stackConfig && config.stackConfig.by !== withStyled.StackBy.SCENARIOS) {
|
|
18180
|
+
this.populateDimensionStackSegments(scenarios, config.stackConfig, config.level);
|
|
18181
|
+
}
|
|
18182
|
+
this.addSumRows(scenarios);
|
|
17725
18183
|
for (const row of this.dataModel) {
|
|
17726
18184
|
for (const dataPoint of [row.scenario1, row.scenario2, row.scenario3, row.scenario4]) {
|
|
17727
18185
|
// a category without a value has no bar: nothing an annotation can point at
|
|
@@ -17730,17 +18188,15 @@ class StructureChart {
|
|
|
17730
18188
|
}
|
|
17731
18189
|
}
|
|
17732
18190
|
}
|
|
17733
|
-
// Populate per-dimension stack segments when stacking by a data dimension
|
|
17734
|
-
if (config.stackConfig && config.stackConfig.by !== withStyled.StackBy.SCENARIOS) {
|
|
17735
|
-
this.populateDimensionStackSegments(scenarios, config.stackConfig, config.level);
|
|
17736
|
-
}
|
|
17737
18191
|
this.variancesDataModel = this.populateVarianceModel(config.variances, this.dataModel);
|
|
17738
18192
|
this.configTitle = config.title;
|
|
17739
18193
|
this.configVariances = (_b = config === null || config === void 0 ? void 0 : config.variances) !== null && _b !== void 0 ? _b : [];
|
|
17740
18194
|
this.updateTitle();
|
|
17741
|
-
|
|
18195
|
+
// a sum row has no bar: it does not count for the scale
|
|
18196
|
+
const bars = this.dataModel.filter((row) => !row.sum);
|
|
18197
|
+
this.smallestDataPointValue = this.findSmallestDataPointValue(bars);
|
|
17742
18198
|
this.smallestVarianceDataPointValue = this.findSmallestDataPointValue(this.variancesDataModel);
|
|
17743
|
-
this.highestDataPointValue = this.findHighestDataPointValue(
|
|
18199
|
+
this.highestDataPointValue = this.findHighestDataPointValue(bars);
|
|
17744
18200
|
this.highestVarianceDataPointValue = this.findHighestDataPointValue(this.variancesDataModel);
|
|
17745
18201
|
this.axisScenario = this.setAxisScenario(config.variances);
|
|
17746
18202
|
this.measureScale = config.measureScale;
|
|
@@ -17857,7 +18313,7 @@ class StructureChart {
|
|
|
17857
18313
|
* from variable width components.
|
|
17858
18314
|
*/
|
|
17859
18315
|
getUnitBarExtent() {
|
|
17860
|
-
var _a, _b;
|
|
18316
|
+
var _a, _b, _c, _d;
|
|
17861
18317
|
const stacked = this.isStacked();
|
|
17862
18318
|
const vt = this.getVarianceType();
|
|
17863
18319
|
const isVariance = vt !== VarianceType$1.NONE;
|
|
@@ -17867,8 +18323,9 @@ class StructureChart {
|
|
|
17867
18323
|
// both sides of the axis; a relative stack is laid out on a span of 1, so its sides add up to 1 * ppu
|
|
17868
18324
|
fixedDomain: stacked ? this.stackSides.positive + this.stackSides.negative : undefined,
|
|
17869
18325
|
relativeVariance: vt === VarianceType$1.RELATIVE,
|
|
17870
|
-
|
|
17871
|
-
|
|
18326
|
+
// a reference line right of the longest bar needs its room too
|
|
18327
|
+
maxPositive: Math.max((_a = highest === null || highest === void 0 ? void 0 : highest.value) !== null && _a !== void 0 ? _a : 0, !stacked && !isVariance ? ((_c = (_b = this.referenceLine) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 0) : 0),
|
|
18328
|
+
minNegative: (_d = smallest === null || smallest === void 0 ? void 0 : smallest.value) !== null && _d !== void 0 ? _d : 0,
|
|
17872
18329
|
});
|
|
17873
18330
|
}
|
|
17874
18331
|
/**
|
|
@@ -17902,6 +18359,8 @@ class StructureChart {
|
|
|
17902
18359
|
return (this.position.getAxisEndPositionY() +
|
|
17903
18360
|
this.position.spacings.labelToAxis +
|
|
17904
18361
|
this.position.fontSize +
|
|
18362
|
+
// the 100% mark stands below the axis end
|
|
18363
|
+
(this.hasPercentMark() ? this.position.fontSize * 0.8 : 0) +
|
|
17905
18364
|
this.styles.padding.bottom);
|
|
17906
18365
|
}
|
|
17907
18366
|
patternToString() {
|
|
@@ -17963,11 +18422,15 @@ class StructureChart {
|
|
|
17963
18422
|
this.drawStackedScenarios(this.dataModel, svgContainer);
|
|
17964
18423
|
this.drawStackedHeaders(this.dataModel, svgContainer);
|
|
17965
18424
|
this.drawAxisAndLabels(this.dataModel, svgContainer, true);
|
|
18425
|
+
this.drawPercentMark(svgContainer);
|
|
17966
18426
|
}
|
|
17967
18427
|
else {
|
|
17968
18428
|
this.drawScenarios(this.dataModel, svgContainer);
|
|
17969
18429
|
this.drawAxisAndLabels(this.dataModel, svgContainer);
|
|
17970
18430
|
}
|
|
18431
|
+
if (this.variancesDataModel.length === 0) {
|
|
18432
|
+
this.drawReferenceLine(svgContainer);
|
|
18433
|
+
}
|
|
17971
18434
|
}
|
|
17972
18435
|
setPattern(fc, fcPolygonPattern) {
|
|
17973
18436
|
this.styles.pattern.set(fc, fcPolygonPattern);
|
|
@@ -18084,7 +18547,7 @@ class StructureChart {
|
|
|
18084
18547
|
};
|
|
18085
18548
|
return obj;
|
|
18086
18549
|
}, {
|
|
18087
|
-
id:
|
|
18550
|
+
id: REST_ROW_ID,
|
|
18088
18551
|
category: "REST",
|
|
18089
18552
|
type: VarianceType$1.NONE,
|
|
18090
18553
|
scenario1: new DataPoint$1(NaN, selectedScenarios[0], this.pixelPerUnit, Scenario$1.NEU),
|
|
@@ -18271,7 +18734,7 @@ class StructureChart {
|
|
|
18271
18734
|
// a 100 % stack prints no total
|
|
18272
18735
|
const totalLabelRoom = (layout) => {
|
|
18273
18736
|
var _a;
|
|
18274
|
-
return ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) === withStyled.StackMode.RELATIVE
|
|
18737
|
+
return ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) === withStyled.StackMode.RELATIVE && this.stackConfig.labels !== "value"
|
|
18275
18738
|
? 0
|
|
18276
18739
|
: (labelToBar + this.calculateTotalLabelWidth(layout.total)) / this.pixelPerUnit;
|
|
18277
18740
|
};
|
|
@@ -18279,6 +18742,8 @@ class StructureChart {
|
|
|
18279
18742
|
}
|
|
18280
18743
|
/** Layouts of the stacks of a row that are drawn, back to front. */
|
|
18281
18744
|
drawnStackLayouts(row) {
|
|
18745
|
+
if (this.isTextSum(row))
|
|
18746
|
+
return [];
|
|
18282
18747
|
return this.stackGroups(row)
|
|
18283
18748
|
.filter((group) => group.hasValue)
|
|
18284
18749
|
.map((group) => group.layout);
|
|
@@ -18326,6 +18791,7 @@ class StructureChart {
|
|
|
18326
18791
|
scenario2: new DataPoint$1(null, null, null, null),
|
|
18327
18792
|
scenario3: new DataPoint$1(null, null, null, null),
|
|
18328
18793
|
scenario4: new DataPoint$1(null, null, null, null),
|
|
18794
|
+
sum: dataModel[index].sum,
|
|
18329
18795
|
});
|
|
18330
18796
|
}
|
|
18331
18797
|
}
|
|
@@ -18397,6 +18863,7 @@ class StructureChart {
|
|
|
18397
18863
|
let isRelative = false;
|
|
18398
18864
|
if (!this.hideCategories) {
|
|
18399
18865
|
dataModel.forEach((elements, index) => {
|
|
18866
|
+
var _a;
|
|
18400
18867
|
if (elements["type"] === VarianceType$1.RELATIVE) {
|
|
18401
18868
|
isRelative = true;
|
|
18402
18869
|
}
|
|
@@ -18418,9 +18885,23 @@ class StructureChart {
|
|
|
18418
18885
|
new Label(axisLabelGroup, this.position.getCategoryPositionX(isPositive) + clearance, this.position.getBarCenterPositionY(index), "",
|
|
18419
18886
|
// Category labels come from the data, but the synthetic "REST"
|
|
18420
18887
|
// overflow bucket is engine-generated and translatable, as in bn-table.
|
|
18421
|
-
this.i18n.get(elements.category) || elements.category, this.styles, HookLocation.Center, textHook)
|
|
18888
|
+
this.i18n.get(elements.category) || elements.category, this.styles, HookLocation.Center, textHook)
|
|
18889
|
+
.setEmphasis(!!((_a = this.dataModel[index]) === null || _a === void 0 ? void 0 : _a.sum), this.isItalic(elements.category))
|
|
18890
|
+
.draw();
|
|
18422
18891
|
});
|
|
18423
18892
|
}
|
|
18893
|
+
// a thin line above a sum row, from the labels to the end of the row
|
|
18894
|
+
dataModel.forEach((_elements, index) => {
|
|
18895
|
+
const row = this.dataModel[index];
|
|
18896
|
+
if (!(row === null || row === void 0 ? void 0 : row.sum))
|
|
18897
|
+
return;
|
|
18898
|
+
const y = this.position.getBarCenterPositionY(index) - this.position.spacings.categoryWidth / 2;
|
|
18899
|
+
const left = this.hideCategories ? this.position.getAxisPositionX() : this.styles.padding.left;
|
|
18900
|
+
axisLabelGroup
|
|
18901
|
+
.line(left, y, this.position.getAxisPositionX() + this.sumRowExtent(row), y)
|
|
18902
|
+
.stroke({ color: "#000000", width: Math.max(0.5, this.position.spacings.axisLineWidth / 2) })
|
|
18903
|
+
.addClass("sum-line");
|
|
18904
|
+
});
|
|
18424
18905
|
new Axis$1({
|
|
18425
18906
|
scenarioType: this.axisScenario,
|
|
18426
18907
|
labelText: this.title,
|
|
@@ -18429,25 +18910,111 @@ class StructureChart {
|
|
|
18429
18910
|
}
|
|
18430
18911
|
drawScenarios(dataModel, svgContainer) {
|
|
18431
18912
|
const barsGroup = svgContainer.group().id("Scenarios");
|
|
18432
|
-
|
|
18913
|
+
// the name of the scenario stands below the last bar, or above the first one
|
|
18914
|
+
let lastBar = -1;
|
|
18915
|
+
dataModel.forEach((row, index) => {
|
|
18916
|
+
if (!row.sum)
|
|
18917
|
+
lastBar = index;
|
|
18918
|
+
});
|
|
18919
|
+
const scenarioFactory = new ScenarioFactory$1(this.position, barsGroup, this.scenarioStyles(),
|
|
18920
|
+
// the factory names the last bar. The row layout leaves room for the name when a sum row follows.
|
|
18921
|
+
this.scenarioLabelTop ? 0 : lastBar + 1, this.i18n);
|
|
18433
18922
|
scenarioFactory.setOverflowConfig(this.overflowConfig);
|
|
18434
18923
|
dataModel.forEach((elements, index) => {
|
|
18924
|
+
if (elements.sum) {
|
|
18925
|
+
this.drawSumValue(elements, index, barsGroup);
|
|
18926
|
+
return;
|
|
18927
|
+
}
|
|
18435
18928
|
scenarioFactory.createPrimaryBar(elements["scenario1"], index).draw(this.dataFormatDigits, this.measureScale);
|
|
18436
18929
|
scenarioFactory.createSecondaryBar(elements["scenario2"], index).draw();
|
|
18437
18930
|
scenarioFactory.createPrimaryMarker(elements["scenario3"], index).draw();
|
|
18438
18931
|
scenarioFactory.createSecondaryMarker(elements["scenario4"], index).draw();
|
|
18439
18932
|
});
|
|
18933
|
+
const first = dataModel.find((row) => !row.sum);
|
|
18934
|
+
if (this.scenarioLabelTop && first && !first.scenario1.isEmpty() && first.scenario1.scenario != null) {
|
|
18935
|
+
const scenario = first.scenario1.scenario;
|
|
18936
|
+
new Label(barsGroup,
|
|
18937
|
+
// from the axis on: the first bar can be shorter than the name
|
|
18938
|
+
this.position.getBarPositionX() + this.position.spacings.labelToAxis, this.position.getStackedHeaderPositionY(), "SCENARIO_HEADER", this.i18n.get(scenario) || scenario, this.styles, HookLocation.Bottom, HookLocation.Left).draw();
|
|
18939
|
+
}
|
|
18940
|
+
}
|
|
18941
|
+
/** The scenarios of a sum row of a chart with plain bars that have a value, in the order of the `scenarios` prop. */
|
|
18942
|
+
sumPoints(row) {
|
|
18943
|
+
const points = [row.scenario1, row.scenario2, row.scenario3, row.scenario4].filter((point) => point != null && !point.isEmpty() && Number.isFinite(point.value));
|
|
18944
|
+
const order = this.scenarioPropOrder;
|
|
18945
|
+
const place = (point) => {
|
|
18946
|
+
const index = order.indexOf(point.scenario);
|
|
18947
|
+
return index === -1 ? order.length : index;
|
|
18948
|
+
};
|
|
18949
|
+
return points.sort((a, b) => place(a) - place(b));
|
|
18950
|
+
}
|
|
18951
|
+
/** How wide the numbers of a sum row of a chart with plain bars are, from the axis on. */
|
|
18952
|
+
sumValuesWidth(row) {
|
|
18953
|
+
const font = this.styles.fontStyles.size;
|
|
18954
|
+
const labelToBar = font * this.styles.scaleFactors.labelToBar;
|
|
18955
|
+
const points = this.sumPoints(row);
|
|
18956
|
+
if (points.length === 0)
|
|
18957
|
+
return 0;
|
|
18958
|
+
const numbers = points.map((point) => this.boldWidth(this.sumText(point.value)));
|
|
18959
|
+
if (points.length === 1)
|
|
18960
|
+
return labelToBar + numbers[0];
|
|
18961
|
+
return labelToBar + numbers.reduce((sum, width) => sum + font * 0.9 + width, 0) + (points.length - 1) * font * 1.4;
|
|
18962
|
+
}
|
|
18963
|
+
/**
|
|
18964
|
+
* The sum row of a chart with plain bars: bold numbers at the axis, no bar. One
|
|
18965
|
+
* scenario is a plain number. Several get a small square each, in the look of the scenario.
|
|
18966
|
+
*/
|
|
18967
|
+
drawSumValue(row, index, group) {
|
|
18968
|
+
const points = this.sumPoints(row);
|
|
18969
|
+
if (points.length === 0)
|
|
18970
|
+
return;
|
|
18971
|
+
const font = this.styles.fontStyles.size;
|
|
18972
|
+
const y = this.position.getBarCenterPositionY(index);
|
|
18973
|
+
const sumGroup = group.group().id(`sum_${index}`);
|
|
18974
|
+
const number = (point, x, hook) => {
|
|
18975
|
+
new Label(sumGroup, x, y, `SUM_${point.scenario}`, point.value, this.styles, HookLocation.Center, hook)
|
|
18976
|
+
.setEmphasis(true, false)
|
|
18977
|
+
.setPoint(point.key)
|
|
18978
|
+
.draw(this.dataFormatDigits, this.measureScale);
|
|
18979
|
+
};
|
|
18980
|
+
if (points.length === 1) {
|
|
18981
|
+
// like the label of a bar without length: a negative number stands left of the axis
|
|
18982
|
+
const negative = points[0].value < 0;
|
|
18983
|
+
number(points[0], this.position.getLabelPositionX(negative ? -1e-6 : 0), negative ? HookLocation.Right : HookLocation.Left);
|
|
18984
|
+
return;
|
|
18985
|
+
}
|
|
18986
|
+
const key = font * 0.6;
|
|
18987
|
+
const barStyles = this.scenarioStyles().barStyles;
|
|
18988
|
+
let x = this.position.getLabelPositionX(0);
|
|
18989
|
+
for (const point of points) {
|
|
18990
|
+
const style = barStyles.getSVGStyle(point.getScenario());
|
|
18991
|
+
sumGroup
|
|
18992
|
+
.rect(key, key)
|
|
18993
|
+
.fill({ color: (style === null || style === void 0 ? void 0 : style.fill) || "#000000" })
|
|
18994
|
+
.stroke({ color: (style === null || style === void 0 ? void 0 : style.stroke) || "#000000", width: 1 })
|
|
18995
|
+
.cy(y)
|
|
18996
|
+
.x(x);
|
|
18997
|
+
number(point, x + key + font * 0.3, HookLocation.Left);
|
|
18998
|
+
x += font * 0.9 + this.boldWidth(this.sumText(point.value)) + font * 1.4;
|
|
18999
|
+
}
|
|
18440
19000
|
}
|
|
18441
19001
|
drawVarianceScenario(dataModel, svgContainer) {
|
|
18442
19002
|
const barsGroup = svgContainer.group().id("Scenarios");
|
|
18443
19003
|
const scenarioFactory = new ScenarioFactory$1(this.position, barsGroup, this.scenarioStyles(), dataModel.length, this.i18n);
|
|
18444
19004
|
scenarioFactory.setOverflowConfig(this.overflowConfig);
|
|
18445
19005
|
dataModel.forEach((elements, index) => {
|
|
19006
|
+
// the variance of a sum row is a bar like the others, with a bold number
|
|
18446
19007
|
if (elements["type"] === VarianceType$1.RELATIVE) {
|
|
18447
|
-
scenarioFactory.createRelativeVarianceBar(elements["scenario1"], index)
|
|
19008
|
+
const needle = scenarioFactory.createRelativeVarianceBar(elements["scenario1"], index);
|
|
19009
|
+
if (elements.sum)
|
|
19010
|
+
needle.emphasize();
|
|
19011
|
+
needle.draw(this.dataFormatDigits);
|
|
18448
19012
|
}
|
|
18449
19013
|
else {
|
|
18450
|
-
scenarioFactory.createVarianceBar(elements["scenario1"], index)
|
|
19014
|
+
const bar = scenarioFactory.createVarianceBar(elements["scenario1"], index);
|
|
19015
|
+
if (elements.sum)
|
|
19016
|
+
bar.emphasize();
|
|
19017
|
+
bar.draw(this.dataFormatDigits, this.measureScale);
|
|
18451
19018
|
}
|
|
18452
19019
|
});
|
|
18453
19020
|
return barsGroup;
|
|
@@ -18475,14 +19042,27 @@ class StructureChart {
|
|
|
18475
19042
|
return;
|
|
18476
19043
|
const stackGroup = svgContainer.group().id("StackedScenarios");
|
|
18477
19044
|
const isScenarioStack = this.stackConfig.by === withStyled.StackBy.SCENARIOS;
|
|
19045
|
+
const relative = this.stackConfig.mode === withStyled.StackMode.RELATIVE;
|
|
19046
|
+
const valueLabels = relative && this.stackConfig.labels === "value";
|
|
19047
|
+
const label = valueLabels ? "value" : this.stackConfig.percentMark ? "plain-share" : "share";
|
|
18478
19048
|
dataModel.forEach((elements, index) => {
|
|
18479
19049
|
const groups = this.stackGroups(elements);
|
|
19050
|
+
if (this.isTextSum(elements)) {
|
|
19051
|
+
this.drawSumText(elements, index, stackGroup);
|
|
19052
|
+
return;
|
|
19053
|
+
}
|
|
19054
|
+
const options = {
|
|
19055
|
+
label,
|
|
19056
|
+
total: valueLabels,
|
|
19057
|
+
bold: !!elements.sum,
|
|
19058
|
+
italic: this.isItalic(elements.category),
|
|
19059
|
+
};
|
|
18480
19060
|
groups.forEach((group, groupIdx) => {
|
|
18481
19061
|
let lastBar = null;
|
|
18482
19062
|
group.segments.forEach((seg, segIdx) => {
|
|
18483
19063
|
const bar = new StackedBar(this.position, this.styles, seg.dataPoint, index, group.layout.segments[segIdx], seg.scenario,
|
|
18484
19064
|
// overlay: one colour per group, back=lighter, front=darker
|
|
18485
|
-
groups.length > 1 ? groups.length - 1 - groupIdx : segIdx, this.stackConfig.mode, group.layout, isScenarioStack, stackGroup);
|
|
19065
|
+
groups.length > 1 ? groups.length - 1 - groupIdx : segIdx, this.stackConfig.mode, group.layout, isScenarioStack, stackGroup, options);
|
|
18486
19066
|
bar.draw(this.dataFormatDigits, this.measureScale);
|
|
18487
19067
|
lastBar = bar;
|
|
18488
19068
|
});
|
|
@@ -18500,9 +19080,10 @@ class StructureChart {
|
|
|
18500
19080
|
* The headers take their place from the first row.
|
|
18501
19081
|
*/
|
|
18502
19082
|
drawStackedHeaders(dataModel, svgContainer) {
|
|
19083
|
+
var _a;
|
|
18503
19084
|
if (!this.stackConfig || dataModel.length === 0)
|
|
18504
19085
|
return;
|
|
18505
|
-
const firstRow = dataModel[0];
|
|
19086
|
+
const firstRow = (_a = dataModel.find((row) => !this.isTextSum(row))) !== null && _a !== void 0 ? _a : dataModel[0];
|
|
18506
19087
|
// Dimension stacking without segments draws one plain bar: nothing to name
|
|
18507
19088
|
if (this.stackConfig.by !== withStyled.StackBy.SCENARIOS && (!firstRow.stackSegments || firstRow.stackSegments.length === 0)) {
|
|
18508
19089
|
return;
|
|
@@ -18527,6 +19108,11 @@ class StructureChart {
|
|
|
18527
19108
|
}
|
|
18528
19109
|
// Single group: one header per segment, centered on the segment
|
|
18529
19110
|
const [group] = groups;
|
|
19111
|
+
const totalDrawn = this.stackConfig.mode !== withStyled.StackMode.RELATIVE || this.stackConfig.labels === "value";
|
|
19112
|
+
if (this.stackConfig.totalTitle && totalDrawn) {
|
|
19113
|
+
// above the total of the first bar, which starts behind the bar
|
|
19114
|
+
new Label(headerGroup, this.position.getLabelPositionX(group.layout.positive * this.pixelPerUnit), headerY, "STACK_TOTAL_HEADER", this.stackConfig.totalTitle, this.styles, HookLocation.Bottom, HookLocation.Left).draw();
|
|
19115
|
+
}
|
|
18530
19116
|
group.segments.forEach((seg, segIdx) => {
|
|
18531
19117
|
const { start, end } = group.layout.segments[segIdx];
|
|
18532
19118
|
drawHeader(axisX + ((start + end) / 2) * seg.dataPoint.pixelPerUnit, this.i18n.get(seg.scenario) || seg.scenario);
|
|
@@ -18579,7 +19165,7 @@ class StructureChart {
|
|
|
18579
19165
|
return width;
|
|
18580
19166
|
}
|
|
18581
19167
|
calculateRightSideWidth(varianceType) {
|
|
18582
|
-
var _a, _b, _c;
|
|
19168
|
+
var _a, _b, _c, _d, _e, _f;
|
|
18583
19169
|
// Stacked charts: width based on the positive side of the stacks, not individual max
|
|
18584
19170
|
if (this.isStacked()) {
|
|
18585
19171
|
const labelToBar = this.styles.fontStyles.size * this.styles.scaleFactors.labelToBar;
|
|
@@ -18591,28 +19177,42 @@ class StructureChart {
|
|
|
18591
19177
|
this.position.getCategoryToAxisSpaceing() +
|
|
18592
19178
|
this.calculateCategoryWidth());
|
|
18593
19179
|
}
|
|
18594
|
-
|
|
19180
|
+
if ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.totalTitle) {
|
|
19181
|
+
const title = CalculateSize(this.stackConfig.totalTitle, {
|
|
19182
|
+
font: this.styles.fontStyles.font,
|
|
19183
|
+
fontSize: this.styles.fontStyles.size + "px",
|
|
19184
|
+
}).width;
|
|
19185
|
+
width = Math.max(width, this.stackSides.positive * this.pixelPerUnit + labelToBar + title);
|
|
19186
|
+
}
|
|
19187
|
+
return Math.max(width, this.titleLength, (_c = (_b = this.sumColumns()) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0, this.referenceLineExtent());
|
|
18595
19188
|
}
|
|
18596
19189
|
let width = 0;
|
|
18597
19190
|
const labelToBar = this.styles.fontStyles.size * this.styles.scaleFactors.labelToBar;
|
|
18598
19191
|
if (VarianceType$1.NONE === varianceType &&
|
|
18599
|
-
((
|
|
19192
|
+
((_d = this.highestDataPointValue) === null || _d === void 0 ? void 0 : _d.value) != null &&
|
|
18600
19193
|
this.highestDataPointValue.value >= 0) {
|
|
18601
19194
|
const sizeLabelValue = this.calculateTextBoxWidth(this.highestDataPointValue.value);
|
|
18602
19195
|
width = Math.abs(this.highestDataPointValue.getScaledUnit()) + labelToBar + sizeLabelValue;
|
|
18603
19196
|
}
|
|
18604
19197
|
else if (VarianceType$1.RELATIVE === varianceType &&
|
|
18605
|
-
((
|
|
19198
|
+
((_e = this.highestVarianceDataPointValue) === null || _e === void 0 ? void 0 : _e.value) != null &&
|
|
18606
19199
|
this.highestVarianceDataPointValue.value >= 0) {
|
|
18607
19200
|
const sizeLabelValue = this.calculatePercentageTextBoxWidth(this.highestVarianceDataPointValue.value);
|
|
18608
19201
|
width = Math.abs(this.highestVarianceDataPointValue.getScaledPercentUnit()) + labelToBar + sizeLabelValue;
|
|
18609
19202
|
}
|
|
18610
19203
|
else if (VarianceType$1.ABSOLUTE === varianceType &&
|
|
18611
|
-
((
|
|
19204
|
+
((_f = this.highestVarianceDataPointValue) === null || _f === void 0 ? void 0 : _f.value) != null &&
|
|
18612
19205
|
this.highestVarianceDataPointValue.value >= 0) {
|
|
18613
19206
|
const sizeLabelValue = this.calculateTextBoxWidth(this.highestVarianceDataPointValue.value);
|
|
18614
19207
|
width = Math.abs(this.highestVarianceDataPointValue.getScaledUnit()) + labelToBar + sizeLabelValue;
|
|
18615
19208
|
}
|
|
19209
|
+
width = Math.max(width, this.referenceLineExtent());
|
|
19210
|
+
// the bold number of a sum row stands at the axis
|
|
19211
|
+
for (const row of this.dataModel) {
|
|
19212
|
+
if (row.sum && VarianceType$1.NONE === varianceType) {
|
|
19213
|
+
width = Math.max(width, this.sumRowExtent(row));
|
|
19214
|
+
}
|
|
19215
|
+
}
|
|
18616
19216
|
if (width <= this.titleLength) {
|
|
18617
19217
|
return this.titleLength;
|
|
18618
19218
|
}
|
|
@@ -18623,6 +19223,7 @@ class StructureChart {
|
|
|
18623
19223
|
* at the stack dimension level and attach stackSegments to each dataModel row.
|
|
18624
19224
|
*/
|
|
18625
19225
|
populateDimensionStackSegments(scenarios, _stackConfig, level) {
|
|
19226
|
+
var _a;
|
|
18626
19227
|
if (this.rowCount === 0 || !this.fromExpr || scenarios.length === 0)
|
|
18627
19228
|
return;
|
|
18628
19229
|
// Derive stack column from level: stack by the next-lower hierarchy dimension
|
|
@@ -18641,6 +19242,7 @@ class StructureChart {
|
|
|
18641
19242
|
let result;
|
|
18642
19243
|
try {
|
|
18643
19244
|
result = this.db.exec(`SELECT [${displayColumn}] as displayGroup, [${stackColumn}] as stackLabel, ` +
|
|
19245
|
+
`MIN([${stackColumn}Index]) as stackIndex, ` +
|
|
18644
19246
|
`SUM([${scenario}] * transformOperator(operation)) as stackValue ` +
|
|
18645
19247
|
`FROM ${this.fromExpr} GROUP BY [${displayColumn}], [${stackColumn}]`);
|
|
18646
19248
|
}
|
|
@@ -18648,19 +19250,46 @@ class StructureChart {
|
|
|
18648
19250
|
this.failQuery(e);
|
|
18649
19251
|
return;
|
|
18650
19252
|
}
|
|
19253
|
+
// The series of the chart: by the index column of the stack dimension, else in the order of the rows
|
|
19254
|
+
const series = new Map();
|
|
19255
|
+
for (const row of result) {
|
|
19256
|
+
if (row.stackValue == null || row.stackLabel == null)
|
|
19257
|
+
continue;
|
|
19258
|
+
const label = row.stackLabel;
|
|
19259
|
+
const index = Number.isFinite(Number(row.stackIndex)) && row.stackIndex != null ? Number(row.stackIndex) : NaN;
|
|
19260
|
+
const known = series.get(label);
|
|
19261
|
+
if (known === undefined || (Number.isNaN(known) && !Number.isNaN(index)) || index < known) {
|
|
19262
|
+
series.set(label, index);
|
|
19263
|
+
}
|
|
19264
|
+
}
|
|
19265
|
+
const order = [...series.keys()];
|
|
19266
|
+
if ([...series.values()].every((index) => !Number.isNaN(index))) {
|
|
19267
|
+
order.sort((a, b) => series.get(a) - series.get(b));
|
|
19268
|
+
}
|
|
18651
19269
|
// Group results by displayGroup
|
|
18652
19270
|
const groupMap = new Map();
|
|
18653
19271
|
for (const row of result) {
|
|
18654
19272
|
const key = row.displayGroup;
|
|
18655
19273
|
if (!groupMap.has(key))
|
|
18656
|
-
groupMap.set(key,
|
|
19274
|
+
groupMap.set(key, new Map());
|
|
18657
19275
|
if (row.stackValue != null && row.stackLabel != null) {
|
|
18658
|
-
groupMap.get(key).
|
|
19276
|
+
groupMap.get(key).set(row.stackLabel, row.stackValue);
|
|
19277
|
+
}
|
|
19278
|
+
}
|
|
19279
|
+
// the REST row stands for the rows the limit cut off: it gets their sum per series
|
|
19280
|
+
const shown = new Set(this.dataModel.map((row) => row.category));
|
|
19281
|
+
const rest = new Map();
|
|
19282
|
+
for (const [category, values] of groupMap) {
|
|
19283
|
+
if (shown.has(category))
|
|
19284
|
+
continue;
|
|
19285
|
+
for (const [label, value] of values) {
|
|
19286
|
+
rest.set(label, ((_a = rest.get(label)) !== null && _a !== void 0 ? _a : 0) + value);
|
|
18659
19287
|
}
|
|
18660
19288
|
}
|
|
18661
|
-
// Attach stackSegments to each dataModel row
|
|
19289
|
+
// Attach stackSegments to each dataModel row: every row has every series, so place and colour stay
|
|
18662
19290
|
for (const row of this.dataModel) {
|
|
18663
|
-
const
|
|
19291
|
+
const values = row.id === REST_ROW_ID && !groupMap.has(row.category) ? rest : groupMap.get(row.category);
|
|
19292
|
+
const segments = values && values.size > 0 ? order.map((label) => { var _a; return ({ label, value: (_a = values.get(label)) !== null && _a !== void 0 ? _a : NaN }); }) : undefined;
|
|
18664
19293
|
if (segments && segments.length > 0) {
|
|
18665
19294
|
row.stackSegments = segments.map((seg) => {
|
|
18666
19295
|
const dataPoint = new DataPoint$1(seg.value, scenario, this.pixelPerUnit, Scenario$1.NEU);
|
|
@@ -18673,6 +19302,339 @@ class StructureChart {
|
|
|
18673
19302
|
}
|
|
18674
19303
|
}
|
|
18675
19304
|
}
|
|
19305
|
+
/** A sum row that is printed as numbers: every stack but a 100 % stack, where it is a bar of shares. */
|
|
19306
|
+
isTextSum(row) {
|
|
19307
|
+
return !!row.sum && !!this.stackConfig && this.stackConfig.mode !== withStyled.StackMode.RELATIVE;
|
|
19308
|
+
}
|
|
19309
|
+
isItalic(category) {
|
|
19310
|
+
return this.italicCategories.includes(category);
|
|
19311
|
+
}
|
|
19312
|
+
hasPercentMark() {
|
|
19313
|
+
var _a;
|
|
19314
|
+
return (!!((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.percentMark) &&
|
|
19315
|
+
this.stackConfig.mode === withStyled.StackMode.RELATIVE &&
|
|
19316
|
+
this.variancesDataModel.length === 0 &&
|
|
19317
|
+
this.isStacked());
|
|
19318
|
+
}
|
|
19319
|
+
/**
|
|
19320
|
+
* Adds the sum rows: one below the rows of each `rowGroup`, which keeps the rows of a
|
|
19321
|
+
* group together, and one over all rows at the end.
|
|
19322
|
+
*/
|
|
19323
|
+
addSumRows(scenarios) {
|
|
19324
|
+
if (this.sums === "none" || this.dataModel.length === 0)
|
|
19325
|
+
return;
|
|
19326
|
+
// a cell without a value is left out, and a sum over no value stays NaN
|
|
19327
|
+
const add = (sum, value) => Number.isFinite(value) ? (Number.isFinite(sum) ? sum : 0) + value : sum;
|
|
19328
|
+
const sumRow = (members, category, sum) => {
|
|
19329
|
+
var _a, _b;
|
|
19330
|
+
const point = (key, index) => new DataPoint$1(scenarios[index] === undefined
|
|
19331
|
+
? undefined
|
|
19332
|
+
: members.reduce((total, row) => add(total, row[key].value), NaN), scenarios[index], this.pixelPerUnit, Scenario$1.NEU);
|
|
19333
|
+
const row = {
|
|
19334
|
+
id: 10000 + this.dataModel.length,
|
|
19335
|
+
category,
|
|
19336
|
+
type: VarianceType$1.NONE,
|
|
19337
|
+
scenario1: point("scenario1", 0),
|
|
19338
|
+
scenario2: point("scenario2", 1),
|
|
19339
|
+
scenario3: point("scenario3", 2),
|
|
19340
|
+
scenario4: point("scenario4", 3),
|
|
19341
|
+
sum,
|
|
19342
|
+
};
|
|
19343
|
+
if (members.some((member) => member.stackSegments)) {
|
|
19344
|
+
const values = new Map();
|
|
19345
|
+
for (const member of members) {
|
|
19346
|
+
for (const segment of (_a = member.stackSegments) !== null && _a !== void 0 ? _a : []) {
|
|
19347
|
+
values.set(segment.label, add((_b = values.get(segment.label)) !== null && _b !== void 0 ? _b : NaN, segment.value));
|
|
19348
|
+
}
|
|
19349
|
+
}
|
|
19350
|
+
row.stackSegments = [...values].map(([label, value]) => {
|
|
19351
|
+
const dataPoint = new DataPoint$1(value, scenarios[0], this.pixelPerUnit, Scenario$1.NEU);
|
|
19352
|
+
return { label, value, dataPoint };
|
|
19353
|
+
});
|
|
19354
|
+
}
|
|
19355
|
+
return row;
|
|
19356
|
+
};
|
|
19357
|
+
const rows = this.dataModel;
|
|
19358
|
+
const result = [];
|
|
19359
|
+
const groups = this.sums === "total" ? new Map() : this.rowGroups();
|
|
19360
|
+
if (groups.size > 0) {
|
|
19361
|
+
const names = [...new Set([...groups.values()].sort((a, b) => a.index - b.index).map((group) => group.name))];
|
|
19362
|
+
for (const name of names) {
|
|
19363
|
+
const members = rows.filter((row) => { var _a; return ((_a = groups.get(row.category)) === null || _a === void 0 ? void 0 : _a.name) === name; });
|
|
19364
|
+
if (members.length === 0)
|
|
19365
|
+
continue;
|
|
19366
|
+
const sum = sumRow(members, name, "group");
|
|
19367
|
+
sum.gapAfter = true;
|
|
19368
|
+
result.push(...members, sum);
|
|
19369
|
+
}
|
|
19370
|
+
// a row without a group, like REST, comes last
|
|
19371
|
+
result.push(...rows.filter((row) => !groups.has(row.category)));
|
|
19372
|
+
}
|
|
19373
|
+
else {
|
|
19374
|
+
result.push(...rows);
|
|
19375
|
+
}
|
|
19376
|
+
if (this.sums === "total" || this.sums === "all") {
|
|
19377
|
+
result.push(sumRow(rows, this.sumTitle || "SUM_TOTAL", "total"));
|
|
19378
|
+
}
|
|
19379
|
+
this.dataModel = result;
|
|
19380
|
+
}
|
|
19381
|
+
/** The `rowGroup` of each row of a chart at level `category`, with the place of the group. */
|
|
19382
|
+
rowGroups() {
|
|
19383
|
+
const groups = new Map();
|
|
19384
|
+
if (this.level !== withStyled.AggregationLevel.CATEGORY && this.level !== withStyled.AggregationLevel.CATEGORYINDEX)
|
|
19385
|
+
return groups;
|
|
19386
|
+
let result;
|
|
19387
|
+
try {
|
|
19388
|
+
result = this.db.exec(`SELECT [category] as category, [rowGroup] as rowGroup, MIN([rowGroupIndex]) as rowGroupIndex ` +
|
|
19389
|
+
`FROM ${this.fromExpr} GROUP BY [category], [rowGroup]`);
|
|
19390
|
+
}
|
|
19391
|
+
catch (e) {
|
|
19392
|
+
this.failQuery(e);
|
|
19393
|
+
return groups;
|
|
19394
|
+
}
|
|
19395
|
+
const first = new Map();
|
|
19396
|
+
result.forEach((row, position) => {
|
|
19397
|
+
var _a;
|
|
19398
|
+
if (row.rowGroup == null || row.rowGroup === "")
|
|
19399
|
+
return;
|
|
19400
|
+
const name = String(row.rowGroup);
|
|
19401
|
+
const given = Number(row.rowGroupIndex);
|
|
19402
|
+
// without an index column the groups keep the order of the rows
|
|
19403
|
+
const index = row.rowGroupIndex != null && Number.isFinite(given) ? given : ((_a = first.get(name)) !== null && _a !== void 0 ? _a : position);
|
|
19404
|
+
if (!first.has(name))
|
|
19405
|
+
first.set(name, index);
|
|
19406
|
+
groups.set(String(row.category), { name, index: Math.min(index, first.get(name)) });
|
|
19407
|
+
});
|
|
19408
|
+
return groups;
|
|
19409
|
+
}
|
|
19410
|
+
/** Rows of different height (`stack.thickness: total`) and the room below a group. Null: all rows are equal. */
|
|
19411
|
+
rowLayout() {
|
|
19412
|
+
var _a;
|
|
19413
|
+
const rows = this.dataModel;
|
|
19414
|
+
// the component does not set it together with variances: a variance bar has one thickness
|
|
19415
|
+
const byTotal = ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.thickness) === "total";
|
|
19416
|
+
// the name of the scenario stands below the last bar: it needs room when a sum row follows
|
|
19417
|
+
const lastBar = rows.reduce((last, row, index) => (row.sum ? last : index), -1);
|
|
19418
|
+
const nameBelow = !this.stackConfig && !this.scenarioLabelTop && lastBar >= 0 && lastBar < rows.length - 1;
|
|
19419
|
+
if (!byTotal && !nameBelow && !rows.some((row) => row.gapAfter))
|
|
19420
|
+
return null;
|
|
19421
|
+
const totals = rows.map((row) => {
|
|
19422
|
+
if (!byTotal || row.sum)
|
|
19423
|
+
return null;
|
|
19424
|
+
const groups = this.stackGroups(row);
|
|
19425
|
+
const front = groups[groups.length - 1];
|
|
19426
|
+
return front ? Math.abs(front.layout.total) : 0;
|
|
19427
|
+
});
|
|
19428
|
+
const weights = this.rowWeights(totals);
|
|
19429
|
+
const start = [];
|
|
19430
|
+
const weight = [];
|
|
19431
|
+
let at = 0;
|
|
19432
|
+
rows.forEach((row, index) => {
|
|
19433
|
+
const rowWeight = weights[index];
|
|
19434
|
+
start.push(at);
|
|
19435
|
+
weight.push(rowWeight);
|
|
19436
|
+
at += rowWeight + (row.gapAfter && index < rows.length - 1 ? 0.5 : 0) + (nameBelow && index === lastBar ? 1 : 0);
|
|
19437
|
+
});
|
|
19438
|
+
return { start, weight, total: at, nameBelowBar: nameBelow };
|
|
19439
|
+
}
|
|
19440
|
+
/**
|
|
19441
|
+
* The height of each row in units of a normal row: by its total, with the same height
|
|
19442
|
+
* over all. A row is at least one line of text high, and the others give up that room.
|
|
19443
|
+
* Null stands for a row that keeps the normal height.
|
|
19444
|
+
*/
|
|
19445
|
+
rowWeights(totals) {
|
|
19446
|
+
const minimum = Math.min(1, 1 / this.styles.scaleFactors.categoryWidth);
|
|
19447
|
+
const weights = totals.map((total) => (total === null ? 1 : 0));
|
|
19448
|
+
const open = new Set(totals.flatMap((total, index) => (total === null ? [] : [index])));
|
|
19449
|
+
let room = open.size;
|
|
19450
|
+
// a row below the minimum is set to it, then the rest is shared again
|
|
19451
|
+
for (;;) {
|
|
19452
|
+
const sum = [...open].reduce((all, index) => all + totals[index], 0);
|
|
19453
|
+
if (sum <= 0) {
|
|
19454
|
+
open.forEach((index) => (weights[index] = room / open.size));
|
|
19455
|
+
break;
|
|
19456
|
+
}
|
|
19457
|
+
const small = [...open].filter((index) => (totals[index] / sum) * room < minimum);
|
|
19458
|
+
if (small.length === 0 || small.length === open.size) {
|
|
19459
|
+
open.forEach((index) => (weights[index] = (totals[index] / sum) * room));
|
|
19460
|
+
break;
|
|
19461
|
+
}
|
|
19462
|
+
for (const index of small) {
|
|
19463
|
+
weights[index] = minimum;
|
|
19464
|
+
room -= minimum;
|
|
19465
|
+
open.delete(index);
|
|
19466
|
+
}
|
|
19467
|
+
}
|
|
19468
|
+
return weights;
|
|
19469
|
+
}
|
|
19470
|
+
boldWidth(text) {
|
|
19471
|
+
return CalculateSize(text, {
|
|
19472
|
+
font: this.styles.fontStyles.font,
|
|
19473
|
+
fontSize: this.styles.fontStyles.size + "px",
|
|
19474
|
+
fontWeight: "bold",
|
|
19475
|
+
}).width;
|
|
19476
|
+
}
|
|
19477
|
+
sumText(value) {
|
|
19478
|
+
const digits = this.dataFormatDigits.decimal;
|
|
19479
|
+
return Formatter.number(value, "decimal", digits, digits, this.measureScale.value, this.styles.locale);
|
|
19480
|
+
}
|
|
19481
|
+
/**
|
|
19482
|
+
* Where the numbers of the text sum rows stand, as distance from the axis: one column
|
|
19483
|
+
* per series, the same for all sum rows, then the total. Null without such a row.
|
|
19484
|
+
*/
|
|
19485
|
+
sumColumns() {
|
|
19486
|
+
const rows = this.dataModel.filter((row) => this.isTextSum(row));
|
|
19487
|
+
if (rows.length === 0)
|
|
19488
|
+
return null;
|
|
19489
|
+
const font = this.styles.fontStyles.size;
|
|
19490
|
+
const key = font * 0.6;
|
|
19491
|
+
const keyGap = font * 0.3;
|
|
19492
|
+
const columnGap = font * 1.4;
|
|
19493
|
+
const widths = [];
|
|
19494
|
+
let totalWidth = 0;
|
|
19495
|
+
for (const row of rows) {
|
|
19496
|
+
const groups = this.stackGroups(row);
|
|
19497
|
+
const front = groups[groups.length - 1];
|
|
19498
|
+
if (!front)
|
|
19499
|
+
continue;
|
|
19500
|
+
front.segments.forEach((segment, index) => {
|
|
19501
|
+
var _a;
|
|
19502
|
+
const width = Number.isFinite(segment.value) ? this.boldWidth(this.sumText(segment.value)) : 0;
|
|
19503
|
+
widths[index] = Math.max((_a = widths[index]) !== null && _a !== void 0 ? _a : 0, width);
|
|
19504
|
+
});
|
|
19505
|
+
totalWidth = Math.max(totalWidth, this.boldWidth(this.sumText(front.layout.total)));
|
|
19506
|
+
}
|
|
19507
|
+
const x = [];
|
|
19508
|
+
let at = font * 0.3;
|
|
19509
|
+
// one series: its sum is the total
|
|
19510
|
+
for (const width of widths.length > 1 ? widths : []) {
|
|
19511
|
+
x.push(at);
|
|
19512
|
+
at += key + keyGap + width + columnGap;
|
|
19513
|
+
}
|
|
19514
|
+
return { x, totalX: at, width: at + totalWidth, key, keyGap };
|
|
19515
|
+
}
|
|
19516
|
+
/** A sum row of a stack as numbers: per series a small square in its colour and the sum, then the total. */
|
|
19517
|
+
drawSumText(row, index, group) {
|
|
19518
|
+
const columns = this.sumColumns();
|
|
19519
|
+
const groups = this.stackGroups(row);
|
|
19520
|
+
const front = groups[groups.length - 1];
|
|
19521
|
+
if (!columns || !front)
|
|
19522
|
+
return;
|
|
19523
|
+
const axisX = this.position.getBarPositionX();
|
|
19524
|
+
const y = this.position.getBarCenterPositionY(index);
|
|
19525
|
+
const colors = this.styles.stackColors;
|
|
19526
|
+
const sumGroup = group.group().id(`stacked_sum_${index}`);
|
|
19527
|
+
front.segments.forEach((segment, segmentIndex) => {
|
|
19528
|
+
if (!Number.isFinite(segment.value) || columns.x[segmentIndex] === undefined)
|
|
19529
|
+
return;
|
|
19530
|
+
const x = axisX + columns.x[segmentIndex];
|
|
19531
|
+
sumGroup
|
|
19532
|
+
.rect(columns.key, columns.key)
|
|
19533
|
+
.fill({ color: colors[segmentIndex % colors.length] })
|
|
19534
|
+
.cy(y)
|
|
19535
|
+
.x(x);
|
|
19536
|
+
new Label(sumGroup, x + columns.key + columns.keyGap, y, `SUM_SEG_${segmentIndex}`, segment.value, this.styles, HookLocation.Center, HookLocation.Left)
|
|
19537
|
+
.setEmphasis(true, false)
|
|
19538
|
+
.setPoint(segment.dataPoint.key)
|
|
19539
|
+
.draw(this.dataFormatDigits, this.measureScale);
|
|
19540
|
+
});
|
|
19541
|
+
new Label(sumGroup, axisX + columns.totalX, y, "SUM_TOTAL", front.layout.total, this.styles, HookLocation.Center, HookLocation.Left)
|
|
19542
|
+
.setEmphasis(true, false)
|
|
19543
|
+
.setPoint(levelKey(this.level, row.category), "total")
|
|
19544
|
+
.draw(this.dataFormatDigits, this.measureScale);
|
|
19545
|
+
}
|
|
19546
|
+
/** How far a sum row reaches right of the axis, in px. */
|
|
19547
|
+
sumRowExtent(row) {
|
|
19548
|
+
var _a, _b, _c;
|
|
19549
|
+
const labelToBar = this.styles.fontStyles.size * this.styles.scaleFactors.labelToBar;
|
|
19550
|
+
if (this.variancesDataModel.length > 0)
|
|
19551
|
+
return 0;
|
|
19552
|
+
if (this.isTextSum(row))
|
|
19553
|
+
return (_b = (_a = this.sumColumns()) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0;
|
|
19554
|
+
if (this.stackConfig) {
|
|
19555
|
+
const total = this.stackConfig.labels === "value" ? labelToBar + this.boldWidth(this.sumText((_c = row.scenario1.value) !== null && _c !== void 0 ? _c : 0)) : 0;
|
|
19556
|
+
return this.stackSides.positive * this.pixelPerUnit + total;
|
|
19557
|
+
}
|
|
19558
|
+
return this.sumValuesWidth(row);
|
|
19559
|
+
}
|
|
19560
|
+
/** Where the reference line stands, as distance from the axis in px. Null without a line in this chart. */
|
|
19561
|
+
referenceLineOffset() {
|
|
19562
|
+
var _a;
|
|
19563
|
+
const line = this.referenceLine;
|
|
19564
|
+
if (!line || !Number.isFinite(line.value) || this.variancesDataModel.length > 0)
|
|
19565
|
+
return null;
|
|
19566
|
+
const relative = ((_a = this.stackConfig) === null || _a === void 0 ? void 0 : _a.mode) === withStyled.StackMode.RELATIVE;
|
|
19567
|
+
return (relative ? line.value / 100 : line.value) * this.pixelPerUnit;
|
|
19568
|
+
}
|
|
19569
|
+
/** The room right of the axis that the reference line and its label need. */
|
|
19570
|
+
referenceLineExtent() {
|
|
19571
|
+
var _a;
|
|
19572
|
+
const offset = this.referenceLineOffset();
|
|
19573
|
+
if (offset === null || offset <= 0)
|
|
19574
|
+
return 0;
|
|
19575
|
+
const label = ((_a = this.referenceLine) === null || _a === void 0 ? void 0 : _a.label)
|
|
19576
|
+
? CalculateSize(this.referenceLine.label, {
|
|
19577
|
+
font: this.styles.fontStyles.font,
|
|
19578
|
+
fontSize: this.styles.fontStyles.size + "px",
|
|
19579
|
+
}).width
|
|
19580
|
+
: 0;
|
|
19581
|
+
return offset + Math.max(label / 2, this.styles.fontStyles.size * 0.25);
|
|
19582
|
+
}
|
|
19583
|
+
/** The end of a 100 % stack: a line along the bar ends and one `100%` below it. */
|
|
19584
|
+
drawPercentMark(svgContainer) {
|
|
19585
|
+
if (!this.hasPercentMark())
|
|
19586
|
+
return;
|
|
19587
|
+
const group = svgContainer.group().id("PercentMark");
|
|
19588
|
+
const font = this.styles.fontStyles.size;
|
|
19589
|
+
const x = this.position.getBarPositionX() + this.stackSides.positive * this.pixelPerUnit;
|
|
19590
|
+
const top = this.position.getAxisPositionY();
|
|
19591
|
+
const bottom = this.position.getAxisEndPositionY();
|
|
19592
|
+
const tip = bottom + font * 0.15;
|
|
19593
|
+
const base = tip + font * 0.5;
|
|
19594
|
+
group.line(x, top, x, bottom).stroke({ color: "#000000", width: this.position.spacings.axisLineWidth });
|
|
19595
|
+
group.polygon(`${x},${tip} ${x - font * 0.25},${base} ${x + font * 0.25},${base}`).fill("#000000");
|
|
19596
|
+
new Label(group, x, base + font * 0.1, "PERCENT_MARK", "100%", this.styles, HookLocation.Top, HookLocation.Center)
|
|
19597
|
+
.setEmphasis(true, false)
|
|
19598
|
+
.draw();
|
|
19599
|
+
}
|
|
19600
|
+
/** A line across the bars at one value, with its label above the first bar. In a 100 % stack the value is a percent. */
|
|
19601
|
+
drawReferenceLine(svgContainer) {
|
|
19602
|
+
const line = this.referenceLine;
|
|
19603
|
+
const offset = this.referenceLineOffset();
|
|
19604
|
+
if (!line || offset === null || this.dataModel.length === 0)
|
|
19605
|
+
return;
|
|
19606
|
+
const group = svgContainer.group().id("ReferenceLine");
|
|
19607
|
+
const font = this.styles.fontStyles.size;
|
|
19608
|
+
const color = `var(--bn-annotation-color, ${withHasError.SYSTEM_STYLE_DEFAULTS["bn-annotation"].color})`;
|
|
19609
|
+
const x = this.position.getBarPositionX() + offset;
|
|
19610
|
+
const top = this.position.getStackedHeaderPositionY() - (this.stackConfig || this.scenarioLabelTop ? font * 1.1 : 0);
|
|
19611
|
+
// down to the last row from the top that reaches the line, or over all rows when the first one does not
|
|
19612
|
+
const reaches = (row) => {
|
|
19613
|
+
var _a, _b;
|
|
19614
|
+
if (row.sum)
|
|
19615
|
+
return false;
|
|
19616
|
+
if (!this.stackConfig)
|
|
19617
|
+
return ((_a = row.scenario1.value) !== null && _a !== void 0 ? _a : 0) >= line.value;
|
|
19618
|
+
const first = (_b = this.stackGroups(row)[0]) === null || _b === void 0 ? void 0 : _b.layout.segments[0];
|
|
19619
|
+
return first != null && first.end * this.pixelPerUnit >= x - this.position.getBarPositionX();
|
|
19620
|
+
};
|
|
19621
|
+
let lastBar = this.dataModel.findIndex((row) => !reaches(row)) - 1;
|
|
19622
|
+
if (lastBar < 0)
|
|
19623
|
+
lastBar = this.dataModel.reduce((last, row, index) => (row.sum ? last : index), 0);
|
|
19624
|
+
const bottom = this.position.getBarCenterPositionY(lastBar) + this.position.getBarWidthAt(lastBar) / 2;
|
|
19625
|
+
group
|
|
19626
|
+
.line(x, top, x, bottom)
|
|
19627
|
+
.attr("style", `stroke: ${color}; stroke-width: ${Math.max(1, this.position.spacings.axisLineWidth)}px`);
|
|
19628
|
+
group
|
|
19629
|
+
.polygon(`${x},${top + font * 0.5} ${x - font * 0.25},${top} ${x + font * 0.25},${top}`)
|
|
19630
|
+
.attr("style", `fill: ${color}`);
|
|
19631
|
+
if (line.label) {
|
|
19632
|
+
group
|
|
19633
|
+
.plain(line.label)
|
|
19634
|
+
.attr({ x, y: top - font * 0.3, "text-anchor": "middle" })
|
|
19635
|
+
.attr("style", `fill: ${color}`);
|
|
19636
|
+
}
|
|
19637
|
+
}
|
|
18676
19638
|
hasNoData() {
|
|
18677
19639
|
return this.dataModel.length === 0;
|
|
18678
19640
|
}
|
|
@@ -18822,6 +19784,16 @@ const BnChartStructureRenderer = class {
|
|
|
18822
19784
|
/** @internal */
|
|
18823
19785
|
this.stackConfig = null;
|
|
18824
19786
|
/** @internal */
|
|
19787
|
+
this.sums = "none";
|
|
19788
|
+
/** @internal */
|
|
19789
|
+
this.sumTitle = "";
|
|
19790
|
+
/** @internal */
|
|
19791
|
+
this.scenarioLabelTop = false;
|
|
19792
|
+
/** @internal */
|
|
19793
|
+
this.referenceLine = null;
|
|
19794
|
+
/** @internal */
|
|
19795
|
+
this.italicCategories = [];
|
|
19796
|
+
/** @internal */
|
|
18825
19797
|
this.parentDimensions = { width: 0, height: 0 };
|
|
18826
19798
|
withHasError.withComponentStatus(this);
|
|
18827
19799
|
}
|
|
@@ -19059,6 +20031,11 @@ const BnChartStructureRenderer = class {
|
|
|
19059
20031
|
showMeasureScale: this.showMeasureScale,
|
|
19060
20032
|
dataFormatDigits: this.dataFormatDigits,
|
|
19061
20033
|
stackConfig: this.stackConfig,
|
|
20034
|
+
sums: this.sums,
|
|
20035
|
+
sumTitle: this.sumTitle,
|
|
20036
|
+
scenarioLabelTop: this.scenarioLabelTop,
|
|
20037
|
+
referenceLine: this.referenceLine,
|
|
20038
|
+
italicCategories: this.italicCategories,
|
|
19062
20039
|
});
|
|
19063
20040
|
}
|
|
19064
20041
|
prepareStyle() {
|
|
@@ -25335,12 +26312,41 @@ const Context = class {
|
|
|
25335
26312
|
constructor(hostRef) {
|
|
25336
26313
|
index.registerInstance(this, hostRef);
|
|
25337
26314
|
this.bnNotationChange = index.createEvent(this, "bnNotationChange", 7);
|
|
26315
|
+
/**
|
|
26316
|
+
* Group separator of every number in the document, in place of the one of
|
|
26317
|
+
* the locale: `thin-space`, `space`, `none`, or the separator itself. It
|
|
26318
|
+
* holds for the whole page, also for a context that does not set it.
|
|
26319
|
+
*
|
|
26320
|
+
* @default "" (the separator of the locale)
|
|
26321
|
+
* @example group-separator="thin-space"
|
|
26322
|
+
*/
|
|
26323
|
+
this.groupSeparator = "";
|
|
26324
|
+
this.setsGroupSeparator = false;
|
|
25338
26325
|
/** The page numbers this context wrote. A number that is not in here was set by the author and is left alone. */
|
|
25339
26326
|
this.assignedPageNumbers = new WeakMap();
|
|
25340
26327
|
this.notationSubscriptions = [];
|
|
25341
26328
|
withHasError.withComponentStatus(this);
|
|
25342
26329
|
this.errors = withHasError.withHasError(this);
|
|
25343
26330
|
}
|
|
26331
|
+
watchGroupSeparator(newValue) {
|
|
26332
|
+
var _a;
|
|
26333
|
+
const before = Formatter.groupSeparator;
|
|
26334
|
+
this.setGroupSeparator(newValue);
|
|
26335
|
+
// the numbers are drawn with the old separator: what follows the locale draws again
|
|
26336
|
+
const state = (_a = this.stores) === null || _a === void 0 ? void 0 : _a.context.state;
|
|
26337
|
+
if (state && Formatter.groupSeparator !== before) {
|
|
26338
|
+
const locale = state.locale;
|
|
26339
|
+
state.locale = "";
|
|
26340
|
+
state.locale = locale;
|
|
26341
|
+
}
|
|
26342
|
+
}
|
|
26343
|
+
setGroupSeparator(newValue) {
|
|
26344
|
+
var _a;
|
|
26345
|
+
const named = { "thin-space": "\u2009", space: "\u00a0", none: "" };
|
|
26346
|
+
// no value: the separator of the locale
|
|
26347
|
+
Formatter.groupSeparator = newValue ? ((_a = named[newValue]) !== null && _a !== void 0 ? _a : newValue) : null;
|
|
26348
|
+
this.setsGroupSeparator = !!newValue;
|
|
26349
|
+
}
|
|
25344
26350
|
setLocale(newValue) {
|
|
25345
26351
|
this.stores.context.state.locale = newValue;
|
|
25346
26352
|
}
|
|
@@ -25352,6 +26358,9 @@ const Context = class {
|
|
|
25352
26358
|
if (this.locale) {
|
|
25353
26359
|
this.stores.context.state.locale = this.locale;
|
|
25354
26360
|
}
|
|
26361
|
+
if (this.groupSeparator) {
|
|
26362
|
+
this.setGroupSeparator(this.groupSeparator);
|
|
26363
|
+
}
|
|
25355
26364
|
// a removed scaling group is a "set" too: its entry is set to undefined
|
|
25356
26365
|
const notify = () => this.bnNotationChange.emit();
|
|
25357
26366
|
this.notationSubscriptions = [
|
|
@@ -25370,6 +26379,11 @@ const Context = class {
|
|
|
25370
26379
|
}
|
|
25371
26380
|
disconnectedCallback() {
|
|
25372
26381
|
var _a, _b;
|
|
26382
|
+
// only the context that set it takes it back
|
|
26383
|
+
if (this.setsGroupSeparator) {
|
|
26384
|
+
Formatter.groupSeparator = null;
|
|
26385
|
+
this.setsGroupSeparator = false;
|
|
26386
|
+
}
|
|
25373
26387
|
this.notationSubscriptions.forEach((unsubscribe) => unsubscribe());
|
|
25374
26388
|
this.notationSubscriptions = [];
|
|
25375
26389
|
(_a = this.pageObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
@@ -25522,10 +26536,13 @@ const Context = class {
|
|
|
25522
26536
|
componentWillUpdate() { }
|
|
25523
26537
|
componentDidUpdate() { }
|
|
25524
26538
|
render() {
|
|
25525
|
-
return (index.h(index.Host, { key: '
|
|
26539
|
+
return (index.h(index.Host, { key: '30cd6749c3af25eb4f287ee2771aff0858f4368d' }, index.h("slot", { key: 'ea8bab237f0103f3e3e259ff660004af9a30f982' })));
|
|
25526
26540
|
}
|
|
25527
26541
|
get element() { return index.getElement(this); }
|
|
25528
26542
|
static get watchers() { return {
|
|
26543
|
+
"groupSeparator": [{
|
|
26544
|
+
"watchGroupSeparator": 0
|
|
26545
|
+
}],
|
|
25529
26546
|
"locale": [{
|
|
25530
26547
|
"setLocale": 0
|
|
25531
26548
|
}]
|
|
@@ -27019,6 +28036,16 @@ const LayoutCard = class {
|
|
|
27019
28036
|
* card-custom-template='"a a" "b c"'></bn-layout-card>
|
|
27020
28037
|
*/
|
|
27021
28038
|
this.cardCustomTemplate = '"a b" "c d"';
|
|
28039
|
+
/**
|
|
28040
|
+
* Puts the child after the last slot of the template on top of the grid,
|
|
28041
|
+
* in the cells this CSS `grid-area` names by line numbers:
|
|
28042
|
+
* `row-start / column-start / row-end / column-end`. Use it for a text or a
|
|
28043
|
+
* comment list in the free part of a chart.
|
|
28044
|
+
*
|
|
28045
|
+
* @default "" (no overlay)
|
|
28046
|
+
* @example card-overlay-area="4 / 3 / 7 / 5"
|
|
28047
|
+
*/
|
|
28048
|
+
this.cardOverlayArea = "";
|
|
27022
28049
|
/**
|
|
27023
28050
|
* Gap between grid cells in pixels.
|
|
27024
28051
|
*/
|
|
@@ -27099,7 +28126,20 @@ const LayoutCard = class {
|
|
|
27099
28126
|
const items = this.createDivAreaStyles(slotNames);
|
|
27100
28127
|
return (index.h(index.Fragment, null, items.map((value, index$1) => {
|
|
27101
28128
|
return (index.h("div", { style: value }, index.h("slot", { name: "card-slot-" + index$1 })));
|
|
27102
|
-
})));
|
|
28129
|
+
}), this.overlayArea() ? (index.h("div", { style: { display: "flex", overflow: "hidden", "grid-area": this.overlayArea(), "z-index": "1" } }, index.h("slot", { name: "card-slot-" + items.length }))) : null));
|
|
28130
|
+
}
|
|
28131
|
+
/** The overlay area when it is four line numbers inside the grid of the layout, else nothing. */
|
|
28132
|
+
overlayArea() {
|
|
28133
|
+
var _a, _b;
|
|
28134
|
+
const area = ((_a = this.cardOverlayArea) !== null && _a !== void 0 ? _a : "").trim();
|
|
28135
|
+
if (!/^\d+(\s*\/\s*\d+){3}$/.test(area))
|
|
28136
|
+
return undefined;
|
|
28137
|
+
const [rowStart, columnStart, rowEnd, columnEnd] = area.split("/").map((line) => Number(line.trim()));
|
|
28138
|
+
const rows = this.getRowCount(this.cardLayout);
|
|
28139
|
+
const columns = ((_b = templateRows(this.getTemplatePattern(this.cardLayout))[0]) === null || _b === void 0 ? void 0 : _b.length) || 1;
|
|
28140
|
+
// a line outside the template would add rows or columns to the grid
|
|
28141
|
+
const inside = rowStart >= 1 && columnStart >= 1 && rowEnd <= rows + 1 && columnEnd <= columns + 1;
|
|
28142
|
+
return inside && rowStart < rowEnd && columnStart < columnEnd ? area : undefined;
|
|
27103
28143
|
}
|
|
27104
28144
|
extractSlotNames(styleElement) {
|
|
27105
28145
|
return templateSlotNames(styleElement);
|
|
@@ -27108,6 +28148,7 @@ const LayoutCard = class {
|
|
|
27108
28148
|
return templateAreas(name, this.cardCustomTemplate);
|
|
27109
28149
|
}
|
|
27110
28150
|
componentWillRender() {
|
|
28151
|
+
var _a;
|
|
27111
28152
|
const problem = this.cardLayout === CUSTOM_TEMPLATE ? templateProblem(this.cardCustomTemplate) : undefined;
|
|
27112
28153
|
if (problem) {
|
|
27113
28154
|
this.errors.addOrReplace({
|
|
@@ -27119,6 +28160,16 @@ const LayoutCard = class {
|
|
|
27119
28160
|
else {
|
|
27120
28161
|
this.errors.remove("WARN_cardCustomTemplate");
|
|
27121
28162
|
}
|
|
28163
|
+
if (((_a = this.cardOverlayArea) !== null && _a !== void 0 ? _a : "").trim() !== "" && !this.overlayArea()) {
|
|
28164
|
+
this.errors.addOrReplace({
|
|
28165
|
+
id: "WARN_cardOverlayArea",
|
|
28166
|
+
type: "warning",
|
|
28167
|
+
message: `cardOverlayArea: '${this.cardOverlayArea}' is not 'row-start / column-start / row-end / column-end' in line numbers of the layout.`,
|
|
28168
|
+
});
|
|
28169
|
+
}
|
|
28170
|
+
else {
|
|
28171
|
+
this.errors.remove("WARN_cardOverlayArea");
|
|
28172
|
+
}
|
|
27122
28173
|
}
|
|
27123
28174
|
setCardClass() {
|
|
27124
28175
|
if (this.cardShowBorder === true) {
|
|
@@ -27145,7 +28196,7 @@ const LayoutCard = class {
|
|
|
27145
28196
|
var _a;
|
|
27146
28197
|
const style = this.getLayoutStyle();
|
|
27147
28198
|
const arrOfSlots = this.extractSlotNames(style["grid-template-areas"]);
|
|
27148
|
-
return (index.h("bn-card", { key: '
|
|
28199
|
+
return (index.h("bn-card", { key: 'ef0b6da39a573f162c096c21803e4d647b2817c2', styles: this.styles, "selected-style": this.selectedStyle, class: this.setCardClass() }, index.h("div", { key: '9116df8c88198ebc922dc91d5f45a032a81d37d1', class: "cardtitle" }, index.h("bn-title", { key: '6d9645d5229c3bf32ef944c1f296a55dbe4b3bee', "i18n-namespace": (_a = this.i18nNamespace) !== null && _a !== void 0 ? _a : this.titleNamespace, ruleset: this.titleProp("ruleset"), "title-font-size": this.componentStyle(($) => { var _a; return (_a = $ === null || $ === void 0 ? void 0 : $["bn-layout-card"]) === null || _a === void 0 ? void 0 : _a.titleFontSize; }), "business-unit": this.titleBusinessUnit, scenarios: this.titleProp("titleScenarios"), variances: this.titleProp("titleVariances"), order: this.titleProp("titleOrder"), "order-direction": this.titleProp("titleOrderDirection"), measures: this.titleMeasures, "date-start": this.titleDateStart, "date-end": this.titleDateEnd, "date-format": this.titleDateFormat, "date-link": this.titleDateLink }), this.titleImage != null && this.titleImage !== "" ? (index.h("img", { class: "image", src: this.prepareTitleImage(this.titleImage) })) : ("")), index.h("bn-body", { key: '65803497adad305f02874acf441867e9ba200945' }, index.h("div", { key: '61a57b87b0ffb76c238b2e2facb7d5b855d5dc10', style: style, "data-bn-fit-content": this.cardFitToContent ? String(this.getRowCount(this.cardLayout)) : null }, this.getSlots(arrOfSlots))), index.h("bn-footer", { key: '8589da921d0f8dac8e9a2af23315ded3a3ee3d51', text: this.footerText, "page-number": "0", "display-page-number": "false" })));
|
|
27149
28200
|
}
|
|
27150
28201
|
get element() { return index.getElement(this); }
|
|
27151
28202
|
};
|