Skip to content

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

fix: keep the animation timezone and time format in saved maps (#3754)

Javier Andrés García7aac179997eb
diff --git a/src/reducers/src/vis-state-merger.ts b/src/reducers/src/vis-state-merger.ts
index c6ff0c44b..b1bdb0686 100644
--- a/src/reducers/src/vis-state-merger.ts
+++ b/src/reducers/src/vis-state-merger.ts
@@ -951,7 +951,10 @@ function combineAnimationConfigs(configs: SavedAnimationConfig[]): SavedAnimatio
// get the smallest values of currentTime and speed among all configs
return {
currentTime: aggregate(configs, AGGREGATION_TYPES.minimum, c => c.currentTime) ?? null,
- speed: aggregate(configs, AGGREGATION_TYPES.minimum, c => c.speed) ?? null
+ speed: aggregate(configs, AGGREGATION_TYPES.minimum, c => c.speed) ?? null,
+ // and the most common time format and timezone among the configs that set one
+ timeFormat: getValueWithHighestOccurrence(configs.map(c => c.timeFormat)),
+ timezone: getValueWithHighestOccurrence(configs.map(c => c.timezone))
};
}
diff --git a/src/schemas/src/vis-state-schema.ts b/src/schemas/src/vis-state-schema.ts
index 987071672..be48612bc 100644
--- a/src/schemas/src/vis-state-schema.ts
+++ b/src/schemas/src/vis-state-schema.ts
@@ -1049,7 +1049,9 @@ export const propertiesV1 = {
version: VERSIONS.v1,
properties: {
currentTime: null,
- speed: null
+ speed: null,
+ timeFormat: null,
+ timezone: null
},
key: 'animationConfig'
}),
diff --git a/src/types/schemas.d.ts b/src/types/schemas.d.ts
index 3f9029bb3..69c6c171b 100644
--- a/src/types/schemas.d.ts
+++ b/src/types/schemas.d.ts
@@ -92,6 +92,8 @@ export type SavedEffect = ParsedEffect;
export type SavedAnimationConfig = {
currentTime: AnimationConfig['currentTime'];
speed: AnimationConfig['speed'];
+ timeFormat?: AnimationConfig['timeFormat'];
+ timezone?: AnimationConfig['timezone'];
};
export type SavedEditor = {
diff --git a/test/node/reducers/vis-state-merger-combine-configs-test.spec.js b/test/node/reducers/vis-state-merger-combine-configs-test.spec.js
index 0275c2b64..aacb8c006 100644
--- a/test/node/reducers/vis-state-merger-combine-configs-test.spec.js
+++ b/test/node/reducers/vis-state-merger-combine-configs-test.spec.js
@@ -183,7 +183,18 @@ const TEST_CASES = [
{currentTime: 500, speed: 1},
{currentTime: 100, speed: 5}
],
- expected: {currentTime: 100, speed: 1}
+ expected: {currentTime: 100, speed: 1, timeFormat: null, timezone: null}
+ },
+ {
+ testMessage: 'animationConfig with timezone and time format',
+ propName: 'animationConfig',
+ configsToMerge: [
+ {currentTime: 500, speed: 1, timeFormat: 'L LTS', timezone: 'America/Guayaquil'},
+ {currentTime: 300, speed: 2, timeFormat: null, timezone: 'UTC'},
+ {currentTime: 100, speed: 5, timeFormat: null, timezone: 'America/Guayaquil'},
+ {currentTime: 200, speed: 3}
+ ],
+ expected: {currentTime: 100, speed: 1, timeFormat: 'L LTS', timezone: 'America/Guayaquil'}
},
{
testMessage: 'editor',
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index c71b6c528..93c4ebcff 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -27,7 +27,13 @@ import {SYNC_TIMELINE_MODES} from '@kepler.gl/constants';
import SchemaManager, {CURRENT_VERSION, visStateSchema} from '@kepler.gl/schemas';
import {processKeplerglJSON} from '@kepler.gl/processors';
-import {updateVisData, receiveMapConfig, addDataToMap, registerEntry} from '@kepler.gl/actions';
+import {
+ updateVisData,
+ receiveMapConfig,
+ addDataToMap,
+ registerEntry,
+ setLayerAnimationTimeConfig
+} from '@kepler.gl/actions';
import {createDataContainer, findById} from '@kepler.gl/utils';
@@ -79,6 +85,7 @@ import {
StateWFilesFiltersLayerColor,
StateWSyncedTimeFilter,
StateWSplitMaps,
+ StateWTripGeojson,
testCsvDataId,
testGeoJsonDataId,
StateWFiles,
@@ -2192,6 +2199,35 @@ test('VisStateMerger -> load time filter/trip layer synced map', t => {
t.end();
});
+test('VisStateMerger -> load trip layer animation timezone and time format', t => {
+ const oldState = cloneDeep(StateWTripGeojson);
+ oldState.visState = visStateReducer(
+ oldState.visState,
+ setLayerAnimationTimeConfig({timezone: 'America/Guayaquil', timeFormat: 'L LTS'})
+ );
+
+ const appStateToSave = SchemaManager.save(oldState);
+ const stateParsed = SchemaManager.load(appStateToSave);
+ const initialVisState = cloneDeep(InitialState).visState;
+
+ const visState = applyActions(visStateReducer, initialVisState, [
+ {action: updateVisData, payload: [stateParsed.datasets, {}, stateParsed.config]}
+ ]);
+
+ t.equal(
+ visState.animationConfig.timezone,
+ 'America/Guayaquil',
+ 'Should load the saved animation timezone'
+ );
+ t.equal(
+ visState.animationConfig.timeFormat,
+ 'L LTS',
+ 'Should load the saved animation time format'
+ );
+
+ t.end();
+});
+
test('VisStateMerger -> createLayerFromConfig with Parsed Layer', t => {
const oldState = CloneDeep(StateWFiles);
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index 1695603b6..1c07fd108 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -317,7 +317,12 @@ test('#visStateSchema -> v1 -> save animation', t => {
);
const expectedSavedLayers = [expectedSavedTripLayer];
- const expectedAnimationConfig = {currentTime: 1565577261000, speed: 1};
+ const expectedAnimationConfig = {
+ currentTime: 1565577261000,
+ speed: 1,
+ timeFormat: null,
+ timezone: null
+ };
cmpSavedLayers(t, expectedSavedLayers, vsToSave.layers);
t.deepEqual(vsToSave.animationConfig, expectedAnimationConfig, 'should save animationConfig');