Skip to content

Commit

Permalink
[chore] extra typing for effects (#2390)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta committed Oct 23, 2023
1 parent 459ae55 commit 4f51abc
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/constants/src/default-settings.ts
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion src/effects/src/index.ts
@@ -1,2 +1,2 @@
export {Effect} from './effect';
export {default as Effect} from './effect';
export {createDeckEffectFromConfig} from './utils';
17 changes: 16 additions & 1 deletion src/reducers/src/vis-state-merger.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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
*/
Expand Down
11 changes: 10 additions & 1 deletion src/types/schemas.d.ts
Expand Up @@ -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'];
Expand All @@ -98,6 +104,7 @@ export type SavedEditor = {
export type SavedVisState = {
filters: SavedFilter[];
layers: SavedLayer[];
effects: SavedEffect[];
interactionConfig: SavedInteractionConfig;
layerBlending: string;
overlayBlending?: string;
Expand All @@ -110,6 +117,7 @@ export type SavedVisState = {
export type MinSavedVisStateV1 = {
filters?: MinSavedFilter[];
layers?: MinSavedLayer[];
effects?: SavedEffect[];
interactionConfig?: Partial<SavedInteractionConfig>;
layerBlending?: string;
overlayBlending?: string;
Expand All @@ -122,6 +130,7 @@ export type ParsedVisState = {
layers?: ParsedLayer[];
effects?: ParsedEffect[];
filters?: ParsedFilter[];
effects?: ParsedEffect[];
interactionConfig?: Partial<SavedInteractionConfig>;
layerBlending?: string;
overlayBlending?: string;
Expand Down
20 changes: 20 additions & 0 deletions 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';
20 changes: 20 additions & 0 deletions 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';

Expand Down

0 comments on commit 4f51abc

Please sign in to comment.