@carto/api-client 0.5.7-alpha.2 → 0.5.7-alpha.3

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.
@@ -18878,13 +18878,17 @@
18878
18878
  });
18879
18879
  }
18880
18880
 
18881
+ // src/widget-sources/constants.ts
18882
+ var OTHERS_CATEGORY_NAME = "_carto_others";
18883
+
18881
18884
  // src/operations/groupBy.ts
18882
18885
  function groupValuesByColumn({
18883
18886
  data,
18884
18887
  valuesColumns,
18885
18888
  joinOperation,
18886
18889
  keysColumn,
18887
- operation: operation2
18890
+ operation: operation2,
18891
+ othersThreshold
18888
18892
  }) {
18889
18893
  if (Array.isArray(data) && data.length === 0) {
18890
18894
  return null;
@@ -18902,13 +18906,23 @@
18902
18906
  return accumulator;
18903
18907
  }, /* @__PURE__ */ new Map());
18904
18908
  const targetOperation = aggregationFunctions[operation2];
18905
- if (targetOperation) {
18906
- return Array.from(groups).map(([name, value]) => ({
18907
- name,
18908
- value: targetOperation(value)
18909
- }));
18909
+ if (!targetOperation) {
18910
+ return [];
18911
+ }
18912
+ const allCategories = Array.from(groups).map(([name, value]) => ({
18913
+ name,
18914
+ value: targetOperation(value)
18915
+ }));
18916
+ allCategories.sort((a, b) => b.value - a.value);
18917
+ if (othersThreshold && allCategories.length > othersThreshold) {
18918
+ const otherNames = allCategories.map((entry) => entry.name).slice(othersThreshold);
18919
+ const otherValue = otherNames.flatMap((name) => groups.get(name));
18920
+ allCategories.push({
18921
+ name: OTHERS_CATEGORY_NAME,
18922
+ value: targetOperation(otherValue)
18923
+ });
18910
18924
  }
18911
- return [];
18925
+ return allCategories;
18912
18926
  }
18913
18927
 
18914
18928
  // src/utils/dateUtils.ts
@@ -19527,7 +19541,8 @@
19527
19541
  joinOperation,
19528
19542
  filters,
19529
19543
  filterOwner,
19530
- spatialFilter
19544
+ spatialFilter,
19545
+ othersThreshold
19531
19546
  }) {
19532
19547
  const filteredFeatures = this._getFilteredFeatures(
19533
19548
  spatialFilter,
@@ -19543,7 +19558,8 @@
19543
19558
  valuesColumns: normalizeColumns(operationColumn || column),
19544
19559
  joinOperation,
19545
19560
  keysColumn: column,
19546
- operation: operation2
19561
+ operation: operation2,
19562
+ othersThreshold
19547
19563
  });
19548
19564
  return groups || [];
19549
19565
  }