@carto/api-client 0.5.1 → 0.5.2-alpha.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.
Files changed (65) hide show
  1. package/build/api-client.cjs +194 -84
  2. package/build/api-client.cjs.map +1 -1
  3. package/build/api-client.d.cts +28 -1
  4. package/build/api-client.d.ts +28 -1
  5. package/build/api-client.js +186 -83
  6. package/build/api-client.js.map +1 -1
  7. package/build/worker.js +30 -19
  8. package/build/worker.js.map +1 -1
  9. package/package.json +5 -3
  10. package/src/api/carto-api-error.ts +1 -1
  11. package/src/api/endpoints.ts +1 -1
  12. package/src/api/index.ts +2 -2
  13. package/src/api/query.ts +1 -1
  14. package/src/api/request-with-parameters.ts +2 -2
  15. package/src/deck/get-data-filter-extension-props.ts +3 -3
  16. package/src/fetch-map/basemap-styles.ts +2 -2
  17. package/src/fetch-map/basemap.ts +2 -2
  18. package/src/fetch-map/fetch-map.ts +3 -3
  19. package/src/fetch-map/layer-map.ts +81 -5
  20. package/src/fetch-map/parse-map.ts +71 -7
  21. package/src/fetch-map/source.ts +10 -10
  22. package/src/fetch-map/types.ts +7 -3
  23. package/src/filters/Filter.ts +4 -4
  24. package/src/filters/FilterTypes.ts +1 -1
  25. package/src/filters/geosjonFeatures.ts +3 -3
  26. package/src/filters/tileFeatures.ts +8 -3
  27. package/src/filters/tileFeaturesGeometries.ts +5 -5
  28. package/src/filters/tileFeaturesRaster.ts +3 -3
  29. package/src/filters/tileFeaturesSpatialIndex.ts +4 -4
  30. package/src/filters.ts +38 -3
  31. package/src/geo.ts +1 -1
  32. package/src/index.ts +3 -3
  33. package/src/models/model.ts +6 -3
  34. package/src/operations/aggregation.ts +14 -4
  35. package/src/operations/applySorting.ts +2 -2
  36. package/src/operations/groupBy.ts +2 -2
  37. package/src/operations/groupByDate.ts +2 -2
  38. package/src/operations/histogram.ts +2 -2
  39. package/src/operations/scatterPlot.ts +2 -2
  40. package/src/sources/base-source.ts +2 -2
  41. package/src/sources/boundary-query-source.ts +1 -1
  42. package/src/sources/h3-query-source.ts +1 -1
  43. package/src/sources/h3-table-source.ts +1 -1
  44. package/src/sources/h3-tileset-source.ts +1 -1
  45. package/src/sources/quadbin-query-source.ts +1 -1
  46. package/src/sources/quadbin-table-source.ts +1 -1
  47. package/src/sources/quadbin-tileset-source.ts +1 -1
  48. package/src/sources/raster-source.ts +1 -1
  49. package/src/sources/types.ts +2 -2
  50. package/src/sources/vector-query-source.ts +1 -1
  51. package/src/sources/vector-table-source.ts +1 -1
  52. package/src/sources/vector-tileset-source.ts +1 -1
  53. package/src/utils/getTileFormat.ts +1 -1
  54. package/src/utils/makeIntervalComplete.ts +1 -1
  55. package/src/utils/transformTileCoordsToWGS84.ts +1 -1
  56. package/src/utils/transformToTileCoords.ts +1 -1
  57. package/src/utils.ts +1 -1
  58. package/src/widget-sources/types.ts +5 -2
  59. package/src/widget-sources/widget-query-source.ts +4 -4
  60. package/src/widget-sources/widget-raster-source.ts +2 -2
  61. package/src/widget-sources/widget-remote-source.ts +6 -5
  62. package/src/widget-sources/widget-source.ts +3 -3
  63. package/src/widget-sources/widget-table-source.ts +4 -4
  64. package/src/widget-sources/widget-tileset-source-impl.ts +8 -11
  65. package/src/widget-sources/widget-tileset-source.ts +7 -7
@@ -5510,6 +5510,9 @@ __export(src_exports, {
5510
5510
  SOURCE_DEFAULTS: () => SOURCE_DEFAULTS,
5511
5511
  SpatialIndex: () => SpatialIndex,
5512
5512
  SpatialIndexColumn: () => SpatialIndexColumn,
5513
+ TEXT_LABEL_INDEX: () => TEXT_LABEL_INDEX,
5514
+ TEXT_NUMBER_FORMATTER: () => TEXT_NUMBER_FORMATTER,
5515
+ TEXT_OUTLINE_OPACITY: () => TEXT_OUTLINE_OPACITY,
5513
5516
  TileFormat: () => TileFormat,
5514
5517
  WidgetQuerySource: () => WidgetQuerySource,
5515
5518
  WidgetRasterSource: () => WidgetRasterSource,
@@ -5530,6 +5533,8 @@ __export(src_exports, {
5530
5533
  buildBinaryFeatureFilter: () => buildBinaryFeatureFilter,
5531
5534
  buildPublicMapUrl: () => buildPublicMapUrl,
5532
5535
  buildStatsUrl: () => buildStatsUrl,
5536
+ calculateClusterRadius: () => calculateClusterRadius,
5537
+ calculateClusterTextFontSize: () => calculateClusterTextFontSize,
5533
5538
  clearFilters: () => clearFilters,
5534
5539
  configureSource: () => configureSource,
5535
5540
  createPolygonSpatialFilter: () => createPolygonSpatialFilter,
@@ -5538,11 +5543,13 @@ __export(src_exports, {
5538
5543
  fetchMap: () => fetchMap,
5539
5544
  filterFunctions: () => filterFunctions,
5540
5545
  geojsonFeatures: () => geojsonFeatures,
5546
+ getApplicableFilters: () => getApplicableFilters,
5541
5547
  getClient: () => getClient,
5542
5548
  getColorAccessor: () => getColorAccessor,
5543
5549
  getColorValueAccessor: () => getColorValueAccessor,
5544
5550
  getColumnNameFromGeoColumn: () => getColumnNameFromGeoColumn,
5545
5551
  getDataFilterExtensionProps: () => getDataFilterExtensionProps,
5552
+ getDefaultAggregationExpColumnAliasForLayerType: () => getDefaultAggregationExpColumnAliasForLayerType,
5546
5553
  getFilter: () => getFilter,
5547
5554
  getIconUrlAccessor: () => getIconUrlAccessor,
5548
5555
  getLayerProps: () => getLayerProps,
@@ -11097,23 +11104,6 @@ function isValidBandValue(value, nodata) {
11097
11104
  // src/utils.ts
11098
11105
  init_cjs_shims();
11099
11106
  var FILTER_TYPES = new Set(Object.values(FilterType));
11100
- var isFilterType = (type) => FILTER_TYPES.has(type);
11101
- function getApplicableFilters(owner, filters) {
11102
- if (!filters) return {};
11103
- const applicableFilters = {};
11104
- for (const column in filters) {
11105
- for (const type in filters[column]) {
11106
- if (!isFilterType(type)) continue;
11107
- const filter = filters[column][type];
11108
- const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
11109
- if (filter && isApplicable) {
11110
- applicableFilters[column] || (applicableFilters[column] = {});
11111
- applicableFilters[column][type] = filter;
11112
- }
11113
- }
11114
- }
11115
- return applicableFilters;
11116
- }
11117
11107
  function normalizeObjectKeys(el) {
11118
11108
  if (Array.isArray(el)) {
11119
11109
  return el.map((value) => normalizeObjectKeys(value));
@@ -11800,6 +11790,83 @@ function objectToURLSearchParams(object) {
11800
11790
  return params;
11801
11791
  }
11802
11792
 
11793
+ // src/filters.ts
11794
+ init_cjs_shims();
11795
+ var FILTER_TYPES2 = new Set(Object.values(FilterType));
11796
+ var isFilterType = (type) => FILTER_TYPES2.has(type);
11797
+ function addFilter(filters, { column, type, values, owner }) {
11798
+ if (!filters[column]) {
11799
+ filters[column] = {};
11800
+ }
11801
+ const filter = { values, owner };
11802
+ filters[column][type] = filter;
11803
+ return filters;
11804
+ }
11805
+ function removeFilter(filters, { column, owner }) {
11806
+ const filter = filters[column];
11807
+ if (!filter) {
11808
+ return filters;
11809
+ }
11810
+ if (owner) {
11811
+ for (const type of FILTER_TYPES2) {
11812
+ if (owner === filter[type]?.owner) {
11813
+ delete filter[type];
11814
+ }
11815
+ }
11816
+ }
11817
+ if (!owner || isEmptyObject(filter)) {
11818
+ delete filters[column];
11819
+ }
11820
+ return filters;
11821
+ }
11822
+ function clearFilters(filters) {
11823
+ for (const column of Object.keys(filters)) {
11824
+ delete filters[column];
11825
+ }
11826
+ return filters;
11827
+ }
11828
+ function hasFilter(filters, { column, owner }) {
11829
+ const filter = filters[column];
11830
+ if (!filter) {
11831
+ return false;
11832
+ }
11833
+ if (!owner) {
11834
+ return true;
11835
+ }
11836
+ for (const type of FILTER_TYPES2) {
11837
+ if (owner === filter[type]?.owner) {
11838
+ return true;
11839
+ }
11840
+ }
11841
+ return false;
11842
+ }
11843
+ function getFilter(filters, { column, type, owner }) {
11844
+ const filter = filters[column];
11845
+ if (!filter) {
11846
+ return null;
11847
+ }
11848
+ if (!owner || owner === filter[type]?.owner) {
11849
+ return filter[type] || null;
11850
+ }
11851
+ return null;
11852
+ }
11853
+ function getApplicableFilters(owner, filters) {
11854
+ if (!filters) return {};
11855
+ const applicableFilters = {};
11856
+ for (const column in filters) {
11857
+ for (const type in filters[column]) {
11858
+ if (!isFilterType(type)) continue;
11859
+ const filter = filters[column][type];
11860
+ const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
11861
+ if (filter && isApplicable) {
11862
+ applicableFilters[column] || (applicableFilters[column] = {});
11863
+ applicableFilters[column][type] = filter;
11864
+ }
11865
+ }
11866
+ }
11867
+ return applicableFilters;
11868
+ }
11869
+
11803
11870
  // src/widget-sources/widget-remote-source.ts
11804
11871
  var WidgetRemoteSource = class extends WidgetSource {
11805
11872
  _getModelSource(filters, filterOwner) {
@@ -12135,7 +12202,11 @@ function min(values, keys, joinOperation) {
12135
12202
  Infinity
12136
12203
  );
12137
12204
  }
12138
- return Math.min(...values);
12205
+ let min3 = Number.POSITIVE_INFINITY;
12206
+ for (const value of values) {
12207
+ min3 = Math.min(min3, value);
12208
+ }
12209
+ return min3;
12139
12210
  }
12140
12211
  function max(values, keys, joinOperation) {
12141
12212
  const normalizedKeys = normalizeKeys(keys);
@@ -12145,7 +12216,11 @@ function max(values, keys, joinOperation) {
12145
12216
  -Infinity
12146
12217
  );
12147
12218
  }
12148
- return Math.max(...values);
12219
+ let max3 = Number.NEGATIVE_INFINITY;
12220
+ for (const value of values) {
12221
+ max3 = Math.max(max3, value);
12222
+ }
12223
+ return max3;
12149
12224
  }
12150
12225
  function normalizeKeys(keys) {
12151
12226
  return Array.isArray(keys) ? keys : typeof keys === "string" ? [keys] : void 0;
@@ -14497,7 +14572,8 @@ var customMarkersPropsMap = {
14497
14572
  var heatmapTilePropsMap = {
14498
14573
  visConfig: {
14499
14574
  colorRange: (x) => ({ colorRange: x.colors.map(hexToRGBA) }),
14500
- radius: "radiusPixels"
14575
+ radius: (radius) => ({ radiusPixels: 20 + radius }),
14576
+ opacity: "opacity"
14501
14577
  }
14502
14578
  };
14503
14579
  var defaultProps = {
@@ -14518,6 +14594,12 @@ var deprecatedLayerTypes = [
14518
14594
  "hexagonId",
14519
14595
  "point"
14520
14596
  ];
14597
+ var TEXT_LABEL_INDEX = 0;
14598
+ var TEXT_OUTLINE_OPACITY = 64;
14599
+ var TEXT_NUMBER_FORMATTER = new Intl.NumberFormat("en-US", {
14600
+ maximumFractionDigits: 2,
14601
+ notation: "compact"
14602
+ });
14521
14603
  function getLayerProps(type, config2, dataset) {
14522
14604
  if (deprecatedLayerTypes.includes(type)) {
14523
14605
  throw new Error(
@@ -14609,9 +14691,7 @@ function findAccessorKey(keys, properties) {
14609
14691
  return [key];
14610
14692
  }
14611
14693
  }
14612
- throw new Error(
14613
- `Could not find property for any accessor key: ${keys.join(", ")}`
14614
- );
14694
+ return keys;
14615
14695
  }
14616
14696
  function getColorValueAccessor({ name }, colorAggregation, data) {
14617
14697
  const aggregator = AGGREGATION_FUNC[colorAggregation];
@@ -14738,6 +14818,40 @@ function getTextAccessor({ name, type }, data) {
14738
14818
  };
14739
14819
  return normalizeAccessor(accessor, data);
14740
14820
  }
14821
+ function calculateClusterRadius(properties, stats, radiusRange, column) {
14822
+ const { min: min3, max: max3 } = stats[column];
14823
+ const value = properties[column];
14824
+ if (min3 === max3) return radiusRange[1];
14825
+ const normalizedValue = (value - min3) / (max3 - min3);
14826
+ return radiusRange[0] + normalizedValue * (radiusRange[1] - radiusRange[0]);
14827
+ }
14828
+ function getDefaultAggregationExpColumnAliasForLayerType(layerType, provider, columns) {
14829
+ if (columns && layerType === "clusterTile") {
14830
+ return getColumnAliasForAggregationExp(
14831
+ getDefaultColumnFromSchemaForAggregationExp(columns),
14832
+ "count",
14833
+ provider
14834
+ );
14835
+ } else {
14836
+ return DEFAULT_AGGREGATION_EXP_ALIAS;
14837
+ }
14838
+ }
14839
+ function getColumnAliasForAggregationExp(name, aggregation, provider) {
14840
+ const columnAlias = `${name}_${aggregation}`;
14841
+ return provider === "snowflake" ? columnAlias.toUpperCase() : columnAlias;
14842
+ }
14843
+ function getDefaultColumnFromSchemaForAggregationExp(columns) {
14844
+ return columns ? columns[0] : "";
14845
+ }
14846
+ function calculateClusterTextFontSize(radius) {
14847
+ if (radius >= 80) return 24;
14848
+ if (radius >= 72) return 24;
14849
+ if (radius >= 56) return 20;
14850
+ if (radius >= 40) return 16;
14851
+ if (radius >= 24) return 13;
14852
+ if (radius >= 8) return 11;
14853
+ return 11;
14854
+ }
14741
14855
 
14742
14856
  // src/fetch-map/parse-map.ts
14743
14857
  function parseMap(json) {
@@ -14778,7 +14892,14 @@ function parseMap(json) {
14778
14892
  ...defaultProps2,
14779
14893
  ...createInteractionProps(interactionConfig),
14780
14894
  ...styleProps,
14781
- ...createChannelProps(id, type, config3, visualChannels, data),
14895
+ ...createChannelProps(
14896
+ id,
14897
+ type,
14898
+ config3,
14899
+ visualChannels,
14900
+ data,
14901
+ dataset
14902
+ ),
14782
14903
  // Must come after style
14783
14904
  ...createParametersProp(
14784
14905
  layerBlending,
@@ -14853,7 +14974,7 @@ function createStyleProps(config2, mapping) {
14853
14974
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
14854
14975
  return result;
14855
14976
  }
14856
- function createChannelProps(id, type, config2, visualChannels, data) {
14977
+ function createChannelProps(id, type, config2, visualChannels, data, dataset) {
14857
14978
  const {
14858
14979
  colorField,
14859
14980
  colorScale,
@@ -14913,6 +15034,47 @@ function createChannelProps(id, type, config2, visualChannels, data) {
14913
15034
  };
14914
15035
  }
14915
15036
  }
15037
+ if (type === "clusterTile") {
15038
+ const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
15039
+ type,
15040
+ dataset.providerId,
15041
+ dataset.columns
15042
+ );
15043
+ result.pointType = visConfig.isTextVisible ? "circle+text" : "circle";
15044
+ result.clusterLevel = visConfig.clusterLevel;
15045
+ result.getWeight = (d) => {
15046
+ return d.properties[aggregationExpAlias];
15047
+ };
15048
+ result.getPointRadius = (d, info) => {
15049
+ return calculateClusterRadius(
15050
+ d.properties,
15051
+ info.data.attributes.stats,
15052
+ visConfig.radiusRange,
15053
+ aggregationExpAlias
15054
+ );
15055
+ };
15056
+ result.textCharacterSet = "auto";
15057
+ result.textFontFamily = "Inter, sans";
15058
+ result.textFontSettings = { sdf: true };
15059
+ result.textFontWeight = 600;
15060
+ result.getText = (d) => TEXT_NUMBER_FORMATTER.format(d.properties[aggregationExpAlias]);
15061
+ result.getTextColor = config2.textLabel[TEXT_LABEL_INDEX].color;
15062
+ result.textOutlineColor = [
15063
+ ...config2.textLabel[TEXT_LABEL_INDEX].outlineColor,
15064
+ TEXT_OUTLINE_OPACITY
15065
+ ];
15066
+ result.textOutlineWidth = 5;
15067
+ result.textSizeUnits = "pixels";
15068
+ result.getTextSize = (d, info) => {
15069
+ const radius = calculateClusterRadius(
15070
+ d.properties,
15071
+ info.data.attributes.stats,
15072
+ visConfig.radiusRange,
15073
+ aggregationExpAlias
15074
+ );
15075
+ return calculateClusterTextFontSize(radius);
15076
+ };
15077
+ }
14916
15078
  if (radiusField || sizeField) {
14917
15079
  result.getPointRadius = getSizeAccessor(
14918
15080
  // @ts-ignore
@@ -15477,65 +15639,6 @@ async function fetchMap({
15477
15639
  return out;
15478
15640
  }
15479
15641
 
15480
- // src/filters.ts
15481
- init_cjs_shims();
15482
- function addFilter(filters, { column, type, values, owner }) {
15483
- if (!filters[column]) {
15484
- filters[column] = {};
15485
- }
15486
- const filter = { values, owner };
15487
- filters[column][type] = filter;
15488
- return filters;
15489
- }
15490
- function removeFilter(filters, { column, owner }) {
15491
- const filter = filters[column];
15492
- if (!filter) {
15493
- return filters;
15494
- }
15495
- if (owner) {
15496
- for (const type of Object.values(FilterType)) {
15497
- if (owner === filter[type]?.owner) {
15498
- delete filter[type];
15499
- }
15500
- }
15501
- }
15502
- if (!owner || isEmptyObject(filter)) {
15503
- delete filters[column];
15504
- }
15505
- return filters;
15506
- }
15507
- function clearFilters(filters) {
15508
- for (const column of Object.keys(filters)) {
15509
- delete filters[column];
15510
- }
15511
- return filters;
15512
- }
15513
- function hasFilter(filters, { column, owner }) {
15514
- const filter = filters[column];
15515
- if (!filter) {
15516
- return false;
15517
- }
15518
- if (!owner) {
15519
- return true;
15520
- }
15521
- for (const type of Object.values(FilterType)) {
15522
- if (owner === filter[type]?.owner) {
15523
- return true;
15524
- }
15525
- }
15526
- return false;
15527
- }
15528
- function getFilter(filters, { column, type, owner }) {
15529
- const filter = filters[column];
15530
- if (!filter) {
15531
- return null;
15532
- }
15533
- if (!owner || owner === filter[type]?.owner) {
15534
- return filter[type] || null;
15535
- }
15536
- return null;
15537
- }
15538
-
15539
15642
  // src/geo.ts
15540
15643
  init_cjs_shims();
15541
15644
 
@@ -15690,6 +15793,9 @@ function _getHexagonResolution(viewport, tileSize) {
15690
15793
  SOURCE_DEFAULTS,
15691
15794
  SpatialIndex,
15692
15795
  SpatialIndexColumn,
15796
+ TEXT_LABEL_INDEX,
15797
+ TEXT_NUMBER_FORMATTER,
15798
+ TEXT_OUTLINE_OPACITY,
15693
15799
  TileFormat,
15694
15800
  WidgetQuerySource,
15695
15801
  WidgetRasterSource,
@@ -15710,6 +15816,8 @@ function _getHexagonResolution(viewport, tileSize) {
15710
15816
  buildBinaryFeatureFilter,
15711
15817
  buildPublicMapUrl,
15712
15818
  buildStatsUrl,
15819
+ calculateClusterRadius,
15820
+ calculateClusterTextFontSize,
15713
15821
  clearFilters,
15714
15822
  configureSource,
15715
15823
  createPolygonSpatialFilter,
@@ -15718,11 +15826,13 @@ function _getHexagonResolution(viewport, tileSize) {
15718
15826
  fetchMap,
15719
15827
  filterFunctions,
15720
15828
  geojsonFeatures,
15829
+ getApplicableFilters,
15721
15830
  getClient,
15722
15831
  getColorAccessor,
15723
15832
  getColorValueAccessor,
15724
15833
  getColumnNameFromGeoColumn,
15725
15834
  getDataFilterExtensionProps,
15835
+ getDefaultAggregationExpColumnAliasForLayerType,
15726
15836
  getFilter,
15727
15837
  getIconUrlAccessor,
15728
15838
  getLayerProps,