@carto/api-client 0.5.7 → 0.5.8-alpha-others-orderby.2
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/api-client.cjs +88 -16
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +41 -13
- package/build/api-client.d.ts +41 -13
- package/build/api-client.js +85 -16
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +58 -12
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +58 -12
- package/build/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/operations/groupBy.ts +56 -12
- package/src/operations/groupByDate.ts +6 -1
- package/src/widget-sources/constants.ts +6 -0
- package/src/widget-sources/index.ts +1 -0
- package/src/widget-sources/types.ts +25 -1
- package/src/widget-sources/widget-remote-source.ts +28 -5
- package/src/widget-sources/widget-tileset-source-impl.ts +19 -2
package/build/worker-compat.js
CHANGED
|
@@ -20087,10 +20087,12 @@
|
|
|
20087
20087
|
valuesColumns,
|
|
20088
20088
|
joinOperation,
|
|
20089
20089
|
keysColumn,
|
|
20090
|
-
operation: operation2
|
|
20090
|
+
operation: operation2,
|
|
20091
|
+
othersThreshold,
|
|
20092
|
+
orderBy = "frequency_desc"
|
|
20091
20093
|
}) {
|
|
20092
20094
|
if (Array.isArray(data) && data.length === 0) {
|
|
20093
|
-
return null;
|
|
20095
|
+
return { rows: null };
|
|
20094
20096
|
}
|
|
20095
20097
|
const groups = data.reduce((accumulator, item) => {
|
|
20096
20098
|
const group = item[keysColumn];
|
|
@@ -20105,13 +20107,40 @@
|
|
|
20105
20107
|
return accumulator;
|
|
20106
20108
|
}, /* @__PURE__ */ new Map());
|
|
20107
20109
|
const targetOperation = aggregationFunctions[operation2];
|
|
20108
|
-
if (targetOperation) {
|
|
20109
|
-
return
|
|
20110
|
-
name,
|
|
20111
|
-
value: targetOperation(value)
|
|
20112
|
-
}));
|
|
20110
|
+
if (!targetOperation) {
|
|
20111
|
+
return { rows: [] };
|
|
20113
20112
|
}
|
|
20114
|
-
|
|
20113
|
+
const allCategories = Array.from(groups).map(([name, value]) => ({
|
|
20114
|
+
name,
|
|
20115
|
+
value: targetOperation(value)
|
|
20116
|
+
})).sort(getSorter(orderBy));
|
|
20117
|
+
if (othersThreshold && allCategories.length > othersThreshold) {
|
|
20118
|
+
const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
|
|
20119
|
+
return {
|
|
20120
|
+
rows: allCategories,
|
|
20121
|
+
metadata: {
|
|
20122
|
+
others: targetOperation(otherValue)
|
|
20123
|
+
}
|
|
20124
|
+
};
|
|
20125
|
+
}
|
|
20126
|
+
return {
|
|
20127
|
+
rows: allCategories
|
|
20128
|
+
};
|
|
20129
|
+
}
|
|
20130
|
+
function getSorter(orderBy) {
|
|
20131
|
+
switch (orderBy) {
|
|
20132
|
+
case "frequency_asc":
|
|
20133
|
+
return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
|
|
20134
|
+
case "frequency_desc":
|
|
20135
|
+
return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
|
|
20136
|
+
case "alphabetical_asc":
|
|
20137
|
+
return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
|
|
20138
|
+
case "alphabetical_desc":
|
|
20139
|
+
return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
|
|
20140
|
+
}
|
|
20141
|
+
}
|
|
20142
|
+
function localeCompare(a, b) {
|
|
20143
|
+
return (a ?? "null").localeCompare(b ?? "null");
|
|
20115
20144
|
}
|
|
20116
20145
|
|
|
20117
20146
|
// src/utils/dateUtils.ts
|
|
@@ -20616,6 +20645,9 @@
|
|
|
20616
20645
|
return applicableFilters;
|
|
20617
20646
|
}
|
|
20618
20647
|
|
|
20648
|
+
// src/widget-sources/constants.ts
|
|
20649
|
+
var OTHERS_CATEGORY_NAME = "_carto_others";
|
|
20650
|
+
|
|
20619
20651
|
// src/widget-sources/widget-tileset-source-impl.ts
|
|
20620
20652
|
var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
20621
20653
|
constructor() {
|
|
@@ -20730,7 +20762,10 @@
|
|
|
20730
20762
|
joinOperation,
|
|
20731
20763
|
filters,
|
|
20732
20764
|
filterOwner,
|
|
20733
|
-
spatialFilter
|
|
20765
|
+
spatialFilter,
|
|
20766
|
+
othersThreshold,
|
|
20767
|
+
orderBy = "frequency_desc",
|
|
20768
|
+
rawResult
|
|
20734
20769
|
}) {
|
|
20735
20770
|
const filteredFeatures = this._getFilteredFeatures(
|
|
20736
20771
|
spatialFilter,
|
|
@@ -20741,14 +20776,25 @@
|
|
|
20741
20776
|
return [];
|
|
20742
20777
|
}
|
|
20743
20778
|
assertColumn(this._features, column, operationColumn);
|
|
20744
|
-
const
|
|
20779
|
+
const result = groupValuesByColumn({
|
|
20745
20780
|
data: filteredFeatures,
|
|
20746
20781
|
valuesColumns: normalizeColumns(operationColumn || column),
|
|
20747
20782
|
joinOperation,
|
|
20748
20783
|
keysColumn: column,
|
|
20749
|
-
operation: operation2
|
|
20784
|
+
operation: operation2,
|
|
20785
|
+
othersThreshold,
|
|
20786
|
+
orderBy
|
|
20750
20787
|
});
|
|
20751
|
-
|
|
20788
|
+
if (rawResult) {
|
|
20789
|
+
return result;
|
|
20790
|
+
}
|
|
20791
|
+
if (!othersThreshold) {
|
|
20792
|
+
return result?.rows || [];
|
|
20793
|
+
}
|
|
20794
|
+
return [
|
|
20795
|
+
...result?.rows || [],
|
|
20796
|
+
{ name: OTHERS_CATEGORY_NAME, value: result?.metadata?.others }
|
|
20797
|
+
];
|
|
20752
20798
|
}
|
|
20753
20799
|
async getScatter({
|
|
20754
20800
|
xAxisColumn,
|