@bit.rhplus/ag-grid 0.0.41 → 0.0.43
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/Aggregations.js +343 -343
- package/BulkEdit/BulkEditButton.jsx +187 -187
- package/BulkEdit/BulkEditModule.jsx +68 -0
- package/BulkEdit/index.js +10 -9
- package/BulkEdit/utils.js +10 -8
- package/dist/BulkEdit/BulkEditModule.d.ts +10 -0
- package/dist/BulkEdit/BulkEditModule.js +28 -0
- package/dist/BulkEdit/BulkEditModule.js.map +1 -0
- package/dist/BulkEdit/index.d.ts +1 -0
- package/dist/BulkEdit/index.js +1 -0
- package/dist/BulkEdit/index.js.map +1 -1
- package/dist/BulkEdit/utils.js +11 -9
- package/dist/BulkEdit/utils.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/index.jsx +8 -1
- package/package.json +5 -4
- /package/dist/{preview-1760475768249.js → preview-1760633567897.js} +0 -0
package/Aggregations.js
CHANGED
|
@@ -1,344 +1,344 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
import Enumerable from 'linq';
|
|
3
|
-
import moment from 'moment';
|
|
4
|
-
import { currencySymbols } from '@bit.rhplus/ui.grid';
|
|
5
|
-
|
|
6
|
-
const getColumnOrderDirection = (range) => (range.columns[0].colId === range.startColumn.colId) ? 1 : -1;
|
|
7
|
-
|
|
8
|
-
const getColumnOrderIndex = (range, index) => {
|
|
9
|
-
if (getColumnOrderDirection(range) === 1) {
|
|
10
|
-
return range.columns[index];
|
|
11
|
-
}
|
|
12
|
-
return range.columns[range.columns.length - 1 - index];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const getDimensionDefinition = (ranges) => {
|
|
16
|
-
let dimensionColumns = [];
|
|
17
|
-
let columnIndex = 0;
|
|
18
|
-
ranges.forEach(range => {
|
|
19
|
-
let colOf = 0;
|
|
20
|
-
for (let i = 0; i < range.columns.length; i += 1) {
|
|
21
|
-
if (columnIndex === 3)
|
|
22
|
-
break;
|
|
23
|
-
dimensionColumns = [...dimensionColumns, getColumnOrderIndex(range, colOf).colId];
|
|
24
|
-
columnIndex += 1;
|
|
25
|
-
colOf += 1;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return dimensionColumns;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const rangeContainsRowIndex = (range, row) => {
|
|
32
|
-
const start = Math.min(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
33
|
-
const end = Math.max(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
34
|
-
return (start <= row && end >= row);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const getValue = (gridRef, column, rowIndex) => {
|
|
38
|
-
// AG Grid 33+ API - nahrazuje getModel().getRow(rowIndex)
|
|
39
|
-
const rowNode = gridRef.current.api.getDisplayedRowAtIndex(rowIndex);
|
|
40
|
-
if (!rowNode) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
// AG Grid 33+ API - použití getCellValue s rowNode a colKey
|
|
44
|
-
const value = gridRef.current.api.getCellValue({
|
|
45
|
-
rowNode: rowNode,
|
|
46
|
-
colKey: column.colId
|
|
47
|
-
});
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const isValidDate = value => {
|
|
52
|
-
let typeValid = !(typeof value === 'number' || typeof value === "boolean" || value == null || value === '');
|
|
53
|
-
if (typeValid) {
|
|
54
|
-
typeValid = moment(value).isValid();
|
|
55
|
-
}
|
|
56
|
-
return typeValid;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Cache pro optimalizaci výpočtů
|
|
60
|
-
let cachedAggregations = null;
|
|
61
|
-
let cachedRangeHash = null;
|
|
62
|
-
|
|
63
|
-
// Jednoduchý hash funkce pro rychlé porovnání ranges
|
|
64
|
-
export const hashRanges = (ranges) => {
|
|
65
|
-
if (!ranges || ranges.length === 0) return null;
|
|
66
|
-
return ranges.map(r =>
|
|
67
|
-
`${r.startRow?.rowIndex}-${r.endRow?.rowIndex}-${r.columns?.length}-${r.columns?.[0]?.colId}`
|
|
68
|
-
).join('|');
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export default function Aggregations(gridRef) {
|
|
72
|
-
const ranges = gridRef.current.api.getCellRanges();
|
|
73
|
-
|
|
74
|
-
if (!ranges[0] || !ranges[0].startRow)
|
|
75
|
-
return {};
|
|
76
|
-
|
|
77
|
-
// Cache check - vrátit cache pokud se ranges nezměnily
|
|
78
|
-
const rangeHash = hashRanges(ranges);
|
|
79
|
-
if (cachedRangeHash === rangeHash && cachedAggregations) {
|
|
80
|
-
return cachedAggregations;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let sum = 0; let min = null; let max = null; let avg = null; let count = 0; let numberCount = 0;
|
|
84
|
-
let earliest; let latest;
|
|
85
|
-
let square = 0;
|
|
86
|
-
let cubic = 0;
|
|
87
|
-
let sumRows = [];
|
|
88
|
-
let sumCols = [];
|
|
89
|
-
let numberValues = []; // Pro výpočet mediánu
|
|
90
|
-
let textValues = []; // Pro frekvenční analýzu textových hodnot
|
|
91
|
-
let dateCount = 0;
|
|
92
|
-
let currencyMap = {}; // Pro sledování měn
|
|
93
|
-
|
|
94
|
-
const startRow = Math.min(ranges[0].startRow.rowIndex, ranges[0].endRow.rowIndex);
|
|
95
|
-
const domensionRanges = Enumerable.from(ranges).where(w => rangeContainsRowIndex(w, startRow)).toArray();
|
|
96
|
-
const dimensions = getDimensionDefinition(domensionRanges);
|
|
97
|
-
|
|
98
|
-
ranges.forEach(range => {
|
|
99
|
-
const start = Math.min(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
100
|
-
const end = Math.max(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
101
|
-
const rows = Enumerable.range(start, Math.abs(end - start) + 1).toArray();
|
|
102
|
-
sumRows = new Set([...sumRows, ...rows]);
|
|
103
|
-
|
|
104
|
-
const cols = Enumerable.from(range.columns).select(s => s.colId).distinct().toArray();
|
|
105
|
-
sumCols = new Set([...sumCols, ...cols]);
|
|
106
|
-
|
|
107
|
-
for (let rowIndex = start; rowIndex <= end; rowIndex += 1) {
|
|
108
|
-
let firstDimension = 0;
|
|
109
|
-
let secondDimension = 0;
|
|
110
|
-
let thirdDimension = 0;
|
|
111
|
-
const {columns} = range;
|
|
112
|
-
for (let i = 0; i < columns.length; i+=1) {
|
|
113
|
-
const column = columns[i];
|
|
114
|
-
const value = getValue(gridRef, column, rowIndex);
|
|
115
|
-
|
|
116
|
-
const validDate = isValidDate(value);
|
|
117
|
-
|
|
118
|
-
if (validDate) {
|
|
119
|
-
const dateValue = moment(value);
|
|
120
|
-
const dateValueAsDate = dateValue.toDate();
|
|
121
|
-
|
|
122
|
-
if (!earliest || dateValueAsDate < earliest) {
|
|
123
|
-
earliest = dateValueAsDate;
|
|
124
|
-
}
|
|
125
|
-
if (!latest || dateValueAsDate > latest) {
|
|
126
|
-
latest = dateValueAsDate;
|
|
127
|
-
}
|
|
128
|
-
dateCount += 1;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
// Pokus o konverzi na číslo (AG Grid často vrací stringy)
|
|
132
|
-
const numValue = typeof value === 'number' ? value : parseFloat(value);
|
|
133
|
-
|
|
134
|
-
if (!isNaN(numValue) && value !== null && value !== '' && value !== undefined) {
|
|
135
|
-
if (column.colId === dimensions[0]) { // prvni dimenze
|
|
136
|
-
firstDimension += numValue;
|
|
137
|
-
} else if (column.colId === dimensions[1]) {
|
|
138
|
-
secondDimension += numValue;
|
|
139
|
-
} else if (column.colId === dimensions[2]) {
|
|
140
|
-
thirdDimension += numValue;
|
|
141
|
-
}
|
|
142
|
-
sum += numValue;
|
|
143
|
-
min = (min === null) ? numValue : Math.min(min, numValue);
|
|
144
|
-
max = (max === null) ? numValue : Math.max(max, numValue);
|
|
145
|
-
numberValues.push(numValue); // Ukládáme pro median
|
|
146
|
-
numberCount += 1;
|
|
147
|
-
|
|
148
|
-
// Detekce měny pro currency sloupce
|
|
149
|
-
if (column.colDef && column.colDef.currency) {
|
|
150
|
-
const rowNode = gridRef.current.api.getDisplayedRowAtIndex(rowIndex);
|
|
151
|
-
let currencyValue;
|
|
152
|
-
|
|
153
|
-
if (typeof column.colDef.currency === 'function') {
|
|
154
|
-
// Dynamická měna - vyhodnotit funkci
|
|
155
|
-
currencyValue = column.colDef.currency({ data: rowNode?.data, node: rowNode });
|
|
156
|
-
} else {
|
|
157
|
-
// Statická měna
|
|
158
|
-
currencyValue = column.colDef.currency;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (currencyValue) {
|
|
162
|
-
currencyMap[currencyValue] = (currencyMap[currencyValue] || 0) + 1;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else if (value !== null && value !== '' && value !== undefined) {
|
|
167
|
-
// Textová hodnota - ukládáme pro frekvenční analýzu
|
|
168
|
-
const textValue = String(value).trim();
|
|
169
|
-
if (textValue.length > 0) {
|
|
170
|
-
textValues.push(textValue);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
count += 1;
|
|
175
|
-
};
|
|
176
|
-
square += (firstDimension * secondDimension);
|
|
177
|
-
cubic += (firstDimension * secondDimension * thirdDimension);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// Vypočítat průměr až po dokončení všech ranges
|
|
182
|
-
avg = numberCount > 0 ? (sum / numberCount) : null;
|
|
183
|
-
|
|
184
|
-
// Vypočítat medián
|
|
185
|
-
let median = null;
|
|
186
|
-
if (numberValues.length > 0) {
|
|
187
|
-
const sorted = [...numberValues].sort((a, b) => a - b);
|
|
188
|
-
const mid = Math.floor(sorted.length / 2);
|
|
189
|
-
median = sorted.length % 2 !== 0
|
|
190
|
-
? sorted[mid]
|
|
191
|
-
: (sorted[mid - 1] + sorted[mid]) / 2;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Vypočítat range (rozpětí)
|
|
195
|
-
const range = (min !== null && max !== null) ? (max - min) : null;
|
|
196
|
-
|
|
197
|
-
// Vypočítat rozpětí datumů v dnech
|
|
198
|
-
const dateRange = (earliest && latest)
|
|
199
|
-
? Math.ceil((latest - earliest) / (1000 * 60 * 60 * 24))
|
|
200
|
-
: null;
|
|
201
|
-
|
|
202
|
-
// Frekvenční analýza textových hodnot
|
|
203
|
-
let valueFrequencies = null;
|
|
204
|
-
let uniqueTextCount = 0;
|
|
205
|
-
let textCount = textValues.length;
|
|
206
|
-
let hasDuplicates = false;
|
|
207
|
-
|
|
208
|
-
if (textValues.length > 0) {
|
|
209
|
-
// Spočítat frekvence
|
|
210
|
-
const frequencyMap = {};
|
|
211
|
-
textValues.forEach(val => {
|
|
212
|
-
frequencyMap[val] = (frequencyMap[val] || 0) + 1;
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
uniqueTextCount = Object.keys(frequencyMap).length;
|
|
216
|
-
hasDuplicates = uniqueTextCount < textValues.length;
|
|
217
|
-
|
|
218
|
-
// Pouze pokud jsou duplicity a není příliš mnoho unikátních hodnot
|
|
219
|
-
if (hasDuplicates && uniqueTextCount <= 50) {
|
|
220
|
-
// Převést na pole a seřadit podle frekvence (sestupně)
|
|
221
|
-
valueFrequencies = Object.entries(frequencyMap)
|
|
222
|
-
.map(([value, count]) => ({
|
|
223
|
-
value,
|
|
224
|
-
count,
|
|
225
|
-
percentage: (count / textValues.length) * 100
|
|
226
|
-
}))
|
|
227
|
-
.sort((a, b) => b.count - a.count);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Určit hlavní měnu
|
|
232
|
-
let currency = null;
|
|
233
|
-
let currencySymbol = null;
|
|
234
|
-
let hasMixedCurrencies = false;
|
|
235
|
-
const currencyKeys = Object.keys(currencyMap);
|
|
236
|
-
|
|
237
|
-
if (currencyKeys.length > 0) {
|
|
238
|
-
if (currencyKeys.length === 1) {
|
|
239
|
-
// Pouze jedna měna
|
|
240
|
-
currency = currencyKeys[0];
|
|
241
|
-
currencySymbol = currencySymbols[currency] || currency;
|
|
242
|
-
} else {
|
|
243
|
-
// Více měn - najít nejčastější
|
|
244
|
-
const sortedCurrencies = Object.entries(currencyMap)
|
|
245
|
-
.sort((a, b) => b[1] - a[1]);
|
|
246
|
-
currency = sortedCurrencies[0][0];
|
|
247
|
-
currencySymbol = currencySymbols[currency] || currency;
|
|
248
|
-
hasMixedCurrencies = true;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const result = {
|
|
253
|
-
sum,
|
|
254
|
-
min,
|
|
255
|
-
max,
|
|
256
|
-
avg,
|
|
257
|
-
median,
|
|
258
|
-
range,
|
|
259
|
-
count,
|
|
260
|
-
numberCount,
|
|
261
|
-
textCount,
|
|
262
|
-
uniqueTextCount,
|
|
263
|
-
hasDuplicates,
|
|
264
|
-
valueFrequencies,
|
|
265
|
-
currency,
|
|
266
|
-
currencySymbol,
|
|
267
|
-
hasMixedCurrencies,
|
|
268
|
-
currencyDistribution: currencyMap,
|
|
269
|
-
square,
|
|
270
|
-
cubic,
|
|
271
|
-
earliest,
|
|
272
|
-
latest,
|
|
273
|
-
dateRange,
|
|
274
|
-
dateCount,
|
|
275
|
-
rows: [...sumRows].length,
|
|
276
|
-
cols: [...sumCols].length
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
// Uložit do cache
|
|
280
|
-
cachedAggregations = result;
|
|
281
|
-
cachedRangeHash = rangeHash;
|
|
282
|
-
|
|
283
|
-
return result;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// ranges.map(item => {
|
|
287
|
-
// var start = Math.min(item.startRow.rowIndex, item.endRow.rowIndex);
|
|
288
|
-
// var end = Math.max(item.startRow.rowIndex, item.endRow.rowIndex);
|
|
289
|
-
// for (var rowIndex = start; rowIndex <= end; rowIndex++) {
|
|
290
|
-
// var dimension = 0;
|
|
291
|
-
// rowVolume = 1;
|
|
292
|
-
|
|
293
|
-
// item.columns.forEach(column => {
|
|
294
|
-
// var rowModel = gridRef.current.api.getModel();
|
|
295
|
-
// var rowNode = rowModel.getRow(rowIndex);
|
|
296
|
-
// var value = gridRef.current.api.getValue(column, rowNode);
|
|
297
|
-
|
|
298
|
-
// if (Date.parse(value) && value != 0) {
|
|
299
|
-
// dateCount++;
|
|
300
|
-
// earliest = new Date(Math.min.apply(null, [(earliest || Date.parse(value)), Date.parse(value)]));
|
|
301
|
-
// latest = new Date(Math.max.apply(null, [(latest || Date.parse(value)), Date.parse(value)]));
|
|
302
|
-
// }
|
|
303
|
-
|
|
304
|
-
// if (typeof value === "number") {
|
|
305
|
-
// dimension++;
|
|
306
|
-
// sum += value;
|
|
307
|
-
// min = Math.min(min || value, value);
|
|
308
|
-
// max = Math.max(max || value, value);
|
|
309
|
-
// count++;
|
|
310
|
-
|
|
311
|
-
// if (dimension <= 3) {
|
|
312
|
-
// rowVolume = rowVolume * value;
|
|
313
|
-
// } else {
|
|
314
|
-
// rowVolume = 0;
|
|
315
|
-
// }
|
|
316
|
-
// }
|
|
317
|
-
// })
|
|
318
|
-
// if (dimension === 2) {
|
|
319
|
-
// volume2d = volume2d + rowVolume;
|
|
320
|
-
// } else if (dimension === 3) {
|
|
321
|
-
// volume3d = volume3d + rowVolume;
|
|
322
|
-
// }
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
// }
|
|
326
|
-
// length += (Math.abs(item.startRow.rowIndex - item.endRow.rowIndex) + 1) * item.columns.length;
|
|
327
|
-
// avg = (sum / count);
|
|
328
|
-
// });
|
|
329
|
-
|
|
330
|
-
// return {
|
|
331
|
-
// length,
|
|
332
|
-
// sum,
|
|
333
|
-
// min,
|
|
334
|
-
// max,
|
|
335
|
-
// avg,
|
|
336
|
-
// count,
|
|
337
|
-
// volume2d,
|
|
338
|
-
// volume3d,
|
|
339
|
-
// earliest,
|
|
340
|
-
// latest,
|
|
341
|
-
// isDate: dateCount >= 2,
|
|
342
|
-
// dateCount
|
|
343
|
-
// };
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import Enumerable from 'linq';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import { currencySymbols } from '@bit.rhplus/ui.grid';
|
|
5
|
+
|
|
6
|
+
const getColumnOrderDirection = (range) => (range.columns[0].colId === range.startColumn.colId) ? 1 : -1;
|
|
7
|
+
|
|
8
|
+
const getColumnOrderIndex = (range, index) => {
|
|
9
|
+
if (getColumnOrderDirection(range) === 1) {
|
|
10
|
+
return range.columns[index];
|
|
11
|
+
}
|
|
12
|
+
return range.columns[range.columns.length - 1 - index];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const getDimensionDefinition = (ranges) => {
|
|
16
|
+
let dimensionColumns = [];
|
|
17
|
+
let columnIndex = 0;
|
|
18
|
+
ranges.forEach(range => {
|
|
19
|
+
let colOf = 0;
|
|
20
|
+
for (let i = 0; i < range.columns.length; i += 1) {
|
|
21
|
+
if (columnIndex === 3)
|
|
22
|
+
break;
|
|
23
|
+
dimensionColumns = [...dimensionColumns, getColumnOrderIndex(range, colOf).colId];
|
|
24
|
+
columnIndex += 1;
|
|
25
|
+
colOf += 1;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return dimensionColumns;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const rangeContainsRowIndex = (range, row) => {
|
|
32
|
+
const start = Math.min(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
33
|
+
const end = Math.max(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
34
|
+
return (start <= row && end >= row);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const getValue = (gridRef, column, rowIndex) => {
|
|
38
|
+
// AG Grid 33+ API - nahrazuje getModel().getRow(rowIndex)
|
|
39
|
+
const rowNode = gridRef.current.api.getDisplayedRowAtIndex(rowIndex);
|
|
40
|
+
if (!rowNode) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
// AG Grid 33+ API - použití getCellValue s rowNode a colKey
|
|
44
|
+
const value = gridRef.current.api.getCellValue({
|
|
45
|
+
rowNode: rowNode,
|
|
46
|
+
colKey: column.colId
|
|
47
|
+
});
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const isValidDate = value => {
|
|
52
|
+
let typeValid = !(typeof value === 'number' || typeof value === "boolean" || value == null || value === '');
|
|
53
|
+
if (typeValid) {
|
|
54
|
+
typeValid = moment(value).isValid();
|
|
55
|
+
}
|
|
56
|
+
return typeValid;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Cache pro optimalizaci výpočtů
|
|
60
|
+
let cachedAggregations = null;
|
|
61
|
+
let cachedRangeHash = null;
|
|
62
|
+
|
|
63
|
+
// Jednoduchý hash funkce pro rychlé porovnání ranges
|
|
64
|
+
export const hashRanges = (ranges) => {
|
|
65
|
+
if (!ranges || ranges.length === 0) return null;
|
|
66
|
+
return ranges.map(r =>
|
|
67
|
+
`${r.startRow?.rowIndex}-${r.endRow?.rowIndex}-${r.columns?.length}-${r.columns?.[0]?.colId}`
|
|
68
|
+
).join('|');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default function Aggregations(gridRef) {
|
|
72
|
+
const ranges = gridRef.current.api.getCellRanges();
|
|
73
|
+
|
|
74
|
+
if (!ranges[0] || !ranges[0].startRow)
|
|
75
|
+
return {};
|
|
76
|
+
|
|
77
|
+
// Cache check - vrátit cache pokud se ranges nezměnily
|
|
78
|
+
const rangeHash = hashRanges(ranges);
|
|
79
|
+
if (cachedRangeHash === rangeHash && cachedAggregations) {
|
|
80
|
+
return cachedAggregations;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let sum = 0; let min = null; let max = null; let avg = null; let count = 0; let numberCount = 0;
|
|
84
|
+
let earliest; let latest;
|
|
85
|
+
let square = 0;
|
|
86
|
+
let cubic = 0;
|
|
87
|
+
let sumRows = [];
|
|
88
|
+
let sumCols = [];
|
|
89
|
+
let numberValues = []; // Pro výpočet mediánu
|
|
90
|
+
let textValues = []; // Pro frekvenční analýzu textových hodnot
|
|
91
|
+
let dateCount = 0;
|
|
92
|
+
let currencyMap = {}; // Pro sledování měn
|
|
93
|
+
|
|
94
|
+
const startRow = Math.min(ranges[0].startRow.rowIndex, ranges[0].endRow.rowIndex);
|
|
95
|
+
const domensionRanges = Enumerable.from(ranges).where(w => rangeContainsRowIndex(w, startRow)).toArray();
|
|
96
|
+
const dimensions = getDimensionDefinition(domensionRanges);
|
|
97
|
+
|
|
98
|
+
ranges.forEach(range => {
|
|
99
|
+
const start = Math.min(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
100
|
+
const end = Math.max(range.startRow.rowIndex, range.endRow.rowIndex);
|
|
101
|
+
const rows = Enumerable.range(start, Math.abs(end - start) + 1).toArray();
|
|
102
|
+
sumRows = new Set([...sumRows, ...rows]);
|
|
103
|
+
|
|
104
|
+
const cols = Enumerable.from(range.columns).select(s => s.colId).distinct().toArray();
|
|
105
|
+
sumCols = new Set([...sumCols, ...cols]);
|
|
106
|
+
|
|
107
|
+
for (let rowIndex = start; rowIndex <= end; rowIndex += 1) {
|
|
108
|
+
let firstDimension = 0;
|
|
109
|
+
let secondDimension = 0;
|
|
110
|
+
let thirdDimension = 0;
|
|
111
|
+
const {columns} = range;
|
|
112
|
+
for (let i = 0; i < columns.length; i+=1) {
|
|
113
|
+
const column = columns[i];
|
|
114
|
+
const value = getValue(gridRef, column, rowIndex);
|
|
115
|
+
|
|
116
|
+
const validDate = isValidDate(value);
|
|
117
|
+
|
|
118
|
+
if (validDate) {
|
|
119
|
+
const dateValue = moment(value);
|
|
120
|
+
const dateValueAsDate = dateValue.toDate();
|
|
121
|
+
|
|
122
|
+
if (!earliest || dateValueAsDate < earliest) {
|
|
123
|
+
earliest = dateValueAsDate;
|
|
124
|
+
}
|
|
125
|
+
if (!latest || dateValueAsDate > latest) {
|
|
126
|
+
latest = dateValueAsDate;
|
|
127
|
+
}
|
|
128
|
+
dateCount += 1;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// Pokus o konverzi na číslo (AG Grid často vrací stringy)
|
|
132
|
+
const numValue = typeof value === 'number' ? value : parseFloat(value);
|
|
133
|
+
|
|
134
|
+
if (!isNaN(numValue) && value !== null && value !== '' && value !== undefined) {
|
|
135
|
+
if (column.colId === dimensions[0]) { // prvni dimenze
|
|
136
|
+
firstDimension += numValue;
|
|
137
|
+
} else if (column.colId === dimensions[1]) {
|
|
138
|
+
secondDimension += numValue;
|
|
139
|
+
} else if (column.colId === dimensions[2]) {
|
|
140
|
+
thirdDimension += numValue;
|
|
141
|
+
}
|
|
142
|
+
sum += numValue;
|
|
143
|
+
min = (min === null) ? numValue : Math.min(min, numValue);
|
|
144
|
+
max = (max === null) ? numValue : Math.max(max, numValue);
|
|
145
|
+
numberValues.push(numValue); // Ukládáme pro median
|
|
146
|
+
numberCount += 1;
|
|
147
|
+
|
|
148
|
+
// Detekce měny pro currency sloupce
|
|
149
|
+
if (column.colDef && column.colDef.currency) {
|
|
150
|
+
const rowNode = gridRef.current.api.getDisplayedRowAtIndex(rowIndex);
|
|
151
|
+
let currencyValue;
|
|
152
|
+
|
|
153
|
+
if (typeof column.colDef.currency === 'function') {
|
|
154
|
+
// Dynamická měna - vyhodnotit funkci
|
|
155
|
+
currencyValue = column.colDef.currency({ data: rowNode?.data, node: rowNode });
|
|
156
|
+
} else {
|
|
157
|
+
// Statická měna
|
|
158
|
+
currencyValue = column.colDef.currency;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (currencyValue) {
|
|
162
|
+
currencyMap[currencyValue] = (currencyMap[currencyValue] || 0) + 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (value !== null && value !== '' && value !== undefined) {
|
|
167
|
+
// Textová hodnota - ukládáme pro frekvenční analýzu
|
|
168
|
+
const textValue = String(value).trim();
|
|
169
|
+
if (textValue.length > 0) {
|
|
170
|
+
textValues.push(textValue);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
count += 1;
|
|
175
|
+
};
|
|
176
|
+
square += (firstDimension * secondDimension);
|
|
177
|
+
cubic += (firstDimension * secondDimension * thirdDimension);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Vypočítat průměr až po dokončení všech ranges
|
|
182
|
+
avg = numberCount > 0 ? (sum / numberCount) : null;
|
|
183
|
+
|
|
184
|
+
// Vypočítat medián
|
|
185
|
+
let median = null;
|
|
186
|
+
if (numberValues.length > 0) {
|
|
187
|
+
const sorted = [...numberValues].sort((a, b) => a - b);
|
|
188
|
+
const mid = Math.floor(sorted.length / 2);
|
|
189
|
+
median = sorted.length % 2 !== 0
|
|
190
|
+
? sorted[mid]
|
|
191
|
+
: (sorted[mid - 1] + sorted[mid]) / 2;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Vypočítat range (rozpětí)
|
|
195
|
+
const range = (min !== null && max !== null) ? (max - min) : null;
|
|
196
|
+
|
|
197
|
+
// Vypočítat rozpětí datumů v dnech
|
|
198
|
+
const dateRange = (earliest && latest)
|
|
199
|
+
? Math.ceil((latest - earliest) / (1000 * 60 * 60 * 24))
|
|
200
|
+
: null;
|
|
201
|
+
|
|
202
|
+
// Frekvenční analýza textových hodnot
|
|
203
|
+
let valueFrequencies = null;
|
|
204
|
+
let uniqueTextCount = 0;
|
|
205
|
+
let textCount = textValues.length;
|
|
206
|
+
let hasDuplicates = false;
|
|
207
|
+
|
|
208
|
+
if (textValues.length > 0) {
|
|
209
|
+
// Spočítat frekvence
|
|
210
|
+
const frequencyMap = {};
|
|
211
|
+
textValues.forEach(val => {
|
|
212
|
+
frequencyMap[val] = (frequencyMap[val] || 0) + 1;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
uniqueTextCount = Object.keys(frequencyMap).length;
|
|
216
|
+
hasDuplicates = uniqueTextCount < textValues.length;
|
|
217
|
+
|
|
218
|
+
// Pouze pokud jsou duplicity a není příliš mnoho unikátních hodnot
|
|
219
|
+
if (hasDuplicates && uniqueTextCount <= 50) {
|
|
220
|
+
// Převést na pole a seřadit podle frekvence (sestupně)
|
|
221
|
+
valueFrequencies = Object.entries(frequencyMap)
|
|
222
|
+
.map(([value, count]) => ({
|
|
223
|
+
value,
|
|
224
|
+
count,
|
|
225
|
+
percentage: (count / textValues.length) * 100
|
|
226
|
+
}))
|
|
227
|
+
.sort((a, b) => b.count - a.count);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Určit hlavní měnu
|
|
232
|
+
let currency = null;
|
|
233
|
+
let currencySymbol = null;
|
|
234
|
+
let hasMixedCurrencies = false;
|
|
235
|
+
const currencyKeys = Object.keys(currencyMap);
|
|
236
|
+
|
|
237
|
+
if (currencyKeys.length > 0) {
|
|
238
|
+
if (currencyKeys.length === 1) {
|
|
239
|
+
// Pouze jedna měna
|
|
240
|
+
currency = currencyKeys[0];
|
|
241
|
+
currencySymbol = currencySymbols[currency] || currency;
|
|
242
|
+
} else {
|
|
243
|
+
// Více měn - najít nejčastější
|
|
244
|
+
const sortedCurrencies = Object.entries(currencyMap)
|
|
245
|
+
.sort((a, b) => b[1] - a[1]);
|
|
246
|
+
currency = sortedCurrencies[0][0];
|
|
247
|
+
currencySymbol = currencySymbols[currency] || currency;
|
|
248
|
+
hasMixedCurrencies = true;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const result = {
|
|
253
|
+
sum,
|
|
254
|
+
min,
|
|
255
|
+
max,
|
|
256
|
+
avg,
|
|
257
|
+
median,
|
|
258
|
+
range,
|
|
259
|
+
count,
|
|
260
|
+
numberCount,
|
|
261
|
+
textCount,
|
|
262
|
+
uniqueTextCount,
|
|
263
|
+
hasDuplicates,
|
|
264
|
+
valueFrequencies,
|
|
265
|
+
currency,
|
|
266
|
+
currencySymbol,
|
|
267
|
+
hasMixedCurrencies,
|
|
268
|
+
currencyDistribution: currencyMap,
|
|
269
|
+
square,
|
|
270
|
+
cubic,
|
|
271
|
+
earliest,
|
|
272
|
+
latest,
|
|
273
|
+
dateRange,
|
|
274
|
+
dateCount,
|
|
275
|
+
rows: [...sumRows].length,
|
|
276
|
+
cols: [...sumCols].length
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// Uložit do cache
|
|
280
|
+
cachedAggregations = result;
|
|
281
|
+
cachedRangeHash = rangeHash;
|
|
282
|
+
|
|
283
|
+
return result;
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
// ranges.map(item => {
|
|
287
|
+
// var start = Math.min(item.startRow.rowIndex, item.endRow.rowIndex);
|
|
288
|
+
// var end = Math.max(item.startRow.rowIndex, item.endRow.rowIndex);
|
|
289
|
+
// for (var rowIndex = start; rowIndex <= end; rowIndex++) {
|
|
290
|
+
// var dimension = 0;
|
|
291
|
+
// rowVolume = 1;
|
|
292
|
+
|
|
293
|
+
// item.columns.forEach(column => {
|
|
294
|
+
// var rowModel = gridRef.current.api.getModel();
|
|
295
|
+
// var rowNode = rowModel.getRow(rowIndex);
|
|
296
|
+
// var value = gridRef.current.api.getValue(column, rowNode);
|
|
297
|
+
|
|
298
|
+
// if (Date.parse(value) && value != 0) {
|
|
299
|
+
// dateCount++;
|
|
300
|
+
// earliest = new Date(Math.min.apply(null, [(earliest || Date.parse(value)), Date.parse(value)]));
|
|
301
|
+
// latest = new Date(Math.max.apply(null, [(latest || Date.parse(value)), Date.parse(value)]));
|
|
302
|
+
// }
|
|
303
|
+
|
|
304
|
+
// if (typeof value === "number") {
|
|
305
|
+
// dimension++;
|
|
306
|
+
// sum += value;
|
|
307
|
+
// min = Math.min(min || value, value);
|
|
308
|
+
// max = Math.max(max || value, value);
|
|
309
|
+
// count++;
|
|
310
|
+
|
|
311
|
+
// if (dimension <= 3) {
|
|
312
|
+
// rowVolume = rowVolume * value;
|
|
313
|
+
// } else {
|
|
314
|
+
// rowVolume = 0;
|
|
315
|
+
// }
|
|
316
|
+
// }
|
|
317
|
+
// })
|
|
318
|
+
// if (dimension === 2) {
|
|
319
|
+
// volume2d = volume2d + rowVolume;
|
|
320
|
+
// } else if (dimension === 3) {
|
|
321
|
+
// volume3d = volume3d + rowVolume;
|
|
322
|
+
// }
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
// }
|
|
326
|
+
// length += (Math.abs(item.startRow.rowIndex - item.endRow.rowIndex) + 1) * item.columns.length;
|
|
327
|
+
// avg = (sum / count);
|
|
328
|
+
// });
|
|
329
|
+
|
|
330
|
+
// return {
|
|
331
|
+
// length,
|
|
332
|
+
// sum,
|
|
333
|
+
// min,
|
|
334
|
+
// max,
|
|
335
|
+
// avg,
|
|
336
|
+
// count,
|
|
337
|
+
// volume2d,
|
|
338
|
+
// volume3d,
|
|
339
|
+
// earliest,
|
|
340
|
+
// latest,
|
|
341
|
+
// isDate: dateCount >= 2,
|
|
342
|
+
// dateCount
|
|
343
|
+
// };
|
|
344
344
|
}
|