Skip to content

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

[Chore]: Technical: Translate redusers (vis-state) (#1727)

Maksim Suslov0505fda4be87
diff --git a/src/actions/vis-state-actions.ts b/src/actions/vis-state-actions.ts
index bdca4d94f..b6dd8af20 100644
--- a/src/actions/vis-state-actions.ts
+++ b/src/actions/vis-state-actions.ts
@@ -28,7 +28,7 @@ import {ValueOf, Merge, RGBColor} from '../reducers/types';
// TODO - import LoaderObject type from @loaders.gl/core when supported
// TODO - import LoadOptions type from @loaders.gl/core when supported
-type LayerConfigChangeUpdaterAction = {
+export type LayerConfigChangeUpdaterAction = {
oldLayer: Layer;
newConfig: Partial<LayerConfig>;
};
@@ -1003,7 +1003,7 @@ export function loadFileStepSuccess({
};
}
-export type loadFilesErrUpdaterAction = {
+export type LoadFilesErrUpdaterAction = {
fileName: string;
error: any;
};
@@ -1018,7 +1018,7 @@ export type loadFilesErrUpdaterAction = {
export function loadFilesErr(
fileName: string,
error: any
-): Merge<loadFilesErrUpdaterAction, {type: typeof ActionTypes.LOAD_FILES_ERR}> {
+): Merge<LoadFilesErrUpdaterAction, {type: typeof ActionTypes.LOAD_FILES_ERR}> {
return {
type: ActionTypes.LOAD_FILES_ERR,
fileName,
diff --git a/src/layers/index.d.ts b/src/layers/index.d.ts
index 79a3bad4d..5e17f0319 100644
--- a/src/layers/index.d.ts
+++ b/src/layers/index.d.ts
@@ -3,8 +3,9 @@ import {LayerTextLabel, ColorRange, ColorUI, VisConfigRange} from './layer-facto
export {LAYER_VIS_CONFIGS, LayerVisConfig} from './layer-factory';
+export type LayerColumn = {value: string | null; fieldIdx: number; optional?: boolean};
export type LayerColumns = {
- [key: string]: {value: string | null; fieldIdx: number; optional?: boolean};
+ [key: string]: LayerColumn;
};
export type VisualChannelDomain = number[] | string[];
export type VisualChannelField = Field | null;
diff --git a/src/reducers/combined-updaters.ts b/src/reducers/combined-updaters.ts
index 1d64e9cfd..e116cf03a 100644
--- a/src/reducers/combined-updaters.ts
+++ b/src/reducers/combined-updaters.ts
@@ -148,6 +148,7 @@ export const addDataToMapUpdater = (
if (isValidConfig(config)) {
// if passed in saved config
+ // @ts-expect-error
parsedConfig = state.visState.schema.parseSavedConfig(config);
}
const oldLayers = state.visState.layers;
diff --git a/src/reducers/index.d.ts b/src/reducers/index.d.ts
deleted file mode 100644
index d41dbc7e2..000000000
--- a/src/reducers/index.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-// TODO: Delete this file
diff --git a/src/reducers/map-style-updaters.ts b/src/reducers/map-style-updaters.ts
index 344c778a7..76aed0e6a 100644
--- a/src/reducers/map-style-updaters.ts
+++ b/src/reducers/map-style-updaters.ts
@@ -560,9 +560,7 @@ export const inputMapStyleUpdater = (
const icon = isValid
? getStyleImageIcon({
mapState,
- // @ts-expect-error
styleUrl: updated.url,
- // @ts-expect-error
mapboxApiAccessToken: updated.accessToken || state.mapboxApiAccessToken,
mapboxApiUrl: state.mapboxApiUrl || DEFAULT_MAPBOX_API_URL
})
diff --git a/src/reducers/ui-state-updaters.ts b/src/reducers/ui-state-updaters.ts
index 19adbe606..55ace235c 100644
--- a/src/reducers/ui-state-updaters.ts
+++ b/src/reducers/ui-state-updaters.ts
@@ -37,7 +37,7 @@ import {payload_, apply_, compose_} from './composer-helpers';
import ActionTypes from '../constants/action-types';
import * as UiStateActions from 'actions/ui-state-actions';
-import {KeplerGlInitPayload, loadFilesErrUpdaterAction} from '../actions';
+import {KeplerGlInitPayload, LoadFilesErrUpdaterAction} from '../actions';
export type ExportImage = {
ratio: string;
@@ -770,11 +770,9 @@ export const addNotificationUpdater = (
const notificationToUpdate = payloadId ? state.notifications.find(n => n.id === payloadId) : null;
if (notificationToUpdate) {
notifications = state.notifications.map(n =>
- // @ts-expect-error
n.id === payloadId ? createNotification(payload) : n
);
} else {
- // @ts-expect-error
notifications = [...(state.notifications || []), createNotification(payload)];
}
@@ -836,7 +834,7 @@ export const loadFilesSuccessUpdater = (state: UiState): UiState => ({
* @returns nextState
* @public
*/
-export const loadFilesErrUpdater = (state: UiState, {error}: loadFilesErrUpdaterAction): UiState =>
+export const loadFilesErrUpdater = (state: UiState, {error}: LoadFilesErrUpdaterAction): UiState =>
addNotificationUpdater(
{
...state,
diff --git a/src/reducers/vis-state-merger.d.ts b/src/reducers/vis-state-merger.d.ts
deleted file mode 100644
index c19743254..000000000
--- a/src/reducers/vis-state-merger.d.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-import {VisState, Datasets, Dataset} from './vis-state-updaters';
-import {ParsedConfig, ParsedLayer} from 'schemas';
-import {Layer} from 'layers';
-
-export function mergeAnimationConfig(
- state: VisState,
- animation: ParsedConfig['visState']['animationConfig'],
- fromConfig?: boolean
-): VisState;
-export function mergeFilters(
- state: VisState,
- filters: ParsedConfig['visState']['filters'],
- fromConfig?: boolean
-): VisState;
-export function mergeInteractions(
- state: VisState,
- interactionConfig: ParsedConfig['visState']['interactionConfig'],
- fromConfig?: boolean
-): VisState;
-export function mergeLayerBlending(
- state: VisState,
- layerBlending: ParsedConfig['visState']['layerBlending'],
- fromConfig?: boolean
-): VisState;
-export function mergeLayers(
- state: VisState,
- layers: ParsedConfig['visState']['layers'],
- fromConfig?: boolean
-): VisState;
-export function mergeSplitMaps(
- state: VisState,
- splitMaps: ParsedConfig['visState']['splitMaps'],
- fromConfig?: boolean
-): VisState;
-
-export function mergeInteractionTooltipConfig(state: VisState);
-
-export function isValidMerger(arg: any): boolean;
-export type Merger = {
- merge: (state: VisState, config: any, fromConfig?: boolean) => VisState;
- prop: string;
- toMergeProp?: string;
-};
-
-export function validateSavedVisualChannels(
- fields: Dataset['fields'],
- newLayer: Layer,
- savedLayer: ParsedLayer
-): null | Layer;
-
-export function validateLayerWithData(
- dataset: Dataset,
- savedLayer: ParsedLayer,
- layerClasses: VisState['layerClasses'],
- option?: {
- allowEmptyColumn?: boolean;
- }
-): Layer | null;
-
-export function validateLayersByDatasets(
- datasets: Datasets,
- layerClasses: VisState['layerClasses'],
- layers: ParsedConfig['visState']['layers']
-): {validated: Layer[]; failed: ParsedConfig['visState']['layers']};
-
-export function validateColumn(
- // TODO: Better types here
- column: any,
- columns: any[],
- allFields: Dataset['fields']
-): boolean;
-
-export function createLayerFromConfig(state: VisState, layerConfig: any): Layer;
-export function serializeLayer(Layer): ParsedLayer
-
-export type VisStateMergers = Merger[];
-
-export const VIS_STATE_MERGERS: VisStateMergers;
diff --git a/src/reducers/vis-state-merger.js b/src/reducers/vis-state-merger.ts
similarity index 75%
rename from src/reducers/vis-state-merger.js
rename to src/reducers/vis-state-merger.ts
index 17121c378..abc25294e 100644
--- a/src/reducers/vis-state-merger.js
+++ b/src/reducers/vis-state-merger.ts
@@ -29,13 +29,30 @@ import {resetFilterGpuMode, assignGpuChannels} from 'utils/gpu-filter-utils';
import {LAYER_BLENDINGS} from 'constants/default-settings';
import {CURRENT_VERSION, visStateSchema} from 'schemas';
+import {VisState, Datasets} from './vis-state-updaters';
+import {KeplerTable} from 'utils';
+import {ParsedConfig, ParsedLayer} from 'schemas';
+import {Layer, LayerColumns, LayerColumn} from 'layers';
+import {TooltipInfo} from './vis-state-updaters';
+import {SavedInteractionConfig} from 'schemas/schema-manager';
+
+export type Merger = {
+ merge: (state: VisState, config: any, fromConfig?: boolean) => VisState;
+ prop: string;
+ toMergeProp?: string;
+};
+export type VisStateMergers = Merger[];
+
/**
* Merge loaded filters with current state, if no fields or data are loaded
* save it for later
*
- * @type {typeof import('./vis-state-merger').mergeFilters}
*/
-export function mergeFilters(state, filtersToMerge) {
+export function mergeFilters(
+ state: VisState,
+ filtersToMerge: NonNullable<ParsedConfig['visState']>['filters'],
+ fromConfig?: boolean
+): VisState {
if (!Array.isArray(filtersToMerge) || !filtersToMerge.length) {
return state;
}
@@ -64,13 +81,13 @@ export function mergeFilters(state, filtersToMerge) {
};
}
-export function createLayerFromConfig(state, layerConfig) {
+export function createLayerFromConfig(state: VisState, layerConfig: any): Layer | null {
// first validate config against dataset
const {validated, failed} = validateLayersByDatasets(state.datasets, state.layerClasses, [
layerConfig
]);
- if (failed.length || !validated.length) {
+ if (failed?.length || !validated.length) {
// failed
return null;
}
@@ -80,7 +97,7 @@ export function createLayerFromConfig(state, layerConfig) {
return newLayer;
}
-export function serializeLayer(newLayer) {
+export function serializeLayer(newLayer): ParsedLayer {
const savedVisState = visStateSchema[CURRENT_VERSION].save({
layers: [newLayer],
layerOrder: [0]
@@ -93,9 +110,12 @@ export function serializeLayer(newLayer) {
* Merge layers from de-serialized state, if no fields or data are loaded
* save it for later
*
- * @type {typeof import('./vis-state-merger').mergeLayers}
*/
-export function mergeLayers(state, layersToMerge, fromConfig) {
+export function mergeLayers(
+ state: VisState,
+ layersToMerge: NonNullable<ParsedConfig['visState']>['layers'] = [],
+ fromConfig?: boolean
+): VisState {
const preserveLayerOrder = fromConfig ? layersToMerge.map(l => l.id) : state.preserveLayerOrder;
if (!Array.isArray(layersToMerge) || !layersToMerge.length) {
@@ -113,6 +133,7 @@ export function mergeLayers(state, layersToMerge, fromConfig) {
state.layers,
mergedLayer,
state.layerOrder,
+ // @ts-expect-error
preserveLayerOrder
);
@@ -120,6 +141,7 @@ export function mergeLayers(state, layersToMerge, fromConfig) {
...state,
layers: newLayers,
layerOrder: newLayerOrder,
+ // @ts-expect-error
preserveLayerOrder,
layerToBeMerged: [...state.layerToBeMerged, ...unmerged]
};
@@ -129,7 +151,7 @@ export function insertLayerAtRightOrder(
currentLayers,
layersToInsert,
currentOrder,
- preservedOrder = []
+ preservedOrder: string[] = []
) {
// perservedOrder ['a', 'b', 'c'];
// layerOrder [1, 0, 3]
@@ -152,7 +174,9 @@ export function insertLayerAtRightOrder(
preceedIdx = layerOrderQueue.indexOf(preceedLayer);
}
+ // @ts-expect-error
if (preceedIdx > -1) {
+ // @ts-expect-error
insertAt = preceedIdx + 1;
}
}
@@ -173,42 +197,52 @@ export function insertLayerAtRightOrder(
/**
* Merge interactions with saved config
*
- * @type {typeof import('./vis-state-merger').mergeInteractions}
*/
-export function mergeInteractions(state, interactionToBeMerged) {
- const merged = {};
- const unmerged = {};
+export function mergeInteractions(
+ state: VisState,
+ interactionToBeMerged: Partial<SavedInteractionConfig> | undefined,
+ fromConfig?: boolean
+): VisState {
+ const merged: Partial<SavedInteractionConfig> = {};
+ const unmerged: Partial<SavedInteractionConfig> = {};
if (interactionToBeMerged) {
- Object.keys(interactionToBeMerged).forEach(key => {
+ (Object.keys(interactionToBeMerged) as Array<keyof SavedInteractionConfig>).forEach(key => {
if (!state.interactionConfig[key]) {
return;
}
- const currentConfig = state.interactionConfig[key].config;
+ const currentConfig =
+ key === 'tooltip' || key === 'brush' ? state.interactionConfig[key].config : null;
const {enabled, ...configSaved} = interactionToBeMerged[key] || {};
+
let configToMerge = configSaved;
if (key === 'tooltip') {
- const {mergedTooltip, unmergedTooltip} = mergeInteractionTooltipConfig(state, configSaved);
+ const {mergedTooltip, unmergedTooltip} = mergeInteractionTooltipConfig(
+ state,
+ configSaved as SavedInteractionConfig['tooltip']
+ );
// merge new dataset tooltips with original dataset tooltips
configToMerge = {
fieldsToShow: {
- ...currentConfig.fieldsToShow,
+ ...(currentConfig as TooltipInfo['config']).fieldsToShow,
...mergedTooltip
}
};
if (Object.keys(unmergedTooltip).length) {
- unmerged.tooltip = {fieldsToShow: unmergedTooltip, enabled};
+ // @ts-expect-error
+ unmerged.tooltip = {fieldsToShow: unmergedTooltip, enabled: Boolean(enabled)};
}
}
+ // @ts-expect-error
merged[key] = {
...state.interactionConfig[key],
- enabled,
+ enabled: Boolean(enabled),
...(currentConfig
? {
config: pick(
@@ -226,6 +260,7 @@ export function mergeInteractions(state, interactionToBeMerged) {
return {
...state,
+ // @ts-expect-error
interactionConfig: {
...state.interactionConfig,
...merged
@@ -240,9 +275,12 @@ export function mergeInteractions(state, interactionToBeMerged) {
* : don't merge anything
* 2. if current map is NOT split, but splitMaps contain maps
* : add to splitMaps, and add current layers to splitMaps
- * @type {typeof import('./vis-state-merger').mergeInteractions}
*/
-export function mergeSplitMaps(state, splitMaps = []) {
+export function mergeSplitMaps(
+ state: VisState,
+ splitMaps: NonNullable<ParsedConfig['visState']>['splitMaps'] = [],
+ fromConfig?: boolean
+): VisState {
const merged = [...state.splitMaps];
const unmerged = [];
splitMaps.forEach((sm, i) => {
@@ -272,15 +310,22 @@ export function mergeSplitMaps(state, splitMaps = []) {
* Merge interactionConfig.tooltip with saved config,
* validate fieldsToShow
*
- * @param {object} state
- * @param {object} tooltipConfig
- * @return {object} - {mergedTooltip: {}, unmergedTooltip: {}}
+ * @param state
+ * @param tooltipConfig
+ * @return - {mergedTooltip: {}, unmergedTooltip: {}}
*/
-export function mergeInteractionTooltipConfig(state, tooltipConfig = {}) {
- const unmergedTooltip = {};
- const mergedTooltip = {};
-
- if (!tooltipConfig.fieldsToShow || !Object.keys(tooltipConfig.fieldsToShow).length) {
+export function mergeInteractionTooltipConfig(
+ state: VisState,
+ tooltipConfig: Pick<TooltipInfo['config'], 'fieldsToShow'> | null = null
+) {
+ const unmergedTooltip: TooltipInfo['config']['fieldsToShow'] = {};
+ const mergedTooltip: TooltipInfo['config']['fieldsToShow'] = {};
+
+ if (
+ !tooltipConfig ||
+ !tooltipConfig.fieldsToShow ||
+ !Object.keys(tooltipConfig.fieldsToShow).length
+ ) {
return {mergedTooltip, unmergedTooltip};
}
@@ -304,9 +349,12 @@ export function mergeInteractionTooltipConfig(state, tooltipConfig = {}) {
/**
* Merge layerBlending with saved
*
- * @type {typeof import('./vis-state-merger').mergeLayerBlending}
*/
-export function mergeLayerBlending(state, layerBlending) {
+export function mergeLayerBlending(
+ state: VisState,
+ layerBlending: NonNullable<ParsedConfig['visState']>['layerBlending'],
+ fromConfig?: boolean
+): VisState {
if (layerBlending && LAYER_BLENDINGS[layerBlending]) {
return {
...state,
@@ -319,9 +367,12 @@ export function mergeLayerBlending(state, layerBlending) {
/**
* Merge animation config
- * @type {typeof import('./vis-state-merger').mergeAnimationConfig}
*/
-export function mergeAnimationConfig(state, animation) {
+export function mergeAnimationConfig(
+ state: VisState,
+ animation: NonNullable<ParsedConfig['visState']>['animationConfig'],
+ fromConfig?: boolean
+): VisState {
if (animation && animation.currentTime) {
return {
...state,
@@ -340,15 +391,21 @@ export function mergeAnimationConfig(state, animation) {
* Validate saved layer columns with new data,
* update fieldIdx based on new fields
*
- * @param {Array<Object>} fields
- * @param {Object} savedCols
- * @param {Object} emptyCols
- * @return {null | Object} - validated columns or null
+ * @param fields
+ * @param savedCols
+ * @param emptyCols
+ * @return - validated columns or null
*/
-export function validateSavedLayerColumns(fields, savedCols = {}, emptyCols) {
+export function validateSavedLayerColumns(
+ fields: KeplerTable['fields'],
+ savedCols: {
+ [key: string]: string;
+ } = {},
+ emptyCols: LayerColumns
+) {
// Prepare columns for the validator
- const columns = {};
+ const columns: typeof emptyCols = {};
for (const key of Object.keys(emptyCols)) {
columns[key] = {...emptyCols[key]};
@@ -376,7 +433,11 @@ export function validateSavedLayerColumns(fields, savedCols = {}, emptyCols) {
return null;
}
-export function validateColumn(column, columns, allFields) {
+export function validateColumn(
+ column: LayerColumn & {validator?: typeof validateColumn},
+ columns: LayerColumns,
+ allFields: KeplerTable['fields']
+): boolean {
if (column.optional || column.value) {
return true;
}
@@ -418,9 +479,12 @@ export function validateSavedTextLabel(fields, [layerTextLabel], savedTextLabel)
/**
* Validate saved visual channels config with new data,
* refer to vis-state-schema.js VisualChannelSchemaV1
- * @type {typeof import('./vis-state-merger').validateSavedVisualChannels}
*/
-export function validateSavedVisualChannels(fields, newLayer, savedLayer) {
+export function validateSavedVisualChannels(
+ fields: KeplerTable['fields'],
+ newLayer: Layer,
+ savedLayer: ParsedLayer
+): null | Layer {
Object.values(newLayer.visualChannels).forEach(({field, scale, key}) => {
let foundField;
if (savedLayer.config) {
@@ -444,17 +508,22 @@ export function validateSavedVisualChannels(fields, newLayer, savedLayer) {
return newLayer;
}
-export function validateLayersByDatasets(datasets, layerClasses, layers) {
- const validated = [];
- const failed = [];
+export function validateLayersByDatasets(
+ datasets: Datasets,
+ layerClasses: VisState['layerClasses'],
+ layers: NonNullable<ParsedConfig['visState']>['layers'] = []
+) {
+ const validated: Layer[] = [];
+ const failed: NonNullable<ParsedConfig['visState']>['layers'] = [];
layers.forEach(layer => {
- let validateLayer;
- if (!layer || !layer.config) {
- validateLayer = null;
- } else if (datasets[layer.config.dataId]) {
- // datasets are already loaded
- validateLayer = validateLayerWithData(datasets[layer.config.dataId], layer, layerClasses);
+ let validateLayer: Layer | null = null;
+
+ if (layer?.config?.dataId) {
+ if (datasets[layer.config.dataId]) {
+ // datasets are already loaded
+ validateLayer = validateLayerWithData(datasets[layer.config.dataId], layer, layerClasses);
+ }
}
if (validateLayer) {
@@ -470,14 +539,15 @@ export function validateLayersByDatasets(datasets, layerClasses, layers) {
/**
* Validate saved layer config with new data,
* update fieldIdx based on new fields
- * @type {typeof import('./vis-state-merger').validateLayerWithData}
*/
export function validateLayerWithData(
- {fields, id: dataId},
- savedLayer,
- layerClasses,
- options = {}
-) {
+ {fields, id: dataId}: KeplerTable,
+ savedLayer: ParsedLayer,
+ layerClasses: VisState['layerClasses'],
+ options: {
+ allowEmptyColumn?: boolean;
+ } = {}
+): Layer | null {
const {type} = savedLayer;
// layer doesnt have a valid type
if (!type || !layerClasses.hasOwnProperty(type) || !savedLayer.config) {
@@ -530,11 +600,11 @@ export function validateLayerWithData(
return newLayer;
}
-export function isValidMerger(merger) {
+export function isValidMerger(merger: Merger): boolean {
return isObject(merger) && typeof merger.merge === 'function' && typeof merger.prop === 'string';
}
-export const VIS_STATE_MERGERS = [
+export const VIS_STATE_MERGERS: VisStateMergers = [
{merge: mergeLayers, prop: 'layers', toMergeProp: 'layerToBeMerged'},
{merge: mergeFilters, prop: 'filters', toMergeProp: 'filterToBeMerged'},
{merge: mergeInteractions, prop: 'interactionConfig', toMergeProp: 'interactionToBeMerged'},
diff --git a/src/reducers/vis-state-selectors.js b/src/reducers/vis-state-selectors.ts
similarity index 97%
rename from src/reducers/vis-state-selectors.js
rename to src/reducers/vis-state-selectors.ts
index 4312f8041..a546a1d32 100644
--- a/src/reducers/vis-state-selectors.js
+++ b/src/reducers/vis-state-selectors.ts
@@ -25,11 +25,13 @@ const DEFAULT_FILE_EXTENSIONS = ['csv', 'json', 'geojson'];
const DEFAULT_FILE_FORMATS = ['CSV', 'Json', 'GeoJSON'];
export const getFileFormatNames = createSelector(
+ // @ts-expect-error
state => state.loaders,
loaders => [...DEFAULT_FILE_FORMATS, ...loaders.map(loader => loader.name)]
);
export const getFileExtensions = createSelector(
+ // @ts-expect-error
state => state.loaders,
loaders => [...DEFAULT_FILE_EXTENSIONS, ...loaders.flatMap(loader => loader.extensions)]
);
diff --git a/src/reducers/vis-state-updaters.d.ts b/src/reducers/vis-state-updaters.d.ts
deleted file mode 100644
index 3f18eefab..000000000
--- a/src/reducers/vis-state-updaters.d.ts
+++ /dev/null
@@ -1,541 +0,0 @@
-import {RGBColor, RGBAColor, Millisecond} from './types';
-import {AddDataToMapOptions, ReceiveMapConfigPayload} from '../actions/actions';
-import {ParsedConfig} from 'schemas';
-import * as VisStateActions from 'actions/vis-state-actions';
-import ActionTypes from 'constants/action-types';
-import {LoaderObject} from '@loaders.gl/loader-utils';
-import {KeplerTable, Field} from 'utils';
-
-export {KeplerTable, Field};
-export type HistogramBin = {
- x0: number | undefined;
- x1: number | undefined;
- count: number;
-};
-
-export type RangeFieldDomain = {
- domain: [number, number];
- step: number;
- histogram: HistogramBin[];
- enlargedHistogram: HistogramBin[];
-};
-
-export type SelectFieldDomain = {
- domain: [true, false];
-};
-export type MultiSelectFieldDomain = {
- domain: string[];
-};
-
-export type TimeRangeFieldDomain = {
- domain: [number, number];
- step: number;
- histogram: HistogramBin[];
- enlargedHistogram: HistogramBin[];
- mappedValue: (Millisecond | null)[];
- // auto generated based on time domain
- defaultTimeFormat?: string | null;
- // custom ui input
- timeFormat?: string | null;
- // custom ui input
- timezone?: string | null;
-};
-export type FieldDomain =
- | RangeFieldDomain
- | TimeRangeFieldDomain
- | SelectFieldDomain
- | MultiSelectFieldDomain;
-
-export type LineChart = {
- series: {x: number; y: number}[];
- yDomain: [number, number];
- xDomain: [number, number];
-};
-
-export type FilterBase = {
- dataId: string[];
- id: string;
-
- freeze: boolean;
-
- // time range filter specific
- fixedDomain: boolean;
- enlarged: boolean;
- isAnimating: boolean;
- speed: number;
- showTimeDisplay?: boolean;
-
- // field specific
- name: string[]; // string
- type: string | null;
- fieldIdx: number[]; // [integer]
- domain: any[] | null;
- value: any;
- mappedValue?: number[];
-
- // plot
- yAxis: Field | null;
- plotType: string;
- lineChart?: LineChart;
- // gpu filter
- gpu: boolean;
- gpuChannel?: number[];
- fieldType?: string;
-
- // polygon
- layerId?: string[];
-};
-
-export type RangeFilter = FilterBase &
- RangeFieldDomain & {
- type: 'range';
- fieldType: 'real' | 'integer';
- value: [number, number];
- fixedDomain: true;
- typeOptions: ['range'];
- };
-
-export type SelectFilter = FilterBase &
- SelectFieldDomain & {
- type: 'select';
- fieldType: 'boolean';
- value: boolean;
- };
-
-export type MultiSelectFilter = FilterBase &
- MultiSelectFieldDomain & {
- type: 'range';
- fieldType: 'string' | 'date';
- value: string[];
- };
-export type TimeRangeFilter = FilterBase &
- TimeRangeFieldDomain & {
- type: 'timeRange';
- fieldType: 'timestamp';
- fixedDomain: true;
- value: [number, number];
- bins?: Object;
- plotType: {
- [key: string]: any;
- };
- };
-
-export type PolygonFilter = FilterBase & {
- layerId: string[];
- type: 'polygon';
- fixedDomain: true;
- value: Feature;
-};
-
-export type Filter =
- | FilterBase
- | RangeFilter
- | TimeRangeFilter
- | SelectFilter
- | MultiSelectFilter
- | PolygonFilter;
-
-export type Datasets = {
- [key: string]: KeplerTable;
-};
-
-export type Feature = {
- id: string;
- properties: any;
- geometry: {
- type: string;
- coordinates: any;
- };
-};
-export type FeatureValue = {
- id: string;
- properties: {
- filterId: string;
- };
- geometry: {
- type: string;
- coordinates: any;
- };
-};
-export type Editor = {
- mode: string;
- features: Feature[];
- selectedFeature: any;
- visible: boolean;
-};
-
-export type SplitMapLayers = {[key: string]: boolean};
-export type SplitMap = {
- layers: SplitMapLayers;
-};
-export type AnimationConfig = {
- domain: number[] | null;
- currentTime: number | null;
- speed: number;
- isAnimating?: boolean;
- // auto generated based on time domain
- defaultTimeFormat?: string | null;
- // custom ui input
- timeFormat?: string | null;
- // custom ui input
- timezone?: string | null;
- // hide or show control
- hideControl?: boolean;
-};
-
-export type BaseInteraction = {
- id: string;
- label: string;
- enabled: boolean;
- iconComponent: any;
-};
-export type TooltipField = {
- name: string;
- format: string | null;
-};
-export type CompareType = string | null;
-export type TooltipInfo = BaseInteraction & {
- config: {
- fieldsToShow: {
- [key: string]: TooltipField[];
- };
- compareMode: boolean;
- compareType: CompareType;
- };
-};
-export type Geocoder = BaseInteraction & {
- position: number[] | null;
-};
-export type Brush = BaseInteraction & {
- config: {
- size: number;
- };
-};
-export type Coordinate = BaseInteraction & {
- position: number[] | null;
-};
-export type InteractionConfig = {
- tooltip: TooltipInfo;
- geocoder: Geocoder;
- brush: Brush;
- coordinate: Coordinate;
-};
-export type MapInfo = {
- title: string;
- description: string;
-};
-export type FileLoading = {
- filesToLoad: FileList;
- onFinish: (payload: any) => any;
- fileCache: any[];
-};
-export type FileLoadingProgress = {
- [key: string]: {
- percent: number;
- message: string;
- fileName: string;
- error: any;
- };
-};
-
-export type VisState = {
- mapInfo: MapInfo;
- layers: Layer[];
- layerData: any[];
- layerToBeMerged: any[];
- layerOrder: number[];
- filters: Filter[];
- filterToBeMerged: any[];
- datasets: Datasets;
- editingDataset: string | undefined;
- interactionConfig: InteractionConfig;
- interactionToBeMerged: any;
- layerBlending: string;
- hoverInfo: any;
- clicked: any;
- mousePos: any;
- maxDefaultTooltips: number;
- layerClasses: LayerClassesType;
- animationConfig: AnimationConfig;
- editor: Editor;
- splitMaps: SplitMap[];
- splitMapsToBeMerged: SplitMap[];
- fileLoading: FileLoading | false;
- fileLoadingProgress: FileLoadingProgress;
- loaders: LoaderObject[];
- loadOptions: object;
- initialState?: Partial<VisState>;
- mergers: VisStateMergers;
- schema: KeplerGLSchema;
- preserveLayerOrder?: number[];
-};
-
-export function addDefaultLayers(
- state: VisState,
- datasets: Datasets
-): {state: VisState; newLayers: Layer[]};
-export function updateAllLayerDomainData(
- state: VisState,
- dataId: string | string[],
- updatedFilter?: Filter
-): VisState;
-
-export function updateStateWithLayerAndData(
- state: VisState,
- data: {layerData?: any; layer: Layer; idx: number}
-): VisState;
-
-export function layerConfigChangeUpdater(
- state: VisState,
- action: VisStateActions.LayerConfigChangeUpdaterAction
-): VisState;
-export function layerTextLabelChangeUpdater(
- state: VisState,
- action: VisStateActions.LayerTextLabelChangeUpdaterAction
-): VisState;
-export function layerDataIdChangeUpdater(
- state: VisState,
- action: {
- oldLayer: Layer;
- newConfig: {
- dataId: string;
- };
- }
-): VisState;
-export function layerTypeChangeUpdater(
- state: VisState,
- action: VisStateActions.LayerTypeChangeUpdaterAction
-): VisState;
-export function layerVisualChannelChangeUpdater(
- state: VisState,
- action: VisStateActions.LayerVisualChannelConfigChangeUpdaterAction
-): VisState;
-export function layerVisConfigChangeUpdater(
- state: VisState,
- action: VisStateActions.LayerVisConfigChangeUpdaterAction
-): VisState;
-export function layerColorUIChangeUpdater(
- state: VisState,
- action: VisStateActions.LayerColorUIChangeUpdaterAction
-): VisState;
-export function updateLayerBlendingUpdater(
- state: VisState,
- action: VisStateActions.UpdateLayerBlendingUpdaterAction
-): VisState;
-export function toggleLayerAnimationUpdater(
- state: VisState,
- action: VisStateActions.ToggleLayerAnimationUpdaterAction
-): VisState;
-export function toggleLayerAnimationControlUpdater(
- state: VisState,
- action: VisStateActions.ToggleLayerAnimationControlUpdaterAction
-): VisState;
-export function interactionConfigChangeUpdater(
- state: VisState,
- action: VisStateActions.InteractionConfigChangeUpdaterAction
-): VisState;
-export function setFilterUpdater(
- state: VisState,
- action: VisStateActions.SetFilterUpdaterAction
-): VisState;
-export function setFilterAnimationTimeUpdater(
- state: VisState,
- action: VisStateActions.setFilterAnimationTimeUpdaterAction
-): VisState;
-export function setFilterAnimationWindowUpdater(
- state: VisState,
- action: VisStateActions.setFilterAnimationWindowUpdaterAction
-): VisState;
-export function addFilterUpdater(
- state: VisState,
- action: VisStateActions.AddFilterUpdaterAction
-): VisState;
-export function addLayerUpdater(
- state: VisState,
- action: VisStateActions.AddLayerUpdaterAction
-): VisState;
-export function reorderLayerUpdater(
- state: VisState,
- action: VisStateActions.ReorderLayerUpdaterAction
-): VisState;
-export function removeFilterUpdater(
- state: VisState,
- action: VisStateActions.RemoveFilterUpdaterAction
-): VisState;
-export function removeLayerUpdater(
- state: VisState,
- action: VisStateActions.RemoveLayerUpdaterAction
-): VisState;
-export function duplicateLayerUpdater(
- state: VisState,
- action: VisStateActions.DuplicateLayerUpdaterAction
-): VisState;
-export function removeDatasetUpdater(
- state: VisState,
- action: VisStateActions.RemoveDatasetUpdaterAction
-): VisState;
-export function showDatasetTableUpdater(
- state: VisState,
- action: VisStateActions.ShowDatasetTableUpdaterAction
-): VisState;
-export function updateTableColorUpdater(
- state: VisState,
- action: VisStateActions.UpdateDatasetColorUpdater
-): VisState;
-export function sortTableColumnUpdater(
- state: VisState,
- action: VisStateActions.SortTableColumnUpdaterAction
-): VisState;
-export function pinTableColumnUpdater(
- state: VisState,
- action: VisStateActions.PinTableColumnUpdaterAction
-): VisState;
-export function copyTableColumnUpdater(
- state: VisState,
- action: VisStateActions.CopyTableColumnUpdaterAction
-): VisState;
-export function updateVisDataUpdater(
- state: VisState,
- action: VisStateActions.UpdateVisDataUpdaterAction
-): VisState;
-export function renameDatasetUpdater(
- state: VisState,
- action: VisStateActions.RenameDatasetUpdaterAction
-): VisState;
-export function toggleFilterAnimationUpdater(
- state: VisState,
- action: VisStateActions.ToggleFilterAnimationUpdaterAction
-): VisState;
-export function updateFilterAnimationSpeedUpdater(
- state: VisState,
- action: VisStateActions.UpdateFilterAnimationSpeedUpdaterAction
-): VisState;
-export function setLayerAnimationTimeUpdater(
- state: VisState,
- action: VisStateActions.setLayerAnimationTimeUpdaterAction
-): VisState;
-export function updateLayerAnimationSpeedUpdater(
- state: VisState,
- action: VisStateActions.UpdateLayerAnimationSpeedUpdaterAction
-): VisState;
-export function enlargeFilterUpdater(
- state: VisState,
- action: VisStateActions.EnlargeFilterUpdaterAction
-): VisState;
-export function toggleFilterFeatureUpdater(
- state: VisState,
- action: VisStateActions.ToggleFilterFeatureUpdaterAction
-): VisState;
-export function layerHoverUpdater(
- state: VisState,
- action: VisStateActions.OnLayerHoverUpdaterAction
-): VisState;
-export function layerClickUpdater(
- state: VisState,
- action: VisStateActions.OnLayerClickUpdaterAction
-): VisState;
-export function mapClickUpdater(
- state: VisState,
- action: VisStateActions.OnMapClickUpdaterAction
-): VisState;
-export function mouseMoveUpdater(
- state: VisState,
- action: VisStateActions.OnMouseMoveUpdaterAction
-): VisState;
-export function toggleSplitMapUpdater(
- state: VisState,
- action: MapStateActions.ToggleSplitMapUpdaterAction
-);
-export function toggleLayerForMapUpdater(
- state: VisState,
- action: VisStateActions.ToggleLayerForMapUpdaterAction
-): VisState;
-export function setFilterPlotUpdater(
- state: VisState,
- action: VisStateActions.SetFilterPlotUpdaterAction
-): VisState;
-export function setMapInfoUpdater(
- state: VisState,
- action: VisStateActions.SetMapInfoUpdaterAction
-): VisState;
-export function loadFilesUpdater(
- state: VisState,
- action: VisStateActions.LoadFilesUpdaterAction
-): VisState;
-export function loadNextFileUpdater(state: VisState): VisState;
-export function loadFilesSuccessUpdater(
- state: VisState,
- action: VisStateActions.loadFilesSuccessUpdaterAction
-): VisState;
-export function loadFilesErrUpdater(
- state: VisState,
- action: VisStateActions.LoadFilesErrUpdaterAction
-): VisState;
-export function loadFileStepSuccessUpdater(
- state: VisState,
- action: VisStateActions.LoadFileStepSuccessAction
-): VisState;
-export function nextFileBatchUpdater(
- state: VisState,
- action: VisStateActions.NextFileBatchUpdaterAction
-): VisState;
-export function processFileContentUpdater(
- state: VisState,
- action: VisStateActions.ProcessFileContentUpdaterAction
-): VisState;
-export function setFeaturesUpdater(
- state: VisState,
- action: VisStateActions.SetFeaturesUpdaterAction
-): VisState;
-export function setPolygonFilterLayerUpdater(
- state: VisState,
- action: VisStateActions.SetPolygonFilterLayerUpdaterAction
-): VisState;
-export function setSelectedFeatureUpdater(
- state: VisState,
- action: VisStateActions.SetSelectedFeatureUpdaterAction
-): VisState;
-export function deleteFeatureUpdater(
- state: VisState,
- action: VisStateActions.DeleteFeatureUpdaterAction
-): VisState;
-export function setEditorModeUpdater(
- state: VisState,
- action: VisStateActions.SetEditorModeUpdaterAction
-): VisState;
-export function applyCPUFilterUpdater(
- state: VisState,
- action: VisStateActions.ApplyCPUFilterUpdaterAction
-): VisState;
-export function toggleEditorVisibilityUpdater(
- state: VisState,
- action: VisStateActions.ToggleEditorVisibilityUpdaterAction
-): VisState;
-
-export function resetMapConfigUpdater(state: VisState): VisState;
-
-export function setLayerAnimationTimeConfigUpdater(
- state: VisState,
- action: VisStateActions.setLayerAnimationTimeConfig
-): VisState;
-
-export function setFilterAnimationTimeConfigUpdater(
- state: VisState,
- action: VisStateActions.setFilterAnimationTimeConfig
-): VisState;
-
-export function receiveMapConfigUpdater(
- state: VisState,
- action: {
- type?: ActionTypes.RECEIVE_MAP_CONFIG;
- payload: ReceiveMapConfigPayload;
- }
-): VisState;
-export const INITIAL_VIS_STATE: VisState;
-export const DEFAULT_ANIMATION_CONFIG: AnimationConfig;
-export const DEFAULT_EDITOR: Editor;
-
-export function computeSplitMapLayers(layers: Array<Layer>): Array<Layer>;
-export function closeSpecificMapAtIndex(state: VisState, action: unknown);
-
-export {ProtoDataset} from '../actions/actions';
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.ts
similarity index 76%
rename from src/reducers/vis-state-updaters.js
rename to src/reducers/vis-state-updaters.ts
index 3dd724227..957bb4bfc 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.ts
@@ -70,7 +70,8 @@ import {
VIS_STATE_MERGERS,
validateLayerWithData,
createLayerFromConfig,
- serializeLayer
+ serializeLayer,
+ VisStateMergers
} from './vis-state-merger';
import {
@@ -79,7 +80,7 @@ import {
removeLayerFromSplitMaps
} from 'utils/split-map-utils';
-import {Layer, LayerClasses, LAYER_ID_LENGTH} from 'layers';
+import {Layer, LayerClasses, LayerClassesType, LAYER_ID_LENGTH} from 'layers';
import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';
import {
EDITOR_MODES,
@@ -93,14 +94,276 @@ import {processFileContent} from 'actions/vis-state-actions';
import KeplerGLSchema from 'schemas';
import {isRgbColor} from 'utils/color-utils';
-// type imports
-/** @typedef {import('./vis-state-updaters').Field} Field */
-/** @typedef {import('./vis-state-updaters').Filter} Filter */
-/** @typedef {import('./vis-state-updaters').KeplerTable} KeplerTable */
-/** @typedef {import('./vis-state-updaters').VisState} VisState */
-/** @typedef {import('./vis-state-updaters').Datasets} Datasets */
-/** @typedef {import('./vis-state-updaters').AnimationConfig} AnimationConfig */
-/** @typedef {import('./vis-state-updaters').Editor} Editor */
+import {Millisecond} from './types';
+import {ReceiveMapConfigPayload} from '../actions/actions';
+import * as VisStateActions from 'actions/vis-state-actions';
+import * as MapStateActions from 'actions/map-state-actions';
+import ActionTypes from 'constants/action-types';
+import {LoaderObject} from '@loaders.gl/loader-utils';
+import {KeplerTable, Field} from 'utils';
+
+export type HistogramBin = {
+ x0: number | undefined;
+ x1: number | undefined;
+ count: number;
+};
+
+export type RangeFieldDomain = {
+ domain: [number, number];
+ step: number;
+ histogram: HistogramBin[];
+ enlargedHistogram: HistogramBin[];
+};
+
+export type SelectFieldDomain = {
+ domain: [true, false];
+};
+export type MultiSelectFieldDomain = {
+ domain: string[];
+};
+
+export type TimeRangeFieldDomain = {
+ domain: [number, number];
+ step: number;
+ histogram: HistogramBin[];
+ enlargedHistogram: HistogramBin[];
+ mappedValue: (Millisecond | null)[];
+ // auto generated based on time domain
+ defaultTimeFormat?: string | null;
+ // custom ui input
+ timeFormat?: string | null;
+ // custom ui input
+ timezone?: string | null;
+};
+export type FieldDomain =
+ | RangeFieldDomain
+ | TimeRangeFieldDomain
+ | SelectFieldDomain
+ | MultiSelectFieldDomain;
+
+export type LineChart = {
+ series: {x: number; y: number}[];
+ yDomain: [number, number];
+ xDomain: [number, number];
+};
+
+export type FilterBase = {
+ dataId: string[];
+ id: string;
+
+ freeze: boolean;
+
+ // time range filter specific
+ fixedDomain: boolean;
+ enlarged: boolean;
+ isAnimating: boolean;
+ speed: number;
+ showTimeDisplay?: boolean;
+
+ // field specific
+ name: string[]; // string
+ type: string | null;
+ fieldIdx: number[]; // [integer]
+ domain: any[] | null;
+ value: any;
+ mappedValue?: number[];
+
+ // plot
+ yAxis: Field | null;
+ plotType: string;
+ lineChart?: LineChart;
+ // gpu filter
+ gpu: boolean;
+ gpuChannel?: number[];
+ fieldType?: string;
+
+ // polygon
+ layerId?: string[];
+};
+
+export type RangeFilter = FilterBase &
+ RangeFieldDomain & {
+ type: 'range';
+ fieldType: 'real' | 'integer';
+ value: [number, number];
+ fixedDomain: true;
+ typeOptions: ['range'];
+ };
+
+export type SelectFilter = FilterBase &
+ SelectFieldDomain & {
+ type: 'select';
+ fieldType: 'boolean';
+ value: boolean;
+ };
+
+export type MultiSelectFilter = FilterBase &
+ MultiSelectFieldDomain & {
+ type: 'range';
+ fieldType: 'string' | 'date';
+ value: string[];
+ };
+export type TimeRangeFilter = FilterBase &
+ TimeRangeFieldDomain & {
+ type: 'timeRange';
+ fieldType: 'timestamp';
+ fixedDomain: true;
+ value: [number, number];
+ bins?: Object;
+ plotType: {
+ [key: string]: any;
+ };
+ };
+
+export type PolygonFilter = FilterBase & {
+ layerId: string[];
+ type: 'polygon';
+ fixedDomain: true;
+ value: Feature;
+};
+
+export type Filter =
+ | FilterBase
+ | RangeFilter
+ | TimeRangeFilter
+ | SelectFilter
+ | MultiSelectFilter
+ | PolygonFilter;
+
+export type Datasets = {
+ [key: string]: KeplerTable;
+};
+
+export type Feature = {
+ id: string;
+ properties: any;
+ geometry: {
+ type: string;
+ coordinates: any;
+ };
+};
+export type FeatureValue = {
+ id: string;
+ properties: {
+ filterId: string;
+ };
+ geometry: {
+ type: string;
+ coordinates: any;
+ };
+};
+export type Editor = {
+ mode: string;
+ features: Feature[];
+ selectedFeature: any;
+ visible: boolean;
+};
+
+export type SplitMapLayers = {[key: string]: boolean};
+export type SplitMap = {
+ layers: SplitMapLayers;
+};
+export type AnimationConfig = {
+ domain: number[] | null;
+ currentTime: number | null;
+ speed: number;
+ isAnimating?: boolean;
+ // auto generated based on time domain
+ defaultTimeFormat?: string | null;
+ // custom ui input
+ timeFormat?: string | null;
+ // custom ui input
+ timezone?: string | null;
+ // hide or show control
+ hideControl?: boolean;
+};
+
+export type BaseInteraction = {
+ id: string;
+ label: string;
+ enabled: boolean;
+ iconComponent: any;
+};
+export type TooltipField = {
+ name: string;
+ format: string | null;
+};
+export type CompareType = string | null;
+export type TooltipInfo = BaseInteraction & {
+ config: {
+ fieldsToShow: {
+ [key: string]: TooltipField[];
+ };
+ compareMode: boolean;
+ compareType: CompareType;
+ };
+};
+export type Geocoder = BaseInteraction & {
+ position: number[] | null;
+};
+export type Brush = BaseInteraction & {
+ config: {
+ size: number;
+ };
+};
+export type Coordinate = BaseInteraction & {
+ position: number[] | null;
+};
+export type InteractionConfig = {
+ tooltip: TooltipInfo;
+ geocoder: Geocoder;
+ brush: Brush;
+ coordinate: Coordinate;
+};
+export type MapInfo = {
+ title: string;
+ description: string;
+};
+export type FileLoading = {
+ filesToLoad: FileList;
+ onFinish: (payload: any) => any;
+ fileCache: any[];
+};
+export type FileLoadingProgress = {
+ [key: string]: {
+ percent: number;
+ message: string;
+ fileName: string;
+ error: any;
+ };
+};
+
+export type VisState = {
+ mapInfo: MapInfo;
+ layers: Layer[];
+ layerData: any[];
+ layerToBeMerged: any[];
+ layerOrder: number[];
+ filters: Filter[];
+ filterToBeMerged: any[];
+ datasets: Datasets;
+ editingDataset: string | undefined;
+ interactionConfig: InteractionConfig;
+ interactionToBeMerged: any;
+ layerBlending: string;
+ hoverInfo: any;
+ clicked: any;
+ mousePos: any;
+ maxDefaultTooltips: number;
+ layerClasses: LayerClassesType;
+ animationConfig: AnimationConfig;
+ editor: Editor;
+ splitMaps: SplitMap[];
+ splitMapsToBeMerged: SplitMap[];
+ fileLoading: FileLoading | false;
+ fileLoadingProgress: FileLoadingProgress;
+ loaders: LoaderObject[];
+ loadOptions: object;
+ initialState?: Partial<VisState>;
+ mergers: VisStateMergers;
+ schema: typeof KeplerGLSchema;
+ preserveLayerOrder?: number[];
+};
// react-palm
// disable capture exception for react-palm call to withTask
@@ -147,8 +410,7 @@ disableStackCapturing();
const visStateUpdaters = null;
/* eslint-enable no-unused-vars */
-/** @type {AnimationConfig} */
-export const DEFAULT_ANIMATION_CONFIG = {
+export const DEFAULT_ANIMATION_CONFIG: AnimationConfig = {
domain: null,
currentTime: null,
speed: 1,
@@ -158,8 +420,7 @@ export const DEFAULT_ANIMATION_CONFIG = {
defaultTimeFormat: null
};
-/** @type {Editor} */
-export const DEFAULT_EDITOR = {
+export const DEFAULT_EDITOR: Editor = {
mode: EDITOR_MODES.DRAW_POLYGON,
features: [],
selectedFeature: null,
@@ -170,10 +431,9 @@ export const DEFAULT_EDITOR = {
* Default initial `visState`
* @memberof visStateUpdaters
* @constant
- * @type {VisState}
* @public
*/
-export const INITIAL_VIS_STATE = {
+export const INITIAL_VIS_STATE: VisState = {
// map info
mapInfo: {
title: '',
@@ -238,10 +498,12 @@ export const INITIAL_VIS_STATE = {
/**
* Update state with updated layer and layerData
- * @type {typeof import('./vis-state-updaters').updateStateWithLayerAndData}
*
*/
-export function updateStateWithLayerAndData(state, {layerData, layer, idx}) {
+export function updateStateWithLayerAndData(
+ state: VisState,
+ {layerData, layer, idx}: {layerData?: any; layer: Layer; idx: number}
+): VisState {
return {
...state,
layers: state.layers.map((lyr, i) => (i === idx ? layer : lyr)),
@@ -251,7 +513,7 @@ export function updateStateWithLayerAndData(state, {layerData, layer, idx}) {
};
}
-export function updateStateOnLayerVisibilityChange(state, layer) {
+export function updateStateOnLayerVisibilityChange(state: VisState, layer: Layer): VisState {
let newState = state;
if (state.splitMaps.length) {
newState = {
@@ -272,10 +534,12 @@ export function updateStateOnLayerVisibilityChange(state, layer) {
/**
* Update layer base config: dataId, label, column, isVisible
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerConfigChangeUpdater}
* @returns nextState
*/
-export function layerConfigChangeUpdater(state, action) {
+export function layerConfigChangeUpdater(
+ state: VisState,
+ action: VisStateActions.LayerConfigChangeUpdaterAction
+): VisState {
const {oldLayer} = action;
const idx = state.layers.findIndex(l => l.id === oldLayer.id);
const props = Object.keys(action.newConfig);
@@ -360,10 +624,12 @@ function updateTextLabelPropAndValue(idx, prop, value, textLabel) {
/**
* Update layer base config: dataId, label, column, isVisible
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerTextLabelChangeUpdater}
* @returns nextState
*/
-export function layerTextLabelChangeUpdater(state, action) {
+export function layerTextLabelChangeUpdater(
+ state: VisState,
+ action: VisStateActions.LayerTextLabelChangeUpdaterAction
+): VisState {
const {oldLayer, idx, prop, value} = action;
const {textLabel} = oldLayer.config;
@@ -395,10 +661,17 @@ function validateExistingLayerWithData(dataset, layerClasses, layer) {
/**
* Update layer config dataId
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerDataIdChangeUpdater}
* @returns nextState
*/
-export function layerDataIdChangeUpdater(state, action) {
+export function layerDataIdChangeUpdater(
+ state: VisState,
+ action: {
+ oldLayer: Layer;
+ newConfig: {
+ dataId: string;
+ };
+ }
+): VisState {
const {oldLayer, newConfig} = action;
const {dataId} = newConfig;
@@ -437,10 +710,12 @@ export function layerDataIdChangeUpdater(state, action) {
/**
* Update layer type. Previews layer config will be copied if applicable.
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerTypeChangeUpdater}
* @public
*/
-export function layerTypeChangeUpdater(state, action) {
+export function layerTypeChangeUpdater(
+ state: VisState,
+ action: VisStateActions.LayerTypeChangeUpdaterAction
+): VisState {
const {oldLayer, newType} = action;
if (!oldLayer) {
return state;
@@ -493,11 +768,13 @@ export function layerTypeChangeUpdater(state, action) {
/**
* Update layer visual channel
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerVisualChannelChangeUpdater}
* @returns {Object} nextState
* @public
*/
-export function layerVisualChannelChangeUpdater(state, action) {
+export function layerVisualChannelChangeUpdater(
+ state: VisState,
+ action: VisStateActions.LayerVisualChannelConfigChangeUpdaterAction
+): VisState {
const {oldLayer, newConfig, channel} = action;
if (!oldLayer.config.dataId) {
return state;
@@ -518,10 +795,12 @@ export function layerVisualChannelChangeUpdater(state, action) {
/**
* Update layer `visConfig`
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerVisConfigChangeUpdater}
* @public
*/
-export function layerVisConfigChangeUpdater(state, action) {
+export function layerVisConfigChangeUpdater(
+ state: VisState,
+ action: VisStateActions.LayerVisConfigChangeUpdaterAction
+): VisState {
const {oldLayer} = action;
const idx = state.layers.findIndex(l => l.id === oldLayer.id);
const props = Object.keys(action.newVisConfig);
@@ -544,20 +823,24 @@ export function layerVisConfigChangeUpdater(state, action) {
/**
* Update filter property
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setFilterAnimationTimeUpdater}
* @public
*/
-export function setFilterAnimationTimeUpdater(state, action) {
+export function setFilterAnimationTimeUpdater(
+ state: VisState,
+ action: VisStateActions.SetFilterAnimationTimeUpdaterAction
+): VisState {
return setFilterUpdater(state, action);
}
/**
* Update filter animation window
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setFilterAnimationWindowUpdater}
* @public
*/
-export function setFilterAnimationWindowUpdater(state, {id, animationWindow}) {
+export function setFilterAnimationWindowUpdater(
+ state: VisState,
+ {id, animationWindow}: VisStateActions.SetFilterAnimationWindowUpdaterAction
+): VisState {
return {
...state,
filters: state.filters.map(f =>
@@ -573,10 +856,12 @@ export function setFilterAnimationWindowUpdater(state, {id, animationWindow}) {
/**
* Update filter property
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setFilterUpdater}
* @public
*/
-export function setFilterUpdater(state, action) {
+export function setFilterUpdater(
+ state: VisState,
+ action: VisStateActions.SetFilterUpdaterAction
+): VisState {
const {idx, prop, value, valueIndex = 0} = action;
const oldFilter = state.filters[idx];
@@ -707,10 +992,12 @@ export function setFilterUpdater(state, action) {
/**
* Set the property of a filter plot
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setFilterPlotUpdater}
* @public
*/
-export const setFilterPlotUpdater = (state, {idx, newProp, valueIndex = 0}) => {
+export const setFilterPlotUpdater = (
+ state: VisState,
+ {idx, newProp, valueIndex = 0}: VisStateActions.SetFilterPlotUpdaterAction
+): VisState => {
let newFilter = {...state.filters[idx], ...newProp};
const prop = Object.keys(newProp)[0];
if (prop === 'yAxis') {
@@ -734,10 +1021,12 @@ export const setFilterPlotUpdater = (state, {idx, newProp, valueIndex = 0}) => {
/**
* Add a new filter
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').addFilterUpdater}
* @public
*/
-export const addFilterUpdater = (state, action) =>
+export const addFilterUpdater = (
+ state: VisState,
+ action: VisStateActions.AddFilterUpdaterAction
+): VisState =>
!action.dataId
? state
: {
@@ -748,9 +1037,11 @@ export const addFilterUpdater = (state, action) =>
/**
* Set layer color palette ui state
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerColorUIChangeUpdater}
*/
-export const layerColorUIChangeUpdater = (state, {oldLayer, prop, newConfig}) => {
+export const layerColorUIChangeUpdater = (
+ state: VisState,
+ {oldLayer, prop, newConfig}: VisStateActions.LayerColorUIChangeUpdaterAction
+): VisState => {
const oldVixConfig = oldLayer.config.visConfig[prop];
const newLayer = oldLayer.updateLayerColorUI(prop, newConfig);
const newVisConfig = newLayer.config.visConfig[prop];
@@ -771,20 +1062,24 @@ export const layerColorUIChangeUpdater = (state, {oldLayer, prop, newConfig}) =>
/**
* Start and end filter animation
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').toggleFilterAnimationUpdater}
* @public
*/
-export const toggleFilterAnimationUpdater = (state, action) => ({
+export const toggleFilterAnimationUpdater = (
+ state: VisState,
+ action: VisStateActions.ToggleFilterAnimationUpdaterAction
+): VisState => ({
...state,
filters: state.filters.map((f, i) => (i === action.idx ? {...f, isAnimating: !f.isAnimating} : f))
});
/**
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').toggleLayerAnimationUpdater}
* @public
*/
-export const toggleLayerAnimationUpdater = state => ({
+export const toggleLayerAnimationUpdater = (
+ state: VisState,
+ action: VisStateActions.ToggleLayerAnimationUpdaterAction
+): VisState => ({
...state,
animationConfig: {
...state.animationConfig,
@@ -795,10 +1090,12 @@ export const toggleLayerAnimationUpdater = state => ({
/**
* Hide and show layer animation control
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').toggleLayerAnimationControlUpdater}
* @public
*/
-export const toggleLayerAnimationControlUpdater = state => ({
+export const toggleLayerAnimationControlUpdater = (
+ state: VisState,
+ action: VisStateActions.ToggleLayerAnimationControlUpdaterAction
+): VisState => ({
...state,
animationConfig: {
...state.animationConfig,
@@ -809,10 +1106,12 @@ export const toggleLayerAnimationControlUpdater = state => ({
/**
* Change filter animation speed
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').updateFilterAnimationSpeedUpdater}
* @public
*/
-export const updateFilterAnimationSpeedUpdater = (state, action) => ({
+export const updateFilterAnimationSpeedUpdater = (
+ state: VisState,
+ action: VisStateActions.UpdateFilterAnimationSpeedUpdaterAction
+): VisState => ({
...state,
filters: state.filters.map((f, i) => (i === action.idx ? {...f, speed: action.speed} : f))
});
@@ -820,11 +1119,13 @@ export const updateFilterAnimationSpeedUpdater = (state, action) => ({
/**
* Reset animation config current time to a specified value
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setLayerAnimationTimeUpdater}
* @public
*
*/
-export const setLayerAnimationTimeUpdater = (state, {value}) => ({
+export const setLayerAnimationTimeUpdater = (
+ state: VisState,
+ {value}: VisStateActions.SetLayerAnimationTimeUpdaterAction
+): VisState => ({
...state,
animationConfig: {
...state.animationConfig,
@@ -835,11 +1136,13 @@ export const setLayerAnimationTimeUpdater = (state, {value}) => ({
/**
* Update animation speed with the vertical speed slider
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').updateLayerAnimationSpeedUpdater}
* @public
*
*/
-export const updateLayerAnimationSpeedUpdater = (state, {speed}) => {
+export const updateLayerAnimationSpeedUpdater = (
+ state: VisState,
+ {speed}: VisStateActions.UpdateLayerAnimationSpeedUpdaterAction
+): VisState => {
return {
...state,
animationConfig: {
@@ -852,10 +1155,12 @@ export const updateLayerAnimationSpeedUpdater = (state, {speed}) => {
/**
* Show larger time filter at bottom for time playback (apply to time filter only)
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').enlargeFilterUpdater}
* @public
*/
-export const enlargeFilterUpdater = (state, action) => {
+export const enlargeFilterUpdater = (
+ state: VisState,
+ action: VisStateActions.EnlargeFilterUpdaterAction
+): VisState => {
return {
...state,
filters: state.filters.map((f, i) =>
@@ -872,9 +1177,11 @@ export const enlargeFilterUpdater = (state, action) => {
/**
* Toggles filter feature visibility
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').toggleFilterFeatureUpdater}
*/
-export const toggleFilterFeatureUpdater = (state, action) => {
+export const toggleFilterFeatureUpdater = (
+ state: VisState,
+ action: VisStateActions.ToggleFilterFeatureUpdaterAction
+): VisState => {
const filter = state.filters[action.idx];
const isVisible = get(filter, ['value', 'properties', 'isVisible']);
const newFilter = {
@@ -893,10 +1200,12 @@ export const toggleFilterFeatureUpdater = (state, action) => {
/**
* Remove a filter
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').removeFilterUpdater}
* @public
*/
-export const removeFilterUpdater = (state, action) => {
+export const removeFilterUpdater = (
+ state: VisState,
+ action: VisStateActions.RemoveFilterUpdaterAction
+): VisState => {
const {idx} = action;
const {dataId, id} = state.filters[idx];
@@ -924,10 +1233,12 @@ export const removeFilterUpdater = (state, action) => {
/**
* Add a new layer
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').addLayerUpdater}
* @public
*/
-export const addLayerUpdater = (state, action) => {
+export const addLayerUpdater = (
+ state: VisState,
+ action: VisStateActions.AddLayerUpdaterAction
+): VisState => {
let newLayer;
let newLayerData;
if (action.config) {
@@ -965,10 +1276,12 @@ export const addLayerUpdater = (state, action) => {
/**
* remove layer
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').removeLayerUpdater}
* @public
*/
-export const removeLayerUpdater = (state, {idx}) => {
+export const removeLayerUpdater = (
+ state: VisState,
+ {idx}: VisStateActions.RemoveLayerUpdaterAction
+): VisState => {
const {layers, layerData, clicked, hoverInfo} = state;
const layerToRemove = state.layers[idx];
const newMaps = removeLayerFromSplitMaps(state.splitMaps, layerToRemove);
@@ -990,10 +1303,12 @@ export const removeLayerUpdater = (state, {idx}) => {
/**
* duplicate layer
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').duplicateLayerUpdater}
* @public
*/
-export const duplicateLayerUpdater = (state, {idx}) => {
+export const duplicateLayerUpdater = (
+ state: VisState,
+ {idx}: VisStateActions.DuplicateLayerUpdaterAction
+): VisState => {
const {layers} = state;
const original = state.layers[idx];
const originalLayerOrderIdx = state.layerOrder.findIndex(i => i === idx);
@@ -1041,10 +1356,12 @@ export const duplicateLayerUpdater = (state, {idx}) => {
/**
* Reorder layer
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').reorderLayerUpdater}
* @public
*/
-export const reorderLayerUpdater = (state, {order}) => ({
+export const reorderLayerUpdater = (
+ state: VisState,
+ {order}: VisStateActions.ReorderLayerUpdaterAction
+): VisState => ({
...state,
layerOrder: order
});
@@ -1052,10 +1369,12 @@ export const reorderLayerUpdater = (state, {order}) => ({
/**
* Remove a dataset and all layers, filters, tooltip configs that based on it
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').removeDatasetUpdater}
* @public
*/
-export const removeDatasetUpdater = (state, action) => {
+export const removeDatasetUpdater = (
+ state: VisState,
+ action: VisStateActions.RemoveDatasetUpdaterAction
+): VisState => {
// extract dataset key
const {dataId: datasetKey} = action;
const {datasets} = state;
@@ -1114,10 +1433,12 @@ export const removeDatasetUpdater = (state, action) => {
/**
* update layer blending mode
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').updateLayerBlendingUpdater}
* @public
*/
-export const updateLayerBlendingUpdater = (state, action) => ({
+export const updateLayerBlendingUpdater = (
+ state: VisState,
+ action: VisStateActions.UpdateLayerBlendingUpdaterAction
+): VisState => ({
...state,
layerBlending: action.mode
});
@@ -1125,10 +1446,12 @@ export const updateLayerBlendingUpdater = (state, action) => ({
/**
* Display dataset table in a modal
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').showDatasetTableUpdater}
* @public
*/
-export const showDatasetTableUpdater = (state, action) => {
+export const showDatasetTableUpdater = (
+ state: VisState,
+ action: VisStateActions.ShowDatasetTableUpdaterAction
+): VisState => {
return {
...state,
editingDataset: action.dataId
@@ -1138,10 +1461,12 @@ export const showDatasetTableUpdater = (state, action) => {
/**
* Add custom color for datasets and layers
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').updateTableColorUpdater}
* @public
*/
-export const updateTableColorUpdater = (state, action) => {
+export const updateTableColorUpdater = (
+ state: VisState,
+ action: VisStateActions.UpdateDatasetColorUpdater
+): VisState => {
const {dataId, newColor} = action;
const {datasets} = state;
@@ -1163,10 +1488,9 @@ export const updateTableColorUpdater = (state, action) => {
/**
* reset visState to initial State
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').resetMapConfigUpdater}
* @public
*/
-export const resetMapConfigUpdater = state => ({
+export const resetMapConfigUpdater = (state: VisState): VisState => ({
...INITIAL_VIS_STATE,
...state.initialState,
initialState: state.initialState
@@ -1175,10 +1499,17 @@ export const resetMapConfigUpdater = state => ({
/**
* Propagate `visState` reducer with a new configuration. Current config will be override.
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').receiveMapConfigUpdater}
* @public
*/
-export const receiveMapConfigUpdater = (state, {payload: {config = {}, options = {}}}) => {
+export const receiveMapConfigUpdater = (
+ state: VisState,
+ {
+ payload: {config = {version: ''}, options = {}}
+ }: {
+ type?: typeof ActionTypes.RECEIVE_MAP_CONFIG;
+ payload: ReceiveMapConfigPayload;
+ }
+): VisState => {
if (!config.visState) {
return state;
}
@@ -1199,10 +1530,12 @@ export const receiveMapConfigUpdater = (state, {payload: {config = {}, options =
/**
* Trigger layer hover event with hovered object
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerHoverUpdater}
* @public
*/
-export const layerHoverUpdater = (state, action) => ({
+export const layerHoverUpdater = (
+ state: VisState,
+ action: VisStateActions.OnLayerHoverUpdaterAction
+): VisState => ({
...state,
hoverInfo: action.info
});
@@ -1212,10 +1545,12 @@ export const layerHoverUpdater = (state, action) => ({
/**
* Update `interactionConfig`
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').interactionConfigChangeUpdater}
* @public
*/
-export function interactionConfigChangeUpdater(state, action) {
+export function interactionConfigChangeUpdater(
+ state: VisState,
+ action: VisStateActions.InteractionConfigChangeUpdaterAction
+): VisState {
const {config} = action;
const interactionConfig = {
@@ -1255,10 +1590,12 @@ export function interactionConfigChangeUpdater(state, action) {
/**
* Trigger layer click event with clicked object
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').layerClickUpdater}
* @public
*/
-export const layerClickUpdater = (state, action) => ({
+export const layerClickUpdater = (
+ state: VisState,
+ action: VisStateActions.OnLayerClickUpdaterAction
+): VisState => ({
...state,
mousePos: state.interactionConfig.coordinate.enabled
? {
@@ -1272,10 +1609,12 @@ export const layerClickUpdater = (state, action) => ({
/**
* Trigger map click event, unselect clicked object
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').mapClickUpdater}
* @public
*/
-export const mapClickUpdater = state => {
+export const mapClickUpdater = (
+ state: VisState,
+ action: VisStateActions.OnMapClickUpdaterAction
+): VisState => {
return {
...state,
clicked: null
@@ -1285,10 +1624,12 @@ export const mapClickUpdater = state => {
/**
* Trigger map move event
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').mouseMoveUpdater}
* @public
*/
-export const mouseMoveUpdater = (state, {evt}) => {
+export const mouseMoveUpdater = (
+ state: VisState,
+ {evt}: VisStateActions.OnMouseMoveUpdaterAction
+): VisState => {
if (Object.values(state.interactionConfig).some(config => config.enabled)) {
return {
...state,
@@ -1305,10 +1646,12 @@ export const mouseMoveUpdater = (state, {evt}) => {
/**
* Toggle visibility of a layer for a split map
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').toggleSplitMapUpdater}
* @public
*/
-export const toggleSplitMapUpdater = (state, action) =>
+export const toggleSplitMapUpdater = (
+ state: VisState,
+ action: MapStateActions.ToggleSplitMapUpdaterAction
+): VisState =>
state.splitMaps && state.splitMaps.length === 0
? {
...state,
@@ -1321,10 +1664,12 @@ export const toggleSplitMapUpdater = (state, action) =>
/**
* Toggle visibility of a layer in a split map
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').toggleLayerForMapUpdater}
* @public
*/
-export const toggleLayerForMapUpdater = (state, {mapIndex, layerId}) => {
+export const toggleLayerForMapUpdater = (
+ state: VisState,
+ {mapIndex, layerId}: VisStateActions.ToggleLayerForMapUpdaterAction
+): VisState => {
const {splitMaps} = state;
return {
@@ -1347,12 +1692,14 @@ export const toggleLayerForMapUpdater = (state, {mapIndex, layerId}) => {
/**
* Add new dataset to `visState`, with option to load a map config along with the datasets
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').updateVisDataUpdater}
* @public
*/
/* eslint-disable max-statements */
// eslint-disable-next-line complexity
-export const updateVisDataUpdater = (state, action) => {
+export const updateVisDataUpdater = (
+ state: VisState,
+ action: VisStateActions.UpdateVisDataUpdaterAction
+): VisState => {
// datasets can be a single data entries or an array of multiple data entries
const {config, options} = action;
const datasets = toArray(action.datasets);
@@ -1438,10 +1785,12 @@ export const updateVisDataUpdater = (state, action) => {
/**
* Rename an existing dataset in `visState`
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').renameDatasetUpdater}
* @public
*/
-export function renameDatasetUpdater(state, action) {
+export function renameDatasetUpdater(
+ state: VisState,
+ action: VisStateActions.RenameDatasetUpdaterAction
+): VisState {
const {dataId, label} = action;
const {datasets} = state;
const existing = datasets[dataId];
@@ -1470,7 +1819,10 @@ export function renameDatasetUpdater(state, action) {
* @param {Object} action action
* @returns {Object} nextState
*/
-export function closeSpecificMapAtIndex(state, action) {
+export function closeSpecificMapAtIndex(
+ state: VisState,
+ action: MapStateActions.ToggleSplitMapUpdaterAction
+): VisState {
// retrieve layers meta data from the remaining map that we need to keep
const indexToRetrieve = 1 - action.payload;
const mapLayers = state.splitMaps[indexToRetrieve].layers;
@@ -1497,10 +1849,12 @@ export function closeSpecificMapAtIndex(state, action) {
/**
* Trigger file loading dispatch `addDataToMap` if succeed, or `loadFilesErr` if failed
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').loadFilesUpdater}
* @public
*/
-export const loadFilesUpdater = (state, action) => {
+export const loadFilesUpdater = (
+ state: VisState,
+ action: VisStateActions.LoadFilesUpdaterAction
+): VisState => {
const {files, onFinish = loadFilesSuccess} = action;
if (!files.length) {
return state;
@@ -1525,10 +1879,12 @@ export const loadFilesUpdater = (state, action) => {
/**
* Sucessfully loaded one file, move on to the next one
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').loadFileStepSuccessUpdater}
* @public
*/
-export function loadFileStepSuccessUpdater(state, action) {
+export function loadFileStepSuccessUpdater(
+ state: VisState,
+ action: VisStateActions.LoadFileStepSuccessAction
+): VisState {
if (!state.fileLoading) {
return state;
}
@@ -1553,10 +1909,9 @@ export function loadFileStepSuccessUpdater(state, action) {
/**
*
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').loadNextFileUpdater}
* @public
*/
-export function loadNextFileUpdater(state) {
+export function loadNextFileUpdater(state: VisState): VisState {
if (!state.fileLoading) {
return state;
}
@@ -1574,12 +1929,16 @@ export function loadNextFileUpdater(state) {
const {loaders, loadOptions} = state;
return withTask(
stateWithProgress,
- // @ts-expect-error
- makeLoadFileTask(file, nextState.fileLoading.fileCache, loaders, loadOptions)
+ makeLoadFileTask(
+ file,
+ nextState.fileLoading && nextState.fileLoading.fileCache,
+ loaders,
+ loadOptions
+ )
);
}
-export function makeLoadFileTask(file, fileCache, loaders = [], loadOptions = {}) {
+export function makeLoadFileTask(file, fileCache, loaders: LoaderObject[] = [], loadOptions = {}) {
return LOAD_FILE_TASK({file, fileCache, loaders, loadOptions}).bimap(
// prettier ignore
// success
@@ -1602,10 +1961,12 @@ export function makeLoadFileTask(file, fileCache, loaders = [], loadOptions = {}
/**
*
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').processFileContentUpdater}
* @public
*/
-export function processFileContentUpdater(state, action) {
+export function processFileContentUpdater(
+ state: VisState,
+ action: VisStateActions.ProcessFileContentUpdaterAction
+): VisState {
const {content, fileCache} = action.payload;
const stateWithProgress = updateFileLoadingProgressUpdater(state, {
@@ -1637,13 +1998,14 @@ export function parseProgress(prevProgress = {}, progress) {
/**
* gets called with payload = AsyncGenerator<???>
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').nextFileBatchUpdater}
* @public
*/
export const nextFileBatchUpdater = (
- state,
- {payload: {gen, fileName, progress, accumulated, onFinish}}
-) => {
+ state: VisState,
+ {
+ payload: {gen, fileName, progress, accumulated, onFinish}
+ }: VisStateActions.NextFileBatchUpdaterAction
+): VisState => {
const stateWithProgress = updateFileLoadingProgressUpdater(state, {
fileName,
progress: parseProgress(state.fileLoadingProgress[fileName], progress)
@@ -1670,10 +2032,12 @@ export const nextFileBatchUpdater = (
/**
* Trigger loading file error
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').loadFilesErrUpdater}
* @public
*/
-export const loadFilesErrUpdater = (state, {error, fileName}) => {
+export const loadFilesErrUpdater = (
+ state: VisState,
+ {error, fileName}: VisStateActions.LoadFilesErrUpdaterAction
+): VisState => {
// update ui with error message
Console.warn(error);
if (!state.fileLoading) {
@@ -1696,10 +2060,12 @@ export const loadFilesErrUpdater = (state, {error, fileName}) => {
/**
* When select dataset for export, apply cpu filter to selected dataset
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').applyCPUFilterUpdater}
* @public
*/
-export const applyCPUFilterUpdater = (state, {dataId}) => {
+export const applyCPUFilterUpdater = (
+ state: VisState,
+ {dataId}: VisStateActions.ApplyCPUFilterUpdaterAction
+): VisState => {
// apply cpuFilter
const dataIds = toArray(dataId);
@@ -1709,10 +2075,12 @@ export const applyCPUFilterUpdater = (state, {dataId}) => {
/**
* User input to update the info of the map
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setMapInfoUpdater}
* @public
*/
-export const setMapInfoUpdater = (state, action) => ({
+export const setMapInfoUpdater = (
+ state: VisState,
+ action: VisStateActions.SetMapInfoUpdaterAction
+): VisState => ({
...state,
mapInfo: {
...state.mapInfo,
@@ -1721,11 +2089,12 @@ export const setMapInfoUpdater = (state, action) => ({
});
/**
* Helper function to update All layer domain and layer data of state
- * @type {typeof import('./vis-state-updaters').addDefaultLayers}
*/
-export function addDefaultLayers(state, datasets) {
- /** @type {Layer[]} */
- const empty = [];
+export function addDefaultLayers(
+ state: VisState,
+ datasets: Datasets
+): {state: VisState; newLayers: Layer[]} {
+ const empty: Layer[] = [];
const defaultLayers = Object.values(datasets).reduce((accu, dataset) => {
const foundLayers = findDefaultLayer(dataset, state.layerClasses);
return foundLayers && foundLayers.length ? accu.concat(foundLayers) : accu;
@@ -1778,16 +2147,20 @@ export function initialFileLoadingProgress(file, index) {
}
export function updateFileLoadingProgressUpdater(state, {fileName, progress}) {
+ // @ts-expect-error
return pick_('fileLoadingProgress')(pick_(fileName)(merge_(progress)))(state);
}
/**
* Helper function to update layer domains for an array of datasets
- * @type {typeof import('./vis-state-updaters').updateAllLayerDomainData}
*/
-export function updateAllLayerDomainData(state, dataId, updatedFilter) {
+export function updateAllLayerDomainData(
+ state: VisState,
+ dataId: string | string[],
+ updatedFilter?: Filter
+): VisState {
const dataIds = typeof dataId === 'string' ? [dataId] : dataId;
- const newLayers = [];
- const newLayerData = [];
+ const newLayers: Layer[] = [];
+ const newLayerData: any[] = [];
state.layers.forEach((oldLayer, i) => {
if (oldLayer.config.dataId && dataIds.includes(oldLayer.config.dataId)) {
@@ -1816,13 +2189,14 @@ export function updateAllLayerDomainData(state, dataId, updatedFilter) {
return newState;
}
-export function updateAnimationDomain(state) {
+export function updateAnimationDomain(state: VisState): VisState {
// merge all animatable layer domain and update global config
const animatableLayers = state.layers.filter(
l =>
l.config.isVisible &&
l.config.animation &&
l.config.animation.enabled &&
+ // @ts-expect-error
Array.isArray(l.animationDomain)
);
@@ -1837,9 +2211,11 @@ export function updateAnimationDomain(state) {
};
}
- const mergedDomain = animatableLayers.reduce(
+ const mergedDomain: [number, number] = animatableLayers.reduce(
(accu, layer) => [
+ // @ts-expect-error
Math.min(accu[0], layer.animationDomain[0]),
+ // @ts-expect-error
Math.max(accu[1], layer.animationDomain[1])
],
[Number(Infinity), -Infinity]
@@ -1862,9 +2238,11 @@ export function updateAnimationDomain(state) {
/**
* Update the status of the editor
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setEditorModeUpdater}
*/
-export const setEditorModeUpdater = (state, {mode}) => ({
+export const setEditorModeUpdater = (
+ state: VisState,
+ {mode}: VisStateActions.SetEditorModeUpdaterAction
+): VisState => ({
...state,
editor: {
...state.editor,
@@ -1877,9 +2255,11 @@ export const setEditorModeUpdater = (state, {mode}) => ({
/**
* Update editor features
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setFeaturesUpdater}
*/
-export function setFeaturesUpdater(state, {features = []}) {
+export function setFeaturesUpdater(
+ state: VisState,
+ {features = []}: VisStateActions.SetFeaturesUpdaterAction
+): VisState {
const lastFeature = features.length && features[features.length - 1];
const newState = {
@@ -1921,9 +2301,11 @@ export function setFeaturesUpdater(state, {features = []}) {
/**
* Set the current selected feature
* @memberof uiStateUpdaters
- * @type {typeof import('./vis-state-updaters').setSelectedFeatureUpdater}
*/
-export const setSelectedFeatureUpdater = (state, {feature}) => ({
+export const setSelectedFeatureUpdater = (
+ state: VisState,
+ {feature}: VisStateActions.SetSelectedFeatureUpdaterAction
+): VisState => ({
...state,
editor: {
...state.editor,
@@ -1934,9 +2316,11 @@ export const setSelectedFeatureUpdater = (state, {feature}) => ({
/**
* Delete existing feature from filters
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').deleteFeatureUpdater}
*/
-export function deleteFeatureUpdater(state, {feature}) {
+export function deleteFeatureUpdater(
+ state: VisState,
+ {feature}: VisStateActions.DeleteFeatureUpdaterAction
+): VisState {
if (!feature) {
return state;
}
@@ -1971,9 +2355,11 @@ export function deleteFeatureUpdater(state, {feature}) {
/**
* Toggle feature as layer filter
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setPolygonFilterLayerUpdater}
*/
-export function setPolygonFilterLayerUpdater(state, payload) {
+export function setPolygonFilterLayerUpdater(
+ state: VisState,
+ payload: VisStateActions.SetPolygonFilterLayerUpdaterAction
+): VisState {
const {layer, feature} = payload;
const filterId = getFilterIdInFeature(feature);
@@ -2040,10 +2426,12 @@ export function setPolygonFilterLayerUpdater(state, payload) {
/**
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').sortTableColumnUpdater}
* @public
*/
-export function sortTableColumnUpdater(state, {dataId, column, mode}) {
+export function sortTableColumnUpdater(
+ state: VisState,
+ {dataId, column, mode}: VisStateActions.SortTableColumnUpdaterAction
+): VisState {
const dataset = state.datasets[dataId];
if (!dataset) {
return state;
@@ -2063,10 +2451,12 @@ export function sortTableColumnUpdater(state, {dataId, column, mode}) {
/**
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').pinTableColumnUpdater}
* @public
*/
-export function pinTableColumnUpdater(state, {dataId, column}) {
+export function pinTableColumnUpdater(
+ state: VisState,
+ {dataId, column}: VisStateActions.PinTableColumnUpdaterAction
+): VisState {
const dataset = state.datasets[dataId];
if (!dataset) {
return state;
@@ -2079,10 +2469,12 @@ export function pinTableColumnUpdater(state, {dataId, column}) {
/**
* Copy column content as strings
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').copyTableColumnUpdater}
* @public
*/
-export function copyTableColumnUpdater(state, {dataId, column}) {
+export function copyTableColumnUpdater(
+ state: VisState,
+ {dataId, column}: VisStateActions.CopyTableColumnUpdaterAction
+): VisState {
const dataset = state.datasets[dataId];
if (!dataset) {
return state;
@@ -2103,9 +2495,11 @@ export function copyTableColumnUpdater(state, {dataId, column}) {
/**
* Update editor
- * @type {typeof import('./vis-state-updaters').toggleEditorVisibilityUpdater}
*/
-export function toggleEditorVisibilityUpdater(state) {
+export function toggleEditorVisibilityUpdater(
+ state: VisState,
+ action: VisStateActions.ToggleEditorVisibilityUpdaterAction
+): VisState {
return {
...state,
editor: {
@@ -2115,7 +2509,10 @@ export function toggleEditorVisibilityUpdater(state) {
};
}
-export function setFilterAnimationTimeConfigUpdater(state, {idx, config}) {
+export function setFilterAnimationTimeConfigUpdater(
+ state: VisState,
+ {idx, config}: VisStateActions.SetFilterAnimationTimeConfigAction
+): VisState {
const oldFilter = state.filters[idx];
if (!oldFilter) {
Console.error(`filters.${idx} is undefined`);
@@ -2150,9 +2547,11 @@ function checkTimeConfigArgs(config) {
}
/**
* Update editor
- * @type {typeof import('./vis-state-updaters').setLayerAnimationTimeConfigUpdater}
*/
-export function setLayerAnimationTimeConfigUpdater(state, {config}) {
+export function setLayerAnimationTimeConfigUpdater(
+ state: VisState,
+ {config}: VisStateActions.SetLayerAnimationTimeConfigAction
+): VisState {
if (!config) {
return state;
}
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.ts
similarity index 99%
rename from src/reducers/vis-state.js
rename to src/reducers/vis-state.ts
index e554f39fb..4d3f1a290 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.ts
@@ -147,7 +147,7 @@ const actionHandler = {
// construct vis-state reducer
export const visStateReducerFactory = (initialState = {}) =>
- // @ts-ignore
+ // @ts-expect-error
handleActions(actionHandler, {
...visStateUpdaters.INITIAL_VIS_STATE,
...initialState,