Skip to content

Commit a4a5bba

Browse files
authored
Chart: Improve performance of categories aggregation (T1278348) (#29666)
1 parent 4dcc2fe commit a4a5bba

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/devextreme/js/viz/components/data_validator.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,20 +334,25 @@ function sortData(data, groupsData, options, uniqueArgumentFields) {
334334
return dataByArguments;
335335
}
336336

337-
function checkItemExistence(collection, item) {
338-
return collection.map(function(collectionItem) { return collectionItem.valueOf(); }).indexOf(item.valueOf()) === -1;
339-
}
340-
341337
function getCategories(data, uniqueArgumentFields, userCategories) {
342338
const categories = userCategories ? userCategories.slice() : [];
339+
const existingValues = new Set(categories.map(item => item.valueOf()));
343340

344341
uniqueArgumentFields.forEach(function(field) {
345342
data.forEach(function(item) {
346343
const dataItem = item[field];
344+
if(!_isDefined(dataItem)) {
345+
return;
346+
}
347347

348-
_isDefined(dataItem) && checkItemExistence(categories, dataItem) && categories.push(dataItem);
348+
const dataItemValue = dataItem.valueOf();
349+
if(!existingValues.has(dataItemValue)) {
350+
categories.push(dataItem);
351+
existingValues.add(dataItemValue);
352+
}
349353
});
350354
});
355+
351356
return categories;
352357
}
353358

0 commit comments

Comments
 (0)