@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,1031 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
6
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
7
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
+ var _excluded = ["filterProps"],
9
+ _excluded2 = ["filterProps"],
10
+ _excluded3 = ["filterProps"];
11
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
12
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
13
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ // SPDX-License-Identifier: MIT
18
+ // Copyright contributors to the kepler.gl project
19
+
20
+ import Console from 'global/console';
21
+ import { ascending, descending } from 'd3-array';
22
+ import { TRIP_POINT_FIELDS, SORT_ORDER, ALL_FIELD_TYPES, ALTITUDE_FIELDS, SCALE_TYPES } from '@kepler.gl/constants';
23
+ import { getGpuFilterProps, getDatasetFieldIndexForFilter } from './gpu-filter-utils';
24
+ import { columnContainsBigInts } from './dataset-ops/normalize-bigint-columns';
25
+ import { getSortingFunction, timeToUnixMilli, createDataContainer, ArrowDataContainer, DataForm, diffFilters, filterDataByFilterTypes, getFilterFunction, getFilterProps, getFilterRecord, computePolygonFilteredIndexByLayer, mergePolygonLayerIndexes, getNumericFieldDomain, getTimestampFieldDomain, getLinearDomain, getLogDomain, getOrdinalDomain, getQuantileDomain, getJenksDomain } from '@kepler.gl/utils';
26
+ import { generateHashId, notNullorUndefined } from '@kepler.gl/common-utils';
27
+
28
+ // TODO isolate layer type, depends on @kepler.gl/layers
29
+
30
+ // Unique identifier of each field
31
+ var FID_KEY = 'name';
32
+ var ROW_EDIT_NOT_IMPLEMENTED = 'In-place row edits (append, upsert, delete) are not implemented for this table. DuckDB tables omit row edits (no INSERT yet). Use addDataToMap with keepExistingConfig to replace the table.';
33
+ function warnRowEditsUnavailable(method) {
34
+ Console.warn("KeplerTable.".concat(method, ": ").concat(ROW_EDIT_NOT_IMPLEMENTED));
35
+ }
36
+ function readFieldValue(fieldIdx, dc,
37
+ // An object with row index or a materialized row array (for materialized hover info from trip layer)
38
+ d) {
39
+ return Array.isArray(d) ? d[fieldIdx] : dc.valueAt(d.index, fieldIdx);
40
+ }
41
+ export function maybeToDate(isTime, fieldIdx, format, dc, d) {
42
+ var value = readFieldValue(fieldIdx, dc, d);
43
+ return isTime ? timeToUnixMilli(value, format) : value;
44
+ }
45
+ var KeplerTable = /*#__PURE__*/function () {
46
+ function KeplerTable(_ref) {
47
+ var info = _ref.info,
48
+ color = _ref.color,
49
+ metadata = _ref.metadata,
50
+ _ref$supportedFilterT = _ref.supportedFilterTypes,
51
+ supportedFilterTypes = _ref$supportedFilterT === void 0 ? null : _ref$supportedFilterT,
52
+ _ref$disableDataOpera = _ref.disableDataOperation,
53
+ disableDataOperation = _ref$disableDataOpera === void 0 ? false : _ref$disableDataOpera;
54
+ _classCallCheck(this, KeplerTable);
55
+ _defineProperty(this, "id", void 0);
56
+ _defineProperty(this, "type", void 0);
57
+ _defineProperty(this, "label", void 0);
58
+ _defineProperty(this, "color", void 0);
59
+ // fields and data
60
+ _defineProperty(this, "fields", []);
61
+ _defineProperty(this, "dataContainer", void 0);
62
+ /**
63
+ * Bumped in {@link update} so layer `dataUpdateTriggers` notice in-place row
64
+ * snapshots (the dataContainer instance stays the same).
65
+ */
66
+ _defineProperty(this, "dataRevision", 0);
67
+ _defineProperty(this, "allIndexes", []);
68
+ _defineProperty(this, "filteredIndex", []);
69
+ _defineProperty(this, "filteredIdxCPU", void 0);
70
+ _defineProperty(this, "filteredIndexForDomain", []);
71
+ _defineProperty(this, "filteredIndexByLayer", {});
72
+ _defineProperty(this, "fieldPairs", []);
73
+ _defineProperty(this, "gpuFilter", void 0);
74
+ _defineProperty(this, "filterRecord", void 0);
75
+ _defineProperty(this, "filterRecordCPU", void 0);
76
+ _defineProperty(this, "changedFilters", void 0);
77
+ // table-injected metadata
78
+ _defineProperty(this, "sortColumn", void 0);
79
+ _defineProperty(this, "sortOrder", void 0);
80
+ _defineProperty(this, "pinnedColumns", void 0);
81
+ /** Attribute-table columns omitted from data export. */
82
+ _defineProperty(this, "hiddenColumns", void 0);
83
+ _defineProperty(this, "supportedFilterTypes", void 0);
84
+ _defineProperty(this, "disableDataOperation", void 0);
85
+ // table-injected metadata
86
+ _defineProperty(this, "metadata", void 0);
87
+ _defineProperty(this, "getFileProcessor", void 0);
88
+ // TODO - what to do if validation fails? Can kepler handle exceptions?
89
+ // const validatedData = validateInputData(data);
90
+ // if (!validatedData) {
91
+ // return this;
92
+ // }
93
+
94
+ var datasetInfo = _objectSpread({
95
+ id: generateHashId(4),
96
+ label: 'new dataset',
97
+ type: ''
98
+ }, info);
99
+ var defaultMetadata = {
100
+ id: datasetInfo.id,
101
+ // @ts-ignore
102
+ format: datasetInfo.format || '',
103
+ label: datasetInfo.label || ''
104
+ };
105
+ this.id = datasetInfo.id;
106
+ this.type = datasetInfo.type;
107
+ this.label = datasetInfo.label;
108
+ this.color = color;
109
+ this.metadata = _objectSpread(_objectSpread({}, defaultMetadata), metadata);
110
+ this.supportedFilterTypes = supportedFilterTypes;
111
+ this.disableDataOperation = disableDataOperation;
112
+ this.dataContainer = createDataContainer([]);
113
+ this.gpuFilter = getGpuFilterProps([], this.id, [], undefined);
114
+ }
115
+ return _createClass(KeplerTable, [{
116
+ key: "importData",
117
+ value: function () {
118
+ var _importData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
119
+ var data;
120
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
121
+ while (1) switch (_context.prev = _context.next) {
122
+ case 0:
123
+ data = _ref2.data;
124
+ this.updateSchema(data);
125
+ case 2:
126
+ case "end":
127
+ return _context.stop();
128
+ }
129
+ }, _callee, this);
130
+ }));
131
+ function importData(_x) {
132
+ return _importData.apply(this, arguments);
133
+ }
134
+ return importData;
135
+ }()
136
+ /**
137
+ * Replace this table's columns and fields with new data in place.
138
+ *
139
+ * Unlike `update()` (which only refreshes the rows of the existing data
140
+ * container), `updateSchema` rebuilds the schema — it can add, remove, rename
141
+ * or re-type columns. It preserves the table identity (`id`, `label`, `color`,
142
+ * `metadata`, `type`, `supportedFilterTypes`, `disableDataOperation`) set in
143
+ * the constructor.
144
+ *
145
+ * Synchronous on purpose: reducers call it directly to commit a schema change
146
+ * (see `UPDATE_DATASET`), while `importData` remains the async entry point for
147
+ * the task-based loading pipeline.
148
+ *
149
+ * @param data - new column data + field descriptors, e.g. `{cols, fields, arrowTable}`.
150
+ * When replacing columns, pass `cols` (the arrow vectors) so an
151
+ * `ArrowDataContainer` is built; a rows-only payload cannot express a schema change.
152
+ */
153
+ }, {
154
+ key: "updateSchema",
155
+ value: function updateSchema(data) {
156
+ var dataContainerData = data.cols ? data.cols : data.rows;
157
+ var inputDataFormat = data.cols ? DataForm.COLS_ARRAY : DataForm.ROWS_ARRAY;
158
+ var dataContainer = createDataContainer(dataContainerData, {
159
+ fields: data.fields,
160
+ arrowTable: data.arrowTable,
161
+ geoArrowBinaryData: data.geoArrowBinaryData,
162
+ inputDataFormat: inputDataFormat
163
+ });
164
+ var fields = data.fields.map(function (f, i) {
165
+ return _objectSpread(_objectSpread({}, f), {}, {
166
+ fieldIdx: i,
167
+ id: f.name,
168
+ displayName: f.displayName || f.name,
169
+ analyzerType: f.analyzerType || ALL_FIELD_TYPES.string,
170
+ format: f.format || '',
171
+ valueAccessor: getFieldValueAccessor(f, i, dataContainer)
172
+ });
173
+ });
174
+ var allIndexes = dataContainer.getPlainIndex();
175
+ this.dataContainer = dataContainer;
176
+ this.allIndexes = allIndexes;
177
+ this.filteredIndex = allIndexes;
178
+ this.filteredIndexForDomain = allIndexes;
179
+ this.filteredIndexByLayer = {};
180
+ this.fieldPairs = findPointFieldPairs(fields);
181
+ // @ts-expect-error Make sure that fields satisfies F extends Field
182
+ this.fields = fields;
183
+ this.gpuFilter = getGpuFilterProps([], this.id, fields, undefined);
184
+ return this;
185
+ }
186
+
187
+ /**
188
+ * update table with new data
189
+ * @param data - new data e.g. the arrow data with new batches loaded, or a full row snapshot
190
+ */
191
+ }, {
192
+ key: "update",
193
+ value: (function () {
194
+ var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data) {
195
+ var _data$fields,
196
+ _ref3,
197
+ _data$arrowTable,
198
+ _this = this;
199
+ var isRowSnapshot, dataContainerData, timestampFieldsToRebuild;
200
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
201
+ while (1) switch (_context2.prev = _context2.next) {
202
+ case 0:
203
+ // Arrow/DuckDB incremental loads pass `cols` (and empty `rows`). Row snapshots
204
+ // for remote refresh pass `rows` only. Preserve the GPU filter configuration
205
+ // on column updates, but invalidate cached filter results for every snapshot.
206
+ isRowSnapshot = !data.cols && Array.isArray(data.rows);
207
+ if (!((_data$fields = data.fields) !== null && _data$fields !== void 0 && _data$fields.length && !fieldNamesMatch(this.fields, data.fields))) {
208
+ _context2.next = 6;
209
+ break;
210
+ }
211
+ _context2.next = 4;
212
+ return this.importData({
213
+ data: data
214
+ });
215
+ case 4:
216
+ this.dataRevision += 1;
217
+ return _context2.abrupt("return", this);
218
+ case 6:
219
+ // Row snapshots must not pass leftover arrowTable into RowDataContainer.
220
+ dataContainerData = isRowSnapshot ? data.rows : (_ref3 = (_data$arrowTable = data.arrowTable) !== null && _data$arrowTable !== void 0 ? _data$arrowTable : data.cols) !== null && _ref3 !== void 0 ? _ref3 : data.rows;
221
+ if (typeof this.dataContainer.update === 'function') {
222
+ this.dataContainer.update(dataContainerData, {
223
+ geoArrowBinaryData: data.geoArrowBinaryData
224
+ });
225
+ } else if (isRowSnapshot) {
226
+ this.dataContainer = createDataContainer(dataContainerData, {
227
+ fields: data.fields || this.fields,
228
+ inputDataFormat: DataForm.ROWS_ARRAY
229
+ });
230
+ }
231
+
232
+ // Column snapshots can reorder or replace rows without changing the schema,
233
+ // invalidating row-indexed timestamp mappings. Collect only already-cached
234
+ // field names so unused columns stay lazy and refresh scans stay limited.
235
+ timestampFieldsToRebuild = isRowSnapshot ? [] : this.fields.filter(function (f) {
236
+ return f.type === ALL_FIELD_TYPES.timestamp && f.filterProps;
237
+ }).map(function (f) {
238
+ return f.name;
239
+ });
240
+ if (isRowSnapshot) {
241
+ this.fields = this.fields.map(function (f, i) {
242
+ var _filterProps = f.filterProps,
243
+ rest = _objectWithoutProperties(f, _excluded);
244
+ return _objectSpread(_objectSpread({}, rest), {}, {
245
+ valueAccessor: getFieldValueAccessor(f, i, _this.dataContainer)
246
+ });
247
+ });
248
+ this.gpuFilter = getGpuFilterProps([], this.id, this.fields, undefined);
249
+ } else if (timestampFieldsToRebuild.length) {
250
+ // getColumnFilterProps returns existing filterProps without recomputing.
251
+ // Remove the stale cache so it reads the new snapshot, while preserving
252
+ // the GPU filter configuration and channels across column updates.
253
+ this.fields = this.fields.map(function (f) {
254
+ if (f.type !== ALL_FIELD_TYPES.timestamp || !f.filterProps) {
255
+ return f;
256
+ }
257
+ var _filterProps = f.filterProps,
258
+ rest = _objectWithoutProperties(f, _excluded2);
259
+ return rest;
260
+ });
261
+ }
262
+ this.allIndexes = this.dataContainer.getPlainIndex();
263
+ this.filteredIndex = this.allIndexes;
264
+ this.filteredIndexForDomain = this.allIndexes;
265
+ this.filteredIndexByLayer = {};
266
+ this.filteredIdxCPU = undefined;
267
+ this.filterRecord = undefined;
268
+ this.filterRecordCPU = undefined;
269
+ this.changedFilters = undefined;
270
+ this.dataRevision += 1;
271
+
272
+ // Rebuild after row indexes and filter results are reset: CPU/GPU consumers
273
+ // read mappedValue directly. Caching the new mapping here avoids rescanning
274
+ // timestamps on later filter interactions.
275
+ timestampFieldsToRebuild.forEach(function (name) {
276
+ return _this.getColumnFilterProps(name);
277
+ });
278
+ return _context2.abrupt("return", this);
279
+ case 21:
280
+ case "end":
281
+ return _context2.stop();
282
+ }
283
+ }, _callee2, this);
284
+ }));
285
+ function update(_x2) {
286
+ return _update.apply(this, arguments);
287
+ }
288
+ return update;
289
+ }()
290
+ /**
291
+ * Append column-ordered rows in place. Accessors stay bound: the container
292
+ * instance is not replaced. No-op when the container has no `append`.
293
+ * @returns false when the payload is rejected and the table is unchanged.
294
+ */
295
+ )
296
+ }, {
297
+ key: "appendRows",
298
+ value: function appendRows(rows) {
299
+ if (typeof this.dataContainer.append !== 'function') {
300
+ warnRowEditsUnavailable('appendRows');
301
+ return false;
302
+ }
303
+ if (!rows.length) {
304
+ return false;
305
+ }
306
+ var columnCount = this.fields.length;
307
+ if (!columnCount || rows.some(function (row) {
308
+ return !Array.isArray(row) || row.length !== columnCount;
309
+ })) {
310
+ return false;
311
+ }
312
+ var start = this.dataContainer.numRows();
313
+ if (!this.dataContainer.append(rows)) {
314
+ return false;
315
+ }
316
+ var nextIndexes = this.allIndexes.length === start ? this.allIndexes.concat(rows.map(function (_, i) {
317
+ return start + i;
318
+ })) : this.dataContainer.getPlainIndex();
319
+ this.afterRowMutation(nextIndexes);
320
+ return true;
321
+ }
322
+
323
+ /**
324
+ * Replace rows that share `keyField` and append the rest. Last incoming row
325
+ * wins for a repeated key. No-op when the container has no `append`/`replace`.
326
+ * @returns false when the payload is rejected and the table is unchanged.
327
+ */
328
+ }, {
329
+ key: "upsertRows",
330
+ value: function upsertRows(rows, keyField) {
331
+ if (typeof this.dataContainer.append !== 'function' || typeof this.dataContainer.replace !== 'function') {
332
+ warnRowEditsUnavailable('upsertRows');
333
+ return false;
334
+ }
335
+ var keyIdx = this.fields.findIndex(function (field) {
336
+ return field.name === keyField;
337
+ });
338
+ if (keyIdx < 0 || !rows.length) {
339
+ return false;
340
+ }
341
+ var columnCount = this.fields.length;
342
+ if (rows.some(function (row) {
343
+ return !Array.isArray(row) || row.length !== columnCount;
344
+ })) {
345
+ return false;
346
+ }
347
+
348
+ // Match Arrow keys after encoding so accepted representations such as an
349
+ // Int64 decimal string or a Date compare equal to the stored column value.
350
+ var keys = this.dataContainer instanceof ArrowDataContainer ? this.dataContainer.getRowEditKeys(rows, keyIdx) : rows.map(function (row) {
351
+ return row[keyIdx];
352
+ });
353
+ if (!keys) {
354
+ return false;
355
+ }
356
+ var start = this.dataContainer.numRows();
357
+ var keyToIndex = new Map();
358
+ for (var i = 0; i < start; i++) {
359
+ var _key = this.dataContainer.valueAt(i, keyIdx);
360
+ if (!keyToIndex.has(_key)) {
361
+ keyToIndex.set(_key, i);
362
+ }
363
+ }
364
+ var lastByKey = new Map();
365
+ rows.forEach(function (row, index) {
366
+ return lastByKey.set(keys[index], row);
367
+ });
368
+ var replacements = new Map();
369
+ var toAppend = [];
370
+ var _iterator = _createForOfIteratorHelper(lastByKey),
371
+ _step;
372
+ try {
373
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
374
+ var _step$value = _slicedToArray(_step.value, 2),
375
+ _key2 = _step$value[0],
376
+ _row = _step$value[1];
377
+ var existing = keyToIndex.get(_key2);
378
+ if (existing !== undefined) {
379
+ replacements.set(existing, _row);
380
+ } else {
381
+ toAppend.push(_row);
382
+ }
383
+ }
384
+ } catch (err) {
385
+ _iterator.e(err);
386
+ } finally {
387
+ _iterator.f();
388
+ }
389
+ if (this.dataContainer instanceof ArrowDataContainer) {
390
+ if (!this.dataContainer.replaceRows(replacements, toAppend)) {
391
+ return false;
392
+ }
393
+ } else {
394
+ // Append can reject or throw. Do it before overwriting existing rows so a
395
+ // failed append leaves those rows and their cached state untouched.
396
+ if (toAppend.length && !this.dataContainer.append(toAppend)) {
397
+ return false;
398
+ }
399
+ var _iterator2 = _createForOfIteratorHelper(replacements),
400
+ _step2;
401
+ try {
402
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
403
+ var _step2$value = _slicedToArray(_step2.value, 2),
404
+ index = _step2$value[0],
405
+ row = _step2$value[1];
406
+ this.dataContainer.replace(index, row);
407
+ }
408
+ } catch (err) {
409
+ _iterator2.e(err);
410
+ } finally {
411
+ _iterator2.f();
412
+ }
413
+ }
414
+ var nextIndexes = toAppend.length && this.allIndexes.length === start ? this.allIndexes.concat(toAppend.map(function (_, i) {
415
+ return start + i;
416
+ })) : toAppend.length ? this.dataContainer.getPlainIndex() : this.allIndexes;
417
+ this.afterRowMutation(nextIndexes);
418
+ return true;
419
+ }
420
+
421
+ /**
422
+ * Remove rows by index in place. No-op when the container has no `remove`.
423
+ * @returns false when any index is invalid and the table is unchanged.
424
+ */
425
+ }, {
426
+ key: "removeRows",
427
+ value: function removeRows(indexes) {
428
+ if (typeof this.dataContainer.remove !== 'function') {
429
+ warnRowEditsUnavailable('removeRows');
430
+ return false;
431
+ }
432
+ if (!indexes.length) {
433
+ return false;
434
+ }
435
+ if (!this.dataContainer.remove(indexes)) {
436
+ return false;
437
+ }
438
+ this.afterRowMutation(this.dataContainer.getPlainIndex());
439
+ return true;
440
+ }
441
+
442
+ /**
443
+ * Indexes of rows whose `fieldName` value is in `values` (first-column-wins
444
+ * equality via Set). Empty when the field is missing.
445
+ */
446
+ }, {
447
+ key: "findRowIndexesByFieldValues",
448
+ value: function findRowIndexesByFieldValues(fieldName, values) {
449
+ var fieldIdx = this.fields.findIndex(function (field) {
450
+ return field.name === fieldName;
451
+ });
452
+ if (fieldIdx < 0 || !values.length) {
453
+ return [];
454
+ }
455
+ var match = new Set(values);
456
+ var indexes = [];
457
+ var numRows = this.dataContainer.numRows();
458
+ for (var i = 0; i < numRows; i++) {
459
+ if (match.has(this.dataContainer.valueAt(i, fieldIdx))) {
460
+ indexes.push(i);
461
+ }
462
+ }
463
+ return indexes;
464
+ }
465
+ }, {
466
+ key: "afterRowMutation",
467
+ value: function afterRowMutation(allIndexes) {
468
+ var _this2 = this;
469
+ var fieldsToRebuild = this.fields.filter(function (f) {
470
+ return f.filterProps;
471
+ }).map(function (f) {
472
+ return f.name;
473
+ });
474
+
475
+ // Drop cached per-row props (mappedValue is indexed by row). Same as a
476
+ // snapshot update(); getColumnFilterProps rebuilds after indexes are current.
477
+ this.fields = this.fields.map(function (f) {
478
+ var _filterProps = f.filterProps,
479
+ rest = _objectWithoutProperties(f, _excluded3);
480
+ return rest;
481
+ });
482
+ this.allIndexes = allIndexes;
483
+ this.filteredIndex = allIndexes;
484
+ this.filteredIndexForDomain = allIndexes;
485
+ this.filteredIndexByLayer = {};
486
+ this.filteredIdxCPU = undefined;
487
+ this.filterRecord = undefined;
488
+ this.filterRecordCPU = undefined;
489
+ this.changedFilters = undefined;
490
+ this.sortColumn = undefined;
491
+ this.sortOrder = null;
492
+ this.dataRevision += 1;
493
+ fieldsToRebuild.forEach(function (name) {
494
+ return _this2.getColumnFilterProps(name);
495
+ });
496
+ }
497
+ }, {
498
+ key: "length",
499
+ get: function get() {
500
+ return this.dataContainer.numRows();
501
+ }
502
+
503
+ /**
504
+ * Get field
505
+ * @param columnName
506
+ */
507
+ }, {
508
+ key: "getColumnField",
509
+ value: function getColumnField(columnName) {
510
+ var field = this.fields.find(function (fd) {
511
+ return fd[FID_KEY] === columnName;
512
+ });
513
+ this._assetField(columnName, field);
514
+ return field;
515
+ }
516
+
517
+ /**
518
+ * Get fieldIdx
519
+ * @param columnName
520
+ */
521
+ }, {
522
+ key: "getColumnFieldIdx",
523
+ value: function getColumnFieldIdx(columnName) {
524
+ var fieldIdx = this.fields.findIndex(function (fd) {
525
+ return fd[FID_KEY] === columnName;
526
+ });
527
+ this._assetField(columnName, Boolean(fieldIdx > -1));
528
+ return fieldIdx;
529
+ }
530
+
531
+ /**
532
+ * Get displayFormat
533
+ * @param columnName
534
+ */
535
+ }, {
536
+ key: "getColumnDisplayFormat",
537
+ value: function getColumnDisplayFormat(columnName) {
538
+ var field = this.fields.find(function (fd) {
539
+ return fd[FID_KEY] === columnName;
540
+ });
541
+ this._assetField(columnName, field);
542
+ return field === null || field === void 0 ? void 0 : field.displayFormat;
543
+ }
544
+
545
+ /**
546
+ * Get the value of a cell
547
+ */
548
+ }, {
549
+ key: "getValue",
550
+ value: function getValue(columnName, rowIdx) {
551
+ var field = this.getColumnField(columnName);
552
+ return field ? field.valueAccessor({
553
+ index: rowIdx
554
+ }) : null;
555
+ }
556
+
557
+ /**
558
+ * Updates existing field with a new object
559
+ * @param fieldIdx
560
+ * @param newField
561
+ */
562
+ }, {
563
+ key: "updateColumnField",
564
+ value: function updateColumnField(fieldIdx, newField) {
565
+ this.fields = Object.assign(_toConsumableArray(this.fields), _defineProperty({}, fieldIdx, newField));
566
+ }
567
+
568
+ /**
569
+ * Update dataset color by custom color
570
+ * @param newColor
571
+ */
572
+ }, {
573
+ key: "updateTableColor",
574
+ value: function updateTableColor(newColor) {
575
+ this.color = newColor;
576
+ }
577
+
578
+ /**
579
+ * Save filterProps to field and retrieve it
580
+ * @param columnName
581
+ */
582
+ }, {
583
+ key: "getColumnFilterProps",
584
+ value: function getColumnFilterProps(columnName) {
585
+ var fieldIdx = this.getColumnFieldIdx(columnName);
586
+ if (fieldIdx < 0) {
587
+ return null;
588
+ }
589
+ var field = this.fields[fieldIdx];
590
+ if (Object.prototype.hasOwnProperty.call(field, 'filterProps')) {
591
+ return field.filterProps;
592
+ }
593
+ var fieldDomain = this.getColumnFilterDomain(field);
594
+ if (!fieldDomain) {
595
+ return null;
596
+ }
597
+ var filterProps = getFilterProps(field, fieldDomain);
598
+ var newField = _objectSpread(_objectSpread({}, field), {}, {
599
+ filterProps: filterProps
600
+ });
601
+ this.updateColumnField(fieldIdx, newField);
602
+ return filterProps;
603
+ }
604
+
605
+ /**
606
+ * Apply filters to dataset, return the filtered dataset with updated `gpuFilter`, `filterRecord`, `filteredIndex`, `filteredIndexForDomain`
607
+ * @param filters
608
+ * @param layers
609
+ * @param opt
610
+ */
611
+ }, {
612
+ key: "filterTable",
613
+ value: function filterTable(filters, layers, opt) {
614
+ var _this3 = this;
615
+ var dataContainer = this.dataContainer,
616
+ dataId = this.id,
617
+ oldFilterRecord = this.filterRecord,
618
+ fields = this.fields;
619
+
620
+ // if there is no filters
621
+ var filterRecord = getFilterRecord(dataId, filters, opt || {});
622
+ this.filterRecord = filterRecord;
623
+ this.gpuFilter = getGpuFilterProps(filters, dataId, fields, this.gpuFilter);
624
+ this.changedFilters = diffFilters(filterRecord, oldFilterRecord);
625
+ if (!filters.length) {
626
+ this.filteredIndex = this.allIndexes;
627
+ this.filteredIndexForDomain = this.allIndexes;
628
+ this.filteredIndexByLayer = {};
629
+ return this;
630
+ }
631
+
632
+ // generate 2 sets of filter result
633
+ // filteredIndex used to calculate layer data
634
+ // filteredIndexForDomain used to calculate layer Domain
635
+ var shouldCalDomain = Boolean(this.changedFilters.dynamicDomain);
636
+ var shouldCalIndex = Boolean(this.changedFilters.cpu);
637
+ var filterResult = {};
638
+ if (shouldCalDomain || shouldCalIndex) {
639
+ var dynamicDomainFilters = shouldCalDomain ? filterRecord.dynamicDomain : null;
640
+ var cpuFilters = shouldCalIndex ? filterRecord.cpu : null;
641
+ var filterFuncs = filters.reduce(function (acc, filter) {
642
+ var fieldIndex = getDatasetFieldIndexForFilter(_this3.id, filter);
643
+ var field = fieldIndex !== -1 ? fields[fieldIndex] : null;
644
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, filter.id, getFilterFunction(field, _this3.id, filter, layers, dataContainer)));
645
+ }, {});
646
+ filterResult = filterDataByFilterTypes({
647
+ dynamicDomainFilters: dynamicDomainFilters,
648
+ cpuFilters: cpuFilters,
649
+ filterFuncs: filterFuncs
650
+ }, dataContainer);
651
+ }
652
+ this.filteredIndex = filterResult.filteredIndex || this.filteredIndex;
653
+ this.filteredIndexForDomain = filterResult.filteredIndexForDomain || this.filteredIndexForDomain;
654
+
655
+ // Compute per-layer filtered indices for polygon filters
656
+ this.filteredIndexByLayer = computePolygonFilteredIndexByLayer(filters, layers, dataId, dataContainer, this.filteredIndex);
657
+ return this;
658
+ }
659
+
660
+ /**
661
+ * Apply filters to a dataset all on CPU, assign to `filteredIdxCPU`, `filterRecordCPU`
662
+ * @param filters
663
+ * @param layers
664
+ */
665
+ }, {
666
+ key: "filterTableCPU",
667
+ value: function filterTableCPU(filters, layers) {
668
+ var opt = {
669
+ cpuOnly: true,
670
+ ignoreDomain: true
671
+ };
672
+
673
+ // no filter
674
+ if (!filters.length) {
675
+ this.filteredIdxCPU = this.allIndexes;
676
+ this.filterRecordCPU = getFilterRecord(this.id, filters, opt);
677
+ return this;
678
+ }
679
+ var baseIndex;
680
+ var indexByLayer;
681
+
682
+ // no gpu filter
683
+ if (!filters.find(function (f) {
684
+ return f.gpu;
685
+ })) {
686
+ baseIndex = this.filteredIndex;
687
+ indexByLayer = this.filteredIndexByLayer;
688
+ this.filterRecordCPU = getFilterRecord(this.id, filters, opt);
689
+ } else {
690
+ // make a copy for cpu filtering
691
+ var copied = copyTable(this);
692
+ copied.filterRecord = this.filterRecordCPU;
693
+ copied.filteredIndex = this.filteredIdxCPU || [];
694
+ var filtered = copied.filterTable(filters, layers, opt);
695
+ baseIndex = filtered.filteredIndex;
696
+ indexByLayer = filtered.filteredIndexByLayer;
697
+ this.filterRecordCPU = filtered.filterRecord;
698
+ }
699
+
700
+ // Polygon filters are applied per-layer (not in filteredIndex). For export, keep rows
701
+ // visible on any polygon-targeted layer.
702
+ this.filteredIdxCPU = mergePolygonLayerIndexes(baseIndex, indexByLayer);
703
+ return this;
704
+ }
705
+
706
+ /**
707
+ * Calculate field domain based on field type and data
708
+ * for Filter
709
+ */
710
+ }, {
711
+ key: "getColumnFilterDomain",
712
+ value: function getColumnFilterDomain(field) {
713
+ var dataContainer = this.dataContainer;
714
+ var valueAccessor = field.valueAccessor;
715
+ var domain;
716
+ switch (field.type) {
717
+ case ALL_FIELD_TYPES.real:
718
+ case ALL_FIELD_TYPES.integer:
719
+ // calculate domain and step
720
+ return getNumericFieldDomain(dataContainer, valueAccessor);
721
+ case ALL_FIELD_TYPES["boolean"]:
722
+ return {
723
+ domain: [true, false]
724
+ };
725
+ case ALL_FIELD_TYPES.string:
726
+ case ALL_FIELD_TYPES.h3:
727
+ case ALL_FIELD_TYPES.date:
728
+ domain = getOrdinalDomain(dataContainer, valueAccessor);
729
+ return {
730
+ domain: domain
731
+ };
732
+ case ALL_FIELD_TYPES.timestamp:
733
+ return getTimestampFieldDomain(dataContainer, valueAccessor);
734
+ default:
735
+ return {
736
+ domain: getOrdinalDomain(dataContainer, valueAccessor)
737
+ };
738
+ }
739
+ }
740
+
741
+ /**
742
+ * Get the domain of this column based on scale type
743
+ */
744
+ }, {
745
+ key: "getColumnLayerDomain",
746
+ value: function getColumnLayerDomain(field, scaleType, range) {
747
+ var dataContainer = this.dataContainer,
748
+ filteredIndexForDomain = this.filteredIndexForDomain;
749
+ if (!SCALE_TYPES[scaleType]) {
750
+ Console.error("scale type ".concat(scaleType, " not supported"));
751
+ return null;
752
+ }
753
+ var valueAccessor = field.valueAccessor;
754
+ var indexValueAccessor = function indexValueAccessor(i) {
755
+ return valueAccessor({
756
+ index: i
757
+ });
758
+ };
759
+ var sortFunction = getSortingFunction(field.type);
760
+ switch (scaleType) {
761
+ case SCALE_TYPES.ordinal:
762
+ case SCALE_TYPES.customOrdinal:
763
+ case SCALE_TYPES.point:
764
+ // do not recalculate ordinal domain based on filtered data
765
+ // don't need to update ordinal domain every time
766
+ return getOrdinalDomain(dataContainer, valueAccessor);
767
+ case SCALE_TYPES.quantile:
768
+ return getQuantileDomain(filteredIndexForDomain, indexValueAccessor, sortFunction);
769
+ case SCALE_TYPES.jenks:
770
+ if (!(range !== null && range !== void 0 && range.colors)) {
771
+ Console.error('the range is either missing or it does not have colors available for Jenks scale domain calculation');
772
+ return null;
773
+ }
774
+ return getJenksDomain(filteredIndexForDomain, indexValueAccessor, range.colors.length);
775
+ case SCALE_TYPES.log:
776
+ return getLogDomain(filteredIndexForDomain, indexValueAccessor);
777
+ case SCALE_TYPES.quantize:
778
+ case SCALE_TYPES.linear:
779
+ case SCALE_TYPES.sqrt:
780
+ case SCALE_TYPES.custom:
781
+ default:
782
+ return getLinearDomain(filteredIndexForDomain, indexValueAccessor);
783
+ }
784
+ }
785
+
786
+ /**
787
+ * Get a sample of rows to calculate layer boundaries
788
+ */
789
+ // getSampleData(rows)
790
+
791
+ /**
792
+ * Parse cell value based on column type and return a string representation
793
+ * Value the field value, type the field type
794
+ */
795
+ // parseFieldValue(value, type)
796
+
797
+ // sortDatasetByColumn()
798
+
799
+ /**
800
+ * Assert whether field exist
801
+ * @param fieldName
802
+ * @param condition
803
+ */
804
+ }, {
805
+ key: "_assetField",
806
+ value: function _assetField(fieldName, condition) {
807
+ if (!condition) {
808
+ Console.error("".concat(fieldName, " doesnt exist in dataset ").concat(this.id));
809
+ }
810
+ }
811
+ }]);
812
+ }();
813
+ // HELPER FUNCTIONS (MAINLY EXPORTED FOR TEST...)
814
+ // have to double excape
815
+ var specialCharacterSet = "[#_&@\\.\\-\\ ]";
816
+ function foundMatchingFields(re, suffixPair, allNames, fieldName) {
817
+ var partnerIdx = allNames.findIndex(function (d) {
818
+ return d === fieldName.replace(re, function (match) {
819
+ return match.replace(suffixPair[0], suffixPair[1]);
820
+ });
821
+ });
822
+ var altIdx = -1;
823
+ if (partnerIdx > -1) {
824
+ // if found partner, go on and look for altitude
825
+ ALTITUDE_FIELDS.some(function (alt) {
826
+ altIdx = allNames.findIndex(function (d) {
827
+ return d === fieldName.replace(re, function (match) {
828
+ return match.replace(suffixPair[0], alt);
829
+ });
830
+ });
831
+ return altIdx > -1;
832
+ });
833
+ }
834
+ return {
835
+ partnerIdx: partnerIdx,
836
+ altIdx: altIdx
837
+ };
838
+ }
839
+ /**
840
+ * Find point fields pairs from fields
841
+ *
842
+ * @param fields
843
+ * @returns found point fields
844
+ */
845
+ export function findPointFieldPairs(fields) {
846
+ var allNames = fields.map(function (f) {
847
+ return f.name.toLowerCase();
848
+ });
849
+
850
+ // get list of all fields with matching suffixes
851
+ var acc = [];
852
+ return allNames.reduce(function (carry, fieldName, idx) {
853
+ // This search for pairs will early exit if found.
854
+ var _iterator3 = _createForOfIteratorHelper(TRIP_POINT_FIELDS),
855
+ _step3;
856
+ try {
857
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
858
+ var suffixPair = _step3.value;
859
+ // match first suffix
860
+ // (^|[#_&@\.\-\ ])lat([#_&@\.\-\ ]|$)
861
+ var re = new RegExp("(^|".concat(specialCharacterSet, ")").concat(suffixPair[0], "(").concat(specialCharacterSet, "|$)"));
862
+ if (re.test(fieldName)) {
863
+ var _foundMatchingFields = foundMatchingFields(re, suffixPair, allNames, fieldName),
864
+ partnerIdx = _foundMatchingFields.partnerIdx,
865
+ altIdx = _foundMatchingFields.altIdx;
866
+ if (partnerIdx > -1) {
867
+ var trimName = fieldName.replace(re, '').trim();
868
+ carry.push({
869
+ defaultName: trimName || 'point',
870
+ pair: _objectSpread({
871
+ lat: {
872
+ fieldIdx: idx,
873
+ value: fields[idx].name
874
+ },
875
+ lng: {
876
+ fieldIdx: partnerIdx,
877
+ value: fields[partnerIdx].name
878
+ }
879
+ }, altIdx > -1 ? {
880
+ altitude: {
881
+ fieldIdx: altIdx,
882
+ value: fields[altIdx].name
883
+ }
884
+ } : {}),
885
+ suffix: suffixPair
886
+ });
887
+ return carry;
888
+ }
889
+ }
890
+ }
891
+ } catch (err) {
892
+ _iterator3.e(err);
893
+ } finally {
894
+ _iterator3.f();
895
+ }
896
+ return carry;
897
+ }, acc);
898
+ }
899
+
900
+ /**
901
+ *
902
+ * @param dataset
903
+ * @param column
904
+ * @param mode
905
+ * @type
906
+ */
907
+ export function sortDatasetByColumn(dataset, column, mode) {
908
+ var allIndexes = dataset.allIndexes,
909
+ fields = dataset.fields,
910
+ dataContainer = dataset.dataContainer;
911
+ var fieldIndex = fields.findIndex(function (f) {
912
+ return f.name === column;
913
+ });
914
+ if (fieldIndex < 0) {
915
+ return dataset;
916
+ }
917
+ var sortBy = SORT_ORDER[mode || ''] || SORT_ORDER.ASCENDING;
918
+ if (sortBy === SORT_ORDER.UNSORT) {
919
+ dataset.sortColumn = {};
920
+ dataset.sortOrder = null;
921
+ return dataset;
922
+ }
923
+ var sortFunction = sortBy === SORT_ORDER.ASCENDING ? ascending : descending;
924
+ var sortOrder = allIndexes.slice().sort(function (a, b) {
925
+ var value1 = dataContainer.valueAt(a, fieldIndex);
926
+ var value2 = dataContainer.valueAt(b, fieldIndex);
927
+ if (!notNullorUndefined(value1) && notNullorUndefined(value2)) {
928
+ return 1;
929
+ } else if (notNullorUndefined(value1) && !notNullorUndefined(value2)) {
930
+ return -1;
931
+ }
932
+ return sortFunction(value1, value2);
933
+ });
934
+ dataset.sortColumn = _defineProperty({}, column, sortBy);
935
+ dataset.sortOrder = sortOrder;
936
+ return dataset;
937
+ }
938
+ export function pinTableColumns(dataset, column) {
939
+ var field = dataset.getColumnField(column);
940
+ if (!field) {
941
+ return dataset;
942
+ }
943
+ var pinnedColumns;
944
+ if (Array.isArray(dataset.pinnedColumns) && dataset.pinnedColumns.includes(field.name)) {
945
+ // unpin it
946
+ pinnedColumns = dataset.pinnedColumns.filter(function (co) {
947
+ return co !== field.name;
948
+ });
949
+ } else {
950
+ pinnedColumns = (dataset.pinnedColumns || []).concat(field.name);
951
+ }
952
+
953
+ // @ts-ignore
954
+ return copyTableAndUpdate(dataset, {
955
+ pinnedColumns: pinnedColumns
956
+ });
957
+ }
958
+ export function toggleHiddenTableColumn(dataset, column) {
959
+ var field = dataset.fields.find(function (item) {
960
+ return item.name === column;
961
+ });
962
+ if (!field) {
963
+ return dataset;
964
+ }
965
+ var hidden = dataset.hiddenColumns || [];
966
+ var hiddenColumns = hidden.includes(field.name) ? hidden.filter(function (name) {
967
+ return name !== field.name;
968
+ }) : hidden.concat(field.name);
969
+ return copyTableAndUpdate(dataset, {
970
+ hiddenColumns: hiddenColumns
971
+ });
972
+ }
973
+ export function showAllTableColumns(dataset) {
974
+ var _dataset$hiddenColumn;
975
+ if (!((_dataset$hiddenColumn = dataset.hiddenColumns) !== null && _dataset$hiddenColumn !== void 0 && _dataset$hiddenColumn.length)) {
976
+ return dataset;
977
+ }
978
+ return copyTableAndUpdate(dataset, {
979
+ hiddenColumns: []
980
+ });
981
+ }
982
+ export function copyTable(original) {
983
+ return Object.assign(Object.create(Object.getPrototypeOf(original)), original);
984
+ }
985
+
986
+ /**
987
+ * @type
988
+ * @returns
989
+ */
990
+ export function copyTableAndUpdate(original) {
991
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
992
+ return Object.entries(options).reduce(function (acc, entry) {
993
+ acc[entry[0]] = entry[1];
994
+ return acc;
995
+ }, copyTable(original));
996
+ }
997
+ function fieldNamesMatch(current, incoming) {
998
+ if (current.length !== incoming.length) {
999
+ return false;
1000
+ }
1001
+ return current.every(function (field, i) {
1002
+ return field.name === incoming[i].name;
1003
+ });
1004
+ }
1005
+
1006
+ /**
1007
+ * Arrow Int64/Uint64 columns yield JS BigInt. Detect from the column type once
1008
+ * at bind time so other columns keep the existing accessor with no extra checks.
1009
+ */
1010
+ function isInt64ArrowColumn(dc, fieldIdx) {
1011
+ var _dc$getColumn;
1012
+ var type = (_dc$getColumn = dc.getColumn) === null || _dc$getColumn === void 0 || (_dc$getColumn = _dc$getColumn.call(dc, fieldIdx)) === null || _dc$getColumn === void 0 ? void 0 : _dc$getColumn.type;
1013
+ return (type === null || type === void 0 ? void 0 : type.bitWidth) === 64 && typeof type.isSigned === 'boolean';
1014
+ }
1015
+ export function getFieldValueAccessor(f, i, dc) {
1016
+ if (f.type === ALL_FIELD_TYPES.timestamp) {
1017
+ var format = f.format || '';
1018
+ return function (d) {
1019
+ return timeToUnixMilli(readFieldValue(i, dc, d), format);
1020
+ };
1021
+ }
1022
+ if (columnContainsBigInts(f) || isInt64ArrowColumn(dc, i)) {
1023
+ return function (d) {
1024
+ var value = readFieldValue(i, dc, d);
1025
+ return value == null ? value : Number(value);
1026
+ };
1027
+ }
1028
+ return readFieldValue.bind(null, i, dc);
1029
+ }
1030
+ export default KeplerTable;
1031
+ //# sourceMappingURL=kepler-table.js.map