Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] fix gpu filter update trigger attribute update in every render #2707

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/table/src/gpu-filter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ const defaultGetData = (dc: DataContainerInterface, d: any, fieldIndex: number)
return dc.valueAt(d.index, fieldIndex);
};

/**
* @param channels
* @param dataId
* @param fields
* @return {Function} getFilterValue
*/
const getFilterValueAccessor =
(channels: (Filter | undefined)[], dataId: string, fields: any[]) =>
(dc: DataContainerInterface) =>
Expand Down Expand Up @@ -198,12 +192,21 @@ const getFilterValueAccessor =
return channelValues;
};

function isFilterTriggerEqual(a, b) {
return a === b || (a?.name === b?.name && a?.domain0 === b?.domain0);
}

/**
* Get filter properties for gpu filtering
*/
export function getGpuFilterProps(filters: Filter[], dataId: string, fields: Field[]): GpuFilter {
export function getGpuFilterProps(
filters: Filter[],
dataId: string,
fields: Field[],
oldGpuFilter?: GpuFilter
): GpuFilter {
const filterRange = getEmptyFilterRange();
const triggers = {};
const triggers: GpuFilter['filterValueUpdateTriggers'] = {};

// array of filter for each channel, undefined, if no filter is assigned to that channel
const channels: (Filter | undefined)[] = [];
Expand All @@ -219,14 +222,18 @@ export function getGpuFilterProps(filters: Filter[], dataId: string, fields: Fie

filterRange[i][0] = filter ? filter.value[0] - filter.domain?.[0] : 0;
filterRange[i][1] = filter ? filter.value[1] - filter.domain?.[0] : 0;
const oldFilterTrigger = oldGpuFilter?.filterValueUpdateTriggers?.[`gpuFilter_${i}`] || null;

triggers[`gpuFilter_${i}`] = filter ? filter.name[filter.dataId.indexOf(dataId)] : null;
triggers[`gpuFilter_${i}`] = filter
const trigger = filter
? {
name: filter.name[filter.dataId.indexOf(dataId)],
domain0: filter.domain?.[0]
}
: null;
// don't create a new object, cause deck.gl use shallow compare
triggers[`gpuFilter_${i}`] = isFilterTriggerEqual(trigger, oldFilterTrigger)
? oldFilterTrigger
: trigger;
channels.push(filter);
}

Expand Down
8 changes: 5 additions & 3 deletions src/table/src/kepler-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ import {

export type GpuFilter = {
filterRange: number[][];
filterValueUpdateTriggers: any;
filterValueUpdateTriggers: {
[id: string]: {name: string; domain0: number} | null;
};
filterValueAccessor: (
dc: DataContainerInterface
) => (
Expand Down Expand Up @@ -215,7 +217,7 @@ class KeplerTable {
this.filteredIndexForDomain = allIndexes;
this.fieldPairs = findPointFieldPairs(fields);
this.fields = fields;
this.gpuFilter = getGpuFilterProps([], dataId, fields);
this.gpuFilter = getGpuFilterProps([], dataId, fields, undefined);
this.supportedFilterTypes = supportedFilterTypes;
this.disableDataOperation = disableDataOperation;
}
Expand Down Expand Up @@ -334,7 +336,7 @@ class KeplerTable {
const filterRecord = getFilterRecord(dataId, filters, opt || {});

this.filterRecord = filterRecord;
this.gpuFilter = getGpuFilterProps(filters, dataId, fields);
this.gpuFilter = getGpuFilterProps(filters, dataId, fields, this.gpuFilter);

this.changedFilters = diffFilters(filterRecord, oldFilterRecord);

Expand Down
7 changes: 6 additions & 1 deletion test/helpers/layer-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ export function testRenderLayerCases(t, LayerClass, testCases) {
mapState: INITIAL_MAP_STATE,
gpuFilter:
tc.datasets[layer.config.dataId].gpuFilter ||
getGpuFilterProps([], layer.config.dataId, tc.datasets[layer.config.dataId].fields),
getGpuFilterProps(
[],
layer.config.dataId,
tc.datasets[layer.config.dataId].fields,
layer.gpuFilter
),
interactionConfig: INITIAL_VIS_STATE.interactionConfig,
visible: true,
layerCallbacks: {},
Expand Down
Loading