@qrvey/utils 1.18.10 → 1.18.15

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 CHANGED
@@ -1,4 +1,4 @@
1
- # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.18.10*
1
+ # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.18.15*
2
2
 
3
3
  > Helper, Utils for all Qrvey Projects
4
4
 
@@ -5,6 +5,7 @@ exports.formatDeltaColumnCaption = formatDeltaColumnCaption;
5
5
  exports.formatReferenceColumnCaption = formatReferenceColumnCaption;
6
6
  exports.stripColumnMarker = stripColumnMarker;
7
7
  exports.resolveComparativeColumnCaption = resolveComparativeColumnCaption;
8
+ exports.formatPeriodLabel = formatPeriodLabel;
8
9
  exports.formatComparativePeriodCaption = formatComparativePeriodCaption;
9
10
  exports.formatDeltaDefaultCaption = formatDeltaDefaultCaption;
10
11
  exports.computeComparativeVirtualColumns = computeComparativeVirtualColumns;
@@ -71,38 +72,30 @@ function resolveComparativeColumnCaption(chartModel, columnKey, allDatesText) {
71
72
  }
72
73
  const diffCols = comparativeAnalisis?.styles?.columnDiffs?.[uniqueCode] ?? [];
73
74
  const diffCol = diffCols[deltaIndex];
74
- const hasConfiguredDiffs = comparativeAnalisis?.styles?.columnDiffs?.[uniqueCode] != null;
75
75
  const diffName = diffCol?.name?.trim() || null;
76
- if (hasConfiguredDiffs) {
77
- if (diffName)
78
- return formatDeltaColumnCaption(diffName);
79
- return formatDeltaDefaultCaption(comparativeAnalisis.referencePeriod, comparativeAnalisis.compareTo, fallbackAllDates, defaultName);
80
- }
81
76
  if (diffName)
82
77
  return formatDeltaColumnCaption(diffName);
83
78
  if (customLabels[dataFieldKey])
84
79
  return formatDeltaColumnCaption(customLabels[dataFieldKey]);
85
80
  return formatDeltaDefaultCaption(comparativeAnalisis.referencePeriod, comparativeAnalisis.compareTo, fallbackAllDates, defaultName);
86
81
  }
87
- function formatComparativePeriodCaption(period, allDatesText, colLabel = "") {
88
- if (!period?.date1) {
89
- return colLabel ? `${colLabel} - ${allDatesText}` : allDatesText;
90
- }
82
+ function formatPeriodLabel(period, allDatesText) {
83
+ if (period?.customLabel)
84
+ return period.customLabel;
85
+ if (!period?.date1)
86
+ return allDatesText;
91
87
  const d1 = period.formattedDate1 ?? period.date1;
92
88
  const d2 = period.formattedDate2 ?? period.date2;
93
89
  const dateRange = period.date2 ? `${d1} - ${d2}` : d1;
94
- return colLabel ? `${colLabel} - ${dateRange}` : dateRange;
90
+ return period.presetName ? `${period.presetName} (${dateRange})` : dateRange;
91
+ }
92
+ function formatComparativePeriodCaption(period, allDatesText, colLabel = "") {
93
+ const periodLabel = formatPeriodLabel(period, allDatesText);
94
+ return colLabel ? `${colLabel} - ${periodLabel}` : periodLabel;
95
95
  }
96
96
  function formatDeltaDefaultCaption(referencePeriod, compareTo, allDatesText, colLabel = "") {
97
- const fmtPeriodFn = (p) => {
98
- if (!p?.date1)
99
- return allDatesText;
100
- const d1 = p.formattedDate1 ?? p.date1;
101
- const d2 = p.formattedDate2 ?? p.date2;
102
- return p.date2 ? `${d1} - ${d2}` : d1;
103
- };
104
- const ref = fmtPeriodFn(referencePeriod);
105
- const cmp = fmtPeriodFn(compareTo);
97
+ const ref = formatPeriodLabel(referencePeriod, allDatesText);
98
+ const cmp = formatPeriodLabel(compareTo, allDatesText);
106
99
  const comparison = ref && cmp ? `${ref} vs ${cmp}` : ref || cmp;
107
100
  const prefix = colLabel
108
101
  ? `${exports.DELTA_COLUMN_PREFIX} ${colLabel}`
@@ -178,7 +171,6 @@ function expandColumnListWithComparativeColumns(columnList, comparativeVirtualCo
178
171
  { id: "default", name: "" },
179
172
  ])
180
173
  : [{ id: "default", name: "" }];
181
- const hasConfiguredDiffs = comparativeData?.styles?.columnDiffs?.[uniqueCode] != null;
182
174
  const compLabel = customLabels[vc.compDataField] ??
183
175
  formatComparativePeriodCaption(comparativeData.compareTo, fallbackAllDates, defaultName);
184
176
  result.push({
@@ -197,13 +189,9 @@ function expandColumnListWithComparativeColumns(columnList, comparativeVirtualCo
197
189
  });
198
190
  if (vc.deltaDataField) {
199
191
  const firstDiffName = diffCols[0]?.name?.trim() || "";
200
- const resolvedFirstName = firstDiffName || null;
201
- const deltaLabel = hasConfiguredDiffs
202
- ? (resolvedFirstName ??
203
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName))
204
- : (resolvedFirstName ??
205
- customLabels[vc.deltaDataField] ??
206
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName));
192
+ const deltaLabel = firstDiffName ||
193
+ customLabels[vc.deltaDataField] ||
194
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName);
207
195
  result.push({
208
196
  ...col,
209
197
  dataField: vc.deltaDataField,
@@ -218,13 +206,9 @@ function expandColumnListWithComparativeColumns(columnList, comparativeVirtualCo
218
206
  (vc.extraDeltaDataFields ?? []).forEach((df, j) => {
219
207
  const styleIndex = j + 1;
220
208
  const extraDiffName = diffCols[styleIndex]?.name?.trim() || "";
221
- const resolvedExtraName = extraDiffName || null;
222
- const extraLabel = hasConfiguredDiffs
223
- ? (resolvedExtraName ??
224
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName))
225
- : (resolvedExtraName ??
226
- customLabels[df] ??
227
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName));
209
+ const extraLabel = extraDiffName ||
210
+ customLabels[df] ||
211
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName);
228
212
  result.push({
229
213
  ...col,
230
214
  dataField: df,
@@ -11,6 +11,7 @@ export interface ComparativeVirtualColumn {
11
11
  deltaDataField?: string;
12
12
  extraDeltaDataFields?: string[];
13
13
  }
14
+ export declare function formatPeriodLabel(period: any, allDatesText: string): string;
14
15
  export declare function formatComparativePeriodCaption(period: any, allDatesText: string, colLabel?: string): string;
15
16
  export declare function formatDeltaDefaultCaption(referencePeriod: any, compareTo: any, allDatesText: string, colLabel?: string): string;
16
17
  export declare function computeComparativeVirtualColumns(isGrouped: boolean, myBus: any, chart: any, getChartColumns: () => any[]): ComparativeVirtualColumn[];
@@ -53,38 +53,30 @@ export function resolveComparativeColumnCaption(chartModel, columnKey, allDatesT
53
53
  }
54
54
  const diffCols = comparativeAnalisis?.styles?.columnDiffs?.[uniqueCode] ?? [];
55
55
  const diffCol = diffCols[deltaIndex];
56
- const hasConfiguredDiffs = comparativeAnalisis?.styles?.columnDiffs?.[uniqueCode] != null;
57
56
  const diffName = diffCol?.name?.trim() || null;
58
- if (hasConfiguredDiffs) {
59
- if (diffName)
60
- return formatDeltaColumnCaption(diffName);
61
- return formatDeltaDefaultCaption(comparativeAnalisis.referencePeriod, comparativeAnalisis.compareTo, fallbackAllDates, defaultName);
62
- }
63
57
  if (diffName)
64
58
  return formatDeltaColumnCaption(diffName);
65
59
  if (customLabels[dataFieldKey])
66
60
  return formatDeltaColumnCaption(customLabels[dataFieldKey]);
67
61
  return formatDeltaDefaultCaption(comparativeAnalisis.referencePeriod, comparativeAnalisis.compareTo, fallbackAllDates, defaultName);
68
62
  }
69
- export function formatComparativePeriodCaption(period, allDatesText, colLabel = "") {
70
- if (!period?.date1) {
71
- return colLabel ? `${colLabel} - ${allDatesText}` : allDatesText;
72
- }
63
+ export function formatPeriodLabel(period, allDatesText) {
64
+ if (period?.customLabel)
65
+ return period.customLabel;
66
+ if (!period?.date1)
67
+ return allDatesText;
73
68
  const d1 = period.formattedDate1 ?? period.date1;
74
69
  const d2 = period.formattedDate2 ?? period.date2;
75
70
  const dateRange = period.date2 ? `${d1} - ${d2}` : d1;
76
- return colLabel ? `${colLabel} - ${dateRange}` : dateRange;
71
+ return period.presetName ? `${period.presetName} (${dateRange})` : dateRange;
72
+ }
73
+ export function formatComparativePeriodCaption(period, allDatesText, colLabel = "") {
74
+ const periodLabel = formatPeriodLabel(period, allDatesText);
75
+ return colLabel ? `${colLabel} - ${periodLabel}` : periodLabel;
77
76
  }
78
77
  export function formatDeltaDefaultCaption(referencePeriod, compareTo, allDatesText, colLabel = "") {
79
- const fmtPeriodFn = (p) => {
80
- if (!p?.date1)
81
- return allDatesText;
82
- const d1 = p.formattedDate1 ?? p.date1;
83
- const d2 = p.formattedDate2 ?? p.date2;
84
- return p.date2 ? `${d1} - ${d2}` : d1;
85
- };
86
- const ref = fmtPeriodFn(referencePeriod);
87
- const cmp = fmtPeriodFn(compareTo);
78
+ const ref = formatPeriodLabel(referencePeriod, allDatesText);
79
+ const cmp = formatPeriodLabel(compareTo, allDatesText);
88
80
  const comparison = ref && cmp ? `${ref} vs ${cmp}` : ref || cmp;
89
81
  const prefix = colLabel
90
82
  ? `${DELTA_COLUMN_PREFIX} ${colLabel}`
@@ -160,7 +152,6 @@ export function expandColumnListWithComparativeColumns(columnList, comparativeVi
160
152
  { id: "default", name: "" },
161
153
  ])
162
154
  : [{ id: "default", name: "" }];
163
- const hasConfiguredDiffs = comparativeData?.styles?.columnDiffs?.[uniqueCode] != null;
164
155
  const compLabel = customLabels[vc.compDataField] ??
165
156
  formatComparativePeriodCaption(comparativeData.compareTo, fallbackAllDates, defaultName);
166
157
  result.push({
@@ -179,13 +170,9 @@ export function expandColumnListWithComparativeColumns(columnList, comparativeVi
179
170
  });
180
171
  if (vc.deltaDataField) {
181
172
  const firstDiffName = diffCols[0]?.name?.trim() || "";
182
- const resolvedFirstName = firstDiffName || null;
183
- const deltaLabel = hasConfiguredDiffs
184
- ? (resolvedFirstName ??
185
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName))
186
- : (resolvedFirstName ??
187
- customLabels[vc.deltaDataField] ??
188
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName));
173
+ const deltaLabel = firstDiffName ||
174
+ customLabels[vc.deltaDataField] ||
175
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName);
189
176
  result.push({
190
177
  ...col,
191
178
  dataField: vc.deltaDataField,
@@ -200,13 +187,9 @@ export function expandColumnListWithComparativeColumns(columnList, comparativeVi
200
187
  (vc.extraDeltaDataFields ?? []).forEach((df, j) => {
201
188
  const styleIndex = j + 1;
202
189
  const extraDiffName = diffCols[styleIndex]?.name?.trim() || "";
203
- const resolvedExtraName = extraDiffName || null;
204
- const extraLabel = hasConfiguredDiffs
205
- ? (resolvedExtraName ??
206
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName))
207
- : (resolvedExtraName ??
208
- customLabels[df] ??
209
- formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName));
190
+ const extraLabel = extraDiffName ||
191
+ customLabels[df] ||
192
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName);
210
193
  result.push({
211
194
  ...col,
212
195
  dataField: df,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.18.10",
3
+ "version": "1.18.15",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/cjs/index.js",
@@ -83,7 +83,7 @@
83
83
  ],
84
84
  "overrides": {
85
85
  "brace-expansion": "^5.0.8",
86
- "js-yaml": "4.3.0"
86
+ "js-yaml": "5.4.1"
87
87
  },
88
88
  "sideEffects": false,
89
89
  "types": "dist/index.d.ts"