@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.
@@ -1193,8 +1193,8 @@ interface CategoryRequestOptions extends BaseRequestOptions {
1193
1193
  operationColumn?: string;
1194
1194
  /** Local only. */
1195
1195
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1196
- /** Calculate `_carto_others` category for all categories after first N (N is threshold). Remote only. */
1197
- othersThreshold?: boolean;
1196
+ /** Calculate `_carto_others` category for all categories after first N (N is threshold). */
1197
+ othersThreshold?: number;
1198
1198
  }
1199
1199
  /**
1200
1200
  * Options for {@link WidgetRemoteSource#getFeatures}.
@@ -1331,7 +1331,7 @@ type FormulaResponse = {
1331
1331
  };
1332
1332
  /** Response from {@link WidgetRemoteSource#getCategories}. */
1333
1333
  type CategoryResponse = {
1334
- name: string;
1334
+ name: string | null;
1335
1335
  value: number;
1336
1336
  }[];
1337
1337
  /** Response from {@link WidgetRemoteSource#getRange}. */
@@ -1615,7 +1615,7 @@ declare class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePr
1615
1615
  getFeatures(): Promise<FeaturesResponse>;
1616
1616
  getFormula({ column, operation, joinOperation, filters, filterOwner, spatialFilter, }: FormulaRequestOptions): Promise<FormulaResponse>;
1617
1617
  getHistogram({ operation, ticks, column, joinOperation, filters, filterOwner, spatialFilter, }: HistogramRequestOptions): Promise<HistogramResponse>;
1618
- getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: CategoryRequestOptions): Promise<CategoryResponse>;
1618
+ getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, othersThreshold, }: CategoryRequestOptions): Promise<CategoryResponse>;
1619
1619
  getScatter({ xAxisColumn, yAxisColumn, xAxisJoinOperation, yAxisJoinOperation, filters, filterOwner, spatialFilter, }: ScatterRequestOptions): Promise<ScatterResponse>;
1620
1620
  getTable({ columns, searchFilterColumn, searchFilterText, sortBy, sortDirection, sortByColumnType, offset, limit, filters, filterOwner, spatialFilter, }: TableRequestOptions): Promise<TableResponse>;
1621
1621
  getTimeSeries({ column, stepSize, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
@@ -1826,12 +1826,13 @@ type GroupByFeature = {
1826
1826
  value: number;
1827
1827
  }[];
1828
1828
  /** @privateRemarks Source: @carto/react-core */
1829
- declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, }: {
1829
+ declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, othersThreshold, }: {
1830
1830
  data: FeatureData[];
1831
1831
  valuesColumns?: string[];
1832
1832
  joinOperation?: AggregationType;
1833
1833
  keysColumn: string;
1834
1834
  operation: AggregationType;
1835
+ othersThreshold?: number;
1835
1836
  }): GroupByFeature | null;
1836
1837
 
1837
1838
  /** @privateRemarks Source: @carto/react-core */
@@ -1193,8 +1193,8 @@ interface CategoryRequestOptions extends BaseRequestOptions {
1193
1193
  operationColumn?: string;
1194
1194
  /** Local only. */
1195
1195
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1196
- /** Calculate `_carto_others` category for all categories after first N (N is threshold). Remote only. */
1197
- othersThreshold?: boolean;
1196
+ /** Calculate `_carto_others` category for all categories after first N (N is threshold). */
1197
+ othersThreshold?: number;
1198
1198
  }
1199
1199
  /**
1200
1200
  * Options for {@link WidgetRemoteSource#getFeatures}.
@@ -1331,7 +1331,7 @@ type FormulaResponse = {
1331
1331
  };
1332
1332
  /** Response from {@link WidgetRemoteSource#getCategories}. */
1333
1333
  type CategoryResponse = {
1334
- name: string;
1334
+ name: string | null;
1335
1335
  value: number;
1336
1336
  }[];
1337
1337
  /** Response from {@link WidgetRemoteSource#getRange}. */
@@ -1615,7 +1615,7 @@ declare class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePr
1615
1615
  getFeatures(): Promise<FeaturesResponse>;
1616
1616
  getFormula({ column, operation, joinOperation, filters, filterOwner, spatialFilter, }: FormulaRequestOptions): Promise<FormulaResponse>;
1617
1617
  getHistogram({ operation, ticks, column, joinOperation, filters, filterOwner, spatialFilter, }: HistogramRequestOptions): Promise<HistogramResponse>;
1618
- getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: CategoryRequestOptions): Promise<CategoryResponse>;
1618
+ getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, othersThreshold, }: CategoryRequestOptions): Promise<CategoryResponse>;
1619
1619
  getScatter({ xAxisColumn, yAxisColumn, xAxisJoinOperation, yAxisJoinOperation, filters, filterOwner, spatialFilter, }: ScatterRequestOptions): Promise<ScatterResponse>;
1620
1620
  getTable({ columns, searchFilterColumn, searchFilterText, sortBy, sortDirection, sortByColumnType, offset, limit, filters, filterOwner, spatialFilter, }: TableRequestOptions): Promise<TableResponse>;
1621
1621
  getTimeSeries({ column, stepSize, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
@@ -1826,12 +1826,13 @@ type GroupByFeature = {
1826
1826
  value: number;
1827
1827
  }[];
1828
1828
  /** @privateRemarks Source: @carto/react-core */
1829
- declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, }: {
1829
+ declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, othersThreshold, }: {
1830
1830
  data: FeatureData[];
1831
1831
  valuesColumns?: string[];
1832
1832
  joinOperation?: AggregationType;
1833
1833
  keysColumn: string;
1834
1834
  operation: AggregationType;
1835
+ othersThreshold?: number;
1835
1836
  }): GroupByFeature | null;
1836
1837
 
1837
1838
  /** @privateRemarks Source: @carto/react-core */
@@ -6677,13 +6677,17 @@ function normalizeSortByOptions({
6677
6677
  });
6678
6678
  }
6679
6679
 
6680
+ // src/widget-sources/constants.ts
6681
+ var OTHERS_CATEGORY_NAME = "_carto_others";
6682
+
6680
6683
  // src/operations/groupBy.ts
6681
6684
  function groupValuesByColumn({
6682
6685
  data,
6683
6686
  valuesColumns,
6684
6687
  joinOperation,
6685
6688
  keysColumn,
6686
- operation: operation2
6689
+ operation: operation2,
6690
+ othersThreshold
6687
6691
  }) {
6688
6692
  if (Array.isArray(data) && data.length === 0) {
6689
6693
  return null;
@@ -6701,13 +6705,23 @@ function groupValuesByColumn({
6701
6705
  return accumulator;
6702
6706
  }, /* @__PURE__ */ new Map());
6703
6707
  const targetOperation = aggregationFunctions[operation2];
6704
- if (targetOperation) {
6705
- return Array.from(groups).map(([name, value]) => ({
6706
- name,
6707
- value: targetOperation(value)
6708
- }));
6708
+ if (!targetOperation) {
6709
+ return [];
6710
+ }
6711
+ const allCategories = Array.from(groups).map(([name, value]) => ({
6712
+ name,
6713
+ value: targetOperation(value)
6714
+ }));
6715
+ allCategories.sort((a, b) => b.value - a.value);
6716
+ if (othersThreshold && allCategories.length > othersThreshold) {
6717
+ const otherNames = allCategories.map((entry) => entry.name).slice(othersThreshold);
6718
+ const otherValue = otherNames.flatMap((name) => groups.get(name));
6719
+ allCategories.push({
6720
+ name: OTHERS_CATEGORY_NAME,
6721
+ value: targetOperation(otherValue)
6722
+ });
6709
6723
  }
6710
- return [];
6724
+ return allCategories;
6711
6725
  }
6712
6726
 
6713
6727
  // src/utils/dateUtils.ts
@@ -7270,7 +7284,8 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7270
7284
  joinOperation,
7271
7285
  filters,
7272
7286
  filterOwner,
7273
- spatialFilter
7287
+ spatialFilter,
7288
+ othersThreshold
7274
7289
  }) {
7275
7290
  const filteredFeatures = this._getFilteredFeatures(
7276
7291
  spatialFilter,
@@ -7286,7 +7301,8 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7286
7301
  valuesColumns: normalizeColumns(operationColumn || column),
7287
7302
  joinOperation,
7288
7303
  keysColumn: column,
7289
- operation: operation2
7304
+ operation: operation2,
7305
+ othersThreshold
7290
7306
  });
7291
7307
  return groups || [];
7292
7308
  }
@@ -7660,9 +7676,6 @@ var WidgetTableSource = class extends WidgetRemoteSource {
7660
7676
  }
7661
7677
  };
7662
7678
 
7663
- // src/widget-sources/constants.ts
7664
- var OTHERS_CATEGORY_NAME = "_carto_others";
7665
-
7666
7679
  // src/sources/h3-query-source.ts
7667
7680
  var h3QuerySource = async function(options) {
7668
7681
  const {