@qrvey/utils 1.18.0 → 1.18.2

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.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/comparativeAnalysis/index.js +474 -0
  3. package/dist/cjs/elements/helpers/fixed.js +10 -1
  4. package/dist/cjs/elements/helpers/gridStrategy.js +10 -0
  5. package/dist/cjs/elements/helpers/responsive.js +10 -1
  6. package/dist/cjs/elements/helpers/vem-element/constants/vem.constants.js +33 -0
  7. package/dist/cjs/elements/helpers/vem-element/definitions/main.definitions.js +263 -0
  8. package/dist/cjs/elements/helpers/vem-element/helpers/vem.helpers.js +76 -0
  9. package/dist/cjs/elements/helpers/vem-element/models/vem.models.js +3 -0
  10. package/dist/cjs/elements/interfaces/IVemCore.js +12 -0
  11. package/dist/cjs/filters/helpers/OLD_getAggFilters.js +10 -2
  12. package/dist/cjs/globalization/service/i18nServiceV2.js +3 -0
  13. package/dist/cjs/globalization/service/i18nextBuilder.js +3 -0
  14. package/dist/cjs/index.js +1 -0
  15. package/dist/cjs/tokens/getCustomTokenBoxParse.js +1 -0
  16. package/dist/comparativeAnalysis/index.d.ts +55 -0
  17. package/dist/comparativeAnalysis/index.js +457 -0
  18. package/dist/elements/helpers/fixed.d.ts +3 -2
  19. package/dist/elements/helpers/fixed.js +9 -1
  20. package/dist/elements/helpers/gridStrategy.d.ts +8 -1
  21. package/dist/elements/helpers/gridStrategy.js +10 -2
  22. package/dist/elements/helpers/responsive.d.ts +3 -2
  23. package/dist/elements/helpers/responsive.js +9 -1
  24. package/dist/elements/helpers/vem-element/constants/vem.constants.d.ts +24 -0
  25. package/dist/elements/helpers/vem-element/constants/vem.constants.js +30 -0
  26. package/dist/elements/helpers/vem-element/definitions/main.definitions.d.ts +9 -0
  27. package/dist/elements/helpers/vem-element/definitions/main.definitions.js +260 -0
  28. package/dist/elements/helpers/vem-element/helpers/vem.helpers.d.ts +8 -0
  29. package/dist/elements/helpers/vem-element/helpers/vem.helpers.js +70 -0
  30. package/dist/elements/helpers/vem-element/models/vem.models.d.ts +85 -0
  31. package/dist/elements/helpers/vem-element/models/vem.models.js +1 -0
  32. package/dist/elements/interfaces/ICanvasGrid.d.ts +24 -0
  33. package/dist/elements/interfaces/IVemCore.d.ts +14 -0
  34. package/dist/elements/interfaces/IVemCore.js +11 -0
  35. package/dist/elements/utils/element.d.ts +1 -1
  36. package/dist/filters/helpers/OLD_getAggFilters.js +10 -2
  37. package/dist/globalization/service/i18nServiceV2.js +3 -0
  38. package/dist/globalization/service/i18nextBuilder.js +3 -0
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.js +1 -0
  41. package/dist/interfaces/CustomTokens.interface.d.ts +1 -0
  42. package/dist/tokens/getCustomTokenBoxParse.js +1 -0
  43. package/package.json +4 -1
@@ -0,0 +1,457 @@
1
+ import { _get } from "../general/object/get";
2
+ import { addFormat } from "../format/format";
3
+ export const DELTA_COLUMN_PREFIX = "\u0394";
4
+ export const REFERENCE_COLUMN_MARKER = "\u25CF";
5
+ export function formatDeltaColumnCaption(caption) {
6
+ return `${DELTA_COLUMN_PREFIX} ${caption}`;
7
+ }
8
+ export function formatReferenceColumnCaption(caption) {
9
+ return `${REFERENCE_COLUMN_MARKER} ${caption}`;
10
+ }
11
+ export function stripColumnMarker(caption) {
12
+ const markers = DELTA_COLUMN_PREFIX + REFERENCE_COLUMN_MARKER;
13
+ return caption
14
+ .replace(new RegExp(`^[${markers}]\\s*`), "")
15
+ .replace(new RegExp(`\\s*[${markers}]$`), "");
16
+ }
17
+ export function resolveComparativeColumnCaption(chartModel, columnKey, allDatesText) {
18
+ const fallbackAllDates = allDatesText || "All dates";
19
+ const columnsList = chartModel?.chart?.fields?.columnsList ??
20
+ _get(chartModel, "data.chart.fields.columnsList") ??
21
+ [];
22
+ const comparativeAnalisis = _get(chartModel, "store.comparativeAnalisis") ??
23
+ chartModel?.v2?.comparativeAnalisis ??
24
+ _get(chartModel, "data.v2.comparativeAnalisis") ??
25
+ {};
26
+ const suffixMatch = columnKey.match(/^(.+?)__(comp|delta(?:_(\d+))?)$/);
27
+ if (!suffixMatch) {
28
+ const col = columnsList.find((c) => c.data?.uniqueCode === columnKey) ??
29
+ columnsList.find((c) => c.dataField === columnKey);
30
+ return col?.label || col?.data?.text || columnKey;
31
+ }
32
+ const baseKey = suffixMatch[1];
33
+ const suffixType = suffixMatch[2];
34
+ const deltaIndexStr = suffixMatch[3];
35
+ const deltaIndex = deltaIndexStr ? parseInt(deltaIndexStr, 10) : 0;
36
+ const refCol = columnsList.find((c) => c.data?.uniqueCode === baseKey) ??
37
+ columnsList.find((c) => c.dataField === baseKey);
38
+ if (!refCol)
39
+ return columnKey;
40
+ const defaultName = refCol.data?.text ?? "";
41
+ const uniqueCode = refCol.data?.uniqueCode ?? "";
42
+ const refDataField = refCol.dataField ?? "";
43
+ const customLabels = _get(comparativeAnalisis, "customColumnLabels") ?? {};
44
+ const dataFieldKey = refDataField
45
+ ? `${refDataField}__${suffixType}`
46
+ : columnKey;
47
+ if (suffixType === "comp") {
48
+ return (customLabels[dataFieldKey] ??
49
+ formatComparativePeriodCaption(comparativeAnalisis.compareTo, fallbackAllDates, defaultName));
50
+ }
51
+ const diffCols = comparativeAnalisis?.styles?.columnDiffs?.[uniqueCode] ?? [];
52
+ const diffCol = diffCols[deltaIndex];
53
+ const hasConfiguredDiffs = comparativeAnalisis?.styles?.columnDiffs?.[uniqueCode] != null;
54
+ const diffName = diffCol?.name?.trim() || null;
55
+ if (hasConfiguredDiffs) {
56
+ if (diffName)
57
+ return formatDeltaColumnCaption(diffName);
58
+ return formatDeltaDefaultCaption(comparativeAnalisis.referencePeriod, comparativeAnalisis.compareTo, fallbackAllDates, defaultName);
59
+ }
60
+ if (diffName)
61
+ return formatDeltaColumnCaption(diffName);
62
+ if (customLabels[dataFieldKey])
63
+ return formatDeltaColumnCaption(customLabels[dataFieldKey]);
64
+ return formatDeltaDefaultCaption(comparativeAnalisis.referencePeriod, comparativeAnalisis.compareTo, fallbackAllDates, defaultName);
65
+ }
66
+ export function formatComparativePeriodCaption(period, allDatesText, colLabel = "") {
67
+ if (!period?.date1) {
68
+ return colLabel ? `${colLabel} - ${allDatesText}` : allDatesText;
69
+ }
70
+ const dateRange = period.date2
71
+ ? `${period.date1}-${period.date2}`
72
+ : period.date1;
73
+ return colLabel ? `${colLabel} - ${dateRange}` : dateRange;
74
+ }
75
+ export function formatDeltaDefaultCaption(referencePeriod, compareTo, allDatesText, colLabel = "") {
76
+ const fmtPeriodFn = (p) => {
77
+ if (!p?.date1)
78
+ return allDatesText;
79
+ return p.date2 ? `${p.date1}-${p.date2}` : p.date1;
80
+ };
81
+ const ref = fmtPeriodFn(referencePeriod);
82
+ const cmp = fmtPeriodFn(compareTo);
83
+ const comparison = ref && cmp ? `${ref} vs ${cmp}` : ref || cmp;
84
+ const prefix = colLabel ? `${DELTA_COLUMN_PREFIX} ${colLabel}` : DELTA_COLUMN_PREFIX;
85
+ return comparison ? `${prefix} - ${comparison}` : prefix;
86
+ }
87
+ export function computeComparativeVirtualColumns(isGrouped, myBus, chart, getChartColumns) {
88
+ if (!isGrouped)
89
+ return [];
90
+ const isActive = _get(myBus, "store.comparativeAnalisis.enabled", _get(chart, "data.v2.comparativeAnalisis.enabled")) === true;
91
+ const compareVisible = _get(myBus, "store.comparativeAnalisis.compareVisible", _get(chart, "data.v2.comparativeAnalisis.compareVisible", true));
92
+ if (!isActive || compareVisible === false)
93
+ return [];
94
+ const referenceColumnCodes = _get(myBus, "store.comparativeAnalisis.referenceColumns", _get(chart, "data.v2.comparativeAnalisis.referenceColumns", [])) || [];
95
+ if (!referenceColumnCodes.length)
96
+ return [];
97
+ const ca = _get(myBus, "store.comparativeAnalisis") ??
98
+ _get(chart, "data.v2.comparativeAnalisis") ??
99
+ {};
100
+ const columnList = getChartColumns();
101
+ const result = [];
102
+ columnList.forEach((col, i) => {
103
+ if (!referenceColumnCodes.includes(col.data?.uniqueCode))
104
+ return;
105
+ const uniqueCode = col.data?.uniqueCode;
106
+ const colDiffs = ca?.styles != null
107
+ ? (ca.styles.columnDiffs?.[uniqueCode] ?? [{ id: "default" }])
108
+ : [{ id: "default" }];
109
+ const extraDeltaDataFields = colDiffs
110
+ .slice(1)
111
+ .map((_, j) => `${col.dataField}__delta_${j + 1}`);
112
+ result.push({
113
+ originalDataField: col.dataField,
114
+ originalIndex: i,
115
+ compDataField: `${col.dataField}__comp`,
116
+ ...(colDiffs.length > 0
117
+ ? {
118
+ deltaDataField: `${col.dataField}__delta`,
119
+ extraDeltaDataFields: extraDeltaDataFields.length
120
+ ? extraDeltaDataFields
121
+ : undefined,
122
+ }
123
+ : {}),
124
+ });
125
+ });
126
+ return result;
127
+ }
128
+ export function expandColumnListWithComparativeColumns(columnList, comparativeVirtualColumns, myBus, chart, allDatesText) {
129
+ if (!comparativeVirtualColumns?.length)
130
+ return columnList;
131
+ const comparativeData = _get(myBus, "store.comparativeAnalisis", _get(chart, "data.v2.comparativeAnalisis", {})) || {};
132
+ const fallbackAllDates = allDatesText || "All dates";
133
+ const result = [];
134
+ for (const col of columnList) {
135
+ const vc = comparativeVirtualColumns.find((v) => v.originalDataField === col.dataField);
136
+ if (!vc) {
137
+ result.push(col);
138
+ }
139
+ else {
140
+ const defaultName = col.data?.text ?? "";
141
+ const hasCustomLabel = typeof col.label === "string" &&
142
+ col.label.trim().length > 0 &&
143
+ col.label.trim() !== defaultName.trim();
144
+ const refLabel = hasCustomLabel
145
+ ? col.label
146
+ : formatComparativePeriodCaption(comparativeData.referencePeriod, fallbackAllDates, defaultName);
147
+ const customLabels = _get(myBus, "store.comparativeAnalisis.customColumnLabels") ??
148
+ _get(chart, "data.v2.comparativeAnalisis.customColumnLabels") ??
149
+ {};
150
+ const uniqueCode = col.data?.uniqueCode ?? "";
151
+ const diffCols = comparativeData?.styles != null
152
+ ? (comparativeData.styles.columnDiffs?.[uniqueCode] ?? [
153
+ { id: "default", name: "" },
154
+ ])
155
+ : [{ id: "default", name: "" }];
156
+ const hasConfiguredDiffs = comparativeData?.styles?.columnDiffs?.[uniqueCode] != null;
157
+ const compLabel = customLabels[vc.compDataField] ??
158
+ formatComparativePeriodCaption(comparativeData.compareTo, fallbackAllDates, defaultName);
159
+ result.push({
160
+ ...col,
161
+ _comparativeLabel: refLabel,
162
+ _originalColIndex: vc.originalIndex,
163
+ });
164
+ result.push({
165
+ ...col,
166
+ dataField: vc.compDataField,
167
+ label: compLabel,
168
+ _isVirtualComparative: true,
169
+ _virtualType: "comp",
170
+ _originalDataField: vc.originalDataField,
171
+ _originalColIndex: vc.originalIndex,
172
+ });
173
+ if (vc.deltaDataField) {
174
+ const firstDiffName = diffCols[0]?.name?.trim() || "";
175
+ const resolvedFirstName = firstDiffName || null;
176
+ const deltaLabel = hasConfiguredDiffs
177
+ ? (resolvedFirstName ??
178
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName))
179
+ : (resolvedFirstName ??
180
+ customLabels[vc.deltaDataField] ??
181
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName));
182
+ result.push({
183
+ ...col,
184
+ dataField: vc.deltaDataField,
185
+ label: deltaLabel,
186
+ _isVirtualComparative: true,
187
+ _virtualType: "delta",
188
+ _diffColStyleIndex: 0,
189
+ _originalDataField: vc.originalDataField,
190
+ _originalColIndex: vc.originalIndex,
191
+ });
192
+ }
193
+ (vc.extraDeltaDataFields ?? []).forEach((df, j) => {
194
+ const styleIndex = j + 1;
195
+ const extraDiffName = diffCols[styleIndex]?.name?.trim() || "";
196
+ const resolvedExtraName = extraDiffName || null;
197
+ const extraLabel = hasConfiguredDiffs
198
+ ? (resolvedExtraName ??
199
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName))
200
+ : (resolvedExtraName ??
201
+ customLabels[df] ??
202
+ formatDeltaDefaultCaption(comparativeData.referencePeriod, comparativeData.compareTo, fallbackAllDates, defaultName));
203
+ result.push({
204
+ ...col,
205
+ dataField: df,
206
+ label: extraLabel,
207
+ _isVirtualComparative: true,
208
+ _virtualType: "delta",
209
+ _diffColStyleIndex: styleIndex,
210
+ _originalDataField: vc.originalDataField,
211
+ _originalColIndex: vc.originalIndex,
212
+ });
213
+ });
214
+ }
215
+ }
216
+ return result;
217
+ }
218
+ export function applyComparativeHeaderBorders(columns, myBus, chart) {
219
+ const tableBodyStyle = _get(myBus, "store.stylesSettings.tableBodyStyle") ||
220
+ _get(chart, "data.v2.stylesSettings.tableBodyStyle") ||
221
+ {};
222
+ const hasVerticalBorder = tableBodyStyle.verticalBorder === undefined ||
223
+ tableBodyStyle.verticalBorder === null
224
+ ? true
225
+ : tableBodyStyle.verticalBorder;
226
+ const borderColor = tableBodyStyle.borderColor || "#CACFD6";
227
+ return columns.map((col) => {
228
+ if (!col?.headerCellTemplate)
229
+ return col;
230
+ const origTemplate = col.headerCellTemplate;
231
+ return {
232
+ ...col,
233
+ headerCellTemplate: (columnHeader, cellInfo) => {
234
+ origTemplate(columnHeader, cellInfo);
235
+ if (col._comparativeLabel) {
236
+ const titleEl = columnHeader.querySelector(".an-header-title-text");
237
+ if (titleEl)
238
+ titleEl.textContent = `${REFERENCE_COLUMN_MARKER} ${col._comparativeLabel}`;
239
+ }
240
+ const totalCols = cellInfo.component?.columnCount?.() ?? 0;
241
+ if (hasVerticalBorder && cellInfo.columnIndex < totalCols - 1) {
242
+ columnHeader.parentElement?.style.setProperty("border-right", `1px solid ${borderColor}`);
243
+ }
244
+ else {
245
+ columnHeader.parentElement?.style.setProperty("border-right", "1px solid transparent");
246
+ }
247
+ },
248
+ };
249
+ });
250
+ }
251
+ export function mapOperatorToValidationType(operatorLabel) {
252
+ if (!operatorLabel)
253
+ return "EQUAL";
254
+ switch (operatorLabel) {
255
+ case "EQUAL":
256
+ return "EQUAL";
257
+ case "DOES_NOT_EQUAL":
258
+ return "NOT_EQUAL";
259
+ case "BETWEEN_INCLUSIVE":
260
+ case "BETWEEN_EXCLUSIVE":
261
+ case "BETWEEN":
262
+ case "GREATER_THAN":
263
+ case "LESS_THAN":
264
+ case "GREATER_THAN_OR_EQUAL":
265
+ case "LESS_THAN_OR_EQUAL":
266
+ case "BEFORE":
267
+ case "AFTER":
268
+ case "BEFORE_OR_ON":
269
+ case "AFTER_OR_ON":
270
+ return "RANGE";
271
+ case "IS_NULL":
272
+ return "IS_EMPTY";
273
+ case "IS_NOT_NULL":
274
+ return "IS_NOT_EMPTY";
275
+ default:
276
+ return "EQUAL";
277
+ }
278
+ }
279
+ export function buildComparisonExpressionValue(date1, date2, operatorLabel) {
280
+ switch (operatorLabel) {
281
+ case "EQUAL":
282
+ case "DOES_NOT_EQUAL":
283
+ return date1 ? [date1] : [];
284
+ case "BETWEEN_INCLUSIVE":
285
+ return date1 && date2 ? [{ gte: date1, lte: date2 }] : [];
286
+ case "BETWEEN_EXCLUSIVE":
287
+ case "BETWEEN":
288
+ return date1 && date2 ? [{ gt: date1, lt: date2 }] : [];
289
+ case "GREATER_THAN":
290
+ case "AFTER":
291
+ return date1 ? [{ gt: date1 }] : [];
292
+ case "GREATER_THAN_OR_EQUAL":
293
+ case "AFTER_OR_ON":
294
+ return date1 ? [{ gte: date1 }] : [];
295
+ case "LESS_THAN":
296
+ case "BEFORE":
297
+ return date1 ? [{ lt: date1 }] : [];
298
+ case "LESS_THAN_OR_EQUAL":
299
+ case "BEFORE_OR_ON":
300
+ return date1 ? [{ lte: date1 }] : [];
301
+ default:
302
+ return [];
303
+ }
304
+ }
305
+ export function buildComparativeChartComparison(myBus, chart, groups) {
306
+ const comparativeData = _get(myBus, "store.comparativeAnalisis", _get(chart, "data.v2.comparativeAnalisis", {})) || {};
307
+ const { dateColumn, referencePeriod, compareTo } = comparativeData;
308
+ if (!dateColumn)
309
+ return undefined;
310
+ const dateGroup = groups.find((g) => g.data.id === dateColumn);
311
+ const qrveyid = dateGroup?.data?.qrveyid;
312
+ const questionType = dateGroup?.data?.type || "DATE";
313
+ const buildExpression = (periodData) => {
314
+ if (!periodData || !periodData.operator)
315
+ return null;
316
+ const operatorLabel = periodData.operator.label;
317
+ const isNullType = operatorLabel === "IS_NULL" || operatorLabel === "IS_NOT_NULL";
318
+ if (!isNullType && !periodData.date1)
319
+ return null;
320
+ const validationType = mapOperatorToValidationType(operatorLabel);
321
+ const expression = {
322
+ groupValue: "day",
323
+ questionid: dateColumn,
324
+ qrveyid,
325
+ questionType,
326
+ validationType,
327
+ enabled: true,
328
+ };
329
+ if (!isNullType) {
330
+ expression.value = buildComparisonExpressionValue(periodData.date1, periodData.date2, operatorLabel);
331
+ }
332
+ return expression;
333
+ };
334
+ return {
335
+ comparison: buildExpression(compareTo),
336
+ period: buildExpression(referencePeriod),
337
+ };
338
+ }
339
+ export function resolveDeltaDiffInfo(dataField, comparativeVirtualColumns, getChartColumns) {
340
+ for (const vc of comparativeVirtualColumns) {
341
+ if (vc.deltaDataField === dataField) {
342
+ const chartCols = getChartColumns();
343
+ const refCol = chartCols.find((c) => c.dataField === vc.originalDataField);
344
+ return {
345
+ origUniqueCode: refCol?.data?.uniqueCode ?? "",
346
+ diffIndex: 0,
347
+ };
348
+ }
349
+ const extraIdx = (vc.extraDeltaDataFields ?? []).indexOf(dataField);
350
+ if (extraIdx !== -1) {
351
+ const chartCols = getChartColumns();
352
+ const refCol = chartCols.find((c) => c.dataField === vc.originalDataField);
353
+ return {
354
+ origUniqueCode: refCol?.data?.uniqueCode ?? "",
355
+ diffIndex: extraIdx + 1,
356
+ };
357
+ }
358
+ }
359
+ return { origUniqueCode: "", diffIndex: -1 };
360
+ }
361
+ export function computeDeltaCellContent(comparativeAnalisis, columnKey, rawValue, options) {
362
+ const match = columnKey.match(/^(.+?)__delta(?:_(\d+))?$/);
363
+ if (!match)
364
+ return { text: String(rawValue ?? ""), color: "#1f3864" };
365
+ const uniqueCode = match[1];
366
+ const deltaIndex = match[2] ? parseInt(match[2], 10) : 0;
367
+ const styles = comparativeAnalisis?.styles ?? {};
368
+ const diffCols = styles?.columnDiffs?.[uniqueCode] ?? [];
369
+ const diffStyle = diffCols[deltaIndex] ?? diffCols[0] ?? null;
370
+ const gs = styles;
371
+ const neutralColor = gs.neutralColor ?? "#1f3864";
372
+ const positiveColor = gs.positiveColor ?? "#52c41a";
373
+ const negativeColor = gs.negativeColor ?? "#f5222d";
374
+ const positiveIs = diffStyle?.positiveIs ?? gs.positiveIs ?? "higher";
375
+ const delta = -rawValue;
376
+ if (typeof delta !== "number" || !isFinite(delta)) {
377
+ return { text: "", color: neutralColor };
378
+ }
379
+ const increased = delta > 0;
380
+ const decreased = delta < 0;
381
+ const neutral = delta === 0;
382
+ const isPositive = positiveIs === "higher" ? increased : decreased;
383
+ let color;
384
+ if (neutral) {
385
+ color = neutralColor;
386
+ }
387
+ else if (isPositive) {
388
+ color = positiveColor;
389
+ }
390
+ else {
391
+ color = negativeColor;
392
+ }
393
+ const defaultOrder = [
394
+ "showTrendIcon",
395
+ "showPercent",
396
+ "showValue",
397
+ "showABCLabels",
398
+ ];
399
+ const order = diffStyle?.displayOrder?.length
400
+ ? diffStyle.displayOrder
401
+ : defaultOrder;
402
+ const showTrendIcon = diffStyle?.showTrendIcon ?? false;
403
+ const showPercent = diffStyle?.showPercent ?? true;
404
+ const showValue = diffStyle?.showValue ?? false;
405
+ const showABC = diffStyle?.showABCLabels ?? false;
406
+ const parts = [];
407
+ for (const flag of order) {
408
+ if (flag === "showTrendIcon" && showTrendIcon) {
409
+ if (increased)
410
+ parts.push("\u25B2");
411
+ else if (decreased)
412
+ parts.push("\u25BC");
413
+ }
414
+ else if (flag === "showPercent" && showPercent) {
415
+ const origNum = options?.originalValue;
416
+ if (origNum != null &&
417
+ typeof origNum === "number" &&
418
+ isFinite(origNum) &&
419
+ origNum !== 0) {
420
+ const pct = (delta / origNum) * 100;
421
+ const sign = pct > 0 ? "+" : "";
422
+ parts.push(`${sign}${pct.toFixed(1)}%`);
423
+ }
424
+ }
425
+ else if (flag === "showValue" && showValue) {
426
+ let sign;
427
+ if (delta > 0) {
428
+ sign = "+";
429
+ }
430
+ else if (delta < 0) {
431
+ sign = "-";
432
+ }
433
+ else {
434
+ sign = "";
435
+ }
436
+ const formattedAbs = options?.format
437
+ ? addFormat(Math.abs(delta), options.format, options.locale)
438
+ : Math.abs(delta).toLocaleString();
439
+ parts.push(`${sign}${formattedAbs}`);
440
+ }
441
+ else if (flag === "showABCLabels" && showABC) {
442
+ let abcLabel;
443
+ if (neutral) {
444
+ abcLabel = diffStyle?.neutralLabel ?? "";
445
+ }
446
+ else if (isPositive) {
447
+ abcLabel = diffStyle?.positiveLabel ?? "";
448
+ }
449
+ else {
450
+ abcLabel = diffStyle?.negativeLabel ?? "";
451
+ }
452
+ if (abcLabel)
453
+ parts.push(abcLabel);
454
+ }
455
+ }
456
+ return { text: parts.join(" "), color };
457
+ }
@@ -1,6 +1,6 @@
1
- import { CanvasDevice } from "../interfaces/ICanvasGrid";
1
+ import { CanvasDevice, CanvasGridConfig, CanvasGridConfigFixed } from "../interfaces/ICanvasGrid";
2
2
  import { FindAvailablePositionOptions } from "../interfaces/IFixedPosition";
3
- import { VemFixed } from "../interfaces/IVemCore";
3
+ import { Vem, VemFixed } from "../interfaces/IVemCore";
4
4
  import { VemPositionFixed } from "../interfaces/IVemPosition";
5
5
  export declare const CANVAS_EXTRA_HEIGHT = 10;
6
6
  export declare function updateFixedPosition(element: VemFixed, newDevicePosition: Partial<VemPositionFixed>, device: CanvasDevice): VemFixed;
@@ -25,3 +25,4 @@ export declare const sortElementsFromReferencePoint: (elements: VemFixed<unknown
25
25
  y: number;
26
26
  }) => VemFixed<unknown>[];
27
27
  export declare const updateFixedElementDimensions: (containerItem: VemFixed<unknown>, device: CanvasDevice, scopeElements: VemFixed<unknown>[]) => VemFixed<unknown>;
28
+ export declare const convertResponsiveElementsToFixed: (config: CanvasGridConfig<CanvasGridConfigFixed>, elements: Vem[], canvasDevice?: CanvasDevice) => VemFixed[];
@@ -1,5 +1,6 @@
1
+ import { updateDimension } from "./vem-element/helpers/vem.helpers";
1
2
  import { objectCopy } from "../../general";
2
- import { CanvasDevice } from "../interfaces/ICanvasGrid";
3
+ import { CanvasDevice, } from "../interfaces/ICanvasGrid";
3
4
  import { VemPositionType } from "../interfaces/IVemPosition";
4
5
  import { dxGetFixedGridItemDevice, dxGetFixedGridItemsBottomLimit, hasOverflow, hasOverlap, } from "../utils/fixed.position";
5
6
  import { sortByDistanceFunction } from "../utils/general";
@@ -165,3 +166,10 @@ export const updateFixedElementDimensions = (containerItem, device, scopeElement
165
166
  }, device);
166
167
  return { ...currentElement };
167
168
  };
169
+ export const convertResponsiveElementsToFixed = (config, elements, canvasDevice = CanvasDevice.DESKTOP) => {
170
+ const newElements = elements.filter((element) => !element.position?.fixed);
171
+ const currentFixedElements = elements.filter((element) => element.position?.fixed);
172
+ const recalculatedElements = newElements.map((element) => updateDimension(element, config, VemPositionType.FIXED));
173
+ const toProcessElements = findFixedAvailablePositions(config[canvasDevice].width, recalculatedElements, currentFixedElements, canvasDevice);
174
+ return [...currentFixedElements, ...toProcessElements];
175
+ };
@@ -1,10 +1,17 @@
1
- import { CanvasDevice, Vem } from "../interfaces";
1
+ import { CanvasDevice, CanvasGridConfig, CanvasGridConfigFixed, CanvasGridConfigResponsive, Vem, VemPositionType } from "../interfaces";
2
2
  interface RecalculateOptions {
3
3
  canvasHeight?: number;
4
4
  sort?: CanvasDevice;
5
5
  allowCopy?: boolean;
6
6
  keepPosition?: boolean;
7
7
  }
8
+ type NormalizeElementDimensionFunction = {
9
+ elements: Vem[];
10
+ canvasConfig: CanvasGridConfig<CanvasGridConfigResponsive | CanvasGridConfigFixed>;
11
+ target: VemPositionType;
12
+ canvasDevice?: CanvasDevice;
13
+ };
14
+ export declare const normalizeElementPositions: ({ elements, canvasConfig, target, canvasDevice, }: NormalizeElementDimensionFunction) => Vem[];
8
15
  export declare function recalculateElements(newElements: Vem[], currentElements: Vem[], canvasWidth: number, canvasType: string, device: CanvasDevice, options?: RecalculateOptions): Vem[];
9
16
  export declare function applyDynamicSize(containerItem: Vem, scopeElements: Vem[], device: CanvasDevice, canvasType: string, gap?: number): Vem | undefined;
10
17
  export declare function calculateCanvasHeight(elements: Vem[], canvasType: string, device: CanvasDevice, rowGap?: number): number;
@@ -1,7 +1,11 @@
1
- import { findFixedAvailablePositions, getFixedGridElementsBottomLimit, recalculatePreservingPositions, sortElementsFromReferencePoint, updateFixedElementDimensions, } from "./fixed";
2
- import { findResponsiveAvailablePositions, getResponsiveGridElementsBottomLimit, sortResponsiveElements, updateResponsiveElementDimensions, } from "./responsive";
1
+ import { convertResponsiveElementsToFixed, findFixedAvailablePositions, getFixedGridElementsBottomLimit, recalculatePreservingPositions, sortElementsFromReferencePoint, updateFixedElementDimensions, } from "./fixed";
2
+ import { convertFixedElementsToResponsive, findResponsiveAvailablePositions, getResponsiveGridElementsBottomLimit, sortResponsiveElements, updateResponsiveElementDimensions, } from "./responsive";
3
3
  import { CanvasDevice, VemPositionType, } from "../interfaces";
4
4
  import { copyDesktopPositionToDevice, normalizeElements, } from "../utils/element";
5
+ const normalizePositionStrategies = {
6
+ [VemPositionType.FIXED]: (canvasConfig, elements, device) => convertResponsiveElementsToFixed(canvasConfig, elements, device),
7
+ [VemPositionType.RESPONSIVE]: (canvasConfig, elements, device) => convertFixedElementsToResponsive(canvasConfig, elements, device),
8
+ };
5
9
  const applyDynamicSizeStrategies = {
6
10
  fixed: (containerItem, scopeElements, device) => {
7
11
  return updateFixedElementDimensions(containerItem, device, scopeElements);
@@ -10,6 +14,10 @@ const applyDynamicSizeStrategies = {
10
14
  return updateResponsiveElementDimensions(containerItem, device, scopeElements, gap);
11
15
  },
12
16
  };
17
+ export const normalizeElementPositions = ({ elements, canvasConfig, target, canvasDevice, }) => {
18
+ const _canvasDevice = canvasDevice ?? CanvasDevice.DESKTOP;
19
+ return normalizePositionStrategies[target](canvasConfig, elements, _canvasDevice);
20
+ };
13
21
  const recalculateStrategies = {
14
22
  fixed: (elements, currentElements, canvasWidth, device, options) => {
15
23
  const { newElements, scopeElements } = normalizeElements(currentElements, device, VemPositionType.FIXED);
@@ -1,5 +1,5 @@
1
- import { CanvasDevice } from "../interfaces/ICanvasGrid";
2
- import { VemFixed, VemResponsive } from "../interfaces/IVemCore";
1
+ import { CanvasDevice, CanvasGridConfig, CanvasGridConfigResponsive } from "../interfaces/ICanvasGrid";
2
+ import { Vem, VemFixed, VemResponsive } from "../interfaces/IVemCore";
3
3
  import { VemPositionResponsive } from "../interfaces/IVemPosition";
4
4
  export declare function findAvailablePosition(canvasWidth: number, newElement: VemResponsive, elements: VemResponsive[], device: CanvasDevice): {
5
5
  colStart: number;
@@ -25,3 +25,4 @@ export declare const sortByDistanceInResponsiveFunction: (a: {
25
25
  }, _device: CanvasDevice) => number;
26
26
  export declare const sortResponsiveElements: (elements: VemResponsive<unknown>[], sortByDevice?: CanvasDevice) => VemResponsive<unknown>[];
27
27
  export declare const updateResponsiveElementDimensions: (containerItem: VemResponsive<unknown>, device: CanvasDevice, scopeElements: VemFixed<unknown>[], rowGapSize: number) => VemResponsive<unknown>;
28
+ export declare const convertFixedElementsToResponsive: (config: CanvasGridConfig<CanvasGridConfigResponsive>, elements: Vem[], canvasDevice?: CanvasDevice) => VemResponsive[];
@@ -1,9 +1,10 @@
1
1
  import { objectCopy } from "../../general";
2
- import { CanvasDevice } from "../interfaces/ICanvasGrid";
2
+ import { CanvasDevice, } from "../interfaces/ICanvasGrid";
3
3
  import { VemPositionType, } from "../interfaces/IVemPosition";
4
4
  import { dxGetFixedGridItemsBottomLimit } from "../utils/fixed.position";
5
5
  import { OverlapIntervalTree } from "../utils/overlap";
6
6
  import { setElementPosition } from "../utils/position";
7
+ import { updateDimension } from "./vem-element/helpers/vem.helpers";
7
8
  const SPACE_DELTA = 1;
8
9
  const HEIGHT_DELTA = 32;
9
10
  const CANVAS_EXTRA_ROW = 1;
@@ -119,3 +120,10 @@ export const updateResponsiveElementDimensions = (containerItem, device, scopeEl
119
120
  }, device);
120
121
  return { ...currentElement };
121
122
  };
123
+ export const convertFixedElementsToResponsive = (config, elements, canvasDevice = CanvasDevice.DESKTOP) => {
124
+ const newElements = elements.filter((element) => !element.position?.responsive);
125
+ const currentElements = elements.filter((element) => element.position?.responsive);
126
+ let recalculatedElements = newElements.map((baseElem) => updateDimension(baseElem, config, VemPositionType.RESPONSIVE));
127
+ recalculatedElements = findResponsiveAvailablePositions(config[canvasDevice].columns.count, recalculatedElements, currentElements, canvasDevice);
128
+ return [...currentElements, ...recalculatedElements];
129
+ };
@@ -0,0 +1,24 @@
1
+ import { CanvasDevice } from "../../../interfaces/ICanvasGrid";
2
+ export declare const DEFAULT_CUSTOM_HEIGHT_IN_FIXED = 30;
3
+ export declare const DEFAULT_CUSTOM_HEIGHT_IN_RESPONSIVE = 32;
4
+ export declare const DEFAULT_MIN_FONT_TO_AUTO_RESIZE = 18;
5
+ export declare const DEFAULT_DELTA_RESIZE_IN_FIXED = 1.5;
6
+ export declare const DEFAULT_DELTA_RESIZE_IN_RESPONSIVE = 2.8;
7
+ export declare const DEFAULT_WIDTH_IN_FIXED = 415;
8
+ export declare const MIN_WIDTH_IN_FIXED = 275;
9
+ export declare const DEFAULT_HEIGHT_IN_FIXED = 76;
10
+ export declare const DEFAULT_WIDTH_IN_RESPONSIVE = 4;
11
+ export declare const MIN_WIDTH_IN_RESPONSIVE = 3;
12
+ export declare const DEFAULT_HEIGHT_IN_RESPONSIVE = 2;
13
+ export declare const DEFAULT_HEIGHT_IN_LIST = 245;
14
+ export declare enum FILTER_LIST_TYPE {
15
+ DROPDOWN = "DROPDOWN",
16
+ LIST = "LIST"
17
+ }
18
+ export declare enum FILTER_TRIGGER_TYPE {
19
+ AUTOMATIC = "AUTOMATIC",
20
+ BUTTON = "BUTTON",
21
+ DROPDOWN = "DROPDOWN",
22
+ LIST = "LIST"
23
+ }
24
+ export declare const DEVICE_LIST: CanvasDevice[];
@@ -0,0 +1,30 @@
1
+ import { CanvasDevice } from "../../../interfaces/ICanvasGrid";
2
+ export const DEFAULT_CUSTOM_HEIGHT_IN_FIXED = 30;
3
+ export const DEFAULT_CUSTOM_HEIGHT_IN_RESPONSIVE = 32;
4
+ export const DEFAULT_MIN_FONT_TO_AUTO_RESIZE = 18;
5
+ export const DEFAULT_DELTA_RESIZE_IN_FIXED = 1.5;
6
+ export const DEFAULT_DELTA_RESIZE_IN_RESPONSIVE = 2.8;
7
+ export const DEFAULT_WIDTH_IN_FIXED = 415;
8
+ export const MIN_WIDTH_IN_FIXED = 275;
9
+ export const DEFAULT_HEIGHT_IN_FIXED = 76;
10
+ export const DEFAULT_WIDTH_IN_RESPONSIVE = 4;
11
+ export const MIN_WIDTH_IN_RESPONSIVE = 3;
12
+ export const DEFAULT_HEIGHT_IN_RESPONSIVE = 2;
13
+ export const DEFAULT_HEIGHT_IN_LIST = 245;
14
+ export var FILTER_LIST_TYPE;
15
+ (function (FILTER_LIST_TYPE) {
16
+ FILTER_LIST_TYPE["DROPDOWN"] = "DROPDOWN";
17
+ FILTER_LIST_TYPE["LIST"] = "LIST";
18
+ })(FILTER_LIST_TYPE || (FILTER_LIST_TYPE = {}));
19
+ export var FILTER_TRIGGER_TYPE;
20
+ (function (FILTER_TRIGGER_TYPE) {
21
+ FILTER_TRIGGER_TYPE["AUTOMATIC"] = "AUTOMATIC";
22
+ FILTER_TRIGGER_TYPE["BUTTON"] = "BUTTON";
23
+ FILTER_TRIGGER_TYPE["DROPDOWN"] = "DROPDOWN";
24
+ FILTER_TRIGGER_TYPE["LIST"] = "LIST";
25
+ })(FILTER_TRIGGER_TYPE || (FILTER_TRIGGER_TYPE = {}));
26
+ export const DEVICE_LIST = [
27
+ CanvasDevice.DESKTOP,
28
+ CanvasDevice.TABLET,
29
+ CanvasDevice.MOBILE,
30
+ ];
@@ -0,0 +1,9 @@
1
+ import { VemAnalytics, VemButton, VemDefinition, VemImage, VemText } from "../models/vem.models";
2
+ export declare const IMAGE_ITEM_DEFINITION: VemDefinition<VemImage>;
3
+ export declare const BUTTON_ITEM_DEFINITION: VemDefinition<VemButton>;
4
+ export declare const TEXT_ITEM_DEFINITION: VemDefinition<VemText>;
5
+ export declare const ANALYTICS_ITEM_DEFINITION: VemDefinition<VemAnalytics>;
6
+ export declare const FILTER_INPUT_ITEM_DEFINITION: VemDefinition<unknown>;
7
+ export declare const FILTER_LIST_ITEM_DEFINITION: VemDefinition<unknown>;
8
+ export declare const FILTER_DATE_ITEM_DEFINITION: VemDefinition<unknown>;
9
+ export declare const CONTAINER_ITEM_DEFINITION: VemDefinition<unknown>;