@carto/api-client 0.5.8-alpha-others-orderby.2 → 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/build/worker.js CHANGED
@@ -5414,11 +5414,7 @@ var DEFAULT_AGGREGATION_EXP_ALIAS = "__aggregationValue";
5414
5414
  var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5415
5415
 
5416
5416
  // src/filters/tileFeaturesRaster.ts
5417
- import {
5418
- cellToChildren as _cellToChildren,
5419
- cellToTile,
5420
- getResolution as getResolution2
5421
- } from "quadbin";
5417
+ import { cellToTile, getResolution as getResolution2, tileToCell } from "quadbin";
5422
5418
  function tileFeaturesRaster({
5423
5419
  tiles,
5424
5420
  ...options
@@ -5441,7 +5437,7 @@ function tileFeaturesRaster({
5441
5437
  options.spatialFilter
5442
5438
  );
5443
5439
  if (intersection3 === false) continue;
5444
- const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5440
+ const tileSortedCells = cellToChildrenRaster(parent, cellResolution);
5445
5441
  for (let i = 0; i < tileSortedCells.length; i++) {
5446
5442
  if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5447
5443
  continue;
@@ -5469,17 +5465,19 @@ function isRasterTile(tile) {
5469
5465
  function isRasterTileVisible(tile) {
5470
5466
  return !!(tile.isVisible && tile.data?.cells?.numericProps);
5471
5467
  }
5472
- function cellToChildrenSorted(parent, resolution) {
5473
- return _cellToChildren(parent, resolution).sort(
5474
- (cellA, cellB) => {
5475
- const tileA = cellToTile(cellA);
5476
- const tileB = cellToTile(cellB);
5477
- if (tileA.y !== tileB.y) {
5478
- return tileA.y > tileB.y ? 1 : -1;
5479
- }
5480
- return tileA.x > tileB.x ? 1 : -1;
5481
- }
5482
- );
5468
+ function cellToChildrenRaster(parent, resolution) {
5469
+ const parentTile = cellToTile(parent);
5470
+ const childZ = Number(resolution);
5471
+ const blockSize = 2 ** (childZ - parentTile.z);
5472
+ const childBaseX = parentTile.x * blockSize;
5473
+ const childBaseY = parentTile.y * blockSize;
5474
+ const cells = [];
5475
+ for (let i = 0, il = blockSize ** 2; i < il; i++) {
5476
+ const x = childBaseX + i % blockSize;
5477
+ const y = childBaseY + Math.floor(i / blockSize);
5478
+ cells.push(tileToCell({ x, y, z: childZ }));
5479
+ }
5480
+ return cells;
5483
5481
  }
5484
5482
  function isValidBandValue(value, nodata) {
5485
5483
  return Number.isNaN(value) ? false : nodata !== value;
@@ -5685,8 +5683,7 @@ function groupValuesByColumn({
5685
5683
  joinOperation,
5686
5684
  keysColumn,
5687
5685
  operation: operation2,
5688
- othersThreshold,
5689
- orderBy = "frequency_desc"
5686
+ othersThreshold
5690
5687
  }) {
5691
5688
  if (Array.isArray(data) && data.length === 0) {
5692
5689
  return { rows: null };
@@ -5710,7 +5707,7 @@ function groupValuesByColumn({
5710
5707
  const allCategories = Array.from(groups).map(([name, value]) => ({
5711
5708
  name,
5712
5709
  value: targetOperation(value)
5713
- })).sort(getSorter(orderBy));
5710
+ })).sort((a, b) => b.value - a.value);
5714
5711
  if (othersThreshold && allCategories.length > othersThreshold) {
5715
5712
  const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
5716
5713
  return {
@@ -5724,21 +5721,6 @@ function groupValuesByColumn({
5724
5721
  rows: allCategories
5725
5722
  };
5726
5723
  }
5727
- function getSorter(orderBy) {
5728
- switch (orderBy) {
5729
- case "frequency_asc":
5730
- return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
5731
- case "frequency_desc":
5732
- return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
5733
- case "alphabetical_asc":
5734
- return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
5735
- case "alphabetical_desc":
5736
- return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
5737
- }
5738
- }
5739
- function localeCompare(a, b) {
5740
- return (a ?? "null").localeCompare(b ?? "null");
5741
- }
5742
5724
 
5743
5725
  // src/utils/dateUtils.ts
5744
5726
  function getUTCMonday(date) {
@@ -6361,7 +6343,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6361
6343
  filterOwner,
6362
6344
  spatialFilter,
6363
6345
  othersThreshold,
6364
- orderBy = "frequency_desc",
6365
6346
  rawResult
6366
6347
  }) {
6367
6348
  const filteredFeatures = this._getFilteredFeatures(
@@ -6379,8 +6360,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6379
6360
  joinOperation,
6380
6361
  keysColumn: column,
6381
6362
  operation: operation2,
6382
- othersThreshold,
6383
- orderBy
6363
+ othersThreshold
6384
6364
  });
6385
6365
  if (rawResult) {
6386
6366
  return result;