Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[chore] Add runGpuFilterForPlot to export, ts changes to KeplerTableModel (#2702)

Igor Dykhtaef2ac8f07b2a
diff --git a/src/utils/src/filter-utils.ts b/src/utils/src/filter-utils.ts
index 8ab08627c..61dc372b5 100644
--- a/src/utils/src/filter-utils.ts
+++ b/src/utils/src/filter-utils.ts
@@ -45,6 +45,7 @@ import {generateHashId, set, toArray} from './utils';
import {notNullorUndefined, timeToUnixMilli, unique} from './data-utils';
import {getCentroid} from './h3-utils';
import {updateTimeFilterPlotType, updateRangeFilterPlotType} from './plot';
+import {KeplerTableModel} from './types';
export const durationSecond = 1000;
export const durationMinute = durationSecond * 60;
@@ -153,25 +154,6 @@ export function shouldApplyFilter(filter: Filter, datasetId: string): boolean {
return dataIds.includes(datasetId) && filter.value !== null;
}
-interface KeplerTableModel<K, L> {
- id: string;
- getColumnFieldIdx(columnName: string): number;
- filterTable(filters: Filter[], layers: L[], opt?: FilterDatasetOpt): K;
- getColumnFilterProps(columnName: string): Field['filterProps'] | null | undefined;
- dataContainer: DataContainerInterface;
- filterTableCPU(filters: Filter[], layers: L[]): K;
- gpuFilter: {
- filterRange: number[][];
- filterValueUpdateTriggers: any;
- filterValueAccessor: (
- dc: DataContainerInterface
- ) => (
- getIndex?: (any) => number,
- getData?: (dc_: DataContainerInterface, d: any, fieldIndex: number) => any
- ) => (d: any) => (number | number[])[];
- };
-}
-
/**
* Validates and modifies polygon filter structure
* @param dataset
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index e2ec5e6b8..abadd8752 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -21,7 +21,7 @@ export {createNotification, exportImageError, successNotification} from './notif
export {setStyleSheetBaseHref} from './dom-utils';
export {default as domtoimage} from './dom-to-image';
export {getFrequency, getMode, aggregate} from './aggregation';
-export {getBinThresholds, histogramFromThreshold, histogramFromDomain} from './plot';
+export {getBinThresholds, histogramFromThreshold, histogramFromDomain, runGpuFilterForPlot} from './plot';
// eslint-disable-next-line prettier/prettier
export type {FieldFormatter} from './data-utils';
export * from './data-utils';
diff --git a/src/utils/src/plot.ts b/src/utils/src/plot.ts
index acbc8d993..3ea5e5623 100644
--- a/src/utils/src/plot.ts
+++ b/src/utils/src/plot.ts
@@ -34,6 +34,7 @@ import {capitalizeFirstLetter} from './strings';
import {getDefaultTimeFormat} from './format';
import {rgbToHex} from './color-utils';
import {DataContainerInterface} from '.';
+import {KeplerTableModel} from './types';
// TODO kepler-table module isn't accessible from utils. Add compatible interface to types
type Datasets = any;
@@ -167,10 +168,13 @@ export function getBinThresholds(interval: string, domain: number[]): number[] {
/**
* Run GPU filter on current filter result to generate indexes for ploting chart
* Skip ruuning for the same field
- * @param {KeplerTable} dataset
- * @param {Filter} filter
+ * @param dataset
+ * @param filter
*/
-export function runGpuFilterForPlot(dataset, filter) {
+export function runGpuFilterForPlot<K extends KeplerTableModel<K, L>, L>(
+ dataset: K,
+ filter?: Filter
+): number[] {
const skipIndexes = getSkipIndexes(dataset, filter);
const {
diff --git a/src/utils/src/types.ts b/src/utils/src/types.ts
new file mode 100644
index 000000000..cb2ec828f
--- /dev/null
+++ b/src/utils/src/types.ts
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import {Filter, Field, FilterDatasetOpt} from '@kepler.gl/types';
+
+import {DataContainerInterface} from './data-container-interface';
+
+export interface KeplerTableModel<K, L> {
+ id: string;
+ getColumnFieldIdx(columnName: string): number;
+ filterTable(filters: Filter[], layers: L[], opt?: FilterDatasetOpt): K;
+ getColumnFilterProps(columnName: string): Field['filterProps'] | null | undefined;
+ dataContainer: DataContainerInterface;
+ filterTableCPU(filters: Filter[], layers: L[]): K;
+ gpuFilter: {
+ filterRange: number[][];
+ filterValueUpdateTriggers: any;
+ filterValueAccessor: (
+ dc: DataContainerInterface
+ ) => (
+ getIndex?: (any) => number,
+ getData?: (dc_: DataContainerInterface, d: any, fieldIndex: number) => any
+ ) => (d: any) => (number | number[])[];
+ };
+ filteredIndex: number[];
+}