@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.
package/build/worker.js CHANGED
@@ -5632,13 +5632,17 @@ function normalizeSortByOptions({
5632
5632
  });
5633
5633
  }
5634
5634
 
5635
+ // src/widget-sources/constants.ts
5636
+ var OTHERS_CATEGORY_NAME = "_carto_others";
5637
+
5635
5638
  // src/operations/groupBy.ts
5636
5639
  function groupValuesByColumn({
5637
5640
  data,
5638
5641
  valuesColumns,
5639
5642
  joinOperation,
5640
5643
  keysColumn,
5641
- operation: operation2
5644
+ operation: operation2,
5645
+ othersThreshold
5642
5646
  }) {
5643
5647
  if (Array.isArray(data) && data.length === 0) {
5644
5648
  return null;
@@ -5656,13 +5660,23 @@ function groupValuesByColumn({
5656
5660
  return accumulator;
5657
5661
  }, /* @__PURE__ */ new Map());
5658
5662
  const targetOperation = aggregationFunctions[operation2];
5659
- if (targetOperation) {
5660
- return Array.from(groups).map(([name, value]) => ({
5661
- name,
5662
- value: targetOperation(value)
5663
- }));
5663
+ if (!targetOperation) {
5664
+ return [];
5665
+ }
5666
+ const allCategories = Array.from(groups).map(([name, value]) => ({
5667
+ name,
5668
+ value: targetOperation(value)
5669
+ }));
5670
+ allCategories.sort((a, b) => b.value - a.value);
5671
+ if (othersThreshold && allCategories.length > othersThreshold) {
5672
+ const otherNames = allCategories.map((entry) => entry.name).slice(othersThreshold);
5673
+ const otherValue = otherNames.flatMap((name) => groups.get(name));
5674
+ allCategories.push({
5675
+ name: OTHERS_CATEGORY_NAME,
5676
+ value: targetOperation(otherValue)
5677
+ });
5664
5678
  }
5665
- return [];
5679
+ return allCategories;
5666
5680
  }
5667
5681
 
5668
5682
  // src/utils/dateUtils.ts
@@ -6281,7 +6295,8 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6281
6295
  joinOperation,
6282
6296
  filters,
6283
6297
  filterOwner,
6284
- spatialFilter
6298
+ spatialFilter,
6299
+ othersThreshold
6285
6300
  }) {
6286
6301
  const filteredFeatures = this._getFilteredFeatures(
6287
6302
  spatialFilter,
@@ -6297,7 +6312,8 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6297
6312
  valuesColumns: normalizeColumns(operationColumn || column),
6298
6313
  joinOperation,
6299
6314
  keysColumn: column,
6300
- operation: operation2
6315
+ operation: operation2,
6316
+ othersThreshold
6301
6317
  });
6302
6318
  return groups || [];
6303
6319
  }