Skip to content

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

[Enhancement] add setTimeAnimation action (#70) (#1263)

Shan He0184cf1ec0c7
diff --git a/src/actions/vis-state-actions.d.ts b/src/actions/vis-state-actions.d.ts
index 5eee259dc..9b4c10081 100644
--- a/src/actions/vis-state-actions.d.ts
+++ b/src/actions/vis-state-actions.d.ts
@@ -124,6 +124,21 @@ export function setFilter(
valueIndex: number
): Merge<SetFilterUpdaterAction, {type: ActionTypes.SET_FILTER}>;
+
+export type SetTimeAnimationUpdaterAction = {
+ idx: number;
+ prop: string;
+ value: any;
+ valueIndex?: number;
+};
+export function setTimeAnmation(
+ idx: number,
+ prop: string,
+ value: any,
+ valueIndex?: number
+): Merge<SetTimeAnimationUpdaterAction, {type: ActionTypes.SET_TIME_ANIMATION}>;
+
+
export type AddFilterUpdaterAction = {
dataId: string;
};
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.js
index 79ab2496c..bb128fc90 100644
--- a/src/actions/vis-state-actions.js
+++ b/src/actions/vis-state-actions.js
@@ -179,6 +179,27 @@ export function setFilter(idx, prop, value, valueIndex) {
};
}
+/**
+ * Same as Update filter
+ * @memberof visStateActions
+ * @param idx -`idx` of filter to be updated
+ * @param prop - `prop` of filter, e,g, `dataId`, `name`, `value`
+ * @param value - new value
+ * @param valueIndex - dataId index
+ * @returns action
+ * @type {typeof import('./vis-state-actions').setTimeAnmation}
+ * @public
+ */
+export function setTimeAnmation(idx, prop, value, valueIndex) {
+ return {
+ type: ActionTypes.SET_TIME_ANIMATION,
+ idx,
+ prop,
+ value,
+ valueIndex
+ };
+}
+
/**
* Add a new filter
* @memberof visStateActions
diff --git a/src/components/bottom-widget.js b/src/components/bottom-widget.js
index 1b15d30fc..528f63a36 100644
--- a/src/components/bottom-widget.js
+++ b/src/components/bottom-widget.js
@@ -112,6 +112,7 @@ export default function BottomWidgetFactory(TimeWidget, AnimationControl) {
showTimeDisplay={showFloatingTimeDisplay}
setFilterPlot={visStateActions.setFilterPlot}
setFilter={visStateActions.setFilter}
+ setTimeAnmation={visStateActions.setTimeAnmation}
toggleAnimation={visStateActions.toggleFilterAnimation}
updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
enlargeFilter={visStateActions.enlargeFilter}
diff --git a/src/constants/action-types.d.ts b/src/constants/action-types.d.ts
index 5f74f5d17..05a5ea6ec 100644
--- a/src/constants/action-types.d.ts
+++ b/src/constants/action-types.d.ts
@@ -23,6 +23,7 @@ export type ActionType = {
REMOVE_DATASET: string;
REORDER_LAYER: string;
SET_FILTER: string;
+ SET_TIME_ANIMATION: string;
SHOW_DATASET_TABLE: string;
UPDATE_LAYER_BLENDING: string;
UPDATE_VIS_DATA: string;
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index 0e8ca762a..2c2e70c88 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -75,6 +75,7 @@ const ActionTypes = {
REMOVE_DATASET: `${ACTION_PREFIX}REMOVE_DATASET`,
REORDER_LAYER: `${ACTION_PREFIX}REORDER_LAYER`,
SET_FILTER: `${ACTION_PREFIX}SET_FILTER`,
+ SET_TIME_ANIMATION: `${ACTION_PREFIX}SET_TIME_ANIMATION`,
SHOW_DATASET_TABLE: `${ACTION_PREFIX}SHOW_DATASET_TABLE`,
UPDATE_LAYER_BLENDING: `${ACTION_PREFIX}UPDATE_LAYER_BLENDING`,
UPDATE_VIS_DATA: `${ACTION_PREFIX}UPDATE_VIS_DATA`,
diff --git a/src/reducers/vis-state-updaters.d.ts b/src/reducers/vis-state-updaters.d.ts
index a673b4e1a..aaa3c92af 100644
--- a/src/reducers/vis-state-updaters.d.ts
+++ b/src/reducers/vis-state-updaters.d.ts
@@ -363,6 +363,10 @@ export function setFilterUpdater(
state: VisState,
action: VisStateActions.SetFilterUpdaterAction
): VisState;
+export function setTimeAnmationUpdater(
+ state: VisState,
+ action: VisStateActions.SetTimeAnmationUpdaterAction
+): VisState;
export function addFilterUpdater(
state: VisState,
action: VisStateActions.AddFilterUpdaterAction
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index c7ee2c7bd..79793b1b4 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -461,6 +461,16 @@ export function layerVisConfigChangeUpdater(state, action) {
return updateStateWithLayerAndData(state, {layer: newLayer, idx});
}
+/**
+ * Update filter property
+ * @memberof visStateUpdaters
+ * @type {typeof import('./vis-state-updaters').setTimeAnmationUpdater}
+ * @public
+ */
+export function setTimeAnmationUpdater(state, action) {
+ return setFilterUpdater(state, action);
+}
+
/**
* Update filter property
* @memberof visStateUpdaters
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.js
index 671b43d2d..a8ea57fa8 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.js
@@ -76,6 +76,8 @@ const actionHandler = {
[ActionTypes.RESET_MAP_CONFIG]: visStateUpdaters.resetMapConfigUpdater,
[ActionTypes.SET_FILTER]: visStateUpdaters.setFilterUpdater,
+
+ [ActionTypes.SET_TIME_ANIMATION]: visStateUpdaters.setTimeAnmationUpdater,
[ActionTypes.SET_FILTER_PLOT]: visStateUpdaters.setFilterPlotUpdater,
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index c00dd6013..8b164fd63 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -1899,7 +1899,7 @@ test('#visStateReducer -> SET_FILTER.dataId', t => {
t.end();
});
-test('#visStateReducer -> setFilter.dynamicDomain & gpu', t => {
+function testSetFilterDynamicDomainGPU(t, setFilter) {
const {fields, rows} = processGeojson(CloneDeep(geojsonData));
const payload = [
{
@@ -1918,10 +1918,7 @@ test('#visStateReducer -> setFilter.dynamicDomain & gpu', t => {
const stateWithFilter = reducer(initialState, VisStateActions.addFilter('milkshake'));
// set filter 'name'
- const stateWithFilterName = reducer(
- stateWithFilter,
- VisStateActions.setFilter(0, 'name', 'TRIPS')
- );
+ const stateWithFilterName = reducer(stateWithFilter, setFilter(0, 'name', 'TRIPS'));
const expectedFilterWName = {
dataId: ['milkshake'],
@@ -1952,10 +1949,7 @@ test('#visStateReducer -> setFilter.dynamicDomain & gpu', t => {
cmpFilters(t, expectedFilterWName, stateWithFilterName.filters[0]);
// set filter value
- const stateWithFilterValue = reducer(
- stateWithFilterName,
- VisStateActions.setFilter(0, 'value', [8, 20])
- );
+ const stateWithFilterValue = reducer(stateWithFilterName, setFilter(0, 'value', [8, 20]));
const expectedFilterWValue = {
...expectedFilterWName,
@@ -2020,7 +2014,14 @@ test('#visStateReducer -> setFilter.dynamicDomain & gpu', t => {
t.deepEqual(actualTripField[k], expectedField[k], `trip field ${k} should be same`);
});
cmpDataset(t, expectedFilteredDataset, stateWithFilterValue.datasets.milkshake);
+}
+test('#visStateReducer -> setFilter.dynamicDomain & gpu', t => {
+ testSetFilterDynamicDomainGPU(t, VisStateActions.setFilter);
+ t.end();
+});
+test('#visStateReducer -> setTimeAnmation', t => {
+ testSetFilterDynamicDomainGPU(t, VisStateActions.setTimeAnmation);
t.end();
});