@carto/api-client 0.5.7-alpha-optional-spatial-filter.1 → 0.5.7-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.
@@ -108,6 +108,7 @@ __export(src_exports, {
108
108
  FEATURE_GEOM_PROPERTY: () => FEATURE_GEOM_PROPERTY,
109
109
  FilterType: () => FilterType,
110
110
  OPACITY_MAP: () => OPACITY_MAP,
111
+ OTHERS_CATEGORY_NAME: () => OTHERS_CATEGORY_NAME,
111
112
  Provider: () => Provider,
112
113
  SOURCE_DEFAULTS: () => SOURCE_DEFAULTS,
113
114
  SchemaFieldType: () => SchemaFieldType,
@@ -158,6 +159,7 @@ __export(src_exports, {
158
159
  getLayerProps: () => getLayerProps,
159
160
  getMaxMarkerSize: () => getMaxMarkerSize,
160
161
  getSizeAccessor: () => getSizeAccessor,
162
+ getSorter: () => getSorter,
161
163
  getSpatialIndexFromGeoColumn: () => getSpatialIndexFromGeoColumn,
162
164
  getTextAccessor: () => getTextAccessor,
163
165
  groupValuesByColumn: () => groupValuesByColumn,
@@ -1727,143 +1729,6 @@ init_cjs_shims();
1727
1729
  // src/filters/tileFeaturesGeometries.ts
1728
1730
  init_cjs_shims();
1729
1731
 
1730
- // src/utils/transformTileCoordsToWGS84.ts
1731
- init_cjs_shims();
1732
-
1733
- // node_modules/@math.gl/core/dist/index.js
1734
- init_cjs_shims();
1735
-
1736
- // node_modules/@math.gl/core/dist/lib/common.js
1737
- init_cjs_shims();
1738
- var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
1739
- var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
1740
- var DEFAULT_CONFIG = {
1741
- EPSILON: 1e-12,
1742
- debug: false,
1743
- precision: 4,
1744
- printTypes: false,
1745
- printDegrees: false,
1746
- printRowMajor: true,
1747
- _cartographicRadians: false
1748
- };
1749
- globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
1750
- var config = globalThis.mathgl.config;
1751
- function isArray(value) {
1752
- return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
1753
- }
1754
- function lerp(a, b, t) {
1755
- if (isArray(a)) {
1756
- return a.map((ai, i) => lerp(ai, b[i], t));
1757
- }
1758
- return t * b + (1 - t) * a;
1759
- }
1760
-
1761
- // node_modules/@math.gl/web-mercator/dist/index.js
1762
- init_cjs_shims();
1763
-
1764
- // node_modules/@math.gl/web-mercator/dist/web-mercator-viewport.js
1765
- init_cjs_shims();
1766
-
1767
- // node_modules/@math.gl/web-mercator/dist/math-utils.js
1768
- init_cjs_shims();
1769
-
1770
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
1771
- init_cjs_shims();
1772
-
1773
- // node_modules/@math.gl/web-mercator/dist/assert.js
1774
- init_cjs_shims();
1775
- function assert(condition, message) {
1776
- if (!condition) {
1777
- throw new Error(message || "@math.gl/web-mercator: assertion failed.");
1778
- }
1779
- }
1780
-
1781
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
1782
- var PI = Math.PI;
1783
- var PI_4 = PI / 4;
1784
- var DEGREES_TO_RADIANS2 = PI / 180;
1785
- var RADIANS_TO_DEGREES2 = 180 / PI;
1786
- var TILE_SIZE = 512;
1787
- function lngLatToWorld(lngLat) {
1788
- const [lng, lat] = lngLat;
1789
- assert(Number.isFinite(lng));
1790
- assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
1791
- const lambda2 = lng * DEGREES_TO_RADIANS2;
1792
- const phi2 = lat * DEGREES_TO_RADIANS2;
1793
- const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
1794
- const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
1795
- return [x, y];
1796
- }
1797
- function worldToLngLat(xy) {
1798
- const [x, y] = xy;
1799
- const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
1800
- const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
1801
- return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
1802
- }
1803
-
1804
- // node_modules/@math.gl/web-mercator/dist/fit-bounds.js
1805
- init_cjs_shims();
1806
-
1807
- // node_modules/@math.gl/web-mercator/dist/get-bounds.js
1808
- init_cjs_shims();
1809
- var DEGREES_TO_RADIANS3 = Math.PI / 180;
1810
-
1811
- // node_modules/@math.gl/web-mercator/dist/normalize-viewport-props.js
1812
- init_cjs_shims();
1813
-
1814
- // node_modules/@math.gl/web-mercator/dist/fly-to-viewport.js
1815
- init_cjs_shims();
1816
-
1817
- // src/utils/transformTileCoordsToWGS84.ts
1818
- var TRANSFORM_FN = {
1819
- Point: transformPoint,
1820
- MultiPoint: transformMultiPoint,
1821
- LineString: transformLineString,
1822
- MultiLineString: transformMultiLineString,
1823
- Polygon: transformPolygon,
1824
- MultiPolygon: transformMultiPolygon
1825
- };
1826
- function transformTileCoordsToWGS84(geometry, bbox2) {
1827
- const [west, south, east, north] = bbox2;
1828
- const nw = lngLatToWorld([west, north]);
1829
- const se = lngLatToWorld([east, south]);
1830
- const projectedBbox = [nw, se];
1831
- if (geometry.type === "GeometryCollection") {
1832
- throw new Error("Unsupported geometry type GeometryCollection");
1833
- }
1834
- const transformFn = TRANSFORM_FN[geometry.type];
1835
- const coordinates = transformFn(geometry.coordinates, projectedBbox);
1836
- return { ...geometry, coordinates };
1837
- }
1838
- function transformPoint([pointX, pointY], [nw, se]) {
1839
- const x = lerp(nw[0], se[0], pointX);
1840
- const y = lerp(nw[1], se[1], pointY);
1841
- return worldToLngLat([x, y]);
1842
- }
1843
- function getPoints(geometry, bbox2) {
1844
- return geometry.map((g) => transformPoint(g, bbox2));
1845
- }
1846
- function transformMultiPoint(multiPoint, bbox2) {
1847
- return getPoints(multiPoint, bbox2);
1848
- }
1849
- function transformLineString(line, bbox2) {
1850
- return getPoints(line, bbox2);
1851
- }
1852
- function transformMultiLineString(multiLineString2, bbox2) {
1853
- return multiLineString2.map(
1854
- (lineString2) => transformLineString(lineString2, bbox2)
1855
- );
1856
- }
1857
- function transformPolygon(polygon2, bbox2) {
1858
- return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
1859
- }
1860
- function transformMultiPolygon(multiPolygon2, bbox2) {
1861
- return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
1862
- }
1863
-
1864
- // src/filters/tileIntersection.ts
1865
- init_cjs_shims();
1866
-
1867
1732
  // node_modules/@turf/bbox-polygon/dist/esm/index.js
1868
1733
  init_cjs_shims();
1869
1734
  function bboxPolygon(bbox2, options = {}) {
@@ -2195,7 +2060,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
2195
2060
  var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
2196
2061
  var SQRT_BASE = 1e7;
2197
2062
  var MAX = 1e9;
2198
- function clone2(configObject) {
2063
+ function clone(configObject) {
2199
2064
  var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
2200
2065
  prefix: "",
2201
2066
  groupSize: 3,
@@ -2321,7 +2186,7 @@ function clone2(configObject) {
2321
2186
  x.c = [x.e = 0];
2322
2187
  }
2323
2188
  }
2324
- BigNumber2.clone = clone2;
2189
+ BigNumber2.clone = clone;
2325
2190
  BigNumber2.ROUND_UP = 0;
2326
2191
  BigNumber2.ROUND_DOWN = 1;
2327
2192
  BigNumber2.ROUND_CEIL = 2;
@@ -3524,7 +3389,7 @@ function toFixedPoint(str, e, z) {
3524
3389
  }
3525
3390
  return str;
3526
3391
  }
3527
- var BigNumber = clone2();
3392
+ var BigNumber = clone();
3528
3393
  var bignumber_default = BigNumber;
3529
3394
 
3530
3395
  // node_modules/splaytree-ts/dist/esm/index.js
@@ -5097,13 +4962,99 @@ var turf_intersect_default = intersect;
5097
4962
 
5098
4963
  // src/utils/transformToTileCoords.ts
5099
4964
  init_cjs_shims();
5100
- var TRANSFORM_FN2 = {
5101
- Point: transformPoint2,
5102
- MultiPoint: transformMultiPoint2,
5103
- LineString: transformLineString2,
5104
- MultiLineString: transformMultiLineString2,
5105
- Polygon: transformPolygon2,
5106
- MultiPolygon: transformMultiPolygon2
4965
+
4966
+ // node_modules/@math.gl/web-mercator/dist/index.js
4967
+ init_cjs_shims();
4968
+
4969
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-viewport.js
4970
+ init_cjs_shims();
4971
+
4972
+ // node_modules/@math.gl/web-mercator/dist/math-utils.js
4973
+ init_cjs_shims();
4974
+
4975
+ // node_modules/@math.gl/core/dist/index.js
4976
+ init_cjs_shims();
4977
+
4978
+ // node_modules/@math.gl/core/dist/lib/common.js
4979
+ init_cjs_shims();
4980
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
4981
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
4982
+ var DEFAULT_CONFIG = {
4983
+ EPSILON: 1e-12,
4984
+ debug: false,
4985
+ precision: 4,
4986
+ printTypes: false,
4987
+ printDegrees: false,
4988
+ printRowMajor: true,
4989
+ _cartographicRadians: false
4990
+ };
4991
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4992
+ var config = globalThis.mathgl.config;
4993
+ function isArray(value) {
4994
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
4995
+ }
4996
+ function lerp(a, b, t) {
4997
+ if (isArray(a)) {
4998
+ return a.map((ai, i) => lerp(ai, b[i], t));
4999
+ }
5000
+ return t * b + (1 - t) * a;
5001
+ }
5002
+
5003
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
5004
+ init_cjs_shims();
5005
+
5006
+ // node_modules/@math.gl/web-mercator/dist/assert.js
5007
+ init_cjs_shims();
5008
+ function assert(condition, message) {
5009
+ if (!condition) {
5010
+ throw new Error(message || "@math.gl/web-mercator: assertion failed.");
5011
+ }
5012
+ }
5013
+
5014
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
5015
+ var PI = Math.PI;
5016
+ var PI_4 = PI / 4;
5017
+ var DEGREES_TO_RADIANS2 = PI / 180;
5018
+ var RADIANS_TO_DEGREES2 = 180 / PI;
5019
+ var TILE_SIZE = 512;
5020
+ function lngLatToWorld(lngLat) {
5021
+ const [lng, lat] = lngLat;
5022
+ assert(Number.isFinite(lng));
5023
+ assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
5024
+ const lambda2 = lng * DEGREES_TO_RADIANS2;
5025
+ const phi2 = lat * DEGREES_TO_RADIANS2;
5026
+ const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
5027
+ const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
5028
+ return [x, y];
5029
+ }
5030
+ function worldToLngLat(xy) {
5031
+ const [x, y] = xy;
5032
+ const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
5033
+ const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
5034
+ return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
5035
+ }
5036
+
5037
+ // node_modules/@math.gl/web-mercator/dist/fit-bounds.js
5038
+ init_cjs_shims();
5039
+
5040
+ // node_modules/@math.gl/web-mercator/dist/get-bounds.js
5041
+ init_cjs_shims();
5042
+ var DEGREES_TO_RADIANS3 = Math.PI / 180;
5043
+
5044
+ // node_modules/@math.gl/web-mercator/dist/normalize-viewport-props.js
5045
+ init_cjs_shims();
5046
+
5047
+ // node_modules/@math.gl/web-mercator/dist/fly-to-viewport.js
5048
+ init_cjs_shims();
5049
+
5050
+ // src/utils/transformToTileCoords.ts
5051
+ var TRANSFORM_FN = {
5052
+ Point: transformPoint,
5053
+ MultiPoint: transformMultiPoint,
5054
+ LineString: transformLineString,
5055
+ MultiLineString: transformMultiLineString,
5056
+ Polygon: transformPolygon,
5057
+ MultiPolygon: transformMultiPolygon
5107
5058
  };
5108
5059
  function transformToTileCoords(geometry, bbox2) {
5109
5060
  const [west, south, east, north] = bbox2;
@@ -5113,34 +5064,34 @@ function transformToTileCoords(geometry, bbox2) {
5113
5064
  if (geometry.type === "GeometryCollection") {
5114
5065
  throw new Error("Unsupported geometry type GeometryCollection");
5115
5066
  }
5116
- const transformFn = TRANSFORM_FN2[geometry.type];
5067
+ const transformFn = TRANSFORM_FN[geometry.type];
5117
5068
  const coordinates = transformFn(geometry.coordinates, projectedBbox);
5118
5069
  return { ...geometry, coordinates };
5119
5070
  }
5120
- function transformPoint2([pointX, pointY], [nw, se]) {
5071
+ function transformPoint([pointX, pointY], [nw, se]) {
5121
5072
  const x = inverseLerp(nw[0], se[0], pointX);
5122
5073
  const y = inverseLerp(nw[1], se[1], pointY);
5123
5074
  return [x, y];
5124
5075
  }
5125
- function getPoints2(geometry, bbox2) {
5126
- return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
5076
+ function getPoints(geometry, bbox2) {
5077
+ return geometry.map((g) => transformPoint(projectFlat(g), bbox2));
5127
5078
  }
5128
- function transformMultiPoint2(multiPoint, bbox2) {
5129
- return getPoints2(multiPoint, bbox2);
5079
+ function transformMultiPoint(multiPoint, bbox2) {
5080
+ return getPoints(multiPoint, bbox2);
5130
5081
  }
5131
- function transformLineString2(line, bbox2) {
5132
- return getPoints2(line, bbox2);
5082
+ function transformLineString(line, bbox2) {
5083
+ return getPoints(line, bbox2);
5133
5084
  }
5134
- function transformMultiLineString2(multiLineString2, bbox2) {
5085
+ function transformMultiLineString(multiLineString2, bbox2) {
5135
5086
  return multiLineString2.map(
5136
- (lineString2) => transformLineString2(lineString2, bbox2)
5087
+ (lineString2) => transformLineString(lineString2, bbox2)
5137
5088
  );
5138
5089
  }
5139
- function transformPolygon2(polygon2, bbox2) {
5140
- return polygon2.map((polygonRing) => getPoints2(polygonRing, bbox2));
5141
- }
5142
- function transformMultiPolygon2(multiPolygon2, bbox2) {
5143
- return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
5090
+ function transformPolygon(polygon2, bbox2) {
5091
+ return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
5092
+ }
5093
+ function transformMultiPolygon(multiPolygon2, bbox2) {
5094
+ return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
5144
5095
  }
5145
5096
  function projectFlat(xyz) {
5146
5097
  return lngLatToWorld(xyz);
@@ -5149,181 +5100,52 @@ function inverseLerp(a, b, x) {
5149
5100
  return (x - a) / (b - a);
5150
5101
  }
5151
5102
 
5152
- // src/filters/tileIntersection.ts
5153
- var import_quadbin = require("quadbin");
5154
- var import_h3_js = require("h3-js");
5155
-
5156
- // node_modules/@turf/bbox-clip/dist/esm/index.js
5103
+ // src/utils/transformTileCoordsToWGS84.ts
5157
5104
  init_cjs_shims();
5158
- function lineclip(points, bbox2, result) {
5159
- var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5160
- let a;
5161
- let b;
5162
- if (!result) result = [];
5163
- for (i = 1; i < len; i++) {
5164
- a = points[i - 1];
5165
- b = points[i];
5166
- codeB = lastCode = bitCode(b, bbox2);
5167
- while (true) {
5168
- if (!(codeA | codeB)) {
5169
- part.push(a);
5170
- if (codeB !== lastCode) {
5171
- part.push(b);
5172
- if (i < len - 1) {
5173
- result.push(part);
5174
- part = [];
5175
- }
5176
- } else if (i === len - 1) {
5177
- part.push(b);
5178
- }
5179
- break;
5180
- } else if (codeA & codeB) {
5181
- break;
5182
- } else if (codeA) {
5183
- a = intersect2(a, b, codeA, bbox2);
5184
- codeA = bitCode(a, bbox2);
5185
- } else {
5186
- b = intersect2(a, b, codeB, bbox2);
5187
- codeB = bitCode(b, bbox2);
5188
- }
5189
- }
5190
- codeA = lastCode;
5191
- }
5192
- if (part.length) result.push(part);
5193
- return result;
5194
- }
5195
- function polygonclip(points, bbox2) {
5196
- var result, edge, prev, prevInside, i, p, inside;
5197
- for (edge = 1; edge <= 8; edge *= 2) {
5198
- result = [];
5199
- prev = points[points.length - 1];
5200
- prevInside = !(bitCode(prev, bbox2) & edge);
5201
- for (i = 0; i < points.length; i++) {
5202
- p = points[i];
5203
- inside = !(bitCode(p, bbox2) & edge);
5204
- if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5205
- if (inside) result.push(p);
5206
- prev = p;
5207
- prevInside = inside;
5208
- }
5209
- points = result;
5210
- if (!points.length) break;
5105
+ var TRANSFORM_FN2 = {
5106
+ Point: transformPoint2,
5107
+ MultiPoint: transformMultiPoint2,
5108
+ LineString: transformLineString2,
5109
+ MultiLineString: transformMultiLineString2,
5110
+ Polygon: transformPolygon2,
5111
+ MultiPolygon: transformMultiPolygon2
5112
+ };
5113
+ function transformTileCoordsToWGS84(geometry, bbox2) {
5114
+ const [west, south, east, north] = bbox2;
5115
+ const nw = lngLatToWorld([west, north]);
5116
+ const se = lngLatToWorld([east, south]);
5117
+ const projectedBbox = [nw, se];
5118
+ if (geometry.type === "GeometryCollection") {
5119
+ throw new Error("Unsupported geometry type GeometryCollection");
5211
5120
  }
5212
- return result;
5121
+ const transformFn = TRANSFORM_FN2[geometry.type];
5122
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
5123
+ return { ...geometry, coordinates };
5213
5124
  }
5214
- function intersect2(a, b, edge, bbox2) {
5215
- return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox2[3] - a[1]) / (b[1] - a[1]), bbox2[3]] : edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox2[1] - a[1]) / (b[1] - a[1]), bbox2[1]] : edge & 2 ? [bbox2[2], a[1] + (b[1] - a[1]) * (bbox2[2] - a[0]) / (b[0] - a[0])] : edge & 1 ? [bbox2[0], a[1] + (b[1] - a[1]) * (bbox2[0] - a[0]) / (b[0] - a[0])] : null;
5125
+ function transformPoint2([pointX, pointY], [nw, se]) {
5126
+ const x = lerp(nw[0], se[0], pointX);
5127
+ const y = lerp(nw[1], se[1], pointY);
5128
+ return worldToLngLat([x, y]);
5216
5129
  }
5217
- function bitCode(p, bbox2) {
5218
- var code = 0;
5219
- if (p[0] < bbox2[0]) code |= 1;
5220
- else if (p[0] > bbox2[2]) code |= 2;
5221
- if (p[1] < bbox2[1]) code |= 4;
5222
- else if (p[1] > bbox2[3]) code |= 8;
5223
- return code;
5130
+ function getPoints2(geometry, bbox2) {
5131
+ return geometry.map((g) => transformPoint2(g, bbox2));
5224
5132
  }
5225
- function bboxClip(feature2, bbox2) {
5226
- const geom = getGeom(feature2);
5227
- const type = geom.type;
5228
- const properties = feature2.type === "Feature" ? feature2.properties : {};
5229
- let coords = geom.coordinates;
5230
- switch (type) {
5231
- case "LineString":
5232
- case "MultiLineString": {
5233
- const lines = [];
5234
- if (type === "LineString") {
5235
- coords = [coords];
5236
- }
5237
- coords.forEach((line) => {
5238
- lineclip(line, bbox2, lines);
5239
- });
5240
- if (lines.length === 1) {
5241
- return lineString(lines[0], properties);
5242
- }
5243
- return multiLineString(lines, properties);
5244
- }
5245
- case "Polygon":
5246
- return polygon(clipPolygon(coords, bbox2), properties);
5247
- case "MultiPolygon":
5248
- return multiPolygon(
5249
- coords.map((poly) => {
5250
- return clipPolygon(poly, bbox2);
5251
- }),
5252
- properties
5253
- );
5254
- default:
5255
- throw new Error("geometry " + type + " not supported");
5256
- }
5133
+ function transformMultiPoint2(multiPoint, bbox2) {
5134
+ return getPoints2(multiPoint, bbox2);
5257
5135
  }
5258
- function clipPolygon(rings, bbox2) {
5259
- const outRings = [];
5260
- for (const ring of rings) {
5261
- const clipped = polygonclip(ring, bbox2);
5262
- if (clipped.length > 0) {
5263
- if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5264
- clipped.push(clipped[0]);
5265
- }
5266
- if (clipped.length >= 4) {
5267
- outRings.push(clipped);
5268
- }
5269
- }
5270
- }
5271
- return outRings;
5136
+ function transformLineString2(line, bbox2) {
5137
+ return getPoints2(line, bbox2);
5272
5138
  }
5273
- var turf_bbox_clip_default = bboxClip;
5274
-
5275
- // src/filters/tileIntersection.ts
5276
- function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
5277
- const tilePolygon = turf_bbox_polygon_default(tileBbox);
5278
- if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5279
- return true;
5280
- }
5281
- const clippedSpatialFilter = turf_intersect_default(
5282
- featureCollection([tilePolygon, feature(spatialFilter)])
5139
+ function transformMultiLineString2(multiLineString2, bbox2) {
5140
+ return multiLineString2.map(
5141
+ (lineString2) => transformLineString2(lineString2, bbox2)
5283
5142
  );
5284
- if (!clippedSpatialFilter) {
5285
- return false;
5286
- }
5287
- return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
5288
- }
5289
- function intersectTileRaster(parent, cellResolution, spatialFilter) {
5290
- return intersectTileQuadbin(parent, cellResolution, spatialFilter);
5291
5143
  }
5292
- function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
5293
- const tilePolygon = (0, import_quadbin.cellToBoundary)(parent);
5294
- if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5295
- return true;
5296
- }
5297
- const clippedSpatialFilter = turf_intersect_default(
5298
- featureCollection([feature(tilePolygon), feature(spatialFilter)])
5299
- );
5300
- if (!clippedSpatialFilter) {
5301
- return false;
5302
- }
5303
- const cells = (0, import_quadbin.geometryToCells)(
5304
- clippedSpatialFilter.geometry,
5305
- cellResolution
5306
- );
5307
- return new Set(cells);
5144
+ function transformPolygon2(polygon2, bbox2) {
5145
+ return polygon2.map((polygonRing) => getPoints2(polygonRing, bbox2));
5308
5146
  }
5309
- var BBOX_WEST = [-180, -90, 0, 90];
5310
- var BBOX_EAST = [0, -90, 180, 90];
5311
- function intersectTileH3(cellResolution, spatialFilter) {
5312
- if (!spatialFilter) {
5313
- return true;
5314
- }
5315
- const spatialFilterFeature = feature(spatialFilter);
5316
- const cellsWest = (0, import_h3_js.polygonToCells)(
5317
- turf_bbox_clip_default(spatialFilterFeature, BBOX_WEST).geometry.coordinates,
5318
- cellResolution,
5319
- true
5320
- );
5321
- const cellsEast = (0, import_h3_js.polygonToCells)(
5322
- turf_bbox_clip_default(spatialFilterFeature, BBOX_EAST).geometry.coordinates,
5323
- cellResolution,
5324
- true
5325
- );
5326
- return new Set(cellsWest.concat(cellsEast));
5147
+ function transformMultiPolygon2(multiPolygon2, bbox2) {
5148
+ return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
5327
5149
  }
5328
5150
 
5329
5151
  // src/filters/tileFeaturesGeometries.ts
@@ -5340,45 +5162,55 @@ function tileFeaturesGeometries({
5340
5162
  if (tile.isVisible === false || !tile.data) {
5341
5163
  continue;
5342
5164
  }
5343
- const tileBbox = [
5165
+ const bbox2 = [
5344
5166
  tile.bbox.west,
5345
5167
  tile.bbox.south,
5346
5168
  tile.bbox.east,
5347
5169
  tile.bbox.north
5348
5170
  ];
5349
- const intersection3 = intersectTileGeometry(
5350
- tileBbox,
5351
- tileFormat,
5352
- spatialFilter
5171
+ const bboxToGeom = turf_bbox_polygon_default(bbox2);
5172
+ const tileIsFullyVisible = turf_boolean_within_default(bboxToGeom, spatialFilter);
5173
+ const spatialFilterFeature = {
5174
+ type: "Feature",
5175
+ geometry: spatialFilter,
5176
+ properties: {}
5177
+ };
5178
+ const clippedGeometryToIntersect = turf_intersect_default(
5179
+ featureCollection([bboxToGeom, spatialFilterFeature])
5353
5180
  );
5354
- if (intersection3 === false) continue;
5355
- const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
5181
+ if (!clippedGeometryToIntersect) {
5182
+ continue;
5183
+ }
5184
+ const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
5356
5185
  calculateFeatures({
5357
5186
  map,
5358
- spatialFilter: transformedSpatialFilter,
5187
+ tileIsFullyVisible,
5188
+ geometryIntersection: transformedGeometryToIntersect,
5359
5189
  data: tile.data.points,
5360
5190
  type: "Point",
5361
- bbox: tileBbox,
5191
+ bbox: bbox2,
5362
5192
  tileFormat,
5363
5193
  uniqueIdProperty,
5364
5194
  options
5365
5195
  });
5366
5196
  calculateFeatures({
5367
5197
  map,
5368
- spatialFilter: transformedSpatialFilter,
5198
+ tileIsFullyVisible,
5199
+ geometryIntersection: transformedGeometryToIntersect,
5369
5200
  data: tile.data.lines,
5370
5201
  type: "LineString",
5371
- bbox: tileBbox,
5202
+ bbox: bbox2,
5372
5203
  tileFormat,
5373
5204
  uniqueIdProperty,
5374
5205
  options
5375
5206
  });
5376
5207
  calculateFeatures({
5377
5208
  map,
5378
- spatialFilter: transformedSpatialFilter,
5209
+ tileIsFullyVisible,
5210
+ geometryIntersection: transformedGeometryToIntersect,
5379
5211
  data: tile.data.polygons,
5380
5212
  type: "Polygon",
5381
- bbox: tileBbox,
5213
+ bbox: bbox2,
5382
5214
  tileFormat,
5383
5215
  uniqueIdProperty,
5384
5216
  options
@@ -5396,7 +5228,7 @@ function processTileFeatureProperties({
5396
5228
  tileFormat,
5397
5229
  uniqueIdProperty,
5398
5230
  storeGeometry,
5399
- spatialFilter
5231
+ geometryIntersection
5400
5232
  }) {
5401
5233
  const tileProps = getPropertiesFromTile(data, startIndex);
5402
5234
  const uniquePropertyValue = getUniquePropertyValue(
@@ -5408,7 +5240,7 @@ function processTileFeatureProperties({
5408
5240
  return;
5409
5241
  }
5410
5242
  let geometry = null;
5411
- if (storeGeometry || spatialFilter) {
5243
+ if (storeGeometry || geometryIntersection) {
5412
5244
  const { positions } = data;
5413
5245
  const ringCoordinates = getRingCoordinatesFor(
5414
5246
  startIndex,
@@ -5417,7 +5249,7 @@ function processTileFeatureProperties({
5417
5249
  );
5418
5250
  geometry = getFeatureByType(ringCoordinates, type);
5419
5251
  }
5420
- if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
5252
+ if (geometry && geometryIntersection && !turf_boolean_intersects_default(geometry, geometryIntersection)) {
5421
5253
  return;
5422
5254
  }
5423
5255
  const properties = parseProperties(tileProps);
@@ -5429,7 +5261,7 @@ function processTileFeatureProperties({
5429
5261
  function addIntersectedFeaturesInTile({
5430
5262
  map,
5431
5263
  data,
5432
- spatialFilter,
5264
+ geometryIntersection,
5433
5265
  type,
5434
5266
  bbox: bbox2,
5435
5267
  tileFormat,
@@ -5451,7 +5283,7 @@ function addIntersectedFeaturesInTile({
5451
5283
  tileFormat,
5452
5284
  uniqueIdProperty,
5453
5285
  storeGeometry,
5454
- spatialFilter
5286
+ geometryIntersection
5455
5287
  });
5456
5288
  }
5457
5289
  }
@@ -5533,7 +5365,8 @@ function getRingCoordinatesFor(startIndex, endIndex, positions) {
5533
5365
  }
5534
5366
  function calculateFeatures({
5535
5367
  map,
5536
- spatialFilter,
5368
+ tileIsFullyVisible,
5369
+ geometryIntersection,
5537
5370
  data,
5538
5371
  type,
5539
5372
  bbox: bbox2,
@@ -5544,7 +5377,7 @@ function calculateFeatures({
5544
5377
  if (!data?.properties.length) {
5545
5378
  return;
5546
5379
  }
5547
- if (!spatialFilter) {
5380
+ if (tileIsFullyVisible) {
5548
5381
  addAllFeaturesInTile({
5549
5382
  map,
5550
5383
  data,
@@ -5558,7 +5391,7 @@ function calculateFeatures({
5558
5391
  addIntersectedFeaturesInTile({
5559
5392
  map,
5560
5393
  data,
5561
- spatialFilter,
5394
+ geometryIntersection,
5562
5395
  type,
5563
5396
  bbox: bbox2,
5564
5397
  tileFormat,
@@ -5609,8 +5442,129 @@ function createIndicesForPoints(data) {
5609
5442
 
5610
5443
  // src/filters/tileFeaturesSpatialIndex.ts
5611
5444
  init_cjs_shims();
5612
- var import_quadbin2 = require("quadbin");
5613
- var import_h3_js2 = require("h3-js");
5445
+ var import_quadbin = require("quadbin");
5446
+
5447
+ // node_modules/@turf/bbox-clip/dist/esm/index.js
5448
+ init_cjs_shims();
5449
+ function lineclip(points, bbox2, result) {
5450
+ var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5451
+ let a;
5452
+ let b;
5453
+ if (!result) result = [];
5454
+ for (i = 1; i < len; i++) {
5455
+ a = points[i - 1];
5456
+ b = points[i];
5457
+ codeB = lastCode = bitCode(b, bbox2);
5458
+ while (true) {
5459
+ if (!(codeA | codeB)) {
5460
+ part.push(a);
5461
+ if (codeB !== lastCode) {
5462
+ part.push(b);
5463
+ if (i < len - 1) {
5464
+ result.push(part);
5465
+ part = [];
5466
+ }
5467
+ } else if (i === len - 1) {
5468
+ part.push(b);
5469
+ }
5470
+ break;
5471
+ } else if (codeA & codeB) {
5472
+ break;
5473
+ } else if (codeA) {
5474
+ a = intersect2(a, b, codeA, bbox2);
5475
+ codeA = bitCode(a, bbox2);
5476
+ } else {
5477
+ b = intersect2(a, b, codeB, bbox2);
5478
+ codeB = bitCode(b, bbox2);
5479
+ }
5480
+ }
5481
+ codeA = lastCode;
5482
+ }
5483
+ if (part.length) result.push(part);
5484
+ return result;
5485
+ }
5486
+ function polygonclip(points, bbox2) {
5487
+ var result, edge, prev, prevInside, i, p, inside;
5488
+ for (edge = 1; edge <= 8; edge *= 2) {
5489
+ result = [];
5490
+ prev = points[points.length - 1];
5491
+ prevInside = !(bitCode(prev, bbox2) & edge);
5492
+ for (i = 0; i < points.length; i++) {
5493
+ p = points[i];
5494
+ inside = !(bitCode(p, bbox2) & edge);
5495
+ if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5496
+ if (inside) result.push(p);
5497
+ prev = p;
5498
+ prevInside = inside;
5499
+ }
5500
+ points = result;
5501
+ if (!points.length) break;
5502
+ }
5503
+ return result;
5504
+ }
5505
+ function intersect2(a, b, edge, bbox2) {
5506
+ return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox2[3] - a[1]) / (b[1] - a[1]), bbox2[3]] : edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox2[1] - a[1]) / (b[1] - a[1]), bbox2[1]] : edge & 2 ? [bbox2[2], a[1] + (b[1] - a[1]) * (bbox2[2] - a[0]) / (b[0] - a[0])] : edge & 1 ? [bbox2[0], a[1] + (b[1] - a[1]) * (bbox2[0] - a[0]) / (b[0] - a[0])] : null;
5507
+ }
5508
+ function bitCode(p, bbox2) {
5509
+ var code = 0;
5510
+ if (p[0] < bbox2[0]) code |= 1;
5511
+ else if (p[0] > bbox2[2]) code |= 2;
5512
+ if (p[1] < bbox2[1]) code |= 4;
5513
+ else if (p[1] > bbox2[3]) code |= 8;
5514
+ return code;
5515
+ }
5516
+ function bboxClip(feature2, bbox2) {
5517
+ const geom = getGeom(feature2);
5518
+ const type = geom.type;
5519
+ const properties = feature2.type === "Feature" ? feature2.properties : {};
5520
+ let coords = geom.coordinates;
5521
+ switch (type) {
5522
+ case "LineString":
5523
+ case "MultiLineString": {
5524
+ const lines = [];
5525
+ if (type === "LineString") {
5526
+ coords = [coords];
5527
+ }
5528
+ coords.forEach((line) => {
5529
+ lineclip(line, bbox2, lines);
5530
+ });
5531
+ if (lines.length === 1) {
5532
+ return lineString(lines[0], properties);
5533
+ }
5534
+ return multiLineString(lines, properties);
5535
+ }
5536
+ case "Polygon":
5537
+ return polygon(clipPolygon(coords, bbox2), properties);
5538
+ case "MultiPolygon":
5539
+ return multiPolygon(
5540
+ coords.map((poly) => {
5541
+ return clipPolygon(poly, bbox2);
5542
+ }),
5543
+ properties
5544
+ );
5545
+ default:
5546
+ throw new Error("geometry " + type + " not supported");
5547
+ }
5548
+ }
5549
+ function clipPolygon(rings, bbox2) {
5550
+ const outRings = [];
5551
+ for (const ring of rings) {
5552
+ const clipped = polygonclip(ring, bbox2);
5553
+ if (clipped.length > 0) {
5554
+ if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5555
+ clipped.push(clipped[0]);
5556
+ }
5557
+ if (clipped.length >= 4) {
5558
+ outRings.push(clipped);
5559
+ }
5560
+ }
5561
+ }
5562
+ return outRings;
5563
+ }
5564
+ var turf_bbox_clip_default = bboxClip;
5565
+
5566
+ // src/filters/tileFeaturesSpatialIndex.ts
5567
+ var import_h3_js = require("h3-js");
5614
5568
  function tileFeaturesSpatialIndex({
5615
5569
  tiles,
5616
5570
  spatialFilter,
@@ -5619,52 +5573,58 @@ function tileFeaturesSpatialIndex({
5619
5573
  }) {
5620
5574
  const map = /* @__PURE__ */ new Map();
5621
5575
  const spatialIndex = getSpatialIndex(spatialDataType);
5622
- const cellResolution = getResolution(tiles, spatialIndex);
5576
+ const resolution = getResolution(tiles, spatialIndex);
5623
5577
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
5624
- if (!cellResolution) {
5578
+ if (!resolution) {
5625
5579
  return [];
5626
5580
  }
5627
- let intersection3;
5628
- if (spatialIndex === "h3" /* H3 */) {
5629
- intersection3 = intersectTileH3(cellResolution, spatialFilter);
5581
+ const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
5582
+ if (!cells?.length) {
5583
+ return [];
5630
5584
  }
5585
+ const cellsSet = new Set(cells);
5631
5586
  for (const tile of tiles) {
5632
5587
  if (tile.isVisible === false || !tile.data) {
5633
5588
  continue;
5634
5589
  }
5635
- if (spatialIndex === "quadbin" /* QUADBIN */) {
5636
- const parent = getTileIndex(tile, spatialIndex);
5637
- intersection3 = intersectTileQuadbin(
5638
- parent,
5639
- cellResolution,
5640
- spatialFilter
5641
- );
5642
- }
5643
- if (!intersection3) continue;
5644
5590
  tile.data.forEach((d) => {
5645
- if (intersection3 === true || intersection3.has(d.id)) {
5591
+ if (cellsSet.has(d.id)) {
5646
5592
  map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
5647
5593
  }
5648
5594
  });
5649
5595
  }
5650
5596
  return Array.from(map.values());
5651
5597
  }
5652
- function getTileIndex(tile, spatialIndex) {
5653
- if (spatialIndex === "quadbin" /* QUADBIN */) {
5654
- return tile.index.q;
5655
- }
5656
- return tile.id;
5657
- }
5658
5598
  function getResolution(tiles, spatialIndex) {
5659
5599
  const data = tiles.find((tile) => tile.data?.length)?.data;
5660
5600
  if (!data) {
5661
5601
  return;
5662
5602
  }
5663
5603
  if (spatialIndex === "quadbin" /* QUADBIN */) {
5664
- return Number((0, import_quadbin2.getResolution)(data[0].id));
5604
+ return Number((0, import_quadbin.getResolution)(data[0].id));
5665
5605
  }
5666
5606
  if (spatialIndex === "h3" /* H3 */) {
5667
- return (0, import_h3_js2.getResolution)(data[0].id);
5607
+ return (0, import_h3_js.getResolution)(data[0].id);
5608
+ }
5609
+ }
5610
+ var bboxWest = [-180, -90, 0, 90];
5611
+ var bboxEast = [0, -90, 180, 90];
5612
+ function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
5613
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5614
+ return (0, import_quadbin.geometryToCells)(geometry, resolution);
5615
+ }
5616
+ if (spatialIndex === "h3" /* H3 */) {
5617
+ return (0, import_h3_js.polygonToCells)(
5618
+ turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
5619
+ resolution,
5620
+ true
5621
+ ).concat(
5622
+ (0, import_h3_js.polygonToCells)(
5623
+ turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
5624
+ resolution,
5625
+ true
5626
+ )
5627
+ );
5668
5628
  }
5669
5629
  }
5670
5630
  function getSpatialIndex(spatialDataType) {
@@ -5692,7 +5652,7 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5692
5652
 
5693
5653
  // src/filters/tileFeaturesRaster.ts
5694
5654
  init_cjs_shims();
5695
- var import_quadbin3 = require("quadbin");
5655
+ var import_quadbin2 = require("quadbin");
5696
5656
  function tileFeaturesRaster({
5697
5657
  tiles,
5698
5658
  ...options
@@ -5703,21 +5663,21 @@ function tileFeaturesRaster({
5703
5663
  }
5704
5664
  tiles = tiles.filter(isRasterTileVisible);
5705
5665
  if (tiles.length === 0) return [];
5706
- const tileResolution = (0, import_quadbin3.getResolution)(tiles[0].index.q);
5666
+ const tileResolution = (0, import_quadbin2.getResolution)(tiles[0].index.q);
5707
5667
  const tileBlockSize = tiles[0].data.blockSize;
5708
5668
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
5709
5669
  const data = /* @__PURE__ */ new Map();
5710
5670
  for (const tile of tiles) {
5711
5671
  const parent = tile.index.q;
5712
- const intersection3 = intersectTileRaster(
5713
- parent,
5714
- cellResolution,
5715
- options.spatialFilter
5672
+ const tilePolygon = (0, import_quadbin2.cellToBoundary)(parent);
5673
+ const tileFilter = turf_intersect_default(
5674
+ featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
5716
5675
  );
5717
- if (intersection3 === false) continue;
5676
+ const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
5677
+ const tileFilterCells = needsFilter ? new Set((0, import_quadbin2.geometryToCells)(tileFilter.geometry, cellResolution)) : null;
5718
5678
  const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5719
5679
  for (let i = 0; i < tileSortedCells.length; i++) {
5720
- if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5680
+ if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
5721
5681
  continue;
5722
5682
  }
5723
5683
  const cellData = {};
@@ -5744,10 +5704,10 @@ function isRasterTileVisible(tile) {
5744
5704
  return !!(tile.isVisible && tile.data?.cells?.numericProps);
5745
5705
  }
5746
5706
  function cellToChildrenSorted(parent, resolution) {
5747
- return (0, import_quadbin3.cellToChildren)(parent, resolution).sort(
5707
+ return (0, import_quadbin2.cellToChildren)(parent, resolution).sort(
5748
5708
  (cellA, cellB) => {
5749
- const tileA = (0, import_quadbin3.cellToTile)(cellA);
5750
- const tileB = (0, import_quadbin3.cellToTile)(cellB);
5709
+ const tileA = (0, import_quadbin2.cellToTile)(cellA);
5710
+ const tileB = (0, import_quadbin2.cellToTile)(cellB);
5751
5711
  if (tileA.y !== tileB.y) {
5752
5712
  return tileA.y > tileB.y ? 1 : -1;
5753
5713
  }
@@ -6551,6 +6511,10 @@ function getApplicableFilters(owner, filters) {
6551
6511
  return applicableFilters;
6552
6512
  }
6553
6513
 
6514
+ // src/widget-sources/constants.ts
6515
+ init_cjs_shims();
6516
+ var OTHERS_CATEGORY_NAME = "_carto_others";
6517
+
6554
6518
  // src/widget-sources/widget-remote-source.ts
6555
6519
  var WidgetRemoteSource = class extends WidgetSource {
6556
6520
  _getModelSource(filters, filterOwner) {
@@ -6574,13 +6538,21 @@ var WidgetRemoteSource = class extends WidgetSource {
6574
6538
  filterOwner,
6575
6539
  spatialFilter,
6576
6540
  spatialFiltersMode,
6541
+ rawResult,
6577
6542
  ...params
6578
6543
  } = options;
6579
- const { column, operation: operation2, operationColumn, operationExp } = params;
6544
+ const {
6545
+ column,
6546
+ operation: operation2,
6547
+ operationColumn,
6548
+ operationExp,
6549
+ othersThreshold,
6550
+ orderBy
6551
+ } = params;
6580
6552
  if (operation2 === AggregationTypes.Custom) {
6581
6553
  assert2(operationExp, "operationExp is required for custom operation");
6582
6554
  }
6583
- return executeModel({
6555
+ const result = await executeModel({
6584
6556
  model: "category",
6585
6557
  source: {
6586
6558
  ...this.getModelSource(filters, filterOwner),
@@ -6591,10 +6563,23 @@ var WidgetRemoteSource = class extends WidgetSource {
6591
6563
  column,
6592
6564
  operation: operation2,
6593
6565
  operationExp,
6594
- operationColumn: operationColumn || column
6566
+ operationColumn: operationColumn || column,
6567
+ othersThreshold,
6568
+ orderBy
6595
6569
  },
6596
6570
  opts: { signal, headers: this.props.headers }
6597
- }).then((res) => normalizeObjectKeys(res.rows));
6571
+ });
6572
+ const normalizedRows = normalizeObjectKeys(result.rows || []);
6573
+ if (rawResult) {
6574
+ return result;
6575
+ }
6576
+ if (!othersThreshold) {
6577
+ return normalizedRows;
6578
+ }
6579
+ return [
6580
+ ...normalizedRows,
6581
+ { name: OTHERS_CATEGORY_NAME, value: result?.metadata?.others }
6582
+ ];
6598
6583
  }
6599
6584
  async getFeatures(options) {
6600
6585
  const {
@@ -6999,10 +6984,12 @@ function groupValuesByColumn({
6999
6984
  valuesColumns,
7000
6985
  joinOperation,
7001
6986
  keysColumn,
7002
- operation: operation2
6987
+ operation: operation2,
6988
+ othersThreshold,
6989
+ orderBy = "frequency_desc"
7003
6990
  }) {
7004
6991
  if (Array.isArray(data) && data.length === 0) {
7005
- return null;
6992
+ return { rows: null };
7006
6993
  }
7007
6994
  const groups = data.reduce((accumulator, item) => {
7008
6995
  const group2 = item[keysColumn];
@@ -7017,13 +7004,44 @@ function groupValuesByColumn({
7017
7004
  return accumulator;
7018
7005
  }, /* @__PURE__ */ new Map());
7019
7006
  const targetOperation = aggregationFunctions[operation2];
7020
- if (targetOperation) {
7021
- return Array.from(groups).map(([name, value]) => ({
7022
- name,
7023
- value: targetOperation(value)
7024
- }));
7007
+ if (!targetOperation) {
7008
+ return { rows: [] };
7009
+ }
7010
+ const allCategories = Array.from(groups).map(([name, value]) => ({
7011
+ name,
7012
+ value: targetOperation(value)
7013
+ })).sort(getSorter(orderBy));
7014
+ if (othersThreshold && allCategories.length > othersThreshold) {
7015
+ const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
7016
+ allCategories.push({
7017
+ name: OTHERS_CATEGORY_NAME,
7018
+ value: targetOperation(otherValue)
7019
+ });
7020
+ return {
7021
+ rows: allCategories,
7022
+ metadata: {
7023
+ others: targetOperation(otherValue)
7024
+ }
7025
+ };
7026
+ }
7027
+ return {
7028
+ rows: allCategories
7029
+ };
7030
+ }
7031
+ function getSorter(orderBy) {
7032
+ switch (orderBy) {
7033
+ case "frequency_asc":
7034
+ return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
7035
+ case "frequency_desc":
7036
+ return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
7037
+ case "alphabetical_asc":
7038
+ return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
7039
+ case "alphabetical_desc":
7040
+ return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
7025
7041
  }
7026
- return [];
7042
+ }
7043
+ function localeCompare(a, b) {
7044
+ return (a ?? "null").localeCompare(b ?? "null");
7027
7045
  }
7028
7046
 
7029
7047
  // src/operations/groupByDate.ts
@@ -7508,7 +7526,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7508
7526
  }
7509
7527
  _extractTileFeatures(spatialFilter) {
7510
7528
  const prevInputs = this._tileFeatureExtractPreviousInputs;
7511
- if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
7529
+ if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
7512
7530
  return;
7513
7531
  }
7514
7532
  this._features = tileFeatures({
@@ -7597,7 +7615,10 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7597
7615
  joinOperation,
7598
7616
  filters,
7599
7617
  filterOwner,
7600
- spatialFilter
7618
+ spatialFilter,
7619
+ othersThreshold,
7620
+ orderBy = "frequency_desc",
7621
+ rawResult
7601
7622
  }) {
7602
7623
  const filteredFeatures = this._getFilteredFeatures(
7603
7624
  spatialFilter,
@@ -7608,14 +7629,25 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7608
7629
  return [];
7609
7630
  }
7610
7631
  assertColumn(this._features, column, operationColumn);
7611
- const groups = groupValuesByColumn({
7632
+ const result = groupValuesByColumn({
7612
7633
  data: filteredFeatures,
7613
7634
  valuesColumns: normalizeColumns(operationColumn || column),
7614
7635
  joinOperation,
7615
7636
  keysColumn: column,
7616
- operation: operation2
7637
+ operation: operation2,
7638
+ othersThreshold,
7639
+ orderBy
7617
7640
  });
7618
- return groups || [];
7641
+ if (rawResult) {
7642
+ return result;
7643
+ }
7644
+ if (!othersThreshold) {
7645
+ return result?.rows || [];
7646
+ }
7647
+ return [
7648
+ ...result?.rows || [],
7649
+ { name: OTHERS_CATEGORY_NAME, value: result?.metadata?.others }
7650
+ ];
7619
7651
  }
7620
7652
  async getScatter({
7621
7653
  xAxisColumn,
@@ -7748,6 +7780,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7748
7780
  * INTERNAL
7749
7781
  */
7750
7782
  _getFilteredFeatures(spatialFilter, filters, filterOwner) {
7783
+ assert2(spatialFilter, "spatialFilter required for tilesets");
7751
7784
  this._extractTileFeatures(spatialFilter);
7752
7785
  return applyFilters(
7753
7786
  this._features,
@@ -7771,11 +7804,6 @@ function assertColumn(features, ...columnArgs) {
7771
7804
  function normalizeColumns(columns) {
7772
7805
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
7773
7806
  }
7774
- function spatialFilterEquals(a, b) {
7775
- if (a === b) return true;
7776
- if (!a || !b) return false;
7777
- return booleanEqual(a, b);
7778
- }
7779
7807
 
7780
7808
  // src/widget-sources/widget-tileset-source.ts
7781
7809
  var WidgetTilesetSource = class extends WidgetSource {
@@ -10408,6 +10436,7 @@ function hashBuckets(initialCount) {
10408
10436
  FEATURE_GEOM_PROPERTY,
10409
10437
  FilterType,
10410
10438
  OPACITY_MAP,
10439
+ OTHERS_CATEGORY_NAME,
10411
10440
  Provider,
10412
10441
  SOURCE_DEFAULTS,
10413
10442
  SchemaFieldType,
@@ -10458,6 +10487,7 @@ function hashBuckets(initialCount) {
10458
10487
  getLayerProps,
10459
10488
  getMaxMarkerSize,
10460
10489
  getSizeAccessor,
10490
+ getSorter,
10461
10491
  getSpatialIndexFromGeoColumn,
10462
10492
  getTextAccessor,
10463
10493
  groupValuesByColumn,