[Enhancement - RFC] Update filter structure
- Dominant language
- TypeScript
- Stars
- 12k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 66
Description
## Filter structure
### Current State
the current kepler.gl filter allows to perform actions against dataset/field/layer through the following property:
- dataId
- name
- layerId
During the development of geofiltering we enhanced the filter structure to perform operations against selected layers.
Because of the current structure, supporting multiple dataset filters has been challenging.
Some of the. challenges are the following:
- making sure __dataId__ and __name__ properties are in sync: length and field/dataset match.
- adding a new dataset/field pair requires calling setFIlterUpdater twice, once to update __dataId__ and the last one to update __name__.
- currently layerId is only used for geofilters but we have still store the name property.
- when trying to remove an existing dataset/field pair, we need to perform two operations (dataId and name updates) but most importantly we need to re-validate, calculate difference and ensure data and names are in sync.
- shouldApplyFilter: we validate a filter by the presence of a value and whether the current datasetId is contained within dataId. The logic became more complicated when added multi dataset filter by doing an extra check (if current. dataset we are testing against is present in __dataId__ at some index, said index must be used to retrieve the __name__ value to be applied to perform filtering operations).
### Proposal
Change the current structure into the following:
- create a new property datasources which holds a list of objects that defined a filter datasource to be used to run filter operations against datasets/fields/layers
- each datasource may hold references to: datasetId, field (name), layerId
- remove dataId/layerId from filter root level
- re-purpose name property to assign an actual name to each filter
- different types of filter can require different properties
```
type FilterDatasources {
[key: string]: {
fieldName?: string;
layerId?: string[]
// to support span filters
startFieldName?: string;
endFieldName?: string;
}
}
filter: {
....,
datasources: FilterDatasources,
// to support span filters
rules: 'include' || 'intersect' // need to list all posibile values
}
```
#### Filter example
```
// Time Range filter
filter = {
type: 'timeRange',
datasources: {
datasetA: {
fieldName: 'field1',
}
}
}
// Geo filter:
filter = {
type: 'timeRange',
datasources: {
datasetA: {
layerId: ['layerId1', 'layerId2'],
},
datasetB: {
layerId: ['layerId3'],
}
}
}
// Timespan Filter
filter = {
datasources: {
'datasetA': {
startField: 'begin_trip',
endField: 'end_trip'
},
'datasetB': {
startField: 'restaurant_open',
endField: 'restaurant_end'
},
},
value: [1584571749149, 15845717982349],
rule: 'include' || 'intersect'
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.