Skip to content

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

[chore] Effects - config refactoring (#2422)

Igor Dykhtaa69b08783337
diff --git a/src/actions/src/vis-state-actions.ts b/src/actions/src/vis-state-actions.ts
index d9e7d7b23..3480890be 100644
--- a/src/actions/src/vis-state-actions.ts
+++ b/src/actions/src/vis-state-actions.ts
@@ -37,8 +37,7 @@ import {
Filter,
ParsedConfig,
ParsedLayer,
- EffectConfig,
- EffectParamsPartial
+ EffectPropsPartial
} from '@kepler.gl/types';
// TODO - import LoaderObject type from @loaders.gl/core when supported
// TODO - import LoadOptions type from @loaders.gl/core when supported
@@ -524,7 +523,7 @@ export function duplicateLayer(
}
export type AddEffectUpdaterAction = {
- config: EffectParamsPartial;
+ config: EffectPropsPartial;
};
/**
@@ -535,7 +534,7 @@ export type AddEffectUpdaterAction = {
* @public
*/
export function addEffect(
- config: EffectParamsPartial
+ config: EffectPropsPartial
): Merge<AddEffectUpdaterAction, {type: typeof ActionTypes.ADD_EFFECT}> {
return {
type: ActionTypes.ADD_EFFECT,
@@ -585,7 +584,7 @@ export function removeEffect(
export type UpdateEffectUpdaterAction = {
id: string;
- props: Partial<EffectConfig>;
+ props: EffectPropsPartial;
};
/**
@@ -597,7 +596,7 @@ export type UpdateEffectUpdaterAction = {
*/
export function updateEffect(
id: string,
- props: Partial<EffectConfig>
+ props: EffectPropsPartial
): Merge<UpdateEffectUpdaterAction, {type: typeof ActionTypes.UPDATE_EFFECT}> {
return {
type: ActionTypes.UPDATE_EFFECT,
diff --git a/src/components/src/effects/effect-configurator.tsx b/src/components/src/effects/effect-configurator.tsx
index 10823113e..c7da242a9 100644
--- a/src/components/src/effects/effect-configurator.tsx
+++ b/src/components/src/effects/effect-configurator.tsx
@@ -4,7 +4,7 @@ import {injectIntl, IntlShape} from 'react-intl';
import {LIGHT_AND_SHADOW_EFFECT} from '@kepler.gl/constants';
import {isNumber} from '@kepler.gl/utils';
-import {Effect, EffectConfig} from '@kepler.gl/types';
+import {Effect, EffectUpdateProps} from '@kepler.gl/types';
import {PanelLabel} from '../common/styled-components';
import RangeSliderFactory from '../common/range-slider';
@@ -16,7 +16,7 @@ export type EffectConfiguratorProps = {
updateEffectConfig: (
e: Event | null | undefined,
id: string,
- config: Partial<EffectConfig>
+ config: Partial<EffectUpdateProps>
) => void;
};
@@ -67,40 +67,39 @@ export default function EffectConfiguratorFactory(
): React.FC<EffectConfiguratorProps> {
const EffectConfigurator = ({
effect,
- updateEffectConfig,
- intl
+ updateEffectConfig
}: EffectConfiguratorProps & {intl: IntlShape}) => {
const renderShadowEffectConfigurator = useCallback(() => {
- const {config} = effect;
+ const {parameters} = effect;
const sliderProps = useMemo(() => {
const propNames = ['shadowIntensity', 'ambientLightIntensity', 'sunLightIntensity'];
return propNames.map(propName => {
return {
- value1: effect.config.params[propName],
+ value1: parameters[propName],
range: [0, 1],
value0: 0,
- onChange: (value: number[], e?: Event) => {
- updateEffectConfig(e, effect.id, {params: {[propName]: value[1]}});
+ onChange: (value: number[], event?: Event) => {
+ updateEffectConfig(event, effect.id, {parameters: {[propName]: value[1]}});
}
};
});
- }, [effect, config.params, updateEffectConfig]);
+ }, [effect.id, parameters, updateEffectConfig]);
const onDateTimeChange = useCallback(
value => {
- updateEffectConfig(null, effect.id, {params: {timestamp: value}});
+ updateEffectConfig(null, effect.id, {parameters: {timestamp: value}});
},
- [effect, updateEffectConfig]
+ [effect.id, updateEffectConfig]
);
const onTimeModeChange = useCallback(
value => {
updateEffectConfig(null, effect.id, {
- params: {timeMode: value}
+ parameters: {timeMode: value}
});
},
- [effect, updateEffectConfig]
+ [effect.id, updateEffectConfig]
);
const colorPickerProps = useMemo(() => {
@@ -109,13 +108,13 @@ export default function EffectConfiguratorFactory(
return {
colorSets: [
{
- selectedColor: config.params[propName],
- setColor: v => updateEffectConfig(null, effect.id, {params: {[propName]: v}})
+ selectedColor: parameters[propName],
+ setColor: v => updateEffectConfig(null, effect.id, {parameters: {[propName]: v}})
}
]
};
});
- }, [effect, config.params, updateEffectConfig]);
+ }, [effect.id, parameters, updateEffectConfig]);
return (
<StyledEffectConfigurator key={effect.id}>
@@ -123,11 +122,10 @@ export default function EffectConfiguratorFactory(
<PanelLabel>{'Date & Time'}</PanelLabel>
</PanelLabelWrapper>
<EffectTimeConfigurator
- timestamp={config.params.timestamp}
+ timestamp={parameters.timestamp}
onDateTimeChange={onDateTimeChange}
- timeMode={config.params.timeMode}
+ timeMode={parameters.timeMode}
onTimeModeChange={onTimeModeChange}
- intl={intl}
/>
<PanelLabelWrapper>
<PanelLabel>{'Shadow intensity'}</PanelLabel>
@@ -161,12 +159,11 @@ export default function EffectConfiguratorFactory(
</StyledColorSelectorWrapper>
</StyledEffectConfigurator>
);
- }, [effect, updateEffectConfig]);
+ }, [effect, effect.parameters, updateEffectConfig]);
const renderPostProcessingEffectConfigurator = useCallback(() => {
- const {config} = effect;
const uniforms = effect.deckEffect?.module.uniforms || {};
- const propNames = Object.keys(uniforms);
+ const propNames = useMemo(() => Object.keys(uniforms), [uniforms]);
const slidersForProps = useMemo(() => {
return propNames.map(propName => {
@@ -181,7 +178,7 @@ export default function EffectConfiguratorFactory(
range: [number, number];
onChange: (value: number[], e?: Event) => void;
}[] = [];
- const prevValue = config.params[propName];
+ const prevValue = effect.parameters[propName];
// the uniform is [0, 1] array
if (uniform.length === 2) {
@@ -189,9 +186,9 @@ export default function EffectConfiguratorFactory(
value1: prevValue[0] || 0,
range: [0, 1],
value0: 0,
- onChange: (newValue, e) => {
- updateEffectConfig(e, effect.id, {
- params: {[propName]: [newValue[1], prevValue[1]]}
+ onChange: (newValue, event) => {
+ updateEffectConfig(event, effect.id, {
+ parameters: {[propName]: [newValue[1], prevValue[1]]}
});
}
});
@@ -200,9 +197,9 @@ export default function EffectConfiguratorFactory(
value1: prevValue[1] || 0,
range: [0, 1],
value0: 0,
- onChange: (newValue, e) => {
- updateEffectConfig(e, effect.id, {
- params: {[propName]: [prevValue[0], newValue[1]]}
+ onChange: (newValue, event) => {
+ updateEffectConfig(event, effect.id, {
+ parameters: {[propName]: [prevValue[0], newValue[1]]}
});
}
});
@@ -213,8 +210,8 @@ export default function EffectConfiguratorFactory(
value1: prevValue || 0,
range: [0, 500],
value0: 0,
- onChange: (newValue, e) => {
- updateEffectConfig(e, effect.id, {params: {[propName]: newValue[1]}});
+ onChange: (newValue, event) => {
+ updateEffectConfig(event, effect.id, {parameters: {[propName]: newValue[1]}});
}
});
}
@@ -224,8 +221,8 @@ export default function EffectConfiguratorFactory(
value1: prevValue || 0,
range: [uniform.min ?? uniform.softMin ?? 0, uniform.max ?? uniform.softMax ?? 1],
value0: uniform.min ?? uniform.softMin ?? 0,
- onChange: (newValue, e) => {
- updateEffectConfig(e, effect.id, {params: {[propName]: newValue[1]}});
+ onChange: (newValue, event) => {
+ updateEffectConfig(event, effect.id, {parameters: {[propName]: newValue[1]}});
}
});
} else {
@@ -234,7 +231,7 @@ export default function EffectConfiguratorFactory(
return sliders;
});
- }, [propNames, effect, effect.config.params, updateEffectConfig]);
+ }, [propNames, effect, effect.parameters, updateEffectConfig]);
return (
<StyledEffectConfigurator key={effect.id}>
@@ -257,10 +254,9 @@ export default function EffectConfiguratorFactory(
})}
</StyledEffectConfigurator>
);
- }, [effect, updateEffectConfig]);
+ }, [effect, effect.parameters, updateEffectConfig]);
- const {config} = effect;
- if (config.type === LIGHT_AND_SHADOW_EFFECT.type) return renderShadowEffectConfigurator();
+ if (effect.type === LIGHT_AND_SHADOW_EFFECT.type) return renderShadowEffectConfigurator();
return renderPostProcessingEffectConfigurator();
};
diff --git a/src/components/src/effects/effect-manager.tsx b/src/components/src/effects/effect-manager.tsx
index 62d6269b9..683991d30 100644
--- a/src/components/src/effects/effect-manager.tsx
+++ b/src/components/src/effects/effect-manager.tsx
@@ -3,7 +3,7 @@ import styled from 'styled-components';
import {injectIntl, IntlShape} from 'react-intl';
import {addEffect, updateEffect, removeEffect, reorderEffect} from '@kepler.gl/actions';
-import {LIGHT_AND_SHADOW_EFFECT, EFFECT_DESCS} from '@kepler.gl/constants';
+import {LIGHT_AND_SHADOW_EFFECT, EFFECT_DESCRIPTIONS} from '@kepler.gl/constants';
import {VisStateActions} from '@kepler.gl/actions';
import {Effect} from '@kepler.gl/types';
@@ -73,12 +73,12 @@ function EffectManagerFactory(
// Prevent shadow effect from being added multiple times
const effectOptions = useMemo(() => {
const hasShadow = effects.some(effect => {
- return effect.config.type === LIGHT_AND_SHADOW_EFFECT.type;
+ return effect.type === LIGHT_AND_SHADOW_EFFECT.type;
});
return hasShadow
- ? EFFECT_DESCS.filter(desc => desc.type !== LIGHT_AND_SHADOW_EFFECT.type)
- : EFFECT_DESCS;
+ ? EFFECT_DESCRIPTIONS.filter(desc => desc.type !== LIGHT_AND_SHADOW_EFFECT.type)
+ : EFFECT_DESCRIPTIONS;
}, [effects]);
return (
diff --git a/src/components/src/effects/effect-panel-header.tsx b/src/components/src/effects/effect-panel-header.tsx
index 787b43d62..d3d159390 100644
--- a/src/components/src/effects/effect-panel-header.tsx
+++ b/src/components/src/effects/effect-panel-header.tsx
@@ -1,13 +1,15 @@
-import React from 'react';
+import React, {useMemo} from 'react';
import classnames from 'classnames';
import styled from 'styled-components';
+import {EFFECT_DESCRIPTIONS} from '@kepler.gl/constants';
+
import PanelHeaderActionFactory from '../side-panel/panel-header-action';
import {ArrowDown, EyeSeen, EyeUnseen, Trash, VertDots, BaseProps} from '../common/icons';
import {StyledPanelHeader} from '../common/styled-components';
export type EffectPanelHeaderProps = {
- label: string;
+ type: string;
listeners: any;
effectId: string;
isEnabled: boolean;
@@ -181,12 +183,17 @@ function EffectPanelHeaderFactory(
const {
isConfigActive,
isDragNDropEnabled,
- label,
+ type,
onToggleEnableConfig,
listeners,
showSortHandle = true
} = props;
+ const label = useMemo(() => {
+ const description = EFFECT_DESCRIPTIONS.find(_description => _description.type === type);
+ return description?.name || 'Effect';
+ }, [type]);
+
return (
<StyledEffectPanelHeader
className={classnames('effect-panel__header', {
diff --git a/src/components/src/effects/effect-panel.tsx b/src/components/src/effects/effect-panel.tsx
index 76b5d85dc..8a074abba 100644
--- a/src/components/src/effects/effect-panel.tsx
+++ b/src/components/src/effects/effect-panel.tsx
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import {dataTestIds, LIGHT_AND_SHADOW_EFFECT} from '@kepler.gl/constants';
import {removeEffect, updateEffect} from '@kepler.gl/actions';
-import {Effect, EffectConfig} from '@kepler.gl/types';
+import {Effect} from '@kepler.gl/types';
import EffectPanelHeaderFactory from './effect-panel-header';
import EffectConfiguratorFactory from './effect-configurator';
@@ -52,35 +52,35 @@ function EffectPanelFactory(
isDraggable: PropTypes.bool
};
- _toggleEnabled = (e?: Event) => {
- e?.stopPropagation();
+ _toggleEnabled = (event?: Event) => {
+ event?.stopPropagation();
this.props.updateEffect(this.props.effect.id, {
- isEnabled: !this.props.effect.config.isEnabled
+ isEnabled: !this.props.effect.isEnabled
});
};
- _toggleConfigActive = (e?: Event) => {
- e?.stopPropagation();
+ _toggleConfigActive = (event?: Event) => {
+ event?.stopPropagation();
this.props.updateEffect(this.props.effect.id, {
- isConfigActive: !this.props.effect.config.isConfigActive
+ isConfigActive: !this.props.effect.isConfigActive
});
};
- _removeEffect = (e?: Event) => {
- e?.stopPropagation();
+ _removeEffect = (event?: Event) => {
+ event?.stopPropagation();
this.props.removeEffect(this.props.effect.id);
};
- _updateEffectConfig = (e, id, props) => {
- e?.stopPropagation();
+ _updateEffectConfig = (event, id, props) => {
+ event?.stopPropagation();
this.props.updateEffect(id, props);
};
render() {
const {effect, isDraggable, listeners} = this.props;
- const {config = {} as EffectConfig} = effect;
+ const {id, type, isConfigActive, isEnabled} = effect;
- const sortingAllowed = config.type !== LIGHT_AND_SHADOW_EFFECT.type;
+ const sortingAllowed = type !== LIGHT_AND_SHADOW_EFFECT.type;
return (
<PanelWrapper
@@ -92,20 +92,20 @@ function EffectPanelFactory(
onTouchStart={this.props.onTouchStart}
>
<EffectPanelHeader
- isConfigActive={config.isConfigActive}
- effectId={effect.id}
- label={config.name}
- isEnabled={config.isEnabled}
+ isConfigActive={isConfigActive}
+ effectId={id}
+ type={type}
+ isEnabled={isEnabled}
onToggleEnabled={this._toggleEnabled}
onRemoveEffect={this._removeEffect}
onToggleEnableConfig={this._toggleConfigActive}
isDragNDropEnabled={isDraggable && sortingAllowed}
listeners={listeners}
- showSortHandle={effect.type !== LIGHT_AND_SHADOW_EFFECT.type}
+ showSortHandle={type !== LIGHT_AND_SHADOW_EFFECT.type}
/>
- {config.isConfigActive && (
+ {isConfigActive && (
<EffectConfigurator
- key={`effect-configurator-${effect.id}`}
+ key={`effect-configurator-${id}`}
effect={effect}
updateEffectConfig={this._updateEffectConfig}
/>
diff --git a/src/components/src/effects/effect-time-configurator.tsx b/src/components/src/effects/effect-time-configurator.tsx
index ad19d2e3e..8c682cc10 100644
--- a/src/components/src/effects/effect-time-configurator.tsx
+++ b/src/components/src/effects/effect-time-configurator.tsx
@@ -22,7 +22,6 @@ export type EffectTimeConfiguratorProps = {
onDateTimeChange: (time: number) => void;
timeMode: LightAndShadowEffectTimeMode;
onTimeModeChange: (newMode: LightAndShadowEffectTimeMode) => void;
- intl: IntlShape;
};
type StyledWrapperProps = {disabled?: boolean};
@@ -91,7 +90,7 @@ export default function EffectTimeConfiguratorFactory(
timeMode,
onTimeModeChange,
intl
- }: EffectTimeConfiguratorProps) => {
+ }: EffectTimeConfiguratorProps & {intl: IntlShape}) => {
const [dateOnly, selectedTimeString] = useMemo(() => {
const date = new Date(timestamp);
diff --git a/src/components/src/effects/effect-type-selector.tsx b/src/components/src/effects/effect-type-selector.tsx
index 42e026776..dc6a40a3a 100644
--- a/src/components/src/effects/effect-type-selector.tsx
+++ b/src/components/src/effects/effect-type-selector.tsx
@@ -45,7 +45,7 @@ function EffectTypeSelectorFactory(): React.FC<EffectTypeSelectorProps> {
<Button
key={`${effectDesc.type}-${idx}`}
onClick={() => {
- onSelect({config: {type: effectDesc.type}});
+ onSelect({type: effectDesc.type});
// @ts-expect-error type current
tippyInstance.current?.hide();
}}
diff --git a/src/components/src/hooks/use-dnd-effects.tsx b/src/components/src/hooks/use-dnd-effects.tsx
index e93e1055b..f42175c26 100644
--- a/src/components/src/hooks/use-dnd-effects.tsx
+++ b/src/components/src/hooks/use-dnd-effects.tsx
@@ -25,7 +25,7 @@ const useDndEffects: (effects: Effect[], effectOrder: string[]) => DndEffectsHoo
const newActiveEffect = effects.find(effect => effect.id === active.id);
if (newActiveEffect) {
setActiveEffect(newActiveEffect);
- if (newActiveEffect.config.isConfigActive) {
+ if (newActiveEffect.isConfigActive) {
dispatch(updateEffect(newActiveEffect.id, {isConfigActive: false}));
}
}
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index 1bb70f125..a18e15527 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -1260,7 +1260,7 @@ export const POSTPROCESSING_EFFECTS: {[key: string]: {type: string; name: string
}
};
-export const EFFECT_DESCS: {type: string; name: string}[] = [
+export const EFFECT_DESCRIPTIONS: {type: string; name: string}[] = [
LIGHT_AND_SHADOW_EFFECT,
...Object.keys(POSTPROCESSING_EFFECTS).map(keyName => POSTPROCESSING_EFFECTS[keyName])
];
diff --git a/src/effects/src/effect.ts b/src/effects/src/effect.ts
index 91b99e37f..16e55b18c 100644
--- a/src/effects/src/effect.ts
+++ b/src/effects/src/effect.ts
@@ -1,15 +1,24 @@
import {generateHashId} from '@kepler.gl/utils';
-import {Effect as EffectInterface, EffectConfig, EffectParamsPartial} from '@kepler.gl/types';
+import {Effect as EffectInterface, EffectProps, EffectPropsPartial} from '@kepler.gl/types';
+import {DEFAULT_POST_PROCESSING_EFFECT_TYPE} from '@kepler.gl/constants';
export class Effect implements EffectInterface {
id: string;
- config: EffectConfig;
+ type: string;
+ isEnabled: boolean;
+ isConfigActive: boolean;
+ // effect specific parameters for a deck.gl effect (uniforms)
+ parameters: {[key: string]: any};
deckEffect: any;
- constructor(props: EffectParamsPartial = {}) {
+ constructor(props: EffectPropsPartial = {}) {
this.id = props.id || `e_${generateHashId(6)}`;
- this.config = this._getDefaultEffectConfig(props.config);
- this.deckEffect = null;
+
+ const _props = this.getDefaultProps(props);
+ this.type = _props.type;
+ this.isEnabled = _props.isEnabled;
+ this.isConfigActive = _props.isConfigActive;
+ this.parameters = _props.parameters;
this.deckEffect = null;
this._initializeEffect();
@@ -19,29 +28,26 @@ export class Effect implements EffectInterface {
// implemented in subclasses
}
- _onUpdateConfig() {
- // implemented in subclasses
- }
-
- _getDefaultEffectConfig(config: Partial<EffectConfig> = {}) {
- // implemented in subclasses
- return this.config;
- }
-
- updateConfig(config: Partial<EffectConfig>) {
- this.config = {
- ...this.config,
- ...config,
- params: {...this.config.params, ...(config.params || {})}
+ getDefaultProps(props: EffectPropsPartial = {}): EffectProps {
+ return {
+ id: props.id || `e_${generateHashId(6)}`,
+ type: props.type || DEFAULT_POST_PROCESSING_EFFECT_TYPE,
+ isEnabled: props.isEnabled ?? true,
+ isConfigActive: props.isConfigActive ?? true,
+ parameters: {...props.parameters}
};
}
- isValidToSave() {
- return Boolean(this.config.type && this.id && this.deckEffect);
+ setProps(props: EffectPropsPartial) {
+ this.id = props.id ?? this.id;
+ this.type = props.type ?? this.type;
+ this.isEnabled = props.isEnabled ?? this.isEnabled;
+ this.isConfigActive = props.isConfigActive ?? this.isConfigActive;
+ this.parameters = {...this.parameters, ...props.parameters};
}
- get type() {
- return this.config.type;
+ isValidToSave() {
+ return Boolean(this.type && this.id && this.deckEffect);
}
}
diff --git a/src/effects/src/index.ts b/src/effects/src/index.ts
index e171e4d63..389ab6ccd 100644
--- a/src/effects/src/index.ts
+++ b/src/effects/src/index.ts
@@ -1,2 +1,2 @@
export {default as Effect} from './effect';
-export {createDeckEffectFromConfig} from './utils';
+export {createEffect} from './utils';
diff --git a/src/effects/src/lighting-effect.ts b/src/effects/src/lighting-effect.ts
index 78dea3549..6c8e7c0e5 100644
--- a/src/effects/src/lighting-effect.ts
+++ b/src/effects/src/lighting-effect.ts
@@ -2,7 +2,7 @@ import {AmbientLight, _SunLight as SunLight} from '@deck.gl/core';
import {LIGHT_AND_SHADOW_EFFECT, DEFAULT_LIGHT_AND_SHADOW_PROPS} from '@kepler.gl/constants';
import {normalizeColor} from '@kepler.gl/utils';
-import {EffectConfig, EffectParamsPartial} from '@kepler.gl/types';
+import {EffectProps, EffectPropsPartial} from '@kepler.gl/types';
import Effect from './effect';
import CustomDeckLightingEffect from './custom-deck-lighting-effect';
@@ -15,23 +15,23 @@ const LIGHT_AND_SHADOW_EFFECT_DESC = {
class LightingEffect extends Effect {
// deckEffect: PostProcessEffect | LightingEffect | null;
- constructor(props: EffectParamsPartial) {
+ constructor(props: EffectPropsPartial) {
super(props);
}
_initializeEffect() {
- this.config.params = {...DEFAULT_LIGHT_AND_SHADOW_PROPS, ...this.config.params};
- const {params} = this.config;
+ this.parameters = {...DEFAULT_LIGHT_AND_SHADOW_PROPS, ...this.parameters};
+ const {parameters} = this;
const ambientLight = new AmbientLight({
- color: params.ambientLightColor,
- intensity: params.ambientLightIntensity
+ color: parameters.ambientLightColor,
+ intensity: parameters.ambientLightIntensity
});
const sunLight = new SunLight({
- timestamp: params.timestamp,
- color: params.sunLightColor,
- intensity: params.sunLightIntensity,
+ timestamp: parameters.timestamp,
+ color: parameters.sunLightColor,
+ intensity: parameters.sunLightIntensity,
_shadow: true
});
@@ -40,42 +40,41 @@ class LightingEffect extends Effect {
sunLight
});
if (this.deckEffect) {
- this.deckEffect.shadowColor = [...normalizeColor(params.shadowColor), params.shadowIntensity];
+ this.deckEffect.shadowColor = [
+ ...normalizeColor(parameters.shadowColor),
+ parameters.shadowIntensity
+ ];
}
}
- _getDefaultEffectConfig(config: Partial<EffectConfig> = {}) {
- const type = config.type || LIGHT_AND_SHADOW_EFFECT_DESC.type;
- return {
- type,
- name: config.name || LIGHT_AND_SHADOW_EFFECT_DESC.name,
- isEnabled: config.isEnabled ?? true,
- isConfigActive: config.isConfigActive ?? true,
- params: {...(config.params || {})}
- };
+ getDefaultProps(props: EffectPropsPartial = {}): EffectProps {
+ return super.getDefaultProps({type: LIGHT_AND_SHADOW_EFFECT_DESC.type, ...props});
}
- updateConfig(config: Partial<EffectConfig>) {
- super.updateConfig(config);
+ setProps(props: EffectPropsPartial) {
+ super.setProps(props);
// any uniform updated?
- if (config.params) {
- const {params} = this.config;
+ if (props.parameters) {
+ const {parameters} = this;
- if (this.config.type === LIGHT_AND_SHADOW_EFFECT_DESC.type) {
+ if (this.type === LIGHT_AND_SHADOW_EFFECT_DESC.type) {
/** @type {LightingEffect} */
const effect = this.deckEffect;
if (effect) {
- effect.shadowColor = [...normalizeColor(params.shadowColor), params.shadowIntensity];
+ effect.shadowColor = [
+ ...normalizeColor(parameters.shadowColor),
+ parameters.shadowIntensity
+ ];
- effect.ambientLight.intensity = params.ambientLightIntensity;
- effect.ambientLight.color = params.ambientLightColor.slice();
+ effect.ambientLight.intensity = parameters.ambientLightIntensity;
+ effect.ambientLight.color = parameters.ambientLightColor.slice();
const sunLight = effect.directionalLights[0];
if (sunLight) {
- sunLight.intensity = params.sunLightIntensity;
- sunLight.color = params.sunLightColor.slice();
- sunLight.timestamp = params.timestamp;
+ sunLight.intensity = parameters.sunLightIntensity;
+ sunLight.color = parameters.sunLightColor.slice();
+ sunLight.timestamp = parameters.timestamp;
}
}
}
diff --git a/src/effects/src/post-processing-effect.ts b/src/effects/src/post-processing-effect.ts
index 5b1f6253b..22eb3900b 100644
--- a/src/effects/src/post-processing-effect.ts
+++ b/src/effects/src/post-processing-effect.ts
@@ -17,12 +17,8 @@ import {
hexagonalPixelate
} from '@luma.gl/shadertools';
-import {
- POSTPROCESSING_EFFECTS,
- EFFECT_DESCS,
- DEFAULT_POST_PROCESSING_EFFECT_TYPE
-} from '@kepler.gl/constants';
-import {EffectConfig, EffectParamsPartial} from '@kepler.gl/types';
+import {POSTPROCESSING_EFFECTS, DEFAULT_POST_PROCESSING_EFFECT_TYPE} from '@kepler.gl/constants';
+import {EffectPropsPartial} from '@kepler.gl/types';
import Effect from './effect';
@@ -92,45 +88,38 @@ const POSTPROCESSING_EFFECTS_DESCS = [
class PostProcessingEffect extends Effect {
// deckEffect: PostProcessEffect | LightingEffect | null;
- constructor(props: EffectParamsPartial) {
+ constructor(props: EffectPropsPartial) {
super(props);
}
_initializeEffect() {
- const effectDesc = POSTPROCESSING_EFFECTS_DESCS.find(desc => desc.type === this.config.type);
+ const effectDesc = POSTPROCESSING_EFFECTS_DESCS.find(desc => desc.type === this.type);
if (effectDesc) {
- this.deckEffect = new DeckPostProcessEffect(effectDesc.class, this.config.params);
+ this.deckEffect = new DeckPostProcessEffect(effectDesc.class, this.parameters);
const uniforms = this.deckEffect?.module?.uniforms;
if (uniforms) {
- // get default params
+ // get default parameters
const keys = Object.keys(uniforms);
- const defaultParams = {};
+ const defaultParameters = {};
keys.forEach(key => {
- defaultParams[key] = uniforms[key].value ?? uniforms[key];
+ defaultParameters[key] = uniforms[key].value ?? uniforms[key];
});
- this.config.params = {...defaultParams, ...this.config.params};
+ this.parameters = {...defaultParameters, ...this.parameters};
}
}
}
- _getDefaultEffectConfig(config: Partial<EffectConfig> = {}) {
- const type = config.type || DEFAULT_POST_PROCESSING_EFFECT_TYPE;
- return {
- type,
- name: config.name || EFFECT_DESCS.find(desc => desc.type === type)?.name || 'Effect',
- isEnabled: config.isEnabled ?? true,
- isConfigActive: config.isConfigActive ?? true,
- params: {...(config.params || {})}
- };
+ getDefaultProps(props: EffectPropsPartial = {}) {
+ return super.getDefaultProps({type: DEFAULT_POST_PROCESSING_EFFECT_TYPE, ...props});
}
- updateConfig(config: Partial<EffectConfig>) {
- super.updateConfig(config);
+ setProps(props: EffectPropsPartial) {
+ super.setProps(props);
// any uniform updated?
- if (config.params) {
- this.deckEffect?.setProps(this.config.params);
+ if (props.parameters) {
+ this.deckEffect?.setProps(this.parameters);
}
}
}
diff --git a/src/effects/src/utils.ts b/src/effects/src/utils.ts
index 45533bbdb..d04e0d513 100644
--- a/src/effects/src/utils.ts
+++ b/src/effects/src/utils.ts
@@ -1,11 +1,11 @@
-import {Effect as EffectInterface, EffectParamsPartial} from '@kepler.gl/types';
+import {Effect as EffectInterface, EffectPropsPartial} from '@kepler.gl/types';
import {LIGHT_AND_SHADOW_EFFECT} from '@kepler.gl/constants';
import LightingEffect from './lighting-effect';
import PostProcessEffect from './post-processing-effect';
-export function createDeckEffectFromConfig(params: Partial<EffectParamsPartial>): EffectInterface {
- if (params?.config?.type === LIGHT_AND_SHADOW_EFFECT.type) {
+export function createEffect(params: EffectPropsPartial): EffectInterface {
+ if (params?.type === LIGHT_AND_SHADOW_EFFECT.type) {
return new LightingEffect(params);
} else {
return new PostProcessEffect(params);
diff --git a/src/reducers/src/vis-state-merger.ts b/src/reducers/src/vis-state-merger.ts
index e8abdf618..c7d7c52ec 100644
--- a/src/reducers/src/vis-state-merger.ts
+++ b/src/reducers/src/vis-state-merger.ts
@@ -32,7 +32,7 @@ import {
import {getLayerOrderFromLayers} from '@kepler.gl/reducers';
import {LayerColumns, LayerColumn, Layer} from '@kepler.gl/layers';
-import {createDeckEffectFromConfig} from '@kepler.gl/effects';
+import {createEffect} from '@kepler.gl/effects';
import {LAYER_BLENDINGS, OVERLAY_BLENDINGS} from '@kepler.gl/constants';
import {CURRENT_VERSION, VisState, VisStateMergers, KeplerGLSchemaClass} from '@kepler.gl/schemas';
@@ -479,12 +479,19 @@ export function mergeEffects<S extends VisState>(
const newEffects = [
...state.effects,
...(effects || [])
- .map(effect =>
- fromConfig
- ? // collapse all panels when loading effects
- createDeckEffectFromConfig(deepmerge(effect, {config: {isConfigActive: false}}))
- : (effect as EffectType)
- )
+ .map(effect => {
+ return fromConfig
+ ? createEffect(
+ deepmerge.all([
+ effect,
+ {
+ // collapse all panels when loading effects
+ isConfigActive: false
+ }
+ ])
+ )
+ : (effect as EffectType);
+ })
.filter(effect => {
return Boolean(effect && effect.isValidToSave());
})
diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts
index 98906d9c7..ace0130a7 100644
--- a/src/reducers/src/vis-state-updaters.ts
+++ b/src/reducers/src/vis-state-updaters.ts
@@ -127,7 +127,7 @@ import {findFieldsToShow} from './interaction-utils';
import {hasPropsToMerge, getPropValueToMerger} from './merger-handler';
import {mergeDatasetsByOrder} from './vis-state-merger';
import {fixEffectOrder} from '@kepler.gl/utils';
-import {createDeckEffectFromConfig} from '@kepler.gl/effects';
+import {createEffect} from '@kepler.gl/effects';
// react-palm
// disable capture exception for react-palm call to withTask
@@ -1449,10 +1449,10 @@ export const addEffectUpdater = (
state: VisState,
action: VisStateActions.AddEffectUpdaterAction
): VisState => {
- const newEffect = createDeckEffectFromConfig(action.config);
+ const newEffect = createEffect(action.config);
// collapse configurators for other effects
- state.effects.forEach(effect => effect.updateConfig({isConfigActive: false}));
+ state.effects.forEach(effect => effect.setProps({isConfigActive: false}));
const effects = [...state.effects, newEffect];
const effectOrder = fixEffectOrder(effects, [newEffect.id, ...state.effectOrder]);
@@ -1518,7 +1518,7 @@ export const updateEffectUpdater = (
}
const newEffects = [...state.effects];
- newEffects[idx].updateConfig(props);
+ newEffects[idx].setProps(props);
return {
...state,
diff --git a/src/schemas/src/vis-state-schema.ts b/src/schemas/src/vis-state-schema.ts
index 93dafbd24..7fe43a362 100644
--- a/src/schemas/src/vis-state-schema.ts
+++ b/src/schemas/src/vis-state-schema.ts
@@ -787,15 +787,9 @@ export class SplitMapsSchema extends Schema {
export const effectPropsV1 = {
id: null,
- config: new Schema({
- version: VERSIONS.v1,
- key: 'config',
- properties: {
- type: null,
- isEnabled: null,
- params: null
- }
- })
+ type: null,
+ isEnabled: null,
+ parameters: null
};
export class EffectsSchema extends Schema {
key = 'effects';
@@ -820,7 +814,17 @@ export class EffectsSchema extends Schema {
load(effects) {
return {
- [this.key]: effects.map(effect => this.loadPropertiesOrApplySchema(effect, effects).effects)
+ [this.key]: effects.map(effect => {
+ // handle older configs
+ const outEffect = effect.config
+ ? {
+ id: effect.id,
+ ...effect.config,
+ parameters: {...(effect.config.params || {})}
+ }
+ : effect;
+ return this.loadPropertiesOrApplySchema(outEffect, effects).effects;
+ })
};
}
}
diff --git a/src/types/effects.d.ts b/src/types/effects.d.ts
index 3b351a848..e57e3490c 100644
--- a/src/types/effects.d.ts
+++ b/src/types/effects.d.ts
@@ -1,29 +1,27 @@
-export type EffectConfig = {
- type: string;
- name: string;
+export type EffectUpdateProps = {
isEnabled: boolean;
isConfigActive: boolean;
- // effect specific params for a deck.gl effect (uniforms)
- params: {[key: string]: any};
+ // effect specific parameters for a deck.gl effect (uniforms)
+ parameters: {[key: string]: any};
};
-export type EffectParams = {
+export type EffectProps = EffectUpdateProps & {
id: string;
- config: EffectConfig;
+ type: string;
};
-export type EffectParamsPartial = {
- id?: string;
- config?: Partial<EffectConfig>
-};
+export type EffectPropsPartial = Partial<EffectProps>;
export interface Effect {
id: string;
- config: EffectConfig;
+ type: string;
+ isEnabled: boolean;
+ isConfigActive: boolean;
+ // effect specific parameters for a deck.gl effect (uniforms)
+ parameters: {[key: string]: any};
deckEffect: any;
- _getDefaultEffectConfig(config: Partial<EffectConfig>): EffectConfig;
- updateConfig(config: Partial<EffectConfig>): void;
+ getDefaultProps(props: Partial<EffectProps>): EffectProps;
+ setProps(props: Partial<EffectProps>): void;
isValidToSave(): boolean;
- get type(): string;
}
diff --git a/src/types/schemas.d.ts b/src/types/schemas.d.ts
index 8570099d6..9154810ed 100644
--- a/src/types/schemas.d.ts
+++ b/src/types/schemas.d.ts
@@ -11,8 +11,6 @@ import {
import {LayerTextLabel} from './layers';
-import {EffectConfig} from './effects';
-
export type SavedFilter = {
dataId: Filter['dataId'];
id: Filter['id'];
@@ -82,11 +80,9 @@ export type ParsedLayer = SavedLayer | MinSavedLayer;
export type ParsedEffect = {
id: string;
- config: {
- type: string;
- isEnabled: boolean;
- params: Record<string, number | number[] | {value: number}>;
- };
+ type: string;
+ isEnabled: boolean;
+ parameters: Record<string, number | [number, number] | {value: number}>;
};
export type SavedEffect = ParsedEffect;
diff --git a/src/utils/src/effect-utils.ts b/src/utils/src/effect-utils.ts
index 89fb0ffcc..f311d2b30 100644
--- a/src/utils/src/effect-utils.ts
+++ b/src/utils/src/effect-utils.ts
@@ -25,7 +25,7 @@ export function computeDeckEffects({
.map(effectId => {
return findById(effectId)(visState.effects);
})
- .filter(effect => Boolean(effect && effect.config.isEnabled && effect.deckEffect)) as Effect[];
+ .filter(effect => Boolean(effect && effect.isEnabled && effect.deckEffect)) as Effect[];
return effects.map(effect => {
updateEffect({visState, mapState, effect});
@@ -76,7 +76,7 @@ function isDaytime(lat, lon, timestamp) {
*/
function updateEffect({visState, mapState, effect}) {
if (effect.type === LIGHT_AND_SHADOW_EFFECT.type) {
- let {timestamp, timeMode} = effect.config.params;
+ let {timestamp, timeMode} = effect.parameters;
const sunLight = effect.deckEffect.directionalLights[0];
// set timestamp for shadow
@@ -101,7 +101,7 @@ function updateEffect({visState, mapState, effect}) {
// output uniform shadow during nighttime
if (isDaytime(mapState.latitude, mapState.longitude, timestamp)) {
effect.deckEffect.outputUniformShadow = false;
- sunLight.intensity = effect.config.params.sunLightIntensity;
+ sunLight.intensity = effect.parameters.sunLightIntensity;
} else {
effect.deckEffect.outputUniformShadow = true;
sunLight.intensity = 0;
diff --git a/test/browser/components/effects/effect-configurator-test.js b/test/browser/components/effects/effect-configurator-test.js
index f7471c8bd..4bad461a7 100644
--- a/test/browser/components/effects/effect-configurator-test.js
+++ b/test/browser/components/effects/effect-configurator-test.js
@@ -73,7 +73,7 @@ test('Components -> EffectConfigurator -> render -> light & shadow effect', t =>
let nextState = visStateReducer(
InitialState.visState,
VisStateActions.addEffect({
- config: {type: 'lightAndShadow'}
+ type: 'lightAndShadow'
})
);
diff --git a/test/browser/components/effects/effect-manager-test.js b/test/browser/components/effects/effect-manager-test.js
index 737f57fe9..830dfdec5 100644
--- a/test/browser/components/effects/effect-manager-test.js
+++ b/test/browser/components/effects/effect-manager-test.js
@@ -71,7 +71,7 @@ test('Components -> EffectManager -> render', t => {
t.equal(wrapper.find(EffectList).length, 1, 'should render EffectList');
t.equal(wrapper.find(SidePanelTitle).length, 1, 'should render SidePanelTitle');
t.equal(wrapper.find(EffectTypeSelector).length, 1, 'should render EffectTypeSelector');
- t.equal(wrapper.find('EffectPanel').length, 3, 'should render 3 EffectPanels');
+ t.equal(wrapper.find('EffectPanel').length, 4, 'should render 3 EffectPanels');
t.end();
});
diff --git a/test/browser/components/hooks/use-dnd-effects.spec.js b/test/browser/components/hooks/use-dnd-effects.spec.js
index e2f5627f4..709453b20 100644
--- a/test/browser/components/hooks/use-dnd-effects.spec.js
+++ b/test/browser/components/hooks/use-dnd-effects.spec.js
@@ -46,9 +46,9 @@ jest.mock('@kepler.gl/utils', () => ({
describe('useDndEffects', () => {
const effects = [
- {id: 1, name: 'Effect 1', config: {isConfigActive: false}},
- {id: 2, name: 'Effect 2', config: {isConfigActive: false}},
- {id: 3, name: 'Effect 3', config: {isConfigActive: false}}
+ {id: 1, isConfigActive: false},
+ {id: 2, isConfigActive: false},
+ {id: 3, isConfigActive: false}
];
const effectOrder = [2, 1, 3];
@@ -77,9 +77,9 @@ describe('useDndEffects', () => {
test('onDragStart should update activeEffect and dispatch updateEffect if config is active', () => {
const currentEffects = [
- {id: 1, name: 'Effect 1', config: {isConfigActive: false}},
- {id: 2, name: 'Effect 2', config: {isConfigActive: true}},
- {id: 3, name: 'Effect 3', config: {isConfigActive: false}}
+ {id: 1, isConfigActive: false},
+ {id: 2, isConfigActive: true},
+ {id: 3, isConfigActive: false}
];
const {result} = renderHook(() => useDndEffects(currentEffects, effectOrder));
diff --git a/test/helpers/comparison-utils.js b/test/helpers/comparison-utils.js
index 023da33ea..963dcfd47 100644
--- a/test/helpers/comparison-utils.js
+++ b/test/helpers/comparison-utils.js
@@ -217,29 +217,22 @@ export function cmpEffects(t, expectedEffect, actualEffect, opts = {}) {
t.equal(actualEffect.id, expectedEffect.id, `${actualEffect.type} effect.id should be same`);
}
- cmpObjectKeys(
- t,
- expectedEffect.config,
- actualEffect.config,
- `${actualEffect.type} effect.config`
- );
-
- Object.keys(expectedEffect.config).forEach(key => {
+ Object.keys(expectedEffect).forEach(key => {
// test everything except id, which can be auto generated
switch (key) {
- case 'params':
+ case 'parameters':
t.deepEqual(
- actualEffect.config[key],
- expectedEffect.config[key],
- `${actualEffect.type} effect.config.${key} values should be identical`
+ actualEffect[key],
+ expectedEffect[key],
+ `${actualEffect.type} effect.${key} values should be identical`
);
break;
default:
- if (typeof expectedEffect.config[key] !== 'function') {
+ if (typeof expectedEffect[key] !== 'function') {
t.deepEqual(
- actualEffect.config[key],
- expectedEffect.config[key],
- `${actualEffect.type} effect.config.${key} should be correct`
+ actualEffect[key],
+ expectedEffect[key],
+ `${actualEffect.type} effect.${key} should be correct`
);
}
}
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index 3fd65545a..e7a37afaf 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -258,11 +258,15 @@ function mockStateWithEffects() {
},
{
action: VisStateActions.addEffect,
- payload: [{id: 'e_2', config: {type: 'sepia'}}]
+ payload: [{id: 'e_2', type: 'sepia'}]
},
{
action: VisStateActions.addEffect,
- payload: [{id: 'e_3', config: {type: 'magnify'}}]
+ payload: [{id: 'e_3', type: 'magnify'}]
+ },
+ {
+ action: VisStateActions.addEffect,
+ payload: [{id: 'e_4', type: 'lightAndShadow', parameters: {timestamp: 100}}]
}
]);
return prepareState;
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index 3f34f9053..f800d1999 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -25,6 +25,7 @@ import Task, {withTask, drainTasksForTesting, succeedTaskInTest} from 'react-pal
import keplerGlReducer, {
mergeFilters,
mergeLayers,
+ mergeEffects,
mergeInteractions,
mergeLayerBlending,
mergeSplitMaps,
@@ -88,6 +89,7 @@ import {cmpFilters, cmpLayers, cmpDatasets} from 'test/helpers/comparison-utils'
import {
InitialState,
StateWFilters,
+ StateWEffects,
StateWMultiFilters,
StateWFilesFiltersLayerColor,
StateWSplitMaps,
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index b3bbd8242..2beb13acc 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -5494,13 +5494,10 @@ test('#VisStateUpdater -> addEffect', t => {
t.equal(nextState.effects.length, 1, 'should add a default effect');
const expectedEffect = {
- config: {
- type: 'ink',
- name: 'Ink',
- isEnabled: true,
- isConfigActive: true,
- params: {strength: 0.25}
- }
+ type: 'ink',
+ isEnabled: true,
+ isConfigActive: true,
+ parameters: {strength: 0.25}
};
cmpEffects(t, expectedEffect, nextState.effects[0]);
@@ -5509,7 +5506,8 @@ test('#VisStateUpdater -> addEffect', t => {
nextState,
VisStateActions.addEffect({
id: 'e_shadow',
- config: {type: 'lightAndShadow', params: {timestamp: 1689280466362}}
+ type: 'lightAndShadow',
+ parameters: {timestamp: 1689280466362}
})
);
@@ -5517,30 +5515,27 @@ test('#VisStateUpdater -> addEffect', t => {
const expectedEffect2 = {
id: 'e_shadow',
- config: {
- isConfigActive: true,
- isEnabled: true,
- name: 'Light & Shadow',
- params: {
- timestamp: 1689280466362,
- timeMode: 'pick',
- shadowIntensity: 0.5,
- shadowColor: [0, 0, 0],
- sunLightColor: [255, 255, 255],
- sunLightIntensity: 1,
- ambientLightColor: [255, 255, 255],
- ambientLightIntensity: 1
- },
- type: 'lightAndShadow'
+ type: 'lightAndShadow',
+ isConfigActive: true,
+ isEnabled: true,
+ parameters: {
+ timestamp: 1689280466362,
+ timeMode: 'pick',
+ shadowIntensity: 0.5,
+ shadowColor: [0, 0, 0],
+ sunLightColor: [255, 255, 255],
+ sunLightIntensity: 1,
+ ambientLightColor: [255, 255, 255],
+ ambientLightIntensity: 1
}
};
cmpEffects(t, expectedEffect2, nextState.effects[1], {id: true});
t.equal(
- nextState.effects[0].config.isConfigActive,
+ nextState.effects[0].isConfigActive,
false,
- "first effect's config should be collapsed"
+ "first effect's configurator should be collapsed"
);
nextState = reducer(nextState, VisStateActions.addEffect({}));
@@ -5560,18 +5555,15 @@ test('#VisStateUpdater -> updateEffect', t => {
const expectedEffect = {
id: 'e_1',
- config: {
- type: 'ink',
- name: 'changed name',
- isEnabled: false,
- isConfigActive: false,
- params: {
- strength: 0.06
- }
+ type: 'ink',
+ isEnabled: false,
+ isConfigActive: false,
+ parameters: {
+ strength: 0.06
}
};
- nextState = reducer(nextState, VisStateActions.updateEffect('e_1', expectedEffect.config));
+ nextState = reducer(nextState, VisStateActions.updateEffect('e_1', expectedEffect));
cmpEffects(t, expectedEffect, nextState.effects[0], {id: true});
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index 5c6a0a3a9..a63d50058 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -345,27 +345,44 @@ test('visStateSchema -> saving with a null column value does not throw an error'
test('#visStateSchema -> v1 -> save load effects', t => {
const expectedEffects = [
+ {
+ id: 'e_4',
+ type: 'lightAndShadow',
+ isEnabled: true,
+ parameters: {
+ timestamp: 100,
+ timeMode: 'pick',
+ shadowIntensity: 0.5,
+ shadowColor: [0, 0, 0],
+ sunLightColor: [255, 255, 255],
+ sunLightIntensity: 1,
+ ambientLightColor: [255, 255, 255],
+ ambientLightIntensity: 1
+ }
+ },
{
id: 'e_3',
- config: {
- type: 'magnify',
- isEnabled: true,
- params: {
- screenXY: [0, 0],
- radiusPixels: 200,
- zoom: 2,
- borderWidthPixels: 0,
- borderColor: [255, 255, 255, 255]
- }
+ type: 'magnify',
+ isEnabled: true,
+ parameters: {
+ screenXY: [0, 0],
+ radiusPixels: 200,
+ zoom: 2,
+ borderWidthPixels: 0,
+ borderColor: [255, 255, 255, 255]
}
},
{
id: 'e_2',
- config: {type: 'sepia', isEnabled: true, params: {amount: 0.5}}
+ type: 'sepia',
+ isEnabled: true,
+ parameters: {amount: 0.5}
},
{
id: 'e_1',
- config: {type: 'ink', isEnabled: true, params: {strength: 0.25}}
+ type: 'ink',
+ isEnabled: true,
+ parameters: {strength: 0.25}
}
];
@@ -382,3 +399,54 @@ test('#visStateSchema -> v1 -> save load effects', t => {
t.end();
});
+
+test('#visStateSchema -> v1 -> save load effects (deprecated beta config)', t => {
+ const deprecatedEffects = [
+ {
+ id: 'e_5',
+ config: {
+ type: 'magnify',
+ name: 'Magnify',
+ isEnabled: false,
+ isConfigActive: true,
+ params: {
+ screenXY: [0, 0],
+ radiusPixels: 200,
+ zoom: 2,
+ borderWidthPixels: 0,
+ borderColor: [255, 255, 255, 255]
+ }
+ }
+ }
+ ];
+
+ const expectedLoadedEffects = [
+ {
+ id: 'e_5',
+ type: 'magnify',
+ isEnabled: false,
+ parameters: {
+ screenXY: [0, 0],
+ radiusPixels: 200,
+ zoom: 2,
+ borderWidthPixels: 0,
+ borderColor: [255, 255, 255, 255]
+ }
+ }
+ ];
+
+ const initialState = cloneDeep(StateWEffects);
+ const deprecatedSavedState = SchemaManager.getConfigToSave(initialState);
+ deprecatedSavedState.config.visState.effects = deprecatedEffects;
+ deprecatedSavedState.config.visState.effectOrder = [deprecatedEffects[0].id];
+
+ const loadedState = SchemaManager.parseSavedConfig(deprecatedSavedState);
+
+ t.deepEqual(
+ loadedState.visState.effects,
+ expectedLoadedEffects,
+ 'Effects should be loaded as expected'
+ );
+
+ t.end();
+});
diff --git a/test/node/utils/effect-utils-test.js b/test/node/utils/effect-utils-test.js
index b7a014cc1..faa086702 100644
--- a/test/node/utils/effect-utils-test.js
+++ b/test/node/utils/effect-utils-test.js
@@ -24,7 +24,12 @@ import test from 'tape';
import {computeDeckEffects} from '@kepler.gl/utils';
import {VisStateActions} from '@kepler.gl/actions';
import {visStateReducer} from '@kepler.gl/reducers';
-import {createDeckEffectFromConfig} from '@kepler.gl/effects';
+import {createEffect} from '@kepler.gl/effects';
+import {
+ POSTPROCESSING_EFFECTS,
+ LIGHT_AND_SHADOW_EFFECT,
+ DEFAULT_POST_PROCESSING_EFFECT_TYPE
+} from '@kepler.gl/constants';
import {InitialState} from 'test/helpers/mock-state';
@@ -32,17 +37,15 @@ test('effectUtils -> computeDeckEffects', t => {
const initialState = InitialState.visState;
let nextState = visStateReducer(
initialState,
- VisStateActions.addEffect({id: 'e_1', config: {type: 'sepia', isEnabled: false}})
- );
- nextState = visStateReducer(
- initialState,
- VisStateActions.addEffect({id: 'e_1', config: {type: 'ink'}})
+ VisStateActions.addEffect({id: 'e_1', type: 'sepia', isEnabled: false})
);
+ nextState = visStateReducer(initialState, VisStateActions.addEffect({id: 'e_1', type: 'ink'}));
nextState = visStateReducer(
nextState,
VisStateActions.addEffect({
id: 'e_shadow',
- config: {type: 'lightAndShadow', params: {timestamp: 1689383452635}}
+ type: 'lightAndShadow',
+ parameters: {timestamp: 1689383452635}
})
);
@@ -60,7 +63,7 @@ test('effectUtils -> computeDeckEffects', t => {
t.equal(deckEffects[0].directionalLights[0].intensity, 0, 'directional light should be disabled');
// daytime
- nextState.effects[1].updateConfig({params: {timestamp: 1689415852635}});
+ nextState.effects[1].setProps({parameters: {timestamp: 1689415852635}});
deckEffects = computeDeckEffects({
visState: nextState,
mapState: {latitude: 51.033105, longitude: 0.348512}
@@ -71,12 +74,24 @@ test('effectUtils -> computeDeckEffects', t => {
t.end();
});
-test('effectUtils -> createDeckEffectFromConfig', t => {
- const ppEffect = createDeckEffectFromConfig({});
- const lasEffect = createDeckEffectFromConfig({config: {type: 'lightAndShadow'}});
+test('effectUtils -> createEffect', t => {
+ const defaultEffect = createEffect({});
+ const postProcessingEffect = createEffect({
+ type: POSTPROCESSING_EFFECTS.hueSaturation.type
+ });
+ const lightEffect = createEffect({type: LIGHT_AND_SHADOW_EFFECT.type});
- t.equal(ppEffect.config.type, 'ink', 'should create default ink effect');
- t.equal(lasEffect.config.type, 'lightAndShadow', 'should create lightAndShadow effect');
+ t.equal(
+ defaultEffect.type,
+ DEFAULT_POST_PROCESSING_EFFECT_TYPE,
+ 'should create default ink effect'
+ );
+ t.equal(
+ postProcessingEffect.type,
+ POSTPROCESSING_EFFECTS.hueSaturation.type,
+ 'should create hueSaturation effect'
+ );
+ t.equal(lightEffect.type, LIGHT_AND_SHADOW_EFFECT.type, 'should create Light&Shadow effect');
t.end();
});