Skip to content

Commit

Permalink
[chore] Add runGpuFilterForPlot to export, ts changes to KeplerTableM…
Browse files Browse the repository at this point in the history
…odel (#2702)

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta authored Oct 21, 2024
1 parent ee69532 commit ef2ac8f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
20 changes: 1 addition & 19 deletions src/utils/src/filter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 7 additions & 3 deletions src/utils/src/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions src/utils/src/types.ts
Original file line number Diff line number Diff line change
@@ -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[];
}

0 comments on commit ef2ac8f

Please sign in to comment.