@kepler.gl/table 3.3.0-alpha.2 → 3.3.0-alpha.21

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 (121) hide show
  1. package/dist/cjs/dataset-ops/aggregations.js +133 -0
  2. package/dist/cjs/dataset-ops/aggregations.js.map +1 -0
  3. package/dist/cjs/dataset-ops/column-edit.js +472 -0
  4. package/dist/cjs/dataset-ops/column-edit.js.map +1 -0
  5. package/dist/cjs/dataset-ops/geometry.js +237 -0
  6. package/dist/cjs/dataset-ops/geometry.js.map +1 -0
  7. package/dist/cjs/dataset-ops/group-by.js +139 -0
  8. package/dist/cjs/dataset-ops/group-by.js.map +1 -0
  9. package/dist/cjs/dataset-ops/index.js +135 -0
  10. package/dist/cjs/dataset-ops/index.js.map +1 -0
  11. package/dist/cjs/dataset-ops/join.js +213 -0
  12. package/dist/cjs/dataset-ops/join.js.map +1 -0
  13. package/dist/cjs/dataset-ops/normalize-bigint-columns.js +58 -0
  14. package/dist/cjs/dataset-ops/normalize-bigint-columns.js.map +1 -0
  15. package/dist/cjs/dataset-ops/proto-dataset.js +71 -0
  16. package/dist/cjs/dataset-ops/proto-dataset.js.map +1 -0
  17. package/dist/cjs/dataset-ops/spatial-join.js +340 -0
  18. package/dist/cjs/dataset-ops/spatial-join.js.map +1 -0
  19. package/dist/cjs/dataset-ops/suitability.js +200 -0
  20. package/dist/cjs/dataset-ops/suitability.js.map +1 -0
  21. package/dist/cjs/dataset-ops/table-helpers.js +48 -0
  22. package/dist/cjs/dataset-ops/table-helpers.js.map +1 -0
  23. package/dist/cjs/dataset-ops/types.js +81 -0
  24. package/dist/cjs/dataset-ops/types.js.map +1 -0
  25. package/dist/cjs/dataset-utils.js +466 -0
  26. package/dist/cjs/dataset-utils.js.map +1 -0
  27. package/dist/cjs/gpu-filter-utils.js +368 -0
  28. package/dist/cjs/gpu-filter-utils.js.map +1 -0
  29. package/dist/cjs/index.js +243 -0
  30. package/dist/cjs/index.js.map +1 -0
  31. package/dist/cjs/kepler-table.js +1044 -0
  32. package/dist/cjs/kepler-table.js.map +1 -0
  33. package/dist/cjs/tileset/raster-tile-utils.js +76 -0
  34. package/dist/cjs/tileset/raster-tile-utils.js.map +1 -0
  35. package/dist/cjs/tileset/tileset-utils.js +83 -0
  36. package/dist/cjs/tileset/tileset-utils.js.map +1 -0
  37. package/dist/cjs/tileset/vector-tile-utils.js +757 -0
  38. package/dist/cjs/tileset/vector-tile-utils.js.map +1 -0
  39. package/dist/cjs/tileset/wms-utils.js +236 -0
  40. package/dist/cjs/tileset/wms-utils.js.map +1 -0
  41. package/dist/cjs/tileset/zarr-axis.js +178 -0
  42. package/dist/cjs/tileset/zarr-axis.js.map +1 -0
  43. package/dist/cjs/tileset/zarr-runtime.js +29 -0
  44. package/dist/cjs/tileset/zarr-runtime.js.map +1 -0
  45. package/dist/cjs/tileset/zarr-utils.js +2168 -0
  46. package/dist/cjs/tileset/zarr-utils.js.map +1 -0
  47. package/dist/dataset-ops/aggregations.d.ts +17 -0
  48. package/dist/dataset-ops/column-edit.d.ts +48 -0
  49. package/dist/dataset-ops/geometry.d.ts +13 -0
  50. package/dist/dataset-ops/group-by.d.ts +3 -0
  51. package/dist/dataset-ops/index.d.ts +12 -0
  52. package/dist/dataset-ops/join.d.ts +3 -0
  53. package/dist/dataset-ops/normalize-bigint-columns.d.ts +7 -0
  54. package/dist/dataset-ops/proto-dataset.d.ts +20 -0
  55. package/dist/dataset-ops/spatial-join.d.ts +17 -0
  56. package/dist/dataset-ops/suitability.d.ts +15 -0
  57. package/dist/dataset-ops/table-helpers.d.ts +12 -0
  58. package/dist/dataset-ops/types.d.ts +164 -0
  59. package/dist/dataset-utils.d.ts +2 -2
  60. package/dist/esm/dataset-ops/aggregations.js +120 -0
  61. package/dist/esm/dataset-ops/aggregations.js.map +1 -0
  62. package/dist/esm/dataset-ops/column-edit.js +460 -0
  63. package/dist/esm/dataset-ops/column-edit.js.map +1 -0
  64. package/dist/esm/dataset-ops/geometry.js +225 -0
  65. package/dist/esm/dataset-ops/geometry.js.map +1 -0
  66. package/dist/esm/dataset-ops/group-by.js +134 -0
  67. package/dist/esm/dataset-ops/group-by.js.map +1 -0
  68. package/dist/esm/dataset-ops/index.js +24 -0
  69. package/dist/esm/dataset-ops/index.js.map +1 -0
  70. package/dist/esm/dataset-ops/join.js +208 -0
  71. package/dist/esm/dataset-ops/join.js.map +1 -0
  72. package/dist/esm/dataset-ops/normalize-bigint-columns.js +51 -0
  73. package/dist/esm/dataset-ops/normalize-bigint-columns.js.map +1 -0
  74. package/dist/esm/dataset-ops/proto-dataset.js +62 -0
  75. package/dist/esm/dataset-ops/proto-dataset.js.map +1 -0
  76. package/dist/esm/dataset-ops/spatial-join.js +332 -0
  77. package/dist/esm/dataset-ops/spatial-join.js.map +1 -0
  78. package/dist/esm/dataset-ops/suitability.js +191 -0
  79. package/dist/esm/dataset-ops/suitability.js.map +1 -0
  80. package/dist/esm/dataset-ops/table-helpers.js +38 -0
  81. package/dist/esm/dataset-ops/table-helpers.js.map +1 -0
  82. package/dist/esm/dataset-ops/types.js +74 -0
  83. package/dist/esm/dataset-ops/types.js.map +1 -0
  84. package/dist/esm/dataset-utils.js +460 -0
  85. package/dist/esm/dataset-utils.js.map +1 -0
  86. package/dist/esm/gpu-filter-utils.js +357 -0
  87. package/dist/esm/gpu-filter-utils.js.map +1 -0
  88. package/dist/esm/index.js +18 -0
  89. package/dist/esm/index.js.map +1 -0
  90. package/dist/esm/kepler-table.js +1031 -0
  91. package/dist/esm/kepler-table.js.map +1 -0
  92. package/dist/esm/tileset/raster-tile-utils.js +69 -0
  93. package/dist/esm/tileset/raster-tile-utils.js.map +1 -0
  94. package/dist/esm/tileset/tileset-utils.js +79 -0
  95. package/dist/esm/tileset/tileset-utils.js.map +1 -0
  96. package/dist/esm/tileset/vector-tile-utils.js +747 -0
  97. package/dist/esm/tileset/vector-tile-utils.js.map +1 -0
  98. package/dist/esm/tileset/wms-utils.js +224 -0
  99. package/dist/esm/tileset/wms-utils.js.map +1 -0
  100. package/dist/esm/tileset/zarr-axis.js +167 -0
  101. package/dist/esm/tileset/zarr-axis.js.map +1 -0
  102. package/dist/esm/tileset/zarr-runtime.js +22 -0
  103. package/dist/esm/tileset/zarr-runtime.js.map +1 -0
  104. package/dist/esm/tileset/zarr-utils.js +2144 -0
  105. package/dist/esm/tileset/zarr-utils.js.map +1 -0
  106. package/dist/gpu-filter-utils.d.ts +4 -0
  107. package/dist/index.d.ts +7 -1
  108. package/dist/kepler-table.d.ts +56 -5
  109. package/dist/tileset/wms-utils.d.ts +40 -0
  110. package/dist/tileset/zarr-axis.d.ts +23 -0
  111. package/dist/tileset/zarr-runtime.d.ts +4 -0
  112. package/dist/tileset/zarr-utils.d.ts +200 -0
  113. package/package.json +36 -19
  114. package/dist/dataset-utils.js +0 -440
  115. package/dist/gpu-filter-utils.js +0 -254
  116. package/dist/index.js +0 -127
  117. package/dist/kepler-table.js +0 -648
  118. package/dist/tileset/raster-tile-utils.js +0 -76
  119. package/dist/tileset/tileset-utils.js +0 -73
  120. package/dist/tileset/vector-tile-utils.js +0 -741
  121. package/dist/tileset/vector-tile-utils.spec.js +0 -303
@@ -0,0 +1,164 @@
1
+ import { Field, ProtoDataset, RGBColor } from '@kepler.gl/types';
2
+ import { DataContainerInterface } from '@kepler.gl/utils';
3
+ export declare const DATASET_OPS_AGGREGATIONS: {
4
+ readonly count: "count";
5
+ readonly sum: "sum";
6
+ readonly average: "average";
7
+ readonly maximum: "maximum";
8
+ readonly minimum: "minimum";
9
+ readonly median: "median";
10
+ readonly countUnique: "countUnique";
11
+ readonly merge: "merge";
12
+ };
13
+ export type DatasetOpAggregation = (typeof DATASET_OPS_AGGREGATIONS)[keyof typeof DATASET_OPS_AGGREGATIONS];
14
+ export type DerivedDatasetType = 'groupBy' | 'join' | 'spatialJoin' | 'suitability';
15
+ export type DerivedDatasetMetadata = {
16
+ type: DerivedDatasetType;
17
+ sourceDataIds: string[];
18
+ operationId: string;
19
+ };
20
+ export type DatasetOpsTable = {
21
+ id: string;
22
+ label: string;
23
+ color: RGBColor;
24
+ fields: Field[];
25
+ dataContainer: DataContainerInterface;
26
+ type?: string;
27
+ disableDataOperation?: boolean;
28
+ metadata?: Record<string, any>;
29
+ };
30
+ export type GroupByDatasetConfig = {
31
+ fieldName: string;
32
+ aggregations: Record<string, DatasetOpAggregation>;
33
+ label?: string;
34
+ resultId?: string;
35
+ operationId?: string;
36
+ };
37
+ export type AttributeJoinType = 'LEFT' | 'INNER' | 'FULL';
38
+ export type JoinDatasetConfig = {
39
+ leftField: string;
40
+ rightField: string;
41
+ type: AttributeJoinType;
42
+ leftColumns?: string[];
43
+ rightColumns?: string[];
44
+ label?: string;
45
+ resultId?: string;
46
+ operationId?: string;
47
+ };
48
+ export type SpatialGeoSource = {
49
+ kind: 'geojson';
50
+ fieldName: string;
51
+ } | {
52
+ kind: 'h3';
53
+ fieldName: string;
54
+ } | {
55
+ kind: 'latlng';
56
+ latField: string;
57
+ lngField: string;
58
+ };
59
+ export declare function fieldNamesForGeoSource(geo: SpatialGeoSource): string[];
60
+ export declare const SPATIAL_JOIN_PREDICATES: {
61
+ readonly intersects: "intersects";
62
+ readonly equals: "equals";
63
+ readonly crosses: "crosses";
64
+ readonly overlaps: "overlaps";
65
+ readonly within: "within";
66
+ readonly touches: "touches";
67
+ };
68
+ export type SpatialJoinPredicate = (typeof SPATIAL_JOIN_PREDICATES)[keyof typeof SPATIAL_JOIN_PREDICATES];
69
+ export declare const SPATIAL_JOIN_PREDICATE_OPTIONS: {
70
+ id: SpatialJoinPredicate;
71
+ labelId: string;
72
+ }[];
73
+ export type SpatialJoinDatasetConfig = {
74
+ leftGeo: SpatialGeoSource;
75
+ rightGeo: SpatialGeoSource;
76
+ aggregations: Record<string, DatasetOpAggregation>;
77
+ leftColumns?: string[];
78
+ predicate?: SpatialJoinPredicate;
79
+ label?: string;
80
+ resultId?: string;
81
+ operationId?: string;
82
+ };
83
+ export type GroupByOp = {
84
+ id: string;
85
+ dataId: string;
86
+ fieldName: string | null;
87
+ aggregations: Record<string, DatasetOpAggregation>;
88
+ resultId: string;
89
+ resultLabel: string;
90
+ isConfigActive: boolean;
91
+ error?: string | null;
92
+ };
93
+ export type JoinImplementation = 'simple' | 'spatial';
94
+ export type JoinOp = {
95
+ id: string;
96
+ implementation: JoinImplementation;
97
+ leftDataId: string;
98
+ rightDataId: string | null;
99
+ leftField: string | null;
100
+ rightField: string | null;
101
+ type: AttributeJoinType;
102
+ leftColumns?: string[];
103
+ rightColumns?: string[];
104
+ leftGeo?: SpatialGeoSource | null;
105
+ rightGeo?: SpatialGeoSource | null;
106
+ predicate?: SpatialJoinPredicate;
107
+ aggregations: Record<string, DatasetOpAggregation>;
108
+ resultId: string;
109
+ resultLabel: string;
110
+ isConfigActive: boolean;
111
+ error?: string | null;
112
+ };
113
+ export declare const WEIGHT_STANDARDIZATIONS: {
114
+ readonly raw: "raw";
115
+ readonly normalize: "normalize";
116
+ };
117
+ export type WeightStandardization = (typeof WEIGHT_STANDARDIZATIONS)[keyof typeof WEIGHT_STANDARDIZATIONS];
118
+ export declare const WEIGHT_STANDARDIZATION_OPTIONS: {
119
+ id: WeightStandardization;
120
+ labelId: string;
121
+ }[];
122
+ export declare const DATA_STANDARDIZATIONS: {
123
+ readonly raw: "raw";
124
+ readonly range: "range";
125
+ readonly zScore: "zScore";
126
+ };
127
+ export type DataStandardization = (typeof DATA_STANDARDIZATIONS)[keyof typeof DATA_STANDARDIZATIONS];
128
+ export declare const DATA_STANDARDIZATION_OPTIONS: {
129
+ id: DataStandardization;
130
+ labelId: string;
131
+ }[];
132
+ export declare const DEFAULT_SUITABILITY_SCORE_FIELD = "score";
133
+ export declare const DEFAULT_SUITABILITY_WEIGHT = 1;
134
+ export declare const SUITABILITY_WEIGHT_RANGE: [number, number];
135
+ export type SuitabilityDatasetConfig = {
136
+ /** Weight per source field name. Fields absent from this map are not scored. */
137
+ weights: Record<string, number>;
138
+ weightStandardization?: WeightStandardization;
139
+ dataStandardization?: DataStandardization;
140
+ outputFieldName?: string;
141
+ columns?: string[];
142
+ label?: string;
143
+ resultId?: string;
144
+ operationId?: string;
145
+ };
146
+ export type SuitabilityOp = {
147
+ id: string;
148
+ dataId: string;
149
+ weights: Record<string, number>;
150
+ weightStandardization: WeightStandardization;
151
+ dataStandardization: DataStandardization;
152
+ outputFieldName: string;
153
+ columns?: string[];
154
+ resultId: string;
155
+ resultLabel: string;
156
+ isConfigActive: boolean;
157
+ error?: string | null;
158
+ };
159
+ export type DatasetOpsEngine = {
160
+ groupByDataset: (dataset: DatasetOpsTable, config: GroupByDatasetConfig) => ProtoDataset;
161
+ joinDatasets: (left: DatasetOpsTable, right: DatasetOpsTable, config: JoinDatasetConfig) => ProtoDataset;
162
+ spatialJoinDatasets: (left: DatasetOpsTable, right: DatasetOpsTable, config: SpatialJoinDatasetConfig) => ProtoDataset;
163
+ suitabilityDataset: (dataset: DatasetOpsTable, config: SuitabilityDatasetConfig) => ProtoDataset;
164
+ };
@@ -1,10 +1,10 @@
1
1
  import { Datasets } from './kepler-table';
2
2
  import { ProtoDataset, RGBColor } from '@kepler.gl/types';
3
+ import type { TaskDescriptor } from '@kepler.gl/tasks-core';
3
4
  import { WMSCapabilities } from '@loaders.gl/wms';
4
5
  export declare function getNewDatasetColor(datasets: Datasets): RGBColor;
5
6
  /**
6
7
  * Take datasets payload from addDataToMap, create datasets entry save to visState
7
8
  */
8
- export declare function createNewDataEntry({ info, data, ...opts }: ProtoDataset, datasets?: Datasets): Datasets | null;
9
+ export declare function createNewDataEntry({ info, data, ...opts }: ProtoDataset, datasets?: Datasets): TaskDescriptor | null;
9
10
  export declare function getWMSCapabilities(wsmUrl: string): Promise<WMSCapabilities>;
10
- export declare function wmsCapabilitiesToDatasetMetadata(capabilities: WMSCapabilities): any | null;
@@ -0,0 +1,120 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright contributors to the kepler.gl project
3
+
4
+ import { ALL_FIELD_TYPES } from '@kepler.gl/constants';
5
+ import { aggregate } from '@kepler.gl/utils';
6
+ import { notNullorUndefined } from '@kepler.gl/common-utils';
7
+ import { DATASET_OPS_AGGREGATIONS } from './types';
8
+ import { mergeGeometries } from './geometry';
9
+ export var DATASET_OPS_AGGREGATION_OPTIONS = [{
10
+ id: DATASET_OPS_AGGREGATIONS.merge,
11
+ labelId: 'datasetOps.aggregation.merge'
12
+ }, {
13
+ id: DATASET_OPS_AGGREGATIONS.count,
14
+ labelId: 'datasetOps.aggregation.count'
15
+ }, {
16
+ id: DATASET_OPS_AGGREGATIONS.sum,
17
+ labelId: 'datasetOps.aggregation.sum'
18
+ }, {
19
+ id: DATASET_OPS_AGGREGATIONS.average,
20
+ labelId: 'datasetOps.aggregation.average'
21
+ }, {
22
+ id: DATASET_OPS_AGGREGATIONS.maximum,
23
+ labelId: 'datasetOps.aggregation.maximum'
24
+ }, {
25
+ id: DATASET_OPS_AGGREGATIONS.minimum,
26
+ labelId: 'datasetOps.aggregation.minimum'
27
+ }, {
28
+ id: DATASET_OPS_AGGREGATIONS.median,
29
+ labelId: 'datasetOps.aggregation.median'
30
+ }, {
31
+ id: DATASET_OPS_AGGREGATIONS.countUnique,
32
+ labelId: 'datasetOps.aggregation.countUnique'
33
+ }];
34
+ var NUMERIC_FIELD_TYPES = new Set([ALL_FIELD_TYPES.integer, ALL_FIELD_TYPES.real]);
35
+ var CATEGORICAL_FIELD_TYPES = new Set([ALL_FIELD_TYPES.string, ALL_FIELD_TYPES.h3]);
36
+ var TIME_FIELD_TYPES = new Set([ALL_FIELD_TYPES.timestamp, ALL_FIELD_TYPES.date]);
37
+ export function aggregationIdsForFieldType(type) {
38
+ if (type && NUMERIC_FIELD_TYPES.has(type)) {
39
+ return [DATASET_OPS_AGGREGATIONS.count, DATASET_OPS_AGGREGATIONS.sum, DATASET_OPS_AGGREGATIONS.average, DATASET_OPS_AGGREGATIONS.maximum, DATASET_OPS_AGGREGATIONS.minimum, DATASET_OPS_AGGREGATIONS.median, DATASET_OPS_AGGREGATIONS.countUnique];
40
+ }
41
+ if (type === ALL_FIELD_TYPES["boolean"]) {
42
+ return [DATASET_OPS_AGGREGATIONS.count, DATASET_OPS_AGGREGATIONS.sum, DATASET_OPS_AGGREGATIONS.average, DATASET_OPS_AGGREGATIONS.countUnique];
43
+ }
44
+ if (type && TIME_FIELD_TYPES.has(type)) {
45
+ return [DATASET_OPS_AGGREGATIONS.count, DATASET_OPS_AGGREGATIONS.maximum, DATASET_OPS_AGGREGATIONS.minimum, DATASET_OPS_AGGREGATIONS.countUnique];
46
+ }
47
+ if (type && CATEGORICAL_FIELD_TYPES.has(type)) {
48
+ return [DATASET_OPS_AGGREGATIONS.count, DATASET_OPS_AGGREGATIONS.countUnique];
49
+ }
50
+ if (type === ALL_FIELD_TYPES.geojson || type === ALL_FIELD_TYPES.point) {
51
+ return [DATASET_OPS_AGGREGATIONS.merge, DATASET_OPS_AGGREGATIONS.count, DATASET_OPS_AGGREGATIONS.countUnique];
52
+ }
53
+ return [DATASET_OPS_AGGREGATIONS.count];
54
+ }
55
+ export function aggregationOptionsForField(field) {
56
+ var allowed = new Set(aggregationIdsForFieldType(field.type));
57
+ return DATASET_OPS_AGGREGATION_OPTIONS.filter(function (option) {
58
+ return allowed.has(option.id);
59
+ });
60
+ }
61
+ export function isDatasetOpsAggregationField(field) {
62
+ return aggregationIdsForFieldType(field.type).length > 1;
63
+ }
64
+ export function defaultAggregationForField(field) {
65
+ var allowed = aggregationIdsForFieldType(field.type);
66
+ if (field.type === ALL_FIELD_TYPES.integer || field.type === ALL_FIELD_TYPES.real) {
67
+ return DATASET_OPS_AGGREGATIONS.average;
68
+ }
69
+ if (field.type === ALL_FIELD_TYPES.string || field.type === ALL_FIELD_TYPES.h3) {
70
+ return DATASET_OPS_AGGREGATIONS.countUnique;
71
+ }
72
+ if (field.type === ALL_FIELD_TYPES.geojson || field.type === ALL_FIELD_TYPES.point) {
73
+ return DATASET_OPS_AGGREGATIONS.merge;
74
+ }
75
+ return allowed[0];
76
+ }
77
+ export function defaultAggregationsForFields(fields) {
78
+ var excludeNames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
79
+ var excluded = new Set(excludeNames);
80
+ var aggregations = {};
81
+ fields.forEach(function (field) {
82
+ if (!excluded.has(field.name) && isDatasetOpsAggregationField(field)) {
83
+ aggregations[field.name] = defaultAggregationForField(field);
84
+ }
85
+ });
86
+ return aggregations;
87
+ }
88
+ export function aggregateValues(values, technique) {
89
+ if (technique === DATASET_OPS_AGGREGATIONS.merge) {
90
+ return mergeGeometries(values);
91
+ }
92
+ var defined = values.filter(notNullorUndefined);
93
+ if (technique === DATASET_OPS_AGGREGATIONS.count) {
94
+ return values.length;
95
+ }
96
+ if (!defined.length) {
97
+ return null;
98
+ }
99
+ if (technique === DATASET_OPS_AGGREGATIONS.sum || technique === DATASET_OPS_AGGREGATIONS.average || technique === DATASET_OPS_AGGREGATIONS.median) {
100
+ // D3 arithmetic requires Numbers. Keep raw BigInts for exact extrema/distinct counts
101
+ // and leave the source data unchanged; arithmetic results use Number precision.
102
+ return aggregate(defined, technique, function (value) {
103
+ return typeof value === 'bigint' ? Number(value) : value;
104
+ });
105
+ }
106
+ return aggregate(defined, technique);
107
+ }
108
+ export function resultFieldType(technique, sourceType) {
109
+ if (technique === DATASET_OPS_AGGREGATIONS.merge) {
110
+ return ALL_FIELD_TYPES.geojson;
111
+ }
112
+ if (technique === DATASET_OPS_AGGREGATIONS.count || technique === DATASET_OPS_AGGREGATIONS.countUnique) {
113
+ return ALL_FIELD_TYPES.integer;
114
+ }
115
+ if (technique === DATASET_OPS_AGGREGATIONS.average || technique === DATASET_OPS_AGGREGATIONS.median) {
116
+ return ALL_FIELD_TYPES.real;
117
+ }
118
+ return sourceType || ALL_FIELD_TYPES.real;
119
+ }
120
+ //# sourceMappingURL=aggregations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregations.js","names":["ALL_FIELD_TYPES","aggregate","notNullorUndefined","DATASET_OPS_AGGREGATIONS","mergeGeometries","DATASET_OPS_AGGREGATION_OPTIONS","id","merge","labelId","count","sum","average","maximum","minimum","median","countUnique","NUMERIC_FIELD_TYPES","Set","integer","real","CATEGORICAL_FIELD_TYPES","string","h3","TIME_FIELD_TYPES","timestamp","date","aggregationIdsForFieldType","type","has","geojson","point","aggregationOptionsForField","field","allowed","filter","option","isDatasetOpsAggregationField","length","defaultAggregationForField","defaultAggregationsForFields","fields","excludeNames","arguments","undefined","excluded","aggregations","forEach","name","aggregateValues","values","technique","defined","value","Number","resultFieldType","sourceType"],"sources":["../../../src/dataset-ops/aggregations.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright contributors to the kepler.gl project\n\nimport {ALL_FIELD_TYPES} from '@kepler.gl/constants';\nimport {Field} from '@kepler.gl/types';\nimport {aggregate} from '@kepler.gl/utils';\nimport {notNullorUndefined} from '@kepler.gl/common-utils';\n\nimport {DATASET_OPS_AGGREGATIONS, DatasetOpAggregation} from './types';\nimport {mergeGeometries} from './geometry';\n\nexport const DATASET_OPS_AGGREGATION_OPTIONS: {id: DatasetOpAggregation; labelId: string}[] = [\n {id: DATASET_OPS_AGGREGATIONS.merge, labelId: 'datasetOps.aggregation.merge'},\n {id: DATASET_OPS_AGGREGATIONS.count, labelId: 'datasetOps.aggregation.count'},\n {id: DATASET_OPS_AGGREGATIONS.sum, labelId: 'datasetOps.aggregation.sum'},\n {id: DATASET_OPS_AGGREGATIONS.average, labelId: 'datasetOps.aggregation.average'},\n {id: DATASET_OPS_AGGREGATIONS.maximum, labelId: 'datasetOps.aggregation.maximum'},\n {id: DATASET_OPS_AGGREGATIONS.minimum, labelId: 'datasetOps.aggregation.minimum'},\n {id: DATASET_OPS_AGGREGATIONS.median, labelId: 'datasetOps.aggregation.median'},\n {id: DATASET_OPS_AGGREGATIONS.countUnique, labelId: 'datasetOps.aggregation.countUnique'}\n];\n\nconst NUMERIC_FIELD_TYPES = new Set<string>([ALL_FIELD_TYPES.integer, ALL_FIELD_TYPES.real]);\nconst CATEGORICAL_FIELD_TYPES = new Set<string>([ALL_FIELD_TYPES.string, ALL_FIELD_TYPES.h3]);\nconst TIME_FIELD_TYPES = new Set<string>([ALL_FIELD_TYPES.timestamp, ALL_FIELD_TYPES.date]);\n\nexport function aggregationIdsForFieldType(type?: string): DatasetOpAggregation[] {\n if (type && NUMERIC_FIELD_TYPES.has(type)) {\n return [\n DATASET_OPS_AGGREGATIONS.count,\n DATASET_OPS_AGGREGATIONS.sum,\n DATASET_OPS_AGGREGATIONS.average,\n DATASET_OPS_AGGREGATIONS.maximum,\n DATASET_OPS_AGGREGATIONS.minimum,\n DATASET_OPS_AGGREGATIONS.median,\n DATASET_OPS_AGGREGATIONS.countUnique\n ];\n }\n if (type === ALL_FIELD_TYPES.boolean) {\n return [\n DATASET_OPS_AGGREGATIONS.count,\n DATASET_OPS_AGGREGATIONS.sum,\n DATASET_OPS_AGGREGATIONS.average,\n DATASET_OPS_AGGREGATIONS.countUnique\n ];\n }\n if (type && TIME_FIELD_TYPES.has(type)) {\n return [\n DATASET_OPS_AGGREGATIONS.count,\n DATASET_OPS_AGGREGATIONS.maximum,\n DATASET_OPS_AGGREGATIONS.minimum,\n DATASET_OPS_AGGREGATIONS.countUnique\n ];\n }\n if (type && CATEGORICAL_FIELD_TYPES.has(type)) {\n return [DATASET_OPS_AGGREGATIONS.count, DATASET_OPS_AGGREGATIONS.countUnique];\n }\n if (type === ALL_FIELD_TYPES.geojson || type === ALL_FIELD_TYPES.point) {\n return [\n DATASET_OPS_AGGREGATIONS.merge,\n DATASET_OPS_AGGREGATIONS.count,\n DATASET_OPS_AGGREGATIONS.countUnique\n ];\n }\n return [DATASET_OPS_AGGREGATIONS.count];\n}\n\nexport function aggregationOptionsForField(field: {\n type?: string;\n}): typeof DATASET_OPS_AGGREGATION_OPTIONS {\n const allowed = new Set(aggregationIdsForFieldType(field.type));\n return DATASET_OPS_AGGREGATION_OPTIONS.filter(option => allowed.has(option.id));\n}\n\nexport function isDatasetOpsAggregationField(field: {type?: string}): boolean {\n return aggregationIdsForFieldType(field.type).length > 1;\n}\n\nexport function defaultAggregationForField(field: Field): DatasetOpAggregation {\n const allowed = aggregationIdsForFieldType(field.type);\n if (field.type === ALL_FIELD_TYPES.integer || field.type === ALL_FIELD_TYPES.real) {\n return DATASET_OPS_AGGREGATIONS.average;\n }\n if (field.type === ALL_FIELD_TYPES.string || field.type === ALL_FIELD_TYPES.h3) {\n return DATASET_OPS_AGGREGATIONS.countUnique;\n }\n if (field.type === ALL_FIELD_TYPES.geojson || field.type === ALL_FIELD_TYPES.point) {\n return DATASET_OPS_AGGREGATIONS.merge;\n }\n return allowed[0];\n}\n\nexport function defaultAggregationsForFields(\n fields: Field[],\n excludeNames: string[] = []\n): Record<string, DatasetOpAggregation> {\n const excluded = new Set(excludeNames);\n const aggregations: Record<string, DatasetOpAggregation> = {};\n fields.forEach(field => {\n if (!excluded.has(field.name) && isDatasetOpsAggregationField(field)) {\n aggregations[field.name] = defaultAggregationForField(field);\n }\n });\n return aggregations;\n}\n\nexport function aggregateValues(values: unknown[], technique: DatasetOpAggregation): unknown {\n if (technique === DATASET_OPS_AGGREGATIONS.merge) {\n return mergeGeometries(values);\n }\n const defined = values.filter(notNullorUndefined);\n if (technique === DATASET_OPS_AGGREGATIONS.count) {\n return values.length;\n }\n if (!defined.length) {\n return null;\n }\n if (\n technique === DATASET_OPS_AGGREGATIONS.sum ||\n technique === DATASET_OPS_AGGREGATIONS.average ||\n technique === DATASET_OPS_AGGREGATIONS.median\n ) {\n // D3 arithmetic requires Numbers. Keep raw BigInts for exact extrema/distinct counts\n // and leave the source data unchanged; arithmetic results use Number precision.\n return aggregate(defined, technique, value =>\n typeof value === 'bigint' ? Number(value) : value\n );\n }\n return aggregate(defined, technique);\n}\n\nexport function resultFieldType(technique: DatasetOpAggregation, sourceType?: string): string {\n if (technique === DATASET_OPS_AGGREGATIONS.merge) {\n return ALL_FIELD_TYPES.geojson;\n }\n if (\n technique === DATASET_OPS_AGGREGATIONS.count ||\n technique === DATASET_OPS_AGGREGATIONS.countUnique\n ) {\n return ALL_FIELD_TYPES.integer;\n }\n if (\n technique === DATASET_OPS_AGGREGATIONS.average ||\n technique === DATASET_OPS_AGGREGATIONS.median\n ) {\n return ALL_FIELD_TYPES.real;\n }\n return sourceType || ALL_FIELD_TYPES.real;\n}\n"],"mappings":"AAAA;AACA;;AAEA,SAAQA,eAAe,QAAO,sBAAsB;AAEpD,SAAQC,SAAS,QAAO,kBAAkB;AAC1C,SAAQC,kBAAkB,QAAO,yBAAyB;AAE1D,SAAQC,wBAAwB,QAA6B,SAAS;AACtE,SAAQC,eAAe,QAAO,YAAY;AAE1C,OAAO,IAAMC,+BAA8E,GAAG,CAC5F;EAACC,EAAE,EAAEH,wBAAwB,CAACI,KAAK;EAAEC,OAAO,EAAE;AAA8B,CAAC,EAC7E;EAACF,EAAE,EAAEH,wBAAwB,CAACM,KAAK;EAAED,OAAO,EAAE;AAA8B,CAAC,EAC7E;EAACF,EAAE,EAAEH,wBAAwB,CAACO,GAAG;EAAEF,OAAO,EAAE;AAA4B,CAAC,EACzE;EAACF,EAAE,EAAEH,wBAAwB,CAACQ,OAAO;EAAEH,OAAO,EAAE;AAAgC,CAAC,EACjF;EAACF,EAAE,EAAEH,wBAAwB,CAACS,OAAO;EAAEJ,OAAO,EAAE;AAAgC,CAAC,EACjF;EAACF,EAAE,EAAEH,wBAAwB,CAACU,OAAO;EAAEL,OAAO,EAAE;AAAgC,CAAC,EACjF;EAACF,EAAE,EAAEH,wBAAwB,CAACW,MAAM;EAAEN,OAAO,EAAE;AAA+B,CAAC,EAC/E;EAACF,EAAE,EAAEH,wBAAwB,CAACY,WAAW;EAAEP,OAAO,EAAE;AAAoC,CAAC,CAC1F;AAED,IAAMQ,mBAAmB,GAAG,IAAIC,GAAG,CAAS,CAACjB,eAAe,CAACkB,OAAO,EAAElB,eAAe,CAACmB,IAAI,CAAC,CAAC;AAC5F,IAAMC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