Skip to content

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

[chore] extra typing for effects (#2390)

Igor Dykhta4f51abc33b91
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index 871a93dcd..ee7e673d0 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -1250,3 +1250,21 @@ export const EFFECT_DESCS: {type: string; name: string}[] = [
LIGHT_AND_SHADOW_EFFECT,
...Object.keys(POSTPROCESSING_EFFECTS).map(keyName => POSTPROCESSING_EFFECTS[keyName])
];
+
+export type EffectType =
+ | 'ink'
+ | 'brightnessContrast'
+ | 'hueSaturation'
+ | 'vibrance'
+ | 'sepia'
+ | 'dotScreen'
+ | 'colorHalftone'
+ | 'noise'
+ | 'triangleBlur'
+ | 'zoomBlur'
+ | 'tiltShift'
+ | 'edgeWork'
+ | 'vignette'
+ | 'magnify'
+ | 'hexagonalPixelate'
+ | 'lightAndShadow';
diff --git a/src/effects/src/index.ts b/src/effects/src/index.ts
index 197affa6f..e171e4d63 100644
--- a/src/effects/src/index.ts
+++ b/src/effects/src/index.ts
@@ -1,2 +1,2 @@
-export {Effect} from './effect';
+export {default as Effect} from './effect';
export {createDeckEffectFromConfig} from './utils';
diff --git a/src/reducers/src/vis-state-merger.ts b/src/reducers/src/vis-state-merger.ts
index 19ab334df..6d2f4f234 100644
--- a/src/reducers/src/vis-state-merger.ts
+++ b/src/reducers/src/vis-state-merger.ts
@@ -44,7 +44,8 @@ import {
SavedEditor,
ParsedConfig,
Filter,
- Effect as EffectType
+ Effect as EffectType,
+ ParsedEffect
} from '@kepler.gl/types';
import {KeplerTable, Datasets, assignGpuChannels, resetFilterGpuMode} from '@kepler.gl/table';
@@ -206,6 +207,20 @@ export function serializeLayer(
return serializedVisState?.layers?.[0];
}
+/**
+ * Get loaded effect from state
+ */
+export function serializeEffect(
+ newEffect: EffectType,
+ schema: KeplerGLSchemaClass
+): ParsedEffect | undefined {
+ const serializedVisState = serializeVisState(
+ {effects: [newEffect], effectOrder: [newEffect.id]},
+ schema
+ );
+ return serializedVisState?.effects?.[0];
+}
+
/**
* Get vis state config
*/
diff --git a/src/types/schemas.d.ts b/src/types/schemas.d.ts
index 0066e397c..8570099d6 100644
--- a/src/types/schemas.d.ts
+++ b/src/types/schemas.d.ts
@@ -82,9 +82,15 @@ export type ParsedLayer = SavedLayer | MinSavedLayer;
export type ParsedEffect = {
id: string;
- config: EffectConfig;
+ config: {
+ type: string;
+ isEnabled: boolean;
+ params: Record<string, number | number[] | {value: number}>;
+ };
};
+export type SavedEffect = ParsedEffect;
+
export type SavedAnimationConfig = {
currentTime: AnimationConfig['currentTime'];
speed: AnimationConfig['speed'];
@@ -98,6 +104,7 @@ export type SavedEditor = {
export type SavedVisState = {
filters: SavedFilter[];
layers: SavedLayer[];
+ effects: SavedEffect[];
interactionConfig: SavedInteractionConfig;
layerBlending: string;
overlayBlending?: string;
@@ -110,6 +117,7 @@ export type SavedVisState = {
export type MinSavedVisStateV1 = {
filters?: MinSavedFilter[];
layers?: MinSavedLayer[];
+ effects?: SavedEffect[];
interactionConfig?: Partial<SavedInteractionConfig>;
layerBlending?: string;
overlayBlending?: string;
@@ -122,6 +130,7 @@ export type ParsedVisState = {
layers?: ParsedLayer[];
effects?: ParsedEffect[];
filters?: ParsedFilter[];
+ effects?: ParsedEffect[];
interactionConfig?: Partial<SavedInteractionConfig>;
layerBlending?: string;
overlayBlending?: string;
diff --git a/test/browser/components/effects/index.js b/test/browser/components/effects/index.js
index 734f8d75e..3d1a5e1e2 100644
--- a/test/browser/components/effects/index.js
+++ b/test/browser/components/effects/index.js
@@ -1,2 +1,22 @@
+// Copyright (c) 2023 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
import './effect-manager-test';
import './effect-configurator-test';
diff --git a/test/node/utils/effect-utils-test.js b/test/node/utils/effect-utils-test.js
index 9c46052f9..5c987eafe 100644
--- a/test/node/utils/effect-utils-test.js
+++ b/test/node/utils/effect-utils-test.js
@@ -1,3 +1,23 @@
+// Copyright (c) 2023 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
import {LightingEffect, PostProcessEffect} from '@deck.gl/core';
import test from 'tape';