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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## 0.5
4
4
 
5
+ ## 0.5.8
6
+
7
+ - feat(widgets): Add othersThreshold to WidgetSource.getCategories (#194)
8
+ - perf(rasters): Improve performance of raster widget spatial filtering (#207)
9
+
5
10
  ### 0.5.7
6
11
 
7
12
  - feat(widgets): Allow local widget calculations without spatial filter (#204)
@@ -159,7 +159,6 @@ __export(src_exports, {
159
159
  getLayerProps: () => getLayerProps,
160
160
  getMaxMarkerSize: () => getMaxMarkerSize,
161
161
  getSizeAccessor: () => getSizeAccessor,
162
- getSorter: () => getSorter,
163
162
  getSpatialIndexFromGeoColumn: () => getSpatialIndexFromGeoColumn,
164
163
  getTextAccessor: () => getTextAccessor,
165
164
  groupValuesByColumn: () => groupValuesByColumn,
@@ -5717,7 +5716,7 @@ function tileFeaturesRaster({
5717
5716
  options.spatialFilter
5718
5717
  );
5719
5718
  if (intersection3 === false) continue;
5720
- const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5719
+ const tileSortedCells = cellToChildrenRaster(parent, cellResolution);
5721
5720
  for (let i = 0; i < tileSortedCells.length; i++) {
5722
5721
  if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5723
5722
  continue;
@@ -5745,17 +5744,19 @@ function isRasterTile(tile) {
5745
5744
  function isRasterTileVisible(tile) {
5746
5745
  return !!(tile.isVisible && tile.data?.cells?.numericProps);
5747
5746
  }
5748
- function cellToChildrenSorted(parent, resolution) {
5749
- return (0, import_quadbin3.cellToChildren)(parent, resolution).sort(
5750
- (cellA, cellB) => {
5751
- const tileA = (0, import_quadbin3.cellToTile)(cellA);
5752
- const tileB = (0, import_quadbin3.cellToTile)(cellB);
5753
- if (tileA.y !== tileB.y) {
5754
- return tileA.y > tileB.y ? 1 : -1;
5755
- }
5756
- return tileA.x > tileB.x ? 1 : -1;
5757
- }
5758
- );
5747
+ function cellToChildrenRaster(parent, resolution) {
5748
+ const parentTile = (0, import_quadbin3.cellToTile)(parent);
5749
+ const childZ = Number(resolution);
5750
+ const blockSize = 2 ** (childZ - parentTile.z);
5751
+ const childBaseX = parentTile.x * blockSize;
5752
+ const childBaseY = parentTile.y * blockSize;
5753
+ const cells = [];
5754
+ for (let i = 0, il = blockSize ** 2; i < il; i++) {
5755
+ const x = childBaseX + i % blockSize;
5756
+ const y = childBaseY + Math.floor(i / blockSize);
5757
+ cells.push((0, import_quadbin3.tileToCell)({ x, y, z: childZ }));
5758
+ }
5759
+ return cells;
5759
5760
  }
5760
5761
  function isValidBandValue(value, nodata) {
5761
5762
  return Number.isNaN(value) ? false : nodata !== value;
@@ -6583,14 +6584,7 @@ var WidgetRemoteSource = class extends WidgetSource {
6583
6584
  rawResult,
6584
6585
  ...params
6585
6586
  } = options;
6586
- const {
6587
- column,
6588
- operation: operation2,
6589
- operationColumn,
6590
- operationExp,
6591
- othersThreshold,
6592
- orderBy
6593
- } = params;
6587
+ const { column, operation: operation2, operationColumn, operationExp, othersThreshold } = params;
6594
6588
  if (operation2 === AggregationTypes.Custom) {
6595
6589
  assert2(operationExp, "operationExp is required for custom operation");
6596
6590
  }
@@ -6606,8 +6600,7 @@ var WidgetRemoteSource = class extends WidgetSource {
6606
6600
  operation: operation2,
6607
6601
  operationExp,
6608
6602
  operationColumn: operationColumn || column,
6609
- othersThreshold,
6610
- orderBy
6603
+ othersThreshold
6611
6604
  },
6612
6605
  opts: { signal, headers: this.props.headers }
6613
6606
  });
@@ -7027,8 +7020,7 @@ function groupValuesByColumn({
7027
7020
  joinOperation,
7028
7021
  keysColumn,
7029
7022
  operation: operation2,
7030
- othersThreshold,
7031
- orderBy = "frequency_desc"
7023
+ othersThreshold
7032
7024
  }) {
7033
7025
  if (Array.isArray(data) && data.length === 0) {
7034
7026
  return { rows: null };
@@ -7052,13 +7044,9 @@ function groupValuesByColumn({
7052
7044
  const allCategories = Array.from(groups).map(([name, value]) => ({
7053
7045
  name,
7054
7046
  value: targetOperation(value)
7055
- })).sort(getSorter(orderBy));
7047
+ })).sort((a, b) => b.value - a.value);
7056
7048
  if (othersThreshold && allCategories.length > othersThreshold) {
7057
7049
  const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
7058
- allCategories.push({
7059
- name: OTHERS_CATEGORY_NAME,
7060
- value: targetOperation(otherValue)
7061
- });
7062
7050
  return {
7063
7051
  rows: allCategories,
7064
7052
  metadata: {
@@ -7070,21 +7058,6 @@ function groupValuesByColumn({
7070
7058
  rows: allCategories
7071
7059
  };
7072
7060
  }
7073
- function getSorter(orderBy) {
7074
- switch (orderBy) {
7075
- case "frequency_asc":
7076
- return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
7077
- case "frequency_desc":
7078
- return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
7079
- case "alphabetical_asc":
7080
- return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
7081
- case "alphabetical_desc":
7082
- return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
7083
- }
7084
- }
7085
- function localeCompare(a, b) {
7086
- return (a ?? "null").localeCompare(b ?? "null");
7087
- }
7088
7061
 
7089
7062
  // src/operations/groupByDate.ts
7090
7063
  init_cjs_shims();
@@ -7659,7 +7632,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7659
7632
  filterOwner,
7660
7633
  spatialFilter,
7661
7634
  othersThreshold,
7662
- orderBy = "frequency_desc",
7663
7635
  rawResult
7664
7636
  }) {
7665
7637
  const filteredFeatures = this._getFilteredFeatures(
@@ -7677,8 +7649,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7677
7649
  joinOperation,
7678
7650
  keysColumn: column,
7679
7651
  operation: operation2,
7680
- othersThreshold,
7681
- orderBy
7652
+ othersThreshold
7682
7653
  });
7683
7654
  if (rawResult) {
7684
7655
  return result;
@@ -10533,7 +10504,6 @@ function hashBuckets(initialCount) {
10533
10504
  getLayerProps,
10534
10505
  getMaxMarkerSize,
10535
10506
  getSizeAccessor,
10536
- getSorter,
10537
10507
  getSpatialIndexFromGeoColumn,
10538
10508
  getTextAccessor,
10539
10509
  groupValuesByColumn,