@bino-bi/bn-template-engine 1.0.0-next.39 → 1.0.0-next.40
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-9a61f59d.entry.js → p-8b28c9bd.entry.js} +1 -1
- package/dist/bn-template-engine/{p-DyupX-Z-.js → p-BjozxTTW.js} +1 -1
- package/dist/bn-template-engine/p-EcC0qLtU.js +1 -0
- package/dist/bn-template-engine/{p-eea538f1.entry.js → p-a4b76176.entry.js} +1 -1
- package/dist/bn-template-engine/p-aa0fd797.entry.js +1 -0
- package/dist/bn-template-engine/{p-93b8387f.entry.js → p-ce764078.entry.js} +1 -1
- package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +785 -378
- 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-DfE0aW7D.js → withStyled-BZb6snOx.js} +74 -0
- package/dist/cjs/{withTranslation-0gkn9xoC.js → withTranslation-FxXGUB3H.js} +1 -1
- package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +4 -1
- package/dist/collection/components/bn-chart-structure/utils/elements/Label.js +3 -1
- package/dist/collection/components/bn-chart-time/utils/elements/Label.js +3 -1
- package/dist/collection/components/bn-table/bn-table-renderer/bn-table-renderer.css +22 -1
- package/dist/collection/components/bn-table/bn-table-renderer/bn-table-renderer.js +156 -11
- package/dist/collection/components/bn-table/bn-table.js +134 -5
- package/dist/collection/components/bn-table/utils/elements/Cell.js +10 -1
- package/dist/collection/components/bn-table/utils/elements/CellBarChart.js +25 -10
- package/dist/collection/components/bn-table/utils/elements/WaterfallBar.js +50 -12
- package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +44 -14
- package/dist/collection/components/bn-table/utils/helper/DataQuery.js +63 -2
- package/dist/collection/components/bn-table/utils/helper/WaterfallCalculator.js +123 -11
- package/dist/collection/components/bn-table/utils/helper/barColumnGeometry.js +57 -9
- package/dist/collection/components/bn-table/utils/model/TableComponentConfig.js +16 -1
- package/dist/collection/components/bn-table/utils/model/index.js +6 -0
- package/dist/collection/utils/validate.js +4 -0
- 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.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-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.js +1 -1
- package/dist/components/bn-tree.js +1 -1
- package/dist/components/p-1B_s8oPY.js +1 -0
- package/dist/components/{p-BqUB56k1.js → p-B4L069XF.js} +1 -1
- package/dist/components/p-BC4MwlnX.js +1 -0
- package/dist/components/p-BZXiWkDS.js +1 -0
- package/dist/components/p-BiSytXUy.js +1 -0
- package/dist/components/p-Bn7J1pgl.js +1 -0
- package/dist/components/{p-BmOWXYHF.js → p-CEf5X8MZ.js} +1 -1
- package/dist/components/{p-Cyf5ZEXs.js → p-CUSAlS2o.js} +1 -1
- package/dist/components/p-CvEdUq8i.js +1 -0
- package/dist/components/{p-OquycEMA.js → p-D40Am1Ap.js} +1 -1
- package/dist/components/{p-B4Cf0cVi.js → p-DM4Up10X.js} +1 -1
- package/dist/components/{p-Bo_R7f_T.js → p-DwuXVo2h.js} +1 -1
- package/dist/components/{p-DTmqMQpw.js → p-Y9bth2Y_.js} +1 -1
- package/dist/components/{p-BU_53KVT.js → p-xIWChKGS.js} +1 -1
- package/dist/esm/bn-annotation-layer_30.entry.js +903 -496
- 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-CIoJ86RM.js → withStyled-CzzXg64f.js} +77 -4
- package/dist/esm/{withTranslation-BX9T3dfm.js → withTranslation-Daq2JXkv.js} +1 -1
- package/dist/types/components/bn-table/bn-table-renderer/bn-table-renderer.d.ts +20 -1
- package/dist/types/components/bn-table/bn-table.d.ts +49 -1
- package/dist/types/components/bn-table/utils/elements/Cell.d.ts +3 -0
- package/dist/types/components/bn-table/utils/elements/CellBarChart.d.ts +26 -0
- package/dist/types/components/bn-table/utils/elements/WaterfallBar.d.ts +22 -2
- package/dist/types/components/bn-table/utils/helper/DataQuery.d.ts +13 -0
- package/dist/types/components/bn-table/utils/helper/WaterfallCalculator.d.ts +30 -2
- package/dist/types/components/bn-table/utils/helper/barColumnGeometry.d.ts +24 -4
- package/dist/types/components/bn-table/utils/model/TableComponentConfig.d.ts +7 -1
- package/dist/types/components/bn-table/utils/model/index.d.ts +5 -0
- package/dist/types/components.d.ts +49 -4
- package/dist/types/utils/validate.d.ts +1 -0
- package/package.json +1 -1
- package/dist/bn-template-engine/p-8c84d57e.entry.js +0 -1
- package/dist/bn-template-engine/p-BVU4bIsi.js +0 -1
- package/dist/components/p-BsJOvfIg.js +0 -1
- package/dist/components/p-DCPLGEs_.js +0 -1
- package/dist/components/p-DT04Cka0.js +0 -1
- package/dist/components/p-Dm6EAaJ9.js +0 -1
- package/dist/components/p-dRPJiQB6.js +0 -1
- package/dist/components/p-tkB96Ena.js +0 -1
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { h } from "@stencil/core";
|
|
2
|
-
import { AXIS_COLOR, DEFAULT_STYLES, formatValue, getBarFill, getBarStroke, getBarStyle, getScenarioType, PatternDefs, } from "./CellBarChart";
|
|
3
|
-
import { waterfallGeometry } from "../helper/barColumnGeometry";
|
|
2
|
+
import { AXIS_COLOR, DEFAULT_STYLES, formatValue, getBarFill, getBarStroke, getBarStyle, getScenarioType, getVarianceLook, PatternDefs, VarianceAxis, } from "./CellBarChart";
|
|
3
|
+
import { labelWidth, VARIANCE_AXIS_EM, waterfallGeometry } from "../helper/barColumnGeometry";
|
|
4
|
+
/**
|
|
5
|
+
* Label text of a waterfall bar. Scenario values carry no variance sentiment: unsigned per
|
|
6
|
+
* IBCS. A variance keeps its sign (`signed`).
|
|
7
|
+
*/
|
|
8
|
+
export function waterfallLabelText(value, kind, measureScale, locale, decimalDigits, signed = false) {
|
|
9
|
+
const text = formatValue(value, kind === "partof", measureScale, locale, 0, true, decimalDigits);
|
|
10
|
+
return signed ? text : text.replace(/^\+/, "");
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* Renders one row of an IBCS waterfall for a scenario bar column.
|
|
6
14
|
*
|
|
@@ -13,19 +21,27 @@ import { waterfallGeometry } from "../helper/barColumnGeometry";
|
|
|
13
21
|
* Layout: [left label area][bar area][right label area]
|
|
14
22
|
* The value label sits at the bar's free end (right of rightward bars,
|
|
15
23
|
* left of leftward bars). thereof/partof rows additionally get dashed
|
|
16
|
-
* guides marking their parent bar's extent.
|
|
24
|
+
* guides marking their parent bar's extent. A guide or axis line that would
|
|
25
|
+
* run through the label is left out in that row.
|
|
26
|
+
*
|
|
27
|
+
* An absolute variance column is drawn as a variance waterfall: the bar in the color of
|
|
28
|
+
* the sentiment and the pattern of the minuend, the axis in the look of the reference
|
|
29
|
+
* scenario in every row, a signed label, and thin connectors to the rows above and below
|
|
30
|
+
* in place of the dashed guides. The axis and the connectors join the rows, so where one
|
|
31
|
+
* meets the label it is only interrupted over the height of the text.
|
|
17
32
|
*/
|
|
18
33
|
export const WaterfallBar = (props) => {
|
|
19
|
-
|
|
34
|
+
var _a;
|
|
35
|
+
const { value, scenario, height, isPositiveGood, measureScale, locale, decimalDigits, columnWidthEm = 10, styles = DEFAULT_STYLES, waterfall, geometry, bold, connectorReach = { top: 0, bottom: 0 }, } = props;
|
|
20
36
|
const s = styles.scaleFactor;
|
|
21
37
|
const fs = styles.fontSize;
|
|
22
38
|
const range = waterfall.max - waterfall.min;
|
|
23
39
|
if (value === null || value === undefined || isNaN(value) || range <= 0) {
|
|
24
40
|
return (h("span", { class: "bar-chart-empty", style: { color: styles.fontColor, fontStyle: "italic" } }, "-"));
|
|
25
41
|
}
|
|
26
|
-
const { totalWidth,
|
|
42
|
+
const { totalWidth, labelAreaLeft, barAreaWidth, labelGap } = geometry !== null && geometry !== void 0 ? geometry : waterfallGeometry(columnWidthEm, styles.emPx);
|
|
27
43
|
const pxPerUnit = barAreaWidth / range;
|
|
28
|
-
const xOf = (coordinate) =>
|
|
44
|
+
const xOf = (coordinate) => labelAreaLeft + (coordinate - waterfall.min) * pxPerUnit;
|
|
29
45
|
const padding = 2 * s;
|
|
30
46
|
const barHeight = height - padding * 2;
|
|
31
47
|
const barY = padding;
|
|
@@ -34,13 +50,35 @@ export const WaterfallBar = (props) => {
|
|
|
34
50
|
const endX = xOf(waterfall.end);
|
|
35
51
|
const barX = Math.min(startX, endX);
|
|
36
52
|
const barWidth = Math.abs(endX - startX);
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const
|
|
53
|
+
// null for a scenario column, which ignores the sentiment
|
|
54
|
+
const look = getVarianceLook(scenario, styles);
|
|
55
|
+
const sentimentStyle = getBarStyle(scenario, value, isPositiveGood, styles);
|
|
56
|
+
const minuendPattern = look === null || look === void 0 ? void 0 : look.minuend.fillpattern;
|
|
57
|
+
const barStyle = minuendPattern === "hatched" || minuendPattern === "outlined"
|
|
58
|
+
? Object.assign(Object.assign({}, sentimentStyle), { fillpattern: minuendPattern }) : sentimentStyle;
|
|
59
|
+
const patternPrefix = look ? (sentimentStyle === styles.positive ? "pos" : "neg") : getScenarioType(scenario);
|
|
60
|
+
const fillValue = getBarFill(barStyle, patternPrefix);
|
|
61
|
+
const { stroke: barStroke, strokeWidth: barStrokeWidth } = look && barStyle.fillpattern === "hatched" ? { stroke: barStyle.stroke, strokeWidth: 1 } : getBarStroke(barStyle);
|
|
62
|
+
const displayValue = waterfallLabelText(value, waterfall.kind, measureScale, locale, decimalDigits, look !== null);
|
|
42
63
|
const pointsLeft = endX < startX;
|
|
43
64
|
const labelX = pointsLeft ? barX - labelGap : barX + barWidth + labelGap;
|
|
44
65
|
const labelAnchor = pointsLeft ? "end" : "start";
|
|
45
|
-
|
|
66
|
+
// a line through the label makes it unreadable, so the row drops it
|
|
67
|
+
const labelSize = labelWidth(displayValue, fs, styles.fontFamily, false, bold);
|
|
68
|
+
const labelPad = labelGap / 2;
|
|
69
|
+
const labelFrom = (pointsLeft ? labelX - labelSize : labelX) - labelPad;
|
|
70
|
+
const labelTo = (pointsLeft ? labelX : labelX + labelSize) + labelPad;
|
|
71
|
+
const meetsLabel = (x) => x > labelFrom && x < labelTo;
|
|
72
|
+
const parentEndX = waterfall.parentEnd !== undefined ? xOf(waterfall.parentEnd) : undefined;
|
|
73
|
+
// the parts of a vertical line of a variance waterfall that stay clear of the label text
|
|
74
|
+
const labelTop = height / 2 - fs / 2;
|
|
75
|
+
const labelBottom = height / 2 + fs / 2;
|
|
76
|
+
const clearOfLabel = (x, y1, y2, halfWidth = 0) => x + halfWidth > labelFrom && x - halfWidth < labelTo
|
|
77
|
+
? [[y1, Math.min(y2, labelTop)], [Math.max(y1, labelBottom), y2]].filter(([from, to]) => to > from)
|
|
78
|
+
: [[y1, y2]];
|
|
79
|
+
const axisTop = -connectorReach.top;
|
|
80
|
+
const axisBottom = height + connectorReach.bottom;
|
|
81
|
+
return (h("svg", { width: totalWidth, height: height, class: `cell-bar-chart waterfall-bar${look ? " variance-waterfall" : ""}`, style: { overflow: "visible" } }, h(PatternDefs, { styles: styles }), !look && !meetsLabel(axisX) && (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 && parentEndX !== undefined && !meetsLabel(parentEndX) && (h("line", { x1: parentEndX, y1: 0, x2: parentEndX, y2: height, stroke: AXIS_COLOR, "stroke-width": 1 * s, "stroke-dasharray": `${2 * s},${2 * s}` })), (_a = waterfall.connectors) === null || _a === void 0 ? void 0 :
|
|
82
|
+
_a.map(({ at, part }) => clearOfLabel(xOf(at), part === "bottom" ? barY + barHeight : axisTop, part === "top" ? barY : axisBottom).map(([y1, y2]) => (h("line", { class: "waterfall-connector", x1: xOf(at), y1: y1, x2: xOf(at), y2: y2, stroke: AXIS_COLOR, "stroke-width": 1 * s })))), barWidth > 0 && (h("rect", { x: barX, y: barY, width: barWidth, height: barHeight, fill: fillValue, stroke: barStroke, "stroke-width": barStrokeWidth * s })), look &&
|
|
83
|
+
clearOfLabel(axisX, axisTop, axisBottom, (VARIANCE_AXIS_EM * styles.emPx) / 2).map(([y1, y2]) => (h("g", { transform: `translate(0,${y1})` }, h(VarianceAxis, { x: axisX, height: y2 - y1, look: look, styles: styles })))), h("text", { x: labelX, y: height / 2, dy: "0.35em", "text-anchor": labelAnchor, fill: styles.fontColor, "font-size": fs, "font-family": styles.fontFamily }, displayValue)));
|
|
46
84
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TableRow } from "../elements";
|
|
2
|
-
import { TableRowType, TableType } from "../model";
|
|
2
|
+
import { TableRowType, TableType, ThereofPosition } from "../model";
|
|
3
3
|
import { BLANK_BUCKET_LABEL, computeWaterfall, DataQuery, hasGroupingStructure, INTERVAL_NONE, isDateInterval, } from "../helper";
|
|
4
4
|
import { Formatter } from "../../../../utils";
|
|
5
5
|
import { I18nMode, DataFormat, Scenarios } from "../../../../utils/constants";
|
|
@@ -174,20 +174,24 @@ export class TableDataSetFactory {
|
|
|
174
174
|
this.hasBlankRowGroup = dataQuery.hasBlankRowGroup;
|
|
175
175
|
// Calculate column statistics for bar columns
|
|
176
176
|
const columnStatsMap = this.calculateColumnStatistics(queryData, config.barColumns, config.interval !== INTERVAL_NONE);
|
|
177
|
-
// Scenario bar columns render as a waterfall when grouping structure is present
|
|
177
|
+
// Scenario bar columns render as a waterfall when grouping structure is present,
|
|
178
|
+
// absolute variance bar columns when varianceWaterfall is set;
|
|
178
179
|
// interval/columnthereof composite columns are excluded and render as today
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
hasGroupingStructure(queryData)
|
|
184
|
-
?
|
|
180
|
+
const thereOfAbove = config.thereOfPosition === ThereofPosition.ABOVE;
|
|
181
|
+
const barColumns = (_a = config.barColumns) !== null && _a !== void 0 ? _a : [];
|
|
182
|
+
const scenarioColumns = barColumns.filter((column) => column.toUpperCase().trim() in Scenarios);
|
|
183
|
+
const waterfallColumns = [
|
|
184
|
+
...(scenarioColumns.length > 0 && hasGroupingStructure(queryData) ? scenarioColumns : []),
|
|
185
|
+
...(config.varianceWaterfall ? barColumns.filter((column) => new VarianceScenario(column).type === "d") : []),
|
|
186
|
+
];
|
|
187
|
+
const waterfallResult = waterfallColumns.length > 0 && config.interval === INTERVAL_NONE && config.categoryThereOf.size === 0
|
|
188
|
+
? computeWaterfall(queryData, waterfallColumns, config.type, dataQuery.hasRunningSum(), thereOfAbove)
|
|
185
189
|
: undefined;
|
|
186
190
|
for (const groupData of queryData) {
|
|
187
191
|
// groupData is a collection of dataRows, each group base on a query and represents a 'row' group
|
|
188
192
|
iGroupIndex += 1;
|
|
189
193
|
const iRowIndex = -1;
|
|
190
|
-
bodyRows.push(...this.createRow(config.i18n, i18n, config.scenariosUnitType, groupData, iGroupIndex, iRowIndex, config.categoryWidth, config.measureScale, config.barColumns, columnStatsMap, waterfallResult));
|
|
194
|
+
bodyRows.push(...this.createRow(config.i18n, i18n, config.scenariosUnitType, groupData, iGroupIndex, iRowIndex, config.categoryWidth, config.measureScale, config.barColumns, columnStatsMap, waterfallResult, thereOfAbove));
|
|
191
195
|
}
|
|
192
196
|
return bodyRows;
|
|
193
197
|
}
|
|
@@ -298,9 +302,12 @@ export class TableDataSetFactory {
|
|
|
298
302
|
* @param barColumns
|
|
299
303
|
* @param columnStatsMap
|
|
300
304
|
*/
|
|
301
|
-
createRow(i18nMode, i18n, scenariosUnitType, groupData, iGroupIndex, iRowIndex, categoryWidth, measureScale, barColumns, columnStatsMap, waterfallResult) {
|
|
305
|
+
createRow(i18nMode, i18n, scenariosUnitType, groupData, iGroupIndex, iRowIndex, categoryWidth, measureScale, barColumns, columnStatsMap, waterfallResult, thereOfAbove = false) {
|
|
302
306
|
var _a, _b, _c;
|
|
303
307
|
const result = [];
|
|
308
|
+
// the last entry row and its index in result: the parent of the thereof rows that follow it
|
|
309
|
+
let parentIndex = -1;
|
|
310
|
+
let parent;
|
|
304
311
|
// thereof and partof rows have no operation, they take the one of the row above
|
|
305
312
|
let operation;
|
|
306
313
|
for (const rawDataRow of groupData) {
|
|
@@ -312,20 +319,31 @@ export class TableDataSetFactory {
|
|
|
312
319
|
const type = rawDataRow[QueryColumnNames.TYPE];
|
|
313
320
|
const isSecondElement = rawDataRow[QueryColumnNames.ROWNR] >= 2;
|
|
314
321
|
operation = ((_b = (_a = rawDataRow.operation) !== null && _a !== void 0 ? _a : rawDataRow.restOperation) !== null && _b !== void 0 ? _b : operation);
|
|
322
|
+
// a thereof row moves above the entry row before it only when that row is its parent
|
|
323
|
+
const moved = thereOfAbove &&
|
|
324
|
+
type === TableRowType.DRILLELEMENT &&
|
|
325
|
+
parent !== undefined &&
|
|
326
|
+
parent[QueryColumnNames.CATEGORY] === rawDataRow[QueryColumnNames.CATEGORY] &&
|
|
327
|
+
(parent[QueryColumnNames.ROWGROUP] === "NO_GROUP" || parent[QueryColumnNames.ROWGROUP] === rowGroup);
|
|
315
328
|
const detailsRow = this.createDetailRow(type, iRowIndex, iGroupIndex, groupData.length);
|
|
316
329
|
detailsRow.key = this.rowKey(rawDataRow);
|
|
317
330
|
for (const scenario of this.normalizedHeader) {
|
|
318
331
|
const value = this.getRawDataRowElement(rawDataRow, scenario);
|
|
319
|
-
const
|
|
320
|
-
const columnStats = isBarChart ? columnStatsMap === null || columnStatsMap === void 0 ? void 0 : columnStatsMap.get(scenario.type) : undefined;
|
|
332
|
+
const isBarColumn = (_c = barColumns === null || barColumns === void 0 ? void 0 : barColumns.includes(scenario.type)) !== null && _c !== void 0 ? _c : false;
|
|
321
333
|
// waterfall geometry only exists for plain scenario columns (no ## composites)
|
|
322
|
-
const waterfall =
|
|
334
|
+
const waterfall = isBarColumn &&
|
|
323
335
|
scenario.bucket === undefined &&
|
|
324
336
|
scenario.name === scenario.group &&
|
|
325
337
|
scenario.name === scenario.type
|
|
326
338
|
? waterfallResult === null || waterfallResult === void 0 ? void 0 : waterfallResult.get(rawDataRow, scenario.type)
|
|
327
339
|
: undefined;
|
|
328
|
-
|
|
340
|
+
// a share of a variance has no place in the walk of a variance waterfall: the row prints the number
|
|
341
|
+
const isBarChart = isBarColumn &&
|
|
342
|
+
!(type === TableRowType.PARTELEMENT &&
|
|
343
|
+
new VarianceScenario(scenario.type).isValid &&
|
|
344
|
+
(waterfallResult === null || waterfallResult === void 0 ? void 0 : waterfallResult.has(scenario.type)));
|
|
345
|
+
const columnStats = isBarChart ? columnStatsMap === null || columnStatsMap === void 0 ? void 0 : columnStatsMap.get(scenario.type) : undefined;
|
|
346
|
+
detailsRow.createElement(this.translateSumCellLabel(i18nMode, i18n, value, groupName, subCategory, type, scenario.type), scenario.type, this.createColumnType(scenario), this.setCellType(scenario.type, scenariosUnitType), moved ? null : this.translateCellPrefix(i18n, type, scenario.type), this.translateScenarioCSS(scenario.type, value, operation), isSecondElement, categoryWidth, measureScale === null || measureScale === void 0 ? void 0 : measureScale.value, isBarChart, columnStats, 1, waterfall);
|
|
329
347
|
const cell = detailsRow.elements[detailsRow.elements.length - 1];
|
|
330
348
|
if (this.dateBuckets && scenario.bucket !== undefined) {
|
|
331
349
|
cell.date = pointDate(scenario.bucket);
|
|
@@ -335,6 +353,18 @@ export class TableDataSetFactory {
|
|
|
335
353
|
cell.direction = this.resolveDirection(varianceScenario, operation);
|
|
336
354
|
}
|
|
337
355
|
}
|
|
356
|
+
// moved only here: the operation above and the waterfall geometry both rely on the parent coming first
|
|
357
|
+
if (moved) {
|
|
358
|
+
detailsRow.cssStyle = "ofit-above";
|
|
359
|
+
result[parentIndex].cssStyle = "ofit-sum";
|
|
360
|
+
result.splice(parentIndex, 0, detailsRow);
|
|
361
|
+
parentIndex += 1;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (type === TableRowType.ENTRY) {
|
|
365
|
+
parentIndex = result.length;
|
|
366
|
+
parent = rawDataRow;
|
|
367
|
+
}
|
|
338
368
|
result.push(detailsRow);
|
|
339
369
|
}
|
|
340
370
|
return result;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { OrderDirection, TableType } from "../model";
|
|
2
2
|
import { BLANK_SAFE_ROWGROUP, QueryGroups } from "./QueryGroup";
|
|
3
|
+
import { restSignedAlias } from "./WaterfallCalculator";
|
|
3
4
|
import { BLANK_BUCKET_LABEL, coerceBucketKey, INTERVAL_NONE, INTERVAL_SETNAME, intervalBucketSQL, } from "./IntervalColumns";
|
|
4
5
|
import { FIELD_IDENTIFIER_REGEX } from "../model/TableAttribute";
|
|
5
6
|
import { parseOrderToken } from "../../../../utils/model/Order";
|
|
6
7
|
import { Scenarios } from "../../../../utils/constants";
|
|
7
8
|
import { QueryColumnNames, VarianceScenario } from "../../../../utils/model";
|
|
8
9
|
import { NOT_AVAILABLE, relativeVariance } from "../../../../utils/relativeVariance";
|
|
10
|
+
/** Adds a group sum to a running result; it stays missing as long as no group had a value. */
|
|
11
|
+
function addGroupSum(running, value) {
|
|
12
|
+
return running == null && value == null ? value : (running !== null && running !== void 0 ? running : 0) + (value !== null && value !== void 0 ? value : 0);
|
|
13
|
+
}
|
|
9
14
|
/**
|
|
10
15
|
* AlaSQL-based query builder that produces the complete table result set for bn-table.
|
|
11
16
|
*
|
|
@@ -121,6 +126,9 @@ export class DataQuery {
|
|
|
121
126
|
this.createTotalSumRow(queries, sumGroupQueries, scenariosSUMQuery);
|
|
122
127
|
// executes main queries
|
|
123
128
|
queries.forEach((query) => res.push(this.exec(query)));
|
|
129
|
+
if (this.hasRunningSum()) {
|
|
130
|
+
this.accumulateGroupSums(res, [...new Set(this.exctractScenarioNames(scenariosSUMQuery))]);
|
|
131
|
+
}
|
|
124
132
|
this.detectNaNCells(this.config.scenarios, res);
|
|
125
133
|
this.createThereOfDrillRows(scenarios, attributesSQL, order, res);
|
|
126
134
|
this.createPartOfDrillRows(scenarios, order, sumGroupQueries, res);
|
|
@@ -211,8 +219,13 @@ export class DataQuery {
|
|
|
211
219
|
.map((name) => `SUM(${name}) as ${name}`)
|
|
212
220
|
.join(", ");
|
|
213
221
|
// a REST row of only "-" rows counts as "-" for the op sentiment; not named operation, so it stays hidden
|
|
222
|
+
// the row prints the unsigned sum; the walk of a waterfall needs the signed sum of its bar columns
|
|
223
|
+
const restSigned = this.exctractScenarioNames(scenarios)
|
|
224
|
+
.filter((name) => { var _a; return (_a = this.config.barColumns) === null || _a === void 0 ? void 0 : _a.includes(name); })
|
|
225
|
+
.map((name) => `, SUM(${name} * transformOperator(operation)) as ${restSignedAlias(name)}`)
|
|
226
|
+
.join("");
|
|
214
227
|
const restOperation = TableType.OPT === this.config.type || TableType.OPTNOTOTAL === this.config.type
|
|
215
|
-
? `, CASE WHEN MAX(transformOperator(operation)) = -1 THEN '-' ELSE '+' END as restOperation`
|
|
228
|
+
? `, CASE WHEN MAX(transformOperator(operation)) = -1 THEN '-' ELSE '+' END as restOperation${restSigned}`
|
|
216
229
|
: "";
|
|
217
230
|
querys.push(`SELECT ${QueryColumnNames.ROWNR}, 1 as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, 'NO_GROUP' as ${QueryColumnNames.ROWGROUP}, ${this.bind(String((_a = rowGroupEntry.rowGroup) !== null && _a !== void 0 ? _a : ""))} as restRowGroup, 'REST' as ${QueryColumnNames.CATEGORY}${restOperation} ${restScenarios.length > 0 ? ", " + restScenarios : ""} FROM` +
|
|
218
231
|
` (SELECT ROWNUM() AS ${QueryColumnNames.ROWNR}, ${querys.length} as ${QueryColumnNames.ROWGROUPINDEX} , 'ENTRY' as ${QueryColumnNames.TYPE}, ${this.bind(String(rowGroupEntry.rowGroup || "NO_GROUP"))} as ${QueryColumnNames.ROWGROUP}, ${groups.select()} ${scenarios.length > 0 ? ",".concat(scenarios) : ""}${this.sortSelect} FROM ${this.fromExpr} ${queryWhereSection} GROUP BY ${groups} ORDER BY ${order[0]})` +
|
|
@@ -254,6 +267,34 @@ export class DataQuery {
|
|
|
254
267
|
TableType.OPT === this.config.type ||
|
|
255
268
|
TableType.OPTNOTOTAL === this.config.type);
|
|
256
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* True when the group sum rows are running results: only a grouped table with group sum
|
|
272
|
+
* rows has them. Column drill values of the group sum rows are not accumulated, so
|
|
273
|
+
* `runningSum` is off with columnthereof.
|
|
274
|
+
*/
|
|
275
|
+
hasRunningSum() {
|
|
276
|
+
return (this.config.runningSum && this.config.grouped && this.hasGroupSum() && this.config.categoryThereOf.size === 0);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Turns the GROUP_SUM rows into running results: each one gets the raw aliases of all
|
|
280
|
+
* group sums before it added (scenarios, `_cnt`, variances and `dr_*` denominators).
|
|
281
|
+
* Runs before the NaN step and the relative variance division, where all of them are sums.
|
|
282
|
+
* A missing value stays missing until a group brings a real one.
|
|
283
|
+
*/
|
|
284
|
+
accumulateGroupSums(res, aliases) {
|
|
285
|
+
const running = {};
|
|
286
|
+
for (const segment of res) {
|
|
287
|
+
for (const row of segment) {
|
|
288
|
+
if (row[QueryColumnNames.TYPE] !== "GROUP_SUM") {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
for (const alias of aliases) {
|
|
292
|
+
running[alias] = addGroupSum(running[alias], row[alias]);
|
|
293
|
+
row[alias] = running[alias];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
257
298
|
/** Generates a GROUP_SUM row that aggregates all entries within a single row group. */
|
|
258
299
|
createGroupSumRow(querys, groupSumQuery, rowGroupEntry, scenariosSUMQuery, queryWhereSection, order) {
|
|
259
300
|
// Generates SUM Row; sumsup all rows of group
|
|
@@ -635,7 +676,27 @@ export class DataQuery {
|
|
|
635
676
|
: [];
|
|
636
677
|
const groupTotalsByKey = new Map();
|
|
637
678
|
groupTotalRowsRaw.forEach((row) => groupTotalsByKey.set(`${row.rowGroup}${separator}${coerceBucketKey(row.__interval)}`, row));
|
|
638
|
-
if (isSumTypeGrouped) {
|
|
679
|
+
if (isSumTypeGrouped && this.hasRunningSum()) {
|
|
680
|
+
// per bucket, each group sum row gets the totals of all groups up to its own
|
|
681
|
+
const sumAliases = [...new Set(this.exctractScenarioNames(scenariosSUMQuery))];
|
|
682
|
+
const groupSumRows = res.flat().filter((row) => row.type === "GROUP_SUM");
|
|
683
|
+
for (const bucketKey of new Set(groupTotalRowsRaw.map((row) => coerceBucketKey(row.__interval)))) {
|
|
684
|
+
let running;
|
|
685
|
+
for (const row of groupSumRows) {
|
|
686
|
+
const totalRow = groupTotalsByKey.get(`${row.rowGroup}${separator}${bucketKey}`);
|
|
687
|
+
if (totalRow) {
|
|
688
|
+
running !== null && running !== void 0 ? running : (running = {});
|
|
689
|
+
for (const alias of sumAliases) {
|
|
690
|
+
running[alias] = addGroupSum(running[alias], totalRow[alias]);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (running) {
|
|
694
|
+
writeBucketValues(row, finalizeBucketRow(Object.assign({}, running)), bucketKey);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
else if (isSumTypeGrouped) {
|
|
639
700
|
for (const totalRow of groupTotalRowsRaw) {
|
|
640
701
|
const bucketKey = coerceBucketKey(totalRow.__interval);
|
|
641
702
|
const finalized = finalizeBucketRow(Object.assign({}, totalRow));
|
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
import { TableRowType, TableType } from "../model";
|
|
2
2
|
import { QueryColumnNames } from "../../../../utils/model";
|
|
3
|
+
import { VarianceScenario } from "../../../../utils/model/VarianceScenario";
|
|
4
|
+
function sameCoordinate(a, b) {
|
|
5
|
+
return Math.abs(a - b) <= 1e-9 * Math.max(1, Math.abs(a), Math.abs(b));
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Sets the connectors of a variance walk in print order. A null unit is a printed row
|
|
9
|
+
* without a bar. Two rows are joined only where the walk goes on: a group that restarts
|
|
10
|
+
* at zero gets no line from the sum row above it.
|
|
11
|
+
*/
|
|
12
|
+
function connectWalk(units, thereofAbove) {
|
|
13
|
+
const add = (bar, at, part) => {
|
|
14
|
+
var _a;
|
|
15
|
+
bar.connectors = [...((_a = bar.connectors) !== null && _a !== void 0 ? _a : []), { at, part }];
|
|
16
|
+
};
|
|
17
|
+
const link = (from, between, to, at) => {
|
|
18
|
+
add(from, at, "bottom");
|
|
19
|
+
between.forEach((bar) => add(bar, at, "through"));
|
|
20
|
+
add(to, at, "top");
|
|
21
|
+
};
|
|
22
|
+
let previous = null;
|
|
23
|
+
for (const unit of units) {
|
|
24
|
+
if (unit === null) {
|
|
25
|
+
previous = null;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const { main, children } = unit;
|
|
29
|
+
const entry = main.kind === "anchor" ? main.end : main.start;
|
|
30
|
+
if (previous && !unit.gapAbove && sameCoordinate(previous.main.end, entry)) {
|
|
31
|
+
// the line runs beside the thereof rows printed between the two rows
|
|
32
|
+
link(previous.main, thereofAbove ? children : previous.children, main, entry);
|
|
33
|
+
}
|
|
34
|
+
if (!unit.gapAbove && !unit.gapBelow) {
|
|
35
|
+
children.forEach((child, index) => {
|
|
36
|
+
if (index > 0)
|
|
37
|
+
link(children[index - 1], [], child, child.start);
|
|
38
|
+
});
|
|
39
|
+
if (children.length > 0) {
|
|
40
|
+
const last = children[children.length - 1];
|
|
41
|
+
if (!thereofAbove) {
|
|
42
|
+
link(main, [], children[0], main.start);
|
|
43
|
+
}
|
|
44
|
+
else if (sameCoordinate(last.end, main.end)) {
|
|
45
|
+
link(last, [], main, main.end);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
previous = unit.gapBelow ? null : unit;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
3
52
|
/**
|
|
4
53
|
* Waterfall geometry per raw result row and column, keyed by row identity
|
|
5
54
|
* (the factory iterates the same row objects the calculator walked).
|
|
@@ -7,6 +56,7 @@ import { QueryColumnNames } from "../../../../utils/model";
|
|
|
7
56
|
export class WaterfallResult {
|
|
8
57
|
constructor() {
|
|
9
58
|
this.geometry = new Map();
|
|
59
|
+
this.columns = new Set();
|
|
10
60
|
}
|
|
11
61
|
set(row, column, data) {
|
|
12
62
|
let columns = this.geometry.get(row);
|
|
@@ -15,11 +65,16 @@ export class WaterfallResult {
|
|
|
15
65
|
this.geometry.set(row, columns);
|
|
16
66
|
}
|
|
17
67
|
columns.set(column, data);
|
|
68
|
+
this.columns.add(column);
|
|
18
69
|
}
|
|
19
70
|
get(row, column) {
|
|
20
71
|
var _a;
|
|
21
72
|
return (_a = this.geometry.get(row)) === null || _a === void 0 ? void 0 : _a.get(column);
|
|
22
73
|
}
|
|
74
|
+
/** True when the column has waterfall bars, also for a row of it that got none. */
|
|
75
|
+
has(column) {
|
|
76
|
+
return this.columns.has(column);
|
|
77
|
+
}
|
|
23
78
|
}
|
|
24
79
|
/** True when the result contains grouping structure (sum, subtotal, or drill rows). */
|
|
25
80
|
export function hasGroupingStructure(queryData) {
|
|
@@ -36,12 +91,25 @@ export function hasGroupingStructure(queryData) {
|
|
|
36
91
|
}
|
|
37
92
|
return false;
|
|
38
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Alias of the signed sum of a bar column on the generated REST row of an OPT table. The
|
|
96
|
+
* row prints the unsigned sum of the rows it folds, the walk needs the signed one.
|
|
97
|
+
*/
|
|
98
|
+
export function restSignedAlias(column) {
|
|
99
|
+
return `${column}__signed`;
|
|
100
|
+
}
|
|
101
|
+
/** Sign of an OPT entry row; the generated REST row has `restOperation` in place of `operation`. */
|
|
102
|
+
function operationSign(row) {
|
|
103
|
+
var _a;
|
|
104
|
+
return ((_a = row[QueryColumnNames.OPERATION]) !== null && _a !== void 0 ? _a : row.restOperation) === "-" ? -1 : 1;
|
|
105
|
+
}
|
|
39
106
|
/**
|
|
40
107
|
* Signed waterfall contribution of a row for one column.
|
|
41
108
|
*
|
|
42
109
|
* Non-OPT table types aggregate `SUM(scn * transformOperator(operation))`, so ENTRY
|
|
43
110
|
* values arrive already signed. OPT types aggregate plain `SUM(scn)` with the sign
|
|
44
|
-
* carried in the visible operation column, so the sign is applied here.
|
|
111
|
+
* carried in the visible operation column, so the sign is applied here. A REST row that
|
|
112
|
+
* folds "+" and "-" rows has no single sign, it brings its signed sum. Sum rows are
|
|
45
113
|
* fully signed in both modes.
|
|
46
114
|
*/
|
|
47
115
|
function signedValue(row, column, tableType) {
|
|
@@ -54,8 +122,9 @@ function signedValue(row, column, tableType) {
|
|
|
54
122
|
return null;
|
|
55
123
|
}
|
|
56
124
|
const isOpt = tableType === TableType.OPT || tableType === TableType.OPTNOTOTAL;
|
|
57
|
-
if (isOpt && row[QueryColumnNames.TYPE] === TableRowType.ENTRY
|
|
58
|
-
|
|
125
|
+
if (isOpt && row[QueryColumnNames.TYPE] === TableRowType.ENTRY) {
|
|
126
|
+
const signed = row[restSignedAlias(column)];
|
|
127
|
+
return typeof signed === "number" ? signed : operationSign(row) * value;
|
|
59
128
|
}
|
|
60
129
|
return value;
|
|
61
130
|
}
|
|
@@ -64,6 +133,7 @@ function signedValue(row, column, tableType) {
|
|
|
64
133
|
* segmented query result once per column in display order.
|
|
65
134
|
*
|
|
66
135
|
* - ENTRY rows (incl. REST) cascade from the running total by their signed value.
|
|
136
|
+
* The REST row of an OPT table takes the sign of `restOperation`, or its signed sum.
|
|
67
137
|
* - SUM / GROUP_SUM rows anchor at zero. A SUM row resets the running total to its
|
|
68
138
|
* value, a GROUP_SUM row resets it to zero.
|
|
69
139
|
* - DRILLELEMENT (thereof) rows form a sub-cascade from their parent bar's start in
|
|
@@ -73,53 +143,92 @@ function signedValue(row, column, tableType) {
|
|
|
73
143
|
* `createPartOfDrillRows`, not literally the parent row's value.
|
|
74
144
|
* - GROUPHEAD rows get no bar and restart the running total at zero: every row group
|
|
75
145
|
* is its own cascade that ends at its GROUP_SUM.
|
|
146
|
+
* - With `runningSum` a GROUP_SUM row holds the result of all groups so far, so the
|
|
147
|
+
* cascade goes on from its value and no GROUPHEAD restarts it.
|
|
76
148
|
* - NaN rows get no bar; a NaN parent orphans its drill children.
|
|
77
149
|
*
|
|
150
|
+
* An absolute variance column walks the same way with three differences: a thereof row
|
|
151
|
+
* steps by its signed value times the operation sign of its parent, so its siblings can
|
|
152
|
+
* go both ways and leave the parent bar; a partof row gets no bar; and the bars carry
|
|
153
|
+
* connectors to the rows printed above and below.
|
|
154
|
+
*
|
|
78
155
|
* @param queryData - Segmented result rows from DataQuery.execute().
|
|
79
|
-
* @param columns - Plain scenario
|
|
156
|
+
* @param columns - Plain scenario (ac1..pl4) or absolute variance column keys; no `##` composite keys.
|
|
80
157
|
* @param tableType - Table aggregation mode, needed for OPT sign handling.
|
|
158
|
+
* @param runningSum - True when the GROUP_SUM rows are running results.
|
|
159
|
+
* @param thereofAbove - True when thereof rows are printed above their parent; only the connectors depend on it.
|
|
81
160
|
*/
|
|
82
|
-
export function computeWaterfall(queryData, columns, tableType) {
|
|
161
|
+
export function computeWaterfall(queryData, columns, tableType, runningSum = false, thereofAbove = false) {
|
|
83
162
|
const result = new WaterfallResult();
|
|
163
|
+
const isOpt = tableType === TableType.OPT || tableType === TableType.OPTNOTOTAL;
|
|
84
164
|
for (const column of columns) {
|
|
165
|
+
const variance = new VarianceScenario(column).isValid;
|
|
85
166
|
let running = 0;
|
|
86
167
|
let lastParent;
|
|
87
168
|
let subCursor = 0;
|
|
88
169
|
const emitted = [];
|
|
170
|
+
const units = [];
|
|
171
|
+
let unit = null;
|
|
89
172
|
const emit = (row, data) => {
|
|
90
173
|
emitted.push(data);
|
|
91
174
|
result.set(row, column, data);
|
|
175
|
+
return data;
|
|
176
|
+
};
|
|
177
|
+
const startUnit = (main) => {
|
|
178
|
+
unit = main && { main, children: [], gapAbove: false, gapBelow: false };
|
|
179
|
+
units.push(unit);
|
|
92
180
|
};
|
|
93
181
|
for (const groupData of queryData) {
|
|
94
182
|
for (const row of groupData) {
|
|
95
183
|
const type = row[QueryColumnNames.TYPE];
|
|
96
184
|
if (type === TableRowType.GROUPHEAD) {
|
|
97
185
|
// a group sum only totals its own rows, so the cascade must not carry over
|
|
98
|
-
|
|
186
|
+
if (!runningSum) {
|
|
187
|
+
running = 0;
|
|
188
|
+
}
|
|
99
189
|
lastParent = undefined;
|
|
190
|
+
startUnit(null);
|
|
100
191
|
continue;
|
|
101
192
|
}
|
|
102
193
|
const value = signedValue(row, column, tableType);
|
|
103
194
|
if (type === TableRowType.ENTRY) {
|
|
104
195
|
if (value === null) {
|
|
105
196
|
lastParent = undefined;
|
|
197
|
+
startUnit(null);
|
|
106
198
|
continue;
|
|
107
199
|
}
|
|
108
|
-
emit(row, { start: running, end: running + value, min: 0, max: 0, kind: "cascade" });
|
|
109
|
-
|
|
200
|
+
startUnit(emit(row, { start: running, end: running + value, min: 0, max: 0, kind: "cascade" }));
|
|
201
|
+
// thereof values of an OPT table are unsigned like the entries, so they take the sign of the parent
|
|
202
|
+
const sign = isOpt ? operationSign(row) : 1;
|
|
203
|
+
lastParent = { start: running, end: running + value, sign };
|
|
110
204
|
subCursor = lastParent.start;
|
|
111
205
|
running += value;
|
|
112
206
|
}
|
|
113
207
|
else if (type === TableRowType.SUM || type === TableRowType.GROUPSUM) {
|
|
114
208
|
if (value === null) {
|
|
115
209
|
lastParent = undefined;
|
|
210
|
+
startUnit(null);
|
|
116
211
|
continue;
|
|
117
212
|
}
|
|
118
|
-
emit(row, { start: 0, end: value, min: 0, max: 0, kind: "anchor" });
|
|
119
|
-
lastParent = { start: 0, end: value };
|
|
213
|
+
startUnit(emit(row, { start: 0, end: value, min: 0, max: 0, kind: "anchor" }));
|
|
214
|
+
lastParent = { start: 0, end: value, sign: 1 };
|
|
120
215
|
subCursor = 0;
|
|
121
216
|
// a group sum closes its group (there may be no GROUPHEAD row when the title is hidden)
|
|
122
|
-
running = type === TableRowType.GROUPSUM ? 0 : value;
|
|
217
|
+
running = type === TableRowType.GROUPSUM && !runningSum ? 0 : value;
|
|
218
|
+
}
|
|
219
|
+
else if (variance && (type === TableRowType.DRILLELEMENT || type === TableRowType.PARTELEMENT)) {
|
|
220
|
+
if (type === TableRowType.DRILLELEMENT && value !== null && lastParent !== undefined && unit) {
|
|
221
|
+
const end = subCursor + lastParent.sign * value;
|
|
222
|
+
unit.children.push(emit(row, { start: subCursor, end, min: 0, max: 0, kind: "thereof" }));
|
|
223
|
+
subCursor = end;
|
|
224
|
+
}
|
|
225
|
+
else if (unit) {
|
|
226
|
+
// only thereof rows move above the parent
|
|
227
|
+
if (thereofAbove && type === TableRowType.DRILLELEMENT)
|
|
228
|
+
unit.gapAbove = true;
|
|
229
|
+
else
|
|
230
|
+
unit.gapBelow = true;
|
|
231
|
+
}
|
|
123
232
|
}
|
|
124
233
|
else if (type === TableRowType.DRILLELEMENT) {
|
|
125
234
|
if (value === null || lastParent === undefined) {
|
|
@@ -156,6 +265,9 @@ export function computeWaterfall(queryData, columns, tableType) {
|
|
|
156
265
|
}
|
|
157
266
|
}
|
|
158
267
|
}
|
|
268
|
+
if (variance) {
|
|
269
|
+
connectWalk(units, thereofAbove);
|
|
270
|
+
}
|
|
159
271
|
// All rows of a column share one coordinate system including zero
|
|
160
272
|
let min = 0;
|
|
161
273
|
let max = 0;
|
|
@@ -82,24 +82,27 @@ function labelMeasureContext() {
|
|
|
82
82
|
}
|
|
83
83
|
return measureContext;
|
|
84
84
|
}
|
|
85
|
+
/** Bold digits of a font can be wider than the regular ones the glyph table lists. */
|
|
86
|
+
const BOLD_WIDTH_MARGIN = 1.08;
|
|
85
87
|
/**
|
|
86
88
|
* Rendered width of a value label in px, measured with the font the SVG text uses. Falls
|
|
87
89
|
* back to estimateLabelWidth where no canvas can measure.
|
|
88
90
|
*/
|
|
89
|
-
export function labelWidth(text, fontSize, fontFamily, italic) {
|
|
91
|
+
export function labelWidth(text, fontSize, fontFamily, italic, bold = false) {
|
|
92
|
+
const estimate = () => estimateLabelWidth(text, fontSize) * (bold ? BOLD_WIDTH_MARGIN : 1);
|
|
90
93
|
const ctx = labelMeasureContext();
|
|
91
94
|
if (ctx) {
|
|
92
95
|
// the canvas ignores a font it cannot parse and keeps the last one: the sentinel shows that
|
|
93
96
|
ctx.font = FONT_SENTINEL;
|
|
94
97
|
const sentinel = ctx.font;
|
|
95
|
-
ctx.font = `${italic ? "italic " : ""}${fontSize}px ${fontFamily}`;
|
|
98
|
+
ctx.font = `${italic ? "italic " : ""}${bold ? "bold " : ""}${fontSize}px ${fontFamily}`;
|
|
96
99
|
if (ctx.font === sentinel)
|
|
97
|
-
return
|
|
100
|
+
return estimate();
|
|
98
101
|
const width = ctx.measureText(text).width;
|
|
99
102
|
if (Number.isFinite(width) && (width > 0 || text === ""))
|
|
100
103
|
return width + MEASURE_PAD * fontSize;
|
|
101
104
|
}
|
|
102
|
-
return
|
|
105
|
+
return estimate();
|
|
103
106
|
}
|
|
104
107
|
/** The SVG fills the cell's content box: the requested column width minus the cell padding. */
|
|
105
108
|
function contentWidth(widthEm, emPx) {
|
|
@@ -215,13 +218,58 @@ export function relativePinGeometry(widthEm, emPx, labels, headSize, reach) {
|
|
|
215
218
|
labelGap,
|
|
216
219
|
};
|
|
217
220
|
}
|
|
218
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Without `column` both sides get the fixed gutter. With it each side gets the room its
|
|
223
|
+
* labels need beyond the bar area at the scale of the bars. The bar area keeps at least
|
|
224
|
+
* half the width: only gutters that need more shrink, and a side that fits the fixed
|
|
225
|
+
* gutter keeps its room then.
|
|
226
|
+
*/
|
|
227
|
+
export function waterfallGeometry(widthEm, emPx, column) {
|
|
219
228
|
const totalWidth = contentWidth(widthEm, emPx);
|
|
220
|
-
const
|
|
229
|
+
const labelGap = LABEL_GAP_EM * emPx;
|
|
230
|
+
const fixed = Math.min(BAR_LABEL_EM * emPx, totalWidth / 4);
|
|
231
|
+
let left = fixed;
|
|
232
|
+
let right = fixed;
|
|
233
|
+
const range = column ? column.max - column.min : 0;
|
|
234
|
+
if (column && range > 0) {
|
|
235
|
+
// what the labels of one side stick out of the bar area at the given scale
|
|
236
|
+
const room = (pointsLeft, pxPerUnit) => Math.max(0, ...column.labels
|
|
237
|
+
.filter((label) => label.pointsLeft === pointsLeft)
|
|
238
|
+
.map((label) => label.width + labelGap - (pointsLeft ? label.end - column.min : column.max - label.end) * pxPerUnit));
|
|
239
|
+
left = room(true, 0);
|
|
240
|
+
right = room(false, 0);
|
|
241
|
+
const budget = totalWidth / 2;
|
|
242
|
+
// a label needs less room the further its bar ends from the edge; a smaller gutter only widens the scale.
|
|
243
|
+
// One pass is enough for gutters that fit; more passes only while they take more than half the width.
|
|
244
|
+
for (let pass = 0; pass < 8; pass++) {
|
|
245
|
+
const pxPerUnit = Math.max(0, totalWidth - left - right) / range;
|
|
246
|
+
const nextLeft = Math.min(left, room(true, pxPerUnit));
|
|
247
|
+
const nextRight = Math.min(right, room(false, pxPerUnit));
|
|
248
|
+
const settled = nextLeft + nextRight <= budget || (nextLeft === left && nextRight === right);
|
|
249
|
+
left = nextLeft;
|
|
250
|
+
right = nextRight;
|
|
251
|
+
if (settled)
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (left + right > budget) {
|
|
255
|
+
if (Math.min(left, right) > fixed) {
|
|
256
|
+
const shrink = budget / (left + right);
|
|
257
|
+
left *= shrink;
|
|
258
|
+
right *= shrink;
|
|
259
|
+
}
|
|
260
|
+
else if (left <= right) {
|
|
261
|
+
right = budget - left;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
left = budget - right;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
221
268
|
return {
|
|
222
269
|
totalWidth,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
270
|
+
labelAreaLeft: left,
|
|
271
|
+
labelAreaRight: right,
|
|
272
|
+
barAreaWidth: totalWidth - left - right,
|
|
273
|
+
labelGap,
|
|
226
274
|
};
|
|
227
275
|
}
|