@bino-bi/bn-template-engine 1.0.0-next.49 → 1.0.0-next.51
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-0cad5598.entry.js +1 -0
- package/dist/bn-template-engine/{p-2de524d0.entry.js → p-150bdb68.entry.js} +1 -1
- 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 +1045 -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 +507 -27
- package/dist/collection/components/bn-chart-structure/utils/elements/Bar.js +3 -1
- package/dist/collection/components/bn-chart-structure/utils/elements/Label.js +12 -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 +19 -3
- package/dist/collection/components/bn-chart-structure/utils/model/StructureChartComponentConfig.js +23 -0
- package/dist/collection/components/bn-context/bn-context.js +56 -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-Dpc8_R-Y.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-jEqo8YD5.js +1 -0
- package/dist/esm/bn-annotation-layer_30.entry.js +1045 -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 +42 -0
- 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 +45 -0
- package/dist/types/components/bn-chart-structure/utils/elements/Label.d.ts +4 -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 +13 -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 +11 -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 +12 -0
- 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
|
@@ -84,7 +84,7 @@ export class Bar {
|
|
|
84
84
|
return this;
|
|
85
85
|
}
|
|
86
86
|
draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
|
|
87
|
-
var _a, _b;
|
|
87
|
+
var _a, _b, _c;
|
|
88
88
|
if (this.isEmpty() || this.dataPoint.getScenario() == null) {
|
|
89
89
|
return this;
|
|
90
90
|
}
|
|
@@ -104,6 +104,8 @@ export class Bar {
|
|
|
104
104
|
}
|
|
105
105
|
(_a = this.scenarioGroup) === null || _a === void 0 ? void 0 : _a.attr(dataPointAttributes(this.dataPoint.key));
|
|
106
106
|
(_b = this.barGroup) === null || _b === void 0 ? void 0 : _b.attr(dataPointAttributes(this.dataPoint.key, "element"));
|
|
107
|
+
if (!this.isVarianceBar)
|
|
108
|
+
(_c = this.barGroup) === null || _c === void 0 ? void 0 : _c.attr("data-bn-value", this.dataPoint.value);
|
|
107
109
|
if (this.barGroup != null) {
|
|
108
110
|
if (this.isOverflowing && this.overflowConfig) {
|
|
109
111
|
this.drawOverdriveBar(fillStyle, strokeStyle);
|
|
@@ -32,6 +32,8 @@ export class Label {
|
|
|
32
32
|
this.group = null;
|
|
33
33
|
this.segmentFillColor = null;
|
|
34
34
|
this.maxWidth = null;
|
|
35
|
+
this.bold = false;
|
|
36
|
+
this.italic = false;
|
|
35
37
|
this.ID_SCENARIOLABEL = "Label";
|
|
36
38
|
this.CSS_CATEGORIES = "categories";
|
|
37
39
|
this.pointPart = "label";
|
|
@@ -60,6 +62,12 @@ export class Label {
|
|
|
60
62
|
this.segmentFillColor = color;
|
|
61
63
|
return this;
|
|
62
64
|
}
|
|
65
|
+
/** Bold for a sum row, italic for a rest row. */
|
|
66
|
+
setEmphasis(bold, italic) {
|
|
67
|
+
this.bold = bold;
|
|
68
|
+
this.italic = italic;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
63
71
|
setMaxWidth(width) {
|
|
64
72
|
this.maxWidth = width;
|
|
65
73
|
return this;
|
|
@@ -115,6 +123,10 @@ export class Label {
|
|
|
115
123
|
}
|
|
116
124
|
// @ts-ignore
|
|
117
125
|
const text = label.text(prefix + valueStr);
|
|
126
|
+
if (this.bold)
|
|
127
|
+
text.font({ weight: "bold" });
|
|
128
|
+
if (this.italic)
|
|
129
|
+
text.font({ style: "italic" });
|
|
118
130
|
text.move(this.x, this.y);
|
|
119
131
|
// One bbox() per label, not two: svg.js caches nothing, and on a detached
|
|
120
132
|
// tree each call clones the subtree into the document to measure it.
|
|
@@ -7,7 +7,7 @@ import { dataPointAttributes } from "../../../../utils/layoutState/dataPoint";
|
|
|
7
7
|
* Renders a single horizontal stacked bar segment for the structure chart.
|
|
8
8
|
*/
|
|
9
9
|
export class StackedBar {
|
|
10
|
-
constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup) {
|
|
10
|
+
constructor(position, styles, dataPoint, index, segment, _segmentLabel, segmentIndex, stackMode, stack, _isScenarioStack, parentGroup, options = {}) {
|
|
11
11
|
this.hasData = false;
|
|
12
12
|
this.position = position;
|
|
13
13
|
this.styles = styles;
|
|
@@ -17,6 +17,7 @@ export class StackedBar {
|
|
|
17
17
|
this.segmentIndex = segmentIndex;
|
|
18
18
|
this.stackMode = stackMode;
|
|
19
19
|
this.stack = stack;
|
|
20
|
+
this.options = options;
|
|
20
21
|
this.group = parentGroup;
|
|
21
22
|
this.barGroup = parentGroup.group().id(`stacked_bar_${index}_seg_${segmentIndex}`);
|
|
22
23
|
if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true && dataPoint.value != null) {
|
|
@@ -24,6 +25,7 @@ export class StackedBar {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
|
|
28
|
+
var _a;
|
|
27
29
|
// a segment without a value (NaN) keeps its place in the stack, so the colours stay, but draws nothing
|
|
28
30
|
if (!this.hasData || !Number.isFinite(this.dataPoint.value)) {
|
|
29
31
|
return;
|
|
@@ -31,7 +33,7 @@ export class StackedBar {
|
|
|
31
33
|
const value = this.dataPoint.value;
|
|
32
34
|
const pixelPerUnit = this.dataPoint.pixelPerUnit;
|
|
33
35
|
const axisX = this.position.getBarPositionX();
|
|
34
|
-
const barWidth = this.position.
|
|
36
|
+
const barWidth = this.position.getBarWidthAt(this.index);
|
|
35
37
|
// a negative segment ends left of its start: the rect begins at the edge that is further left
|
|
36
38
|
const segmentLength = Math.abs(this.segment.end - this.segment.start) * pixelPerUnit;
|
|
37
39
|
const xPos = axisX + Math.min(this.segment.start, this.segment.end) * pixelPerUnit;
|
|
@@ -41,16 +43,24 @@ export class StackedBar {
|
|
|
41
43
|
const fillStyle = { color: fillColor };
|
|
42
44
|
const strokeStyle = { color: fillColor, width: 0.5 };
|
|
43
45
|
this.barGroup.attr(dataPointAttributes(this.dataPoint.key, "element"));
|
|
46
|
+
this.barGroup.attr("data-bn-value", value);
|
|
44
47
|
this.barGroup.rect(Math.max(segmentLength, 0.5), barWidth).fill(fillStyle).stroke(strokeStyle).cy(yPos).x(xPos);
|
|
45
48
|
// Draw segment value label centered on bar if wide enough
|
|
46
|
-
|
|
47
|
-
const
|
|
49
|
+
// 6 px at the base font of 16 px, less with a smaller font
|
|
50
|
+
const labelPadding = Math.min(6, this.styles.fontStyles.size * 0.375);
|
|
51
|
+
const availableWidth = segmentLength - labelPadding;
|
|
52
|
+
const { bold = false, italic = false } = this.options;
|
|
53
|
+
const relative = this.stackMode === StackMode.RELATIVE || this.stackMode === StackMode.ABSOLUTE_RELATIVE;
|
|
54
|
+
const labelKind = this.stackMode === StackMode.RELATIVE ? ((_a = this.options.label) !== null && _a !== void 0 ? _a : "share") : "share";
|
|
48
55
|
if (availableWidth > 0) {
|
|
49
56
|
const labelX = xPos + segmentLength / 2;
|
|
50
|
-
if (
|
|
51
|
-
const labelValue =
|
|
57
|
+
if (relative && labelKind !== "value") {
|
|
58
|
+
const labelValue = labelKind === "plain-share"
|
|
59
|
+
? Formatter.number(this.segment.share * 100, "decimal", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale)
|
|
60
|
+
: Formatter.number(this.segment.share, "percent", dataFormatDigits.percent, dataFormatDigits.percent, 1, this.styles.locale);
|
|
52
61
|
new Label(this.group, labelX, yPos, "STACK_SEG", labelValue, this.styles, HookLocation.Center, HookLocation.Center)
|
|
53
62
|
.setSegmentFill(fillColor)
|
|
63
|
+
.setEmphasis(bold, italic)
|
|
54
64
|
.setMaxWidth(availableWidth)
|
|
55
65
|
.setPoint(this.dataPoint.key)
|
|
56
66
|
.draw();
|
|
@@ -59,6 +69,7 @@ export class StackedBar {
|
|
|
59
69
|
// Pass raw numeric value - Label.draw() formats with measureScale
|
|
60
70
|
new Label(this.group, labelX, yPos, "STACK_SEG", value, this.styles, HookLocation.Center, HookLocation.Center)
|
|
61
71
|
.setSegmentFill(fillColor)
|
|
72
|
+
.setEmphasis(bold, italic)
|
|
62
73
|
.setMaxWidth(availableWidth)
|
|
63
74
|
.setPoint(this.dataPoint.key)
|
|
64
75
|
.draw(dataFormatDigits, measureScale);
|
|
@@ -66,7 +77,8 @@ export class StackedBar {
|
|
|
66
77
|
}
|
|
67
78
|
}
|
|
68
79
|
drawTotalLabel(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix(), key) {
|
|
69
|
-
|
|
80
|
+
var _a, _b;
|
|
81
|
+
if (this.stackMode === StackMode.RELATIVE && !this.options.total) {
|
|
70
82
|
return;
|
|
71
83
|
}
|
|
72
84
|
// like a plain bar: the label of a negative total sits left of the negative side
|
|
@@ -75,6 +87,9 @@ export class StackedBar {
|
|
|
75
87
|
const labelX = this.position.getLabelPositionX(end * this.dataPoint.pixelPerUnit);
|
|
76
88
|
const yPos = this.position.getBarPositionY(this.index, true);
|
|
77
89
|
const label = new Label(this.group, labelX, yPos, "STACK_TOTAL", this.stack.total, this.styles, HookLocation.Center, isNegative ? HookLocation.Right : HookLocation.Left);
|
|
78
|
-
label
|
|
90
|
+
label
|
|
91
|
+
.setEmphasis((_a = this.options.bold) !== null && _a !== void 0 ? _a : false, (_b = this.options.italic) !== null && _b !== void 0 ? _b : false)
|
|
92
|
+
.setPoint(key, "total")
|
|
93
|
+
.draw(dataFormatDigits, measureScale);
|
|
79
94
|
}
|
|
80
95
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export class ElementPositions {
|
|
17
17
|
// private smallestDataPoint: DataPoint;
|
|
18
|
-
constructor(padding, scaleFactors, fontSize, numberOfColumns, leftSideLengthSync, titleLength, leftSideWidth, categoryWidth, hasStackedHeaders = false) {
|
|
18
|
+
constructor(padding, scaleFactors, fontSize, numberOfColumns, leftSideLengthSync, titleLength, leftSideWidth, categoryWidth, hasStackedHeaders = false, rows = null) {
|
|
19
19
|
this.categoryPosition = { x: 0, y: 0 };
|
|
20
20
|
this.spacings = {
|
|
21
21
|
scenarioOffset: 0,
|
|
@@ -46,6 +46,7 @@ export class ElementPositions {
|
|
|
46
46
|
this.leftSideLengthSync = leftSideLengthSync;
|
|
47
47
|
this.topSideLabelHeight = titleLength > 0 ? this.fontSize : 0;
|
|
48
48
|
this.hasStackedHeaders = hasStackedHeaders;
|
|
49
|
+
this.rows = rows;
|
|
49
50
|
this.leftSideLabelLength = this.calculateSideLabelLength(titleLength, leftSideWidth, categoryWidth);
|
|
50
51
|
this.calculateSpacings();
|
|
51
52
|
this.calculateCategoryPosition();
|
|
@@ -55,8 +56,22 @@ export class ElementPositions {
|
|
|
55
56
|
return this.axisPosition.x;
|
|
56
57
|
}
|
|
57
58
|
getBarCenterPositionY(index) {
|
|
59
|
+
if (this.rows && index < this.rows.start.length) {
|
|
60
|
+
const middle = this.rows.start[index] + this.rows.weight[index] / 2;
|
|
61
|
+
return this.getAxisPositionY() + this.spacings.scenarioOffset + middle * this.spacings.categoryWidth;
|
|
62
|
+
}
|
|
58
63
|
return this.categoryPosition.y + this.spacings.scenarioOffset + index * this.spacings.categoryWidth;
|
|
59
64
|
}
|
|
65
|
+
/** Upper edge of the room of a row. */
|
|
66
|
+
getRowTopPositionY(index) {
|
|
67
|
+
const start = this.rows && index < this.rows.start.length ? this.rows.start[index] : index;
|
|
68
|
+
return this.getAxisPositionY() + this.spacings.scenarioOffset + start * this.spacings.categoryWidth;
|
|
69
|
+
}
|
|
70
|
+
/** Thickness of the bar of a row. Rows have one thickness unless the chart sets a row layout. */
|
|
71
|
+
getBarWidthAt(index) {
|
|
72
|
+
const weight = this.rows && index < this.rows.weight.length ? this.rows.weight[index] : 1;
|
|
73
|
+
return this.spacings.barWidth * weight;
|
|
74
|
+
}
|
|
60
75
|
getBarPositionY(index, isPrimaryMarker) {
|
|
61
76
|
if (isPrimaryMarker) {
|
|
62
77
|
return this.getBarCenterPositionY(index);
|
|
@@ -77,7 +92,7 @@ export class ElementPositions {
|
|
|
77
92
|
return this.axisPosition.y - this.spacings.labelToAxis - this.getTopLabelOverhang();
|
|
78
93
|
}
|
|
79
94
|
getStackedHeaderPositionY() {
|
|
80
|
-
return this.getBarCenterPositionY(0) - this.
|
|
95
|
+
return this.getBarCenterPositionY(0) - this.getBarWidthAt(0) * 0.5 - this.spacings.scenarioLabelToBar;
|
|
81
96
|
}
|
|
82
97
|
getNeedleWidth() {
|
|
83
98
|
return this.spacings.needleWidth;
|
|
@@ -129,7 +144,8 @@ export class ElementPositions {
|
|
|
129
144
|
return this.spacings.scenarioOffset; // this.categoryOffset;
|
|
130
145
|
}
|
|
131
146
|
getAxisEndPositionY() {
|
|
132
|
-
|
|
147
|
+
const rows = this.rows ? this.rows.total : this.numberOfColumns;
|
|
148
|
+
return this.getAxisPositionY() + (rows + 1 / 2) * this.spacings.categoryWidth;
|
|
133
149
|
}
|
|
134
150
|
getScenarioLabelPositionOffsetY(isPrimaryBar) {
|
|
135
151
|
if (isPrimaryBar) {
|
package/dist/collection/components/bn-chart-structure/utils/model/StructureChartComponentConfig.js
CHANGED
|
@@ -36,6 +36,14 @@ export class StructureChartComponentConfig {
|
|
|
36
36
|
this.showMeasureScale = true;
|
|
37
37
|
this.dataFormatDigits = { decimal: 1, percent: 2 };
|
|
38
38
|
this.stackConfig = null;
|
|
39
|
+
this.sums = "none";
|
|
40
|
+
/** Label of the row over all rows. Empty: the `SUM_TOTAL` text. */
|
|
41
|
+
this.sumTitle = "";
|
|
42
|
+
/** The name of the scenario stands above the first bar and not below the last one. */
|
|
43
|
+
this.scenarioLabelTop = false;
|
|
44
|
+
this.referenceLine = null;
|
|
45
|
+
/** Values of the level column whose row is printed in italics. */
|
|
46
|
+
this.italicCategories = [];
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
/**
|
|
@@ -100,6 +108,21 @@ export class StructureChartComponentConfigAdapter {
|
|
|
100
108
|
if (CompareUtil.isExisting(data.stackConfig)) {
|
|
101
109
|
config.stackConfig = data.stackConfig;
|
|
102
110
|
}
|
|
111
|
+
if (CompareUtil.isString(data.sums) && ["groups", "total", "all"].includes(data.sums)) {
|
|
112
|
+
config.sums = data.sums;
|
|
113
|
+
}
|
|
114
|
+
if (CompareUtil.isString(data.sumTitle)) {
|
|
115
|
+
config.sumTitle = data.sumTitle;
|
|
116
|
+
}
|
|
117
|
+
if (CompareUtil.isBoolean(data.scenarioLabelTop)) {
|
|
118
|
+
config.scenarioLabelTop = data.scenarioLabelTop;
|
|
119
|
+
}
|
|
120
|
+
if (CompareUtil.isExisting(data.referenceLine)) {
|
|
121
|
+
config.referenceLine = data.referenceLine;
|
|
122
|
+
}
|
|
123
|
+
if (CompareUtil.isArray(data.italicCategories)) {
|
|
124
|
+
config.italicCategories = AdapterUtils.adaptArray(data.italicCategories, this.stringAdapter);
|
|
125
|
+
}
|
|
103
126
|
return config;
|
|
104
127
|
}
|
|
105
128
|
default() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Formatter } from "../../utils/formatter";
|
|
1
2
|
import { h, Host, forceUpdate } from "@stencil/core";
|
|
2
3
|
import { getOrCreateStores } from "../../context/context-protocol";
|
|
3
4
|
import { LAYOUT_STATE_VERSION, assignIds, buildGenericState, resolveOwnIdentity, toLayoutRect, } from "../../utils/layoutState";
|
|
@@ -37,12 +38,29 @@ const VISUAL_SELECTOR = "bn-annotation-layer, bn-annotation-list, bn-body, bn-ca
|
|
|
37
38
|
"bn-text, bn-title, bn-tree";
|
|
38
39
|
export class Context {
|
|
39
40
|
constructor() {
|
|
41
|
+
/**
|
|
42
|
+
* Group separator of every number in the document, in place of the one of
|
|
43
|
+
* the locale: `thin-space`, `space`, `none`, or the separator itself. It
|
|
44
|
+
* holds for the whole page, also for a context that does not set it.
|
|
45
|
+
*
|
|
46
|
+
* @default "" (the separator of the locale)
|
|
47
|
+
* @example group-separator="thin-space"
|
|
48
|
+
*/
|
|
49
|
+
this.groupSeparator = "";
|
|
50
|
+
this.setsGroupSeparator = false;
|
|
40
51
|
/** The page numbers this context wrote. A number that is not in here was set by the author and is left alone. */
|
|
41
52
|
this.assignedPageNumbers = new WeakMap();
|
|
42
53
|
this.notationSubscriptions = [];
|
|
43
54
|
withComponentStatus(this);
|
|
44
55
|
this.errors = withHasError(this);
|
|
45
56
|
}
|
|
57
|
+
setGroupSeparator(newValue) {
|
|
58
|
+
var _a;
|
|
59
|
+
const named = { "thin-space": "\u2009", space: "\u00a0", none: "" };
|
|
60
|
+
// no value: the separator of the locale
|
|
61
|
+
Formatter.groupSeparator = newValue ? ((_a = named[newValue]) !== null && _a !== void 0 ? _a : newValue) : null;
|
|
62
|
+
this.setsGroupSeparator = !!newValue;
|
|
63
|
+
}
|
|
46
64
|
setLocale(newValue) {
|
|
47
65
|
this.stores.context.state.locale = newValue;
|
|
48
66
|
}
|
|
@@ -54,6 +72,9 @@ export class Context {
|
|
|
54
72
|
if (this.locale) {
|
|
55
73
|
this.stores.context.state.locale = this.locale;
|
|
56
74
|
}
|
|
75
|
+
if (this.groupSeparator) {
|
|
76
|
+
this.setGroupSeparator(this.groupSeparator);
|
|
77
|
+
}
|
|
57
78
|
// a removed scaling group is a "set" too: its entry is set to undefined
|
|
58
79
|
const notify = () => this.bnNotationChange.emit();
|
|
59
80
|
this.notationSubscriptions = [
|
|
@@ -72,6 +93,11 @@ export class Context {
|
|
|
72
93
|
}
|
|
73
94
|
disconnectedCallback() {
|
|
74
95
|
var _a, _b;
|
|
96
|
+
// only the context that set it takes it back
|
|
97
|
+
if (this.setsGroupSeparator) {
|
|
98
|
+
Formatter.groupSeparator = null;
|
|
99
|
+
this.setsGroupSeparator = false;
|
|
100
|
+
}
|
|
75
101
|
this.notationSubscriptions.forEach((unsubscribe) => unsubscribe());
|
|
76
102
|
this.notationSubscriptions = [];
|
|
77
103
|
(_a = this.pageObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
@@ -224,7 +250,7 @@ export class Context {
|
|
|
224
250
|
componentWillUpdate() { }
|
|
225
251
|
componentDidUpdate() { }
|
|
226
252
|
render() {
|
|
227
|
-
return (h(Host, { key: '
|
|
253
|
+
return (h(Host, { key: '71bdc7dcbcadcae35b67f4d3fbb47e8ee204b3bb' }, h("slot", { key: 'c2fb4c85cb1a3b3af6ec013d0e558c0ef611358d' })));
|
|
228
254
|
}
|
|
229
255
|
static get is() { return "bn-context"; }
|
|
230
256
|
static get encapsulation() { return "shadow"; }
|
|
@@ -296,6 +322,32 @@ export class Context {
|
|
|
296
322
|
"setter": false,
|
|
297
323
|
"reflect": true,
|
|
298
324
|
"attribute": "render-orientation"
|
|
325
|
+
},
|
|
326
|
+
"groupSeparator": {
|
|
327
|
+
"type": "string",
|
|
328
|
+
"mutable": false,
|
|
329
|
+
"complexType": {
|
|
330
|
+
"original": "string",
|
|
331
|
+
"resolved": "string",
|
|
332
|
+
"references": {}
|
|
333
|
+
},
|
|
334
|
+
"required": false,
|
|
335
|
+
"optional": false,
|
|
336
|
+
"docs": {
|
|
337
|
+
"tags": [{
|
|
338
|
+
"name": "default",
|
|
339
|
+
"text": "\"\" (the separator of the locale)"
|
|
340
|
+
}, {
|
|
341
|
+
"name": "example",
|
|
342
|
+
"text": "group-separator=\"thin-space\""
|
|
343
|
+
}],
|
|
344
|
+
"text": "Group separator of every number in the document, in place of the one of\nthe locale: `thin-space`, `space`, `none`, or the separator itself. It\nholds for the whole page, also for a context that does not set it."
|
|
345
|
+
},
|
|
346
|
+
"getter": false,
|
|
347
|
+
"setter": false,
|
|
348
|
+
"reflect": false,
|
|
349
|
+
"attribute": "group-separator",
|
|
350
|
+
"defaultValue": "\"\""
|
|
299
351
|
}
|
|
300
352
|
};
|
|
301
353
|
}
|
|
@@ -414,6 +466,9 @@ export class Context {
|
|
|
414
466
|
static get elementRef() { return "element"; }
|
|
415
467
|
static get watchers() {
|
|
416
468
|
return [{
|
|
469
|
+
"propName": "groupSeparator",
|
|
470
|
+
"methodName": "setGroupSeparator"
|
|
471
|
+
}, {
|
|
417
472
|
"propName": "locale",
|
|
418
473
|
"methodName": "setLocale"
|
|
419
474
|
}];
|
|
@@ -97,6 +97,16 @@ export class LayoutCard {
|
|
|
97
97
|
* card-custom-template='"a a" "b c"'></bn-layout-card>
|
|
98
98
|
*/
|
|
99
99
|
this.cardCustomTemplate = '"a b" "c d"';
|
|
100
|
+
/**
|
|
101
|
+
* Puts the child after the last slot of the template on top of the grid,
|
|
102
|
+
* in the cells this CSS `grid-area` names by line numbers:
|
|
103
|
+
* `row-start / column-start / row-end / column-end`. Use it for a text or a
|
|
104
|
+
* comment list in the free part of a chart.
|
|
105
|
+
*
|
|
106
|
+
* @default "" (no overlay)
|
|
107
|
+
* @example card-overlay-area="4 / 3 / 7 / 5"
|
|
108
|
+
*/
|
|
109
|
+
this.cardOverlayArea = "";
|
|
100
110
|
/**
|
|
101
111
|
* Gap between grid cells in pixels.
|
|
102
112
|
*/
|
|
@@ -177,7 +187,20 @@ export class LayoutCard {
|
|
|
177
187
|
const items = this.createDivAreaStyles(slotNames);
|
|
178
188
|
return (h(Fragment, null, items.map((value, index) => {
|
|
179
189
|
return (h("div", { style: value }, h("slot", { name: "card-slot-" + index })));
|
|
180
|
-
})));
|
|
190
|
+
}), this.overlayArea() ? (h("div", { style: { display: "flex", overflow: "hidden", "grid-area": this.overlayArea(), "z-index": "1" } }, h("slot", { name: "card-slot-" + items.length }))) : null));
|
|
191
|
+
}
|
|
192
|
+
/** The overlay area when it is four line numbers inside the grid of the layout, else nothing. */
|
|
193
|
+
overlayArea() {
|
|
194
|
+
var _a, _b;
|
|
195
|
+
const area = ((_a = this.cardOverlayArea) !== null && _a !== void 0 ? _a : "").trim();
|
|
196
|
+
if (!/^\d+(\s*\/\s*\d+){3}$/.test(area))
|
|
197
|
+
return undefined;
|
|
198
|
+
const [rowStart, columnStart, rowEnd, columnEnd] = area.split("/").map((line) => Number(line.trim()));
|
|
199
|
+
const rows = this.getRowCount(this.cardLayout);
|
|
200
|
+
const columns = ((_b = templateRows(this.getTemplatePattern(this.cardLayout))[0]) === null || _b === void 0 ? void 0 : _b.length) || 1;
|
|
201
|
+
// a line outside the template would add rows or columns to the grid
|
|
202
|
+
const inside = rowStart >= 1 && columnStart >= 1 && rowEnd <= rows + 1 && columnEnd <= columns + 1;
|
|
203
|
+
return inside && rowStart < rowEnd && columnStart < columnEnd ? area : undefined;
|
|
181
204
|
}
|
|
182
205
|
extractSlotNames(styleElement) {
|
|
183
206
|
return templateSlotNames(styleElement);
|
|
@@ -186,6 +209,7 @@ export class LayoutCard {
|
|
|
186
209
|
return templateAreas(name, this.cardCustomTemplate);
|
|
187
210
|
}
|
|
188
211
|
componentWillRender() {
|
|
212
|
+
var _a;
|
|
189
213
|
const problem = this.cardLayout === CUSTOM_TEMPLATE ? templateProblem(this.cardCustomTemplate) : undefined;
|
|
190
214
|
if (problem) {
|
|
191
215
|
this.errors.addOrReplace({
|
|
@@ -197,6 +221,16 @@ export class LayoutCard {
|
|
|
197
221
|
else {
|
|
198
222
|
this.errors.remove("WARN_cardCustomTemplate");
|
|
199
223
|
}
|
|
224
|
+
if (((_a = this.cardOverlayArea) !== null && _a !== void 0 ? _a : "").trim() !== "" && !this.overlayArea()) {
|
|
225
|
+
this.errors.addOrReplace({
|
|
226
|
+
id: "WARN_cardOverlayArea",
|
|
227
|
+
type: "warning",
|
|
228
|
+
message: `cardOverlayArea: '${this.cardOverlayArea}' is not 'row-start / column-start / row-end / column-end' in line numbers of the layout.`,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.errors.remove("WARN_cardOverlayArea");
|
|
233
|
+
}
|
|
200
234
|
}
|
|
201
235
|
setCardClass() {
|
|
202
236
|
if (this.cardShowBorder === true) {
|
|
@@ -223,7 +257,7 @@ export class LayoutCard {
|
|
|
223
257
|
var _a;
|
|
224
258
|
const style = this.getLayoutStyle();
|
|
225
259
|
const arrOfSlots = this.extractSlotNames(style["grid-template-areas"]);
|
|
226
|
-
return (h("bn-card", { key: '
|
|
260
|
+
return (h("bn-card", { key: 'ef0b6da39a573f162c096c21803e4d647b2817c2', styles: this.styles, "selected-style": this.selectedStyle, class: this.setCardClass() }, h("div", { key: '9116df8c88198ebc922dc91d5f45a032a81d37d1', class: "cardtitle" }, 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 !== "" ? (h("img", { class: "image", src: this.prepareTitleImage(this.titleImage) })) : ("")), h("bn-body", { key: '65803497adad305f02874acf441867e9ba200945' }, h("div", { key: '61a57b87b0ffb76c238b2e2facb7d5b855d5dc10', style: style, "data-bn-fit-content": this.cardFitToContent ? String(this.getRowCount(this.cardLayout)) : null }, this.getSlots(arrOfSlots))), h("bn-footer", { key: '8589da921d0f8dac8e9a2af23315ded3a3ee3d51', text: this.footerText, "page-number": "0", "display-page-number": "false" })));
|
|
227
261
|
}
|
|
228
262
|
static get is() { return "bn-layout-card"; }
|
|
229
263
|
static get encapsulation() { return "shadow"; }
|
|
@@ -627,6 +661,32 @@ export class LayoutCard {
|
|
|
627
661
|
"attribute": "card-custom-template",
|
|
628
662
|
"defaultValue": "'\"a b\" \"c d\"'"
|
|
629
663
|
},
|
|
664
|
+
"cardOverlayArea": {
|
|
665
|
+
"type": "string",
|
|
666
|
+
"mutable": false,
|
|
667
|
+
"complexType": {
|
|
668
|
+
"original": "string",
|
|
669
|
+
"resolved": "string",
|
|
670
|
+
"references": {}
|
|
671
|
+
},
|
|
672
|
+
"required": false,
|
|
673
|
+
"optional": false,
|
|
674
|
+
"docs": {
|
|
675
|
+
"tags": [{
|
|
676
|
+
"name": "default",
|
|
677
|
+
"text": "\"\" (no overlay)"
|
|
678
|
+
}, {
|
|
679
|
+
"name": "example",
|
|
680
|
+
"text": "card-overlay-area=\"4 / 3 / 7 / 5\""
|
|
681
|
+
}],
|
|
682
|
+
"text": "Puts the child after the last slot of the template on top of the grid,\nin the cells this CSS `grid-area` names by line numbers:\n`row-start / column-start / row-end / column-end`. Use it for a text or a\ncomment list in the free part of a chart."
|
|
683
|
+
},
|
|
684
|
+
"getter": false,
|
|
685
|
+
"setter": false,
|
|
686
|
+
"reflect": false,
|
|
687
|
+
"attribute": "card-overlay-area",
|
|
688
|
+
"defaultValue": "\"\""
|
|
689
|
+
},
|
|
630
690
|
"cardGridGap": {
|
|
631
691
|
"type": "string",
|
|
632
692
|
"mutable": false,
|
|
@@ -33,9 +33,15 @@ export class Formatter {
|
|
|
33
33
|
}
|
|
34
34
|
this.formats.set(key, format);
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const print = (number) => this.groupSeparator === null
|
|
37
|
+
? format.format(number)
|
|
38
|
+
: format
|
|
39
|
+
.formatToParts(number)
|
|
40
|
+
.map((part) => (part.type === "group" ? this.groupSeparator : part.value))
|
|
41
|
+
.join("");
|
|
42
|
+
const text = print(value / scale);
|
|
37
43
|
// a small negative that rounds to zero would print "-0"
|
|
38
|
-
return (text ===
|
|
44
|
+
return (text === print(-0) ? print(0) : text).replace(/\s+(%)/g, "$1");
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
47
|
* Translates a technical scenario identifier into a human-readable IBCS label.
|
|
@@ -93,3 +99,8 @@ export class Formatter {
|
|
|
93
99
|
}
|
|
94
100
|
/** One formatter per locale, style and digits: building one per cell is slow. */
|
|
95
101
|
Formatter.formats = new Map();
|
|
102
|
+
/**
|
|
103
|
+
* Replaces the group separator of the locale in every number, for example by a thin
|
|
104
|
+
* space. Null: the separator of the locale. One setting for the page: `bn-context` sets it.
|
|
105
|
+
*/
|
|
106
|
+
Formatter.groupSeparator = null;
|
|
@@ -373,6 +373,15 @@ export function validateStackConfig(value) {
|
|
|
373
373
|
if (config.hasOwnProperty("percentMark") && typeof config.percentMark !== "boolean") {
|
|
374
374
|
errors.push("stack: 'percentMark' must be true or false");
|
|
375
375
|
}
|
|
376
|
+
if (config.hasOwnProperty("labels") && !["share", "value"].includes(config.labels)) {
|
|
377
|
+
errors.push("stack: 'labels' must be one of: share, value");
|
|
378
|
+
}
|
|
379
|
+
if (config.hasOwnProperty("totalTitle") && typeof config.totalTitle !== "string") {
|
|
380
|
+
errors.push("stack: 'totalTitle' must be a text");
|
|
381
|
+
}
|
|
382
|
+
if (config.hasOwnProperty("thickness") && !["equal", "total"].includes(config.thickness)) {
|
|
383
|
+
errors.push("stack: 'thickness' must be one of: equal, total");
|
|
384
|
+
}
|
|
376
385
|
return errors;
|
|
377
386
|
}
|
|
378
387
|
catch (_e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as t,t as e,H as n,h as i,d as o}from"./p-BnmylmXF.js";import{g as r}from"./p-6242qMx1.js";import{a as s,c as l,b as a}from"./p-CHJ6WE0l.js";import{w as h,C as c}from"./p-BrQCbmG0.js";import{w as u}from"./p-JG4Sx1lE.js";import{w as d}from"./p-D32TsLzd.js";const f=t=>({x:t.x+t.width/2,y:t.y+t.height/2});function b(t,e){const n=f(t),i=e.x-n.x,o=e.y-n.y,r=Math.min(0===i?1/0:t.width/2/Math.abs(i),0===o?1/0:t.height/2/Math.abs(o));return Number.isFinite(r)?{x:n.x+i*r,y:n.y+o*r}:n}function m(t,e){return e?Object.assign(Object.assign({},t),{cx:Math.max(t.r,Math.min(t.cx,e.width-t.r)),cy:Math.max(t.r,Math.min(t.cy,e.height-t.r))}):t}const v=(t,e)=>t.x<e.x+e.width&&e.x<t.x+t.width&&t.y<e.y+e.height&&e.y<t.y+t.height;function y(t,e,n,i){var o,r,s;const l=.25*n,a=t.y+t.height/2,h=null!==(o=i.obstacles)&&void 0!==o?o:[],c=t=>{const n={x:t-e,y:a-e,width:2*e,height:2*e},o=i.area;return(!o||n.x>=0&&n.x+n.width<=o.width)&&!h.some((t=>v(n,t)))},u=t.x+t.width,d=t.x-l-e,f=u+l+e;if(c(d))return{x:d,y:a,r:e};if(c(f))return{x:f,y:a,r:e};const b=2*(e+l),m=h.filter((t=>t.y<a&&t.y+t.height>a)),y=Math.max(0,t.x-b,...m.filter((e=>e.x+e.width<=t.x)).map((t=>t.x+t.width))),x=Math.min(null!==(s=null===(r=i.area)||void 0===r?void 0:r.width)&&void 0!==s?s:1/0,u+b,...m.filter((t=>t.x>=u)).map((t=>t.x))),p=t.x-y,g=x-u;return{x:g>=p?u+g/2:t.x-p/2,y:a,r:Math.min(e,Math.max(Math.max(p,g)/2,.3*n))}}const x=(t,e)=>.6*t.length*e,p=(t,e)=>(t<0?"-":"+")+Math.abs(t).toFixed(e);function g(t,e,n,i,o,r,s){var l,a,h;if(null==i||null==o)return;const c=o-i,u=Number.isInteger(t.digits)&&t.digits>=0?t.digits:1,d="good-down"===t.sentiment?c<=0:c>=0,f=n.x+n.width/2>=e.x+e.width/2?1:-1,b=t=>1===f?t.x+t.width:t.x,m=b(n)+.9*f*r,v=m+.125*f*r,y=null!==(l=null==s?void 0:s.from)&&void 0!==l?l:e.y,g=null!==(a=null==s?void 0:s.to)&&void 0!==a?a:n.y,w=.25*r,M=t.percent&&0!==i?`(${p(c/Math.abs(i)*100,0)}%)`:void 0,k=p(c,u),S=m+.6*f*r,$=(y+g)/2,O=M?x(M,.85*r):0,j=1===f?S+.5*k.length*r+.35*r:S-O;return{kind:"difference",color:null!==(h=t.color)&&void 0!==h?h:d?"positive":"negative",lines:[{x1:b(e),y1:y,x2:v,y2:y},{x1:b(n),y1:g,x2:v,y2:g}],bar:{x:m-w/2,y:Math.min(y,g),width:w,height:Math.max(Math.abs(g-y),1)},text:{x:S,y:$,anchor:1===f?"start":"end",value:k,percent:M},frame:M&&t.highlight?{x:j-.25*r,y:$-.65*r,width:O+.5*r,height:1.3*r,r:.65*r}:void 0,badge:null!=t.label?{cx:m,cy:Math.min(y,g)-.9*r,r:.65*r,label:t.label}:void 0}}function w(t,e,n,i,o={}){var r,s,l,a;const{label:h,color:c}=t,{whole:u,area:d,text:p}=o,g=!u&&!p&&null!=o.obstacles,w=((t,e)=>t?Math.min(e,t.height/1.3):e)(null!=p?p:g?e:void 0,i);if("arrow"===t.mark){if(!n)return;const t=f(e),o=f(n);if(t.x===o.x&&t.y===o.y)return;let r=b(e,o),s=b(n,t);(s.x-r.x)*(o.x-t.x)+(s.y-r.y)*(o.y-t.y)<=0&&(r=t,s=o);const l=Math.hypot(s.x-r.x,s.y-r.y),a=Math.min(.8*i,l),u=(s.x-r.x)/l,v=(s.y-r.y)/l,y=s.x-u*a,x=s.y-v*a,p=.35*i;return{kind:"arrow",color:c,x1:r.x,y1:r.y,x2:y,y2:x,head:[`${s.x},${s.y}`,`${y-v*p},${x+u*p}`,`${y+v*p},${x-u*p}`].join(" "),badge:null!=h?m({cx:r.x,cy:r.y,r:.65*i,label:h},d):void 0}}if("frame"===t.mark){const n=null==t.text||u?void 0:{x:e.x+e.width/2,y:e.y+Math.min(e.height/2,Math.max(.9*i,.3*e.height))},o=n&&{x:n.x-x(t.text,i)/2,y:n.y-.6*i,width:x(t.text,i),height:1.2*i},l=null!==(r=null!=o?o:p)&&void 0!==r?r:e,a=null===(s=t.point)||void 0===s?void 0:s.part,f=!u&&(null!=o||null!=p||"label"===a||"total"===a),b=(f?.45:.2)*w,v=(f?.1:.2)*w,y=f?Math.max(l.width,l.height):l.width,g=l.x+l.width/2,M=1,k=Math.max(d?M:-1/0,g-y/2-b),S=Math.max(d?M:-1/0,l.y-v),$=Math.min(d?d.width-M:1/0,g+y/2+b),O=Math.min(d?d.height-M:1/0,l.y+l.height+v),j=Math.min($-k,O-S)/2,z=u?.25*i:j,C=u?.25*i:f?Math.min(($-k)/2,1.6*j):j,N=1-Math.SQRT1_2,W=.65*w,J=f?.6*W:0;return{kind:"frame",color:c,x:k,y:S,width:$-k,height:O-S,rx:C,ry:z,badge:null!=h?m({cx:$-C*N+J,cy:S+z*N-J,r:W,label:h},d):void 0,caption:n&&Object.assign(Object.assign({},n),{text:t.text})}}if(p&&!u){const t=y(p,(null==h?.4:.65)*w,w,o);return{kind:"marker",color:c,badge:m({cx:t.x,cy:t.y,r:t.r,label:h},d)}}const M=(null==h?.4:.75)*w,k=g?Math.min(M,e.height/2):M;let S=u?{x:e.x+e.width-k,y:e.y+k}:f(e);if(!u&&o.stacked&&"label"!==(null===(l=t.point)||void 0===l?void 0:l.part)&&"total"!==(null===(a=t.point)||void 0===a?void 0:a.part)&&(S={x:e.x+e.width,y:e.y+Math.min(.5*k,e.height/2)}),g){const t={x:S.x-k,y:S.y-k,width:2*k,height:2*k},e=o.obstacles.find((e=>v(t,e)));if(e){const t=y(e,k,w,o);return{kind:"marker",color:c,badge:m({cx:t.x,cy:t.y,r:t.r,label:h},d)}}}return{kind:"marker",color:c,badge:m({cx:S.x,cy:S.y,r:k,label:h},d)}}const M=["rowGroup","category","subCategory","date","scenario","row"];function k(t,e){var n;const i=t.table&&null==e.scenario?t.table.rows:null!==(n=t.elements)&&void 0!==n?n:[],o=null!=t.table&&null==e.subCategory;return i.filter((t=>function(t,e){var n;return!(!t||t.part!==(null!==(n=e.part)&&void 0!==n?n:"element"))&&M.every((n=>null==e[n]||e[n]+""===t[n]))}(t.point,e)&&!(o&&null!=t.point.subCategory))).map((({rect:t,content:e,contentSign:n,value:i,scenario:o})=>({rect:t,content:e,contentSign:n,value:i,stacked:"string"==typeof o&&o.startsWith("stack:")})))}function S(t,e){const n=e.getBoundingClientRect();if(0===n.width||0===n.height)return!0;const i=t.x+t.width/2,o=t.y+t.height/2;return i>=n.left&&i<=n.right&&o>=n.top&&o<=n.bottom}const $=new Set(["bn-asset","bn-component-style","bn-dataset","bn-datasource","bn-internationalization","bn-ruleset","bn-scaling-group"]);function O(t,e){const n=e.getBoundingClientRect();return 0===n.width||0===n.height||t.x<n.right&&t.x+t.width>n.left&&t.y<n.bottom&&t.y+t.height>n.top}const j=t(class extends n{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.marks=[],this.pageKey="",this.parsedItems=[],this.scheduled=!1,this.run=0,this.observed=new WeakSet,this.observedAround=new WeakSet,this.reported=new Set,this.schedule=()=>{this.scheduled||(this.scheduled=!0,this.holdStatus(new Promise((t=>{requestAnimationFrame((()=>{this.scheduled=!1,this.place().catch((t=>console.error("bn-annotation-layer: placing the marks failed",t))).finally(t)}))}))))},this.holdStatus=h(this),this.errors=d(this),this.componentStyle=u(this)}connectedCallback(){var t;this.stores=r(this.element),this.pageKey=s(this.element),this.observed=new WeakSet,this.observedAround=new WeakSet,this.resizeObserver=new ResizeObserver(this.schedule),this.mutationObserver=new MutationObserver(this.schedule),this.observeSize(this.element);const e=this.element.closest("bn-layout-page");e&&this.mutationObserver.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["slot","data-bino-annotation-target"]}),null===(t=document.fonts)||void 0===t||t.addEventListener("loadingdone",this.schedule)}disconnectedCallback(){var t,e,n,i;null===(t=this.resizeObserver)||void 0===t||t.disconnect(),null===(e=this.mutationObserver)||void 0===e||e.disconnect(),null===(n=document.fonts)||void 0===n||n.removeEventListener("loadingdone",this.schedule),this.run++,(null===(i=this.stores)||void 0===i?void 0:i.annotationsUnplaced.state[this.pageKey])&&this.stores.annotationsUnplaced.set(this.pageKey,void 0)}componentWillLoad(){this.parseItems()}componentDidLoad(){this.schedule()}onItemsChange(){this.parseItems(),this.schedule()}parseItems(){const t=l(this.items);t?this.errors.remove("ERR_items"):this.errors.addOrReplace({id:"ERR_items",type:"error",message:"items: not a JSON array of objects."}),this.parsedItems=null!=t?t:[]}async place(){var t,e;const n=++this.run;if(!this.element.isConnected||!this.svg)return;const i=this.element.closest("bn-layout-page"),o=new Map,r=new Map;null==i||i.querySelectorAll("[data-bino-annotation-target]").forEach((t=>{const e=Array.from(t.querySelectorAll("*")).find((t=>t.localName.startsWith("bn-")&&!$.has(t.localName))),n=null!=e?e:t;o.set(t.getAttribute("data-bino-annotation-target"),n),r.set(n,t)})),null==i||i.querySelectorAll("[slot]").forEach((t=>this.observeSize(t)));const s=new Set(this.parsedItems.flatMap((t=>[t.target,t.to]))),l=[...o].filter((([t])=>s.has(t))).map((([,t])=>t));if(await Promise.all(l.map((t=>{var e;return null===(e=t.componentOnReady)||void 0===e?void 0:e.call(t)}))),n!==this.run)return;l.forEach((t=>{this.observe(t),this.observeAround(t,i)}));const a=new Map;if(await Promise.all(l.map((async t=>{var e;a.set(t,await(null===(e=t.getLayoutState)||void 0===e?void 0:e.call(t,{detail:"full"}).catch((()=>{}))))}))),n!==this.run)return;const h=(t,e)=>{var n;const i=null!=t?o.get(t):void 0;if(!i)return{problem:`no target "${t}" on this page`};const s=i.getBoundingClientRect();if(function(t){return!t||M.every((e=>null==t[e]))&&null==t.part}(e)){const e={x:s.left,y:s.top,width:s.width,height:s.height};return function(t,e,n){if(0===t.width||0===t.height||!O(t,n))return!0;for(let n=e;n&&"bn-layout-page"!==n.localName;n=n.parentElement)if(!O(t,n))return!0;return!1}(e,r.get(i),this.element)?{problem:`"${t}" cannot be seen`}:{box:e,whole:!0}}const l=a.get(i),h=l?k(l,e):[];if(1!==h.length)return{problem:`${h.length} elements match the point ${JSON.stringify(e)} in "${t}"`};const c=({component:{x:t,y:e,width:n,height:i}})=>({x:s.left+t,y:s.top+e,width:n,height:i}),u=c(h[0].rect);if(function(t,e){for(let n=e;n&&"bn-layout-page"!==n.localName;n=n.parentElement)if(!S(t,n))return!0;return!1}(u,r.get(i))||!S(u,this.element))return{problem:`the point ${JSON.stringify(e)} in "${t}" is cut off`};const d=h[0].content;if(!l.table)return{box:u,whole:!1,stacked:h[0].stacked};const f=(null!==(n=l.elements)&&void 0!==n?n:[]).flatMap((t=>"cell"===t.kind&&t.content?[{box:c(t.content),sign:t.contentSign}]:[]));return{box:u,whole:!1,text:d&&{box:c(d),sign:h[0].contentSign},obstacles:f}},c=(t,e)=>{const n=null!=t?o.get(t):void 0;if(!n)return{problem:`no target "${t}" on this page`};const i=a.get(n),r=(i&&e?k(i,Object.assign(Object.assign({},e),{part:"element"})):[]).filter((t=>null!=t.value));if(0===r.length)return{problem:`no bar with a value matches the point ${JSON.stringify(e)} in "${t}"`};if(r.length>1&&!r.every((t=>t.stacked)))return{problem:`${r.length} elements match the point ${JSON.stringify(e)} in "${t}"`};const s=n.getBoundingClientRect(),l=Math.min(...r.map((t=>t.rect.component.x))),h=Math.min(...r.map((t=>t.rect.component.y))),c=Math.max(...r.map((t=>t.rect.component.x+t.rect.component.width))),u=Math.max(...r.map((t=>t.rect.component.y+t.rect.component.height)));return{box:{x:s.left+l,y:s.top+h,width:c-l,height:u-h},negatives:r.filter((t=>t.value<0)).map((t=>(t=>({x:s.left+t.x,y:s.top+t.y,width:t.width,height:t.height}))(t.rect.component))),value:r.reduce(((t,e)=>t+e.value),0)}},u=this.toLocalSpace(),d=({box:t,sign:e=0})=>{const n=u(t);return Object.assign(Object.assign({},n),{x:n.x-e,width:n.width+e})},f=parseFloat(getComputedStyle(this.svg).fontSize)||13.3333,b={width:this.element.clientWidth,height:this.element.clientHeight},m=[],v=[];for(const n of this.parsedItems){if("difference"===n.mark){const e=c(n.target,n.point),i=c(null!==(t=n.to)&&void 0!==t?t:n.target,n.toPoint),o="problem"in e?e:"problem"in i?i:void 0;if(o){v.push({item:n,problem:o.problem});continue}const[r,s]=[e,i],l=t=>u(t.box).y+t.negatives.reduce(((t,e)=>t+u(e).height),0),a=g(n,u(r.box),u(s.box),r.value,s.value,f,{from:l(r),to:l(s)});a&&m.push(a);continue}const i=h(n.target,n.point),o="arrow"===n.mark?h(n.to,n.toPoint):void 0,r="problem"in i?i:o&&"problem"in o?o:void 0;if(r){v.push({item:n,problem:r.problem});continue}const s=i,l=o,a=w(n,u(s.box),l&&u(l.box),f,{whole:s.whole,area:b,text:s.text&&d(s.text),obstacles:null===(e=s.obstacles)||void 0===e?void 0:e.map(d),stacked:s.stacked});a?m.push(a):v.push({item:n,problem:"an arrow needs two ends at different places"})}this.marks=m,this.storeUnplaced(v.flatMap((({item:t})=>null!=t.label?[t.label]:[]))),v.length>0&&this.reportWhenQuiet(n,v)}async reportWhenQuiet(t,e){let n=0;for(let e=0;e<50&&n<2;e++){if(await new Promise((t=>window.setTimeout(t,200))),t!==this.run)return;n=0===c.componentRegisterStatus().running?n+1:0}this.report(e)}report(t){var e,n;for(const{item:i,problem:o}of t){const t=`bn-annotation-layer: ${null!==(e=i.mark)&&void 0!==e?e:"marker"} ${null!==(n=i.label)&&void 0!==n?n:"without a number"} is not drawn: ${o}.`;this.reported.has(t)||(this.reported.add(t),console.warn(t))}}toLocalSpace(){var t;const e=null===(t=this.svg.getScreenCTM())||void 0===t?void 0:t.inverse();return t=>{if(!e)return t;const n=[[t.x,t.y],[t.x+t.width,t.y+t.height]].map((([t,n])=>new DOMPoint(t,n).matrixTransform(e)));return{x:Math.min(n[0].x,n[1].x),y:Math.min(n[0].y,n[1].y),width:Math.abs(n[1].x-n[0].x),height:Math.abs(n[1].y-n[0].y)}}}storeUnplaced(t){var e,n;const i=null===(e=this.stores)||void 0===e?void 0:e.annotationsUnplaced,o=null!==(n=null==i?void 0:i.state[this.pageKey])&&void 0!==n?n:[];i&&JSON.stringify(o)!==JSON.stringify(t)&&i.set(this.pageKey,t)}observe(t){this.observeSize(t);const e=t=>{var n;t&&(this.observed.has(t)||(this.observed.add(t),null===(n=this.mutationObserver)||void 0===n||n.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["x","y","width","height","transform","style","class"]})),t.querySelectorAll("*").forEach((t=>e(t.shadowRoot))))};e(t.shadowRoot)}observeAround(t,e){var n,i;for(let o=t.parentElement;o&&o!==e;o=o.parentElement)this.observedAround.has(o)||(this.observedAround.add(o),null===(n=this.mutationObserver)||void 0===n||n.observe(o,{attributes:!0,attributeFilter:["style"]}),o.shadowRoot&&(null===(i=this.mutationObserver)||void 0===i||i.observe(o.shadowRoot,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]})))}observeSize(t){var e;this.observed.has(t)||(this.observed.add(t),null===(e=this.resizeObserver)||void 0===e||e.observe(t))}renderBadge(t,e){return t?i("g",null,i("circle",{cx:t.cx,cy:t.cy,r:t.r,style:{fill:e}}),null!=t.label?i("text",{class:"badge-text",x:t.cx,y:t.cy,style:{fontSize:1.1*t.r+"px"}},t.label):null):null}renderMark(t){var e,n,o;const r=a(t.color,this.componentStyle((t=>t["bn-annotation"])));if("marker"===t.kind)return i("g",{class:"mark marker","data-label":t.badge.label},this.renderBadge(t.badge,r));if("frame"===t.kind)return i("g",{class:"mark frame","data-label":null===(e=t.badge)||void 0===e?void 0:e.label},i("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:t.rx,ry:t.ry,style:{fill:t.caption?"#ffffff":"none",stroke:r,strokeWidth:"1.5"}}),t.caption?i("text",{class:"mark-text caption",x:t.caption.x,y:t.caption.y},t.caption.text):null,this.renderBadge(t.badge,r));if("difference"===t.kind){const e=a(void 0,this.componentStyle((t=>t["bn-annotation"])));return i("g",{class:"mark difference","data-label":null===(n=t.badge)||void 0===n?void 0:n.label},t.lines.map((t=>i("line",{class:"difference-line",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2}))),i("rect",{x:t.bar.x,y:t.bar.y,width:t.bar.width,height:t.bar.height,style:{fill:r}}),i("text",{class:"mark-text",x:t.text.x,y:t.text.y,style:{textAnchor:t.text.anchor}},t.text.value,t.text.percent?i("tspan",{class:"percent",dx:"0.35em"},t.text.percent):null),t.frame?i("rect",{x:t.frame.x,y:t.frame.y,width:t.frame.width,height:t.frame.height,rx:t.frame.r,ry:t.frame.r,style:{fill:"none",stroke:e,strokeWidth:"1.5"}}):null,this.renderBadge(t.badge,e))}return i("g",{class:"mark arrow","data-label":null===(o=t.badge)||void 0===o?void 0:o.label},i("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,style:{stroke:r,strokeWidth:"1.5"}}),i("polygon",{points:t.head,style:{fill:r}}),this.renderBadge(t.badge,r))}render(){return i(o,{key:"f2864246b86078e97a15f58cab7f46a792e6d300"},i("svg",{key:"52f932a7f8dff3e00773f8f827c82ec62848cb34",ref:t=>this.svg=t},this.marks.map((t=>this.renderMark(t)))))}get element(){return this}static get watchers(){return{items:[{onItemsChange:0}]}}static get style(){return':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}'}},[1,"bn-annotation-layer",{items:[1],selectedStyle:[513,"selected-style"],marks:[32]},void 0,{items:[{onItemsChange:0}]}]),z=j,C=function(){"undefined"!=typeof customElements&&["bn-annotation-layer"].forEach((t=>{"bn-annotation-layer"===t&&(customElements.get(e(t))||customElements.define(e(t),j))}))};export{z as BnAnnotationLayer,C as defineCustomElement}
|
|
1
|
+
import{p as t,t as e,H as n,h as i,d as o}from"./p-BnmylmXF.js";import{g as r}from"./p-6242qMx1.js";import{a as l,c as s,b as a}from"./p-CHJ6WE0l.js";import{w as h,C as c}from"./p-BrQCbmG0.js";import{w as u}from"./p-JG4Sx1lE.js";import{w as d}from"./p-D32TsLzd.js";const f=t=>({x:t.x+t.width/2,y:t.y+t.height/2});function b(t,e){const n=f(t),i=e.x-n.x,o=e.y-n.y,r=Math.min(0===i?1/0:t.width/2/Math.abs(i),0===o?1/0:t.height/2/Math.abs(o));return Number.isFinite(r)?{x:n.x+i*r,y:n.y+o*r}:n}function v(t,e){return e?Object.assign(Object.assign({},t),{cx:Math.max(t.r,Math.min(t.cx,e.width-t.r)),cy:Math.max(t.r,Math.min(t.cy,e.height-t.r))}):t}const m=(t,e)=>t.x<e.x+e.width&&e.x<t.x+t.width&&t.y<e.y+e.height&&e.y<t.y+t.height;function y(t,e,n,i){var o,r,l;const s=.25*n,a=t.y+t.height/2,h=null!==(o=i.obstacles)&&void 0!==o?o:[],c=t=>{const n={x:t-e,y:a-e,width:2*e,height:2*e},o=i.area;return(!o||n.x>=0&&n.x+n.width<=o.width)&&!h.some((t=>m(n,t)))},u=t.x+t.width,d=t.x-s-e,f=u+s+e;if(c(d))return{x:d,y:a,r:e};if(c(f))return{x:f,y:a,r:e};const b=2*(e+s),v=h.filter((t=>t.y<a&&t.y+t.height>a)),y=Math.max(0,t.x-b,...v.filter((e=>e.x+e.width<=t.x)).map((t=>t.x+t.width))),x=Math.min(null!==(l=null===(r=i.area)||void 0===r?void 0:r.width)&&void 0!==l?l:1/0,u+b,...v.filter((t=>t.x>=u)).map((t=>t.x))),p=t.x-y,g=x-u;return{x:g>=p?u+g/2:t.x-p/2,y:a,r:Math.min(e,Math.max(Math.max(p,g)/2,.3*n))}}const x=(t,e)=>.6*t.length*e,p=(t,e)=>(t<0?"-":"+")+Math.abs(t).toFixed(e);function g(t,e,n,i,o,r,l){var s,a,h;if(null==i||null==o)return;const c=o-i,u=Number.isInteger(t.digits)&&t.digits>=0?t.digits:1,d="good-down"===t.sentiment?c<=0:c>=0,f=n.x+n.width/2>=e.x+e.width/2?1:-1,b=t=>1===f?t.x+t.width:t.x,v=b(n)+.9*f*r,m=v+.125*f*r,y=null!==(s=null==l?void 0:l.from)&&void 0!==s?s:e.y,g=null!==(a=null==l?void 0:l.to)&&void 0!==a?a:n.y,w=.25*r,k=t.percent&&0!==i?`(${p(c/Math.abs(i)*100,0)}%)`:void 0,M=p(c,u),$=v+.6*f*r,O=(y+g)/2,S=k?x(k,.85*r):0,j=1===f?$+.5*M.length*r+.35*r:$-S;return{kind:"difference",color:null!==(h=t.color)&&void 0!==h?h:d?"positive":"negative",lines:[{x1:b(e),y1:y,x2:m,y2:y},{x1:b(n),y1:g,x2:m,y2:g}],bar:{x:v-w/2,y:Math.min(y,g),width:w,height:Math.max(Math.abs(g-y),1)},text:{x:$,y:O,anchor:1===f?"start":"end",value:M,percent:k},frame:k&&t.highlight?{x:j-.25*r,y:O-.65*r,width:S+.5*r,height:1.3*r,r:.65*r}:void 0,badge:null!=t.label?{cx:v,cy:Math.min(y,g)-.9*r,r:.65*r,label:t.label}:void 0}}function w(t,e,n,i,o={}){var r,l,s,a;const{label:h,color:c}=t,{whole:u,area:d,text:p}=o,g=!u&&!p&&null!=o.obstacles,w=((t,e)=>t?Math.min(e,t.height/1.3):e)(null!=p?p:g?e:void 0,i);if("arrow"===t.mark){if(!n)return;const t=f(e),o=f(n);if(t.x===o.x&&t.y===o.y)return;let r=b(e,o),l=b(n,t);(l.x-r.x)*(o.x-t.x)+(l.y-r.y)*(o.y-t.y)<=0&&(r=t,l=o);const s=Math.hypot(l.x-r.x,l.y-r.y),a=Math.min(.8*i,s),u=(l.x-r.x)/s,m=(l.y-r.y)/s,y=l.x-u*a,x=l.y-m*a,p=.35*i;return{kind:"arrow",color:c,x1:r.x,y1:r.y,x2:y,y2:x,head:[`${l.x},${l.y}`,`${y-m*p},${x+u*p}`,`${y+m*p},${x-u*p}`].join(" "),badge:null!=h?v({cx:r.x,cy:r.y,r:.65*i,label:h},d):void 0}}if("frame"===t.mark){const n=null==t.text||u?void 0:o.label?{x:e.x+e.width+.7*i+x(t.text,i)/2,y:e.y+e.height/2}:{x:e.x+e.width/2,y:e.y+Math.min(e.height/2,Math.max(.9*i,.3*e.height))},s=n&&{x:n.x-x(t.text,i)/2,y:n.y-.6*i,width:x(t.text,i),height:1.2*i},a=null!==(r=null!=s?s:p)&&void 0!==r?r:e,f=null===(l=t.point)||void 0===l?void 0:l.part,b=!u&&(null!=s||null!=p||"label"===f||"total"===f),m=(b?.45:.2)*w,y=(b?.1:.2)*w,g=b?Math.max(a.width,a.height):a.width,k=a.x+a.width/2,M=1,$=Math.max(d?M:-1/0,k-g/2-m),O=Math.max(d?M:-1/0,a.y-y),S=Math.min(d?d.width-M:1/0,k+g/2+m),j=Math.min(d?d.height-M:1/0,a.y+a.height+y),z=Math.min(S-$,j-O)/2,W=u?.25*i:z,C=u?.25*i:b?Math.min((S-$)/2,1.6*z):z,N=1-Math.SQRT1_2,J=.65*w,E=b?.6*J:0;return{kind:"frame",color:c,x:$,y:O,width:S-$,height:j-O,rx:C,ry:W,badge:null!=h?v({cx:S-C*N+E,cy:O+W*N-E,r:J,label:h},d):void 0,caption:n&&Object.assign(Object.assign({},n),{text:t.text})}}if(p&&!u){const t=y(p,(null==h?.4:.65)*w,w,o);return{kind:"marker",color:c,badge:v({cx:t.x,cy:t.y,r:t.r,label:h},d)}}const k=(null==h?.4:.75)*w,M=g?Math.min(k,e.height/2):k;let $=u?{x:e.x+e.width-M,y:e.y+M}:f(e);if(!u&&o.label)$={x:e.x+e.width+.25*w+M,y:e.y+e.height/2};else if(!u&&o.stacked&&o.horizontal){const t=1.3*w+M;$=e.width/2>=t+M?{x:e.x+e.width/2+t,y:e.y+e.height/2}:{x:e.x+e.width-Math.min(M,e.width/2),y:e.y}}else!u&&o.stacked&&"label"!==(null===(s=t.point)||void 0===s?void 0:s.part)&&"total"!==(null===(a=t.point)||void 0===a?void 0:a.part)&&($={x:e.x+e.width,y:e.y+Math.min(.5*M,e.height/2)});if(g){const t={x:$.x-M,y:$.y-M,width:2*M,height:2*M},e=o.obstacles.find((e=>m(t,e)));if(e){const t=y(e,M,w,o);return{kind:"marker",color:c,badge:v({cx:t.x,cy:t.y,r:t.r,label:h},d)}}}return{kind:"marker",color:c,badge:v({cx:$.x,cy:$.y,r:M,label:h},d)}}function k(t,e,n,i,o,r,l){var s;if(null==i||null==o)return;const a=o-i,h=Number.isInteger(t.digits)&&t.digits>=0?t.digits:1,c="good-down"===t.sentiment?a<=0:a>=0,u=n.y+n.height/2>=e.y+e.height/2?1:-1,d=t=>1===u?t.y+t.height:t.y,f=.25*r,b=d(n)+.25*u*r,v=Math.min(l.from,l.to),m=Math.max(l.from,l.to),y=t.percent&&0!==i?`(${p(a/Math.abs(i)*100,0)}%)`:void 0,g=p(a,h),w=m+.5*r,k=.5*g.length*r,M=y?x(y,.85*r):0,$=w+k+.35*r;return{kind:"difference",color:null!==(s=t.color)&&void 0!==s?s:c?"positive":"negative",lines:[{x1:l.from,y1:d(e),x2:l.from,y2:b},{x1:l.to,y1:d(n),x2:l.to,y2:b}],bar:{x:v,y:b-f/2,width:Math.max(m-v,1),height:f},text:{x:w,y:b,anchor:"start",value:g,percent:y},frame:y&&t.highlight?{x:$-.25*r,y:b-.65*r,width:M+.5*r,height:1.3*r,r:.65*r}:void 0,badge:null!=t.label?{cx:v-.9*r,cy:b,r:.65*r,label:t.label}:void 0}}function M(t,e,n){const i=e.x,o=e.y-.15*n,r=o-.7*n,l=o-1.9*n,s=.55*n,a=.22*n;return{kind:"pointer",color:t.color,shape:[[i,o],[i-s,r],[i-a,r],[i-a,l],[i+a,l],[i+a,r],[i+s,r]].map((([t,e])=>`${t},${e}`)).join(" "),badge:null!=t.label?{cx:i+1.1*n,cy:l+.65*n,r:.65*n,label:t.label}:void 0}}function $(t,e,n,i,o,r,l){const s=e.y<=n.y,[a,h]=s?[e,n]:[n,e],[c,u]=s?[i.first,i.last]:[i.last,i.first],d=h.y+h.height+.2*l,f=[[o,d],[u,d],[c,a.y-.1*l]],b=r?x(r,l):0,v=a.y-.9*l,m=r?{x:o+.5*l+b/2,y:v,text:r}:void 0,y=m?m.x+b/2+1.2*l:o+.65*l;return{kind:"bracket",color:t.color,path:f.map((([t,e])=>`${t},${e}`)).join(" "),caption:m,frame:m&&{x:m.x-b/2-.45*l,y:m.y-.7*l,width:b+.9*l,height:1.4*l,r:.7*l},badge:null!=t.label?{cx:y,cy:v,r:.65*l,label:t.label}:void 0}}const O=["rowGroup","category","subCategory","date","scenario","row"];function S(t,e){var n;const i=t.table&&null==e.scenario?t.table.rows:null!==(n=t.elements)&&void 0!==n?n:[],o=null!=t.table&&null==e.subCategory;return i.filter((t=>function(t,e){var n;return!(!t||t.part!==(null!==(n=e.part)&&void 0!==n?n:"element"))&&O.every((n=>null==e[n]||e[n]+""===t[n]))}(t.point,e)&&!(o&&null!=t.point.subCategory))).map((({rect:t,content:e,contentSign:n,value:i,scenario:o,kind:r})=>({rect:t,content:e,contentSign:n,value:i,stacked:"string"==typeof o&&o.startsWith("stack:"),label:"label"===r})))}function j(t,e){const n=e.getBoundingClientRect();if(0===n.width||0===n.height)return!0;const i=t.x+t.width/2,o=t.y+t.height/2;return i>=n.left&&i<=n.right&&o>=n.top&&o<=n.bottom}const z=new Set(["bn-asset","bn-component-style","bn-dataset","bn-datasource","bn-internationalization","bn-ruleset","bn-scaling-group"]);function W(t,e){const n=e.getBoundingClientRect();return 0===n.width||0===n.height||t.x<n.right&&t.x+t.width>n.left&&t.y<n.bottom&&t.y+t.height>n.top}const C=t(class extends n{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.marks=[],this.pageKey="",this.parsedItems=[],this.scheduled=!1,this.run=0,this.observed=new WeakSet,this.observedAround=new WeakSet,this.reported=new Set,this.schedule=()=>{this.scheduled||(this.scheduled=!0,this.holdStatus(new Promise((t=>{requestAnimationFrame((()=>{this.scheduled=!1,this.place().catch((t=>console.error("bn-annotation-layer: placing the marks failed",t))).finally(t)}))}))))},this.holdStatus=h(this),this.errors=d(this),this.componentStyle=u(this)}connectedCallback(){var t;this.stores=r(this.element),this.pageKey=l(this.element),this.observed=new WeakSet,this.observedAround=new WeakSet,this.resizeObserver=new ResizeObserver(this.schedule),this.mutationObserver=new MutationObserver(this.schedule),this.observeSize(this.element);const e=this.element.closest("bn-layout-page");e&&this.mutationObserver.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["slot","data-bino-annotation-target"]}),null===(t=document.fonts)||void 0===t||t.addEventListener("loadingdone",this.schedule)}disconnectedCallback(){var t,e,n,i;null===(t=this.resizeObserver)||void 0===t||t.disconnect(),null===(e=this.mutationObserver)||void 0===e||e.disconnect(),null===(n=document.fonts)||void 0===n||n.removeEventListener("loadingdone",this.schedule),this.run++,(null===(i=this.stores)||void 0===i?void 0:i.annotationsUnplaced.state[this.pageKey])&&this.stores.annotationsUnplaced.set(this.pageKey,void 0)}componentWillLoad(){this.parseItems()}componentDidLoad(){this.schedule()}onItemsChange(){this.parseItems(),this.schedule()}parseItems(){const t=s(this.items);t?this.errors.remove("ERR_items"):this.errors.addOrReplace({id:"ERR_items",type:"error",message:"items: not a JSON array of objects."}),this.parsedItems=null!=t?t:[]}async place(){var t,e,n,i;const o=++this.run;if(!this.element.isConnected||!this.svg)return;const r=this.element.closest("bn-layout-page"),l=new Map,s=new Map;null==r||r.querySelectorAll("[data-bino-annotation-target]").forEach((t=>{const e=Array.from(t.querySelectorAll("*")).find((t=>t.localName.startsWith("bn-")&&!z.has(t.localName))),n=null!=e?e:t;l.set(t.getAttribute("data-bino-annotation-target"),n),s.set(n,t)})),null==r||r.querySelectorAll("[slot]").forEach((t=>this.observeSize(t)));const a=new Set(this.parsedItems.flatMap((t=>[t.target,t.to]))),h=[...l].filter((([t])=>a.has(t))).map((([,t])=>t));if(await Promise.all(h.map((t=>{var e;return null===(e=t.componentOnReady)||void 0===e?void 0:e.call(t)}))),o!==this.run)return;h.forEach((t=>{this.observe(t),this.observeAround(t,r)}));const c=new Map;if(await Promise.all(h.map((async t=>{var e;c.set(t,await(null===(e=t.getLayoutState)||void 0===e?void 0:e.call(t,{detail:"full"}).catch((()=>{}))))}))),o!==this.run)return;const u=(t,e)=>{var n;const i=null!=t?l.get(t):void 0;if(!i)return{problem:`no target "${t}" on this page`};const o=i.getBoundingClientRect();if(function(t){return!t||O.every((e=>null==t[e]))&&null==t.part}(e)){const e={x:o.left,y:o.top,width:o.width,height:o.height};return function(t,e,n){if(0===t.width||0===t.height||!W(t,n))return!0;for(let n=e;n&&"bn-layout-page"!==n.localName;n=n.parentElement)if(!W(t,n))return!0;return!1}(e,s.get(i),this.element)?{problem:`"${t}" cannot be seen`}:{box:e,whole:!0}}const r=c.get(i),a=r?S(r,e):[];if(1!==a.length)return{problem:`${a.length} elements match the point ${JSON.stringify(e)} in "${t}"`};const h=({component:{x:t,y:e,width:n,height:i}})=>({x:o.left+t,y:o.top+e,width:n,height:i}),u=h(a[0].rect);if(function(t,e){for(let n=e;n&&"bn-layout-page"!==n.localName;n=n.parentElement)if(!j(t,n))return!0;return!1}(u,s.get(i))||!j(u,this.element))return{problem:`the point ${JSON.stringify(e)} in "${t}" is cut off`};const f=a[0].content;if(!r.table)return{box:u,whole:!1,stacked:a[0].stacked,label:a[0].label,horizontal:d(r)};const b=(null!==(n=r.elements)&&void 0!==n?n:[]).flatMap((t=>"cell"===t.kind&&t.content?[{box:h(t.content),sign:t.contentSign}]:[]));return{box:u,whole:!1,text:f&&{box:h(f),sign:a[0].contentSign},obstacles:b}},d=t=>{var e;return(null!==(e=null==t?void 0:t.elements)&&void 0!==e?e:[]).some((t=>"axis"===t.kind&&"vertical"===t.orientation))},f=(t,e)=>{const n=null!=t?l.get(t):void 0;if(!n)return{problem:`no target "${t}" on this page`};const i=c.get(n),o=(i&&e?S(i,Object.assign(Object.assign({},e),{part:"element"})):[]).filter((t=>null!=t.value));if(0===o.length)return{problem:`no bar with a value matches the point ${JSON.stringify(e)} in "${t}"`};if(o.length>1&&!o.every((t=>t.stacked)))return{problem:`${o.length} elements match the point ${JSON.stringify(e)} in "${t}"`};const r=n.getBoundingClientRect(),s=Math.min(...o.map((t=>t.rect.component.x))),a=Math.min(...o.map((t=>t.rect.component.y))),h=Math.max(...o.map((t=>t.rect.component.x+t.rect.component.width))),u=Math.max(...o.map((t=>t.rect.component.y+t.rect.component.height)));return{box:{x:r.left+s,y:r.top+a,width:h-s,height:u-a},negatives:o.filter((t=>t.value<0)).map((t=>(t=>({x:r.left+t.x,y:r.top+t.y,width:t.width,height:t.height}))(t.rect.component))),value:o.reduce(((t,e)=>t+e.value),0),horizontal:d(i)}},b=(t,e,n)=>{const i=l.get(t.target),o=i&&c.get(i);if(!i||!o||!t.point)return;const r=i.getBoundingClientRect(),s=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(t.point,["rowGroup","category","subCategory","date"]),a=S(o,Object.assign(Object.assign({},s),{part:"element"})).filter((t=>null!=t.value)),h=a.reduce(((t,e)=>t+e.value),0),u=a.filter((t=>{const i=r.top+t.rect.component.y+t.rect.component.height/2;return i>=e.y&&i<=n.y+n.height})).reduce(((t,e)=>t+e.value),0);return 0!==h?u/h:void 0},v=this.toLocalSpace(),m=({box:t,sign:e=0})=>{const n=v(t);return Object.assign(Object.assign({},n),{x:n.x-e,width:n.width+e})},y=parseFloat(getComputedStyle(this.svg).fontSize)||13.3333,x={width:this.element.clientWidth,height:this.element.clientHeight},p=[],C=[];for(const o of this.parsedItems){if("difference"===o.mark){const e=f(o.target,o.point),n=f(null!==(t=o.to)&&void 0!==t?t:o.target,o.toPoint),i="problem"in e?e:"problem"in n?n:void 0;if(i){C.push({item:o,problem:i.problem});continue}const[r,l]=[e,n];if(r.horizontal){const t=t=>{const e=v(t.box);return e.x+e.width-t.negatives.reduce(((t,e)=>t+v(e).width),0)},e=k(o,v(r.box),v(l.box),r.value,l.value,y,{from:t(r),to:t(l)});e&&p.push(e);continue}const s=t=>v(t.box).y+t.negatives.reduce(((t,e)=>t+v(e).height),0),a=g(o,v(r.box),v(l.box),r.value,l.value,y,{from:s(r),to:s(l)});a&&p.push(a);continue}if("pointer"===o.mark||"bracket"===o.mark){const t=f(o.target,o.point),i="bracket"===o.mark?f(null!==(e=o.to)&&void 0!==e?e:o.target,o.toPoint):t,r="problem"in t?t:"problem"in i?i:void 0;if(r){C.push({item:o,problem:r.problem});continue}const[s,a]=[t,i],h=t=>{const e=v(t.box);return t.horizontal?{x:e.x+e.width-t.negatives.reduce(((t,e)=>t+v(e).width),0),y:e.y}:{x:e.x+e.width/2,y:e.y+t.negatives.reduce(((t,e)=>t+v(e).height),0)}};if("pointer"===o.mark){p.push(M(o,h(s),y));continue}if(!s.horizontal){C.push({item:o,problem:"a bracket needs bars that run from left to right"});continue}if(null!=o.to&&o.to!==o.target){C.push({item:o,problem:"both ends of a bracket must be in one chart"});continue}const[c,u]=s.box.y<=a.box.y?[s.box,a.box]:[a.box,s.box],d=o.percent?b(o,c,u):void 0,m=l.get(o.target).getBoundingClientRect(),x=v({x:m.left,y:m.top,width:m.width,height:m.height}),g=null!==(n=o.text)&&void 0!==n?n:null!=d?Math.round(100*d)+"%":void 0;p.push($(o,v(s.box),v(a.box),{first:h(s).x,last:h(a).x},x.x,g,y));continue}const r=u(o.target,o.point),s="arrow"===o.mark?u(o.to,o.toPoint):void 0,a="problem"in r?r:s&&"problem"in s?s:void 0;if(a){C.push({item:o,problem:a.problem});continue}const h=r,c=s,d=w(o,v(h.box),c&&v(c.box),y,{whole:h.whole,area:x,text:h.text&&m(h.text),obstacles:null===(i=h.obstacles)||void 0===i?void 0:i.map(m),stacked:h.stacked,label:h.label,horizontal:h.horizontal});d?p.push(d):C.push({item:o,problem:"an arrow needs two ends at different places"})}this.marks=p,this.storeUnplaced(C.flatMap((({item:t})=>null!=t.label?[t.label]:[]))),C.length>0&&this.reportWhenQuiet(o,C)}async reportWhenQuiet(t,e){let n=0;for(let e=0;e<50&&n<2;e++){if(await new Promise((t=>window.setTimeout(t,200))),t!==this.run)return;n=0===c.componentRegisterStatus().running?n+1:0}this.report(e)}report(t){var e,n;for(const{item:i,problem:o}of t){const t=`bn-annotation-layer: ${null!==(e=i.mark)&&void 0!==e?e:"marker"} ${null!==(n=i.label)&&void 0!==n?n:"without a number"} is not drawn: ${o}.`;this.reported.has(t)||(this.reported.add(t),console.warn(t))}}toLocalSpace(){var t;const e=null===(t=this.svg.getScreenCTM())||void 0===t?void 0:t.inverse();return t=>{if(!e)return t;const n=[[t.x,t.y],[t.x+t.width,t.y+t.height]].map((([t,n])=>new DOMPoint(t,n).matrixTransform(e)));return{x:Math.min(n[0].x,n[1].x),y:Math.min(n[0].y,n[1].y),width:Math.abs(n[1].x-n[0].x),height:Math.abs(n[1].y-n[0].y)}}}storeUnplaced(t){var e,n;const i=null===(e=this.stores)||void 0===e?void 0:e.annotationsUnplaced,o=null!==(n=null==i?void 0:i.state[this.pageKey])&&void 0!==n?n:[];i&&JSON.stringify(o)!==JSON.stringify(t)&&i.set(this.pageKey,t)}observe(t){this.observeSize(t);const e=t=>{var n;t&&(this.observed.has(t)||(this.observed.add(t),null===(n=this.mutationObserver)||void 0===n||n.observe(t,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["x","y","width","height","transform","style","class"]})),t.querySelectorAll("*").forEach((t=>e(t.shadowRoot))))};e(t.shadowRoot)}observeAround(t,e){var n,i;for(let o=t.parentElement;o&&o!==e;o=o.parentElement)this.observedAround.has(o)||(this.observedAround.add(o),null===(n=this.mutationObserver)||void 0===n||n.observe(o,{attributes:!0,attributeFilter:["style"]}),o.shadowRoot&&(null===(i=this.mutationObserver)||void 0===i||i.observe(o.shadowRoot,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]})))}observeSize(t){var e;this.observed.has(t)||(this.observed.add(t),null===(e=this.resizeObserver)||void 0===e||e.observe(t))}renderBadge(t,e){return t?i("g",null,i("circle",{cx:t.cx,cy:t.cy,r:t.r,style:{fill:e}}),null!=t.label?i("text",{class:"badge-text",x:t.cx,y:t.cy,style:{fontSize:1.1*t.r+"px"}},t.label):null):null}renderMark(t){var e,n,o,r,l;const s=a(t.color,this.componentStyle((t=>t["bn-annotation"])));if("marker"===t.kind)return i("g",{class:"mark marker","data-label":t.badge.label},this.renderBadge(t.badge,s));if("frame"===t.kind)return i("g",{class:"mark frame","data-label":null===(e=t.badge)||void 0===e?void 0:e.label},i("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:t.rx,ry:t.ry,style:{fill:t.caption?"#ffffff":"none",stroke:s,strokeWidth:"1.5"}}),t.caption?i("text",{class:"mark-text caption",x:t.caption.x,y:t.caption.y},t.caption.text):null,this.renderBadge(t.badge,s));if("difference"===t.kind){const e=a(void 0,this.componentStyle((t=>t["bn-annotation"])));return i("g",{class:"mark difference","data-label":null===(n=t.badge)||void 0===n?void 0:n.label},t.lines.map((t=>i("line",{class:"difference-line",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2}))),i("rect",{x:t.bar.x,y:t.bar.y,width:t.bar.width,height:t.bar.height,style:{fill:s}}),i("text",{class:"mark-text",x:t.text.x,y:t.text.y,style:{textAnchor:t.text.anchor}},t.text.value,t.text.percent?i("tspan",{class:"percent",dx:"0.35em"},t.text.percent):null),t.frame?i("rect",{x:t.frame.x,y:t.frame.y,width:t.frame.width,height:t.frame.height,rx:t.frame.r,ry:t.frame.r,style:{fill:"none",stroke:e,strokeWidth:"1.5"}}):null,this.renderBadge(t.badge,e))}return"pointer"===t.kind?i("g",{class:"mark pointer","data-label":null===(o=t.badge)||void 0===o?void 0:o.label},i("polygon",{points:t.shape,style:{fill:s}}),this.renderBadge(t.badge,s)):"bracket"===t.kind?i("g",{class:"mark bracket","data-label":null===(r=t.badge)||void 0===r?void 0:r.label},i("polyline",{points:t.path,style:{fill:"none",stroke:s,strokeWidth:"1.5"}}),t.frame?i("rect",{x:t.frame.x,y:t.frame.y,width:t.frame.width,height:t.frame.height,rx:t.frame.r,ry:t.frame.r,style:{fill:"#ffffff",stroke:s,strokeWidth:"1.5"}}):null,t.caption?i("text",{class:"mark-text caption",x:t.caption.x,y:t.caption.y},t.caption.text):null,this.renderBadge(t.badge,s)):i("g",{class:"mark arrow","data-label":null===(l=t.badge)||void 0===l?void 0:l.label},i("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,style:{stroke:s,strokeWidth:"1.5"}}),i("polygon",{points:t.head,style:{fill:s}}),this.renderBadge(t.badge,s))}render(){return i(o,{key:"3b82cff435bdbabe51cdb7581afef428a16716b0"},i("svg",{key:"0613bd3ecb59150c6959c9f96322b0f3eafc6164",ref:t=>this.svg=t},this.marks.map((t=>this.renderMark(t)))))}get element(){return this}static get watchers(){return{items:[{onItemsChange:0}]}}static get style(){return':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}'}},[1,"bn-annotation-layer",{items:[1],selectedStyle:[513,"selected-style"],marks:[32]},void 0,{items:[{onItemsChange:0}]}]),N=C,J=function(){"undefined"!=typeof customElements&&["bn-annotation-layer"].forEach((t=>{"bn-annotation-layer"===t&&(customElements.get(e(t))||customElements.define(e(t),C))}))};export{N as BnAnnotationLayer,J as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as
|
|
1
|
+
import{B as m,d as o}from"./p-BOwmXBm-.js";const s=m,p=o;export{s as BnChartBubbleRenderer,p as defineCustomElement}
|