@bino-bi/bn-template-engine 1.0.0-next.21 → 1.0.0-next.23
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-28d5c266.entry.js → p-0a49cf00.entry.js} +1 -1
- package/dist/bn-template-engine/{p-b9e94127.entry.js → p-22b8d044.entry.js} +1 -1
- package/dist/bn-template-engine/{p-6c7f0076.entry.js → p-251bb53d.entry.js} +1 -1
- package/dist/bn-template-engine/p-2aed639e.entry.js +1 -0
- package/dist/bn-template-engine/{p-7e9dbc93.entry.js → p-4616b879.entry.js} +1 -1
- package/dist/bn-template-engine/{p-99477a27.entry.js → p-629edcca.entry.js} +1 -1
- package/dist/bn-template-engine/p-686d8e44.entry.js +1 -0
- package/dist/bn-template-engine/{p-a4ea9a79.entry.js → p-68aa61cc.entry.js} +1 -1
- package/dist/bn-template-engine/{p-DwYUTvvI.js → p-B5x8M8OC.js} +1 -1
- package/dist/bn-template-engine/{p-fFtEvsY-.js → p-BGrnfif3.js} +1 -1
- package/dist/bn-template-engine/{p-6lOdN-fB.js → p-BVfLus3u.js} +1 -1
- package/dist/bn-template-engine/{p-CJThzFZm.js → p-BcZ5GQZ8.js} +1 -1
- package/dist/bn-template-engine/{p-CYE0I1Mx.js → p-Bca5V28_.js} +1 -1
- package/dist/bn-template-engine/p-C5UYpZUU.js +2 -0
- package/dist/bn-template-engine/{p-BgIpdpfH.js → p-C7T4DAAW.js} +1 -1
- package/dist/bn-template-engine/p-CDo04UEU.js +1 -0
- package/dist/bn-template-engine/p-CTrNbSXN.js +1 -0
- package/dist/bn-template-engine/{p-C5uvAEKI.js → p-CbciPY-M.js} +1 -1
- package/dist/bn-template-engine/{p-BpWWgN6k.js → p-CuR4S456.js} +1 -1
- package/dist/bn-template-engine/p-DWtTjg0f.js +1 -0
- package/dist/bn-template-engine/{p-eEfqksk-.js → p-DdqXNsKP.js} +1 -1
- package/dist/bn-template-engine/{p-B4JfKvVT.js → p-DtLI_CzV.js} +1 -1
- package/dist/bn-template-engine/p-UtNHLX1j.js +1 -0
- package/dist/bn-template-engine/{p-ba912130.entry.js → p-aecb5de3.entry.js} +1 -1
- package/dist/bn-template-engine/{p-687032d5.entry.js → p-ba43d46e.entry.js} +1 -1
- package/dist/bn-template-engine/{p-6077155f.entry.js → p-c476e7bb.entry.js} +1 -1
- package/dist/bn-template-engine/{p-2d3ea756.entry.js → p-d7c670ec.entry.js} +1 -1
- package/dist/bn-template-engine/{p-a1380d7c.entry.js → p-e4a584a8.entry.js} +1 -1
- package/dist/bn-template-engine/{p-de29986f.entry.js → p-f12fb09b.entry.js} +1 -1
- package/dist/bn-template-engine/p-f9a721bb.entry.js +1 -0
- package/dist/cjs/{AxisConfig-D7CAyPLO.js → AxisConfig-DmP4U3JM.js} +1 -1
- package/dist/cjs/{LabelCollisionManager-DkdQ9Xdg.js → LabelCollisionManager-Cet3WPm0.js} +2 -2
- package/dist/cjs/{Order-IPfAP0q8.js → Order-DlKLywO_.js} +1 -1
- package/dist/cjs/{SVGStyle-BD8jApd4.js → SVGStyle-D78RaNnj.js} +2 -2
- package/dist/cjs/{SVGVariancesStyleGroup-BaWzR951.js → SVGVariancesStyleGroup-XvNAnYYA.js} +1 -1
- package/dist/cjs/{VarianceMeasure-BBWTgv2e.js → VarianceMeasure-BfZLlICl.js} +4 -4
- package/dist/cjs/{XYChartDataRow-BoR0CTfl.js → XYChartDataRow-B0NNOqxB.js} +4 -4
- package/dist/cjs/bn-asset_21.cjs.entry.js +1052 -314
- package/dist/cjs/bn-chart-bubble.cjs.entry.js +25 -15
- package/dist/cjs/bn-chart-bullet.cjs.entry.js +9 -9
- package/dist/cjs/bn-chart-scatter.cjs.entry.js +9 -9
- package/dist/cjs/bn-grid.cjs.entry.js +6 -6
- package/dist/cjs/bn-image.cjs.entry.js +6 -6
- package/dist/cjs/bn-internationalization.cjs.entry.js +4 -4
- package/dist/cjs/bn-ruleset.cjs.entry.js +4 -4
- package/dist/cjs/bn-template-engine.cjs.js +3 -3
- package/dist/cjs/bn-template.cjs.entry.js +2 -2
- package/dist/cjs/bn-text.cjs.entry.js +7 -7
- package/dist/cjs/bn-tree.cjs.entry.js +6 -6
- package/dist/cjs/{context-protocol-BBhT9B52.js → context-protocol-DeLmu5s2.js} +1 -1
- package/dist/cjs/editor-companion.cjs.entry.js +2 -2
- package/dist/cjs/ibcs-chart-bubble.cjs.entry.js +6 -6
- package/dist/cjs/ibcs-chart-bullet.cjs.entry.js +6 -6
- package/dist/cjs/ibcs-chart-scatter.cjs.entry.js +6 -6
- package/dist/cjs/{index-CDKG4xmO.js → index-C1Z9vO7z.js} +61 -19
- package/dist/cjs/{layoutObserver-DUYYkDMQ.js → layoutObserver-CrzQQGpv.js} +5 -5
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/{scaling-BIJQ2NV1.js → scaling-JAU6IJnR.js} +85 -3
- package/dist/cjs/{withBodyObserver-BKUE_ypL.js → withBodyObserver-DJO98AJ-.js} +2 -2
- package/dist/cjs/{withHasError-Cl2gTQzA.js → withHasError-BdDmiOXM.js} +1 -1
- package/dist/cjs/{withScalingGroup-D5clRvRe.js → withScalingGroup-Bu5gatHT.js} +3 -3
- package/dist/cjs/{withStyled-Cm9dWQhu.js → withStyled-50UepUwV.js} +8 -8
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/bn-chart-bubble/bn-chart-bubble.js +15 -5
- package/dist/collection/components/bn-chart-structure/bn-chart-structure.css +6 -0
- package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +149 -57
- package/dist/collection/components/bn-chart-structure/ibcs-chart-structure.js +135 -28
- package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +30 -19
- package/dist/collection/components/bn-chart-time/bn-chart-time.js +186 -49
- package/dist/collection/components/bn-chart-time/ibcs-chart-time.css +9 -3
- package/dist/collection/components/bn-chart-time/ibcs-chart-time.js +141 -22
- package/dist/collection/components/bn-chart-time/utils/TimeChart.js +36 -0
- package/dist/collection/components/bn-scaling-group/bn-scaling-group.js +76 -19
- package/dist/collection/components/bn-table/bn-table.js +121 -49
- package/dist/collection/components/bn-table/ibcs-table.js +83 -42
- package/dist/collection/components/bn-table/utils/elements/CellBarChart.js +20 -34
- package/dist/collection/components/bn-table/utils/elements/WaterfallBar.js +4 -5
- package/dist/collection/components/bn-table/utils/helper/barColumnGeometry.js +89 -0
- package/dist/collection/utils/autoFit.js +63 -0
- package/dist/collection/utils/constants.js +3 -3
- package/dist/collection/utils/dataAnalyzer.js +17 -8
- package/dist/collection/utils/scaling.js +79 -0
- package/dist/collection/utils/validate.js +3 -3
- package/dist/components/DataFormatDigits.js +1 -1
- package/dist/components/autoFit.js +1 -0
- package/dist/components/bn-chart-bubble.js +1 -1
- package/dist/components/bn-chart-bullet.js +1 -1
- package/dist/components/bn-chart-scatter.js +1 -1
- package/dist/components/bn-chart-structure.js +1 -1
- package/dist/components/bn-chart-time.js +1 -1
- package/dist/components/bn-grid.js +1 -1
- package/dist/components/bn-scaling-group.js +1 -1
- package/dist/components/bn-table.js +1 -1
- package/dist/components/bn-text.js +1 -1
- package/dist/components/bn-tree.js +1 -1
- package/dist/components/ibcs-chart-structure2.js +1 -1
- package/dist/components/ibcs-chart-time2.js +1 -1
- package/dist/components/ibcs-table2.js +1 -1
- package/dist/components/scaling.js +1 -0
- package/dist/components/validate.js +1 -1
- package/dist/components/withDataset.js +1 -1
- package/dist/components/withStyled.js +1 -1
- package/dist/esm/{AxisConfig-ByIP5J-9.js → AxisConfig-Cjy_RANi.js} +1 -1
- package/dist/esm/{LabelCollisionManager-DaNiDiM9.js → LabelCollisionManager-B_NUM9yq.js} +2 -2
- package/dist/esm/{Order-BQeJE_yi.js → Order-B-aF6Rwn.js} +1 -1
- package/dist/esm/{SVGStyle-BwBlY3Km.js → SVGStyle-8FfAtUF-.js} +2 -2
- package/dist/esm/{SVGVariancesStyleGroup-BpGW4CvN.js → SVGVariancesStyleGroup-DD4mIOjT.js} +1 -1
- package/dist/esm/{VarianceMeasure-CE3N8Bea.js → VarianceMeasure-DLOuIIJ7.js} +4 -4
- package/dist/esm/{XYChartDataRow-DeMI1JKU.js → XYChartDataRow-CKfILBFG.js} +4 -4
- package/dist/esm/bn-asset_21.entry.js +1052 -314
- package/dist/esm/bn-chart-bubble.entry.js +25 -15
- package/dist/esm/bn-chart-bullet.entry.js +9 -9
- package/dist/esm/bn-chart-scatter.entry.js +9 -9
- package/dist/esm/bn-grid.entry.js +6 -6
- package/dist/esm/bn-image.entry.js +6 -6
- package/dist/esm/bn-internationalization.entry.js +4 -4
- package/dist/esm/bn-ruleset.entry.js +4 -4
- package/dist/esm/bn-template-engine.js +4 -4
- package/dist/esm/bn-template.entry.js +2 -2
- package/dist/esm/bn-text.entry.js +7 -7
- package/dist/esm/bn-tree.entry.js +6 -6
- package/dist/esm/{context-protocol-d8MHrEo8.js → context-protocol-BoEL0caI.js} +1 -1
- package/dist/esm/editor-companion.entry.js +2 -2
- package/dist/esm/ibcs-chart-bubble.entry.js +6 -6
- package/dist/esm/ibcs-chart-bullet.entry.js +6 -6
- package/dist/esm/ibcs-chart-scatter.entry.js +6 -6
- package/dist/esm/{index-B_d-jp99.js → index-C5UYpZUU.js} +61 -19
- package/dist/esm/{layoutObserver-BJBEyhNf.js → layoutObserver-cgIXg2sg.js} +5 -5
- package/dist/esm/loader.js +3 -3
- package/dist/esm/{scaling-BGnpSN1j.js → scaling-CxyNpMQM.js} +83 -4
- package/dist/esm/{withBodyObserver-IokS6fHD.js → withBodyObserver-Cb9ZC5_J.js} +2 -2
- package/dist/esm/{withHasError-DW_vMDUp.js → withHasError-Bh1Viz52.js} +1 -1
- package/dist/esm/{withScalingGroup-CC3UcvC5.js → withScalingGroup-Yv9nGGe1.js} +3 -3
- package/dist/esm/{withStyled-2l5Tx3cf.js → withStyled-By9Jd-Oy.js} +8 -8
- package/dist/types/components/bn-chart-bubble/bn-chart-bubble.d.ts +5 -2
- package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +47 -19
- package/dist/types/components/bn-chart-structure/ibcs-chart-structure.d.ts +17 -3
- package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +11 -3
- package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +52 -18
- package/dist/types/components/bn-chart-time/ibcs-chart-time.d.ts +18 -3
- package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +12 -0
- package/dist/types/components/bn-scaling-group/bn-scaling-group.d.ts +28 -8
- package/dist/types/components/bn-table/bn-table.d.ts +45 -19
- package/dist/types/components/bn-table/ibcs-table.d.ts +23 -6
- package/dist/types/components/bn-table/utils/elements/CellBarChart.d.ts +9 -1
- package/dist/types/components/bn-table/utils/helper/barColumnGeometry.d.ts +51 -0
- package/dist/types/components.d.ts +91 -55
- package/dist/types/stencil-public-runtime.d.ts +1 -0
- package/dist/types/utils/autoFit.d.ts +79 -0
- package/dist/types/utils/constants.d.ts +3 -3
- package/dist/types/utils/dataAnalyzer.d.ts +5 -1
- package/dist/types/utils/scaling.d.ts +63 -0
- package/dist/types/utils/validate.d.ts +2 -2
- package/package.json +1 -1
- package/readme.md +2 -0
- package/dist/bn-template-engine/p-2fba7c99.entry.js +0 -1
- package/dist/bn-template-engine/p-A8xyE4b1.js +0 -1
- package/dist/bn-template-engine/p-B_d-jp99.js +0 -2
- package/dist/bn-template-engine/p-BjBz5cSL.js +0 -1
- package/dist/bn-template-engine/p-C8Q0lsaU.js +0 -1
- package/dist/bn-template-engine/p-C9i1Xsib.js +0 -1
- package/dist/bn-template-engine/p-a8291de2.entry.js +0 -1
- package/dist/bn-template-engine/p-b5274369.entry.js +0 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { h } from "@stencil/core";
|
|
2
|
+
import { absoluteBarGeometry, BAR_LABEL_FONT_RATIO, relativePinGeometry } from "../helper/barColumnGeometry";
|
|
3
|
+
/** Matches SYSTEM_STYLE_DEFAULTS.global.fontSizePx; only used when `styles` is omitted. */
|
|
4
|
+
const DEFAULT_EM_PX = 13.3333;
|
|
2
5
|
// Default fallback colors (should come from componentStyle)
|
|
3
6
|
export const DEFAULT_STYLES = {
|
|
4
7
|
positive: { stroke: "#008f96", fill: "#008f96", fillpattern: "solid" },
|
|
@@ -11,10 +14,11 @@ export const DEFAULT_STYLES = {
|
|
|
11
14
|
pl: { stroke: "#404040", fill: "#ffffff", fillpattern: "outlined" },
|
|
12
15
|
},
|
|
13
16
|
fontColor: "#000000",
|
|
14
|
-
fontSize:
|
|
17
|
+
fontSize: DEFAULT_EM_PX * BAR_LABEL_FONT_RATIO,
|
|
18
|
+
emPx: DEFAULT_EM_PX,
|
|
15
19
|
fontFamily: "'Noto Sans', sans-serif",
|
|
16
|
-
unitScaling: 0.01, // Default:
|
|
17
|
-
percentageScaling: 0.5, // Default:
|
|
20
|
+
unitScaling: 0.01, // Default: 100 units per em of bar
|
|
21
|
+
percentageScaling: 0.5, // Default: 2 percentage points per em of pin
|
|
18
22
|
scaleFactor: 1,
|
|
19
23
|
};
|
|
20
24
|
export const AXIS_COLOR = "#666666";
|
|
@@ -186,21 +190,20 @@ function renderZigzagBreak(breakX, breakGap, yTop, barHeight, s) {
|
|
|
186
190
|
/**
|
|
187
191
|
* Renders an absolute variance bar chart (d_ prefix).
|
|
188
192
|
* Horizontal bar with centered axis, green for positive, red for negative.
|
|
189
|
-
* When a bar exceeds
|
|
193
|
+
* When a bar exceeds the geometry's cut width it is drawn as an overdrive bar:
|
|
190
194
|
* base segment + zigzag break + proportional overdrive stub (like structure chart).
|
|
191
195
|
*
|
|
192
|
-
* Layout: [left label area][bar area with axis][right label area]
|
|
196
|
+
* Layout: [left label area][bar area with axis][right label area], summing to
|
|
197
|
+
* exactly `columnWidthEm` em — see barColumnGeometry.ts.
|
|
193
198
|
*/
|
|
194
199
|
const AbsoluteVarianceBar = (props) => {
|
|
195
|
-
const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale,
|
|
200
|
+
const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, columnWidthEm = 10, styles = DEFAULT_STYLES, } = props;
|
|
196
201
|
const s = styles.scaleFactor;
|
|
197
202
|
const fs = styles.fontSize;
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
const breakGap =
|
|
202
|
-
const overdriveZoneWidth = maxBarWidth * 0.15;
|
|
203
|
-
const cutWidth = maxBarWidth - breakGap - overdriveZoneWidth;
|
|
203
|
+
// Adaptive axis placement based on data range
|
|
204
|
+
const hasNeg = columnStats.min < 0;
|
|
205
|
+
const hasPos = columnStats.max > 0;
|
|
206
|
+
const { totalWidth, axisX, breakGap, overdriveZoneWidth, cutWidth, labelGap } = absoluteBarGeometry(columnWidthEm, styles.emPx, hasNeg, hasPos);
|
|
204
207
|
// Direct unit scaling via fontSize
|
|
205
208
|
const scaledWidth = Math.abs(value) * styles.unitScaling * fs;
|
|
206
209
|
const isExtreme = scaledWidth > cutWidth;
|
|
@@ -209,16 +212,8 @@ const AbsoluteVarianceBar = (props) => {
|
|
|
209
212
|
const maxOverflow = Math.max(0, maxScaledWidth - cutWidth);
|
|
210
213
|
const overflowAmount = Math.max(0, scaledWidth - cutWidth);
|
|
211
214
|
const overdriveWidth = maxOverflow > 0 ? (overflowAmount / maxOverflow) * overdriveZoneWidth : 0;
|
|
212
|
-
// Adaptive axis placement based on data range
|
|
213
|
-
const hasNeg = columnStats.min < 0;
|
|
214
|
-
const hasPos = columnStats.max > 0;
|
|
215
|
-
const negBarWidth = hasNeg ? maxBarWidth : 0;
|
|
216
|
-
const posBarWidth = hasPos ? maxBarWidth : 0;
|
|
217
|
-
const barAreaWidth = negBarWidth + posBarWidth;
|
|
218
|
-
const totalWidth = (hasNeg ? labelAreaWidth : 0) + barAreaWidth + (hasPos ? labelAreaWidth : 0);
|
|
219
215
|
const padding = 2 * s;
|
|
220
216
|
const barHeight = height - padding * 2;
|
|
221
|
-
const axisX = (hasNeg ? labelAreaWidth : 0) + negBarWidth;
|
|
222
217
|
const barY = padding;
|
|
223
218
|
const isPositive = value >= 0;
|
|
224
219
|
// Get style based on column type (scenario vs variance)
|
|
@@ -239,7 +234,7 @@ const AbsoluteVarianceBar = (props) => {
|
|
|
239
234
|
const baseBarWidth = isExtreme ? cutWidth : scaledWidth;
|
|
240
235
|
// Label position accounts for overdrive
|
|
241
236
|
const totalVisualWidth = isExtreme ? cutWidth + breakGap + overdriveWidth : scaledWidth;
|
|
242
|
-
const labelX = isPositive ? axisX + totalVisualWidth +
|
|
237
|
+
const labelX = isPositive ? axisX + totalVisualWidth + labelGap : axisX - totalVisualWidth - labelGap;
|
|
243
238
|
const labelAnchor = isPositive ? "start" : "end";
|
|
244
239
|
return (h("svg", { width: totalWidth, height: height, class: "cell-bar-chart absolute-variance", style: { overflow: "visible" } }, h(PatternDefs, { styles: styles }), h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), baseBarWidth > 0 && (h("rect", { x: isPositive ? axisX : axisX - baseBarWidth, y: barY, width: baseBarWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme && overdriveWidth > 0 && (h("rect", { x: isPositive ? axisX + cutWidth + breakGap : axisX - cutWidth - breakGap - overdriveWidth, y: barY, width: overdriveWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), isExtreme &&
|
|
245
240
|
renderZigzagBreak(isPositive ? axisX + cutWidth : axisX - cutWidth - breakGap, breakGap, barY, barHeight, s), h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": labelAnchor, fill: styles.fontColor, "font-size": fs, "font-family": styles.fontFamily }, displayValue)));
|
|
@@ -248,25 +243,18 @@ const AbsoluteVarianceBar = (props) => {
|
|
|
248
243
|
* Renders a relative variance pin chart (dr_ prefix).
|
|
249
244
|
* Thin horizontal line from axis with dot at end and value label.
|
|
250
245
|
*
|
|
251
|
-
* Layout: [pin area with axis][label area on right]
|
|
246
|
+
* Layout: [pin area with axis][label area on right], summing to exactly
|
|
247
|
+
* `columnWidthEm` em — see barColumnGeometry.ts.
|
|
252
248
|
* Uses percentageScaling to determine pin length (pixels per percentage point).
|
|
253
249
|
*/
|
|
254
250
|
const RelativeVariancePin = (props) => {
|
|
255
|
-
const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale,
|
|
251
|
+
const { value, scenario, columnStats, height, isPositiveGood, formattedValue, measureScale, columnWidthEm = 10, styles = DEFAULT_STYLES, } = props;
|
|
256
252
|
const s = styles.scaleFactor;
|
|
257
253
|
const fs = styles.fontSize;
|
|
258
|
-
// Pin length is ~2/3 of bar width for visual balance
|
|
259
|
-
const maxPinLength = Math.round(maxBarWidthEm * 0.67 * fs);
|
|
260
|
-
const pinPadding = 5 * s;
|
|
261
254
|
// Adaptive axis placement based on data range
|
|
262
255
|
const hasNeg = columnStats.min < 0;
|
|
263
256
|
const hasPos = columnStats.max > 0;
|
|
264
|
-
const
|
|
265
|
-
const posPinWidth = hasPos ? maxPinLength + pinPadding : 0;
|
|
266
|
-
const pinAreaWidth = negPinWidth + posPinWidth;
|
|
267
|
-
const labelAreaWidth = 45 * s;
|
|
268
|
-
const totalWidth = pinAreaWidth + labelAreaWidth;
|
|
269
|
-
const axisX = negPinWidth;
|
|
257
|
+
const { totalWidth, maxPinLength, axisX, labelX } = relativePinGeometry(columnWidthEm, styles.emPx, hasNeg, hasPos);
|
|
270
258
|
const centerY = height / 2;
|
|
271
259
|
// Direct unit scaling via fontSize
|
|
272
260
|
const percentValue = Math.abs(value) * 100;
|
|
@@ -279,8 +267,6 @@ const RelativeVariancePin = (props) => {
|
|
|
279
267
|
const barStyle = getBarStyle(scenario, value, isPositiveGood, styles);
|
|
280
268
|
const dotRadius = 3 * s;
|
|
281
269
|
const displayValue = formattedValue || formatValue(value, true, measureScale);
|
|
282
|
-
// Label always on the right side after the pin area
|
|
283
|
-
const labelX = pinAreaWidth + 4 * s;
|
|
284
270
|
return (h("svg", { width: totalWidth, height: height, class: "cell-bar-chart relative-variance", style: { overflow: "visible" } }, h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), !isExtreme && h("circle", { cx: pinEndX, cy: centerY, r: dotRadius, fill: styles.fontColor }), h("line", { x1: axisX, y1: centerY, x2: pinEndX, y2: centerY, stroke: barStyle.fill, "stroke-width": 2 * s }), isExtreme && isPositive && (h("polygon", { points: `${axisX + maxPinLength},${centerY} ${axisX + maxPinLength - 6 * s},${centerY - 3 * s} ${axisX + maxPinLength - 6 * s},${centerY + 3 * s}`, fill: barStyle.fill })), isExtreme && !isPositive && (h("polygon", { points: `${axisX - maxPinLength},${centerY} ${axisX - maxPinLength + 6 * s},${centerY - 3 * s} ${axisX - maxPinLength + 6 * s},${centerY + 3 * s}`, fill: barStyle.fill })), h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": "start", fill: styles.fontColor, "font-size": fs, "font-style": "italic", "font-family": styles.fontFamily }, displayValue)));
|
|
285
271
|
};
|
|
286
272
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { h } from "@stencil/core";
|
|
2
2
|
import { AXIS_COLOR, DEFAULT_STYLES, formatValue, getBarFill, getBarStroke, getBarStyle, getScenarioType, PatternDefs, } from "./CellBarChart";
|
|
3
|
+
import { waterfallGeometry } from "../helper/barColumnGeometry";
|
|
3
4
|
/**
|
|
4
5
|
* Renders one row of an IBCS waterfall for a scenario bar column.
|
|
5
6
|
*
|
|
@@ -15,16 +16,14 @@ import { AXIS_COLOR, DEFAULT_STYLES, formatValue, getBarFill, getBarStroke, getB
|
|
|
15
16
|
* guides marking their parent bar's extent.
|
|
16
17
|
*/
|
|
17
18
|
export const WaterfallBar = (props) => {
|
|
18
|
-
const { value, scenario, height, measureScale,
|
|
19
|
+
const { value, scenario, height, measureScale, columnWidthEm = 10, styles = DEFAULT_STYLES, waterfall } = props;
|
|
19
20
|
const s = styles.scaleFactor;
|
|
20
21
|
const fs = styles.fontSize;
|
|
21
22
|
const range = waterfall.max - waterfall.min;
|
|
22
23
|
if (value === null || value === undefined || isNaN(value) || range <= 0) {
|
|
23
24
|
return (h("span", { class: "bar-chart-empty", style: { color: styles.fontColor, fontStyle: "italic" } }, "-"));
|
|
24
25
|
}
|
|
25
|
-
const labelAreaWidth =
|
|
26
|
-
const barAreaWidth = maxBarWidthEm * fs;
|
|
27
|
-
const totalWidth = labelAreaWidth + barAreaWidth + labelAreaWidth;
|
|
26
|
+
const { totalWidth, labelAreaWidth, barAreaWidth, labelGap } = waterfallGeometry(columnWidthEm, styles.emPx);
|
|
28
27
|
const pxPerUnit = barAreaWidth / range;
|
|
29
28
|
const xOf = (coordinate) => labelAreaWidth + (coordinate - waterfall.min) * pxPerUnit;
|
|
30
29
|
const padding = 2 * s;
|
|
@@ -41,7 +40,7 @@ export const WaterfallBar = (props) => {
|
|
|
41
40
|
// Scenario values carry no variance sentiment — labels are unsigned per IBCS
|
|
42
41
|
const displayValue = formatValue(value, waterfall.kind === "partof", measureScale).replace(/^\+/, "");
|
|
43
42
|
const pointsLeft = endX < startX;
|
|
44
|
-
const labelX = pointsLeft ? barX -
|
|
43
|
+
const labelX = pointsLeft ? barX - labelGap : barX + barWidth + labelGap;
|
|
45
44
|
const labelAnchor = pointsLeft ? "end" : "start";
|
|
46
45
|
return (h("svg", { width: totalWidth, height: height, class: "cell-bar-chart waterfall-bar", style: { overflow: "visible" } }, h(PatternDefs, { styles: styles }), h("line", { x1: axisX, y1: 0, x2: axisX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s }), waterfall.parentStart !== undefined && waterfall.parentEnd !== undefined && (h("line", { x1: xOf(waterfall.parentStart), y1: 0, x2: xOf(waterfall.parentStart), y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s, "stroke-dasharray": `${2 * s},${2 * s}` })), waterfall.parentStart !== undefined && waterfall.parentEnd !== undefined && (h("line", { x1: xOf(waterfall.parentEnd), y1: 0, x2: xOf(waterfall.parentEnd), y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s, "stroke-dasharray": `${2 * s},${2 * s}` })), barWidth > 0 && (h("rect", { x: barX, y: barY, width: barWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": labelAnchor, fill: styles.fontColor, "font-size": fs, "font-family": styles.fontFamily }, displayValue)));
|
|
47
46
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column geometry for the inline bar / pin / waterfall charts of bn-table.
|
|
3
|
+
*
|
|
4
|
+
* `bar-column-width="wN"` and `category-width="wN"` both mean "N em of the table font",
|
|
5
|
+
* so both columns render at the same width for the same N. The em used here is the TRUE
|
|
6
|
+
* table em (`--bn-font-size`, i.e. `global.fontSizePx × scaleFactor`) — deliberately NOT
|
|
7
|
+
* `CellBarChartStyles.fontSize`, which is 0.85 of it and doubles as the unitScaling /
|
|
8
|
+
* percentageScaling basis.
|
|
9
|
+
*
|
|
10
|
+
* Every quantity is returned in px so the SVG renderers stay in one coordinate space.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* SVG label font size relative to the table em. Also the multiplier in the
|
|
14
|
+
* unitScaling / percentageScaling math, so changing it rescales every user-set value.
|
|
15
|
+
*/
|
|
16
|
+
export const BAR_LABEL_FONT_RATIO = 0.85;
|
|
17
|
+
/**
|
|
18
|
+
* Horizontal padding of a bar cell, in table em:
|
|
19
|
+
* `td:has(.cell-bar-chart) { padding: 0 0.25em }` (ibcs-table.scss:320).
|
|
20
|
+
* With `box-sizing: border-box` the SVG has to be that much narrower than the requested
|
|
21
|
+
* column width, so the cell's border box lands on exactly N em — the same box
|
|
22
|
+
* `.category-wN` (ibcs-table.scss:50-83) produces.
|
|
23
|
+
*/
|
|
24
|
+
const BAR_CELL_PADDING_EM = 0.5;
|
|
25
|
+
/** Value-label gutter beside a bar, in em (was a hardcoded 38 px at the 13.3333 px em). */
|
|
26
|
+
const BAR_LABEL_EM = 2.85;
|
|
27
|
+
/** Value-label gutter beside a pin, in em (was 45 px). */
|
|
28
|
+
const PIN_LABEL_EM = 3.375;
|
|
29
|
+
/** Gap between the axis and the start of a pin's reserved side, in em (was 5 px). */
|
|
30
|
+
const PIN_PADDING_EM = 0.375;
|
|
31
|
+
/** Zigzag break gap of an overdrive bar, in em (was 4 px). */
|
|
32
|
+
const BREAK_GAP_EM = 0.3;
|
|
33
|
+
/** Gap between a bar/pin end and its value label, in em (was 4 px). */
|
|
34
|
+
const LABEL_GAP_EM = 0.3;
|
|
35
|
+
/** Share of the per-side bar extent reserved for the overdrive stub. */
|
|
36
|
+
const OVERDRIVE_FRACTION = 0.15;
|
|
37
|
+
/** The SVG fills the cell's content box: the requested column width minus the cell padding. */
|
|
38
|
+
function contentWidth(widthEm, emPx) {
|
|
39
|
+
return Math.max(0, (widthEm - BAR_CELL_PADDING_EM) * emPx);
|
|
40
|
+
}
|
|
41
|
+
/** Sides the axis serves. Clamped to 1 so a hypothetical all-zero column never divides by 0. */
|
|
42
|
+
function sideCount(hasNeg, hasPos) {
|
|
43
|
+
return Math.max(1, (hasNeg ? 1 : 0) + (hasPos ? 1 : 0));
|
|
44
|
+
}
|
|
45
|
+
export function absoluteBarGeometry(widthEm, emPx, hasNeg, hasPos) {
|
|
46
|
+
const totalWidth = contentWidth(widthEm, emPx);
|
|
47
|
+
const sides = sideCount(hasNeg, hasPos);
|
|
48
|
+
// Narrow columns shrink the gutters rather than the total, so wN stays wN.
|
|
49
|
+
const labelAreaWidth = Math.min(BAR_LABEL_EM * emPx, totalWidth / (2 * sides));
|
|
50
|
+
const maxBarWidth = (totalWidth - labelAreaWidth * sides) / sides;
|
|
51
|
+
const breakGap = Math.min(BREAK_GAP_EM * emPx, maxBarWidth * 0.2);
|
|
52
|
+
const overdriveZoneWidth = maxBarWidth * OVERDRIVE_FRACTION;
|
|
53
|
+
return {
|
|
54
|
+
totalWidth,
|
|
55
|
+
labelAreaWidth,
|
|
56
|
+
maxBarWidth,
|
|
57
|
+
axisX: hasNeg ? labelAreaWidth + maxBarWidth : 0,
|
|
58
|
+
breakGap,
|
|
59
|
+
overdriveZoneWidth,
|
|
60
|
+
cutWidth: Math.max(0, maxBarWidth - breakGap - overdriveZoneWidth),
|
|
61
|
+
labelGap: LABEL_GAP_EM * emPx,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function relativePinGeometry(widthEm, emPx, hasNeg, hasPos) {
|
|
65
|
+
const totalWidth = contentWidth(widthEm, emPx);
|
|
66
|
+
const sides = sideCount(hasNeg, hasPos);
|
|
67
|
+
const labelAreaWidth = Math.min(PIN_LABEL_EM * emPx, totalWidth / 2);
|
|
68
|
+
const pinAreaWidth = totalWidth - labelAreaWidth;
|
|
69
|
+
const sideWidth = pinAreaWidth / sides;
|
|
70
|
+
const pinPadding = Math.min(PIN_PADDING_EM * emPx, sideWidth * 0.2);
|
|
71
|
+
return {
|
|
72
|
+
totalWidth,
|
|
73
|
+
labelAreaWidth,
|
|
74
|
+
maxPinLength: Math.max(0, sideWidth - pinPadding),
|
|
75
|
+
pinPadding,
|
|
76
|
+
axisX: hasNeg ? sideWidth : 0,
|
|
77
|
+
labelX: pinAreaWidth + LABEL_GAP_EM * emPx,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function waterfallGeometry(widthEm, emPx) {
|
|
81
|
+
const totalWidth = contentWidth(widthEm, emPx);
|
|
82
|
+
const labelAreaWidth = Math.min(BAR_LABEL_EM * emPx, totalWidth / 4);
|
|
83
|
+
return {
|
|
84
|
+
totalWidth,
|
|
85
|
+
labelAreaWidth,
|
|
86
|
+
barAreaWidth: totalWidth - labelAreaWidth * 2,
|
|
87
|
+
labelGap: LABEL_GAP_EM * emPx,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure math for the chart auto-fit loops (ibcs-chart-structure fits width,
|
|
3
|
+
* ibcs-chart-time fits height). Kept free of chart/svg.js imports so it can
|
|
4
|
+
* be unit-tested under mock-doc (which lacks getBBox).
|
|
5
|
+
*
|
|
6
|
+
* Model: a chart's size along its fit axis is affine in the pixel scales,
|
|
7
|
+
* measured = fixed + unitExtent * pixelPerUnit + pctExtent * pixelPerPercentage
|
|
8
|
+
* where the extents are the total bar lengths in data units (positive plus
|
|
9
|
+
* negative side of the axis). The chart classes report their extents via
|
|
10
|
+
* getUnitBarExtent()/getPercentBarExtent(); {@link solveAutoFitStep} solves
|
|
11
|
+
* the model for the target size against a fresh measurement, so repeated
|
|
12
|
+
* steps converge even when clamped label widths flip between passes.
|
|
13
|
+
*/
|
|
14
|
+
/** Lower bound for auto-fitted pixelPerUnit / pixelPerPercentage values. */
|
|
15
|
+
export const MIN_PIXEL_SCALE = 0.001;
|
|
16
|
+
/**
|
|
17
|
+
* Total bar extent (in data units) that scales linearly with pixelPerUnit.
|
|
18
|
+
* Counts BOTH sides of the axis — a chart with values -13..+12 spans 25
|
|
19
|
+
* units, not 12 (fitting only the positive side is how charts used to
|
|
20
|
+
* overshoot their container).
|
|
21
|
+
*/
|
|
22
|
+
export function computeUnitBarExtent(inputs) {
|
|
23
|
+
if (inputs.fixedDomain != null) {
|
|
24
|
+
return Math.max(0, inputs.fixedDomain);
|
|
25
|
+
}
|
|
26
|
+
if (inputs.relativeVariance) {
|
|
27
|
+
return 0; // relative variance bars scale with pixelPerPercentage instead
|
|
28
|
+
}
|
|
29
|
+
return Math.max(0, inputs.maxPositive) + Math.abs(Math.min(0, inputs.minNegative));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Total bar extent (in fraction units) that scales linearly with
|
|
33
|
+
* pixelPerPercentage. Only relative variances use it; each side is clamped
|
|
34
|
+
* because extreme pins render as fixed-size arrows instead of longer bars.
|
|
35
|
+
*/
|
|
36
|
+
export function computePercentBarExtent(inputs) {
|
|
37
|
+
var _a;
|
|
38
|
+
if (!inputs.relativeVariance) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
const clamp = (_a = inputs.sideClamp) !== null && _a !== void 0 ? _a : 1.45;
|
|
42
|
+
const positive = Math.min(clamp, Math.max(0, inputs.maxPositive));
|
|
43
|
+
const negative = Math.min(clamp, Math.abs(Math.min(0, inputs.minNegative)));
|
|
44
|
+
return positive + negative;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Solves the affine size model for the target and returns corrected scale
|
|
48
|
+
* values (floored at {@link MIN_PIXEL_SCALE}). Returns an empty object when
|
|
49
|
+
* nothing scales with the solved values (both extents 0) — callers fall back
|
|
50
|
+
* to a ratio heuristic. Only the quantities whose extent is > 0 are returned.
|
|
51
|
+
*/
|
|
52
|
+
export function solveAutoFitStep(inputs) {
|
|
53
|
+
const divisor = inputs.unitExtent + inputs.pctExtent;
|
|
54
|
+
if (divisor <= 0) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
const fixed = inputs.measured - inputs.unitExtent * inputs.currentPpu - inputs.pctExtent * inputs.currentPpp;
|
|
58
|
+
const solved = Math.max(MIN_PIXEL_SCALE, (inputs.target - fixed) / divisor);
|
|
59
|
+
return {
|
|
60
|
+
ppu: inputs.unitExtent > 0 ? solved : undefined,
|
|
61
|
+
ppp: inputs.pctExtent > 0 ? solved : undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -70,7 +70,7 @@ export var TableType;
|
|
|
70
70
|
TableType["OPT"] = "opt";
|
|
71
71
|
TableType["OPTNOTOTAL"] = "optnototal";
|
|
72
72
|
})(TableType || (TableType = {}));
|
|
73
|
-
/** Width of the category label column
|
|
73
|
+
/** Width of the category label column, in em of the table font. INF = auto/infinite. */
|
|
74
74
|
export var TableCategoryWidth;
|
|
75
75
|
(function (TableCategoryWidth) {
|
|
76
76
|
TableCategoryWidth["INF"] = "inf";
|
|
@@ -82,7 +82,7 @@ export var TableCategoryWidth;
|
|
|
82
82
|
TableCategoryWidth["W10"] = "w10";
|
|
83
83
|
TableCategoryWidth["W5"] = "w5";
|
|
84
84
|
})(TableCategoryWidth || (TableCategoryWidth = {}));
|
|
85
|
-
/** Width preset for inline bar/pin chart columns. Value =
|
|
85
|
+
/** Width preset for inline bar/pin chart columns. Value = total column width in em. */
|
|
86
86
|
export var TableBarColumnWidth;
|
|
87
87
|
(function (TableBarColumnWidth) {
|
|
88
88
|
TableBarColumnWidth["W5"] = "w5";
|
|
@@ -96,7 +96,7 @@ export var TableBarColumnWidth;
|
|
|
96
96
|
TableBarColumnWidth["W80"] = "w80";
|
|
97
97
|
TableBarColumnWidth["W100"] = "w100";
|
|
98
98
|
})(TableBarColumnWidth || (TableBarColumnWidth = {}));
|
|
99
|
-
/** Maps TableBarColumnWidth presets to
|
|
99
|
+
/** Maps TableBarColumnWidth presets to total bar column width in em. */
|
|
100
100
|
export const BAR_COLUMN_WIDTH_EM = {
|
|
101
101
|
[TableBarColumnWidth.W5]: 5,
|
|
102
102
|
[TableBarColumnWidth.W10]: 10,
|
|
@@ -50,6 +50,10 @@ export class DataAnalyzer {
|
|
|
50
50
|
if (mode === "_") {
|
|
51
51
|
return new SiPrefix();
|
|
52
52
|
}
|
|
53
|
+
// Accept the Unicode micro sign as an alias for the ASCII "my" key.
|
|
54
|
+
if (mode === "μ") {
|
|
55
|
+
mode = "my";
|
|
56
|
+
}
|
|
53
57
|
if (mode != null) {
|
|
54
58
|
if ([...this.unitsLeast, ...this.unitsGreat].includes(mode)) {
|
|
55
59
|
return this.lookupPrefix(mode);
|
|
@@ -84,17 +88,22 @@ export class DataAnalyzer {
|
|
|
84
88
|
}
|
|
85
89
|
return this.determinePrefix(Math.abs(num));
|
|
86
90
|
}
|
|
87
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Maps an absolute numeric value to the best-fitting SI prefix based on
|
|
93
|
+
* its decimal magnitude. Values in (0.001, 1000) keep the identity prefix.
|
|
94
|
+
* Magnitudes beyond the covered SI range clamp to the outermost prefix.
|
|
95
|
+
*/
|
|
88
96
|
static determinePrefix(num) {
|
|
97
|
+
if (!Number.isFinite(num) || num <= 0) {
|
|
98
|
+
return new SiPrefix();
|
|
99
|
+
}
|
|
89
100
|
if (num >= 1000) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
return new SiPrefix(this.unitsGreat[floor - 1], value);
|
|
101
|
+
const idx = Math.min(Math.floor(Math.log10(num) / 3), this.unitsGreat.length) - 1;
|
|
102
|
+
return new SiPrefix(this.unitsGreat[idx], Math.pow(1000, idx + 1));
|
|
93
103
|
}
|
|
94
104
|
if (num <= 0.001) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
return new SiPrefix(this.unitsLeast[floor - 1], value);
|
|
105
|
+
const idx = Math.min(-Math.floor(Math.log10(num) / 3), this.unitsLeast.length) - 1;
|
|
106
|
+
return new SiPrefix(this.unitsLeast[idx], Math.pow(1000, -(idx + 1)));
|
|
98
107
|
}
|
|
99
108
|
return new SiPrefix();
|
|
100
109
|
}
|
|
@@ -106,4 +115,4 @@ export class DataAnalyzer {
|
|
|
106
115
|
/** SI prefixes for large numbers, ordered by magnitude (k=10^3 .. Y=10^24). */
|
|
107
116
|
DataAnalyzer.unitsGreat = ["k", "M", "G", "T", "P", "E", "Z", "Y"];
|
|
108
117
|
/** SI prefixes for small numbers, ordered by magnitude (m=10^-3 .. y=10^-24). */
|
|
109
|
-
DataAnalyzer.unitsLeast = ["m", "my", "n", "p", "
|
|
118
|
+
DataAnalyzer.unitsLeast = ["m", "my", "n", "p", "f", "a", "z", "y"];
|
|
@@ -15,3 +15,82 @@ export function parseScaling(scale) {
|
|
|
15
15
|
return { mode: "factor", factor: num };
|
|
16
16
|
return { mode: "empty" };
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* SI suffixes accepted by the shared scaling-value grammar.
|
|
20
|
+
* Case-sensitive except `k`/`K`; lowercase `m` (SI milli) is deliberately
|
|
21
|
+
* rejected to avoid ambiguity with `M` (mega).
|
|
22
|
+
*/
|
|
23
|
+
const SCALING_SI_SUFFIX = { k: 1e3, K: 1e3, M: 1e6, G: 1e9, T: 1e12 };
|
|
24
|
+
/**
|
|
25
|
+
* Positive decimal with optional whitespace and optional single SI suffix.
|
|
26
|
+
* No sign, no exponent notation — keeps the grammar unambiguous against
|
|
27
|
+
* scaling-group names.
|
|
28
|
+
*/
|
|
29
|
+
const SCALING_NUMBER_RE = /^(\d+(?:\.\d+)?|\.\d+)\s*([kKMGT])?$/;
|
|
30
|
+
/**
|
|
31
|
+
* Parses a raw scaling value with the shared grammar used by
|
|
32
|
+
* `unit-scaling` / `percentage-scaling` and `<bn-scaling-group>`:
|
|
33
|
+
*
|
|
34
|
+
* - `"auto"` (trimmed, case-insensitive) -> `{ kind: "auto" }`
|
|
35
|
+
* - a positive number with optional SI suffix (`"250000"`, `"2.5M"`, `"1 k"`;
|
|
36
|
+
* suffixes `k`/`K` = 1e3, `M` = 1e6, `G` = 1e9, `T` = 1e12) -> `{ kind: "number" }`
|
|
37
|
+
* - anything else (blank, signs, exponent notation, lowercase `m`/`g`/`t`,
|
|
38
|
+
* zero, negatives, non-finite) -> `{ kind: "invalid" }`
|
|
39
|
+
*/
|
|
40
|
+
export function parseScalingValue(raw) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (typeof raw === "number") {
|
|
43
|
+
return Number.isFinite(raw) && raw > 0 ? { kind: "number", value: raw } : { kind: "invalid", raw: String(raw) };
|
|
44
|
+
}
|
|
45
|
+
const s = (_a = raw === null || raw === void 0 ? void 0 : raw.toString().trim()) !== null && _a !== void 0 ? _a : "";
|
|
46
|
+
if (s.toLowerCase() === "auto")
|
|
47
|
+
return { kind: "auto" };
|
|
48
|
+
const match = SCALING_NUMBER_RE.exec(s);
|
|
49
|
+
if (match) {
|
|
50
|
+
const value = Number(match[1]) * (match[2] ? SCALING_SI_SUFFIX[match[2]] : 1);
|
|
51
|
+
if (Number.isFinite(value) && value > 0)
|
|
52
|
+
return { kind: "number", value };
|
|
53
|
+
}
|
|
54
|
+
return { kind: "invalid", raw: s };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolves a raw `unit-scaling` / `percentage-scaling` value.
|
|
58
|
+
* Resolution order: `auto` -> scaling-group lookup (trimmed name) ->
|
|
59
|
+
* number/SI parse -> invalid. `auto` wins over a group of the same name
|
|
60
|
+
* because the name is reserved.
|
|
61
|
+
*/
|
|
62
|
+
export function resolveScalingValue(raw, groups) {
|
|
63
|
+
const parsed = parseScalingValue(raw);
|
|
64
|
+
if (parsed.kind === "auto")
|
|
65
|
+
return { kind: "auto" };
|
|
66
|
+
if (typeof raw === "string") {
|
|
67
|
+
const name = raw.trim();
|
|
68
|
+
if (groups.has(name))
|
|
69
|
+
return { kind: "value", value: groups.get(name) };
|
|
70
|
+
}
|
|
71
|
+
if (parsed.kind === "number")
|
|
72
|
+
return { kind: "value", value: parsed.value };
|
|
73
|
+
return { kind: "invalid", raw: parsed.raw };
|
|
74
|
+
}
|
|
75
|
+
const SCALING_FORMAT_STEPS = [
|
|
76
|
+
[1e12, "T"],
|
|
77
|
+
[1e9, "G"],
|
|
78
|
+
[1e6, "M"],
|
|
79
|
+
[1e3, "k"],
|
|
80
|
+
];
|
|
81
|
+
/**
|
|
82
|
+
* Formats a positive value with the same SI suffixes the parser accepts,
|
|
83
|
+
* rounded to 3 significant digits (`250000` -> `"250k"`). Values just below
|
|
84
|
+
* a suffix boundary may round up across it (`999999` -> `"1000k"`) — fine
|
|
85
|
+
* for warning messages, which is all this is used for.
|
|
86
|
+
*/
|
|
87
|
+
export function formatScalingValue(value) {
|
|
88
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
89
|
+
return String(value);
|
|
90
|
+
const sig = (n) => String(Number(n.toPrecision(3)));
|
|
91
|
+
for (const [mult, suffix] of SCALING_FORMAT_STEPS) {
|
|
92
|
+
if (value >= mult)
|
|
93
|
+
return `${sig(value / mult)}${suffix}`;
|
|
94
|
+
}
|
|
95
|
+
return sig(value);
|
|
96
|
+
}
|
|
@@ -259,11 +259,11 @@ export function isValidMeasureType(value) {
|
|
|
259
259
|
}
|
|
260
260
|
/**
|
|
261
261
|
* Validates a measure-scale attribute value.
|
|
262
|
-
* Accepted values: `"_"` (no scaling), SI prefix letters (k, M, G, T, P, E, Z, Y, m, etc
|
|
263
|
-
* or auto-detection modes `"GREATEST"` / `"LEAST"`.
|
|
262
|
+
* Accepted values: `"_"` (no scaling), SI prefix letters (k, M, G, T, P, E, Z, Y, m, etc.;
|
|
263
|
+
* micro as `"my"` or `"μ"`), or auto-detection modes `"GREATEST"` / `"LEAST"`.
|
|
264
264
|
*/
|
|
265
265
|
export function isValidMeasureScale(value) {
|
|
266
|
-
return (["_", "k", "M", "G", "T", "P", "E", "Z", "Y", "m", "
|
|
266
|
+
return (["_", "k", "M", "G", "T", "P", "E", "Z", "Y", "m", "my", "μ", "n", "p", "f", "a", "z", "y"].includes(value === null || value === void 0 ? void 0 : value.trim()) || ["GREATEST", "LEAST"].includes(value === null || value === void 0 ? void 0 : value.trim().toUpperCase()));
|
|
267
267
|
}
|
|
268
268
|
export function validateI18nString(value) {
|
|
269
269
|
if (isBlankInput(value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e}from"./SiPrefix.js";import{C as t}from"./CompareUtil.js";var
|
|
1
|
+
import{S as e}from"./SiPrefix.js";import{C as t}from"./CompareUtil.js";var r;!function(e){e[e.Y=1e24]="Y",e[e.Z=1e21]="Z",e[e.E=1e18]="E",e[e.P=1e15]="P",e[e.T=1e12]="T",e[e.G=1e9]="G",e[e.M=1e6]="M",e[e.k=1e3]="k",e[e.h=100]="h",e[e.da=10]="da",e[e.d=.1]="d",e[e.c=.01]="c",e[e.m=.001]="m",e[e.my=1e-6]="my",e[e.n=1e-9]="n",e[e.p=1e-12]="p",e[e.f=1e-15]="f",e[e.a=1e-18]="a",e[e.z=1e-21]="z",e[e.y=1e-24]="y"}(r||(r={}));class a{static calculateMeasureScale(t,r,a,n){var s,i;if("_"===n)return new e;if("μ"===n&&(n="my"),null!=n&&[...this.unitsLeast,...this.unitsGreat].includes(n))return this.lookupPrefix(n);if(0===a.length||!r)return new e;const u=`SELECT MAX(GREATEST(${a.filter((e=>3===e.length)).map((e=>"ABS("+e+")")).toString()})) as prefixvalue\n FROM ${r}`,l=`SELECT MIN(LEAST(${a.filter((e=>3===e.length)).map((e=>"ABS("+e+")")).toString()})) as prefixvalue\n FROM ${r}`;let c,h=u;"LEAST"===(null==n?void 0:n.toUpperCase())&&(h=l);try{c=null!==(i=null===(s=t.exec(h)[0])||void 0===s?void 0:s.prefixvalue)&&void 0!==i?i:0}catch(t){return console.error("DataAnalyzer: measure-scale query failed",h,t),new e}return this.determinePrefix(Math.abs(c))}static determinePrefix(t){if(!Number.isFinite(t)||t<=0)return new e;if(t>=1e3){const r=Math.min(Math.floor(Math.log10(t)/3),this.unitsGreat.length)-1;return new e(this.unitsGreat[r],Math.pow(1e3,r+1))}if(t<=.001){const r=Math.min(-Math.floor(Math.log10(t)/3),this.unitsLeast.length)-1;return new e(this.unitsLeast[r],Math.pow(1e3,-(r+1)))}return new e}static lookupPrefix(t){return new e(t,r[t])}}a.unitsGreat=["k","M","G","T","P","E","Z","Y"],a.unitsLeast=["m","my","n","p","f","a","z","y"];class n{constructor(e=2,t=1){this.percent=e,this.decimal=t}}class s{adapt(e){const r=new n;return t.isNumber(e.percent)&&(r.percent=e.percent),t.isNumber(e.decimal)&&(r.decimal=e.decimal),r}default(){return new n}}export{a as D,n as a,s as b}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=.001;function n(t){return null!=t.fixedDomain?Math.max(0,t.fixedDomain):t.relativeVariance?0:Math.max(0,t.maxPositive)+Math.abs(Math.min(0,t.minNegative))}function a(t){var n;if(!t.relativeVariance)return 0;const a=null!==(n=t.sideClamp)&&void 0!==n?n:1.45;return Math.min(a,Math.max(0,t.maxPositive))+Math.min(a,Math.abs(Math.min(0,t.minNegative)))}function r(t){const n=t.unitExtent+t.pctExtent;if(n<=0)return{};const a=Math.max(.001,(t.target-(t.measured-t.unitExtent*t.currentPpu-t.pctExtent*t.currentPpp))/n);return{ppu:t.unitExtent>0?a:void 0,ppp:t.pctExtent>0?a:void 0}}export{t as M,a,n as c,r as s}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{proxyCustomElement as t,HTMLElement as e,writeTask as i,forceUpdate as s,h as a,Host as r,transformTag as l}from"@stencil/core/internal/client";import{a as n}from"./context-protocol.js";import{w as o,g as h,p as c}from"./withDataset.js";import{o as u}from"./layoutObserver.js";import{i as d,h as p,j as v}from"./validate.js";import{w as m,a as f}from"./withHasError.js";import{w as g}from"./withComponentStyle.js";import{w as y}from"./withRuleSet.js";import{w as b}from"./withScalingGroup.js";import{w}from"./withTranslation.js";import{w as x}from"./withStyled.js";import{r as _,s as R}from"./VarianceMeasure.js";import{t as S,a as E,b as L,c as $,d as j,e as A,p as C}from"./AxisConfig.js";import{d as z}from"./ibcs-chart-bubble2.js";const O={rowGroup:0,category:1,subCategory:2},W=["ac","pp","fc","pl"],N=t(class extends e{validateX(t){this.validateMeasureSpec("x",t,!0,(t=>S(t)))}validateY(t){this.validateMeasureSpec("y",t,!0,(t=>S(t)))}validateSize(t){this.validateMeasureSpec("size",t,!0,(t=>E(t))),this.validateSizeScaling()}validateShare(t){this.validateMeasureSpec("share",t,!1,(t=>L(t)))}validateCompareWith(t){const e="ERR_compareWith";d(t)||W.includes(t.trim().toLowerCase())?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`compare-with: invalid value '${t}' — expected ${W.join("/")}; ignored.`})}validateLevel(t){const e="ERR_level",i=["auto","category","subcategory"];d(t)||i.includes(t.trim().toLowerCase())?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`level: invalid value '${t}' — expected ${i.join("/")}; using 'auto'.`})}validateSeriesLevel(t){const e="ERR_seriesLevel",i=["auto","rowgroup","category","none"];d(t)||i.includes(t.trim().toLowerCase())?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`series-level: invalid value '${t}' — expected ${i.join("/")}; using 'auto'.`})}validateFacet(t){this.validateObjectSpec("facet",t,(t=>$(t)))}validateLabels(t){this.validateObjectSpec("labels",t,(t=>j(t,this.labelDefaults())))}validateLegend(t){this.validateObjectSpec("legend",t,(t=>A(t)))}validateAspect(t){const e="ERR_aspect";d(t)||null!==this.parseAspect(t)?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`aspect: invalid value '${t}' — expected "w:h" (e.g. "16:9"); using the default.`})}validateLimit(t){const e="ERR_limit";p(t)&&Number(t)>=0?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`limit: invalid value '${t}' — expected a non-negative integer; using 0.`})}validateScale(t){const e="ERR_scale";if(d(t))return void this.errors.remove(e);const{mode:i,factor:s}=c(t);"factor"===i&&(void 0===s||s<=0)?this.errors.addOrReplace({id:e,type:"warning",message:`scale: invalid value '${t}' — expected none/auto or a positive number.`}):this.errors.remove(e)}constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.datasetName="",this.dataVersion=0,this.datasetMeta=null,this.appliedScaleFactor=1,this.layoutObserver=null,this.activeErrors=new Set,this.pixelPerUnitGroupMap=new Map,this.chartTitle="",this.filter="",this.share="",this.compareWith="",this.level="auto",this.seriesLevel="auto",this.facet="",this.labels="",this.legend="",this.aspect="16:9",this.limit=0,this._autoScaleGuard=!1,this._lastObservedWidth=0,this.translateForInner=(t,e)=>this.t(t,e),x(this),m(this),o(this,(t=>{this.datasetName=(null==t?void 0:t.startsWith("$"))?t.substring(1):t||"",this.dataVersion=this.dataVersion+1}),((t,e)=>{this.datasetMeta=e})),this.errors=f(this),b(this),this.componentStyle=g(this),this.ruleSetConfig=y(this),this.t=w(this).t}componentWillLoad(){this.validateX(this.x),this.validateY(this.y),this.validateSize(this.size),this.validateShare(this.share),this.validateCompareWith(this.compareWith),this.validateLevel(this.level),this.validateSeriesLevel(this.seriesLevel),this.validateFacet(this.facet),this.validateLabels(this.labels),this.validateLegend(this.legend),this.validateAspect(this.aspect),this.validateLimit(this.limit),this.validateScale(this.scale)}componentDidRender(){const{mode:t}=c(this.scale);if("auto"!==t&&"empty"!==t){this._autoScaleGuard=!1;const t=h(this.element),e="WARN_overflow";return void(t.width>0&&this.element.scrollWidth>t.width+1?this.errors.addOrReplace({id:e,type:"warning",message:"Chart exceeds available space and will be cut off. Check the scale value."}):this.errors.remove(e))}if(this._autoScaleGuard)return void(this._autoScaleGuard=!1);const e=this.element,{width:s}=h(e);if(s<=0)return;this._lastObservedWidth=s;const a=this.componentStyle((t=>{var e;return(null===(e=t.global)||void 0===e?void 0:e.fontSizePx)||13.3333})),r=e.scrollWidth,l=this.appliedScaleFactor;if(!Number.isFinite(r)||r<=s+1)return void this.errors.remove("AUTO_scale");const n=Math.max(.3,l*(s-1)/r);Math.abs(n-l)<.01||(e.style.setProperty("--bn-font-size",a*n+"px"),"empty"===t?this.errors.addOrReplace({id:"AUTO_scale",type:"warning",message:"Auto-scaled chart by factor "+n.toFixed(3)}):this.errors.remove("AUTO_scale"),this._autoScaleGuard=!0,i((()=>{this.appliedScaleFactor=n})))}componentDidLoad(){this.layoutObserver=u(this.element,(()=>{if(this._autoScaleGuard)return;const{width:t}=h(this.element);t>0&&Math.abs(t-this._lastObservedWidth)>2&&(this._lastObservedWidth=t,s(this))})),requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(this._autoScaleGuard)return;const{width:t}=h(this.element);this._lastObservedWidth=t,s(this)}))}))}disconnectedCallback(){var t;null===(t=this.layoutObserver)||void 0===t||t.disconnect(),this.layoutObserver=null}labelDefaults(){return{points:"all",values:!0,max:12}}setBlockingError(t,e){null===e?(this.errors.remove(t),this.activeErrors.delete(t)):(this.errors.addOrReplace({id:t,type:"error",message:e}),this.activeErrors.add(t))}hasBlockingErrors(){return this.activeErrors.size>0}validateSizeScaling(){var t;const e=null===(t=this.prepareSize())||void 0===t?void 0:t.group;this.setBlockingError("ERR_xy_scale_group",void 0===e||this.pixelPerUnitGroupMap.has(e)?null:this.t(".bubble-scale-group-unknown",{group:e}))}validateMeasureSpec(t,e,i,s){var a;const r="ERR_xy_json_"+t,l="ERR_xy_measure_"+t,n="WARN_xy_fields_"+t,{data:o,parseError:h}=C(e,"measure");if(h)return this.setBlockingError(r,this.t(".xy-prop-json",{prop:t})),this.setBlockingError(l,null),void this.errors.remove(n);if(this.setBlockingError(r,null),null===o)return this.setBlockingError(l,i?this.t(".xy-measure-invalid",{prop:t,measure:""}):null),void this.errors.remove(n);const c=null!==(a=o.measure)&&void 0!==a?a:"";v(c)?this.setBlockingError(l,null):this.setBlockingError(l,this.t(".xy-measure-invalid",{prop:t,measure:c})),this.reportSpecIssues(n,t,s(o))}validateObjectSpec(t,e,i){const s="ERR_xy_json_"+t,a="WARN_xy_fields_"+t,{data:r,parseError:l}=C(e,null);if(l)return this.setBlockingError(s,this.t(".xy-prop-json",{prop:t})),void this.errors.remove(a);this.setBlockingError(s,null),null!==r?this.reportSpecIssues(a,t,i(r)):this.errors.remove(a)}reportSpecIssues(t,e,i){const s=[];null!==i&&i.invalidFields.length>0&&s.push("invalid: "+i.invalidFields.join(", ")),null!==i&&i.unknownKeys.length>0&&s.push("unknown: "+i.unknownKeys.join(", ")),s.length>0?this.errors.addOrReplace({id:t,type:"warning",message:`${e}: ignored sub-fields (${s.join("; ")}).`}):this.errors.remove(t)}prepareAxis(t,e){const{data:i,parseError:s}=C(e,"measure");if(s||null===i)return null;const{config:a}=S(i);return null!==a&&v(a.measure)?(void 0!==a.min&&void 0!==a.max&&a.min>=a.max?(this.errors.addOrReplace({id:"WARN_xy_domain_"+t,type:"warning",message:t+": min must be smaller than max; the override is ignored."}),a.min=void 0,a.max=void 0):this.errors.remove("WARN_xy_domain_"+t),a):null}prepareSize(){const{data:t,parseError:e}=C(this.size,"measure");if(e||null===t)return null;const{config:i}=E(t);return null!==i&&v(i.measure)?i:null}prepareShare(){const{data:t,parseError:e}=C(this.share,"measure");if(e||null===t)return null;const{config:i}=L(t);return null!==i&&v(i.measure)?i:null}prepareCompareFamily(){var t;const e=null===(t=this.compareWith)||void 0===t?void 0:t.trim().toLowerCase();return W.includes(e)?e:null}prepareLabels(){const t=this.labelDefaults(),{data:e,parseError:i}=C(this.labels,null);return i||null===e?{points:t.points,values:t.values,max:t.max}:j(e,t).config}prepareLegend(){const{data:t,parseError:e}=C(this.legend,null);return e||null===t?{show:!0,position:"right"}:A(t).config}prepareFacet(){const{data:t,parseError:e}=C(this.facet,null);return e||null===t?null:$(t).config}preparePointLevel(){var t,e;const i=null===(t=this.level)||void 0===t?void 0:t.trim().toLowerCase();if("category"===i)return"category";if("subcategory"===i)return"subCategory";const s=null===(e=this.datasetMeta)||void 0===e?void 0:e.suggestedLevel;return"rowGroup"===s||"category"===s||"subCategory"===s?s:"category"}prepareSeriesLevel(t){var e;const i=null===(e=this.seriesLevel)||void 0===e?void 0:e.trim().toLowerCase();return"none"===i?null:"rowgroup"===i?"rowGroup":"category"===i||"subCategory"===t?"category":"category"===t?"rowGroup":null}validateCrossProp(t,e){const i=new Set;let s=!1;for(const e of t){if(void 0===e)continue;const t=_(e);null!==t&&("scenario"===t.kind?i.add(R(t.slot)):s=!0)}this.setBlockingError("ERR_xy_family",i.size>1?this.t(".xy-family-mixed",{families:[...i].join(", ")}):null);const a=this.prepareCompareFamily();this.setBlockingError("ERR_xy_compare_variance",null!==a&&s?this.t(".xy-compare-variance"):null),this.setBlockingError("ERR_xy_compare_family",null!==a&&1===i.size&&i.has(a)?`compare-with: '${a}' is already the primary scenario family.`:null);const r=this.preparePointLevel(),l=this.prepareSeriesLevel(r),n=null!==e?"rowgroup"===e.level?"rowGroup":"category":null;let o=null;if(null!==l&&O[l]>=O[r]&&(o=`series '${l}' vs point '${r}'`),null!==n){const t=null!=l?l:r;O[n]>=O[t]&&(o=`facet '${n}' vs '${t}'`)}this.setBlockingError("ERR_xy_level_order",null!==o?this.t(".xy-level-order",{detail:o}):null)}parseAspect(t){const e=/^\s*(\d+(?:\.\d+)?)\s*:\s*(\d+(?:\.\d+)?)\s*$/.exec(null!=t?t:"");if(null===e)return null;const i=Number(e[1]),s=Number(e[2]);return i<=0||s<=0?null:i/s}prepareAspect(){var t;return null!==(t=this.parseAspect(this.aspect))&&void 0!==t?t:16/9}prepareLimit(){const t=Math.floor(Number(this.limit)||0);return t>0?t:0}prepareSizeAreaPerUnit(){var t;const e=null===(t=this.prepareSize())||void 0===t?void 0:t.group;if(void 0===e||!this.pixelPerUnitGroupMap.has(e))return 0;const i=this.getEffectiveScaleFactor();return this.pixelPerUnitGroupMap.get(e)*i*i}i18nLocalKeys(){return["no-data","axis.in","legend.title","legend.size","legend.compare"]}prepareI18n(){const t=new Map(this.i18nLocalKeys().map((t=>[t,this.t(".".concat(t))]))),e=new Map(n.map((t=>[t,this.t("global.".concat(t))])));return new Map([...e.entries(),...t.entries()])}prepareStyle(){const t=this.getEffectiveScaleFactor();return this.componentStyle((e=>{const i=e.global.fontSizePx*t;return{scaleFactors:e["bn-chart-bubble"].scaleFactors,fontStyles:{font:`${i}px ${e.global.fontFamily}`,size:i,color:e.global.fontColor,background:e.global.fontBackgroundColor,leading:1.8},axisStyles:e["bn-chart-bubble"].axisStyles,seriesColors:e["bn-chart-bubble"].seriesColors,padding:e["bn-chart-bubble"].padding}}))}getEffectiveScaleFactor(){const{mode:t,factor:e}=c(this.scale);return"factor"===t?e:"auto"===t||"empty"===t?this.appliedScaleFactor:1}getFontStyles(){const t=this.getEffectiveScaleFactor();return this.componentStyle((e=>{var i,s,a,r;const l=(null===(i=e.global)||void 0===i?void 0:i.fontSizePx)||13.3333;return{"--bn-font-family":(null===(s=e.global)||void 0===s?void 0:s.fontFamily)||"'Noto Sans', sans-serif","--bn-font-size":l*t+"px","--bn-font-color":(null===(a=e.global)||void 0===a?void 0:a.fontColor)||"#000000","--bn-font-background":(null===(r=e.global)||void 0===r?void 0:r.fontBackgroundColor)||"#ffffff"}}))}getDataStructure(){const t={};for(const e of["ac","pp","fc","pl"])for(const i of[1,2,3,4])t[`${e}${i}`]={type:"number",isOptional:!0,description:""};const e={x:this.prepareAxis("x",this.x),y:this.prepareAxis("y",this.y),size:this.prepareSize(),share:this.prepareShare()};for(const[i,s]of Object.entries(e)){if(null===s)continue;const e=_(s.measure);null!==e&&("scenario"===e.kind?t[e.slot].description=`${i}: ${void 0!==s.label?s.label:s.measure}`:(t[e.measure.base].description=`${i}: ${s.measure} (base)`,t[e.measure.delta].description=`${i}: ${s.measure} (delta)`))}const i=this.prepareCompareFamily();if(null!==i)for(const[s,a]of Object.entries(e)){if(null===a||"share"===s)continue;const e=_(a.measure);if(null!==e&&"scenario"===e.kind){const a=i+e.slot.replace(/^[a-z]+/,"");""===t[a].description&&(t[a].description=s+": compareWith")}}return{IBubbleChartDataRow:Object.assign({operation:{type:"string",isOptional:!1,description:""},rowGroup:{type:"string",isOptional:!0,description:""},rowGroupIndex:{type:"number",isOptional:!0,description:""},category:{type:"string",isOptional:!1,description:""},categoryIndex:{type:"number",isOptional:!1,description:""},subCategory:{type:"string",isOptional:!0,description:""},subCategoryIndex:{type:"number",isOptional:!0,description:""}},t)}}chartTemplate(){const t=this.prepareAxis("x",this.x),e=this.prepareAxis("y",this.y),i=this.prepareSize(),s=this.prepareShare(),r=this.prepareFacet();if(this.validateCrossProp([null==t?void 0:t.measure,null==e?void 0:e.measure,null==i?void 0:i.measure,null==s?void 0:s.measure],r),this.validateSizeScaling(),this.hasBlockingErrors()||null===t||null===e||null===i)return null;const l=this.preparePointLevel(),n=this.prepareI18n(),o=this.prepareStyle(),c=h(this.element).width;return a("ibcs-chart-bubble",{tableName:this.datasetName,dataVersion:this.dataVersion,chartTitle:this.chartTitle,x:t,y:e,size:i,share:s,compareFamily:this.prepareCompareFamily(),labels:this.prepareLabels(),legend:this.prepareLegend(),facet:r,pointLevel:l,seriesLevel:this.prepareSeriesLevel(l),aspect:this.prepareAspect(),limit:this.prepareLimit(),filter:this.filter,sizeAreaPerUnit:this.prepareSizeAreaPerUnit(),styles:o,i18n:n,containerWidth:c,ruleSetConfig:this.ruleSetConfig(),errors:this.errors,translate:this.translateForInner})}render(){return a(r,{key:"4191801f8d17e3241a9b681d9a7f0ab8a453bf64",style:this.getFontStyles()},a("div",{key:"a5284956b892a3647331532daae8d3251dbb6fad",class:"container"},this.chartTemplate()))}get element(){return this}static get watchers(){return{x:[{validateX:0}],y:[{validateY:0}],size:[{validateSize:0}],share:[{validateShare:0}],compareWith:[{validateCompareWith:0}],level:[{validateLevel:0}],seriesLevel:[{validateSeriesLevel:0}],facet:[{validateFacet:0}],labels:[{validateLabels:0}],legend:[{validateLegend:0}],aspect:[{validateAspect:0}],limit:[{validateLimit:0}],scale:[{validateScale:0}]}}static get style(){return":host{display:inline-block;position:relative;overflow:hidden}.container{display:flex;flex-direction:column}"}},[1,"bn-chart-bubble",{ruleset:[513],chartTitle:[1,"chart-title"],filter:[1],x:[1],y:[1],size:[1],share:[1],compareWith:[1,"compare-with"],level:[1],seriesLevel:[1,"series-level"],facet:[1],labels:[1],legend:[1],aspect:[1],limit:[2],scale:[1],datasetName:[32],dataVersion:[32],datasetMeta:[32],appliedScaleFactor:[32]},void 0,{x:[{validateX:0}],y:[{validateY:0}],size:[{validateSize:0}],share:[{validateShare:0}],compareWith:[{validateCompareWith:0}],level:[{validateLevel:0}],seriesLevel:[{validateSeriesLevel:0}],facet:[{validateFacet:0}],labels:[{validateLabels:0}],legend:[{validateLegend:0}],aspect:[{validateAspect:0}],limit:[{validateLimit:0}],scale:[{validateScale:0}]}]),k=N,F=function(){"undefined"!=typeof customElements&&["bn-chart-bubble","ibcs-chart-bubble"].forEach((t=>{switch(t){case"bn-chart-bubble":customElements.get(l(t))||customElements.define(l(t),N);break;case"ibcs-chart-bubble":customElements.get(l(t))||z()}}))};export{k as BnChartBubble,F as defineCustomElement}
|
|
1
|
+
import{proxyCustomElement as t,HTMLElement as e,writeTask as i,forceUpdate as s,h as a,Host as r,transformTag as l}from"@stencil/core/internal/client";import{a as n}from"./context-protocol.js";import{w as o,g as h}from"./withDataset.js";import{o as c}from"./layoutObserver.js";import{p as u}from"./scaling.js";import{i as d,h as p,j as v}from"./validate.js";import{w as m,a as f}from"./withHasError.js";import{w as g}from"./withComponentStyle.js";import{w as y}from"./withRuleSet.js";import{w as b}from"./withScalingGroup.js";import{w}from"./withTranslation.js";import{w as x}from"./withStyled.js";import{r as _,s as R}from"./VarianceMeasure.js";import{t as S,a as E,b as L,c as $,d as j,e as A,p as C}from"./AxisConfig.js";import{d as z}from"./ibcs-chart-bubble2.js";const O={rowGroup:0,category:1,subCategory:2},W=["ac","pp","fc","pl"],F=t(class extends e{validateX(t){this.validateMeasureSpec("x",t,!0,(t=>S(t)))}validateY(t){this.validateMeasureSpec("y",t,!0,(t=>S(t)))}validateSize(t){this.validateMeasureSpec("size",t,!0,(t=>E(t))),this.validateSizeScaling()}validateShare(t){this.validateMeasureSpec("share",t,!1,(t=>L(t)))}validateCompareWith(t){const e="ERR_compareWith";d(t)||W.includes(t.trim().toLowerCase())?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`compare-with: invalid value '${t}' — expected ${W.join("/")}; ignored.`})}validateLevel(t){const e="ERR_level",i=["auto","category","subcategory"];d(t)||i.includes(t.trim().toLowerCase())?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`level: invalid value '${t}' — expected ${i.join("/")}; using 'auto'.`})}validateSeriesLevel(t){const e="ERR_seriesLevel",i=["auto","rowgroup","category","none"];d(t)||i.includes(t.trim().toLowerCase())?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`series-level: invalid value '${t}' — expected ${i.join("/")}; using 'auto'.`})}validateFacet(t){this.validateObjectSpec("facet",t,(t=>$(t)))}validateLabels(t){this.validateObjectSpec("labels",t,(t=>j(t,this.labelDefaults())))}validateLegend(t){this.validateObjectSpec("legend",t,(t=>A(t)))}validateAspect(t){const e="ERR_aspect";d(t)||null!==this.parseAspect(t)?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`aspect: invalid value '${t}' — expected "w:h" (e.g. "16:9"); using the default.`})}validateLimit(t){const e="ERR_limit";p(t)&&Number(t)>=0?this.errors.remove(e):this.errors.addOrReplace({id:e,type:"warning",message:`limit: invalid value '${t}' — expected a non-negative integer; using 0.`})}validateScale(t){const e="ERR_scale";if(d(t))return void this.errors.remove(e);const{mode:i,factor:s}=u(t);"factor"===i&&(void 0===s||s<=0)?this.errors.addOrReplace({id:e,type:"warning",message:`scale: invalid value '${t}' — expected none/auto or a positive number.`}):this.errors.remove(e)}constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.datasetName="",this.dataVersion=0,this.datasetMeta=null,this.appliedScaleFactor=1,this.layoutObserver=null,this.activeErrors=new Set,this.pixelPerUnitGroupMap=new Map,this.chartTitle="",this.filter="",this.share="",this.compareWith="",this.level="auto",this.seriesLevel="auto",this.facet="",this.labels="",this.legend="",this.aspect="16:9",this.limit=0,this._autoScaleGuard=!1,this._lastObservedWidth=0,this.translateForInner=(t,e)=>this.t(t,e),x(this),m(this),o(this,(t=>{this.datasetName=(null==t?void 0:t.startsWith("$"))?t.substring(1):t||"",this.dataVersion=this.dataVersion+1}),((t,e)=>{this.datasetMeta=e})),this.errors=f(this),b(this),this.componentStyle=g(this),this.ruleSetConfig=y(this),this.t=w(this).t}componentWillLoad(){this.validateX(this.x),this.validateY(this.y),this.validateSize(this.size),this.validateShare(this.share),this.validateCompareWith(this.compareWith),this.validateLevel(this.level),this.validateSeriesLevel(this.seriesLevel),this.validateFacet(this.facet),this.validateLabels(this.labels),this.validateLegend(this.legend),this.validateAspect(this.aspect),this.validateLimit(this.limit),this.validateScale(this.scale)}componentDidRender(){const{mode:t}=u(this.scale);if("auto"!==t&&"empty"!==t){this._autoScaleGuard=!1;const t=h(this.element),e="WARN_overflow";return void(t.width>0&&this.element.scrollWidth>t.width+1?this.errors.addOrReplace({id:e,type:"warning",message:"Chart exceeds available space and will be cut off. Check the scale value."}):this.errors.remove(e))}if(this._autoScaleGuard)return void(this._autoScaleGuard=!1);const e=this.element,{width:s}=h(e);if(s<=0)return;this._lastObservedWidth=s;const a=this.componentStyle((t=>{var e;return(null===(e=t.global)||void 0===e?void 0:e.fontSizePx)||13.3333})),r=e.scrollWidth,l=this.appliedScaleFactor;if(!Number.isFinite(r)||r<=s+1)return void this.errors.remove("AUTO_scale");const n=Math.max(.3,l*(s-1)/r);Math.abs(n-l)<.01||(e.style.setProperty("--bn-font-size",a*n+"px"),"empty"===t?this.errors.addOrReplace({id:"AUTO_scale",type:"warning",message:"Auto-scaled chart by factor "+n.toFixed(3)}):this.errors.remove("AUTO_scale"),this._autoScaleGuard=!0,i((()=>{this.appliedScaleFactor=n})))}componentDidLoad(){this.layoutObserver=c(this.element,(()=>{if(this._autoScaleGuard)return;const{width:t}=h(this.element);t>0&&Math.abs(t-this._lastObservedWidth)>2&&(this._lastObservedWidth=t,s(this))})),requestAnimationFrame((()=>{requestAnimationFrame((()=>{if(this._autoScaleGuard)return;const{width:t}=h(this.element);this._lastObservedWidth=t,s(this)}))}))}disconnectedCallback(){var t;null===(t=this.layoutObserver)||void 0===t||t.disconnect(),this.layoutObserver=null}labelDefaults(){return{points:"all",values:!0,max:12}}setBlockingError(t,e){null===e?(this.errors.remove(t),this.activeErrors.delete(t)):(this.errors.addOrReplace({id:t,type:"error",message:e}),this.activeErrors.add(t))}hasBlockingErrors(){return this.activeErrors.size>0}validateSizeScaling(){var t;const e=null===(t=this.prepareSize())||void 0===t?void 0:t.group;this.setBlockingError("ERR_xy_scale_group",void 0===e||this.pixelPerUnitGroupMap.has(e)?null:this.t(".bubble-scale-group-unknown",{group:e}))}validateMeasureSpec(t,e,i,s){var a;const r="ERR_xy_json_"+t,l="ERR_xy_measure_"+t,n="WARN_xy_fields_"+t,{data:o,parseError:h}=C(e,"measure");if(h)return this.setBlockingError(r,this.t(".xy-prop-json",{prop:t})),this.setBlockingError(l,null),void this.errors.remove(n);if(this.setBlockingError(r,null),null===o)return this.setBlockingError(l,i?this.t(".xy-measure-invalid",{prop:t,measure:""}):null),void this.errors.remove(n);const c=null!==(a=o.measure)&&void 0!==a?a:"";v(c)?this.setBlockingError(l,null):this.setBlockingError(l,this.t(".xy-measure-invalid",{prop:t,measure:c})),this.reportSpecIssues(n,t,s(o))}validateObjectSpec(t,e,i){const s="ERR_xy_json_"+t,a="WARN_xy_fields_"+t,{data:r,parseError:l}=C(e,null);if(l)return this.setBlockingError(s,this.t(".xy-prop-json",{prop:t})),void this.errors.remove(a);this.setBlockingError(s,null),null!==r?this.reportSpecIssues(a,t,i(r)):this.errors.remove(a)}reportSpecIssues(t,e,i){const s=[];null!==i&&i.invalidFields.length>0&&s.push("invalid: "+i.invalidFields.join(", ")),null!==i&&i.unknownKeys.length>0&&s.push("unknown: "+i.unknownKeys.join(", ")),s.length>0?this.errors.addOrReplace({id:t,type:"warning",message:`${e}: ignored sub-fields (${s.join("; ")}).`}):this.errors.remove(t)}prepareAxis(t,e){const{data:i,parseError:s}=C(e,"measure");if(s||null===i)return null;const{config:a}=S(i);return null!==a&&v(a.measure)?(void 0!==a.min&&void 0!==a.max&&a.min>=a.max?(this.errors.addOrReplace({id:"WARN_xy_domain_"+t,type:"warning",message:t+": min must be smaller than max; the override is ignored."}),a.min=void 0,a.max=void 0):this.errors.remove("WARN_xy_domain_"+t),a):null}prepareSize(){const{data:t,parseError:e}=C(this.size,"measure");if(e||null===t)return null;const{config:i}=E(t);return null!==i&&v(i.measure)?i:null}prepareShare(){const{data:t,parseError:e}=C(this.share,"measure");if(e||null===t)return null;const{config:i}=L(t);return null!==i&&v(i.measure)?i:null}prepareCompareFamily(){var t;const e=null===(t=this.compareWith)||void 0===t?void 0:t.trim().toLowerCase();return W.includes(e)?e:null}prepareLabels(){const t=this.labelDefaults(),{data:e,parseError:i}=C(this.labels,null);return i||null===e?{points:t.points,values:t.values,max:t.max}:j(e,t).config}prepareLegend(){const{data:t,parseError:e}=C(this.legend,null);return e||null===t?{show:!0,position:"right"}:A(t).config}prepareFacet(){const{data:t,parseError:e}=C(this.facet,null);return e||null===t?null:$(t).config}preparePointLevel(){var t,e;const i=null===(t=this.level)||void 0===t?void 0:t.trim().toLowerCase();if("category"===i)return"category";if("subcategory"===i)return"subCategory";const s=null===(e=this.datasetMeta)||void 0===e?void 0:e.suggestedLevel;return"rowGroup"===s||"category"===s||"subCategory"===s?s:"category"}prepareSeriesLevel(t){var e;const i=null===(e=this.seriesLevel)||void 0===e?void 0:e.trim().toLowerCase();return"none"===i?null:"rowgroup"===i?"rowGroup":"category"===i||"subCategory"===t?"category":"category"===t?"rowGroup":null}validateCrossProp(t,e){const i=new Set;let s=!1;for(const e of t){if(void 0===e)continue;const t=_(e);null!==t&&("scenario"===t.kind?i.add(R(t.slot)):s=!0)}this.setBlockingError("ERR_xy_family",i.size>1?this.t(".xy-family-mixed",{families:[...i].join(", ")}):null);const a=this.prepareCompareFamily();this.setBlockingError("ERR_xy_compare_variance",null!==a&&s?this.t(".xy-compare-variance"):null),this.setBlockingError("ERR_xy_compare_family",null!==a&&1===i.size&&i.has(a)?`compare-with: '${a}' is already the primary scenario family.`:null);const r=this.preparePointLevel(),l=this.prepareSeriesLevel(r),n=null!==e?"rowgroup"===e.level?"rowGroup":"category":null;let o=null;if(null!==l&&O[l]>=O[r]&&(o=`series '${l}' vs point '${r}'`),null!==n){const t=null!=l?l:r;O[n]>=O[t]&&(o=`facet '${n}' vs '${t}'`)}this.setBlockingError("ERR_xy_level_order",null!==o?this.t(".xy-level-order",{detail:o}):null)}parseAspect(t){const e=/^\s*(\d+(?:\.\d+)?)\s*:\s*(\d+(?:\.\d+)?)\s*$/.exec(null!=t?t:"");if(null===e)return null;const i=Number(e[1]),s=Number(e[2]);return i<=0||s<=0?null:i/s}prepareAspect(){var t;return null!==(t=this.parseAspect(this.aspect))&&void 0!==t?t:16/9}prepareLimit(){const t=Math.floor(Number(this.limit)||0);return t>0?t:0}prepareSizeAreaPerUnit(){var t;const e=null===(t=this.prepareSize())||void 0===t?void 0:t.group;if(void 0===e||!this.pixelPerUnitGroupMap.has(e))return 0;const i=this.pixelPerUnitGroupMap.get(e);if(!(i>0))return 0;const s=this.getEffectiveFontPx();return s*s/i}i18nLocalKeys(){return["no-data","axis.in","legend.title","legend.size","legend.compare"]}prepareI18n(){const t=new Map(this.i18nLocalKeys().map((t=>[t,this.t(".".concat(t))]))),e=new Map(n.map((t=>[t,this.t("global.".concat(t))])));return new Map([...e.entries(),...t.entries()])}prepareStyle(){const t=this.getEffectiveScaleFactor();return this.componentStyle((e=>{const i=e.global.fontSizePx*t;return{scaleFactors:e["bn-chart-bubble"].scaleFactors,fontStyles:{font:`${i}px ${e.global.fontFamily}`,size:i,color:e.global.fontColor,background:e.global.fontBackgroundColor,leading:1.8},axisStyles:e["bn-chart-bubble"].axisStyles,seriesColors:e["bn-chart-bubble"].seriesColors,padding:e["bn-chart-bubble"].padding}}))}getEffectiveScaleFactor(){const{mode:t,factor:e}=u(this.scale);return"factor"===t?e:"auto"===t||"empty"===t?this.appliedScaleFactor:1}getEffectiveFontPx(){return this.componentStyle((t=>{var e;return(null===(e=t.global)||void 0===e?void 0:e.fontSizePx)||13.3333}))*this.getEffectiveScaleFactor()}getFontStyles(){const t=this.getEffectiveScaleFactor();return this.componentStyle((e=>{var i,s,a,r;const l=(null===(i=e.global)||void 0===i?void 0:i.fontSizePx)||13.3333;return{"--bn-font-family":(null===(s=e.global)||void 0===s?void 0:s.fontFamily)||"'Noto Sans', sans-serif","--bn-font-size":l*t+"px","--bn-font-color":(null===(a=e.global)||void 0===a?void 0:a.fontColor)||"#000000","--bn-font-background":(null===(r=e.global)||void 0===r?void 0:r.fontBackgroundColor)||"#ffffff"}}))}getDataStructure(){const t={};for(const e of["ac","pp","fc","pl"])for(const i of[1,2,3,4])t[`${e}${i}`]={type:"number",isOptional:!0,description:""};const e={x:this.prepareAxis("x",this.x),y:this.prepareAxis("y",this.y),size:this.prepareSize(),share:this.prepareShare()};for(const[i,s]of Object.entries(e)){if(null===s)continue;const e=_(s.measure);null!==e&&("scenario"===e.kind?t[e.slot].description=`${i}: ${void 0!==s.label?s.label:s.measure}`:(t[e.measure.base].description=`${i}: ${s.measure} (base)`,t[e.measure.delta].description=`${i}: ${s.measure} (delta)`))}const i=this.prepareCompareFamily();if(null!==i)for(const[s,a]of Object.entries(e)){if(null===a||"share"===s)continue;const e=_(a.measure);if(null!==e&&"scenario"===e.kind){const a=i+e.slot.replace(/^[a-z]+/,"");""===t[a].description&&(t[a].description=s+": compareWith")}}return{IBubbleChartDataRow:Object.assign({operation:{type:"string",isOptional:!1,description:""},rowGroup:{type:"string",isOptional:!0,description:""},rowGroupIndex:{type:"number",isOptional:!0,description:""},category:{type:"string",isOptional:!1,description:""},categoryIndex:{type:"number",isOptional:!1,description:""},subCategory:{type:"string",isOptional:!0,description:""},subCategoryIndex:{type:"number",isOptional:!0,description:""}},t)}}chartTemplate(){const t=this.prepareAxis("x",this.x),e=this.prepareAxis("y",this.y),i=this.prepareSize(),s=this.prepareShare(),r=this.prepareFacet();if(this.validateCrossProp([null==t?void 0:t.measure,null==e?void 0:e.measure,null==i?void 0:i.measure,null==s?void 0:s.measure],r),this.validateSizeScaling(),this.hasBlockingErrors()||null===t||null===e||null===i)return null;const l=this.preparePointLevel(),n=this.prepareI18n(),o=this.prepareStyle(),c=h(this.element).width;return a("ibcs-chart-bubble",{tableName:this.datasetName,dataVersion:this.dataVersion,chartTitle:this.chartTitle,x:t,y:e,size:i,share:s,compareFamily:this.prepareCompareFamily(),labels:this.prepareLabels(),legend:this.prepareLegend(),facet:r,pointLevel:l,seriesLevel:this.prepareSeriesLevel(l),aspect:this.prepareAspect(),limit:this.prepareLimit(),filter:this.filter,sizeAreaPerUnit:this.prepareSizeAreaPerUnit(),styles:o,i18n:n,containerWidth:c,ruleSetConfig:this.ruleSetConfig(),errors:this.errors,translate:this.translateForInner})}render(){return a(r,{key:"24a71177722409772ddf8e68df747d821173bd6d",style:this.getFontStyles()},a("div",{key:"8f36775425c700dc10e2901a964f6c1e23f524be",class:"container"},this.chartTemplate()))}get element(){return this}static get watchers(){return{x:[{validateX:0}],y:[{validateY:0}],size:[{validateSize:0}],share:[{validateShare:0}],compareWith:[{validateCompareWith:0}],level:[{validateLevel:0}],seriesLevel:[{validateSeriesLevel:0}],facet:[{validateFacet:0}],labels:[{validateLabels:0}],legend:[{validateLegend:0}],aspect:[{validateAspect:0}],limit:[{validateLimit:0}],scale:[{validateScale:0}]}}static get style(){return":host{display:inline-block;position:relative;overflow:hidden}.container{display:flex;flex-direction:column}"}},[1,"bn-chart-bubble",{ruleset:[513],chartTitle:[1,"chart-title"],filter:[1],x:[1],y:[1],size:[1],share:[1],compareWith:[1,"compare-with"],level:[1],seriesLevel:[1,"series-level"],facet:[1],labels:[1],legend:[1],aspect:[1],limit:[2],scale:[1],datasetName:[32],dataVersion:[32],datasetMeta:[32],appliedScaleFactor:[32]},void 0,{x:[{validateX:0}],y:[{validateY:0}],size:[{validateSize:0}],share:[{validateShare:0}],compareWith:[{validateCompareWith:0}],level:[{validateLevel:0}],seriesLevel:[{validateSeriesLevel:0}],facet:[{validateFacet:0}],labels:[{validateLabels:0}],legend:[{validateLegend:0}],aspect:[{validateAspect:0}],limit:[{validateLimit:0}],scale:[{validateScale:0}]}]),N=F,k=function(){"undefined"!=typeof customElements&&["bn-chart-bubble","ibcs-chart-bubble"].forEach((t=>{switch(t){case"bn-chart-bubble":customElements.get(l(t))||customElements.define(l(t),F);break;case"ibcs-chart-bubble":customElements.get(l(t))||z()}}))};export{N as BnChartBubble,k as defineCustomElement}
|