@qrvey/utils 1.17.6 → 1.18.1
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/README.md +1 -1
- package/dist/cjs/comparativeAnalysis/index.js +99 -0
- package/dist/cjs/tokens/getCustomTokenBoxParse.js +1 -0
- package/dist/comparativeAnalysis/index.d.ts +30 -0
- package/dist/comparativeAnalysis/index.js +98 -0
- package/dist/interfaces/CustomTokens.interface.d.ts +1 -0
- package/dist/tokens/getCustomTokenBoxParse.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,9 @@ exports.mapOperatorToValidationType = mapOperatorToValidationType;
|
|
|
13
13
|
exports.buildComparisonExpressionValue = buildComparisonExpressionValue;
|
|
14
14
|
exports.buildComparativeChartComparison = buildComparativeChartComparison;
|
|
15
15
|
exports.resolveDeltaDiffInfo = resolveDeltaDiffInfo;
|
|
16
|
+
exports.computeDeltaCellContent = computeDeltaCellContent;
|
|
16
17
|
const get_1 = require("../general/object/get");
|
|
18
|
+
const format_1 = require("../format/format");
|
|
17
19
|
exports.DELTA_COLUMN_PREFIX = "\u0394";
|
|
18
20
|
exports.REFERENCE_COLUMN_MARKER = "\u25CF";
|
|
19
21
|
function formatDeltaColumnCaption(caption) {
|
|
@@ -366,3 +368,100 @@ function resolveDeltaDiffInfo(dataField, comparativeVirtualColumns, getChartColu
|
|
|
366
368
|
}
|
|
367
369
|
return { origUniqueCode: "", diffIndex: -1 };
|
|
368
370
|
}
|
|
371
|
+
function computeDeltaCellContent(comparativeAnalisis, columnKey, rawValue, options) {
|
|
372
|
+
const match = columnKey.match(/^(.+?)__delta(?:_(\d+))?$/);
|
|
373
|
+
if (!match)
|
|
374
|
+
return { text: String(rawValue ?? ""), color: "#1f3864" };
|
|
375
|
+
const uniqueCode = match[1];
|
|
376
|
+
const deltaIndex = match[2] ? parseInt(match[2], 10) : 0;
|
|
377
|
+
const styles = comparativeAnalisis?.styles ?? {};
|
|
378
|
+
const diffCols = styles?.columnDiffs?.[uniqueCode] ?? [];
|
|
379
|
+
const diffStyle = diffCols[deltaIndex] ?? diffCols[0] ?? null;
|
|
380
|
+
const gs = styles;
|
|
381
|
+
const neutralColor = gs.neutralColor ?? "#1f3864";
|
|
382
|
+
const positiveColor = gs.positiveColor ?? "#52c41a";
|
|
383
|
+
const negativeColor = gs.negativeColor ?? "#f5222d";
|
|
384
|
+
const positiveIs = diffStyle?.positiveIs ?? gs.positiveIs ?? "higher";
|
|
385
|
+
const delta = -rawValue;
|
|
386
|
+
if (typeof delta !== "number" || !isFinite(delta)) {
|
|
387
|
+
return { text: "", color: neutralColor };
|
|
388
|
+
}
|
|
389
|
+
const increased = delta > 0;
|
|
390
|
+
const decreased = delta < 0;
|
|
391
|
+
const neutral = delta === 0;
|
|
392
|
+
const isPositive = positiveIs === "higher" ? increased : decreased;
|
|
393
|
+
let color;
|
|
394
|
+
if (neutral) {
|
|
395
|
+
color = neutralColor;
|
|
396
|
+
}
|
|
397
|
+
else if (isPositive) {
|
|
398
|
+
color = positiveColor;
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
color = negativeColor;
|
|
402
|
+
}
|
|
403
|
+
const defaultOrder = [
|
|
404
|
+
"showTrendIcon",
|
|
405
|
+
"showPercent",
|
|
406
|
+
"showValue",
|
|
407
|
+
"showABCLabels",
|
|
408
|
+
];
|
|
409
|
+
const order = diffStyle?.displayOrder?.length
|
|
410
|
+
? diffStyle.displayOrder
|
|
411
|
+
: defaultOrder;
|
|
412
|
+
const showTrendIcon = diffStyle?.showTrendIcon ?? false;
|
|
413
|
+
const showPercent = diffStyle?.showPercent ?? true;
|
|
414
|
+
const showValue = diffStyle?.showValue ?? false;
|
|
415
|
+
const showABC = diffStyle?.showABCLabels ?? false;
|
|
416
|
+
const parts = [];
|
|
417
|
+
for (const flag of order) {
|
|
418
|
+
if (flag === "showTrendIcon" && showTrendIcon) {
|
|
419
|
+
if (increased)
|
|
420
|
+
parts.push("\u25B2");
|
|
421
|
+
else if (decreased)
|
|
422
|
+
parts.push("\u25BC");
|
|
423
|
+
}
|
|
424
|
+
else if (flag === "showPercent" && showPercent) {
|
|
425
|
+
const origNum = options?.originalValue;
|
|
426
|
+
if (origNum != null &&
|
|
427
|
+
typeof origNum === "number" &&
|
|
428
|
+
isFinite(origNum) &&
|
|
429
|
+
origNum !== 0) {
|
|
430
|
+
const pct = (delta / origNum) * 100;
|
|
431
|
+
const sign = pct > 0 ? "+" : "";
|
|
432
|
+
parts.push(`${sign}${pct.toFixed(1)}%`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else if (flag === "showValue" && showValue) {
|
|
436
|
+
let sign;
|
|
437
|
+
if (delta > 0) {
|
|
438
|
+
sign = "+";
|
|
439
|
+
}
|
|
440
|
+
else if (delta < 0) {
|
|
441
|
+
sign = "-";
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
sign = "";
|
|
445
|
+
}
|
|
446
|
+
const formattedAbs = options?.format
|
|
447
|
+
? (0, format_1.addFormat)(Math.abs(delta), options.format, options.locale)
|
|
448
|
+
: Math.abs(delta).toLocaleString();
|
|
449
|
+
parts.push(`${sign}${formattedAbs}`);
|
|
450
|
+
}
|
|
451
|
+
else if (flag === "showABCLabels" && showABC) {
|
|
452
|
+
let abcLabel;
|
|
453
|
+
if (neutral) {
|
|
454
|
+
abcLabel = diffStyle?.neutralLabel ?? "";
|
|
455
|
+
}
|
|
456
|
+
else if (isPositive) {
|
|
457
|
+
abcLabel = diffStyle?.positiveLabel ?? "";
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
abcLabel = diffStyle?.negativeLabel ?? "";
|
|
461
|
+
}
|
|
462
|
+
if (abcLabel)
|
|
463
|
+
parts.push(abcLabel);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return { text: parts.join(" "), color };
|
|
467
|
+
}
|
|
@@ -22,3 +22,33 @@ export declare function resolveDeltaDiffInfo(dataField: string, comparativeVirtu
|
|
|
22
22
|
origUniqueCode: string;
|
|
23
23
|
diffIndex: number;
|
|
24
24
|
};
|
|
25
|
+
export interface IDifferenceColumnStyle {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
positiveIs: "higher" | "lower";
|
|
29
|
+
showPercent: boolean;
|
|
30
|
+
showValue: boolean;
|
|
31
|
+
showTrendIcon: boolean;
|
|
32
|
+
showABCLabels: boolean;
|
|
33
|
+
positiveLabel: string;
|
|
34
|
+
negativeLabel: string;
|
|
35
|
+
neutralLabel: string;
|
|
36
|
+
displayOrder?: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface IComparativeStyles {
|
|
39
|
+
columnDiffs: Record<string, IDifferenceColumnStyle[]>;
|
|
40
|
+
positiveIs: "higher" | "lower";
|
|
41
|
+
positiveColor: string;
|
|
42
|
+
negativeColor: string;
|
|
43
|
+
neutralColor: string;
|
|
44
|
+
}
|
|
45
|
+
export interface FormatDeltaCellOptions {
|
|
46
|
+
originalValue?: number;
|
|
47
|
+
format?: any;
|
|
48
|
+
locale?: any;
|
|
49
|
+
}
|
|
50
|
+
export interface DeltaCellContent {
|
|
51
|
+
text: string;
|
|
52
|
+
color: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function computeDeltaCellContent(comparativeAnalisis: any, columnKey: string, rawValue: number, options?: FormatDeltaCellOptions): DeltaCellContent;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _get } from "../general/object/get";
|
|
2
|
+
import { addFormat } from "../format/format";
|
|
2
3
|
export const DELTA_COLUMN_PREFIX = "\u0394";
|
|
3
4
|
export const REFERENCE_COLUMN_MARKER = "\u25CF";
|
|
4
5
|
export function formatDeltaColumnCaption(caption) {
|
|
@@ -351,3 +352,100 @@ export function resolveDeltaDiffInfo(dataField, comparativeVirtualColumns, getCh
|
|
|
351
352
|
}
|
|
352
353
|
return { origUniqueCode: "", diffIndex: -1 };
|
|
353
354
|
}
|
|
355
|
+
export function computeDeltaCellContent(comparativeAnalisis, columnKey, rawValue, options) {
|
|
356
|
+
const match = columnKey.match(/^(.+?)__delta(?:_(\d+))?$/);
|
|
357
|
+
if (!match)
|
|
358
|
+
return { text: String(rawValue ?? ""), color: "#1f3864" };
|
|
359
|
+
const uniqueCode = match[1];
|
|
360
|
+
const deltaIndex = match[2] ? parseInt(match[2], 10) : 0;
|
|
361
|
+
const styles = comparativeAnalisis?.styles ?? {};
|
|
362
|
+
const diffCols = styles?.columnDiffs?.[uniqueCode] ?? [];
|
|
363
|
+
const diffStyle = diffCols[deltaIndex] ?? diffCols[0] ?? null;
|
|
364
|
+
const gs = styles;
|
|
365
|
+
const neutralColor = gs.neutralColor ?? "#1f3864";
|
|
366
|
+
const positiveColor = gs.positiveColor ?? "#52c41a";
|
|
367
|
+
const negativeColor = gs.negativeColor ?? "#f5222d";
|
|
368
|
+
const positiveIs = diffStyle?.positiveIs ?? gs.positiveIs ?? "higher";
|
|
369
|
+
const delta = -rawValue;
|
|
370
|
+
if (typeof delta !== "number" || !isFinite(delta)) {
|
|
371
|
+
return { text: "", color: neutralColor };
|
|
372
|
+
}
|
|
373
|
+
const increased = delta > 0;
|
|
374
|
+
const decreased = delta < 0;
|
|
375
|
+
const neutral = delta === 0;
|
|
376
|
+
const isPositive = positiveIs === "higher" ? increased : decreased;
|
|
377
|
+
let color;
|
|
378
|
+
if (neutral) {
|
|
379
|
+
color = neutralColor;
|
|
380
|
+
}
|
|
381
|
+
else if (isPositive) {
|
|
382
|
+
color = positiveColor;
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
color = negativeColor;
|
|
386
|
+
}
|
|
387
|
+
const defaultOrder = [
|
|
388
|
+
"showTrendIcon",
|
|
389
|
+
"showPercent",
|
|
390
|
+
"showValue",
|
|
391
|
+
"showABCLabels",
|
|
392
|
+
];
|
|
393
|
+
const order = diffStyle?.displayOrder?.length
|
|
394
|
+
? diffStyle.displayOrder
|
|
395
|
+
: defaultOrder;
|
|
396
|
+
const showTrendIcon = diffStyle?.showTrendIcon ?? false;
|
|
397
|
+
const showPercent = diffStyle?.showPercent ?? true;
|
|
398
|
+
const showValue = diffStyle?.showValue ?? false;
|
|
399
|
+
const showABC = diffStyle?.showABCLabels ?? false;
|
|
400
|
+
const parts = [];
|
|
401
|
+
for (const flag of order) {
|
|
402
|
+
if (flag === "showTrendIcon" && showTrendIcon) {
|
|
403
|
+
if (increased)
|
|
404
|
+
parts.push("\u25B2");
|
|
405
|
+
else if (decreased)
|
|
406
|
+
parts.push("\u25BC");
|
|
407
|
+
}
|
|
408
|
+
else if (flag === "showPercent" && showPercent) {
|
|
409
|
+
const origNum = options?.originalValue;
|
|
410
|
+
if (origNum != null &&
|
|
411
|
+
typeof origNum === "number" &&
|
|
412
|
+
isFinite(origNum) &&
|
|
413
|
+
origNum !== 0) {
|
|
414
|
+
const pct = (delta / origNum) * 100;
|
|
415
|
+
const sign = pct > 0 ? "+" : "";
|
|
416
|
+
parts.push(`${sign}${pct.toFixed(1)}%`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
else if (flag === "showValue" && showValue) {
|
|
420
|
+
let sign;
|
|
421
|
+
if (delta > 0) {
|
|
422
|
+
sign = "+";
|
|
423
|
+
}
|
|
424
|
+
else if (delta < 0) {
|
|
425
|
+
sign = "-";
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
sign = "";
|
|
429
|
+
}
|
|
430
|
+
const formattedAbs = options?.format
|
|
431
|
+
? addFormat(Math.abs(delta), options.format, options.locale)
|
|
432
|
+
: Math.abs(delta).toLocaleString();
|
|
433
|
+
parts.push(`${sign}${formattedAbs}`);
|
|
434
|
+
}
|
|
435
|
+
else if (flag === "showABCLabels" && showABC) {
|
|
436
|
+
let abcLabel;
|
|
437
|
+
if (neutral) {
|
|
438
|
+
abcLabel = diffStyle?.neutralLabel ?? "";
|
|
439
|
+
}
|
|
440
|
+
else if (isPositive) {
|
|
441
|
+
abcLabel = diffStyle?.positiveLabel ?? "";
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
abcLabel = diffStyle?.negativeLabel ?? "";
|
|
445
|
+
}
|
|
446
|
+
if (abcLabel)
|
|
447
|
+
parts.push(abcLabel);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return { text: parts.join(" "), color };
|
|
451
|
+
}
|