@carto/api-client 0.5.7 → 0.5.8-alpha-others-orderby.1

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.
@@ -1165,6 +1165,7 @@ interface BaseRequestOptions {
1165
1165
  filters?: Filters;
1166
1166
  filterOwner?: string;
1167
1167
  }
1168
+ type CategoryOrderBy = 'frequency_asc' | 'frequency_desc' | 'alphabetical_asc' | 'alphabetical_desc';
1168
1169
  /**
1169
1170
  * Examples:
1170
1171
  * * population by state
@@ -1193,6 +1194,15 @@ interface CategoryRequestOptions extends BaseRequestOptions {
1193
1194
  operationColumn?: string;
1194
1195
  /** Local only. */
1195
1196
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1197
+ /** Calculate `_carto_others` category for all categories after first N (N is threshold). */
1198
+ othersThreshold?: number;
1199
+ /**
1200
+ * Order categories by frequency or alphabetically.
1201
+ * @default 'frequency_desc'
1202
+ */
1203
+ orderBy?: CategoryOrderBy;
1204
+ /** Return raw result (CategoryResponseRaw). */
1205
+ rawResult?: boolean;
1196
1206
  }
1197
1207
  /**
1198
1208
  * Options for {@link WidgetRemoteSource#getFeatures}.
@@ -1327,11 +1337,19 @@ type FeaturesResponse = {
1327
1337
  type FormulaResponse = {
1328
1338
  value: number | null;
1329
1339
  };
1330
- /** Response from {@link WidgetRemoteSource#getCategories}. */
1331
- type CategoryResponse = {
1332
- name: string;
1340
+ /** Entry in the category widget response, see {@link WidgetRemoteSource#getCategories}. */
1341
+ type CategoryResponseEntry = {
1342
+ name: string | null;
1333
1343
  value: number;
1334
- }[];
1344
+ };
1345
+ /** Response from {@link WidgetRemoteSource#getCategories}. */
1346
+ type CategoryResponse = CategoryResponseEntry[];
1347
+ type CategoryResponseRaw = {
1348
+ rows: CategoryResponseEntry[] | null;
1349
+ metadata?: {
1350
+ others?: number;
1351
+ };
1352
+ };
1335
1353
  /** Response from {@link WidgetRemoteSource#getRange}. */
1336
1354
  type RangeResponse = {
1337
1355
  min: number;
@@ -1613,7 +1631,7 @@ declare class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePr
1613
1631
  getFeatures(): Promise<FeaturesResponse>;
1614
1632
  getFormula({ column, operation, joinOperation, filters, filterOwner, spatialFilter, }: FormulaRequestOptions): Promise<FormulaResponse>;
1615
1633
  getHistogram({ operation, ticks, column, joinOperation, filters, filterOwner, spatialFilter, }: HistogramRequestOptions): Promise<HistogramResponse>;
1616
- getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: CategoryRequestOptions): Promise<CategoryResponse>;
1634
+ getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, othersThreshold, orderBy, rawResult, }: CategoryRequestOptions): Promise<CategoryResponse>;
1617
1635
  getScatter({ xAxisColumn, yAxisColumn, xAxisJoinOperation, yAxisJoinOperation, filters, filterOwner, spatialFilter, }: ScatterRequestOptions): Promise<ScatterResponse>;
1618
1636
  getTable({ columns, searchFilterColumn, searchFilterText, sortBy, sortDirection, sortByColumnType, offset, limit, filters, filterOwner, spatialFilter, }: TableRequestOptions): Promise<TableResponse>;
1619
1637
  getTimeSeries({ column, stepSize, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
@@ -1734,6 +1752,13 @@ declare class WidgetTableSource extends WidgetRemoteSource<LayerTableSourceOptio
1734
1752
  protected getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
1735
1753
  }
1736
1754
 
1755
+ /**
1756
+ * Name of the category that represents the "Others" category.
1757
+ *
1758
+ * See `WidgetSource.getCategories` for more information.
1759
+ */
1760
+ declare const OTHERS_CATEGORY_NAME = "_carto_others";
1761
+
1737
1762
  type H3QuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions & FilterOptions;
1738
1763
  type H3QuerySourceResponse = TilejsonResult & WidgetQuerySourceResult;
1739
1764
  declare const h3QuerySource: (options: H3QuerySourceOptions) => Promise<H3QuerySourceResponse>;
@@ -1812,19 +1837,22 @@ interface SortOptions {
1812
1837
  declare function applySorting(features: FeatureData[], { sortBy, sortByDirection, sortByColumnType, }?: SortOptions): FeatureData[];
1813
1838
 
1814
1839
  /** @privateRemarks Source: @carto/react-core */
1815
- type GroupByFeature = {
1816
- name: string;
1817
- value: number;
1818
- }[];
1819
- /** @privateRemarks Source: @carto/react-core */
1820
- declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, }: {
1840
+ declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, othersThreshold, orderBy, }: {
1821
1841
  data: FeatureData[];
1822
1842
  valuesColumns?: string[];
1823
1843
  joinOperation?: AggregationType;
1824
1844
  keysColumn: string;
1825
1845
  operation: AggregationType;
1826
- }): GroupByFeature | null;
1846
+ othersThreshold?: number;
1847
+ orderBy?: CategoryOrderBy;
1848
+ }): CategoryResponseRaw | null;
1849
+ declare function getSorter(orderBy: CategoryOrderBy): (a: CategoryResponseEntry, b: CategoryResponseEntry) => number;
1827
1850
 
1851
+ /** @privateRemarks Source: @carto/react-core */
1852
+ type GroupByFeature = {
1853
+ name: string;
1854
+ value: number;
1855
+ }[];
1828
1856
  /** @privateRemarks Source: @carto/react-core */
1829
1857
  declare function groupValuesByDateColumn({ data, valuesColumns, joinOperation, keysColumn, groupType, operation, }: {
1830
1858
  data: Record<string, unknown>[];
@@ -1921,4 +1949,4 @@ declare function getColumnNameFromGeoColumn(geoColumn: string | null | undefined
1921
1949
  */
1922
1950
  declare function getSpatialIndexFromGeoColumn(geoColumn: string): SpatialIndex | null;
1923
1951
 
1924
- export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, AggregationTypes, ApiVersion, type Attribute, _default as BASEMAP, type BaseRequestOptions, type Basemap, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryRequestOptions, type CategoryResponse, CellSet, type ColumnsOption, type D3Scale, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type FetchMapOptions, type FetchMapResult, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, type FilterOptions, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GetFilterOptions, type GoogleBasemap, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type KeplerMapConfig, type Layer, type LayerDescriptor, type LayerType, type MapLibreBasemap, type MapType, type NamedQueryParameter, OPACITY_MAP, type ParseMapResult, type PositionalQueryParameter, Provider, type ProviderType, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterBandType, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RasterTile, type RemoveFilterOptions, SOURCE_DEFAULTS, type Scale, type ScaleKey, type ScaleType, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SchemaField, SchemaFieldType, type SortColumnType, type SortDirection, type SourceOptionalOptions, type SourceOptions, type SourceRequiredOptions, type SpatialDataType, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, SpatialIndexColumn, type SpatialIndexTile, type StringSearchOptions, TEXT_LABEL_INDEX, TEXT_NUMBER_FORMATTER, TEXT_OUTLINE_OPACITY, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type Tilejson, type TilejsonResult, type TilesetSourceOptions, type Tilestats, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRasterSource, type WidgetRasterSourceProps, type WidgetRasterSourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, type _DataFilterExtensionProps, _buildFeatureFilter, domainFromValues as _domainFromValues, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, calculateClusterRadius, calculateClusterTextFontSize, clearDefaultRequestCache, clearFilters, configureSource, createPolygonSpatialFilter, createViewportSpatialFilter, fetchBasemapProps, fetchMap, filterFunctions, geojsonFeatures, getApplicableFilters, getClient, getColorAccessor, getColumnNameFromGeoColumn, getDataFilterExtensionProps, getDefaultAggregationExpColumnAliasForLayerType, getFilter, getIconUrlAccessor, getLayerProps, getMaxMarkerSize, getSizeAccessor, getSpatialIndexFromGeoColumn, getTextAccessor, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, negateAccessor, opacityToAlpha, parseMap, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scaleAggregationResLevel, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
1952
+ export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, AggregationTypes, ApiVersion, type Attribute, _default as BASEMAP, type BaseRequestOptions, type Basemap, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryOrderBy, type CategoryRequestOptions, type CategoryResponse, type CategoryResponseEntry, type CategoryResponseRaw, CellSet, type ColumnsOption, type D3Scale, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type FetchMapOptions, type FetchMapResult, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, type FilterOptions, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GetFilterOptions, type GoogleBasemap, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type KeplerMapConfig, type Layer, type LayerDescriptor, type LayerType, type MapLibreBasemap, type MapType, type NamedQueryParameter, OPACITY_MAP, OTHERS_CATEGORY_NAME, type ParseMapResult, type PositionalQueryParameter, Provider, type ProviderType, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterBandType, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RasterTile, type RemoveFilterOptions, SOURCE_DEFAULTS, type Scale, type ScaleKey, type ScaleType, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SchemaField, SchemaFieldType, type SortColumnType, type SortDirection, type SourceOptionalOptions, type SourceOptions, type SourceRequiredOptions, type SpatialDataType, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, SpatialIndexColumn, type SpatialIndexTile, type StringSearchOptions, TEXT_LABEL_INDEX, TEXT_NUMBER_FORMATTER, TEXT_OUTLINE_OPACITY, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type Tilejson, type TilejsonResult, type TilesetSourceOptions, type Tilestats, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRasterSource, type WidgetRasterSourceProps, type WidgetRasterSourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, type _DataFilterExtensionProps, _buildFeatureFilter, domainFromValues as _domainFromValues, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, calculateClusterRadius, calculateClusterTextFontSize, clearDefaultRequestCache, clearFilters, configureSource, createPolygonSpatialFilter, createViewportSpatialFilter, fetchBasemapProps, fetchMap, filterFunctions, geojsonFeatures, getApplicableFilters, getClient, getColorAccessor, getColumnNameFromGeoColumn, getDataFilterExtensionProps, getDefaultAggregationExpColumnAliasForLayerType, getFilter, getIconUrlAccessor, getLayerProps, getMaxMarkerSize, getSizeAccessor, getSorter, getSpatialIndexFromGeoColumn, getTextAccessor, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, negateAccessor, opacityToAlpha, parseMap, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scaleAggregationResLevel, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
@@ -1165,6 +1165,7 @@ interface BaseRequestOptions {
1165
1165
  filters?: Filters;
1166
1166
  filterOwner?: string;
1167
1167
  }
1168
+ type CategoryOrderBy = 'frequency_asc' | 'frequency_desc' | 'alphabetical_asc' | 'alphabetical_desc';
1168
1169
  /**
1169
1170
  * Examples:
1170
1171
  * * population by state
@@ -1193,6 +1194,15 @@ interface CategoryRequestOptions extends BaseRequestOptions {
1193
1194
  operationColumn?: string;
1194
1195
  /** Local only. */
1195
1196
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1197
+ /** Calculate `_carto_others` category for all categories after first N (N is threshold). */
1198
+ othersThreshold?: number;
1199
+ /**
1200
+ * Order categories by frequency or alphabetically.
1201
+ * @default 'frequency_desc'
1202
+ */
1203
+ orderBy?: CategoryOrderBy;
1204
+ /** Return raw result (CategoryResponseRaw). */
1205
+ rawResult?: boolean;
1196
1206
  }
1197
1207
  /**
1198
1208
  * Options for {@link WidgetRemoteSource#getFeatures}.
@@ -1327,11 +1337,19 @@ type FeaturesResponse = {
1327
1337
  type FormulaResponse = {
1328
1338
  value: number | null;
1329
1339
  };
1330
- /** Response from {@link WidgetRemoteSource#getCategories}. */
1331
- type CategoryResponse = {
1332
- name: string;
1340
+ /** Entry in the category widget response, see {@link WidgetRemoteSource#getCategories}. */
1341
+ type CategoryResponseEntry = {
1342
+ name: string | null;
1333
1343
  value: number;
1334
- }[];
1344
+ };
1345
+ /** Response from {@link WidgetRemoteSource#getCategories}. */
1346
+ type CategoryResponse = CategoryResponseEntry[];
1347
+ type CategoryResponseRaw = {
1348
+ rows: CategoryResponseEntry[] | null;
1349
+ metadata?: {
1350
+ others?: number;
1351
+ };
1352
+ };
1335
1353
  /** Response from {@link WidgetRemoteSource#getRange}. */
1336
1354
  type RangeResponse = {
1337
1355
  min: number;
@@ -1613,7 +1631,7 @@ declare class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePr
1613
1631
  getFeatures(): Promise<FeaturesResponse>;
1614
1632
  getFormula({ column, operation, joinOperation, filters, filterOwner, spatialFilter, }: FormulaRequestOptions): Promise<FormulaResponse>;
1615
1633
  getHistogram({ operation, ticks, column, joinOperation, filters, filterOwner, spatialFilter, }: HistogramRequestOptions): Promise<HistogramResponse>;
1616
- getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: CategoryRequestOptions): Promise<CategoryResponse>;
1634
+ getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, othersThreshold, orderBy, rawResult, }: CategoryRequestOptions): Promise<CategoryResponse>;
1617
1635
  getScatter({ xAxisColumn, yAxisColumn, xAxisJoinOperation, yAxisJoinOperation, filters, filterOwner, spatialFilter, }: ScatterRequestOptions): Promise<ScatterResponse>;
1618
1636
  getTable({ columns, searchFilterColumn, searchFilterText, sortBy, sortDirection, sortByColumnType, offset, limit, filters, filterOwner, spatialFilter, }: TableRequestOptions): Promise<TableResponse>;
1619
1637
  getTimeSeries({ column, stepSize, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
@@ -1734,6 +1752,13 @@ declare class WidgetTableSource extends WidgetRemoteSource<LayerTableSourceOptio
1734
1752
  protected getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
1735
1753
  }
1736
1754
 
1755
+ /**
1756
+ * Name of the category that represents the "Others" category.
1757
+ *
1758
+ * See `WidgetSource.getCategories` for more information.
1759
+ */
1760
+ declare const OTHERS_CATEGORY_NAME = "_carto_others";
1761
+
1737
1762
  type H3QuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions & FilterOptions;
1738
1763
  type H3QuerySourceResponse = TilejsonResult & WidgetQuerySourceResult;
1739
1764
  declare const h3QuerySource: (options: H3QuerySourceOptions) => Promise<H3QuerySourceResponse>;
@@ -1812,19 +1837,22 @@ interface SortOptions {
1812
1837
  declare function applySorting(features: FeatureData[], { sortBy, sortByDirection, sortByColumnType, }?: SortOptions): FeatureData[];
1813
1838
 
1814
1839
  /** @privateRemarks Source: @carto/react-core */
1815
- type GroupByFeature = {
1816
- name: string;
1817
- value: number;
1818
- }[];
1819
- /** @privateRemarks Source: @carto/react-core */
1820
- declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, }: {
1840
+ declare function groupValuesByColumn({ data, valuesColumns, joinOperation, keysColumn, operation, othersThreshold, orderBy, }: {
1821
1841
  data: FeatureData[];
1822
1842
  valuesColumns?: string[];
1823
1843
  joinOperation?: AggregationType;
1824
1844
  keysColumn: string;
1825
1845
  operation: AggregationType;
1826
- }): GroupByFeature | null;
1846
+ othersThreshold?: number;
1847
+ orderBy?: CategoryOrderBy;
1848
+ }): CategoryResponseRaw | null;
1849
+ declare function getSorter(orderBy: CategoryOrderBy): (a: CategoryResponseEntry, b: CategoryResponseEntry) => number;
1827
1850
 
1851
+ /** @privateRemarks Source: @carto/react-core */
1852
+ type GroupByFeature = {
1853
+ name: string;
1854
+ value: number;
1855
+ }[];
1828
1856
  /** @privateRemarks Source: @carto/react-core */
1829
1857
  declare function groupValuesByDateColumn({ data, valuesColumns, joinOperation, keysColumn, groupType, operation, }: {
1830
1858
  data: Record<string, unknown>[];
@@ -1921,4 +1949,4 @@ declare function getColumnNameFromGeoColumn(geoColumn: string | null | undefined
1921
1949
  */
1922
1950
  declare function getSpatialIndexFromGeoColumn(geoColumn: string): SpatialIndex | null;
1923
1951
 
1924
- export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, AggregationTypes, ApiVersion, type Attribute, _default as BASEMAP, type BaseRequestOptions, type Basemap, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryRequestOptions, type CategoryResponse, CellSet, type ColumnsOption, type D3Scale, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type FetchMapOptions, type FetchMapResult, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, type FilterOptions, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GetFilterOptions, type GoogleBasemap, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type KeplerMapConfig, type Layer, type LayerDescriptor, type LayerType, type MapLibreBasemap, type MapType, type NamedQueryParameter, OPACITY_MAP, type ParseMapResult, type PositionalQueryParameter, Provider, type ProviderType, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterBandType, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RasterTile, type RemoveFilterOptions, SOURCE_DEFAULTS, type Scale, type ScaleKey, type ScaleType, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SchemaField, SchemaFieldType, type SortColumnType, type SortDirection, type SourceOptionalOptions, type SourceOptions, type SourceRequiredOptions, type SpatialDataType, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, SpatialIndexColumn, type SpatialIndexTile, type StringSearchOptions, TEXT_LABEL_INDEX, TEXT_NUMBER_FORMATTER, TEXT_OUTLINE_OPACITY, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type Tilejson, type TilejsonResult, type TilesetSourceOptions, type Tilestats, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRasterSource, type WidgetRasterSourceProps, type WidgetRasterSourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, type _DataFilterExtensionProps, _buildFeatureFilter, domainFromValues as _domainFromValues, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, calculateClusterRadius, calculateClusterTextFontSize, clearDefaultRequestCache, clearFilters, configureSource, createPolygonSpatialFilter, createViewportSpatialFilter, fetchBasemapProps, fetchMap, filterFunctions, geojsonFeatures, getApplicableFilters, getClient, getColorAccessor, getColumnNameFromGeoColumn, getDataFilterExtensionProps, getDefaultAggregationExpColumnAliasForLayerType, getFilter, getIconUrlAccessor, getLayerProps, getMaxMarkerSize, getSizeAccessor, getSpatialIndexFromGeoColumn, getTextAccessor, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, negateAccessor, opacityToAlpha, parseMap, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scaleAggregationResLevel, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
1952
+ export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, AggregationTypes, ApiVersion, type Attribute, _default as BASEMAP, type BaseRequestOptions, type Basemap, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryOrderBy, type CategoryRequestOptions, type CategoryResponse, type CategoryResponseEntry, type CategoryResponseRaw, CellSet, type ColumnsOption, type D3Scale, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type FetchMapOptions, type FetchMapResult, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, type FilterOptions, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GetFilterOptions, type GoogleBasemap, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type KeplerMapConfig, type Layer, type LayerDescriptor, type LayerType, type MapLibreBasemap, type MapType, type NamedQueryParameter, OPACITY_MAP, OTHERS_CATEGORY_NAME, type ParseMapResult, type PositionalQueryParameter, Provider, type ProviderType, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterBandType, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RasterTile, type RemoveFilterOptions, SOURCE_DEFAULTS, type Scale, type ScaleKey, type ScaleType, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SchemaField, SchemaFieldType, type SortColumnType, type SortDirection, type SourceOptionalOptions, type SourceOptions, type SourceRequiredOptions, type SpatialDataType, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, SpatialIndexColumn, type SpatialIndexTile, type StringSearchOptions, TEXT_LABEL_INDEX, TEXT_NUMBER_FORMATTER, TEXT_OUTLINE_OPACITY, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type Tilejson, type TilejsonResult, type TilesetSourceOptions, type Tilestats, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRasterSource, type WidgetRasterSourceProps, type WidgetRasterSourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, type _DataFilterExtensionProps, _buildFeatureFilter, domainFromValues as _domainFromValues, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, calculateClusterRadius, calculateClusterTextFontSize, clearDefaultRequestCache, clearFilters, configureSource, createPolygonSpatialFilter, createViewportSpatialFilter, fetchBasemapProps, fetchMap, filterFunctions, geojsonFeatures, getApplicableFilters, getClient, getColorAccessor, getColumnNameFromGeoColumn, getDataFilterExtensionProps, getDefaultAggregationExpColumnAliasForLayerType, getFilter, getIconUrlAccessor, getLayerProps, getMaxMarkerSize, getSizeAccessor, getSorter, getSpatialIndexFromGeoColumn, getTextAccessor, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, negateAccessor, opacityToAlpha, parseMap, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scaleAggregationResLevel, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
@@ -6292,6 +6292,9 @@ function getApplicableFilters(owner, filters) {
6292
6292
  return applicableFilters;
6293
6293
  }
6294
6294
 
6295
+ // src/widget-sources/constants.ts
6296
+ var OTHERS_CATEGORY_NAME = "_carto_others";
6297
+
6295
6298
  // src/widget-sources/widget-remote-source.ts
6296
6299
  var WidgetRemoteSource = class extends WidgetSource {
6297
6300
  _getModelSource(filters, filterOwner) {
@@ -6315,13 +6318,21 @@ var WidgetRemoteSource = class extends WidgetSource {
6315
6318
  filterOwner,
6316
6319
  spatialFilter,
6317
6320
  spatialFiltersMode,
6321
+ rawResult,
6318
6322
  ...params
6319
6323
  } = options;
6320
- const { column, operation: operation2, operationColumn, operationExp } = params;
6324
+ const {
6325
+ column,
6326
+ operation: operation2,
6327
+ operationColumn,
6328
+ operationExp,
6329
+ othersThreshold,
6330
+ orderBy
6331
+ } = params;
6321
6332
  if (operation2 === AggregationTypes.Custom) {
6322
6333
  assert2(operationExp, "operationExp is required for custom operation");
6323
6334
  }
6324
- return executeModel({
6335
+ const result = await executeModel({
6325
6336
  model: "category",
6326
6337
  source: {
6327
6338
  ...this.getModelSource(filters, filterOwner),
@@ -6332,10 +6343,23 @@ var WidgetRemoteSource = class extends WidgetSource {
6332
6343
  column,
6333
6344
  operation: operation2,
6334
6345
  operationExp,
6335
- operationColumn: operationColumn || column
6346
+ operationColumn: operationColumn || column,
6347
+ othersThreshold,
6348
+ orderBy
6336
6349
  },
6337
6350
  opts: { signal, headers: this.props.headers }
6338
- }).then((res) => normalizeObjectKeys(res.rows));
6351
+ });
6352
+ const normalizedRows = normalizeObjectKeys(result.rows || []);
6353
+ if (rawResult) {
6354
+ return result;
6355
+ }
6356
+ if (!othersThreshold) {
6357
+ return normalizedRows;
6358
+ }
6359
+ return [
6360
+ ...normalizedRows,
6361
+ { name: OTHERS_CATEGORY_NAME, value: result?.metadata?.others }
6362
+ ];
6339
6363
  }
6340
6364
  async getFeatures(options) {
6341
6365
  const {
@@ -6728,10 +6752,12 @@ function groupValuesByColumn({
6728
6752
  valuesColumns,
6729
6753
  joinOperation,
6730
6754
  keysColumn,
6731
- operation: operation2
6755
+ operation: operation2,
6756
+ othersThreshold,
6757
+ orderBy = "frequency_desc"
6732
6758
  }) {
6733
6759
  if (Array.isArray(data) && data.length === 0) {
6734
- return null;
6760
+ return { rows: null };
6735
6761
  }
6736
6762
  const groups = data.reduce((accumulator, item) => {
6737
6763
  const group2 = item[keysColumn];
@@ -6746,13 +6772,44 @@ function groupValuesByColumn({
6746
6772
  return accumulator;
6747
6773
  }, /* @__PURE__ */ new Map());
6748
6774
  const targetOperation = aggregationFunctions[operation2];
6749
- if (targetOperation) {
6750
- return Array.from(groups).map(([name, value]) => ({
6751
- name,
6752
- value: targetOperation(value)
6753
- }));
6775
+ if (!targetOperation) {
6776
+ return { rows: [] };
6777
+ }
6778
+ const allCategories = Array.from(groups).map(([name, value]) => ({
6779
+ name,
6780
+ value: targetOperation(value)
6781
+ })).sort(getSorter(orderBy));
6782
+ if (othersThreshold && allCategories.length > othersThreshold) {
6783
+ const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
6784
+ allCategories.push({
6785
+ name: OTHERS_CATEGORY_NAME,
6786
+ value: targetOperation(otherValue)
6787
+ });
6788
+ return {
6789
+ rows: allCategories,
6790
+ metadata: {
6791
+ others: targetOperation(otherValue)
6792
+ }
6793
+ };
6794
+ }
6795
+ return {
6796
+ rows: allCategories
6797
+ };
6798
+ }
6799
+ function getSorter(orderBy) {
6800
+ switch (orderBy) {
6801
+ case "frequency_asc":
6802
+ return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
6803
+ case "frequency_desc":
6804
+ return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
6805
+ case "alphabetical_asc":
6806
+ return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
6807
+ case "alphabetical_desc":
6808
+ return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
6754
6809
  }
6755
- return [];
6810
+ }
6811
+ function localeCompare(a, b) {
6812
+ return (a ?? "null").localeCompare(b ?? "null");
6756
6813
  }
6757
6814
 
6758
6815
  // src/utils/dateUtils.ts
@@ -7315,7 +7372,10 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7315
7372
  joinOperation,
7316
7373
  filters,
7317
7374
  filterOwner,
7318
- spatialFilter
7375
+ spatialFilter,
7376
+ othersThreshold,
7377
+ orderBy = "frequency_desc",
7378
+ rawResult
7319
7379
  }) {
7320
7380
  const filteredFeatures = this._getFilteredFeatures(
7321
7381
  spatialFilter,
@@ -7326,14 +7386,25 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7326
7386
  return [];
7327
7387
  }
7328
7388
  assertColumn(this._features, column, operationColumn);
7329
- const groups = groupValuesByColumn({
7389
+ const result = groupValuesByColumn({
7330
7390
  data: filteredFeatures,
7331
7391
  valuesColumns: normalizeColumns(operationColumn || column),
7332
7392
  joinOperation,
7333
7393
  keysColumn: column,
7334
- operation: operation2
7394
+ operation: operation2,
7395
+ othersThreshold,
7396
+ orderBy
7335
7397
  });
7336
- return groups || [];
7398
+ if (rawResult) {
7399
+ return result;
7400
+ }
7401
+ if (!othersThreshold) {
7402
+ return result?.rows || [];
7403
+ }
7404
+ return [
7405
+ ...result?.rows || [],
7406
+ { name: OTHERS_CATEGORY_NAME, value: result?.metadata?.others }
7407
+ ];
7337
7408
  }
7338
7409
  async getScatter({
7339
7410
  xAxisColumn,
@@ -10079,6 +10150,7 @@ export {
10079
10150
  FEATURE_GEOM_PROPERTY,
10080
10151
  FilterType,
10081
10152
  OPACITY_MAP,
10153
+ OTHERS_CATEGORY_NAME,
10082
10154
  Provider,
10083
10155
  SOURCE_DEFAULTS,
10084
10156
  SchemaFieldType,
@@ -10129,6 +10201,7 @@ export {
10129
10201
  getLayerProps,
10130
10202
  getMaxMarkerSize,
10131
10203
  getSizeAccessor,
10204
+ getSorter,
10132
10205
  getSpatialIndexFromGeoColumn,
10133
10206
  getTextAccessor,
10134
10207
  groupValuesByColumn,