Skip to content

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

[Chore]: Technical: Isolate utils (#1876)

dariaterekhovaaef2459c6c4692
diff --git a/examples/demo-app/src/cloud-providers/carto/carto-provider.js b/examples/demo-app/src/cloud-providers/carto/carto-provider.js
index cba510802..1fee60224 100644
--- a/examples/demo-app/src/cloud-providers/carto/carto-provider.js
+++ b/examples/demo-app/src/cloud-providers/carto/carto-provider.js
@@ -21,9 +21,8 @@
import {OAuthApp} from '@carto/toolkit';
import Console from 'global/console';
import CartoIcon from './carto-icon';
-import {formatCsv} from 'kepler.gl/processors';
import {Provider} from 'kepler.gl/cloud-providers';
-import {createDataContainer} from 'kepler.gl/utils';
+import {createDataContainer, formatCsv} from 'kepler.gl/reducers/table-utils';
const NAME = 'carto';
const DISPLAY_NAME = 'CARTO';
diff --git a/package.json b/package.json
index 2a3547d12..e6b2c48ad 100644
--- a/package.json
+++ b/package.json
@@ -16,8 +16,9 @@
],
"private": true,
"workspaces": [
- "./src/constants",
"./src/types",
+ "./src/constants",
+ "./src/utils",
"./src/styles",
"./src/localization",
"./src/middleware",
@@ -57,7 +58,7 @@
"start:web": "yarn install-and-start -- website start",
"start:https": "yarn install-and-start -- examples/demo-app start-local-https",
"start:e2e": "yarn install-and-start -- examples/demo-app start-local-e2e",
- "build": "rm -fr dist && babel src/{actions,components,layers,middleware,reducers,styles,templates,utils,cloud-providers,connect,localization,processors,schemas,tasks} --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src/{actions,components,middleware,reducers,templates,cloud-providers,connect,localization,schemas,tasks} --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:umd": "webpack --config ./webpack/umd.js --progress --env.prod",
"build:types": "tsc --project tsconfig.production.json",
"analyze": "yarn analyze:bundle",
diff --git a/src/actions/actions.ts b/src/actions/actions.ts
index 434ee8f9e..13bd3e2b5 100644
--- a/src/actions/actions.ts
+++ b/src/actions/actions.ts
@@ -22,13 +22,11 @@ import {default as ActionTypes} from './action-types';
import {createAction} from '@reduxjs/toolkit';
import {ParsedConfig} from '../schemas';
-import {RGBColor} from '@kepler.gl/types';
-import {Bounds} from 'reducers/map-state-updaters';
-import {MapInfo} from 'reducers/vis-state-updaters';
+import {RGBColor, Bounds, MapInfo} from '@kepler.gl/types';
import {UiState} from 'reducers/ui-state-updaters';
/**
- * Input dataest parsed to addDataToMap
+ * Input dataset parsed to addDataToMap
*/
export type ProtoDataset = {
info: {
diff --git a/src/actions/map-state-actions.ts b/src/actions/map-state-actions.ts
index 931cb7e30..e296b4cb8 100644
--- a/src/actions/map-state-actions.ts
+++ b/src/actions/map-state-actions.ts
@@ -20,8 +20,8 @@
import {createAction} from '@reduxjs/toolkit';
import {default as ActionTypes} from './action-types';
-import {Merge} from '@kepler.gl/types';
-import {Bounds, Viewport} from '../reducers/map-state-updaters';
+import {Bounds, Merge} from '@kepler.gl/types';
+import {Viewport} from 'reducers/map-state-updaters';
export type TogglePerspectiveUpdaterAction = {};
/**
diff --git a/src/actions/map-style-actions.ts b/src/actions/map-style-actions.ts
index 80ead5b4c..6b7ad2fa1 100644
--- a/src/actions/map-style-actions.ts
+++ b/src/actions/map-style-actions.ts
@@ -20,9 +20,8 @@
import {createAction} from '@reduxjs/toolkit';
import {default as ActionTypes} from './action-types';
-import {Merge, RGBColor} from '@kepler.gl/types';
-import {InputStyle, MapStyles, VisibleLayerGroups} from '../reducers/map-style-updaters';
-import {MapState} from '../reducers/map-state-updaters';
+import {Merge, RGBColor, MapState} from '@kepler.gl/types';
+import {InputStyle, MapStyles, VisibleLayerGroups} from 'reducers/map-style-updaters';
/**
* Add map style from user input to reducer and set it to current style
diff --git a/src/actions/ui-state-actions.ts b/src/actions/ui-state-actions.ts
index f01f6320f..a2792141e 100644
--- a/src/actions/ui-state-actions.ts
+++ b/src/actions/ui-state-actions.ts
@@ -21,7 +21,7 @@
import {createAction} from '@reduxjs/toolkit';
import {default as ActionTypes} from './action-types';
import {Merge} from '@kepler.gl/types';
-import {ExportImage} from '../reducers/ui-state-updaters';
+import {ExportImage} from '@kepler.gl/constants';
/** TOGGLE_SIDE_PANEL */
export type ToggleSidePanelUpdaterAction = {
diff --git a/src/actions/vis-state-actions.ts b/src/actions/vis-state-actions.ts
index 4e2f22177..740c67eec 100644
--- a/src/actions/vis-state-actions.ts
+++ b/src/actions/vis-state-actions.ts
@@ -23,8 +23,16 @@ import {default as ActionTypes} from './action-types';
import {AddDataToMapPayload} from '../actions/actions';
import {FileCacheItem} from '@kepler.gl/processors';
import {Layer, LayerBaseConfig} from '@kepler.gl/layers';
-import {Feature, InteractionConfig} from 'reducers/vis-state-updaters';
-import {ValueOf, Merge, RGBColor, NestedPartial, LayerVisConfig, ColorUI} from '@kepler.gl/types';
+import {
+ ValueOf,
+ Merge,
+ RGBColor,
+ NestedPartial,
+ LayerVisConfig,
+ ColorUI,
+ Feature,
+ InteractionConfig
+} from '@kepler.gl/types';
// TODO - import LoaderObject type from @loaders.gl/core when supported
// TODO - import LoadOptions type from @loaders.gl/core when supported
diff --git a/src/components/bottom-widget.tsx b/src/components/bottom-widget.tsx
index 8f34c5094..40223801f 100644
--- a/src/components/bottom-widget.tsx
+++ b/src/components/bottom-widget.tsx
@@ -24,9 +24,9 @@ import TimeWidgetFactory from './filters/time-widget';
import AnimationControlFactory from './common/animation-control/animation-control';
import AnimationControllerFactory from './common/animation-control/animation-controller';
import {ANIMATION_WINDOW, DIMENSIONS, FILTER_TYPES} from '@kepler.gl/constants';
-import {getIntervalBins} from 'utils/filter-utils';
+import {getIntervalBins} from 'reducers/filter-utils';
import {media} from '@kepler.gl/styles';
-import {AnimationConfig, TimeRangeFilter} from 'reducers';
+import {AnimationConfig, TimeRangeFilter} from '@kepler.gl/types';
import {bottomWidgetSelector} from './kepler-gl';
const maxWidth = 1080;
diff --git a/src/components/common/animation-control/animation-control.tsx b/src/components/common/animation-control/animation-control.tsx
index 90d7b7bcb..d9abc87eb 100644
--- a/src/components/common/animation-control/animation-control.tsx
+++ b/src/components/common/animation-control/animation-control.tsx
@@ -26,7 +26,7 @@ import Slider from 'components/common/slider/slider';
import {BottomWidgetInner} from 'components/common/styled-components';
import PlaybackControlsFactory from './playback-controls';
import FloatingTimeDisplayFactory from './floating-time-display';
-import {snapToMarks, datetimeFormatter} from 'utils/data-utils';
+import {datetimeFormatter, snapToMarks} from '@kepler.gl/utils';
import {DEFAULT_TIME_FORMAT} from '@kepler.gl/constants';
const SliderWrapper = styled.div`
diff --git a/src/components/common/animation-control/floating-time-display.tsx b/src/components/common/animation-control/floating-time-display.tsx
index 6d8653d2a..c3582ffc1 100644
--- a/src/components/common/animation-control/floating-time-display.tsx
+++ b/src/components/common/animation-control/floating-time-display.tsx
@@ -24,7 +24,7 @@ import classnames from 'classnames';
import {Minus} from 'components/common/icons';
import {DEFAULT_TIME_FORMAT} from '@kepler.gl/constants';
import {CenterFlexbox} from 'components/common/styled-components';
-import {datetimeFormatter} from 'utils/data-utils';
+import {datetimeFormatter} from '@kepler.gl/utils';
const StyledTimeDisplayWrapper = styled.div.attrs({
className: 'floating-time-display'
diff --git a/src/components/common/animation-control/speed-control.tsx b/src/components/common/animation-control/speed-control.tsx
index 5c32ffe98..0b212403f 100644
--- a/src/components/common/animation-control/speed-control.tsx
+++ b/src/components/common/animation-control/speed-control.tsx
@@ -23,7 +23,7 @@ import styled from 'styled-components';
import {Tooltip} from 'components/common/styled-components';
import IconButton from '../icon-button';
import {media} from '@kepler.gl/styles';
-import {preciseRound} from 'utils/data-utils';
+import {preciseRound} from '@kepler.gl/utils';
const StyledSpeedControl = styled.div`
display: flex;
diff --git a/src/components/common/color-legend.tsx b/src/components/common/color-legend.tsx
index 8c2af4ade..9ce05b980 100644
--- a/src/components/common/color-legend.tsx
+++ b/src/components/common/color-legend.tsx
@@ -24,7 +24,7 @@ import {createSelector} from 'reselect';
import {format} from 'd3-format';
import moment from 'moment';
import {SCALE_TYPES, SCALE_FUNC, ALL_FIELD_TYPES} from '@kepler.gl/constants';
-import {getTimeWidgetHintFormatter} from 'utils/filter-utils';
+import {getTimeWidgetHintFormatter} from 'reducers/filter-utils';
const ROW_H = 10;
const GAP = 4;
diff --git a/src/components/common/data-table/cell-size.ts b/src/components/common/data-table/cell-size.ts
index 0ef09103d..24974842a 100644
--- a/src/components/common/data-table/cell-size.ts
+++ b/src/components/common/data-table/cell-size.ts
@@ -19,8 +19,8 @@
// THE SOFTWARE.
import document from 'global/document';
-import {parseFieldValue} from 'utils/data-utils';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
+import {DataContainerInterface} from 'reducers/table-utils';
+import {parseFieldValue} from '@kepler.gl/utils';
const MIN_GHOST_CELL_SIZE: number = 200;
diff --git a/src/components/common/data-table/index.tsx b/src/components/common/data-table/index.tsx
index c8c71ea3f..9d066a980 100644
--- a/src/components/common/data-table/index.tsx
+++ b/src/components/common/data-table/index.tsx
@@ -33,12 +33,12 @@ import Grid from './grid';
import Button from './button';
import {ArrowUp, ArrowDown, VertThreeDots} from 'components/common/icons';
-import {parseFieldValue} from 'utils/data-utils';
+import {parseFieldValue} from '@kepler.gl/utils';
import {adjustCellsToContainer} from './cell-size';
import {ALL_FIELD_TYPES, SORT_ORDER} from '@kepler.gl/constants';
import FieldTokenFactory from 'components/common/field-token';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
const defaultHeaderRowHeight = 55;
const defaultRowHeight = 32;
diff --git a/src/components/common/field-selector.tsx b/src/components/common/field-selector.tsx
index 3bbe9ae61..2e8d4d99a 100644
--- a/src/components/common/field-selector.tsx
+++ b/src/components/common/field-selector.tsx
@@ -22,12 +22,12 @@ import React, {Component, ComponentType} from 'react';
import styled from 'styled-components';
import {createSelector} from 'reselect';
+import {Field} from '@kepler.gl/types';
+import {notNullorUndefined, toArray} from '@kepler.gl/utils';
+
import ItemSelector from './item-selector/item-selector';
import {classList} from './item-selector/dropdown-list';
-import {toArray} from 'utils/utils';
-import {notNullorUndefined} from 'utils/data-utils';
import FieldTokenFactory from '../common/field-token';
-import {Field} from 'utils/table-utils/kepler-table';
const defaultDisplayOption = (d: Field) => d.displayName || d.name;
const defaultValueOption = (d: Field) => d.name;
diff --git a/src/components/common/file-uploader/file-upload-progress.tsx b/src/components/common/file-uploader/file-upload-progress.tsx
index 72f19c2e3..53d2223b6 100644
--- a/src/components/common/file-uploader/file-upload-progress.tsx
+++ b/src/components/common/file-uploader/file-upload-progress.tsx
@@ -23,8 +23,8 @@ import styled, {withTheme} from 'styled-components';
import classnames from 'classnames';
import ProgressBar from '../progress-bar';
import {TruncatedTitleText} from 'components/common/styled-components';
-import {getError} from 'utils/utils';
-import {FileLoadingProgress} from 'reducers/vis-state-updaters';
+import {getError} from '@kepler.gl/utils';
+import {FileLoadingProgress} from '@kepler.gl/types';
const StyledFileProgress = styled.div.attrs(props => ({
className: classnames('file-upload__progress', props.className)
diff --git a/src/components/common/file-uploader/file-upload.tsx b/src/components/common/file-uploader/file-upload.tsx
index 1bf7cefb1..61c7fa88a 100644
--- a/src/components/common/file-uploader/file-upload.tsx
+++ b/src/components/common/file-uploader/file-upload.tsx
@@ -25,9 +25,9 @@ import UploadButton from './upload-button';
import {DragNDrop, FileType} from 'components/common/icons';
import FileUploadProgress from 'components/common/file-uploader/file-upload-progress';
import FileDrop from './file-drop';
-import {FileLoading, FileLoadingProgress} from 'reducers/vis-state-updaters';
+import {FileLoading, FileLoadingProgress} from '@kepler.gl/types';
-import {isChrome} from 'utils/utils';
+import {isChrome} from '@kepler.gl/utils';
import {GUIDES_FILE_FORMAT_DOC} from '@kepler.gl/constants';
import ReactMarkdown from 'react-markdown';
// Breakpoints
diff --git a/src/components/common/histogram-plot.tsx b/src/components/common/histogram-plot.tsx
index 142fe7809..d731166e9 100644
--- a/src/components/common/histogram-plot.tsx
+++ b/src/components/common/histogram-plot.tsx
@@ -23,7 +23,7 @@ import {scaleLinear} from 'd3-scale';
import {max} from 'd3-array';
import styled from 'styled-components';
import classnames from 'classnames';
-import {HistogramBin} from 'reducers';
+import {HistogramBin} from '@kepler.gl/types';
const histogramStyle = {
highlightW: 0.7,
diff --git a/src/components/common/image-preview.tsx b/src/components/common/image-preview.tsx
index 31c1104af..9c4677b9a 100644
--- a/src/components/common/image-preview.tsx
+++ b/src/components/common/image-preview.tsx
@@ -21,9 +21,9 @@
import React from 'react';
import styled from 'styled-components';
import LoadingSpinner from 'components/common/loading-spinner';
-import {ExportImage} from 'reducers';
+import {ExportImage} from '@kepler.gl/constants';
-/** @typedef {import('../../reducers/ui-state-updaters').ExportImage} ExportImage */
+/** @typedef {import('reducers/ui-state-updaters').ExportImage} ExportImage */
const StyledImagePreview = styled.div.attrs({
className: 'image-preview'
diff --git a/src/components/common/index.ts b/src/components/common/index.ts
new file mode 100644
index 000000000..4fbed5a8d
--- /dev/null
+++ b/src/components/common/index.ts
@@ -0,0 +1,3 @@
+/* eslint-disable prettier/prettier */
+export * as Icons from './icons';
+export * from './styled-components';
diff --git a/src/components/common/info-helper.tsx b/src/components/common/info-helper.tsx
index 44e5d3478..de4d58947 100644
--- a/src/components/common/info-helper.tsx
+++ b/src/components/common/info-helper.tsx
@@ -24,7 +24,7 @@ import {FormattedMessage} from '@kepler.gl/localization';
import {Tooltip} from './styled-components';
import {Docs} from 'components/common/icons';
import styled from 'styled-components';
-import {camelize} from 'utils/utils';
+import {camelize} from '@kepler.gl/utils';
interface StyledInfoHelperProps {
width?: number;
diff --git a/src/components/common/item-selector/item-selector.tsx b/src/components/common/item-selector/item-selector.tsx
index 5af3c43bc..828223981 100644
--- a/src/components/common/item-selector/item-selector.tsx
+++ b/src/components/common/item-selector/item-selector.tsx
@@ -30,7 +30,7 @@ import Typeahead from './typeahead';
import {Delete, ArrowDown} from 'components/common/icons';
import DropdownList, {ListItem} from './dropdown-list';
-import {toArray} from 'utils/utils';
+import {toArray} from '@kepler.gl/utils';
import {injectIntl, IntlShape} from 'react-intl';
import {FormattedMessage} from '@kepler.gl/localization';
diff --git a/src/components/common/line-chart.tsx b/src/components/common/line-chart.tsx
index 3ab3ccc18..6b4de797c 100644
--- a/src/components/common/line-chart.tsx
+++ b/src/components/common/line-chart.tsx
@@ -30,9 +30,9 @@ import {
LineSeriesPoint,
RVNearestXData
} from 'react-vis';
-import {LineChart} from 'reducers';
+import {LineChart} from '@kepler.gl/types';
import styled from 'styled-components';
-import {datetimeFormatter} from 'utils/data-utils';
+import {datetimeFormatter} from '@kepler.gl/utils';
const LineChartWrapper = styled.div`
.rv-xy-plot {
diff --git a/src/components/common/map-layer-selector.tsx b/src/components/common/map-layer-selector.tsx
index 79b66ddf0..7fd794083 100644
--- a/src/components/common/map-layer-selector.tsx
+++ b/src/components/common/map-layer-selector.tsx
@@ -21,7 +21,7 @@
import React from 'react';
import styled from 'styled-components';
import Checkbox from 'components/common/checkbox';
-import {generateHashId} from '../../utils/utils';
+import {generateHashId} from '@kepler.gl/utils';
const MapLayerSelect = styled.div`
padding: 12px;
diff --git a/src/components/common/range-brush.tsx b/src/components/common/range-brush.tsx
index 50b992a84..b97ddb24e 100644
--- a/src/components/common/range-brush.tsx
+++ b/src/components/common/range-brush.tsx
@@ -22,7 +22,7 @@ import React, {Component, createRef} from 'react';
import styled, {withTheme} from 'styled-components';
import {select, Selection} from 'd3-selection';
import {BrushBehavior, brushX} from 'd3-brush';
-import {normalizeSliderValue} from 'utils/data-utils';
+import {normalizeSliderValue} from '@kepler.gl/utils';
interface StyledGProps {
isRanged?: boolean;
diff --git a/src/components/common/range-plot.tsx b/src/components/common/range-plot.tsx
index 7b916341f..2b73014ca 100644
--- a/src/components/common/range-plot.tsx
+++ b/src/components/common/range-plot.tsx
@@ -23,8 +23,8 @@ import styled, {withTheme} from 'styled-components';
import RangeBrushFactory, {OnBrush, RangeBrushProps} from './range-brush';
import HistogramPlotFactory from './histogram-plot';
import LineChartFactory, {HoverDP} from './line-chart';
-import {isTest} from 'utils/utils';
-import {LineChart} from 'reducers';
+import {isTest} from '@kepler.gl/utils';
+import {LineChart} from '@kepler.gl/types';
const StyledRangePlot = styled.div`
margin-bottom: ${props => props.theme.sliderBarHeight}px;
diff --git a/src/components/common/range-slider.tsx b/src/components/common/range-slider.tsx
index 3030a6cc2..26c1d0fa5 100644
--- a/src/components/common/range-slider.tsx
+++ b/src/components/common/range-slider.tsx
@@ -26,9 +26,8 @@ import RangePlotFactory from './range-plot';
import Slider from 'components/common/slider/slider';
import {Input} from 'components/common/styled-components';
-import {roundValToStep, clamp} from 'utils/data-utils';
-import {observeDimensions, unobserveDimensions} from '../../utils/observe-dimensions';
-import {LineChart} from 'reducers';
+import {observeDimensions, unobserveDimensions, roundValToStep, clamp} from '@kepler.gl/utils';
+import {LineChart} from '@kepler.gl/types';
interface SliderInputProps {
flush?: boolean;
diff --git a/src/components/common/slider/slider.tsx b/src/components/common/slider/slider.tsx
index aca738621..7374cd58a 100644
--- a/src/components/common/slider/slider.tsx
+++ b/src/components/common/slider/slider.tsx
@@ -24,7 +24,7 @@ import styled from 'styled-components';
import SliderHandle from './slider-handle';
import SliderBarHandle from './slider-bar-handle';
-import {normalizeSliderValue, clamp} from 'utils/data-utils';
+import {normalizeSliderValue, clamp} from '@kepler.gl/utils';
function noop() {}
diff --git a/src/components/common/styled-components.tsx b/src/components/common/styled-components.tsx
index e9a18286d..827600bb5 100644
--- a/src/components/common/styled-components.tsx
+++ b/src/components/common/styled-components.tsx
@@ -421,7 +421,7 @@ export const SelectionButton = styled.div<SelectionButtonProps>`
}
`;
-export const Table = styled.table`
+export const StyledTable = styled.table`
width: 100%;
border-spacing: 0;
diff --git a/src/components/common/time-range-slider-time-title.tsx b/src/components/common/time-range-slider-time-title.tsx
index 097dcebb3..25746245f 100644
--- a/src/components/common/time-range-slider-time-title.tsx
+++ b/src/components/common/time-range-slider-time-title.tsx
@@ -21,7 +21,7 @@
import React from 'react';
import styled from 'styled-components';
import {Minus} from 'components/common/icons';
-import {datetimeFormatter} from 'utils/data-utils';
+import {datetimeFormatter} from '@kepler.gl/utils';
interface TimeValueWrapperProps {
isEnlarged?: boolean;
diff --git a/src/components/common/time-range-slider.tsx b/src/components/common/time-range-slider.tsx
index 3ebf9e628..c70e0800a 100644
--- a/src/components/common/time-range-slider.tsx
+++ b/src/components/common/time-range-slider.tsx
@@ -26,7 +26,7 @@ import RangeSliderFactory from 'components/common/range-slider';
import TimeSliderMarkerFactory from 'components/common/time-slider-marker';
import PlaybackControlsFactory from 'components/common/animation-control/playback-controls';
import TimeRangeSliderTimeTitleFactory from 'components/common/time-range-slider-time-title';
-import {HistogramBin, LineChart} from 'reducers';
+import {HistogramBin, LineChart} from '@kepler.gl/types';
const animationControlWidth = 176;
diff --git a/src/components/common/time-slider-marker.tsx b/src/components/common/time-slider-marker.tsx
index 9bea7ee74..38482bbf5 100644
--- a/src/components/common/time-slider-marker.tsx
+++ b/src/components/common/time-slider-marker.tsx
@@ -25,7 +25,7 @@ import {NumberValue, scaleUtc} from 'd3-scale';
import {select} from 'd3-selection';
import {axisBottom} from 'd3-axis';
import styled from 'styled-components';
-import {datetimeFormatter} from 'utils/data-utils';
+import {datetimeFormatter} from '@kepler.gl/utils';
const MIN_TICK_WIDTH_LARGE = 80;
const MIN_TICK_WIDTH_SMALL = 50;
diff --git a/src/components/container.tsx b/src/components/container.tsx
index 4c1452858..973a999ad 100644
--- a/src/components/container.tsx
+++ b/src/components/container.tsx
@@ -27,7 +27,7 @@ import KeplerGlFactory from './kepler-gl';
import {forwardTo} from 'actions/action-wrapper';
import {registerEntry, deleteEntry, renameEntry} from 'actions/identity-actions';
-import {notNullorUndefined} from 'utils/data-utils';
+import {notNullorUndefined} from '@kepler.gl/utils';
import {KeplerGlState} from 'reducers/core';
export const ERROR_MSG = {
diff --git a/src/components/editor/editor.tsx b/src/components/editor/editor.tsx
index 84b649df2..e8ff1f165 100644
--- a/src/components/editor/editor.tsx
+++ b/src/components/editor/editor.tsx
@@ -32,9 +32,10 @@ import {EDITOR_AVAILABLE_LAYERS, Layer} from '@kepler.gl/layers';
import {DEFAULT_RADIUS, getStyle as getFeatureStyle} from './feature-styles';
import {getStyle as getEditHandleStyle, getEditHandleShape} from './handle-style';
-import {Datasets, Filter} from 'reducers';
+import {Filter} from '@kepler.gl/types';
import {Feature} from '@nebula.gl/edit-modes';
import {MjolnirEvent} from 'mjolnir.js';
+import {Datasets} from 'reducers/table-utils/kepler-table';
const StyledWrapper = styled.div`
cursor: ${(props: {editor: {mode: string}}) =>
diff --git a/src/components/editor/feature-action-panel.tsx b/src/components/editor/feature-action-panel.tsx
index 870ef704d..84f7332c8 100644
--- a/src/components/editor/feature-action-panel.tsx
+++ b/src/components/editor/feature-action-panel.tsx
@@ -28,8 +28,9 @@ import classnames from 'classnames';
import {Trash, Layers, Copy, Checkmark} from 'components/common/icons';
import copy from 'copy-to-clipboard';
import {Layer} from '@kepler.gl/layers';
-import {Datasets, Filter} from 'reducers';
+import {Filter} from '@kepler.gl/types';
import {Feature} from '@nebula.gl/edit-modes';
+import {Datasets} from 'reducers/table-utils/kepler-table';
const LAYOVER_OFFSET = 4;
diff --git a/src/components/filters/filter-panels/filter-panel-with-field-select.tsx b/src/components/filters/filter-panels/filter-panel-with-field-select.tsx
index 513998d26..80259bdf0 100644
--- a/src/components/filters/filter-panels/filter-panel-with-field-select.tsx
+++ b/src/components/filters/filter-panels/filter-panel-with-field-select.tsx
@@ -26,7 +26,7 @@ import SourceDataSelectorFactory from 'components/side-panel/common/source-data-
import FieldSelectorFactory from '../../common/field-selector';
import {getSupportedFilterFields} from './new-filter-panel';
import {FilterPanelWithFieldSelectComponent} from './types';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import KeplerTable from 'reducers/table-utils/kepler-table';
FieldPanelWithFieldSelectFactory.deps = [
FilterPanelHeaderFactory,
diff --git a/src/components/filters/filter-panels/multi-select-filter-panel.tsx b/src/components/filters/filter-panels/multi-select-filter-panel.tsx
index 2028f2be3..1cc50cf39 100644
--- a/src/components/filters/filter-panels/multi-select-filter-panel.tsx
+++ b/src/components/filters/filter-panels/multi-select-filter-panel.tsx
@@ -20,7 +20,7 @@
import React, {useCallback} from 'react';
import MultiSelectFilterFactory from 'components/filters/multi-select-filter';
-import {MultiSelectFilter} from 'reducers';
+import {MultiSelectFilter} from '@kepler.gl/types';
import FieldPanelWithFieldSelectFactory from 'components/filters/filter-panels/filter-panel-with-field-select';
import {FilterPanelComponent} from './types';
diff --git a/src/components/filters/filter-panels/new-filter-panel.tsx b/src/components/filters/filter-panels/new-filter-panel.tsx
index 0822df538..18a75441a 100644
--- a/src/components/filters/filter-panels/new-filter-panel.tsx
+++ b/src/components/filters/filter-panels/new-filter-panel.tsx
@@ -23,9 +23,9 @@ import {StyledFilterContent} from 'components/common/styled-components';
import FilterPanelHeaderFactory from 'components/side-panel/filter-panel/filter-panel-header';
import SourceDataSelectorFactory from 'components/side-panel/common/source-data-selector';
import FieldSelectorFactory from '../../common/field-selector';
-import {FilterBase, LineChart} from 'reducers';
import {FilterPanelComponent} from './types';
-import KeplerTable, {Field} from 'utils/table-utils/kepler-table';
+import KeplerTable from 'reducers/table-utils/kepler-table';
+import {Field, FilterBase, LineChart} from '@kepler.gl/types';
NewFilterPanelFactory.deps = [
FilterPanelHeaderFactory,
diff --git a/src/components/filters/filter-panels/polygon-filter-panel.tsx b/src/components/filters/filter-panels/polygon-filter-panel.tsx
index 20d471f7e..4858ac1bf 100644
--- a/src/components/filters/filter-panels/polygon-filter-panel.tsx
+++ b/src/components/filters/filter-panels/polygon-filter-panel.tsx
@@ -29,7 +29,7 @@ import {StyledFilterPanel} from '../components';
import get from 'lodash.get';
import {PolygonFilterPanelComponent} from './types';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import KeplerTable from 'reducers/table-utils/kepler-table';
PolygonFilterPanelFactory.deps = [
FilterPanelHeaderFactory,
diff --git a/src/components/filters/filter-panels/range-filter-panel.tsx b/src/components/filters/filter-panels/range-filter-panel.tsx
index 27b96e41b..fb5ec8769 100644
--- a/src/components/filters/filter-panels/range-filter-panel.tsx
+++ b/src/components/filters/filter-panels/range-filter-panel.tsx
@@ -20,7 +20,7 @@
import React, {useCallback} from 'react';
import RangeFilterFactory from 'components/filters/range-filter';
-import {RangeFilter} from 'reducers';
+import {RangeFilter} from '@kepler.gl/types';
import FieldPanelWithFieldSelectFactory from 'components/filters/filter-panels/filter-panel-with-field-select';
import {FilterPanelComponent} from './types';
diff --git a/src/components/filters/filter-panels/single-select-filter-panel.tsx b/src/components/filters/filter-panels/single-select-filter-panel.tsx
index 3e3d4c944..2b857a100 100644
--- a/src/components/filters/filter-panels/single-select-filter-panel.tsx
+++ b/src/components/filters/filter-panels/single-select-filter-panel.tsx
@@ -20,7 +20,7 @@
import React, {useCallback} from 'react';
import SingleSelectFilterFactory from 'components/filters/single-select-filter';
-import {SelectFilter} from 'reducers';
+import {SelectFilter} from '@kepler.gl/types';
import FieldPanelWithFieldSelectFactory from 'components/filters/filter-panels/filter-panel-with-field-select';
import {FilterPanelComponent} from './types';
diff --git a/src/components/filters/filter-panels/types.ts b/src/components/filters/filter-panels/types.ts
index e6cb215e8..9e17af7bd 100644
--- a/src/components/filters/filter-panels/types.ts
+++ b/src/components/filters/filter-panels/types.ts
@@ -1,7 +1,7 @@
import {FunctionComponent, ComponentType} from 'react';
-import {Datasets, Filter, PolygonFilter, TimeRangeFilter} from 'reducers';
+import {Filter, PolygonFilter, TimeRangeFilter, Field} from '@kepler.gl/types';
import {Layer} from '@kepler.gl/layers';
-import {Field} from 'utils/table-utils/kepler-table';
+import {Datasets} from 'reducers/table-utils/kepler-table';
interface PanelAction {
id: string;
diff --git a/src/components/filters/time-range-filter.tsx b/src/components/filters/time-range-filter.tsx
index cbdad623d..253ccf2a3 100644
--- a/src/components/filters/time-range-filter.tsx
+++ b/src/components/filters/time-range-filter.tsx
@@ -21,7 +21,7 @@
import React from 'react';
import TimeRangeSliderFactory from 'components/common/time-range-slider';
import {DEFAULT_TIME_FORMAT} from '@kepler.gl/constants';
-import {TimeRangeFilter} from 'reducers';
+import {TimeRangeFilter} from '@kepler.gl/types';
import {TimeRangeFilterProps} from './types';
/*
* TimeRangeFilter -> TimeRangeSlider -> RangeSlider
diff --git a/src/components/filters/time-widget.tsx b/src/components/filters/time-widget.tsx
index dea8a9ec4..98af92b04 100644
--- a/src/components/filters/time-widget.tsx
+++ b/src/components/filters/time-widget.tsx
@@ -30,7 +30,7 @@ import {Close, Clock, LineChart} from 'components/common/icons';
import TimeRangeSliderFactory from 'components/common/time-range-slider';
import FieldSelectorFactory from 'components/common/field-selector';
import FloatingTimeDisplayFactory from 'components/common/animation-control/floating-time-display';
-import {Field} from 'utils/table-utils/kepler-table';
+import {Field} from '@kepler.gl/types';
import {timeRangeSliderFieldsSelector} from './time-range-filter';
import {TimeWidgetProps, TimeWidgetTopProps, TopSectionWrapperProps} from './types';
diff --git a/src/components/filters/types.ts b/src/components/filters/types.ts
index 9f56f5ade..c453d83b0 100644
--- a/src/components/filters/types.ts
+++ b/src/components/filters/types.ts
@@ -1,11 +1,10 @@
import {
- Datasets,
Filter,
MultiSelectFilter,
RangeFilter,
SelectFilter,
TimeRangeFilter
-} from 'reducers';
+} from '@kepler.gl/types';
import {Layer} from '@kepler.gl/layers';
import {
ActionHandler,
@@ -16,6 +15,7 @@ import {
toggleFilterAnimation,
updateFilterAnimationSpeed
} from 'actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
export type PolygonFilterProps = {
filter: Filter;
diff --git a/src/components/geocoder-panel.tsx b/src/components/geocoder-panel.tsx
index 63187051f..a71bdacce 100644
--- a/src/components/geocoder-panel.tsx
+++ b/src/components/geocoder-panel.tsx
@@ -23,7 +23,7 @@ import styled from 'styled-components';
import {processRowObject} from '@kepler.gl/processors';
import {FlyToInterpolator} from '@deck.gl/core';
import KeplerGlSchema from 'schemas';
-import {getCenterAndZoomFromBounds} from 'utils/projection-utils';
+import {getCenterAndZoomFromBounds} from '@kepler.gl/utils';
import Geocoder, {Result} from './geocoder/geocoder';
import {
@@ -33,7 +33,8 @@ import {
GEOCODER_ICON_COLOR,
GEOCODER_ICON_SIZE
} from '@kepler.gl/constants';
-import {MapState, Viewport} from 'reducers';
+import {MapState} from '@kepler.gl/types';
+import {Viewport} from 'reducers';
const ICON_LAYER = {
id: GEOCODER_LAYER_ID,
diff --git a/src/components/index.ts b/src/components/index.ts
index 0f9ebb17d..f0ccb4add 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -215,10 +215,7 @@ export {
LayerColorSelector
} from './side-panel/layer-panel/layer-configurator';
-export * from './common/styled-components';
-import * as Icons from './common/icons';
-
-export {Icons};
+export * from './common';
// Individual Component from Dependency Tree
export const TimeRangeSlider = appInjector.get(TimeRangeSliderFactory);
diff --git a/src/components/kepler-gl.tsx b/src/components/kepler-gl.tsx
index 045d7ba5a..66663df45 100644
--- a/src/components/kepler-gl.tsx
+++ b/src/components/kepler-gl.tsx
@@ -62,12 +62,16 @@ import PlotContainerFactory from './plot-container';
import NotificationPanelFactory from './notification-panel';
import GeoCoderPanelFactory from './geocoder-panel';
-import {filterObjectByPredicate, generateHashId} from 'utils/utils';
-import {validateToken} from 'utils/mapbox-utils';
-import {mergeMessages} from 'utils/locale-utils';
+import {
+ filterObjectByPredicate,
+ generateHashId,
+ validateToken,
+ mergeMessages,
+ observeDimensions,
+ unobserveDimensions
+} from '@kepler.gl/utils';
import {theme as basicTheme, themeLT, themeBS} from '@kepler.gl/styles';
-import {observeDimensions, unobserveDimensions} from '../utils/observe-dimensions';
import {KeplerGlState} from 'reducers/core';
import {Provider} from 'cloud-providers';
diff --git a/src/components/map-container.tsx b/src/components/map-container.tsx
index 20b18183c..b3daacf2f 100644
--- a/src/components/map-container.tsx
+++ b/src/components/map-container.tsx
@@ -26,8 +26,6 @@ import {createSelector} from 'reselect';
import WebMercatorViewport from 'viewport-mercator-project';
import mapboxgl from 'mapbox-gl';
-import {errorNotification} from 'utils/notifications-utils';
-
import * as VisStateActions from 'actions/vis-state-actions';
import * as MapStateActions from 'actions/map-state-actions';
import * as UIStateActions from 'actions/ui-state-actions';
@@ -47,35 +45,37 @@ import {
LayerBaseConfig,
VisualChannelDomain
} from '@kepler.gl/layers';
-import {setLayerBlending} from 'utils/gl-utils';
-import {transformRequest} from 'utils/map-style-utils/mapbox-utils';
import {
- getLayerHoverProp,
- prepareLayersToRender,
- prepareLayersForDeck,
- LayerHoverProp
-} from 'utils/layer-utils';
+ AnimationConfig,
+ Filter,
+ InteractionConfig,
+ MapState,
+ SplitMapLayers
+} from '@kepler.gl/types';
+import {
+ errorNotification,
+ setLayerBlending,
+ transformRequest,
+ observeDimensions,
+ unobserveDimensions
+} from '@kepler.gl/utils';
// default-settings
import {FILTER_TYPES, GEOCODER_LAYER_ID, THROTTLE_NOTIFICATION_TIME} from '@kepler.gl/constants';
import ErrorBoundary from 'components/common/error-boundary';
-import {observeDimensions, unobserveDimensions} from '../utils/observe-dimensions';
import {LOCALE_CODES} from '@kepler.gl/localization';
-import {computeDeckLayers} from '../utils/layer-utils';
-import {getMapLayersFromSplitMaps, onViewPortChange} from 'utils/map-utils';
+import {getMapLayersFromSplitMaps, onViewPortChange} from '@kepler.gl/utils';
import {MapView} from '@deck.gl/core';
+import {MapControls, MapStyle, Viewport} from 'reducers';
+import {Datasets} from 'reducers/table-utils';
import {
- Datasets,
- Filter,
- InteractionConfig,
- AnimationConfig,
- MapControls,
- MapState,
- MapStyle,
- Viewport
+ computeDeckLayers,
+ getLayerHoverProp,
+ LayerHoverProp,
+ prepareLayersForDeck,
+ prepareLayersToRender
} from 'reducers';
-import {SplitMapLayers} from 'reducers/vis-state-updaters';
/** @type {{[key: string]: React.CSSProperties}} */
const MAP_STYLE: {[key: string]: React.CSSProperties} = {
diff --git a/src/components/map/coordinate-info.tsx b/src/components/map/coordinate-info.tsx
index d09c715fd..a9450e9d6 100644
--- a/src/components/map/coordinate-info.tsx
+++ b/src/components/map/coordinate-info.tsx
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import React from 'react';
-import {preciseRound} from 'utils/data-utils';
+import {preciseRound} from '@kepler.gl/utils';
import {CursorClick} from 'components/common/icons';
import {StyledLayerName} from './layer-hover-info';
diff --git a/src/components/map/layer-hover-info.tsx b/src/components/map/layer-hover-info.tsx
index 570605eba..8fa2e28e6 100644
--- a/src/components/map/layer-hover-info.tsx
+++ b/src/components/map/layer-hover-info.tsx
@@ -20,14 +20,17 @@
import React, {useMemo} from 'react';
import styled from 'styled-components';
-import {TooltipField} from 'reducers/vis-state-updaters';
+import {TooltipField} from '@kepler.gl/types';
import {CenterFlexbox} from 'components/common/styled-components';
import {Layers} from 'components/common/icons';
import PropTypes from 'prop-types';
-import {notNullorUndefined} from 'utils/data-utils';
-import {getTooltipDisplayValue, getTooltipDisplayDeltaValue} from 'utils/interaction-utils';
-import {AggregationLayerHoverData} from 'utils/layer-utils';
-import {Layer} from 'layers';
+import {notNullorUndefined} from '@kepler.gl/utils';
+import {Layer} from '@kepler.gl/layers';
+import {
+ AggregationLayerHoverData,
+ getTooltipDisplayDeltaValue,
+ getTooltipDisplayValue
+} from 'reducers';
export const StyledLayerName = styled(CenterFlexbox)`
color: ${props => props.theme.textColorHl};
diff --git a/src/components/map/lazy-tippy.tsx b/src/components/map/lazy-tippy.tsx
index ecc694eb3..9e97f6984 100644
--- a/src/components/map/lazy-tippy.tsx
+++ b/src/components/map/lazy-tippy.tsx
@@ -1,7 +1,7 @@
// @ts-nocheck
import React, {useState, forwardRef} from 'react';
import Tippy from '@tippyjs/react/headless';
-import {isTest} from 'utils/utils';
+import {isTest} from '@kepler.gl/utils';
const isTestEnv = isTest();
diff --git a/src/components/map/map-control.tsx b/src/components/map/map-control.tsx
index 47799e9f5..9bba71d24 100644
--- a/src/components/map/map-control.tsx
+++ b/src/components/map/map-control.tsx
@@ -29,8 +29,10 @@ import LayerSelectorPanelFactory from './layer-selector-panel';
import MapLegendPanelFactory from './map-legend-panel';
import MapDrawPanelFactory from './map-draw-panel';
import LocalePanelFactory from './locale-panel';
-import {Datasets, Editor, MapControls} from 'reducers';
+import {MapControls} from 'reducers';
import {Layer} from '@kepler.gl/layers';
+import {Editor} from '@kepler.gl/types';
+import {Datasets} from 'reducers/table-utils/kepler-table';
interface StyledMapControlProps {
top?: number;
diff --git a/src/components/map/map-draw-panel.tsx b/src/components/map/map-draw-panel.tsx
index e21f11aa0..6af5b9a9b 100644
--- a/src/components/map/map-draw-panel.tsx
+++ b/src/components/map/map-draw-panel.tsx
@@ -34,7 +34,8 @@ import {MapControlButton} from 'components/common/styled-components';
import ToolbarItem from 'components/common/toolbar-item';
import MapControlTooltipFactory from './map-control-tooltip';
import MapControlToolbarFactory from './map-control-toolbar';
-import {Editor, MapControls} from 'reducers';
+import {MapControls} from 'reducers';
+import {Editor} from '@kepler.gl/types';
import {BaseProps} from 'components/common/icons/base';
MapDrawPanelFactory.deps = [MapControlTooltipFactory, MapControlToolbarFactory];
diff --git a/src/components/map/map-popover.tsx b/src/components/map/map-popover.tsx
index 6bbd85d17..59242e44c 100644
--- a/src/components/map/map-popover.tsx
+++ b/src/components/map/map-popover.tsx
@@ -26,7 +26,7 @@ import {ArrowLeft, ArrowRight, Pin} from 'components/common/icons';
import {injectIntl, IntlShape} from 'react-intl';
import {FormattedMessage} from '@kepler.gl/localization';
import Tippy from '@tippyjs/react/headless';
-import {LayerHoverProp} from 'utils/layer-utils';
+import {LayerHoverProp} from 'reducers/layer-utils';
const MAX_WIDTH = 500;
const MAX_HEIGHT = 600;
diff --git a/src/components/modal-container.tsx b/src/components/modal-container.tsx
index c88b687b2..2cabe2986 100644
--- a/src/components/modal-container.tsx
+++ b/src/components/modal-container.tsx
@@ -26,8 +26,8 @@ import document from 'global/document';
import {EXPORT_DATA_TYPE_OPTIONS, EXPORT_MAP_FORMATS} from '@kepler.gl/constants';
import ModalDialogFactory from './modals/modal-dialog';
-import {exportJson, exportHtml, exportData, exportImage, exportMap} from 'utils/export-utils';
-import {isValidMapInfo} from 'utils/map-info-utils';
+import {exportHtml, isValidMapInfo, exportMap, exportJson} from '@kepler.gl/utils';
+import {exportData} from 'reducers/export-utils';
// modals
import DeleteDatasetModalFactory from './modals/delete-data-modal';
@@ -58,8 +58,10 @@ import {
SHARE_MAP_ID,
OVERWRITE_MAP_ID
} from '@kepler.gl/constants';
-import {getFileFormatNames, getFileExtensions} from '../reducers/vis-state-selectors';
-import {MapState, MapStyle, UiState, VisState} from 'reducers';
+
+import {MapState} from '@kepler.gl/types';
+import {getFileFormatNames, getFileExtensions} from 'reducers/vis-state-selectors';
+import {MapStyle, UiState} from 'reducers';
import {OnSuccessCallBack, OnErrorCallBack} from 'actions';
import {ProviderState} from 'reducers/provider-state-updaters';
@@ -70,6 +72,7 @@ import * as ProviderActions from 'actions/provider-actions';
import {ModalDialogProps} from './common/modal';
import {Provider} from 'cloud-providers';
import {findDOMNode} from 'react-dom';
+import {VisState} from 'schemas';
const DataTableModalStyle = css`
top: 80px;
diff --git a/src/components/modals/add-map-style-modal.tsx b/src/components/modals/add-map-style-modal.tsx
index e9fa41f9d..3b91c8ec4 100644
--- a/src/components/modals/add-map-style-modal.tsx
+++ b/src/components/modals/add-map-style-modal.tsx
@@ -33,11 +33,12 @@ import {
import {media} from '@kepler.gl/styles';
// Utils
-import {transformRequest} from 'utils/map-style-utils/mapbox-utils';
+import {transformRequest} from '@kepler.gl/utils';
import {injectIntl, IntlShape} from 'react-intl';
import {FormattedMessage} from '@kepler.gl/localization';
-import {InputStyle, MapState} from 'reducers';
+import {InputStyle} from 'reducers';
import mapboxgl from 'mapbox-gl';
+import {MapState} from '@kepler.gl/types';
const MapH = 190;
const MapW = 264;
diff --git a/src/components/modals/data-table-modal.tsx b/src/components/modals/data-table-modal.tsx
index b3f64476b..383c9ce38 100644
--- a/src/components/modals/data-table-modal.tsx
+++ b/src/components/modals/data-table-modal.tsx
@@ -25,8 +25,7 @@ import DataTableFactory from 'components/common/data-table';
import {createSelector} from 'reselect';
import {renderedSize} from 'components/common/data-table/cell-size';
import CanvasHack from 'components/common/data-table/canvas';
-import {Datasets} from 'reducers';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import KeplerTable, {Datasets} from 'reducers/table-utils/kepler-table';
const dgSettings = {
sidePadding: '38px',
diff --git a/src/components/modals/delete-data-modal.tsx b/src/components/modals/delete-data-modal.tsx
index 4a738bdf0..bbc44de5b 100644
--- a/src/components/modals/delete-data-modal.tsx
+++ b/src/components/modals/delete-data-modal.tsx
@@ -23,7 +23,7 @@ import styled from 'styled-components';
import DatasetLabel from 'components/common/dataset-label';
import {FormattedMessage} from '@kepler.gl/localization';
import {Layer} from '@kepler.gl/layers';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import {KeplerTable} from 'reducers/table-utils';
const StyledMsg = styled.div`
margin-top: 24px;
diff --git a/src/components/modals/export-data-modal.tsx b/src/components/modals/export-data-modal.tsx
index 4bffbd2c3..4f67fcf39 100644
--- a/src/components/modals/export-data-modal.tsx
+++ b/src/components/modals/export-data-modal.tsx
@@ -31,7 +31,7 @@ import {
} from 'components/common/styled-components';
import {injectIntl, IntlShape} from 'react-intl';
import {FormattedMessage} from '@kepler.gl/localization';
-import {Datasets} from 'reducers';
+import {Datasets} from 'reducers/table-utils';
const getDataRowCount = (
datasets: Datasets,
diff --git a/src/components/modals/export-image-modal.tsx b/src/components/modals/export-image-modal.tsx
index b6a441868..d21bcc113 100644
--- a/src/components/modals/export-image-modal.tsx
+++ b/src/components/modals/export-image-modal.tsx
@@ -23,13 +23,16 @@ import styled from 'styled-components';
import ImagePreview from 'components/common/image-preview';
import {SetExportImageSettingUpdaterAction} from '../../actions';
-import {EXPORT_IMG_RATIO_OPTIONS, EXPORT_IMG_RESOLUTION_OPTIONS} from '@kepler.gl/constants';
+import {
+ EXPORT_IMG_RATIO_OPTIONS,
+ EXPORT_IMG_RESOLUTION_OPTIONS,
+ ExportImage
+} from '@kepler.gl/constants';
import {StyledModalContent, SelectionButton, CheckMark} from 'components/common/styled-components';
import Switch from 'components/common/switch';
import {injectIntl, IntlShape} from 'react-intl';
import {FormattedMessage} from '@kepler.gl/localization';
-import {ExportImage} from 'reducers';
const ImageOptionList = styled.div`
display: flex;
diff --git a/src/components/modals/load-data-modal.tsx b/src/components/modals/load-data-modal.tsx
index 4a0708065..deadd5ee2 100644
--- a/src/components/modals/load-data-modal.tsx
+++ b/src/components/modals/load-data-modal.tsx
@@ -29,7 +29,7 @@ import ModalTabsFactory from './modal-tabs';
import LoadingDialog from './loading-dialog';
import {LOADING_METHODS} from '@kepler.gl/constants';
-import {FileLoading} from 'reducers/vis-state-updaters';
+import {FileLoading} from '@kepler.gl/types';
/** @typedef {import('./load-data-modal').LoadDataModalProps} LoadDataModalProps */
diff --git a/src/components/modals/save-map-modal.tsx b/src/components/modals/save-map-modal.tsx
index ebce68e10..b98df4a80 100644
--- a/src/components/modals/save-map-modal.tsx
+++ b/src/components/modals/save-map-modal.tsx
@@ -25,7 +25,7 @@ import ImageModalContainer, {ImageModalContainerProps} from './image-modal-conta
import ProviderModalContainer, {ProviderModalContainerProps} from './provider-modal-container';
import StatusPanel, {UploadAnimation} from './status-panel';
-import {MAP_THUMBNAIL_DIMENSION, MAP_INFO_CHARACTER} from '@kepler.gl/constants';
+import {MAP_THUMBNAIL_DIMENSION, MAP_INFO_CHARACTER, ExportImage} from '@kepler.gl/constants';
import {
StyledModalContent,
@@ -37,7 +37,7 @@ import {
} from 'components/common/styled-components';
import ImagePreview from 'components/common/image-preview';
import {FormattedMessage} from '@kepler.gl/localization';
-import {ExportImage, MapInfo} from 'reducers';
+import {MapInfo} from '@kepler.gl/types';
import {Provider} from 'cloud-providers';
import {setMapInfo, cleanupExportImage as cleanupExportImageAction} from 'actions';
diff --git a/src/components/plot-container.tsx b/src/components/plot-container.tsx
index af8507834..4ee4843d1 100644
--- a/src/components/plot-container.tsx
+++ b/src/components/plot-container.tsx
@@ -24,16 +24,19 @@ import {createSelector} from 'reselect';
import styled from 'styled-components';
import {StaticMap} from 'react-map-gl';
import debounce from 'lodash.debounce';
-import {exportImageError} from 'utils/notifications-utils';
+import {
+ exportImageError,
+ scaleMapStyleByResolution,
+ getCenterAndZoomFromBounds,
+ convertToPng,
+ getScaleFromImageSize
+} from '@kepler.gl/utils';
+import {findMapBounds} from 'reducers/data-utils';
import MapContainerFactory from './map-container';
import MapsLayoutFactory from './maps-layout';
-import {convertToPng, getScaleFromImageSize} from 'utils/export-utils';
-import {scaleMapStyleByResolution} from 'utils/map-style-utils/mapbox-gl-style-editor';
-import {findMapBounds} from 'utils/data-utils';
-import {getCenterAndZoomFromBounds} from 'utils/projection-utils';
-import {GEOCODER_LAYER_ID} from '@kepler.gl/constants';
-import {ExportImage, SplitMap} from 'reducers';
+import {GEOCODER_LAYER_ID, ExportImage} from '@kepler.gl/constants';
+import {SplitMap} from '@kepler.gl/types';
import {setExportImageDataUri, setExportImageError, setExportImageSetting} from 'actions';
import {mapFieldsSelector} from './kepler-gl';
diff --git a/src/components/side-panel/common/dataset-title.tsx b/src/components/side-panel/common/dataset-title.tsx
index debe0fc61..38770835d 100644
--- a/src/components/side-panel/common/dataset-title.tsx
+++ b/src/components/side-panel/common/dataset-title.tsx
@@ -27,7 +27,7 @@ import {ArrowRight, Table, Trash} from 'components/common/icons';
import DatasetTagFactory from 'components/side-panel/common/dataset-tag';
import CustomPicker from '../layer-panel/custom-picker';
import {Portaled} from 'components';
-import {rgbToHex} from 'utils/color-utils';
+import {rgbToHex} from '@kepler.gl/utils';
import {
StyledDatasetTitleProps,
DatasetTitleProps,
diff --git a/src/components/side-panel/common/types.ts b/src/components/side-panel/common/types.ts
index 24a785ee1..62773b24e 100644
--- a/src/components/side-panel/common/types.ts
+++ b/src/components/side-panel/common/types.ts
@@ -1,9 +1,8 @@
import React, {MouseEvent} from 'react';
-import KeplerTable from 'utils/table-utils/kepler-table';
import {openDeleteModal} from 'actions/ui-state-actions';
import * as VisStateActions from 'actions/vis-state-actions';
-import {Datasets} from 'reducers';
import {ActionHandler} from 'actions';
+import KeplerTable, {Datasets} from 'reducers/table-utils/kepler-table';
export type DatasetInfoProps = {
dataset: KeplerTable;
diff --git a/src/components/side-panel/filter-manager.tsx b/src/components/side-panel/filter-manager.tsx
index 05263caa4..e09420dda 100644
--- a/src/components/side-panel/filter-manager.tsx
+++ b/src/components/side-panel/filter-manager.tsx
@@ -24,10 +24,11 @@ import {Button, SidePanelDivider, SidePanelSection} from 'components/common/styl
import {Add} from 'components/common/icons';
import SourceDataCatalogFactory from './common/source-data-catalog';
import FilterPanelFactory from './filter-panel/filter-panel';
-import {Datasets, Filter} from 'reducers';
+import {Filter} from '@kepler.gl/types';
import {Layer} from '@kepler.gl/layers';
import * as VisStateActions from 'actions/vis-state-actions';
import {ActionHandler} from 'actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type FilterManagerProps = {
filters: Filter[];
diff --git a/src/components/side-panel/filter-panel/filter-panel-header.tsx b/src/components/side-panel/filter-panel/filter-panel-header.tsx
index 6111ec5f7..a24d42b2b 100644
--- a/src/components/side-panel/filter-panel/filter-panel-header.tsx
+++ b/src/components/side-panel/filter-panel/filter-panel-header.tsx
@@ -22,11 +22,10 @@ import React, {ComponentType} from 'react';
import styled from 'styled-components';
import PanelHeaderActionFactory from 'components/side-panel/panel-header-action';
import {Trash} from 'components/common/icons';
-import {createLinearGradient} from 'utils/color-utils';
+import {createLinearGradient} from '@kepler.gl/utils';
import {StyledPanelHeader, StyledPanelHeaderProps} from 'components/common/styled-components';
-import {Filter} from 'reducers';
-import {RGBColor} from '@kepler.gl/types';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import {RGBColor, Filter} from '@kepler.gl/types';
+import KeplerTable from 'reducers/table-utils/kepler-table';
interface StyledFilterHeaderProps extends StyledPanelHeaderProps {
$labelRCGColorValues: RGBColor[];
diff --git a/src/components/side-panel/filter-panel/filter-panel.tsx b/src/components/side-panel/filter-panel/filter-panel.tsx
index 1c87afc04..723853eaf 100644
--- a/src/components/side-panel/filter-panel/filter-panel.tsx
+++ b/src/components/side-panel/filter-panel/filter-panel.tsx
@@ -30,8 +30,7 @@ import SingleSelectFilterPanelFactory from 'components/filters/filter-panels/sin
import MultiSelectFilterPanelFactory from 'components/filters/filter-panels/multi-select-filter-panel';
import RangeFilterPanelFactory from 'components/filters/filter-panels/range-filter-panel';
import PolygonFilterPanelFactory from 'components/filters/filter-panels/polygon-filter-panel';
-import {Filter} from 'reducers/vis-state-updaters';
-import {Field} from 'utils/table-utils/kepler-table';
+import {Field, Filter} from '@kepler.gl/types';
import {FilterPanelProps} from 'components/filters/filter-panels/types';
import {Layer} from '@kepler.gl/layers';
diff --git a/src/components/side-panel/interaction-manager.tsx b/src/components/side-panel/interaction-manager.tsx
index 5a8765612..e6e788509 100644
--- a/src/components/side-panel/interaction-manager.tsx
+++ b/src/components/side-panel/interaction-manager.tsx
@@ -19,9 +19,10 @@
// THE SOFTWARE.
import React from 'react';
-import {Datasets, InteractionConfig} from 'reducers';
+import {InteractionConfig} from '@kepler.gl/types';
import InteractionPanelFactory from './interaction-panel/interaction-panel';
import * as VisStateActions from 'actions/vis-state-actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type InteractionManagerProps = {
interactionConfig: InteractionConfig;
diff --git a/src/components/side-panel/interaction-panel/brush-config.tsx b/src/components/side-panel/interaction-panel/brush-config.tsx
index 1cf1bcef5..35caf6fb4 100644
--- a/src/components/side-panel/interaction-panel/brush-config.tsx
+++ b/src/components/side-panel/interaction-panel/brush-config.tsx
@@ -22,7 +22,7 @@ import React from 'react';
import RangeSliderFactory from 'components/common/range-slider';
import {PanelLabel, SidePanelSection} from 'components/common/styled-components';
-import {BRUSH_CONFIG} from 'utils/interaction-utils';
+import {BRUSH_CONFIG} from 'reducers/interaction-utils';
import {FormattedMessage} from '@kepler.gl/localization';
BrushConfigFactory.deps = [RangeSliderFactory];
diff --git a/src/components/side-panel/interaction-panel/tooltip-config.tsx b/src/components/side-panel/interaction-panel/tooltip-config.tsx
index d6ab22209..7a6356e51 100644
--- a/src/components/side-panel/interaction-panel/tooltip-config.tsx
+++ b/src/components/side-panel/interaction-panel/tooltip-config.tsx
@@ -35,8 +35,7 @@ import Switch from 'components/common/switch';
import ItemSelector from 'components/common/item-selector/item-selector';
import {COMPARE_TYPES, GEOCODER_DATASET_NAME} from '@kepler.gl/constants';
import FieldSelectorFactory from '../../common/field-selector';
-import KeplerTable from 'utils/table-utils/kepler-table';
-import {Datasets} from 'reducers';
+import KeplerTable, {Datasets} from 'reducers/table-utils/kepler-table';
const TooltipConfigWrapper = styled.div`
.item-selector > div > div {
diff --git a/src/components/side-panel/interaction-panel/tooltip-config/tooltip-chicklet.tsx b/src/components/side-panel/interaction-panel/tooltip-config/tooltip-chicklet.tsx
index 69dfda696..58ce5df33 100644
--- a/src/components/side-panel/interaction-panel/tooltip-config/tooltip-chicklet.tsx
+++ b/src/components/side-panel/interaction-panel/tooltip-config/tooltip-chicklet.tsx
@@ -26,7 +26,7 @@ import DropdownList from 'components/common/item-selector/dropdown-list';
import {FormattedMessage} from '@kepler.gl/localization';
import onClickOutside from 'react-onclickoutside';
import {FIELD_OPTS, TOOLTIP_FORMATS, TOOLTIP_FORMAT_TYPES, TOOLTIP_KEY} from '@kepler.gl/constants';
-import {getFormatter} from 'utils/data-utils';
+import {getFormatter} from '@kepler.gl/utils';
import TippyTooltip from 'components/common/tippy-tooltip';
interface TooltipChickletProps {
diff --git a/src/components/side-panel/layer-manager.tsx b/src/components/side-panel/layer-manager.tsx
index e68415c02..a199f5845 100644
--- a/src/components/side-panel/layer-manager.tsx
+++ b/src/components/side-panel/layer-manager.tsx
@@ -35,13 +35,13 @@ import ItemSelector from 'components/common/item-selector/item-selector';
import {PanelLabel, SidePanelDivider, SidePanelSection} from 'components/common/styled-components';
import {LAYER_BLENDINGS} from '@kepler.gl/constants';
-import {Datasets} from 'reducers';
import {Layer, LayerClassesType} from '@kepler.gl/layers';
import * as UiStateActions from 'actions/ui-state-actions';
import * as VisStateActions from 'actions/vis-state-actions';
import {SidePanelItem} from 'components/types';
import {LayerPanelListView} from 'reducers/ui-state-updaters';
import {ActionHandler} from 'actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type LayerBlendingSelectorProps = {
layerBlending: string;
diff --git a/src/components/side-panel/layer-panel/add-layer-button.tsx b/src/components/side-panel/layer-panel/add-layer-button.tsx
index 0852ff68a..699961bbc 100644
--- a/src/components/side-panel/layer-panel/add-layer-button.tsx
+++ b/src/components/side-panel/layer-panel/add-layer-button.tsx
@@ -29,7 +29,7 @@ import {Button} from 'components/common/styled-components';
import {DatasetSquare} from 'components';
import Typeahead from 'components/common/item-selector/typeahead';
import Accessor from 'components/common/item-selector/accessor';
-import {Datasets} from 'reducers';
+import {Datasets} from 'reducers/table-utils/kepler-table';
import {RGBColor} from '@kepler.gl/types';
type AddLayerButtonProps = {
diff --git a/src/components/side-panel/layer-panel/color-range-selector.tsx b/src/components/side-panel/layer-panel/color-range-selector.tsx
index ec43afc8f..dec9d743a 100644
--- a/src/components/side-panel/layer-panel/color-range-selector.tsx
+++ b/src/components/side-panel/layer-panel/color-range-selector.tsx
@@ -29,8 +29,7 @@ import Switch from 'components/common/switch';
import ColorPalette from './color-palette';
import CustomPalette from './custom-palette';
import {COLOR_RANGES, ColorRange} from '@kepler.gl/constants';
-import {numberSort} from 'utils/data-utils';
-import {reverseColorRange} from 'utils/color-utils';
+import {reverseColorRange, numberSort} from '@kepler.gl/utils';
import {FormattedMessage} from '@kepler.gl/localization';
import {NestedPartial, ColorUI} from '@kepler.gl/types';
diff --git a/src/components/side-panel/layer-panel/color-selector.tsx b/src/components/side-panel/layer-panel/color-selector.tsx
index 1db3d77b4..caef409f5 100644
--- a/src/components/side-panel/layer-panel/color-selector.tsx
+++ b/src/components/side-panel/layer-panel/color-selector.tsx
@@ -20,7 +20,7 @@
import React, {Component, createRef, MouseEvent} from 'react';
import styled from 'styled-components';
-import {rgbToHex} from 'utils/color-utils';
+import {rgbToHex} from '@kepler.gl/utils';
import SingleColorPalette from './single-color-palette';
import ColorRangeSelector from './color-range-selector';
import ColorPalette from './color-palette';
diff --git a/src/components/side-panel/layer-panel/column-selector.tsx b/src/components/side-panel/layer-panel/column-selector.tsx
index d4120bc55..10fecda3c 100644
--- a/src/components/side-panel/layer-panel/column-selector.tsx
+++ b/src/components/side-panel/layer-panel/column-selector.tsx
@@ -25,7 +25,7 @@ import {PanelLabel} from 'components/common/styled-components';
import FieldSelectorFactory from 'components/common/field-selector';
import {validateColumn} from 'reducers/vis-state-merger';
import {LayerColumn, LayerColumns} from '@kepler.gl/layers';
-import {Field, FieldPair} from 'utils/table-utils/kepler-table';
+import {Field, FieldPair} from '@kepler.gl/types';
type Pair = {
name: string;
diff --git a/src/components/side-panel/layer-panel/custom-palette.tsx b/src/components/side-panel/layer-panel/custom-palette.tsx
index f4f06b920..ceb82e79a 100644
--- a/src/components/side-panel/layer-panel/custom-palette.tsx
+++ b/src/components/side-panel/layer-panel/custom-palette.tsx
@@ -28,7 +28,7 @@ import {Button, InlineInput} from 'components/common/styled-components';
import {VertDots, Trash} from 'components/common/icons';
import ColorPalette from './color-palette';
import CustomPicker from './custom-picker';
-import {arrayMove} from 'utils/data-utils';
+import {arrayMove} from '@kepler.gl/utils';
import {ColorRange} from '@kepler.gl/constants';
import {NestedPartial} from '@kepler.gl/types';
diff --git a/src/components/side-panel/layer-panel/dataset-layer-group.tsx b/src/components/side-panel/layer-panel/dataset-layer-group.tsx
index be5efdd4b..373f6f958 100644
--- a/src/components/side-panel/layer-panel/dataset-layer-group.tsx
+++ b/src/components/side-panel/layer-panel/dataset-layer-group.tsx
@@ -21,11 +21,11 @@
import React, {useMemo} from 'react';
import DatasetLayerSectionFactory from './dataset-layer-section';
-import {Datasets} from 'reducers';
import {Layer, LayerClassesType} from '@kepler.gl/layers';
import * as UiStateActions from 'actions/ui-state-actions';
import * as VisStateActions from 'actions/vis-state-actions';
import {ActionHandler} from 'actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type DatasetLayerGroupProps = {
datasets: Datasets;
diff --git a/src/components/side-panel/layer-panel/dataset-layer-section.tsx b/src/components/side-panel/layer-panel/dataset-layer-section.tsx
index 2f418baf8..75d608be7 100644
--- a/src/components/side-panel/layer-panel/dataset-layer-section.tsx
+++ b/src/components/side-panel/layer-panel/dataset-layer-section.tsx
@@ -24,10 +24,10 @@ import styled from 'styled-components';
import SourceDataCatalogFactory from '../common/source-data-catalog';
import LayerListFactory from './layer-list';
import {Layer, LayerClassesType} from '@kepler.gl/layers';
-import KeplerTable from 'utils/table-utils/kepler-table';
import * as UiStateActions from 'actions/ui-state-actions';
import * as VisStateActions from 'actions/vis-state-actions';
import {ActionHandler} from 'actions';
+import KeplerTable from 'reducers/table-utils/kepler-table';
type DatasetLayerSectionProps = {
dataset: KeplerTable;
diff --git a/src/components/side-panel/layer-panel/dataset-section.tsx b/src/components/side-panel/layer-panel/dataset-section.tsx
index 485f1da79..9f297b455 100644
--- a/src/components/side-panel/layer-panel/dataset-section.tsx
+++ b/src/components/side-panel/layer-panel/dataset-section.tsx
@@ -25,10 +25,10 @@ import {Add} from 'components/common/icons';
import {Button} from 'components/common/styled-components';
import SourceDataCatalogFactory from '../common/source-data-catalog';
-import {Datasets} from 'reducers';
import * as UiStateActions from 'actions/ui-state-actions';
import * as VisStateActions from 'actions/vis-state-actions';
import {ActionHandler} from 'actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type AddDataButtonProps = {
onClick: () => void;
diff --git a/src/components/side-panel/layer-panel/dimension-scale-selector.tsx b/src/components/side-panel/layer-panel/dimension-scale-selector.tsx
index a737d1cab..5aaa32c91 100644
--- a/src/components/side-panel/layer-panel/dimension-scale-selector.tsx
+++ b/src/components/side-panel/layer-panel/dimension-scale-selector.tsx
@@ -22,7 +22,7 @@ import React from 'react';
import {PanelLabel, SidePanelSection} from 'components/common/styled-components';
import ItemSelector from 'components/common/item-selector/item-selector';
import {FormattedMessage} from '@kepler.gl/localization';
-import {camelize} from 'utils/utils';
+import {camelize} from '@kepler.gl/utils';
type DimensionScaleSelectorProps = {
label: string;
diff --git a/src/components/side-panel/layer-panel/layer-column-config.tsx b/src/components/side-panel/layer-panel/layer-column-config.tsx
index 020612347..0e7b7d0f9 100644
--- a/src/components/side-panel/layer-panel/layer-column-config.tsx
+++ b/src/components/side-panel/layer-panel/layer-column-config.tsx
@@ -24,7 +24,7 @@ import {FormattedMessage} from '@kepler.gl/localization';
import {PanelLabel, SidePanelSection} from 'components/common/styled-components';
import ColumnSelectorFactory from './column-selector';
import {ColumnPairs, Layer, LayerColumns, LayerBaseConfig} from '@kepler.gl/layers';
-import {Field, FieldPair} from 'utils/table-utils/kepler-table';
+import {Field, FieldPair} from '@kepler.gl/types';
type LayerColumnConfigProps = {
columnPairs?: ColumnPairs | null;
diff --git a/src/components/side-panel/layer-panel/layer-configurator.tsx b/src/components/side-panel/layer-panel/layer-configurator.tsx
index d1edfef97..02892c53c 100644
--- a/src/components/side-panel/layer-panel/layer-configurator.tsx
+++ b/src/components/side-panel/layer-panel/layer-configurator.tsx
@@ -38,7 +38,7 @@ import LayerConfigGroupFactory, {ConfigGroupCollapsibleContent} from './layer-co
import TextLabelPanelFactory from './text-label-panel';
import HowToButton from './how-to-button';
-import {capitalizeFirstLetter} from 'utils/utils';
+import {capitalizeFirstLetter} from '@kepler.gl/utils';
import {CHANNEL_SCALE_SUPPORTED_FIELDS, ColorRange} from '@kepler.gl/constants';
import {
@@ -49,11 +49,10 @@ import {
AggregationLayer
} from '@kepler.gl/layers';
-import {Datasets} from 'reducers';
-import {NestedPartial, RGBColor, LayerVisConfig, ColorUI} from '@kepler.gl/types';
-import {Field} from 'utils/table-utils/kepler-table';
+import {NestedPartial, RGBColor, LayerVisConfig, ColorUI, Field} from '@kepler.gl/types';
import {toggleModal} from 'actions/ui-state-actions';
import {ActionHandler} from 'actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type LayerConfiguratorProps = {
layer: Layer;
diff --git a/src/components/side-panel/layer-panel/layer-list.tsx b/src/components/side-panel/layer-panel/layer-list.tsx
index 85f75190e..0c3683d9f 100644
--- a/src/components/side-panel/layer-panel/layer-list.tsx
+++ b/src/components/side-panel/layer-panel/layer-list.tsx
@@ -19,15 +19,15 @@
// THE SOFTWARE.
import React, {useCallback, useMemo, useState} from 'react';
-import {arrayMove} from 'utils/data-utils';
import styled from 'styled-components';
import classnames from 'classnames';
import {SortableContainer, SortableElement} from 'react-sortable-hoc';
import LayerPanelFactory from './layer-panel';
-import {Datasets} from 'reducers';
import {Layer, LayerClassesType} from '@kepler.gl/layers';
import * as UiStateActions from 'actions/ui-state-actions';
import * as VisStateActions from 'actions/vis-state-actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
+import {arrayMove} from '@kepler.gl/utils';
type LayerListProps = {
datasets: Datasets;
diff --git a/src/components/side-panel/layer-panel/layer-panel.tsx b/src/components/side-panel/layer-panel/layer-panel.tsx
index b0cc369da..c767ad065 100644
--- a/src/components/side-panel/layer-panel/layer-panel.tsx
+++ b/src/components/side-panel/layer-panel/layer-panel.tsx
@@ -29,12 +29,12 @@ import styled from 'styled-components';
import LayerConfiguratorFactory from './layer-configurator';
import LayerPanelHeaderFactory from './layer-panel-header';
-import {Datasets} from 'reducers';
import {NestedPartial, LayerVisConfig, ColorUI} from '@kepler.gl/types';
import {Layer, LayerBaseConfig} from '@kepler.gl/layers';
import {toggleModal} from 'actions/ui-state-actions';
import * as VisStateActions from 'actions/vis-state-actions';
import {ActionHandler} from 'actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type LayerPanelProps = {
className?: string;
diff --git a/src/components/side-panel/layer-panel/layer-type-selector.tsx b/src/components/side-panel/layer-panel/layer-type-selector.tsx
index aed909263..ce0360ad8 100644
--- a/src/components/side-panel/layer-panel/layer-type-selector.tsx
+++ b/src/components/side-panel/layer-panel/layer-type-selector.tsx
@@ -27,7 +27,7 @@ import ItemSelector from 'components/common/item-selector/item-selector';
import {SidePanelSection} from 'components/common/styled-components';
import {Layer} from '@kepler.gl/layers';
-import {Datasets} from 'reducers';
+import {Datasets} from 'reducers/table-utils/kepler-table';
type Option = {
id: string;
diff --git a/src/components/side-panel/layer-panel/single-color-palette.tsx b/src/components/side-panel/layer-panel/single-color-palette.tsx
index 0a6e511f3..a6949f9ec 100644
--- a/src/components/side-panel/layer-panel/single-color-palette.tsx
+++ b/src/components/side-panel/layer-panel/single-color-palette.tsx
@@ -21,7 +21,7 @@
import React, {MouseEvent} from 'react';
import {range} from 'd3-array';
import styled from 'styled-components';
-import {hexToRgb} from 'utils/color-utils';
+import {hexToRgb} from '@kepler.gl/utils';
import {ColorsByTheme, Themes, ColorRange} from '@kepler.gl/constants';
import {RGBColor} from '@kepler.gl/types';
diff --git a/src/components/side-panel/layer-panel/text-label-panel.tsx b/src/components/side-panel/layer-panel/text-label-panel.tsx
index 2f5c51ea2..78f549203 100644
--- a/src/components/side-panel/layer-panel/text-label-panel.tsx
+++ b/src/components/side-panel/layer-panel/text-label-panel.tsx
@@ -38,8 +38,7 @@ import LayerConfigGroupFactory, {
import RangeSliderFactory from 'components/common/range-slider';
import FieldSelectorFactory from '../../common/field-selector';
-import {Field} from 'utils/table-utils/kepler-table';
-import {RGBColor, LayerTextLabel} from '@kepler.gl/types';
+import {RGBColor, LayerTextLabel, Field} from '@kepler.gl/types';
import {LAYER_TEXT_CONFIGS} from '@kepler.gl/constants';
type TextLabelPanelProps = {
diff --git a/src/components/side-panel/layer-panel/vis-config-by-field-selector.tsx b/src/components/side-panel/layer-panel/vis-config-by-field-selector.tsx
index af468e5cc..aa8a01b20 100644
--- a/src/components/side-panel/layer-panel/vis-config-by-field-selector.tsx
+++ b/src/components/side-panel/layer-panel/vis-config-by-field-selector.tsx
@@ -21,12 +21,13 @@
import React, {Component} from 'react';
import {FormattedMessage, injectIntl, WrappedComponentProps} from 'react-intl';
+import {Field} from '@kepler.gl/types';
+
import {PanelLabel, PanelLabelWrapper, SidePanelSection} from 'components/common/styled-components';
import InfoHelperFactory from 'components/common/info-helper';
import DimensionScaleSelector from './dimension-scale-selector';
-import {camelize} from 'utils/utils';
+import {camelize} from '@kepler.gl/utils';
import FieldSelectorFactory from '../../common/field-selector';
-import {Field} from 'utils/table-utils/kepler-table';
type VisConfigByFieldSelectorProps = {
channel: string;
diff --git a/src/components/side-panel/layer-panel/vis-config-slider.tsx b/src/components/side-panel/layer-panel/vis-config-slider.tsx
index c6d025a5c..ae4b28dc9 100644
--- a/src/components/side-panel/layer-panel/vis-config-slider.tsx
+++ b/src/components/side-panel/layer-panel/vis-config-slider.tsx
@@ -26,9 +26,9 @@ import RangeSliderFactory from 'components/common/range-slider';
import {FormattedMessage} from '@kepler.gl/localization';
import {KeyEvent} from '@kepler.gl/constants';
import {Checkbox} from 'components';
-import {clamp} from 'utils/data-utils';
-import {isInRange} from 'utils/filter-utils';
import {Layer, LayerBaseConfig} from '@kepler.gl/layers';
+import {isInRange} from 'reducers/filter-utils';
+import {clamp} from '@kepler.gl/utils';
type LazyInputProps = {
value: string | [string, string];
diff --git a/src/components/side-panel/layer-panel/vis-config-switch.tsx b/src/components/side-panel/layer-panel/vis-config-switch.tsx
index 064a461c7..6d6bf072d 100644
--- a/src/components/side-panel/layer-panel/vis-config-switch.tsx
+++ b/src/components/side-panel/layer-panel/vis-config-switch.tsx
@@ -23,8 +23,8 @@ import styled from 'styled-components';
import InfoHelperFactory from 'components/common/info-helper';
import Switch from 'components/common/switch';
import {SidePanelSection, PanelLabel} from 'components/common/styled-components';
-import {capitalizeFirstLetter} from 'utils/utils';
import {FormattedMessage} from '@kepler.gl/localization';
+import {capitalizeFirstLetter} from '@kepler.gl/utils';
import {Layer} from '@kepler.gl/layers';
type VisConfigSwitchProps = {
diff --git a/src/components/side-panel/map-style-panel/map-layer-selector.tsx b/src/components/side-panel/map-style-panel/map-layer-selector.tsx
index b3331d52f..e7a8417c0 100644
--- a/src/components/side-panel/map-style-panel/map-layer-selector.tsx
+++ b/src/components/side-panel/map-style-panel/map-layer-selector.tsx
@@ -31,7 +31,7 @@ import {
CenterFlexbox
} from 'components/common/styled-components';
import {FormattedMessage} from '@kepler.gl/localization';
-import {camelize} from 'utils/utils';
+import {camelize} from '@kepler.gl/utils';
import {VisibleLayerGroups} from 'reducers';
import {BaseProps} from 'components/common/icons/base';
diff --git a/src/components/types.ts b/src/components/types.ts
index 145520d34..1dc950211 100644
--- a/src/components/types.ts
+++ b/src/components/types.ts
@@ -1,12 +1,14 @@
import {ComponentType} from 'react';
-import {Datasets, Filter, InteractionConfig, MapStyle} from '../reducers';
+import {MapStyle} from 'reducers';
import {Layer, LayerClassesType} from '@kepler.gl/layers';
+import {Filter, InteractionConfig} from '@kepler.gl/types';
import {UiState} from 'reducers/ui-state-updaters';
import * as MapStyleActions from 'actions/map-style-actions';
import * as VisStateActions from 'actions/vis-state-actions';
import * as MapStateActions from 'actions/map-state-actions';
import * as UIStateActions from 'actions/ui-state-actions';
+import {Datasets} from 'reducers/table-utils/kepler-table';
export type SidePanelItem = {
id: string;
diff --git a/src/constants/package.json b/src/constants/package.json
index d1d9f590f..6ba27af72 100644
--- a/src/constants/package.json
+++ b/src/constants/package.json
@@ -5,7 +5,7 @@
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
"main": "dist/index.js",
- "types": "index.d.ts",
+ "types": "dist/index.d.ts",
"keywords": [
"babel",
"es6",
@@ -38,15 +38,6 @@
"react-map-gl-draw": "0.14.8",
"@kepler.gl/types": "2.5.5"
},
- "exports": {
- ".": "./dist/index.js",
- "./*": "./dist/*"
- },
- "typesVersions": {
- "*": {
- "*": ["dist/*"]
- }
- },
"nyc": {
"sourceMap": false,
"instrument": false
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index c54c3e0d3..e5f85ec1c 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -680,6 +680,27 @@ export const EXPORT_IMG_RATIOS = keyMirror({
CUSTOM: null
});
+export type ExportImage = {
+ ratio: keyof typeof EXPORT_IMG_RATIOS;
+ resolution: keyof typeof RESOLUTIONS;
+ legend: boolean;
+ mapH: number;
+ mapW: number;
+ imageSize: {
+ zoomOffset: number;
+ scale: number;
+ imageW: number;
+ imageH: number;
+ };
+ // exporting state
+ imageDataUri: string;
+ exporting: boolean;
+ processing: boolean;
+ error: Error | false;
+ // This field was not in the .d.ts file
+ center: boolean;
+};
+
export type ImageRatioOption = {
id: keyof typeof EXPORT_IMG_RATIOS;
label: string;
diff --git a/src/constants/tsconfig.production.json b/src/constants/tsconfig.production.json
index 6eb667212..0779deeda 100644
--- a/src/constants/tsconfig.production.json
+++ b/src/constants/tsconfig.production.json
@@ -27,6 +27,9 @@
"*": ["*"]
}
},
- "include": ["src"],
- "exclude": ["*/actions/**/*", "*/utils/**/*", "../components/**/*"]
+ "include": [
+ "src"
+ ],
+ "exclude": [
+ ]
}
diff --git a/src/deckgl-layers/package.json b/src/deckgl-layers/package.json
index 8692b7ed1..227e010d1 100644
--- a/src/deckgl-layers/package.json
+++ b/src/deckgl-layers/package.json
@@ -5,7 +5,7 @@
"description": "kepler.gl constants used by kepler.gl components, actions and reducers",
"license": "MIT",
"main": "dist/index.js",
- "types": "dist/deckgl-layers/src/index.d.ts",
+ "types": "index.d.ts",
"keywords": [
"babel",
"es6",
@@ -49,6 +49,15 @@
"@kepler.gl/constants": "2.5.5",
"lodash.memoize": "^4.1.2"
},
+ "exports": {
+ ".": "./dist/index.js",
+ "./*": "./dist/*"
+ },
+ "typesVersions": {
+ "*": {
+ "*": ["dist/*"]
+ }
+ },
"nyc": {
"sourceMap": false,
"instrument": false
diff --git a/src/deckgl-layers/src/layer-utils/cpu-aggregator.ts b/src/deckgl-layers/src/layer-utils/cpu-aggregator.ts
index 0d4998f2d..7cd38ed1d 100644
--- a/src/deckgl-layers/src/layer-utils/cpu-aggregator.ts
+++ b/src/deckgl-layers/src/layer-utils/cpu-aggregator.ts
@@ -22,7 +22,7 @@
import {AGGREGATION_OPERATION, _BinSorter as BinSorter} from '@deck.gl/aggregation-layers';
import {console as Console} from 'global/window';
-import {aggregate} from '../../../utils/aggregate-utils';
+import {aggregate} from '@kepler.gl/utils';
import {AGGREGATION_TYPES, SCALE_FUNC} from '@kepler.gl/constants';
import {RGBAColor} from '@kepler.gl/types';
diff --git a/src/deckgl-layers/tsconfig.production.json b/src/deckgl-layers/tsconfig.production.json
index 398acb540..ca61f25dd 100644
--- a/src/deckgl-layers/tsconfig.production.json
+++ b/src/deckgl-layers/tsconfig.production.json
@@ -22,9 +22,9 @@
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
- "baseUrl": "../../src", //TODO change once all dependencies are isolated
+ "baseUrl": "./src", //TODO change once all dependencies are isolated
"paths": {
- "@kepler.gl/deckgl-layers": ["deckgl-layers/src"] //TODO change once all dependencies are isolated
+ "*": ["*"] //TODO change once all dependencies are isolated
}
},
"include": ["src"]
diff --git a/src/index.js b/src/index.js
index 99b3af1cc..7fe786a21 100644
--- a/src/index.js
+++ b/src/index.js
@@ -46,7 +46,7 @@ export * from './styles';
export * from '@kepler.gl/middleware';
// Utils
-export * from './utils';
+export * from '@kepler.gl/utils';
// Default export
export {default} from './components';
diff --git a/src/layers/src/aggregation-layer.ts b/src/layers/src/aggregation-layer.ts
index b4c22f969..3981720bd 100644
--- a/src/layers/src/aggregation-layer.ts
+++ b/src/layers/src/aggregation-layer.ts
@@ -27,8 +27,7 @@ import Layer, {
VisualChannelDescription,
VisualChannels
} from './base-layer';
-import {hexToRgb} from '../../utils/color-utils';
-import {aggregate} from '../../utils/aggregate-utils';
+import {hexToRgb, aggregate} from '@kepler.gl/utils';
import {
HIGHLIGH_COLOR_3D,
CHANNEL_SCALES,
@@ -36,9 +35,8 @@ import {
DEFAULT_AGGREGATION,
ColorRange
} from '@kepler.gl/constants';
-import {Datasets} from 'reducers';
import {Merge} from '@kepler.gl/types';
-import {KeplerTable} from '../../utils';
+import KeplerTable, {Datasets} from 'reducers/table-utils/kepler-table';
type AggregationLayerColumns = {
lat: LayerColumn;
diff --git a/src/layers/src/arc-layer/arc-layer.ts b/src/layers/src/arc-layer/arc-layer.ts
index f8477df51..e3185bd52 100644
--- a/src/layers/src/arc-layer/arc-layer.ts
+++ b/src/layers/src/arc-layer/arc-layer.ts
@@ -28,14 +28,13 @@ import Layer, {
import {BrushingExtension} from '@deck.gl/extensions';
import {ArcLayer as DeckArcLayer} from '@deck.gl/layers';
-import {hexToRgb} from 'utils/color-utils';
+import {hexToRgb} from '@kepler.gl/utils';
import ArcLayerIcon from './arc-layer-icon';
import {
DEFAULT_LAYER_COLOR,
ColorRange,
PROJECTED_PIXEL_SIZE_MULTIPLIER
} from '@kepler.gl/constants';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
import {
RGBColor,
@@ -45,7 +44,8 @@ import {
VisConfigNumber,
VisConfigRange
} from '@kepler.gl/types';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import KeplerTable from 'reducers/table-utils/kepler-table';
export type ArcLayerVisConfigSettings = {
opacity: VisConfigNumber;
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index 974481cca..924930e7c 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+import React from 'react';
import {console as Console} from 'global/window';
import keymirror from 'keymirror';
import {DataFilterExtension} from '@deck.gl/extensions';
@@ -48,14 +49,8 @@ import {
PROJECTED_PIXEL_SIZE_MULTIPLIER
} from '@kepler.gl/constants';
-import {generateHashId, isPlainObject} from 'utils/utils';
-
-import {getLatLngBounds, notNullorUndefined} from 'utils/data-utils';
-import {getSampleData} from 'utils/table-utils/data-container-utils';
+import {generateHashId, getColorGroupByName, reverseColorRange, hexToRgb} from '@kepler.gl/utils';
-import {hexToRgb, getColorGroupByName, reverseColorRange} from 'utils/color-utils';
-
-import {MapState, Filter, Datasets} from 'reducers';
import {
RGBColor,
RGBAColor,
@@ -64,12 +59,14 @@ import {
LayerTextLabel,
ColorUI,
LayerVisConfig,
- LayerVisConfigSettings
+ LayerVisConfigSettings,
+ Field,
+ MapState,
+ Filter
} from '@kepler.gl/types';
-import {KeplerTable} from '../../utils';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
-import {Field, GpuFilter} from 'utils/table-utils/kepler-table';
-import React from 'react';
+import KeplerTable, {Datasets, GpuFilter} from 'reducers/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import {getLatLngBounds, getSampleData, isPlainObject, notNullorUndefined} from '@kepler.gl/utils';
export type LayerColumn = {value: string | null; fieldIdx: number; optional?: boolean};
diff --git a/src/layers/src/geojson-layer/geojson-layer.ts b/src/layers/src/geojson-layer/geojson-layer.ts
index 9235b0c34..d2e5fe769 100644
--- a/src/layers/src/geojson-layer/geojson-layer.ts
+++ b/src/layers/src/geojson-layer/geojson-layer.ts
@@ -55,8 +55,8 @@ import {
Merge,
RGBColor
} from '@kepler.gl/types';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
-import {KeplerTable} from '../../../utils';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import KeplerTable from 'reducers/table-utils/kepler-table';
const SUPPORTED_ANALYZER_TYPES = {
[DATA_TYPES.GEOMETRY]: true,
diff --git a/src/layers/src/geojson-layer/geojson-utils.ts b/src/layers/src/geojson-layer/geojson-utils.ts
index bb442f990..8f1d2a6c5 100644
--- a/src/layers/src/geojson-layer/geojson-utils.ts
+++ b/src/layers/src/geojson-layer/geojson-utils.ts
@@ -22,8 +22,8 @@ import wktParser from 'wellknown';
import normalize from '@mapbox/geojson-normalize';
import bbox from '@turf/bbox';
-import {getSampleData} from '../../../utils/data-utils';
import {Feature, BBox} from 'geojson';
+import {getSampleData} from '@kepler.gl/utils';
export type GetFeature = (d: any) => Feature;
export type GeojsonDataMaps = Array<Feature | null>;
diff --git a/src/layers/src/grid-layer/grid-utils.ts b/src/layers/src/grid-layer/grid-utils.ts
index 2e285d4be..84c2d972d 100644
--- a/src/layers/src/grid-layer/grid-utils.ts
+++ b/src/layers/src/grid-layer/grid-utils.ts
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import {WebMercatorViewport} from '@deck.gl/core';
-import {MapState} from '../../../reducers';
+import {MapState} from '@kepler.gl/types';
/**
* top left of the grid to a square polygon for the hover layer
diff --git a/src/layers/src/h3-hexagon-layer/h3-hexagon-layer.ts b/src/layers/src/h3-hexagon-layer/h3-hexagon-layer.ts
index ff08fb1e6..2809f5e96 100644
--- a/src/layers/src/h3-hexagon-layer/h3-hexagon-layer.ts
+++ b/src/layers/src/h3-hexagon-layer/h3-hexagon-layer.ts
@@ -25,7 +25,6 @@ import Layer, {
LayerCoverageConfig,
LayerSizeConfig
} from '../base-layer';
-import {findDefaultColorField} from 'utils/dataset-utils';
import {GeoJsonLayer} from '@deck.gl/layers';
import {H3HexagonLayer} from '@deck.gl/geo-layers';
import {EnhancedColumnLayer} from '@kepler.gl/deckgl-layers';
@@ -33,7 +32,6 @@ import {getCentroid, idToPolygonGeo, h3IsValid, getHexFields, Centroid} from './
import H3HexagonLayerIcon from './h3-hexagon-layer-icon';
import {CHANNEL_SCALES, HIGHLIGH_COLOR_3D, ColorRange} from '@kepler.gl/constants';
-import {createDataContainer} from 'utils/table-utils';
import {
VisConfigBoolean,
VisConfigColorRange,
@@ -41,8 +39,10 @@ import {
VisConfigRange,
Merge
} from '@kepler.gl/types';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
-import {KeplerTable} from '../../../utils';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import {findDefaultColorField} from '@kepler.gl/utils';
+import KeplerTable from 'reducers/table-utils/kepler-table';
+import {createDataContainer} from 'reducers/table-utils';
export type HexagonIdLayerColumnsConfig = {
hex_id: LayerColumn;
diff --git a/src/layers/src/h3-hexagon-layer/h3-utils.ts b/src/layers/src/h3-hexagon-layer/h3-utils.ts
index 07d6afcf1..cff998b3f 100644
--- a/src/layers/src/h3-hexagon-layer/h3-utils.ts
+++ b/src/layers/src/h3-hexagon-layer/h3-utils.ts
@@ -20,7 +20,7 @@
import {h3GetResolution, H3Index, h3IsValid, h3ToGeo, h3ToGeoBoundary} from 'h3-js';
import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
-import {notNullorUndefined} from 'utils/data-utils';
+import {notNullorUndefined} from '@kepler.gl/utils';
export {h3GetResolution, h3IsValid};
diff --git a/src/layers/src/h3-hexagon-layer/index.ts b/src/layers/src/h3-hexagon-layer/index.ts
new file mode 100644
index 000000000..c3f5092d3
--- /dev/null
+++ b/src/layers/src/h3-hexagon-layer/index.ts
@@ -0,0 +1,3 @@
+export {default as H3HexagonLayerIcon} from './h3-hexagon-layer-icon';
+export * from './h3-hexagon-layer';
+export * from './h3-utils';
diff --git a/src/layers/src/heatmap-layer/heatmap-layer.ts b/src/layers/src/heatmap-layer/heatmap-layer.ts
index 754238612..47fd97c61 100644
--- a/src/layers/src/heatmap-layer/heatmap-layer.ts
+++ b/src/layers/src/heatmap-layer/heatmap-layer.ts
@@ -21,13 +21,13 @@
import {createSelector} from 'reselect';
import memoize from 'lodash.memoize';
import {CHANNEL_SCALES, SCALE_FUNC, ALL_FIELD_TYPES, ColorRange} from '@kepler.gl/constants';
-import {hexToRgb} from 'utils/color-utils';
+import {hexToRgb} from '@kepler.gl/utils';
import MapboxGLLayer, {MapboxLayerGLConfig} from '../mapboxgl-layer';
import HeatmapLayerIcon from './heatmap-layer-icon';
import {LayerColumn, LayerWeightConfig, VisualChannels} from '../base-layer';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
import {VisConfigColorRange, VisConfigNumber} from '@kepler.gl/types';
import {HexColor, Merge} from '@kepler.gl/types';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
export type HeatmapLayerVisConfigSettings = {
opacity: VisConfigNumber;
diff --git a/src/layers/src/hexagon-layer/hexagon-layer.ts b/src/layers/src/hexagon-layer/hexagon-layer.ts
index 21874a81a..dcd1b3edc 100644
--- a/src/layers/src/hexagon-layer/hexagon-layer.ts
+++ b/src/layers/src/hexagon-layer/hexagon-layer.ts
@@ -23,7 +23,7 @@ import AggregationLayer, {AggregationLayerConfig} from '../aggregation-layer';
import {EnhancedHexagonLayer} from '@kepler.gl/deckgl-layers';
import {hexagonToPolygonGeo} from './hexagon-utils';
import HexagonLayerIcon from './hexagon-layer-icon';
-import {clamp} from 'utils/data-utils';
+import {clamp} from '@kepler.gl/utils';
import {
VisConfigBoolean,
VisConfigColorRange,
diff --git a/src/layers/src/icon-layer/icon-info-modal.tsx b/src/layers/src/icon-layer/icon-info-modal.tsx
index 43ba23766..958d22015 100644
--- a/src/layers/src/icon-layer/icon-info-modal.tsx
+++ b/src/layers/src/icon-layer/icon-info-modal.tsx
@@ -21,8 +21,9 @@
import React from 'react';
import styled from 'styled-components';
import {line} from 'd3-shape';
-import {Table, CenterFlexbox} from 'components/common/styled-components';
+import {CenterFlexbox} from 'components/common/styled-components';
import {FormattedMessage} from '@kepler.gl/localization';
+import {Table} from 'components/common/icons';
const lineFunction = line()
.x(d => d[0] * 10)
diff --git a/src/layers/src/icon-layer/icon-layer.ts b/src/layers/src/icon-layer/icon-layer.ts
index 67ea0d845..965dcb040 100644
--- a/src/layers/src/icon-layer/icon-layer.ts
+++ b/src/layers/src/icon-layer/icon-layer.ts
@@ -28,7 +28,8 @@ import {ICON_FIELDS, CLOUDFRONT, ColorRange} from '@kepler.gl/constants';
import IconInfoModalFactory from './icon-info-modal';
import Layer, {LayerBaseConfig, LayerColumn} from '../base-layer';
import {getTextOffsetByRadius, formatTextLabelData} from '../layer-text-label';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
+import {default as KeplerTable} from 'reducers/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
import {
VisConfigBoolean,
VisConfigColorRange,
@@ -36,7 +37,6 @@ import {
VisConfigRange,
Merge
} from '@kepler.gl/types';
-import {KeplerTable} from '../../../utils';
export type IconLayerColumnsConfig = {
lat: LayerColumn;
diff --git a/src/layers/src/index.ts b/src/layers/src/index.ts
index 68a2664da..ec3b7ea71 100644
--- a/src/layers/src/index.ts
+++ b/src/layers/src/index.ts
@@ -25,11 +25,7 @@ import {default as GridLayer} from './grid-layer/grid-layer';
export {pointToPolygonGeo} from './grid-layer/grid-utils';
import {default as HexagonLayer} from './hexagon-layer/hexagon-layer';
import {default as GeojsonLayer} from './geojson-layer/geojson-layer';
-export {
- defaultElevation,
- defaultLineWidth,
- defaultRadius
-} from './geojson-layer/geojson-layer';
+export {defaultElevation, defaultLineWidth, defaultRadius} from './geojson-layer/geojson-layer';
import {default as ClusterLayer} from './cluster-layer/cluster-layer';
import {default as IconLayer} from './icon-layer/icon-layer';
import {default as HeatmapLayer} from './heatmap-layer/heatmap-layer';
@@ -66,6 +62,7 @@ export type {
ColumnPairs,
FindDefaultLayerPropsReturnValue
} from './base-layer';
+export * from './base-layer';
// individual layers
export const KeplerGlLayers = {
@@ -104,3 +101,5 @@ export const LayerClasses = {
export type OVERLAY_TYPE = {[key: string]: string};
export * from './mapbox-utils';
+export * from './types';
+export * from './h3-hexagon-layer';
diff --git a/src/layers/src/layer-text-label.ts b/src/layers/src/layer-text-label.ts
index cd4962bb4..cadf989b5 100644
--- a/src/layers/src/layer-text-label.ts
+++ b/src/layers/src/layer-text-label.ts
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import {getDistanceScales} from 'viewport-mercator-project';
-import {notNullorUndefined} from 'utils/data-utils';
+import {notNullorUndefined} from '@kepler.gl/utils';
import uniq from 'lodash.uniq';
export const defaultPadding = 20;
diff --git a/src/layers/src/line-layer/line-layer.ts b/src/layers/src/line-layer/line-layer.ts
index 5533bc49f..1c78dd64a 100644
--- a/src/layers/src/line-layer/line-layer.ts
+++ b/src/layers/src/line-layer/line-layer.ts
@@ -33,8 +33,8 @@ import {
VisConfigNumber,
VisConfigRange
} from '@kepler.gl/types';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
-import {KeplerTable} from '../../../utils';
+import {default as KeplerTable} from 'reducers/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
export type LineLayerVisConfigSettings = {
opacity: VisConfigNumber;
diff --git a/src/layers/src/mapboxgl-layer.ts b/src/layers/src/mapboxgl-layer.ts
index ed3b0c5f5..76c380331 100644
--- a/src/layers/src/mapboxgl-layer.ts
+++ b/src/layers/src/mapboxgl-layer.ts
@@ -27,7 +27,7 @@ import Layer, {
import {createSelector} from 'reselect';
import {geoJsonFromData, prefixGpuField, gpuFilterToMapboxFilter} from './mapbox-utils';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import {default as KeplerTable} from 'reducers/table-utils/kepler-table';
import {Merge} from '@kepler.gl/types';
type MapboxLayerGLColumns = {
diff --git a/src/layers/src/point-layer/point-layer.ts b/src/layers/src/point-layer/point-layer.ts
index c440f0dc9..a0bc0af41 100644
--- a/src/layers/src/point-layer/point-layer.ts
+++ b/src/layers/src/point-layer/point-layer.ts
@@ -28,8 +28,9 @@ import Layer, {
LayerSizeConfig,
LayerStrokeColorConfig
} from '../base-layer';
-import {hexToRgb} from 'utils/color-utils';
-import {findDefaultColorField} from 'utils/dataset-utils';
+import {hexToRgb} from '@kepler.gl/utils';
+import {default as KeplerTable} from 'reducers/table-utils/kepler-table';
+import {findDefaultColorField} from '@kepler.gl/utils';
import PointLayerIcon from './point-layer-icon';
import {
LAYER_VIS_CONFIGS,
@@ -48,7 +49,6 @@ import {
VisConfigNumber,
VisConfigRange
} from '@kepler.gl/types';
-import {KeplerTable} from '../../../utils';
export type PointLayerVisConfigSettings = {
radius: VisConfigNumber;
diff --git a/src/layers/src/s2-geometry-layer/s2-geometry-layer.ts b/src/layers/src/s2-geometry-layer/s2-geometry-layer.ts
index 48bd086fe..67b349029 100644
--- a/src/layers/src/s2-geometry-layer/s2-geometry-layer.ts
+++ b/src/layers/src/s2-geometry-layer/s2-geometry-layer.ts
@@ -25,9 +25,9 @@ import {
ColorRange,
LAYER_VIS_CONFIGS
} from '@kepler.gl/constants';
-import {KeplerTable} from '../../../utils';
-import {createDataContainer} from 'utils/table-utils';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
+import {default as KeplerTable} from 'reducers/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import {createDataContainer} from 'reducers/table-utils/data-container-utils';
import Layer, {
LayerBaseConfig,
LayerColorConfig,
diff --git a/src/layers/src/scenegraph-layer/scenegraph-info-modal.tsx b/src/layers/src/scenegraph-layer/scenegraph-info-modal.tsx
index 01226e65f..fb6cfb097 100644
--- a/src/layers/src/scenegraph-layer/scenegraph-info-modal.tsx
+++ b/src/layers/src/scenegraph-layer/scenegraph-info-modal.tsx
@@ -20,7 +20,7 @@
import React from 'react';
import styled from 'styled-components';
-import {Table} from 'components/common/styled-components';
+import {StyledTable as Table} from 'components/common/styled-components';
const StyledTitle = styled.div`
font-size: 20px;
diff --git a/src/layers/src/scenegraph-layer/scenegraph-layer.ts b/src/layers/src/scenegraph-layer/scenegraph-layer.ts
index 147975946..450dae6ca 100644
--- a/src/layers/src/scenegraph-layer/scenegraph-layer.ts
+++ b/src/layers/src/scenegraph-layer/scenegraph-layer.ts
@@ -27,8 +27,8 @@ import ScenegraphLayerIcon from './scenegraph-layer-icon';
import ScenegraphInfoModalFactory from './scenegraph-info-modal';
import {LAYER_VIS_CONFIGS, ColorRange} from '@kepler.gl/constants';
import {Merge, VisConfigColorRange, VisConfigNumber} from '@kepler.gl/types';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
-import {KeplerTable} from '../../../utils';
+import {default as KeplerTable} from 'reducers/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
export type ScenegraphLayerVisConfigSettings = {
opacity: VisConfigNumber;
diff --git a/src/layers/src/trip-layer/trip-layer.ts b/src/layers/src/trip-layer/trip-layer.ts
index 6f6e1fc09..ee4af9bfb 100644
--- a/src/layers/src/trip-layer/trip-layer.ts
+++ b/src/layers/src/trip-layer/trip-layer.ts
@@ -35,9 +35,9 @@ import {
import {isTripGeoJsonField, parseTripGeoJsonTimestamp} from './trip-utils';
import TripInfoModalFactory from './trip-info-modal';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
import {Merge, VisConfigColorRange, VisConfigNumber, VisConfigRange} from '@kepler.gl/types';
-import {KeplerTable} from '../../../utils';
+import {default as KeplerTable} from 'reducers/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
export type TripLayerVisConfigSettings = {
opacity: VisConfigNumber;
diff --git a/src/layers/src/trip-layer/trip-utils.ts b/src/layers/src/trip-layer/trip-utils.ts
index fde95baf4..cd2e8d450 100644
--- a/src/layers/src/trip-layer/trip-utils.ts
+++ b/src/layers/src/trip-layer/trip-utils.ts
@@ -20,12 +20,12 @@
import {Analyzer, DATA_TYPES} from 'type-analyzer';
-import {timeToUnixMilli, notNullorUndefined} from 'utils/data-utils';
-import {getSampleData} from 'utils/table-utils/data-container-utils';
+import {Field} from '@kepler.gl/types';
import {parseGeoJsonRawFeature, getGeojsonFeatureTypes} from '../geojson-layer/geojson-utils';
-import {Field} from 'utils/table-utils/kepler-table';
-import {DataContainerInterface} from 'utils/table-utils/data-container-interface';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import {notNullorUndefined, timeToUnixMilli} from '@kepler.gl/utils';
+import {getSampleData} from 'reducers/table-utils/data-container-utils';
/**
* Parse geojson from string
diff --git a/src/localization/src/messages.ts b/src/localization/src/messages.ts
index 4afed09b5..a47f73171 100644
--- a/src/localization/src/messages.ts
+++ b/src/localization/src/messages.ts
@@ -19,9 +19,23 @@
// THE SOFTWARE.
import en from './translations/en';
-import {flattenMessages} from '../../utils/locale-utils';
import {LOCALE_CODES} from './locales';
+// Flat messages since react-intl does not seem to support nested structures
+// Adapted from https://medium.com/siren-apparel-press/internationalization-and-localization-of-sirenapparel-eu-sirenapparel-us-and-sirenapparel-asia-ddee266066a2
+export const flattenMessages = (nestedMessages, prefix = '') => {
+ return Object.keys(nestedMessages).reduce((messages, key) => {
+ const value = nestedMessages[key];
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
+ if (typeof value === 'string') {
+ messages[prefixedKey] = value;
+ } else {
+ Object.assign(messages, flattenMessages(value, prefixedKey));
+ }
+ return messages;
+ }, {});
+};
+
const enFlat = flattenMessages(en);
export const messages: {
diff --git a/src/processors/src/data-processor.ts b/src/processors/src/data-processor.ts
index 6e0fc924b..dbe6f42c2 100644
--- a/src/processors/src/data-processor.ts
+++ b/src/processors/src/data-processor.ts
@@ -18,48 +18,29 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {csvParseRows, csvFormatRows} from 'd3-dsv';
-import {range} from 'd3-array';
-import {console as globalConsole} from 'global/window';
-import assert from 'assert';
-import {Analyzer, DATA_TYPES as AnalyzerDATA_TYPES} from 'type-analyzer';
+import {csvParseRows} from 'd3-dsv';
import normalize from '@mapbox/geojson-normalize';
import {ALL_FIELD_TYPES, DATASET_FORMATS, GUIDES_FILE_FORMAT_DOC} from '@kepler.gl/constants';
-import {notNullorUndefined, parseFieldValue} from '../../utils/data-utils';
-import KeplerGlSchema, {SavedMap, ParsedDataset} from '../../schemas';
-import {LoadedMap} from 'schemas/schema-manager';
-import {hasOwnProperty, isPlainObject, toArray} from '../../utils/utils';
-import {Field} from '../../utils/table-utils/kepler-table';
-import {DataContainerInterface} from '../../utils/table-utils/data-container-interface';
-import {ProcessorResult, RowData} from './types';
+import {ProcessorResult, Field} from '@kepler.gl/types';
+import {
+ notNullorUndefined,
+ hasOwnProperty,
+ isPlainObject,
+ analyzerTypeToFieldType,
+ getSampleForTypeAnalyze,
+ getFieldsFromData,
+ toArray
+} from '@kepler.gl/utils';
+import {KeplerGlSchema, ParsedDataset, SavedMap} from 'schemas';
import {Feature} from '@nebula.gl/edit-modes';
-
-export const ACCEPTED_ANALYZER_TYPES = [
- AnalyzerDATA_TYPES.DATE,
- AnalyzerDATA_TYPES.TIME,
- AnalyzerDATA_TYPES.DATETIME,
- AnalyzerDATA_TYPES.NUMBER,
- AnalyzerDATA_TYPES.INT,
- AnalyzerDATA_TYPES.FLOAT,
- AnalyzerDATA_TYPES.BOOLEAN,
- AnalyzerDATA_TYPES.STRING,
- AnalyzerDATA_TYPES.GEOMETRY,
- AnalyzerDATA_TYPES.GEOMETRY_FROM_STRING,
- AnalyzerDATA_TYPES.PAIR_GEOMETRY_FROM_STRING,
- AnalyzerDATA_TYPES.ZIPCODE,
- AnalyzerDATA_TYPES.ARRAY,
- AnalyzerDATA_TYPES.OBJECT
-];
+import {LoadedMap} from 'schemas/schema-manager';
+import {formatCsv} from 'reducers/export-utils';
// if any of these value occurs in csv, parse it to null;
// const CSV_NULLS = ['', 'null', 'NULL', 'Null', 'NaN', '/N'];
// matches empty string
export const CSV_NULLS = /^(null|NULL|Null|NaN|\/N||)$/;
-const IGNORE_DATA_TYPES = Object.keys(AnalyzerDATA_TYPES).filter(
- type => !ACCEPTED_ANALYZER_TYPES.includes(type)
-);
-
export const PARSE_FIELD_VALUE_FROM_STRING = {
[ALL_FIELD_TYPES.boolean]: {
valid: (d: unknown): boolean => typeof d === 'boolean',
@@ -164,47 +145,6 @@ export function parseRowsByFields(rows: any[][], fields: Field[]) {
return rows;
}
-/**
- * Getting sample data for analyzing field type.
- */
-export function getSampleForTypeAnalyze({
- fields,
- rows,
- sampleCount = 50
-}: {
- fields: string[];
- rows: unknown[][];
- sampleCount?: number;
-}): RowData {
- const total = Math.min(sampleCount, rows.length);
- // const fieldOrder = fields.map(f => f.name);
- const sample = range(0, total, 1).map(d => ({}));
-
- // collect sample data for each field
- fields.forEach((field, fieldIdx) => {
- // data counter
- let i = 0;
- // sample counter
- let j = 0;
-
- while (j < total) {
- if (i >= rows.length) {
- // if depleted data pool
- sample[j][field] = null;
- j++;
- } else if (notNullorUndefined(rows[i][fieldIdx])) {
- const value = rows[i][fieldIdx];
- sample[j][field] = typeof value === 'string' ? value.trim() : value;
- j++;
- i++;
- } else {
- i++;
- }
- }
- });
-
- return sample;
-}
/**
* Convert falsy value in csv including `'', 'null', 'NULL', 'Null', 'NaN'` to `null`,
@@ -266,171 +206,6 @@ export function parseCsvRowsByFieldType(
}
}
-/**
- * Analyze field types from data in `string` format, e.g. uploaded csv.
- * Assign `type`, `fieldIdx` and `format` (timestamp only) to each field
- *
- * @param data array of row object
- * @param fieldOrder array of field names as string
- * @returns formatted fields
- * @public
- * @example
- *
- * import {getFieldsFromData} from 'kepler.gl/processors';
- * const data = [{
- * time: '2016-09-17 00:09:55',
- * value: '4',
- * surge: '1.2',
- * isTrip: 'true',
- * zeroOnes: '0'
- * }, {
- * time: '2016-09-17 00:30:08',
- * value: '3',
- * surge: null,
- * isTrip: 'false',
- * zeroOnes: '1'
- * }, {
- * time: null,
- * value: '2',
- * surge: '1.3',
- * isTrip: null,
- * zeroOnes: '1'
- * }];
- *
- * const fieldOrder = ['time', 'value', 'surge', 'isTrip', 'zeroOnes'];
- * const fields = getFieldsFromData(data, fieldOrder);
- * // fields = [
- * // {name: 'time', format: 'YYYY-M-D H:m:s', fieldIdx: 1, type: 'timestamp'},
- * // {name: 'value', format: '', fieldIdx: 4, type: 'integer'},
- * // {name: 'surge', format: '', fieldIdx: 5, type: 'real'},
- * // {name: 'isTrip', format: '', fieldIdx: 6, type: 'boolean'},
- * // {name: 'zeroOnes', format: '', fieldIdx: 7, type: 'integer'}];
- *
- */
-export function getFieldsFromData(data: RowData, fieldOrder: string[]): Field[] {
- // add a check for epoch timestamp
- const metadata = Analyzer.computeColMeta(
- data,
- [
- {regex: /.*geojson|all_points/g, dataType: 'GEOMETRY'},
- {regex: /.*census/g, dataType: 'STRING'}
- ],
- {ignoredDataTypes: IGNORE_DATA_TYPES}
- );
-
- const {fieldByIndex} = renameDuplicateFields(fieldOrder);
-
- const result = fieldOrder.map((field, index) => {
- const name = fieldByIndex[index];
-
- const fieldMeta = metadata.find(m => m.key === field);
- const {type, format} = fieldMeta || {};
-
- return {
- name,
- id: name,
- displayName: name,
- format,
- fieldIdx: index,
- type: analyzerTypeToFieldType(type),
- analyzerType: type,
- valueAccessor: dc => d => {
- return dc.valueAt(d.index, index);
- }
- };
- });
-
- return result;
-}
-
-/**
- * pass in an array of field names, rename duplicated one
- * and return a map from old field index to new name
- *
- * @param fieldOrder
- * @returns new field name by index
- */
-export function renameDuplicateFields(
- fieldOrder: string[]
-): {allNames: string[]; fieldByIndex: string[]} {
- return fieldOrder.reduce<{allNames: string[]; fieldByIndex: string[]}>(
- (accu, field, i) => {
- const {allNames} = accu;
- let fieldName = field;
-
- // add a counter to duplicated names
- if (allNames.includes(field)) {
- let counter = 0;
- while (allNames.includes(`${field}-${counter}`)) {
- counter++;
- }
- fieldName = `${field}-${counter}`;
- }
-
- accu.fieldByIndex[i] = fieldName;
- accu.allNames.push(fieldName);
-
- return accu;
- },
- {allNames: [], fieldByIndex: []}
- );
-}
-
-/**
- * Convert type-analyzer output to kepler.gl field types
- *
- * @param aType
- * @returns corresponding type in `ALL_FIELD_TYPES`
- */
-/* eslint-disable complexity */
-export function analyzerTypeToFieldType(aType: string): string {
- const {
- DATE,
- TIME,
- DATETIME,
- NUMBER,
- INT,
- FLOAT,
- BOOLEAN,
- STRING,
- GEOMETRY,
- GEOMETRY_FROM_STRING,
- PAIR_GEOMETRY_FROM_STRING,
- ZIPCODE,
- ARRAY,
- OBJECT
- } = AnalyzerDATA_TYPES;
-
- // TODO: un recognized types
- // CURRENCY PERCENT NONE
- switch (aType) {
- case DATE:
- return ALL_FIELD_TYPES.date;
- case TIME:
- case DATETIME:
- return ALL_FIELD_TYPES.timestamp;
- case FLOAT:
- return ALL_FIELD_TYPES.real;
- case INT:
- return ALL_FIELD_TYPES.integer;
- case BOOLEAN:
- return ALL_FIELD_TYPES.boolean;
- case GEOMETRY:
- case GEOMETRY_FROM_STRING:
- case PAIR_GEOMETRY_FROM_STRING:
- case ARRAY:
- case OBJECT:
- // TODO: create a new data type for objects and arrays
- return ALL_FIELD_TYPES.geojson;
- case NUMBER:
- case STRING:
- case ZIPCODE:
- return ALL_FIELD_TYPES.string;
- default:
- globalConsole.warn(`Unsupported analyzer type: ${aType}`);
- return ALL_FIELD_TYPES.string;
- }
-}
/* eslint-enable complexity */
/**
@@ -559,108 +334,6 @@ export function processGeojson(rawData: unknown): ProcessorResult {
return processRowObject(allDataRows);
}
-/**
- * On export data to csv
- * @param dataContainer
- * @param fields `dataset.fields`
- * @returns csv string
- */
-export function formatCsv(data: DataContainerInterface, fields: Field[]): string {
- const columns = fields.map(f => f.displayName || f.name);
- const formattedData = [columns];
-
- // parse geojson object as string
- for (const row of data.rows(true)) {
- formattedData.push(row.map((d, i) => parseFieldValue(d, fields[i].type)));
- }
-
- return csvFormatRows(formattedData);
-}
-
-/**
- * Validate input data, adding missing field types, rename duplicate columns
- */
-export function validateInputData(data: Record<string, unknown>): ProcessorResult {
- if (!isPlainObject(data)) {
- assert('addDataToMap Error: dataset.data cannot be null');
- return null;
- } else if (!Array.isArray(data.fields)) {
- assert('addDataToMap Error: expect dataset.data.fields to be an array');
- return null;
- } else if (!Array.isArray(data.rows)) {
- assert('addDataToMap Error: expect dataset.data.rows to be an array');
- return null;
- }
-
- const {fields, rows} = data;
-
- // check if all fields has name, format and type
- const allValid = fields.every((f, i) => {
- if (!isPlainObject(f)) {
- assert(`fields needs to be an array of object, but find ${typeof f}`);
- fields[i] = {};
- }
-
- if (!f.name) {
- assert(`field.name is required but missing in ${JSON.stringify(f)}`);
- // assign a name
- fields[i].name = `column_${i}`;
- }
-
- if (!ALL_FIELD_TYPES[f.type]) {
- assert(`unknown field type ${f.type}`);
- return false;
- }
-
- if (!fields.every(field => field.analyzerType)) {
- assert('field missing analyzerType');
- return false;
- }
-
- // check time format is correct based on first 10 not empty element
- if (f.type === ALL_FIELD_TYPES.timestamp) {
- const sample = findNonEmptyRowsAtField(rows, i, 10).map(r => ({ts: r[i]}));
- const analyzedType = Analyzer.computeColMeta(sample)[0];
- return analyzedType && analyzedType.category === 'TIME' && analyzedType.format === f.format;
- }
-
- return true;
- });
-
- if (allValid) {
- return {rows, fields};
- }
-
- // if any field has missing type, recalculate it for everyone
- // because we simply lost faith in humanity
- const sampleData = getSampleForTypeAnalyze({
- fields: fields.map(f => f.name),
- rows
- });
- const fieldOrder = fields.map(f => f.name);
- const meta = getFieldsFromData(sampleData, fieldOrder);
- const updatedFields = fields.map((f, i) => ({
- ...f,
- type: meta[i].type,
- format: meta[i].format,
- analyzerType: meta[i].analyzerType
- }));
-
- return {fields: updatedFields, rows};
-}
-
-function findNonEmptyRowsAtField(rows: unknown[][], fieldIdx: number, total: number): any[] {
- const sample: any[] = [];
- let i = 0;
- while (sample.length < total && i < rows.length) {
- if (notNullorUndefined(rows[i]?.[fieldIdx])) {
- sample.push(rows[i]);
- }
- i++;
- }
- return sample;
-}
-
/**
* Process saved kepler.gl json to be pass to [`addDataToMap`](../actions/actions.md#adddatatomap).
* The json object should contain `datasets` and `config`.
diff --git a/src/processors/src/file-handler.ts b/src/processors/src/file-handler.ts
index 96b2a2d72..91aa267f0 100644
--- a/src/processors/src/file-handler.ts
+++ b/src/processors/src/file-handler.ts
@@ -22,12 +22,12 @@ import {parseInBatches} from '@loaders.gl/core';
import {JSONLoader, _JSONPath} from '@loaders.gl/json';
import {CSVLoader} from '@loaders.gl/csv';
import {processGeojson, processKeplerglJSON, processRowObject} from './data-processor';
-import {isPlainObject, generateHashId} from '../../utils/utils';
+import {generateHashId, isPlainObject} from '@kepler.gl/utils';
import {DATASET_FORMATS} from '@kepler.gl/constants';
import {Loader} from '@loaders.gl/loader-utils';
import {AddDataToMapPayload} from '../../actions/actions';
import {FileCacheItem, ValidKeplerGlMap} from './types';
-import {Feature} from '../../reducers';
+import {Feature} from '@kepler.gl/types';
import {FeatureCollection} from '@turf/helpers';
const BATCH_TYPE = {
diff --git a/src/processors/src/types.ts b/src/processors/src/types.ts
index 84e52a37b..b30fa7102 100644
--- a/src/processors/src/types.ts
+++ b/src/processors/src/types.ts
@@ -1,5 +1,3 @@
-import {Field} from 'utils/table-utils/kepler-table';
-
export type FileCacheItem = {
data: any;
info: {
@@ -9,12 +7,6 @@ export type FileCacheItem = {
};
};
-export type RowData = {
- [key: string]: string | null;
-}[];
-
-export type ProcessorResult = {fields: Field[]; rows: any[][]} | null;
-
export type ValidKeplerGlMap = {
datasets: unknown;
config: unknown;
diff --git a/src/reducers/combined-updaters.ts b/src/reducers/combined-updaters.ts
index 2327b153a..89ee1e0d2 100644
--- a/src/reducers/combined-updaters.ts
+++ b/src/reducers/combined-updaters.ts
@@ -28,19 +28,18 @@ import {
} from './vis-state-updaters';
import {receiveMapConfigUpdater as stateMapConfigUpdater} from './map-state-updaters';
import {receiveMapConfigUpdater as styleMapConfigUpdater} from './map-style-updaters';
-import {findMapBounds} from 'utils/data-utils';
-import {isPlainObject} from 'utils/utils';
import {filesToDataPayload} from '@kepler.gl/processors';
import {payload_, apply_, with_, if_, compose_, merge_, pick_} from './composer-helpers';
-import {VisState} from './vis-state-updaters';
-import {MapState} from './map-state-updaters';
+import {MapState} from '@kepler.gl/types';
import {UiState} from './ui-state-updaters';
import {MapStyle} from './map-style-updaters';
import {ProviderState} from './provider-state-updaters';
import {AddDataToMapPayload} from 'actions/actions';
import {loadFilesSuccessUpdaterAction} from 'actions/vis-state-actions';
-import {ParsedConfig} from 'schemas';
+import {ParsedConfig, VisState} from 'schemas';
import {Layer} from '@kepler.gl/layers';
+import {isPlainObject} from '@kepler.gl/utils';
+import {findMapBounds} from './data-utils';
export type KeplerGlState = {
visState: VisState;
diff --git a/src/reducers/core.ts b/src/reducers/core.ts
index d16a289f1..1a14e95f9 100644
--- a/src/reducers/core.ts
+++ b/src/reducers/core.ts
@@ -28,11 +28,11 @@ import {providerStateReducerFactory} from './provider-state';
import composers from './composers';
-import {VisState} from './vis-state-updaters';
-import {MapState} from './map-state-updaters';
+import {MapState} from '@kepler.gl/types';
import {MapStyle} from './map-style-updaters';
import {ProviderState} from './provider-state-updaters';
import {UiState} from './ui-state-updaters';
+import {VisState} from 'schemas';
export type KeplerGlState = {
visState: VisState;
diff --git a/src/utils/data-scale-utils.ts b/src/reducers/data-scale-utils.ts
similarity index 94%
rename from src/utils/data-scale-utils.ts
rename to src/reducers/data-scale-utils.ts
index 29070f66a..ee0afdf9f 100644
--- a/src/utils/data-scale-utils.ts
+++ b/src/reducers/data-scale-utils.ts
@@ -18,9 +18,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {notNullorUndefined, unique} from './data-utils';
+import {notNullorUndefined, unique} from '@kepler.gl/utils';
import {extent} from 'd3-array';
-import {DataContainerInterface} from './table-utils/data-container-interface';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
type dataValueAccessor = <T>(param: T) => T;
type dataContainerValueAccessor = (d: {index: number}, dc: DataContainerInterface) => any;
diff --git a/src/reducers/data-utils.ts b/src/reducers/data-utils.ts
new file mode 100644
index 000000000..4af1fe087
--- /dev/null
+++ b/src/reducers/data-utils.ts
@@ -0,0 +1,62 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+import {Bounds} from '@kepler.gl/types';
+import {Layer} from '@kepler.gl/layers';
+
+const MAX_LATITUDE = 90;
+const MIN_LATITUDE = -90;
+const MAX_LONGITUDE = 180;
+const MIN_LONGITUDE = -180;
+
+/**
+ * return center of map from given points
+ * @param layers
+ * @returns coordinates of map center, empty if not found
+ */
+export function findMapBounds(layers: Layer[]): Bounds | null {
+ // find bounds in formatted layerData
+ // take ALL layers into account when finding map bounds
+ const availableLayerBounds: Bounds | [] = layers.reduce((res, l) => {
+ // @ts-expect-error
+ if (l.meta && l.meta.bounds) {
+ // @ts-expect-error
+ res.push(l.meta.bounds);
+ }
+ return res;
+ }, []);
+ // return null if no layer is available
+ if (availableLayerBounds.length === 0) {
+ return null;
+ }
+ // merge bounds in each layer
+ const newBounds = (availableLayerBounds as Bounds).reduce(
+ (res, b) => {
+ return [
+ Math.min(res[0], b[0]),
+ Math.min(res[1], b[1]),
+ Math.max(res[2], b[2]),
+ Math.max(res[3], b[3])
+ ];
+ },
+ [MAX_LONGITUDE, MAX_LATITUDE, MIN_LONGITUDE, MIN_LATITUDE]
+ );
+ // @ts-expect-error
+ return newBounds;
+}
diff --git a/src/reducers/export-utils.ts b/src/reducers/export-utils.ts
new file mode 100644
index 000000000..92e64b4f2
--- /dev/null
+++ b/src/reducers/export-utils.ts
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import {Blob} from 'global/window';
+import {csvFormatRows} from 'd3-dsv';
+
+import {EXPORT_DATA_TYPE} from '@kepler.gl/constants';
+import {Field} from '@kepler.gl/types';
+
+import {createIndexedDataContainer} from 'reducers/table-utils/data-container-utils';
+import {parseFieldValue} from '@kepler.gl/utils';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import {Datasets} from 'reducers/table-utils/kepler-table';
+import {downloadFile, DEFAULT_DATA_NAME} from '@kepler.gl/utils';
+
+interface StateType {
+ visState: {datasets: Datasets};
+ appName?: string;
+}
+
+export function exportData(state: StateType, options) {
+ const {visState, appName} = state;
+ const {datasets} = visState;
+ const {selectedDataset, dataType, filtered} = options;
+ // get the selected data
+ const filename = appName ? appName : DEFAULT_DATA_NAME;
+ const selectedDatasets = datasets[selectedDataset]
+ ? [datasets[selectedDataset]]
+ : Object.values(datasets);
+ if (!selectedDatasets.length) {
+ // error: selected dataset not found.
+ return;
+ }
+
+ selectedDatasets.forEach(selectedData => {
+ const {dataContainer, fields, label, filteredIdxCPU = []} = selectedData;
+ const toExport = filtered
+ ? createIndexedDataContainer(dataContainer, filteredIdxCPU)
+ : dataContainer;
+
+ // start to export data according to selected data type
+ switch (dataType) {
+ case EXPORT_DATA_TYPE.CSV: {
+ const csv = formatCsv(toExport, fields);
+
+ const fileBlob = new Blob([csv], {type: 'text/csv'});
+ downloadFile(fileBlob, `${filename}_${label}.csv`);
+ break;
+ }
+ // TODO: support more file types.
+ default:
+ break;
+ }
+ });
+}
+
+/**
+ * On export data to csv
+ * @param dataContainer
+ * @param fields `dataset.fields`
+ * @returns csv string
+ */
+export function formatCsv(data: DataContainerInterface, fields: Field[]): string {
+ const columns = fields.map(f => f.displayName || f.name);
+ const formattedData = [columns];
+
+ // parse geojson object as string
+ for (const row of data.rows(true)) {
+ formattedData.push(row.map((d, i) => parseFieldValue(d, fields[i].type)));
+ }
+
+ return csvFormatRows(formattedData);
+}
+
+const exporters = {
+ exportData
+};
+
+export default exporters;
diff --git a/src/utils/filter-utils.ts b/src/reducers/filter-utils.ts
similarity index 97%
rename from src/utils/filter-utils.ts
rename to src/reducers/filter-utils.ts
index e6c609867..13f3363b4 100644
--- a/src/utils/filter-utils.ts
+++ b/src/reducers/filter-utils.ts
@@ -28,31 +28,35 @@ import booleanWithin from '@turf/boolean-within';
import {point as turfPoint} from '@turf/helpers';
import {Decimal} from 'decimal.js';
import {ALL_FIELD_TYPES, FILTER_TYPES, ANIMATION_WINDOW, PLOT_TYPES} from '@kepler.gl/constants';
-import {LAYER_TYPES, getCentroid, h3IsValid, Layer} from '@kepler.gl/layers';
-import {notNullorUndefined, unique, timeToUnixMilli} from './data-utils';
+import {Layer} from '@kepler.gl/layers';
+import {notNullorUndefined, unique, timeToUnixMilli} from '@kepler.gl/utils';
import * as ScaleUtils from './data-scale-utils';
-import {generateHashId, set, toArray} from './utils';
+import {generateHashId, set, toArray} from '@kepler.gl/utils';
+import {h3IsValid} from 'h3-js';
+import {Millisecond, Entries, Field} from '@kepler.gl/types';
import {
Filter,
FilterBase,
PolygonFilter,
- Datasets,
FieldDomain,
TimeRangeFieldDomain,
HistogramBin,
Feature,
FeatureValue,
- VisState,
LineChart,
TimeRangeFilter,
RangeFieldDomain
-} from '../reducers/vis-state-updaters';
-import KeplerTable, {Field, FilterRecord, FilterDatasetOpt} from './table-utils/kepler-table';
-import {ParsedFilter} from 'schemas';
-import {DataContainerInterface} from './table-utils/data-container-interface';
-import {Millisecond} from 'cloud-providers';
-import {Entries} from '@kepler.gl/types';
+} from '@kepler.gl/types';
+
+import {ParsedFilter, VisState} from 'schemas';
+import KeplerTable, {
+ FilterRecord,
+ Datasets,
+ FilterDatasetOpt
+} from 'reducers/table-utils/kepler-table';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import {LAYER_TYPES, getCentroid} from '@kepler.gl/layers';
export type FilterResult = {
filteredIndexForDomain?: number[];
@@ -1089,7 +1093,13 @@ export function generatePolygonFilter(layers: Layer[], feature: Feature): Polygo
/**
* Run filter entirely on CPU
*/
-export function filterDatasetCPU(state: VisState, dataId: string): VisState {
+interface StateType {
+ layers: Layer[];
+ filters: Filter[];
+ datasets: Datasets;
+}
+
+export function filterDatasetCPU<T extends StateType>(state: T, dataId: string): T {
const datasetFilters = state.filters.filter(f => f.dataId.includes(dataId));
const dataset = state.datasets[dataId];
diff --git a/src/reducers/index.ts b/src/reducers/index.ts
index ce85fca1c..dd735f59e 100644
--- a/src/reducers/index.ts
+++ b/src/reducers/index.ts
@@ -56,42 +56,8 @@ export * as visStateMergers from './vis-state-merger';
// Helpers
export * from './composer-helpers';
-// export types
export type {
- AnimationConfig,
- Brush,
- Coordinate,
- KeplerTable,
- Datasets,
- Editor,
- Feature,
- FeatureValue,
- FieldDomain,
- Filter,
- FilterBase,
- Geocoder,
- HistogramBin,
- InteractionConfig,
- LineChart,
- MapInfo,
- MultiSelectFieldDomain,
- MultiSelectFilter,
- PolygonFilter,
- RangeFieldDomain,
- RangeFilter,
- SelectFieldDomain,
- SelectFilter,
- SplitMap,
- TimeRangeFieldDomain,
- TimeRangeFilter,
- TooltipInfo,
- VisState
-} from './vis-state-updaters';
-
-export type {
- BaseMapStyle,
InputStyle,
- LayerGroup,
MapboxStyleUrl,
MapStyle,
MapStyles,
@@ -99,15 +65,12 @@ export type {
} from './map-style-updaters';
export type {
- Bounds,
- MapState,
Viewport
} from './map-state-updaters';
export type {
ExportData,
ExportHtml,
- ExportImage,
ExportJson,
ExportMap,
LoadFiles,
@@ -118,4 +81,12 @@ export type {
UiState
} from './ui-state-updaters';
+export * from './data-scale-utils';
+export * from './data-utils';
+export * from './table-utils/dataset-utils';
+export * from './export-utils';
+export * from './filter-utils';
+export * from './table-utils/gpu-filter-utils';
+export * from './interaction-utils';
+export * from './layer-utils';
export * as providerStateUpdaters from './provider-state-updaters';
\ No newline at end of file
diff --git a/src/utils/interaction-utils.ts b/src/reducers/interaction-utils.ts
similarity index 80%
rename from src/utils/interaction-utils.ts
rename to src/reducers/interaction-utils.ts
index d33922f12..681984e48 100644
--- a/src/utils/interaction-utils.ts
+++ b/src/reducers/interaction-utils.ts
@@ -26,18 +26,16 @@ import {
TOOLTIP_KEY,
COMPARE_TYPES
} from '@kepler.gl/constants';
+
+import {DataRow} from 'reducers/table-utils/data-row';
+import {Field, TooltipField, CompareType} from '@kepler.gl/types';
import {
parseFieldValue,
getFormatter,
isNumber,
defaultFormatter,
notNullorUndefined
-} from 'utils/data-utils';
-import {Messages, Crosshairs, CursorClick, Pin} from 'components/common/icons/index';
-
-import {InteractionConfig, TooltipField, CompareType} from '../reducers/vis-state-updaters';
-import {DataRow} from './table-utils/data-row';
-import {Field} from './table-utils/kepler-table';
+} from '@kepler.gl/utils';
/**
* Minus sign used in tooltip formatting.
@@ -45,46 +43,6 @@ import {Field} from './table-utils/kepler-table';
*/
export const TOOLTIP_MINUS_SIGN = '\u2212';
-export function getDefaultInteraction(): InteractionConfig {
- return {
- tooltip: {
- id: 'tooltip',
- label: 'interactions.tooltip',
- enabled: true,
- iconComponent: Messages,
- config: {
- fieldsToShow: {},
- compareMode: false,
- compareType: COMPARE_TYPES.ABSOLUTE
- }
- },
- geocoder: {
- id: 'geocoder',
- label: 'interactions.geocoder',
- enabled: false,
- iconComponent: Pin,
- position: null
- },
- brush: {
- id: 'brush',
- label: 'interactions.brush',
- enabled: false,
- iconComponent: Crosshairs,
- config: {
- // size is in km
- size: 0.5
- }
- },
- coordinate: {
- id: 'coordinate',
- label: 'interactions.coordinate',
- enabled: false,
- iconComponent: CursorClick,
- position: null
- }
- };
-}
-
export const BRUSH_CONFIG: {
range: [number, number];
} = {
diff --git a/src/utils/layer-utils.ts b/src/reducers/layer-utils.ts
similarity index 94%
rename from src/utils/layer-utils.ts
rename to src/reducers/layer-utils.ts
index 48a87f683..f850cf10f 100644
--- a/src/utils/layer-utils.ts
+++ b/src/reducers/layer-utils.ts
@@ -18,18 +18,25 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+import {GEOCODER_LAYER_ID} from '@kepler.gl/constants';
+import {
+ Field,
+ TooltipField,
+ CompareType,
+ SplitMapLayers,
+ InteractionConfig
+} from '@kepler.gl/types';
import {
FindDefaultLayerPropsReturnValue,
Layer,
LayerClassesType,
OVERLAY_TYPE_CONST
} from '@kepler.gl/layers';
-import {GEOCODER_LAYER_ID} from '@kepler.gl/constants';
-import {ThreeDBuildingLayer} from '../deckgl-layers';
-import {getMapLayersFromSplitMaps} from './map-utils';
-import {isFunction} from 'utils/utils';
-import {VisState, TooltipField, CompareType, SplitMapLayers} from 'reducers/vis-state-updaters';
-import KeplerTable, {Field} from './table-utils/kepler-table';
+
+import KeplerTable, {Datasets} from 'reducers/table-utils/kepler-table';
+import {VisState} from 'schemas';
+import {isFunction, getMapLayersFromSplitMaps} from '@kepler.gl/utils';
+import {ThreeDBuildingLayer} from '@kepler.gl/deckgl-layers';
export type LayersToRender = {
[layerId: string]: boolean;
@@ -90,7 +97,7 @@ export function findDefaultLayer(dataset: KeplerTable, layerClasses: LayerClasse
*/
export function calculateLayerData(
layer: Layer,
- state: VisState,
+ state: {datasets: Datasets},
oldLayerData?: any
): {
layerData: any;
@@ -117,11 +124,11 @@ export function getLayerHoverProp({
layersToRender,
datasets
}: {
- interactionConfig: VisState['interactionConfig'];
- hoverInfo: VisState['hoverInfo'];
- layers: VisState['layers'];
+ interactionConfig: InteractionConfig;
+ hoverInfo: any;
+ layers: Layer[];
layersToRender: LayersToRender;
- datasets: VisState['datasets'];
+ datasets: Datasets;
}): LayerHoverProp | null {
if (interactionConfig.tooltip.enabled && hoverInfo && hoverInfo.picked) {
// if anything hovered
@@ -203,7 +210,7 @@ export function isLayerVisible(layer, mapLayers) {
// return {[id]: true \ false}
export function prepareLayersForDeck(
layers: Layer[],
- layerData: VisState['layerData']
+ layerData: any[]
): {
[key: string]: boolean;
} {
diff --git a/src/reducers/map-state-updaters.ts b/src/reducers/map-state-updaters.ts
index 72702ddc1..af2c966e0 100644
--- a/src/reducers/map-state-updaters.ts
+++ b/src/reducers/map-state-updaters.ts
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {getCenterAndZoomFromBounds} from 'utils/projection-utils';
+import {getCenterAndZoomFromBounds} from '@kepler.gl/utils';
import * as MapStateActions from 'actions/map-state-actions';
import {ReceiveMapConfigPayload} from '../actions/actions';
import {ActionTypes} from 'actions';
@@ -37,7 +37,6 @@ export type MapState = {
scale?: number;
};
-export type Bounds = [number, number, number, number];
/** Width of viewport */
export type Viewport = {
/** Width of viewport */
diff --git a/src/reducers/map-style-updaters.ts b/src/reducers/map-style-updaters.ts
index 7076a62f3..d802beb3f 100644
--- a/src/reducers/map-style-updaters.ts
+++ b/src/reducers/map-style-updaters.ts
@@ -29,47 +29,30 @@ import {
mergeLayerGroupVisibility,
editTopMapStyle,
editBottomMapStyle,
- getStyleImageIcon
-} from 'utils/map-style-utils/mapbox-gl-style-editor';
+ getStyleImageIcon,
+ generateHashId,
+ hexToRgb
+} from '@kepler.gl/utils';
import {
DEFAULT_MAP_STYLES,
DEFAULT_LAYER_GROUPS,
DEFAULT_MAPBOX_API_URL
} from '@kepler.gl/constants';
import {ActionTypes} from 'actions';
-import {generateHashId} from 'utils/utils';
import {LOAD_MAP_STYLE_TASK} from 'tasks/tasks';
import {loadMapStyles, loadMapStyleErr} from 'actions/map-style-actions';
import {rgb} from 'd3-color';
-import {hexToRgb} from 'utils/color-utils';
-import {RGBColor} from '@kepler.gl/types';
+import {RGBColor, BaseMapStyle, LayerGroup} from '@kepler.gl/types';
import {ReceiveMapConfigPayload, KeplerGlInitPayload} from '../actions/actions';
import * as MapStyleActions from '../actions/map-style-actions';
-export type LayerGroup = {
- slug: string;
- filter(layer: {id: string}): boolean;
- defaultVisibility: boolean;
-};
-
export type VisibleLayerGroups = {
[key: string]: boolean;
};
export type MapboxStyleUrl = string;
-export type BaseMapStyle = {
- id: string;
- label: string;
- url: string;
- icon: string;
- style?: Object;
- layerGroups: LayerGroup[];
- accessToken?: string;
- custom?: boolean;
-};
-
export type MapStyles = {
[key: string]: BaseMapStyle;
};
diff --git a/src/reducers/provider-state-updaters.ts b/src/reducers/provider-state-updaters.ts
index e40b5a12c..15a02e952 100644
--- a/src/reducers/provider-state-updaters.ts
+++ b/src/reducers/provider-state-updaters.ts
@@ -20,7 +20,7 @@
import {withTask} from 'react-palm/tasks';
import Console from 'global/console';
-import {generateHashId, getError, isPlainObject, toArray} from '../utils/utils';
+import {generateHashId, getError, isPlainObject, toArray} from '@kepler.gl/utils';
import {
EXPORT_FILE_TO_CLOUD_TASK,
ACTION_TASK,
diff --git a/src/utils/table-utils/UPGRADE-data-container.md b/src/reducers/table-utils/UPGRADE-data-container.md
similarity index 100%
rename from src/utils/table-utils/UPGRADE-data-container.md
rename to src/reducers/table-utils/UPGRADE-data-container.md
diff --git a/src/utils/table-utils/data-container-interface.ts b/src/reducers/table-utils/data-container-interface.ts
similarity index 100%
rename from src/utils/table-utils/data-container-interface.ts
rename to src/reducers/table-utils/data-container-interface.ts
diff --git a/src/utils/table-utils/data-container-utils.ts b/src/reducers/table-utils/data-container-utils.ts
similarity index 98%
rename from src/utils/table-utils/data-container-utils.ts
rename to src/reducers/table-utils/data-container-utils.ts
index 124904523..719e4dd62 100644
--- a/src/utils/table-utils/data-container-utils.ts
+++ b/src/reducers/table-utils/data-container-utils.ts
@@ -22,7 +22,7 @@ import {RowDataContainer} from './row-data-container';
import {IndexedDataContainer} from './indexed-data-container';
import {DataContainerInterface} from './data-container-interface';
-import {Field} from './kepler-table';
+import {Field} from '@kepler.gl/types';
export type DataContainerOptions = {
inputDataFormat?: string; // one of DataForm
diff --git a/src/utils/table-utils/data-row.ts b/src/reducers/table-utils/data-row.ts
similarity index 100%
rename from src/utils/table-utils/data-row.ts
rename to src/reducers/table-utils/data-row.ts
diff --git a/src/reducers/table-utils/dataset-utils.ts b/src/reducers/table-utils/dataset-utils.ts
new file mode 100644
index 000000000..4207f7899
--- /dev/null
+++ b/src/reducers/table-utils/dataset-utils.ts
@@ -0,0 +1,80 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import uniq from 'lodash.uniq';
+import KeplerTable, {Datasets} from 'reducers/table-utils/kepler-table';
+
+import {ProtoDataset} from 'actions';
+import {RGBColor} from '@kepler.gl/types';
+
+import {hexToRgb, validateInputData, datasetColorMaker} from '@kepler.gl/utils';
+
+// apply a color for each dataset
+// to use as label colors
+const datasetColors = [
+ '#8F2FBF',
+ '#005CFF',
+ '#C06C84',
+ '#F8B195',
+ '#547A82',
+ '#3EACA8',
+ '#A2D4AB'
+].map(hexToRgb);
+
+/** @type {typeof import('./dataset-utils').getNewDatasetColor} */
+export function getNewDatasetColor(datasets: Datasets): RGBColor {
+ const presetColors = datasetColors.map(String);
+ const usedColors = uniq(Object.values(datasets).map(d => String(d.color))).filter(c =>
+ presetColors.includes(c)
+ );
+
+ if (usedColors.length === presetColors.length) {
+ // if we already depleted the pool of color
+ return datasetColorMaker.next().value;
+ }
+
+ let color = datasetColorMaker.next().value;
+ while (usedColors.includes(String(color))) {
+ color = datasetColorMaker.next().value;
+ }
+
+ return color;
+}
+
+/**
+ * Take datasets payload from addDataToMap, create datasets entry save to visState
+ */
+export function createNewDataEntry(
+ {info, data, ...opts}: ProtoDataset,
+ datasets: Datasets = {}
+): Datasets {
+ const validatedData = validateInputData(data);
+ if (!validatedData) {
+ return {};
+ }
+
+ info = info || {};
+ const color = info.color || getNewDatasetColor(datasets);
+
+ const keplerTable = new KeplerTable({info, data: validatedData, color, ...opts});
+ return {
+ [keplerTable.id]: keplerTable
+ };
+}
diff --git a/src/utils/gpu-filter-utils.ts b/src/reducers/table-utils/gpu-filter-utils.ts
similarity index 96%
rename from src/utils/gpu-filter-utils.ts
rename to src/reducers/table-utils/gpu-filter-utils.ts
index 668992afa..44a2e6e0a 100644
--- a/src/utils/gpu-filter-utils.ts
+++ b/src/reducers/table-utils/gpu-filter-utils.ts
@@ -18,13 +18,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {set, toArray} from './utils';
-import {MAX_GPU_FILTERS, FILTER_TYPES} from '@kepler.gl/constants';
-import {notNullorUndefined} from './data-utils';
import moment from 'moment';
-import {Filter} from 'reducers/vis-state-updaters';
-import {DataContainerInterface} from './table-utils/data-container-interface';
-import {Field, GpuFilter} from './table-utils/kepler-table';
+import {MAX_GPU_FILTERS, FILTER_TYPES} from '@kepler.gl/constants';
+import {Field, Filter} from '@kepler.gl/types';
+
+import {set, toArray, notNullorUndefined} from '@kepler.gl/utils';
+import {DataContainerInterface} from 'reducers/table-utils/data-container-interface';
+import {GpuFilter} from 'reducers/table-utils/kepler-table';
/**
* Set gpu mode based on current number of gpu filters exists
diff --git a/src/utils/table-utils/index.ts b/src/reducers/table-utils/index.ts
similarity index 68%
rename from src/utils/table-utils/index.ts
rename to src/reducers/table-utils/index.ts
index 6a1f5c90f..fd513e9f2 100644
--- a/src/utils/table-utils/index.ts
+++ b/src/reducers/table-utils/index.ts
@@ -18,4 +18,17 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-export {createDataContainer, createIndexedDataContainer} from './data-container-utils';
+export {
+ default,
+ default as KeplerTable,
+ findPointFieldPairs,
+ copyTableAndUpdate,
+ pinTableColumns,
+ sortDatasetByColumn,
+ copyTable,
+ maybeToDate
+ } from './kepler-table';
+ /* eslint-disable prettier/prettier */
+ export type {GpuFilter, Datasets} from './kepler-table';
+ export {createDataContainer, createIndexedDataContainer, getSampleData as getSampleContainerData} from './data-container-utils';
+ export type {DataContainerInterface} from './data-container-interface';
diff --git a/src/utils/table-utils/indexed-data-container.ts b/src/reducers/table-utils/indexed-data-container.ts
similarity index 100%
rename from src/utils/table-utils/indexed-data-container.ts
rename to src/reducers/table-utils/indexed-data-container.ts
diff --git a/src/utils/table-utils/kepler-table.ts b/src/reducers/table-utils/kepler-table.ts
similarity index 95%
rename from src/utils/table-utils/kepler-table.ts
rename to src/reducers/table-utils/kepler-table.ts
index 4453076ed..90b2a85b0 100644
--- a/src/utils/table-utils/kepler-table.ts
+++ b/src/reducers/table-utils/kepler-table.ts
@@ -18,51 +18,36 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import Console from 'global/console';
-import {TRIP_POINT_FIELDS, SORT_ORDER, ALL_FIELD_TYPES, SCALE_TYPES} from '@kepler.gl/constants';
+import {console as Console} from 'global/console';
import {ascending, descending} from 'd3-array';
// import {validateInputData} from 'processors/data-processor';
-import {generateHashId} from 'utils/utils';
-import {getGpuFilterProps, getDatasetFieldIndexForFilter} from 'utils/gpu-filter-utils';
+import {TRIP_POINT_FIELDS, SORT_ORDER, ALL_FIELD_TYPES, SCALE_TYPES} from '@kepler.gl/constants';
+import {RGBColor, Field, FieldPair, FieldDomain, Filter, ProtoDataset} from '@kepler.gl/types';
+
+import {generateHashId, getSortingFunction, timeToUnixMilli} from '@kepler.gl/utils';
+import {getGpuFilterProps, getDatasetFieldIndexForFilter} from './gpu-filter-utils';
+
+import {createDataContainer} from './data-container-utils';
+
+import {Layer} from '@kepler.gl/layers';
import {
- getFilterProps,
- getFilterRecord,
diffFilters,
- getFilterFunction,
filterDataByFilterTypes,
+ FilterResult,
+ getFilterFunction,
+ getFilterProps,
+ getFilterRecord,
getNumericFieldDomain,
- getTimestampFieldDomain,
- FilterResult
-} from 'utils/filter-utils';
-import {maybeToDate, getSortingFunction} from 'utils/data-utils';
+ getTimestampFieldDomain
+} from '../filter-utils';
import {
- getQuantileDomain,
- getOrdinalDomain,
+ getLinearDomain,
getLogDomain,
- getLinearDomain
-} from 'utils/data-scale-utils';
-
-import {createDataContainer} from './data-container-utils';
-
-import {RGBColor} from '@kepler.gl/types';
-import {Layer} from '@kepler.gl/layers';
-import {FieldDomain, Filter} from 'reducers/vis-state-updaters';
+ getOrdinalDomain,
+ getQuantileDomain
+} from '../data-scale-utils';
import {DataContainerInterface} from './data-container-interface';
-import {ProtoDataset} from 'actions';
-
-export type Field = {
- analyzerType: string;
- id?: string;
- name: string;
- displayName: string;
- format: string;
- type: string;
- fieldIdx: number;
- valueAccessor(v: {index: number}): any;
- filterProps?: any;
- metadata?: any;
-};
export type GpuFilter = {
filterRange: number[][];
@@ -75,17 +60,6 @@ export type GpuFilter = {
) => (d: any) => number;
};
-export type FieldPair = {
- defaultName: string;
- pair: {
- [key: string]: {
- fieldIdx: number;
- value: string;
- };
- };
- suffix: string[];
-};
-
export type FilterRecord = {
dynamicDomain: Filter[];
fixedDomain: Filter[];
@@ -103,6 +77,20 @@ export type FilterDatasetOpt = {
// Unique identifier of each field
const FID_KEY = 'name';
+export function maybeToDate(
+ isTime: boolean,
+ fieldIdx: number,
+ format: string,
+ dc: DataContainerInterface,
+ d: {index: number}
+) {
+ if (isTime) {
+ return timeToUnixMilli(dc.valueAt(d.index, fieldIdx), format);
+ }
+
+ return dc.valueAt(d.index, fieldIdx);
+}
+
class KeplerTable {
readonly id: string;
@@ -476,6 +464,10 @@ class KeplerTable {
}
}
+export type Datasets = {
+ [key: string]: KeplerTable;
+};
+
// HELPER FUNCTIONS (MAINLY EXPORTED FOR TEST...)
export function removeSuffixAndDelimiters(layerName, suffix) {
diff --git a/src/utils/table-utils/row-data-container.ts b/src/reducers/table-utils/row-data-container.ts
similarity index 99%
rename from src/utils/table-utils/row-data-container.ts
rename to src/reducers/table-utils/row-data-container.ts
index 67b39587c..099b691d8 100644
--- a/src/utils/table-utils/row-data-container.ts
+++ b/src/reducers/table-utils/row-data-container.ts
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import {DataRow, SharedRowOptions} from './data-row';
-import {Field} from './kepler-table';
+import {Field} from '@kepler.gl/types';
import {DataContainerInterface, RangeOptions} from './data-container-interface';
type RowDataContainerInput = {
diff --git a/src/reducers/ui-state-updaters.ts b/src/reducers/ui-state-updaters.ts
index 4c5eecb57..4edc5ca83 100644
--- a/src/reducers/ui-state-updaters.ts
+++ b/src/reducers/ui-state-updaters.ts
@@ -28,38 +28,17 @@ import {
EXPORT_IMG_RATIOS,
EXPORT_MAP_FORMATS,
RESOLUTIONS,
- MAP_CONTROLS
+ MAP_CONTROLS,
+ ExportImage
} from '@kepler.gl/constants';
import {ActionTypes} from 'actions';
import {LOCALE_CODES} from '@kepler.gl/localization';
-import {createNotification, errorNotification} from 'utils/notifications-utils';
-import {calculateExportImageSize} from '../utils/export-utils';
+import {createNotification, errorNotification, calculateExportImageSize} from '@kepler.gl/utils';
import {payload_, apply_, compose_} from './composer-helpers';
import * as UiStateActions from 'actions/ui-state-actions';
import {KeplerGlInitPayload, LoadFilesErrUpdaterAction} from '../actions';
-export type ExportImage = {
- ratio: keyof typeof EXPORT_IMG_RATIOS;
- resolution: keyof typeof RESOLUTIONS;
- legend: boolean;
- mapH: number;
- mapW: number;
- imageSize: {
- zoomOffset: number;
- scale: number;
- imageW: number;
- imageH: number;
- };
- // exporting state
- imageDataUri: string;
- exporting: boolean;
- processing: boolean;
- error: Error | false;
- // This field was not in the .d.ts file
- center: boolean;
-};
-
export type ExportData = {
selectedDataset: string;
dataType: string;
diff --git a/src/reducers/vis-state-merger.ts b/src/reducers/vis-state-merger.ts
index 617d67744..fafc6e3c0 100644
--- a/src/reducers/vis-state-merger.ts
+++ b/src/reducers/vis-state-merger.ts
@@ -21,27 +21,18 @@
import uniq from 'lodash.uniq';
import pick from 'lodash.pick';
import flattenDeep from 'lodash.flattendeep';
-import {isObject, arrayInsert} from 'utils/utils';
-import {applyFiltersToDatasets, validateFiltersUpdateDatasets} from 'utils/filter-utils';
+import {isObject, arrayInsert, getInitialMapLayersForSplitMap} from '@kepler.gl/utils';
-import {getInitialMapLayersForSplitMap} from 'utils/split-map-utils';
-import {resetFilterGpuMode, assignGpuChannels} from 'utils/gpu-filter-utils';
+import {LayerColumns, LayerColumn, Layer} from '@kepler.gl/layers';
import {LAYER_BLENDINGS} from '@kepler.gl/constants';
-import {CURRENT_VERSION, visStateSchema} from 'schemas';
+import {CURRENT_VERSION, Merger, VisState, VisStateMergers, visStateSchema} from 'schemas';
-import {VisState, Datasets} from './vis-state-updaters';
-import {KeplerTable} from '../utils';
import {ParsedConfig, ParsedLayer} from 'schemas';
-import {Layer, LayerColumns, LayerColumn} from '@kepler.gl/layers';
-import {TooltipInfo} from './vis-state-updaters';
import {SavedInteractionConfig} from 'schemas';
-
-export type Merger = {
- merge: <S extends VisState>(state: S, config: any, fromConfig?: boolean) => S;
- prop: string;
- toMergeProp?: string;
-};
-export type VisStateMergers = Merger[];
+import {TooltipInfo} from '@kepler.gl/types';
+import KeplerTable, {Datasets} from './table-utils/kepler-table';
+import {applyFiltersToDatasets, validateFiltersUpdateDatasets} from './filter-utils';
+import {assignGpuChannels, resetFilterGpuMode} from './table-utils/gpu-filter-utils';
/**
* Merge loaded filters with current state, if no fields or data are loaded
diff --git a/src/reducers/vis-state-updaters.ts b/src/reducers/vis-state-updaters.ts
index b71e16444..2c7a17b9a 100644
--- a/src/reducers/vis-state-updaters.ts
+++ b/src/reducers/vis-state-updaters.ts
@@ -25,7 +25,6 @@ import uniq from 'lodash.uniq';
import get from 'lodash.get';
import xor from 'lodash.xor';
import copy from 'copy-to-clipboard';
-import {parseFieldValue} from 'utils/data-utils';
// Tasks
import {LOAD_FILE_TASK, UNWRAP_TASK, PROCESS_FILE_DATA, DELAY_TASK} from 'tasks/tasks';
// Actions
@@ -37,337 +36,74 @@ import {
nextFileBatch
} from 'actions/vis-state-actions';
// Utils
-import {findFieldsToShow, getDefaultInteraction} from 'utils/interaction-utils';
import {
- applyFilterFieldName,
- applyFiltersToDatasets,
- featureToFilterValue,
- FILTER_UPDATER_PROPS,
- filterDatasetCPU,
- generatePolygonFilter,
- getDefaultFilter,
- getDefaultFilterPlotType,
- getFilterIdInFeature,
- getFilterPlot,
- getTimeWidgetTitleFormatter,
- isInRange,
- LIMITED_FILTER_EFFECT_PROPS,
- updateFilterDataId
-} from 'utils/filter-utils';
-import {assignGpuChannel, setFilterGpuMode} from 'utils/gpu-filter-utils';
-import {createNewDataEntry} from 'utils/dataset-utils';
-import {
- pinTableColumns,
- sortDatasetByColumn,
- copyTableAndUpdate,
- Field
-} from 'utils/table-utils/kepler-table';
-import {set, toArray, arrayInsert, generateHashId} from 'utils/utils';
-
-import {calculateLayerData, findDefaultLayer} from 'utils/layer-utils';
+ set,
+ toArray,
+ arrayInsert,
+ generateHashId,
+ addNewLayersToSplitMap,
+ computeSplitMapLayers,
+ removeLayerFromSplitMaps,
+ isRgbColor,
+ parseFieldValue
+} from '@kepler.gl/utils';
import {
isValidMerger,
VIS_STATE_MERGERS,
validateLayerWithData,
createLayerFromConfig,
- serializeLayer,
- VisStateMergers
+ serializeLayer
} from './vis-state-merger';
-import {
- addNewLayersToSplitMap,
- computeSplitMapLayers,
- removeLayerFromSplitMaps
-} from 'utils/split-map-utils';
-
-import {Layer, LayerClasses, LayerClassesType, LAYER_ID_LENGTH} from '@kepler.gl/layers';
+import {Layer, LayerClasses, LAYER_ID_LENGTH} from '@kepler.gl/layers';
import {
EDITOR_MODES,
SORT_ORDER,
FILTER_TYPES,
MAX_DEFAULT_TOOLTIPS,
- DEFAULT_TEXT_LABEL
+ DEFAULT_TEXT_LABEL,
+ COMPARE_TYPES
} from '@kepler.gl/constants';
import {ActionTypes} from 'actions';
import {pick_, merge_, swap_} from './composer-helpers';
import {processFileContent} from 'actions/vis-state-actions';
-import KeplerGLSchema from 'schemas';
-import {isRgbColor} from 'utils/color-utils';
+import KeplerGLSchema, {VisState} from 'schemas';
-import {Millisecond} from '@kepler.gl/types';
+import {Filter, InteractionConfig, AnimationConfig, Editor} from '@kepler.gl/types';
import {ReceiveMapConfigPayload} from '../actions/actions';
import * as VisStateActions from 'actions/vis-state-actions';
import * as MapStateActions from 'actions/map-state-actions';
import {Loader} from '@loaders.gl/loader-utils';
-import {KeplerTable} from '../utils';
-
-export {KeplerTable};
-
-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<L extends LineChart> = {
- 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?: L;
- // gpu filter
- gpu: boolean;
- gpuChannel?: number[];
- fieldType?: string;
-
- // polygon
- layerId?: string[];
-};
-
-export type RangeFilter = FilterBase<LineChart> &
- RangeFieldDomain & {
- type: 'range';
- fieldType: 'real' | 'integer';
- value: [number, number];
- fixedDomain: true;
- typeOptions: ['range'];
- };
-
-export type SelectFilter = FilterBase<LineChart> &
- SelectFieldDomain & {
- type: 'select';
- fieldType: 'boolean';
- value: boolean;
- };
-
-export type MultiSelectFilter = FilterBase<LineChart> &
- MultiSelectFieldDomain & {
- type: 'range';
- fieldType: 'string' | 'date';
- value: string[];
- };
-export type TimeRangeFilter = FilterBase<LineChart> &
- TimeRangeFieldDomain & {
- type: 'timeRange';
- fieldType: 'timestamp';
- fixedDomain: true;
- value: [number, number];
- bins?: Object;
- plotType: {
- [key: string]: any;
- };
- animationWindow: string;
- };
-
-export type PolygonFilter = FilterBase<LineChart> & {
- layerId: string[];
- type: 'polygon';
- fixedDomain: true;
- value: Feature;
-};
-
-export type Filter =
- | FilterBase<LineChart>
- | 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: Loader[];
- loadOptions: object;
- initialState?: Partial<VisState>;
- mergers: VisStateMergers;
- schema: typeof KeplerGLSchema;
- preserveLayerOrder?: number[];
-};
+import {Messages, Crosshairs, CursorClick, Pin} from 'components/common/icons/index';
+import {
+ copyTableAndUpdate,
+ Datasets,
+ pinTableColumns,
+ sortDatasetByColumn
+} from './table-utils/kepler-table';
+import {calculateLayerData, findDefaultLayer} from './layer-utils';
+import {
+ applyFilterFieldName,
+ applyFiltersToDatasets,
+ featureToFilterValue,
+ filterDatasetCPU,
+ FILTER_UPDATER_PROPS,
+ generatePolygonFilter,
+ getDefaultFilter,
+ getFilterIdInFeature,
+ getTimeWidgetTitleFormatter,
+ isInRange,
+ LIMITED_FILTER_EFFECT_PROPS,
+ updateFilterDataId
+} from './filter-utils';
+import {assignGpuChannel, setFilterGpuMode} from './table-utils/gpu-filter-utils';
+import {createNewDataEntry} from './table-utils/dataset-utils';
+import {findFieldsToShow} from './interaction-utils';
+import {getFilterPlot} from './filter-utils';
+import {getDefaultFilterPlotType} from './filter-utils';
// react-palm
// disable capture exception for react-palm call to withTask
@@ -414,6 +150,44 @@ disableStackCapturing();
const visStateUpdaters = null;
/* eslint-enable no-unused-vars */
+export const defaultInteractionConfig: InteractionConfig = {
+ tooltip: {
+ id: 'tooltip',
+ label: 'interactions.tooltip',
+ enabled: true,
+ iconComponent: Messages,
+ config: {
+ fieldsToShow: {},
+ compareMode: false,
+ compareType: COMPARE_TYPES.ABSOLUTE
+ }
+ },
+ geocoder: {
+ id: 'geocoder',
+ label: 'interactions.geocoder',
+ enabled: false,
+ iconComponent: Pin,
+ position: null
+ },
+ brush: {
+ id: 'brush',
+ label: 'interactions.brush',
+ enabled: false,
+ iconComponent: Crosshairs,
+ config: {
+ // size is in km
+ size: 0.5
+ }
+ },
+ coordinate: {
+ id: 'coordinate',
+ label: 'interactions.coordinate',
+ enabled: false,
+ iconComponent: CursorClick,
+ position: null
+ }
+};
+
export const DEFAULT_ANIMATION_CONFIG: AnimationConfig = {
domain: null,
currentTime: null,
@@ -457,7 +231,7 @@ export const INITIAL_VIS_STATE: VisState = {
datasets: {},
editingDataset: undefined,
- interactionConfig: getDefaultInteraction(),
+ interactionConfig: defaultInteractionConfig,
interactionToBeMerged: undefined,
layerBlending: 'normal',
diff --git a/src/schemas/dataset-schema.ts b/src/schemas/dataset-schema.ts
index 58c101730..1725fe120 100644
--- a/src/schemas/dataset-schema.ts
+++ b/src/schemas/dataset-schema.ts
@@ -22,11 +22,11 @@ import pick from 'lodash.pick';
import {console as globalConsole} from 'global/window';
import {ProtoDataset} from 'actions';
-import {KeplerTable} from 'reducers';
+import {KeplerTable} from 'reducers/table-utils';
import {RGBColor} from 'types';
import {VERSIONS} from './versions';
import Schema from './schema';
-import {getFieldsFromData, getSampleForTypeAnalyze} from '@kepler.gl/processors';
+import {getFieldsFromData, getSampleForTypeAnalyze} from '@kepler.gl/utils';
export type SavedField = {
name: string;
diff --git a/src/schemas/schema-manager.ts b/src/schemas/schema-manager.ts
index f1ea92766..0a1945b26 100644
--- a/src/schemas/schema-manager.ts
+++ b/src/schemas/schema-manager.ts
@@ -20,17 +20,17 @@
import {console as Console} from 'global/window';
-import {Datasets} from 'reducers';
+import {Datasets} from 'reducers/table-utils';
import datasetSchema from './dataset-schema';
import mapStyleSchema from './map-style-schema';
import mapStateSchema from './map-state-schema';
import {SavedDatasetV1, ParsedDataset} from './dataset-schema';
-import {visStateSchema, SavedVisState, ParsedVisState} from './vis-state-schema';
+import {visStateSchema, ParsedVisState, SavedVisState} from './vis-state-schema';
import {CURRENT_VERSION, VERSIONS} from './versions';
-import {isPlainObject} from 'utils/utils';
-import {RGBColor} from 'types';
-import {VisState} from '../reducers';
+import {isPlainObject} from '@kepler.gl/utils';
+
+import {MapInfo, RGBColor} from '@kepler.gl/types';
export type SavedMapState = {
bearing: number;
@@ -170,7 +170,7 @@ export class KeplerGLSchema {
};
}
- getMapInfo(state: any): VisState['mapInfo'] {
+ getMapInfo(state: any): MapInfo {
return state.visState.mapInfo;
}
/**
diff --git a/src/schemas/vis-state-schema.ts b/src/schemas/vis-state-schema.ts
index 227233a75..08bcf7f18 100644
--- a/src/schemas/vis-state-schema.ts
+++ b/src/schemas/vis-state-schema.ts
@@ -20,22 +20,28 @@
import pick from 'lodash.pick';
import {VERSIONS} from './versions';
-import {isFilterValidToSave} from 'utils/filter-utils';
import {LAYER_VIS_CONFIGS} from '@kepler.gl/constants';
+import {notNullorUndefined} from '@kepler.gl/utils';
import Schema from './schema';
import cloneDeep from 'lodash.clonedeep';
-import {notNullorUndefined} from 'utils/data-utils';
-import {LayerTextLabel} from '@kepler.gl/types';
import {
- InteractionConfig,
+ AnimationConfig,
+ Editor,
+ FileLoading,
+ FileLoadingProgress,
Filter,
- TooltipInfo,
+ InteractionConfig,
+ LayerTextLabel,
+ MapInfo,
SplitMap,
- AnimationConfig,
- VisState
-} from 'reducers';
+ TooltipInfo
+} from '@kepler.gl/types';
+import {isFilterValidToSave} from 'reducers/filter-utils';
+import {Datasets} from 'reducers/table-utils';
import {RGBColor, Merge} from 'types';
-import {Layer} from 'layers';
+import {Layer, LayerClassesType} from '@kepler.gl/layers';
+import {Loader} from '@loaders.gl/loader-utils';
+import KeplerGLSchema from './schema-manager';
export type SavedFilter = {
dataId: Filter['dataId'];
@@ -143,6 +149,45 @@ export type modifiedType = {
stroked?: boolean;
};
+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: Loader[];
+ loadOptions: object;
+ initialState?: Partial<VisState>;
+ mergers: VisStateMergers;
+ schema: typeof KeplerGLSchema;
+ preserveLayerOrder?: number[];
+};
+
+export type Merger = {
+ merge: <S extends VisState>(state: S, config: any, fromConfig?: boolean) => S;
+ prop: string;
+ toMergeProp?: string;
+};
+export type VisStateMergers = Merger[];
+
// in v0 geojson there is only sizeField
// in v1 geojson
diff --git a/src/types/actions.d.ts b/src/types/actions.d.ts
new file mode 100644
index 000000000..4e61db5c0
--- /dev/null
+++ b/src/types/actions.d.ts
@@ -0,0 +1,24 @@
+export type ProtoDataset = {
+ info: {
+ id?: string;
+ label?: string;
+ format?: string;
+ color?: RGBColor;
+ type?: string;
+ };
+ data: {
+ fields: {
+ name: string;
+ type?: string;
+ format?: string;
+ displayName?: string;
+ id?: string;
+ }[];
+ rows: any[][];
+ };
+
+ // table-injected metadata
+ metadata?: any;
+ supportedFilterTypes?: string[] | null;
+ disableDataOperation?: boolean;
+};
diff --git a/src/types/layers.d.ts b/src/types/layers.d.ts
index 5e2728aef..ecc22b1d3 100644
--- a/src/types/layers.d.ts
+++ b/src/types/layers.d.ts
@@ -70,6 +70,17 @@ export type Field = {
metadata?: any;
};
+export type FieldPair = {
+ defaultName: string;
+ pair: {
+ [key: string]: {
+ fieldIdx: number;
+ value: string;
+ };
+ };
+ suffix: string[];
+};
+
export type LayerTextLabel = {
field: Field | null;
color: RGBColor;
diff --git a/src/types/reducers.d.ts b/src/types/reducers.d.ts
new file mode 100644
index 000000000..7439b914b
--- /dev/null
+++ b/src/types/reducers.d.ts
@@ -0,0 +1,262 @@
+import {Field, Millisecond} from './types';
+
+export type MapState = {
+ pitch: number;
+ bearing: number;
+ latitude: number;
+ longitude: number;
+ zoom: number;
+ dragRotate: boolean;
+ width: number;
+ height: number;
+ isSplit: boolean;
+ initialState?: any;
+ scale?: number;
+};
+
+export type Bounds = [number, number, number, number];
+
+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<L extends LineChart> = {
+ 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?: L;
+ // gpu filter
+ gpu: boolean;
+ gpuChannel?: number[];
+ fieldType?: string;
+
+ // polygon
+ layerId?: string[];
+};
+
+export type RangeFilter = FilterBase<LineChart> &
+ RangeFieldDomain & {
+ type: 'range';
+ fieldType: 'real' | 'integer';
+ value: [number, number];
+ fixedDomain: true;
+ typeOptions: ['range'];
+ };
+
+export type SelectFilter = FilterBase<LineChart> &
+ SelectFieldDomain & {
+ type: 'select';
+ fieldType: 'boolean';
+ value: boolean;
+ };
+
+export type MultiSelectFilter = FilterBase<LineChart> &
+ MultiSelectFieldDomain & {
+ type: 'range';
+ fieldType: 'string' | 'date';
+ value: string[];
+ };
+export type TimeRangeFilter = FilterBase<LineChart> &
+ TimeRangeFieldDomain & {
+ type: 'timeRange';
+ fieldType: 'timestamp';
+ fixedDomain: true;
+ value: [number, number];
+ bins?: Object;
+ plotType: {
+ [key: string]: any;
+ };
+ animationWindow: string;
+ };
+
+export type PolygonFilter = FilterBase<LineChart> & {
+ layerId: string[];
+ type: 'polygon';
+ fixedDomain: true;
+ value: Feature;
+};
+
+export type Filter =
+ | FilterBase<LineChart>
+ | RangeFilter
+ | TimeRangeFilter
+ | SelectFilter
+ | MultiSelectFilter
+ | PolygonFilter;
+
+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 LayerGroup = {
+ slug: string;
+ filter(layer: {id: string}): boolean;
+ defaultVisibility: boolean;
+};
+
+export type BaseMapStyle = {
+ id: string;
+ label: string;
+ url: string;
+ icon: string;
+ style?: Object;
+ layerGroups: LayerGroup[];
+ accessToken?: string;
+ custom?: boolean;
+};
diff --git a/src/types/types.d.ts b/src/types/types.d.ts
index 0c8c08a56..7825e9bd2 100644
--- a/src/types/types.d.ts
+++ b/src/types/types.d.ts
@@ -1,4 +1,6 @@
export * from './layers';
+export * from './reducers';
+export * from './actions';
export type RGBColor = [number, number, number];
export type RGBAColor = [number, number, number, number];
@@ -18,3 +20,9 @@ export type Entries<T> = {
export type NestedPartial<T> = {
[P in keyof T]?: NestedPartial<T[P]>;
};
+
+export type RowData = {
+ [key: string]: string | null;
+}[];
+
+export type ProcessorResult = {fields: Field[]; rows: any[][]} | null;
diff --git a/src/utils/babel.config.js b/src/utils/babel.config.js
new file mode 100644
index 000000000..8693d21ea
--- /dev/null
+++ b/src/utils/babel.config.js
@@ -0,0 +1,66 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+const KeplerPackage = require('./package');
+
+const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
+const PLUGINS = [
+ ['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
+ '@babel/plugin-transform-modules-commonjs',
+ '@babel/plugin-proposal-class-properties',
+ '@babel/plugin-proposal-export-namespace-from',
+ '@babel/plugin-proposal-optional-chaining',
+ [
+ '@babel/transform-runtime',
+ {
+ regenerator: true
+ }
+ ],
+ [
+ 'search-and-replace',
+ {
+ rules: [
+ {
+ search: '__PACKAGE_VERSION__',
+ replace: KeplerPackage.version
+ }
+ ]
+ }
+ ]
+];
+const ENV = {
+ test: {
+ plugins: ['istanbul']
+ },
+ debug: {
+ sourceMaps: 'inline',
+ retainLines: true
+ }
+};
+
+module.exports = function babel(api) {
+ api.cache(true);
+
+ return {
+ presets: PRESETS,
+ plugins: PLUGINS,
+ env: ENV
+ };
+};
diff --git a/src/utils/dataset-utils.ts b/src/utils/dataset-utils.ts
deleted file mode 100644
index 2d36c6eea..000000000
--- a/src/utils/dataset-utils.ts
+++ /dev/null
@@ -1,261 +0,0 @@
-// Copyright (c) 2022 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-import {hexToRgb} from './color-utils';
-import uniq from 'lodash.uniq';
-import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
-import {validateInputData} from '@kepler.gl/processors';
-import KeplerTable, {Field} from './table-utils/kepler-table';
-
-import {Datasets} from '../reducers/vis-state-updaters';
-import {ProtoDataset} from '../actions';
-import {RGBColor} from '@kepler.gl/types';
-
-// apply a color for each dataset
-// to use as label colors
-const datasetColors = [
- '#8F2FBF',
- '#005CFF',
- '#C06C84',
- '#F8B195',
- '#547A82',
- '#3EACA8',
- '#A2D4AB'
-].map(hexToRgb);
-
-/**
- * Random color generator
- */
-function* generateColor(): Generator<RGBColor> {
- let index = 0;
- while (index < datasetColors.length + 1) {
- if (index === datasetColors.length) {
- index = 0;
- }
- yield datasetColors[index++];
- }
-}
-
-export const datasetColorMaker = generateColor();
-
-/** @type {typeof import('./dataset-utils').getNewDatasetColor} */
-export function getNewDatasetColor(datasets: Datasets): RGBColor {
- const presetColors = datasetColors.map(String);
- const usedColors = uniq(Object.values(datasets).map(d => String(d.color))).filter(c =>
- presetColors.includes(c)
- );
-
- if (usedColors.length === presetColors.length) {
- // if we already depleted the pool of color
- return datasetColorMaker.next().value;
- }
-
- let color = datasetColorMaker.next().value;
- while (usedColors.includes(String(color))) {
- color = datasetColorMaker.next().value;
- }
-
- return color;
-}
-
-/**
- * Take datasets payload from addDataToMap, create datasets entry save to visState
- */
-export function createNewDataEntry(
- {info, data, ...opts}: ProtoDataset,
- datasets: Datasets = {}
-): Datasets {
- const validatedData = validateInputData(data);
- if (!validatedData) {
- return {};
- }
-
- info = info || {};
- const color = info.color || getNewDatasetColor(datasets);
-
- const keplerTable = new KeplerTable({info, data: validatedData, color, ...opts});
- return {
- [keplerTable.id]: keplerTable
- };
-}
-
-/**
- * Field name prefixes and suffixes which should not be considered
- * as metrics. Fields will still be included if a 'metric word'
- * is found on the field name, however.
- */
-const EXCLUDED_DEFAULT_FIELDS = [
- // Serial numbers and identification numbers
- '_id',
- 'id',
- 'index',
- 'uuid',
- 'guid',
- 'uid',
- 'gid',
- 'serial',
- // Geographic IDs are unlikely to be interesting to color
- 'zip',
- 'code',
- 'post',
- 'region',
- 'fips',
- 'cbgs',
- 'h3',
- 's2',
- // Geographic coords (but not z/elevation/altitude
- // since that might be a metric)
- 'lat',
- 'lon',
- 'lng',
- 'latitude',
- 'longitude',
- '_x',
- '_y'
-];
-
-/**
- * Prefixes and suffixes that indicate a field is a metric.
- *
- * Note that these are in order of preference, first being
- * most preferred.
- */
-const METRIC_DEFAULT_FIELDS = [
- 'metric',
- 'value',
- 'sum',
- 'count',
- 'unique',
- 'mean',
- 'mode',
- 'median',
- 'max',
- 'min',
- 'deviation',
- 'variance',
- 'p99',
- 'p95',
- 'p75',
- 'p50',
- 'p25',
- 'p05',
- // Abbreviations are less preferred
- 'cnt',
- 'val'
-];
-
-/**
- * Choose a field to use as the default color field of a layer.
- *
- * The heuristic is:
- *
- * First, exclude fields that are on the exclusion list and don't
- * have names that suggest they contain metrics. Also exclude
- * field names that are blank.
- *
- * Next, look for a field that is of real type and contains one
- * of the preferred names (in order of the preferred names).
- *
- * Next, look for a field that is of integer type and contains
- * one of the preferred names (in order of the preferred names).
- *
- * Next, look for the first field that is of real type (in order
- * of field index).
- *
- * Next, look for the first field that is of integer type (in
- * order of field index).
- *
- * It's possible no field will be chosen (i.e. because all fields
- * are strings.)
- *
- * @param dataset
- */
-export function findDefaultColorField({fields, fieldPairs = []}: KeplerTable): null | Field {
- const fieldsWithoutExcluded = fields.filter(field => {
- if (field.type !== ALL_FIELD_TYPES.real && field.type !== ALL_FIELD_TYPES.integer) {
- // Only select numeric fields.
- return false;
- }
- if (
- fieldPairs.find(
- pair => pair.pair.lat.value === field.name || pair.pair.lng.value === field.name
- )
- ) {
- // Do not permit lat, lon fields
- return false;
- }
-
- const normalizedFieldName = field.name.toLowerCase();
- if (normalizedFieldName === '') {
- // Special case excluded name when the name is blank.
- return false;
- }
- const hasExcluded = EXCLUDED_DEFAULT_FIELDS.find(
- f => normalizedFieldName.startsWith(f) || normalizedFieldName.endsWith(f)
- );
- const hasInclusion = METRIC_DEFAULT_FIELDS.find(
- f => normalizedFieldName.startsWith(f) || normalizedFieldName.endsWith(f)
- );
- return !hasExcluded || hasInclusion;
- });
-
- const sortedFields = fieldsWithoutExcluded.sort((left, right) => {
- const normalizedLeft = left.name.toLowerCase();
- const normalizedRight = right.name.toLowerCase();
- const leftHasInclusion = METRIC_DEFAULT_FIELDS.findIndex(
- f => normalizedLeft.startsWith(f) || normalizedLeft.endsWith(f)
- );
- const rightHasInclusion = METRIC_DEFAULT_FIELDS.findIndex(
- f => normalizedRight.startsWith(f) || normalizedRight.endsWith(f)
- );
- if (leftHasInclusion !== rightHasInclusion) {
- if (leftHasInclusion === -1) {
- // Elements that do not have the inclusion list should go after those that do.
- return 1;
- } else if (rightHasInclusion === -1) {
- // Elements that do have the inclusion list should go before those that don't.
- return -1;
- }
- // Compare based on order in the inclusion list
- return leftHasInclusion - rightHasInclusion;
- }
-
- // Compare based on type
- if (left.type !== right.type) {
- if (left.type === ALL_FIELD_TYPES.real) {
- return -1;
- }
- // left is an integer and right is not
- // and reals come before integers
- return 1;
- }
-
- // Finally, order based on the order in the datasets columns
- // @ts-expect-error
- return left.index - right.index;
- });
-
- if (sortedFields.length) {
- // There was a best match
- return sortedFields[0];
- }
- // No matches
- return null;
-}
diff --git a/src/utils/index.ts b/src/utils/index.ts
deleted file mode 100644
index 822bfdd21..000000000
--- a/src/utils/index.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (c) 2022 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-// UTILS
-export {
- maybeToDate,
- roundValToStep,
- timeToUnixMilli,
- defaultFormatter,
- FIELD_DISPLAY_FORMAT
-} from './data-utils';
-export {createNewDataEntry, datasetColorMaker, findDefaultColorField} from './dataset-utils';
-export {hexToRgb} from './color-utils';
-export {errorNotification} from './notifications-utils';
-export {dataURItoBlob, downloadFile, exportJson} from './export-utils';
-export {calculateLayerData, prepareLayersToRender, prepareLayersForDeck} from './layer-utils';
-export {
- applyFilterFieldName,
- applyFiltersToDatasets,
- validateFilterWithData,
- validateFiltersUpdateDatasets,
- getIntervalBins,
- getNumericStepSize,
- formatNumberByStep
-} from 'utils/filter-utils';
-export {resetFilterGpuMode, assignGpuChannels} from 'utils/gpu-filter-utils';
-
-// REDUCER UTILS
-export {updateAllLayerDomainData} from '../reducers/vis-state-updaters';
-export {
- validateLayerWithData,
- validateLayersByDatasets,
- validateSavedVisualChannels,
- mergeLayers
-} from '../reducers/vis-state-merger';
-
-export {getHexFields, containValidTime} from '@kepler.gl/layers';
-
-export {
- default as KeplerTable,
- findPointFieldPairs,
- getFieldValueAccessor,
- copyTable,
- copyTableAndUpdate
-} from './table-utils/kepler-table';
-export {createDataContainer, createIndexedDataContainer} from './table-utils/data-container-utils';
-
-// Render
-export {renderedSize} from 'components/common/data-table/cell-size';
-
-export * from './color-utils';
-export * from './data-scale-utils';
-export * from './data-utils';
-export * from './dataset-utils';
-export * from './gpu-filter-utils';
-export * from './interaction-utils';
-export * from './layer-utils';
-export * from './observe-dimensions';
-
-// Layers
-export {computeDeckLayers} from './layer-utils';
-
-// Mapbox
-export {transformRequest} from './map-style-utils/mapbox-utils';
-
-// Map
-export {onViewPortChange} from './map-utils';
diff --git a/src/utils/package.json b/src/utils/package.json
new file mode 100644
index 000000000..37213f9e2
--- /dev/null
+++ b/src/utils/package.json
@@ -0,0 +1,84 @@
+{
+ "name": "@kepler.gl/utils",
+ "author": "Shan He <[email protected]>",
+ "version": "2.5.5",
+ "description": "kepler.gl constants used by kepler.gl components, actions and reducers",
+ "license": "MIT",
+ "main": "dist/index.js",
+ "types": "index.d.ts",
+ "keywords": [
+ "babel",
+ "es6",
+ "react",
+ "webgl",
+ "visualization",
+ "deck.gl"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/keplergl/kepler.gl.git"
+ },
+ "scripts": {
+ "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build:umd": "webpack --config ./webpack/umd.js --progress --env.prod",
+ "build:types": "tsc --project ./tsconfig.production.json",
+ "prepublish": "uber-licence && yarn build && yarn build:types",
+ "stab": "mkdir -p dist && touch dist/index.js"
+ },
+ "files": [
+ "dist",
+ "umd"
+ ],
+ "dependencies": {
+ "@deck.gl/geo-layers": "^8.5.4",
+ "@deck.gl/core": "^8.5.4",
+ "@deck.gl/extensions": "^8.5.4",
+ "@deck.gl/layers": "^8.5.4",
+ "@deck.gl/mesh-layers": "^8.5.4",
+ "@kepler.gl/deckgl-layers": "^2.5.5",
+ "@kepler.gl/layers": "^2.5.5",
+ "@kepler.gl/constants": "^2.5.5",
+ "@kepler.gl/types": "^2.5.5",
+ "@loaders.gl/core": "^3.0.9",
+ "@loaders.gl/gltf": "^3.0.9",
+ "@mapbox/geojson-normalize": "0.0.1",
+ "@turf/bbox": "^6.0.1",
+ "@types/geojson": "^7946.0.7",
+ "global": "^4.3.0",
+ "h3-js": "^3.1.0",
+ "keymirror": "^0.1.1",
+ "lodash.memoize": "^4.1.2",
+ "lodash.uniq": "^4.0.1",
+ "long": "^4.0.0",
+ "react": "^16.8.4",
+ "s2-geometry": "^1.2.10",
+ "styled-components": "^4.1.3",
+ "type-analyzer": "0.3.0",
+ "viewport-mercator-project": "^6.0.0",
+ "wellknown": "^0.5.0"
+ },
+ "exports": {
+ ".": "./dist/index.js",
+ "./*": "./dist/*"
+ },
+ "typesVersions": {
+ "*": {
+ "*": ["dist/*"]
+ }
+ },
+ "nyc": {
+ "sourceMap": false,
+ "instrument": false
+ },
+ "engines": {
+ "node": ">=12.0.0"
+ },
+ "maintainers": [
+ "Shan He <[email protected]>",
+ "Giuseppe Macri <[email protected]>"
+ ],
+ "volta": {
+ "node": "12.22.0",
+ "yarn": "1.22.17"
+ }
+}
diff --git a/src/utils/aggregate-utils.ts b/src/utils/src/aggregate-utils.ts
similarity index 100%
rename from src/utils/aggregate-utils.ts
rename to src/utils/src/aggregate-utils.ts
diff --git a/src/utils/color-utils.ts b/src/utils/src/color-utils.ts
similarity index 100%
rename from src/utils/color-utils.ts
rename to src/utils/src/color-utils.ts
diff --git a/src/utils/data-utils.ts b/src/utils/src/data-utils.ts
similarity index 85%
rename from src/utils/data-utils.ts
rename to src/utils/src/data-utils.ts
index 533752e82..0ebf38b44 100644
--- a/src/utils/data-utils.ts
+++ b/src/utils/src/data-utils.ts
@@ -29,19 +29,10 @@ import {format as d3Format} from 'd3-format';
import {bisectLeft} from 'd3-array';
import moment from 'moment-timezone';
-import {Millisecond} from '@kepler.gl/types';
-import {Layer} from '@kepler.gl/layers';
-import {Bounds} from 'reducers/map-state-updaters';
-import {DataContainerInterface} from './table-utils/data-container-interface';
-import {Field} from './table-utils/kepler-table';
+import {Millisecond, Field} from '@kepler.gl/types';
export type FieldFormatter = (value: any) => string;
-const MAX_LATITUDE = 90;
-const MIN_LATITUDE = -90;
-const MAX_LONGITUDE = 180;
-const MIN_LONGITUDE = -180;
-
/**
* simple getting unique values of an array
*
@@ -59,42 +50,6 @@ export function unique<T>(values: T[]) {
return results;
}
-/**
- * return center of map from given points
- * @param layers
- * @returns coordinates of map center, empty if not found
- */
-export function findMapBounds(layers: Layer[]): Bounds | null {
- // find bounds in formatted layerData
- // take ALL layers into account when finding map bounds
- const availableLayerBounds: Bounds | [] = layers.reduce((res, l) => {
- // @ts-expect-error
- if (l.meta && l.meta.bounds) {
- // @ts-expect-error
- res.push(l.meta.bounds);
- }
- return res;
- }, []);
- // return null if no layer is available
- if (availableLayerBounds.length === 0) {
- return null;
- }
- // merge bounds in each layer
- const newBounds = (availableLayerBounds as Bounds).reduce(
- (res, b) => {
- return [
- Math.min(res[0], b[0]),
- Math.min(res[1], b[1]),
- Math.max(res[2], b[2]),
- Math.max(res[3], b[3])
- ];
- },
- [MAX_LONGITUDE, MAX_LATITUDE, MIN_LONGITUDE, MIN_LATITUDE]
- );
- // @ts-expect-error
- return newBounds;
-}
-
export function getLatLngBounds(
points: number[][],
idx: number,
@@ -141,20 +96,6 @@ export function timeToUnixMilli(value: string | number, format: string): Millise
return null;
}
-export function maybeToDate(
- isTime: boolean,
- fieldIdx: number,
- format: string,
- dc: DataContainerInterface,
- d: {index: number}
-) {
- if (isTime) {
- return timeToUnixMilli(dc.valueAt(d.index, fieldIdx), format);
- }
-
- return dc.valueAt(d.index, fieldIdx);
-}
-
/**
* whether null or undefined
*/
@@ -168,13 +109,27 @@ export function notNullorUndefined<T extends NonNullable<any>>(d: T | null | und
export function isNumber(d: any): boolean {
return Number.isFinite(d);
}
+
/**
- * whether null or undefined
+ * whether is an object
+ * @returns {boolean} - yes or no
*/
-export function isPlainObject(obj: any): boolean {
+export function isPlainObject(obj: unknown): obj is Record<string, unknown> {
return obj === Object(obj) && typeof obj !== 'function' && !Array.isArray(obj);
}
+/**
+ * whether object has property
+ * @param {string} prop
+ * @returns {boolean} - yes or no
+ */
+export function hasOwnProperty<X extends {}, Y extends PropertyKey>(
+ obj: X,
+ prop: Y
+): obj is X & Record<Y, unknown> {
+ return obj.hasOwnProperty(prop);
+}
+
export function numberSort(a: number, b: number): number {
return a - b;
}
diff --git a/src/utils/src/dataset-utils.ts b/src/utils/src/dataset-utils.ts
new file mode 100644
index 000000000..5b2e53f07
--- /dev/null
+++ b/src/utils/src/dataset-utils.ts
@@ -0,0 +1,539 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import {console as globalConsole} from 'global/window';
+import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
+import {Analyzer, DATA_TYPES as AnalyzerDATA_TYPES} from 'type-analyzer';
+import assert from 'assert';
+
+import {ProcessorResult, RGBColor, RowData, Field, FieldPair} from '@kepler.gl/types';
+
+import {notNullorUndefined, isPlainObject} from './data-utils';
+import {range} from 'd3-array';
+import {hexToRgb} from './color-utils';
+
+// apply a color for each dataset
+// to use as label colors
+const datasetColors = [
+ '#8F2FBF',
+ '#005CFF',
+ '#C06C84',
+ '#F8B195',
+ '#547A82',
+ '#3EACA8',
+ '#A2D4AB'
+].map(hexToRgb);
+
+/**
+ * Random color generator
+ */
+function* generateColor(): Generator<RGBColor> {
+ let index = 0;
+ while (index < datasetColors.length + 1) {
+ if (index === datasetColors.length) {
+ index = 0;
+ }
+ yield datasetColors[index++];
+ }
+}
+
+export const datasetColorMaker = generateColor();
+
+/**
+ * Field name prefixes and suffixes which should not be considered
+ * as metrics. Fields will still be included if a 'metric word'
+ * is found on the field name, however.
+ */
+const EXCLUDED_DEFAULT_FIELDS = [
+ // Serial numbers and identification numbers
+ '_id',
+ 'id',
+ 'index',
+ 'uuid',
+ 'guid',
+ 'uid',
+ 'gid',
+ 'serial',
+ // Geographic IDs are unlikely to be interesting to color
+ 'zip',
+ 'code',
+ 'post',
+ 'region',
+ 'fips',
+ 'cbgs',
+ 'h3',
+ 's2',
+ // Geographic coords (but not z/elevation/altitude
+ // since that might be a metric)
+ 'lat',
+ 'lon',
+ 'lng',
+ 'latitude',
+ 'longitude',
+ '_x',
+ '_y'
+];
+
+/**
+ * Prefixes and suffixes that indicate a field is a metric.
+ *
+ * Note that these are in order of preference, first being
+ * most preferred.
+ */
+const METRIC_DEFAULT_FIELDS = [
+ 'metric',
+ 'value',
+ 'sum',
+ 'count',
+ 'unique',
+ 'mean',
+ 'mode',
+ 'median',
+ 'max',
+ 'min',
+ 'deviation',
+ 'variance',
+ 'p99',
+ 'p95',
+ 'p75',
+ 'p50',
+ 'p25',
+ 'p05',
+ // Abbreviations are less preferred
+ 'cnt',
+ 'val'
+];
+
+/**
+ * Choose a field to use as the default color field of a layer.
+ *
+ * The heuristic is:
+ *
+ * First, exclude fields that are on the exclusion list and don't
+ * have names that suggest they contain metrics. Also exclude
+ * field names that are blank.
+ *
+ * Next, look for a field that is of real type and contains one
+ * of the preferred names (in order of the preferred names).
+ *
+ * Next, look for a field that is of integer type and contains
+ * one of the preferred names (in order of the preferred names).
+ *
+ * Next, look for the first field that is of real type (in order
+ * of field index).
+ *
+ * Next, look for the first field that is of integer type (in
+ * order of field index).
+ *
+ * It's possible no field will be chosen (i.e. because all fields
+ * are strings.)
+ *
+ * @param dataset
+ */
+export function findDefaultColorField({
+ fields,
+ fieldPairs = []
+}: {
+ fields: Field[];
+ fieldPairs: FieldPair[];
+}): null | Field {
+ const fieldsWithoutExcluded = fields.filter(field => {
+ if (field.type !== ALL_FIELD_TYPES.real && field.type !== ALL_FIELD_TYPES.integer) {
+ // Only select numeric fields.
+ return false;
+ }
+ if (
+ fieldPairs.find(
+ pair => pair.pair.lat.value === field.name || pair.pair.lng.value === field.name
+ )
+ ) {
+ // Do not permit lat, lon fields
+ return false;
+ }
+
+ const normalizedFieldName = field.name.toLowerCase();
+ if (normalizedFieldName === '') {
+ // Special case excluded name when the name is blank.
+ return false;
+ }
+ const hasExcluded = EXCLUDED_DEFAULT_FIELDS.find(
+ f => normalizedFieldName.startsWith(f) || normalizedFieldName.endsWith(f)
+ );
+ const hasInclusion = METRIC_DEFAULT_FIELDS.find(
+ f => normalizedFieldName.startsWith(f) || normalizedFieldName.endsWith(f)
+ );
+ return !hasExcluded || hasInclusion;
+ });
+
+ const sortedFields = fieldsWithoutExcluded.sort((left, right) => {
+ const normalizedLeft = left.name.toLowerCase();
+ const normalizedRight = right.name.toLowerCase();
+ const leftHasInclusion = METRIC_DEFAULT_FIELDS.findIndex(
+ f => normalizedLeft.startsWith(f) || normalizedLeft.endsWith(f)
+ );
+ const rightHasInclusion = METRIC_DEFAULT_FIELDS.findIndex(
+ f => normalizedRight.startsWith(f) || normalizedRight.endsWith(f)
+ );
+ if (leftHasInclusion !== rightHasInclusion) {
+ if (leftHasInclusion === -1) {
+ // Elements that do not have the inclusion list should go after those that do.
+ return 1;
+ } else if (rightHasInclusion === -1) {
+ // Elements that do have the inclusion list should go before those that don't.
+ return -1;
+ }
+ // Compare based on order in the inclusion list
+ return leftHasInclusion - rightHasInclusion;
+ }
+
+ // Compare based on type
+ if (left.type !== right.type) {
+ if (left.type === ALL_FIELD_TYPES.real) {
+ return -1;
+ }
+ // left is an integer and right is not
+ // and reals come before integers
+ return 1;
+ }
+
+ // Finally, order based on the order in the datasets columns
+ // @ts-expect-error
+ return left.index - right.index;
+ });
+
+ if (sortedFields.length) {
+ // There was a best match
+ return sortedFields[0];
+ }
+ // No matches
+ return null;
+}
+
+export const ACCEPTED_ANALYZER_TYPES = [
+ AnalyzerDATA_TYPES.DATE,
+ AnalyzerDATA_TYPES.TIME,
+ AnalyzerDATA_TYPES.DATETIME,
+ AnalyzerDATA_TYPES.NUMBER,
+ AnalyzerDATA_TYPES.INT,
+ AnalyzerDATA_TYPES.FLOAT,
+ AnalyzerDATA_TYPES.BOOLEAN,
+ AnalyzerDATA_TYPES.STRING,
+ AnalyzerDATA_TYPES.GEOMETRY,
+ AnalyzerDATA_TYPES.GEOMETRY_FROM_STRING,
+ AnalyzerDATA_TYPES.PAIR_GEOMETRY_FROM_STRING,
+ AnalyzerDATA_TYPES.ZIPCODE,
+ AnalyzerDATA_TYPES.ARRAY,
+ AnalyzerDATA_TYPES.OBJECT
+];
+
+const IGNORE_DATA_TYPES = Object.keys(AnalyzerDATA_TYPES).filter(
+ type => !ACCEPTED_ANALYZER_TYPES.includes(type)
+);
+
+/**
+ * Validate input data, adding missing field types, rename duplicate columns
+ */
+export function validateInputData(data: Record<string, unknown>): ProcessorResult {
+ if (!isPlainObject(data)) {
+ assert('addDataToMap Error: dataset.data cannot be null');
+ return null;
+ } else if (!Array.isArray(data.fields)) {
+ assert('addDataToMap Error: expect dataset.data.fields to be an array');
+ return null;
+ } else if (!Array.isArray(data.rows)) {
+ assert('addDataToMap Error: expect dataset.data.rows to be an array');
+ return null;
+ }
+
+ const {fields, rows} = data;
+
+ // check if all fields has name, format and type
+ const allValid = fields.every((f, i) => {
+ if (!isPlainObject(f)) {
+ assert(`fields needs to be an array of object, but find ${typeof f}`);
+ fields[i] = {};
+ }
+
+ if (!f.name) {
+ assert(`field.name is required but missing in ${JSON.stringify(f)}`);
+ // assign a name
+ fields[i].name = `column_${i}`;
+ }
+
+ if (!ALL_FIELD_TYPES[f.type]) {
+ assert(`unknown field type ${f.type}`);
+ return false;
+ }
+
+ if (!fields.every(field => field.analyzerType)) {
+ assert('field missing analyzerType');
+ return false;
+ }
+
+ // check time format is correct based on first 10 not empty element
+ if (f.type === ALL_FIELD_TYPES.timestamp) {
+ const sample = findNonEmptyRowsAtField(rows, i, 10).map(r => ({ts: r[i]}));
+ const analyzedType = Analyzer.computeColMeta(sample)[0];
+ return analyzedType && analyzedType.category === 'TIME' && analyzedType.format === f.format;
+ }
+
+ return true;
+ });
+
+ if (allValid) {
+ return {rows, fields};
+ }
+
+ // if any field has missing type, recalculate it for everyone
+ // because we simply lost faith in humanity
+ const sampleData = getSampleForTypeAnalyze({
+ fields: fields.map(f => f.name),
+ rows
+ });
+ const fieldOrder = fields.map(f => f.name);
+ const meta = getFieldsFromData(sampleData, fieldOrder);
+ const updatedFields = fields.map((f, i) => ({
+ ...f,
+ type: meta[i].type,
+ format: meta[i].format,
+ analyzerType: meta[i].analyzerType
+ }));
+
+ return {fields: updatedFields, rows};
+}
+
+function findNonEmptyRowsAtField(rows: unknown[][], fieldIdx: number, total: number): any[] {
+ const sample: any[] = [];
+ let i = 0;
+ while (sample.length < total && i < rows.length) {
+ if (notNullorUndefined(rows[i]?.[fieldIdx])) {
+ sample.push(rows[i]);
+ }
+ i++;
+ }
+ return sample;
+}
+/**
+ * Getting sample data for analyzing field type.
+ */
+export function getSampleForTypeAnalyze({
+ fields,
+ rows,
+ sampleCount = 50
+}: {
+ fields: string[];
+ rows: unknown[][];
+ sampleCount?: number;
+}): RowData {
+ const total = Math.min(sampleCount, rows.length);
+ // const fieldOrder = fields.map(f => f.name);
+ const sample = range(0, total, 1).map(d => ({}));
+
+ // collect sample data for each field
+ fields.forEach((field, fieldIdx) => {
+ // data counter
+ let i = 0;
+ // sample counter
+ let j = 0;
+
+ while (j < total) {
+ if (i >= rows.length) {
+ // if depleted data pool
+ sample[j][field] = null;
+ j++;
+ } else if (notNullorUndefined(rows[i][fieldIdx])) {
+ const value = rows[i][fieldIdx];
+ sample[j][field] = typeof value === 'string' ? value.trim() : value;
+ j++;
+ i++;
+ } else {
+ i++;
+ }
+ }
+ });
+
+ return sample;
+}
+
+/**
+ * Analyze field types from data in `string` format, e.g. uploaded csv.
+ * Assign `type`, `fieldIdx` and `format` (timestamp only) to each field
+ *
+ * @param data array of row object
+ * @param fieldOrder array of field names as string
+ * @returns formatted fields
+ * @public
+ * @example
+ *
+ * import {getFieldsFromData} from 'kepler.gl/processors';
+ * const data = [{
+ * time: '2016-09-17 00:09:55',
+ * value: '4',
+ * surge: '1.2',
+ * isTrip: 'true',
+ * zeroOnes: '0'
+ * }, {
+ * time: '2016-09-17 00:30:08',
+ * value: '3',
+ * surge: null,
+ * isTrip: 'false',
+ * zeroOnes: '1'
+ * }, {
+ * time: null,
+ * value: '2',
+ * surge: '1.3',
+ * isTrip: null,
+ * zeroOnes: '1'
+ * }];
+ *
+ * const fieldOrder = ['time', 'value', 'surge', 'isTrip', 'zeroOnes'];
+ * const fields = getFieldsFromData(data, fieldOrder);
+ * // fields = [
+ * // {name: 'time', format: 'YYYY-M-D H:m:s', fieldIdx: 1, type: 'timestamp'},
+ * // {name: 'value', format: '', fieldIdx: 4, type: 'integer'},
+ * // {name: 'surge', format: '', fieldIdx: 5, type: 'real'},
+ * // {name: 'isTrip', format: '', fieldIdx: 6, type: 'boolean'},
+ * // {name: 'zeroOnes', format: '', fieldIdx: 7, type: 'integer'}];
+ *
+ */
+export function getFieldsFromData(data: RowData, fieldOrder: string[]): Field[] {
+ // add a check for epoch timestamp
+ const metadata = Analyzer.computeColMeta(
+ data,
+ [
+ {regex: /.*geojson|all_points/g, dataType: 'GEOMETRY'},
+ {regex: /.*census/g, dataType: 'STRING'}
+ ],
+ {ignoredDataTypes: IGNORE_DATA_TYPES}
+ );
+
+ const {fieldByIndex} = renameDuplicateFields(fieldOrder);
+
+ const result = fieldOrder.map((field, index) => {
+ const name = fieldByIndex[index];
+
+ const fieldMeta = metadata.find(m => m.key === field);
+ const {type, format} = fieldMeta || {};
+
+ return {
+ name,
+ id: name,
+ displayName: name,
+ format,
+ fieldIdx: index,
+ type: analyzerTypeToFieldType(type),
+ analyzerType: type,
+ valueAccessor: dc => d => {
+ return dc.valueAt(d.index, index);
+ }
+ };
+ });
+
+ return result;
+}
+
+/**
+ * pass in an array of field names, rename duplicated one
+ * and return a map from old field index to new name
+ *
+ * @param fieldOrder
+ * @returns new field name by index
+ */
+export function renameDuplicateFields(
+ fieldOrder: string[]
+): {allNames: string[]; fieldByIndex: string[]} {
+ return fieldOrder.reduce<{allNames: string[]; fieldByIndex: string[]}>(
+ (accu, field, i) => {
+ const {allNames} = accu;
+ let fieldName = field;
+
+ // add a counter to duplicated names
+ if (allNames.includes(field)) {
+ let counter = 0;
+ while (allNames.includes(`${field}-${counter}`)) {
+ counter++;
+ }
+ fieldName = `${field}-${counter}`;
+ }
+
+ accu.fieldByIndex[i] = fieldName;
+ accu.allNames.push(fieldName);
+
+ return accu;
+ },
+ {allNames: [], fieldByIndex: []}
+ );
+}
+
+/**
+ * Convert type-analyzer output to kepler.gl field types
+ *
+ * @param aType
+ * @returns corresponding type in `ALL_FIELD_TYPES`
+ */
+/* eslint-disable complexity */
+export function analyzerTypeToFieldType(aType: string): string {
+ const {
+ DATE,
+ TIME,
+ DATETIME,
+ NUMBER,
+ INT,
+ FLOAT,
+ BOOLEAN,
+ STRING,
+ GEOMETRY,
+ GEOMETRY_FROM_STRING,
+ PAIR_GEOMETRY_FROM_STRING,
+ ZIPCODE,
+ ARRAY,
+ OBJECT
+ } = AnalyzerDATA_TYPES;
+
+ // TODO: un recognized types
+ // CURRENCY PERCENT NONE
+ switch (aType) {
+ case DATE:
+ return ALL_FIELD_TYPES.date;
+ case TIME:
+ case DATETIME:
+ return ALL_FIELD_TYPES.timestamp;
+ case FLOAT:
+ return ALL_FIELD_TYPES.real;
+ case INT:
+ return ALL_FIELD_TYPES.integer;
+ case BOOLEAN:
+ return ALL_FIELD_TYPES.boolean;
+ case GEOMETRY:
+ case GEOMETRY_FROM_STRING:
+ case PAIR_GEOMETRY_FROM_STRING:
+ case ARRAY:
+ case OBJECT:
+ // TODO: create a new data type for objects and arrays
+ return ALL_FIELD_TYPES.geojson;
+ case NUMBER:
+ case STRING:
+ case ZIPCODE:
+ return ALL_FIELD_TYPES.string;
+ default:
+ globalConsole.warn(`Unsupported analyzer type: ${aType}`);
+ return ALL_FIELD_TYPES.string;
+ }
+}
diff --git a/src/utils/dom-to-image.ts b/src/utils/src/dom-to-image.ts
similarity index 100%
rename from src/utils/dom-to-image.ts
rename to src/utils/src/dom-to-image.ts
diff --git a/src/utils/dom-utils.ts b/src/utils/src/dom-utils.ts
similarity index 100%
rename from src/utils/dom-utils.ts
rename to src/utils/src/dom-utils.ts
diff --git a/src/templates/export-map-html.ts b/src/utils/src/export-map-html.ts
similarity index 100%
rename from src/templates/export-map-html.ts
rename to src/utils/src/export-map-html.ts
diff --git a/src/utils/export-utils.ts b/src/utils/src/export-utils.ts
similarity index 79%
rename from src/utils/export-utils.ts
rename to src/utils/src/export-utils.ts
index 7a0a01a03..f07ecd5c2 100644
--- a/src/utils/export-utils.ts
+++ b/src/utils/src/export-utils.ts
@@ -18,25 +18,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import domtoimage from 'utils/dom-to-image';
import {Blob, URL, atob, Uint8Array, ArrayBuffer, document} from 'global/window';
+import get from 'lodash.get';
+
import {
EXPORT_IMG_RESOLUTION_OPTIONS,
EXPORT_IMG_RATIO_OPTIONS,
RESOLUTIONS,
EXPORT_IMG_RATIOS,
- EXPORT_DATA_TYPE,
FourByThreeRatioOption,
- OneXResolutionOption
+ OneXResolutionOption,
+ ExportImage
} from '@kepler.gl/constants';
-import {exportMapToHTML} from 'templates/export-map-html';
-import {formatCsv} from '@kepler.gl/processors';
-import get from 'lodash.get';
-import {set, generateHashId} from 'utils/utils';
-
-import {createIndexedDataContainer} from './table-utils/data-container-utils';
-import {ExportImage} from 'reducers/ui-state-updaters';
-import {VisState} from 'reducers';
+import domtoimage from './dom-to-image';
+import {generateHashId, set} from './utils';
+import {exportMapToHTML} from './export-map-html';
/**
* Default file names
@@ -209,47 +205,6 @@ export function exportHtml(state, options) {
downloadFile(fileBlob, state.appName ? `${state.appName}.html` : DEFAULT_HTML_NAME);
}
-interface StateType {
- visState: VisState;
- appName?: string;
-}
-
-export function exportData(state: StateType, options) {
- const {visState, appName} = state;
- const {datasets} = visState;
- const {selectedDataset, dataType, filtered} = options;
- // get the selected data
- const filename = appName ? appName : DEFAULT_DATA_NAME;
- const selectedDatasets = datasets[selectedDataset]
- ? [datasets[selectedDataset]]
- : Object.values(datasets);
- if (!selectedDatasets.length) {
- // error: selected dataset not found.
- return;
- }
-
- selectedDatasets.forEach(selectedData => {
- const {dataContainer, fields, label, filteredIdxCPU = []} = selectedData;
- const toExport = filtered
- ? createIndexedDataContainer(dataContainer, filteredIdxCPU)
- : dataContainer;
-
- // start to export data according to selected data type
- switch (dataType) {
- case EXPORT_DATA_TYPE.CSV: {
- const csv = formatCsv(toExport, fields);
-
- const fileBlob = new Blob([csv], {type: 'text/csv'});
- downloadFile(fileBlob, `${filename}_${label}.csv`);
- break;
- }
- // TODO: support more file types.
- default:
- break;
- }
- });
-}
-
export function exportMap(state, options = DEFAULT_EXPORT_JSON_SETTINGS) {
const {imageDataUri} = state.uiState.exportImage;
const thumbnail: Blob | null = imageDataUri ? dataURItoBlob(imageDataUri) : null;
@@ -264,8 +219,7 @@ export function exportMap(state, options = DEFAULT_EXPORT_JSON_SETTINGS) {
const exporters = {
exportImage,
exportJson,
- exportHtml,
- exportData
+ exportHtml
};
export default exporters;
diff --git a/src/utils/src/filter-utils.ts b/src/utils/src/filter-utils.ts
new file mode 100644
index 000000000..71b598485
--- /dev/null
+++ b/src/utils/src/filter-utils.ts
@@ -0,0 +1,34 @@
+import {FILTER_TYPES} from '@kepler.gl/constants';
+import get from 'lodash.get';
+
+/**
+ * Sanity check on filters to prepare for save
+ */
+
+/* eslint-disable complexity */
+export function isValidFilterValue(type: string | null, value: any): boolean {
+ if (!type) {
+ return false;
+ }
+ switch (type) {
+ case FILTER_TYPES.select:
+ return value === true || value === false;
+
+ case FILTER_TYPES.range:
+ case FILTER_TYPES.timeRange:
+ return Array.isArray(value) && value.every(v => v !== null && !isNaN(v));
+
+ case FILTER_TYPES.multiSelect:
+ return Array.isArray(value) && Boolean(value.length);
+
+ case FILTER_TYPES.input:
+ return Boolean(value.length);
+
+ case FILTER_TYPES.polygon:
+ const coordinates = get(value, ['geometry', 'coordinates']);
+ return Boolean(value && value.id && coordinates);
+
+ default:
+ return true;
+ }
+}
diff --git a/src/utils/gl-utils.ts b/src/utils/src/gl-utils.ts
similarity index 100%
rename from src/utils/gl-utils.ts
rename to src/utils/src/gl-utils.ts
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
new file mode 100644
index 000000000..731dfc28b
--- /dev/null
+++ b/src/utils/src/index.ts
@@ -0,0 +1,150 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// UTILS
+
+export {
+ hexToRgb,
+ isHexColor,
+ rgbToHex,
+ getColorGroupByName,
+ reverseColorRange,
+ createLinearGradient,
+ isRgbColor
+} from './color-utils';
+export {errorNotification} from './notifications-utils';
+
+export {getHexFields, containValidTime} from '@kepler.gl/layers';
+
+export {createNotification, exportImageError, successNotification} from './notifications-utils';
+
+export {default as domtoimage} from './dom-to-image';
+export {getFrequency, getMode, aggregate} from './aggregate-utils';
+// eslint-disable-next-line prettier/prettier
+export type {FieldFormatter} from './data-utils';
+export {
+ unique,
+ getLatLngBounds,
+ clamp,
+ getSampleData,
+ timeToUnixMilli,
+ notNullorUndefined,
+ isNumber,
+ isPlainObject,
+ hasOwnProperty,
+ numberSort,
+ getSortingFunction,
+ preciseRound,
+ getRoundingDecimalFromStep,
+ snapToMarks,
+ normalizeSliderValue,
+ roundValToStep,
+ defaultFormatter,
+ FIELD_DISPLAY_FORMAT,
+ parseFieldValue,
+ arrayMove,
+ getFormatter,
+ applyDefaultFormat,
+ getBooleanFormatter,
+ applyCustomFormat,
+ datetimeFormatter
+} from './data-utils';
+export {
+ datasetColorMaker,
+ findDefaultColorField,
+ ACCEPTED_ANALYZER_TYPES,
+ validateInputData,
+ getSampleForTypeAnalyze,
+ getFieldsFromData,
+ renameDuplicateFields,
+ analyzerTypeToFieldType
+} from './dataset-utils';
+export {exportMapToHTML} from './export-map-html';
+export {
+ DEFAULT_IMAGE_NAME,
+ DEFAULT_HTML_NAME,
+ DEFAULT_JSON_NAME,
+ DEFAULT_DATA_NAME,
+ DEFAULT_EXPORT_JSON_SETTINGS,
+ isMSEdge,
+ getScaleFromImageSize,
+ calculateExportImageSize,
+ convertToPng,
+ dataURItoBlob,
+ downloadFile,
+ exportImage,
+ exportToJsonString,
+ getMapJSON,
+ exportJson,
+ exportHtml,
+ exportMap,
+ default as exporters
+} from './export-utils';
+export {isValidFilterValue} from './filter-utils';
+export {setLayerBlending} from './gl-utils';
+export {flattenMessages, mergeMessages} from './locale-utils';
+export type {Dimensions} from './observe-dimensions';
+export {
+ observeDimensions,
+ unobserveDimensions,
+ default as useDimensions
+} from './observe-dimensions';
+export {validateBounds, getCenterAndZoomFromBounds} from './projection-utils';
+export {validateToken} from './mapbox-utils';
+export {
+ getDefaultLayerGroupVisibility,
+ editTopMapStyle,
+ editBottomMapStyle,
+ isValidStyleUrl,
+ getStyleDownloadUrl,
+ getStyleImageIcon,
+ scaleMapStyleByResolution,
+ mergeLayerGroupVisibility
+} from './map-style-utils/mapbox-gl-style-editor';
+export {isValidMapInfo} from './map-info-utils';
+export {
+ generateHashId,
+ isChrome,
+ capitalizeFirstLetter,
+ camelToTitle,
+ camelize,
+ getHTMLMapModeTileUrl,
+ toArray,
+ insertValue,
+ isObject,
+ set,
+ getError,
+ arrayInsert,
+ isTest,
+ filterObjectByPredicate,
+ isFunction
+} from './utils';
+export {
+ addNewLayersToSplitMap,
+ removeLayerFromSplitMaps,
+ getInitialMapLayersForSplitMap,
+ computeSplitMapLayers
+} from './split-map-utils';
+
+// Mapbox
+export {transformRequest} from './map-style-utils/mapbox-utils';
+
+// Map
+export {onViewPortChange, getMapLayersFromSplitMaps} from './map-utils';
diff --git a/src/utils/locale-utils.ts b/src/utils/src/locale-utils.ts
similarity index 100%
rename from src/utils/locale-utils.ts
rename to src/utils/src/locale-utils.ts
diff --git a/src/utils/map-info-utils.ts b/src/utils/src/map-info-utils.ts
similarity index 100%
rename from src/utils/map-info-utils.ts
rename to src/utils/src/map-info-utils.ts
diff --git a/src/utils/map-style-utils/mapbox-gl-style-editor.ts b/src/utils/src/map-style-utils/mapbox-gl-style-editor.ts
similarity index 98%
rename from src/utils/map-style-utils/mapbox-gl-style-editor.ts
rename to src/utils/src/map-style-utils/mapbox-gl-style-editor.ts
index 738e7f556..18b86cf84 100644
--- a/src/utils/map-style-utils/mapbox-gl-style-editor.ts
+++ b/src/utils/src/map-style-utils/mapbox-gl-style-editor.ts
@@ -21,7 +21,8 @@
import memoize from 'lodash.memoize';
import clondDeep from 'lodash.clonedeep';
import {DEFAULT_LAYER_GROUPS, DEFAULT_MAPBOX_API_URL} from '@kepler.gl/constants';
-import {BaseMapStyle, LayerGroup, MapState} from 'reducers';
+import {BaseMapStyle, LayerGroup} from '@kepler.gl/types';
+import {MapState} from '@kepler.gl/types';
const mapUrlRg = /^mapbox:\/\/styles\/[-a-z0-9]{2,256}\/[-a-z0-9]{2,256}/;
const httpRg = /^(?=(http:|https:))/;
diff --git a/src/utils/map-style-utils/mapbox-utils.ts b/src/utils/src/map-style-utils/mapbox-utils.ts
similarity index 100%
rename from src/utils/map-style-utils/mapbox-utils.ts
rename to src/utils/src/map-style-utils/mapbox-utils.ts
diff --git a/src/utils/map-utils.ts b/src/utils/src/map-utils.ts
similarity index 92%
rename from src/utils/map-utils.ts
rename to src/utils/src/map-utils.ts
index a6735f337..c705cd2cd 100644
--- a/src/utils/map-utils.ts
+++ b/src/utils/src/map-utils.ts
@@ -1,5 +1,5 @@
import {TRANSITION_DURATION} from '@kepler.gl/constants';
-import {SplitMapLayers, SplitMap} from 'reducers/vis-state-updaters';
+import {SplitMapLayers, SplitMap} from '@kepler.gl/types';
export const onViewPortChange = (
viewState: any,
diff --git a/src/utils/mapbox-utils.ts b/src/utils/src/mapbox-utils.ts
similarity index 94%
rename from src/utils/mapbox-utils.ts
rename to src/utils/src/mapbox-utils.ts
index c85dc6a6e..a67c03a10 100644
--- a/src/utils/mapbox-utils.ts
+++ b/src/utils/src/mapbox-utils.ts
@@ -24,4 +24,4 @@
* @param {string} token the Mapbox token to validate
* @return {boolean} true if token is valid, false otherwise
*/
-export const validateToken = token => (token || '') !== '';
+export const validateToken = (token: string): boolean => (token || '') !== '';
diff --git a/src/utils/notifications-utils.ts b/src/utils/src/notifications-utils.ts
similarity index 100%
rename from src/utils/notifications-utils.ts
rename to src/utils/src/notifications-utils.ts
diff --git a/src/utils/observe-dimensions.ts b/src/utils/src/observe-dimensions.ts
similarity index 97%
rename from src/utils/observe-dimensions.ts
rename to src/utils/src/observe-dimensions.ts
index e964094b5..341b86e97 100644
--- a/src/utils/observe-dimensions.ts
+++ b/src/utils/src/observe-dimensions.ts
@@ -19,9 +19,8 @@
// THE SOFTWARE.
import throttle from 'lodash.throttle';
-import {useEffect, useRef, useState} from 'react';
+import {useEffect, useRef, useState, RefObject} from 'react';
import ResizeObserver from 'resize-observer-polyfill';
-import {RefObject} from 'react';
export interface Dimensions {
readonly height: number;
diff --git a/src/utils/projection-utils.ts b/src/utils/src/projection-utils.ts
similarity index 100%
rename from src/utils/projection-utils.ts
rename to src/utils/src/projection-utils.ts
diff --git a/src/utils/searcher-utils.ts b/src/utils/src/searcher-utils.ts
similarity index 100%
rename from src/utils/searcher-utils.ts
rename to src/utils/src/searcher-utils.ts
diff --git a/src/utils/split-map-utils.ts b/src/utils/src/split-map-utils.ts
similarity index 100%
rename from src/utils/split-map-utils.ts
rename to src/utils/src/split-map-utils.ts
diff --git a/src/utils/utils.ts b/src/utils/src/utils.ts
similarity index 91%
rename from src/utils/utils.ts
rename to src/utils/src/utils.ts
index 45e167ee1..f58c1d05e 100644
--- a/src/utils/utils.ts
+++ b/src/utils/src/utils.ts
@@ -40,26 +40,6 @@ export function isChrome() {
return window.chrome && window.chrome.webstore;
}
-/**
- * whether is an object
- * @returns {boolean} - yes or no
- */
-export function isPlainObject(obj: unknown): obj is Record<string, unknown> {
- return obj === Object(obj) && typeof obj !== 'function' && !Array.isArray(obj);
-}
-
-/**
- * whether object has property
- * @param {string} prop
- * @returns {boolean} - yes or no
- */
-export function hasOwnProperty<X extends {}, Y extends PropertyKey>(
- obj: X,
- prop: Y
-): obj is X & Record<Y, unknown> {
- return obj.hasOwnProperty(prop);
-}
-
/**
* Capitalize first letter of a string
* @param {string} str
@@ -98,7 +78,9 @@ export const camelize = str => {
* @param mode export option
* @return {string} url
*/
-export {getHTMLMapModeTileUrl} from '@kepler.gl/constants';
+export function getHTMLMapModeTileUrl(mode) {
+ return `https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/documentation/map-${mode.toLowerCase()}-mode.png`;
+}
/**
* Converts non-arrays to arrays. Leaves arrays alone. Converts
diff --git a/src/utils/tsconfig.production.json b/src/utils/tsconfig.production.json
new file mode 100644
index 000000000..cddf14f7c
--- /dev/null
+++ b/src/utils/tsconfig.production.json
@@ -0,0 +1,33 @@
+{
+ "compilerOptions": {
+ "target": "es2020",
+ "allowJs": false,
+ "checkJs": false,
+ "jsx": "react",
+ "module": "esnext",
+ "moduleResolution": "node",
+ "declaration":true,
+ "emitDeclarationOnly":true,
+ "noImplicitAny": false,
+ "noImplicitReturns": true,
+ "noImplicitThis": true,
+ "noUnusedLocals": true,
+ "outDir": "dist",
+ "sourceMap": true,
+ "strictNullChecks": true,
+ "suppressImplicitAnyIndexErrors": false,
+ "esModuleInterop": true,
+ "allowSyntheticDefaultImports": true,
+ "skipLibCheck": true,
+ "strict": true,
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "baseUrl": "./src", //TODO change once all dependencies are isolated
+ "paths": {
+ "*": ["*"] //TODO change once all dependencies are isolated
+ }
+ },
+ "include": [
+ "src"
+ ]
+}
diff --git a/test/browser/components/modals/data-table-modal-test.js b/test/browser/components/modals/data-table-modal-test.js
index 2c5504c62..47f2c06a9 100644
--- a/test/browser/components/modals/data-table-modal-test.js
+++ b/test/browser/components/modals/data-table-modal-test.js
@@ -39,9 +39,9 @@ import OptionDropdown from 'components/common/data-table/option-dropdown';
import {testFields, testAllData} from 'test/fixtures/test-csv-data';
import {geoStyleFields, geoStyleRows} from 'test/fixtures/geojson';
import {StateWFiles, testCsvDataId, testGeoJsonDataId} from 'test/helpers/mock-state';
-import {appInjector} from '../../../../src/components/container';
+import {appInjector} from 'components/container';
-import {createDataContainer} from 'utils/table-utils';
+import {createDataContainer} from 'reducers/table-utils';
const DataTableModal = appInjector.get(DataTableModalFactory);
const DataTable = appInjector.get(DataTableFactory);
diff --git a/test/browser/components/notifications/notification-item-test.js b/test/browser/components/notifications/notification-item-test.js
index 2aa7d85ab..406211029 100644
--- a/test/browser/components/notifications/notification-item-test.js
+++ b/test/browser/components/notifications/notification-item-test.js
@@ -22,7 +22,7 @@ import React from 'react';
import test from 'tape';
import {shallow} from 'enzyme';
import NotificationItemFactory from 'components/notification-panel/notification-item';
-import {createNotification} from 'utils/notifications-utils';
+import {createNotification} from '@kepler.gl/utils';
import {theme} from '@kepler.gl/styles';
const NotificationItem = NotificationItemFactory();
diff --git a/test/browser/components/notifications/notification-panel-test.js b/test/browser/components/notifications/notification-panel-test.js
index 1a8880748..df6161ae2 100644
--- a/test/browser/components/notifications/notification-panel-test.js
+++ b/test/browser/components/notifications/notification-panel-test.js
@@ -24,7 +24,7 @@ import sinon from 'sinon';
import {shallow} from 'enzyme';
import NotificationItemFactory from 'components/notification-panel/notification-item';
import NotificationPanelFactory from 'components/notification-panel';
-import {createNotification} from 'utils/notifications-utils';
+import {createNotification} from '@kepler.gl/utils';
import {theme} from '@kepler.gl/styles';
const NotificationItem = NotificationItemFactory();
diff --git a/test/browser/components/side-panel/color-selector-test.js b/test/browser/components/side-panel/color-selector-test.js
index 62f3e394c..c01da15a1 100644
--- a/test/browser/components/side-panel/color-selector-test.js
+++ b/test/browser/components/side-panel/color-selector-test.js
@@ -50,7 +50,7 @@ import {COLOR_RANGES} from '@kepler.gl/constants';
import {StateWFilesFiltersLayerColor, StateWTrips} from 'test/helpers/mock-state';
import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
-import {hexToRgb} from 'utils/color-utils';
+import {hexToRgb} from '../../../../src/utils';
test('Components -> ColorSelector.render', t => {
t.doesNotThrow(() => {
diff --git a/test/browser/layer-tests/arc-layer-specs.js b/test/browser/layer-tests/arc-layer-specs.js
index 2a2d7f9db..b84c855c7 100644
--- a/test/browser/layer-tests/arc-layer-specs.js
+++ b/test/browser/layer-tests/arc-layer-specs.js
@@ -34,7 +34,7 @@ import {
import {PROJECTED_PIXEL_SIZE_MULTIPLIER} from '@kepler.gl/constants';
import {KeplerGlLayers} from '@kepler.gl/layers';
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
+import {copyTableAndUpdate} from 'reducers/table-utils';
const {ArcLayer} = KeplerGlLayers;
const columns = {
diff --git a/test/browser/layer-tests/geojson-layer-specs.js b/test/browser/layer-tests/geojson-layer-specs.js
index a8286c333..24f47b7d8 100644
--- a/test/browser/layer-tests/geojson-layer-specs.js
+++ b/test/browser/layer-tests/geojson-layer-specs.js
@@ -19,7 +19,8 @@
// THE SOFTWARE.
import test from 'tape';
-import {KeplerGlLayers, defaultElevation, defaultLineWidth, defaultRadius} from '@kepler.gl/layers';
+import {defaultElevation, defaultLineWidth, defaultRadius, KeplerGlLayers} from '@kepler.gl/layers';
+import {copyTableAndUpdate} from 'reducers/table-utils';
const {GeojsonLayer} = KeplerGlLayers;
@@ -40,9 +41,8 @@ import {
geoStyleDataToFeature,
geoStyleMeta
} from 'test/fixtures/geojson';
-import {createNewDataEntry} from 'utils/dataset-utils';
import {processGeojson} from '@kepler.gl/processors';
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
+import {createNewDataEntry} from 'reducers';
test('#GeojsonLayer -> constructor', t => {
const TEST_CASES = {
diff --git a/test/browser/layer-tests/grid-layer-specs.js b/test/browser/layer-tests/grid-layer-specs.js
index 2b39d8221..6a6aca0ca 100644
--- a/test/browser/layer-tests/grid-layer-specs.js
+++ b/test/browser/layer-tests/grid-layer-specs.js
@@ -31,7 +31,7 @@ import {
pointLayerMeta
} from 'test/helpers/layer-utils';
-import {KeplerGlLayers, pointToPolygonGeo} from '@kepler.gl/layers';
+import {pointToPolygonGeo, KeplerGlLayers} from '@kepler.gl/layers';
const {GridLayer} = KeplerGlLayers;
import {INITIAL_MAP_STATE} from 'reducers/map-state-updaters';
diff --git a/test/browser/layer-tests/h3-hexagon-layer-specs.js b/test/browser/layer-tests/h3-hexagon-layer-specs.js
index 77415229e..f09e8b9cf 100644
--- a/test/browser/layer-tests/h3-hexagon-layer-specs.js
+++ b/test/browser/layer-tests/h3-hexagon-layer-specs.js
@@ -32,11 +32,12 @@ import {
hexagonIdLayerMeta
} from 'test/helpers/layer-utils';
import {
- KeplerGlLayers,
getCentroid,
+ KeplerGlLayers,
h3DefaultElevation as defaultElevation
} from '@kepler.gl/layers';
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
+
+import {copyTableAndUpdate} from 'reducers/table-utils';
const {H3Layer} = KeplerGlLayers;
const columns = {
diff --git a/test/browser/layer-tests/heatmap-layer-specs.js b/test/browser/layer-tests/heatmap-layer-specs.js
index bfc6dff84..adab1b0e7 100644
--- a/test/browser/layer-tests/heatmap-layer-specs.js
+++ b/test/browser/layer-tests/heatmap-layer-specs.js
@@ -29,12 +29,11 @@ import {
import {StateWFiles, testCsvDataId} from 'test/helpers/mock-state';
import {gpsPointBounds} from 'test/fixtures/test-csv-data';
-import {KeplerGlLayers, MAX_ZOOM_LEVEL} from '@kepler.gl/layers';
+import {MAX_ZOOM_LEVEL, KeplerGlLayers} from '@kepler.gl/layers';
+import {copyTableAndUpdate} from 'reducers/table-utils';
const {HeatmapLayer} = KeplerGlLayers;
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
-
const columns = {
lat: 'lat',
lng: 'lng'
diff --git a/test/browser/layer-tests/icon-layer-specs.js b/test/browser/layer-tests/icon-layer-specs.js
index 2ad346b8a..aa1d805fe 100644
--- a/test/browser/layer-tests/icon-layer-specs.js
+++ b/test/browser/layer-tests/icon-layer-specs.js
@@ -24,6 +24,7 @@ import {mount} from 'enzyme';
import sinon from 'sinon';
import sinonStubPromise from 'sinon-stub-promise';
import {getDistanceScales} from 'viewport-mercator-project';
+import {copyTableAndUpdate} from 'reducers/table-utils';
import {KeplerGlLayers} from '@kepler.gl/layers';
import {DEFAULT_TEXT_LABEL, PROJECTED_PIXEL_SIZE_MULTIPLIER} from '@kepler.gl/constants';
@@ -41,7 +42,6 @@ import {
} from 'test/helpers/layer-utils';
import {INITIAL_MAP_STATE} from 'reducers/map-state-updaters';
import {IntlWrapper} from '../../helpers/component-utils';
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
const {IconLayer} = KeplerGlLayers;
const columns = {
diff --git a/test/browser/layer-tests/line-layer-specs.js b/test/browser/layer-tests/line-layer-specs.js
index 551d34364..894f3b54a 100644
--- a/test/browser/layer-tests/line-layer-specs.js
+++ b/test/browser/layer-tests/line-layer-specs.js
@@ -33,7 +33,7 @@ import {
import {PROJECTED_PIXEL_SIZE_MULTIPLIER} from '@kepler.gl/constants';
import {KeplerGlLayers} from '@kepler.gl/layers';
-import {copyTable, copyTableAndUpdate} from 'utils/table-utils/kepler-table';
+import {copyTable, copyTableAndUpdate} from 'reducers/table-utils';
const {LineLayer} = KeplerGlLayers;
const columns = {
diff --git a/test/browser/layer-tests/point-layer-specs.js b/test/browser/layer-tests/point-layer-specs.js
index 9b95c0e7e..6e66eb23b 100644
--- a/test/browser/layer-tests/point-layer-specs.js
+++ b/test/browser/layer-tests/point-layer-specs.js
@@ -33,9 +33,9 @@ import {
fieldDomain
} from 'test/helpers/layer-utils';
+import {copyTableAndUpdate} from 'reducers/table-utils';
import {KeplerGlLayers} from '@kepler.gl/layers';
import {INITIAL_MAP_STATE} from 'reducers/map-state-updaters';
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
import {DEFAULT_TEXT_LABEL, PROJECTED_PIXEL_SIZE_MULTIPLIER} from '@kepler.gl/constants';
const {PointLayer} = KeplerGlLayers;
diff --git a/test/browser/layer-tests/s2-geometry-layer-specs.js b/test/browser/layer-tests/s2-geometry-layer-specs.js
index f65e00058..634fcef7b 100644
--- a/test/browser/layer-tests/s2-geometry-layer-specs.js
+++ b/test/browser/layer-tests/s2-geometry-layer-specs.js
@@ -30,12 +30,11 @@ import {
testRows,
preparedFilterDomain0
} from 'test/helpers/layer-utils';
-import {KeplerGlLayers, s2DefaultElevation as defaultElevation} from '@kepler.gl/layers';
+import {s2DefaultElevation as defaultElevation, KeplerGlLayers} from '@kepler.gl/layers';
+import {copyTableAndUpdate} from 'reducers/table-utils';
const {S2GeometryLayer} = KeplerGlLayers;
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
-
test('#S2Geometry -> constructor', t => {
const TEST_CASES = [
{
diff --git a/test/browser/layer-tests/trip-layer-specs.js b/test/browser/layer-tests/trip-layer-specs.js
index af7c85122..081daa00d 100644
--- a/test/browser/layer-tests/trip-layer-specs.js
+++ b/test/browser/layer-tests/trip-layer-specs.js
@@ -23,11 +23,12 @@ import test from 'tape';
import cloneDeep from 'lodash.clonedeep';
import {
- KeplerGlLayers,
tripDefaultLineWidth as defaultLineWidth,
- parseTripGeoJsonTimestamp
+ parseTripGeoJsonTimestamp,
+ KeplerGlLayers
} from '@kepler.gl/layers';
+import {copyTableAndUpdate} from 'reducers/table-utils';
const {TripLayer} = KeplerGlLayers;
import {
@@ -40,7 +41,6 @@ import {
animationConfig
} from 'test/helpers/layer-utils';
import {TripLayerMeta, dataToFeature, dataToTimeStamp} from 'test/fixtures/trip-geojson';
-import {copyTableAndUpdate} from 'utils/table-utils/kepler-table';
test('#TripLayer -> constructor', t => {
const TEST_CASES = {
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index 8fff3114f..b72fb1005 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -20,8 +20,8 @@
import {KeplerGlLayers} from '@kepler.gl/layers';
const {PointLayer, ArcLayer, HexagonLayer, GeojsonLayer} = KeplerGlLayers;
-import {getDefaultInteraction} from 'utils/interaction-utils';
import {DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI} from '@kepler.gl/constants';
+import {defaultInteractionConfig} from 'reducers/vis-state-updaters';
export const savedStateV0 = {
config: {
@@ -1477,11 +1477,10 @@ mergedLayer4.meta = {
export const mergedLayers = [mergedLayer0, mergedLayer1, mergedLayer2, mergedLayer3, mergedLayer4];
-const defaultInteraction = getDefaultInteraction();
export const mergedInteractions = {
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: true,
config: {
compareMode: false,
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index 25ff5c654..b01bb792c 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -19,10 +19,10 @@
// THE SOFTWARE.
import {KeplerGlLayers} from '@kepler.gl/layers';
-import {getDefaultInteraction} from 'utils/interaction-utils';
import {DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI} from '@kepler.gl/constants';
const {GeojsonLayer} = KeplerGlLayers;
+import {defaultInteractionConfig} from 'reducers/vis-state-updaters';
export const savedStateV1 = {
datasets: [
@@ -2779,11 +2779,10 @@ mergedLayer1.dataToFeature = mergedLayer0.dataToFeature;
export const mergedLayers = [mergedLayer0, mergedLayer1];
-const defaultInteraction = getDefaultInteraction();
export const mergedInteraction = {
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: false,
config: {
compareMode: false,
@@ -2807,7 +2806,7 @@ export const mergedInteraction = {
}
},
brush: {
- ...defaultInteraction.brush,
+ ...defaultInteractionConfig.brush,
enabled: false,
config: {
size: 1
diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.js
index 77d174e03..051802c22 100644
--- a/test/fixtures/test-hex-id-data.js
+++ b/test/fixtures/test-hex-id-data.js
@@ -19,11 +19,10 @@
// THE SOFTWARE.
import {KeplerGlLayers} from '@kepler.gl/layers';
+import {createDataContainer} from 'reducers/table-utils';
import {DEFAULT_COLOR_UI} from '@kepler.gl/constants';
const {H3Layer} = KeplerGlLayers;
-import {createDataContainer} from 'utils/table-utils';
-
export default `hex_id,value
89283082c2fffff,64
8928308288fffff,73
diff --git a/test/helpers/comparison-utils.js b/test/helpers/comparison-utils.js
index 5175bf0b5..168f961a2 100644
--- a/test/helpers/comparison-utils.js
+++ b/test/helpers/comparison-utils.js
@@ -18,10 +18,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {FILTER_TYPES} from '../../src/constants/src/default-settings';
-import {toArray} from '../../src/utils/utils';
-import {getFieldValueAccessor} from '../../src/utils';
-import KeplerTable from '../../src/utils/table-utils/kepler-table';
+import {FILTER_TYPES} from '@kepler.gl/constants';
+import {toArray} from '../../src/utils';
+import {KeplerTable} from '../../src/reducers/table-utils';
export function cmpObjectKeys(t, expectedObj, actualObj, name) {
t.deepEqual(
diff --git a/test/helpers/layer-utils.js b/test/helpers/layer-utils.js
index df257e452..462be2e2c 100644
--- a/test/helpers/layer-utils.js
+++ b/test/helpers/layer-utils.js
@@ -32,8 +32,7 @@ import * as VisStateActions from 'actions/vis-state-actions';
import {addDataToMap} from 'actions/actions';
import {colorMaker, layerColors, LayerClasses} from '@kepler.gl/layers';
-import {getGpuFilterProps} from 'utils/gpu-filter-utils';
-import {renderDeckGlLayer} from 'utils/layer-utils';
+import {getGpuFilterProps, renderDeckGlLayer} from 'reducers';
import {validateLayerWithData} from 'reducers/vis-state-merger';
import {processCsvData, processGeojson} from '@kepler.gl/processors';
import {applyActions, InitialState} from 'test/helpers/mock-state';
@@ -46,7 +45,7 @@ import tripGeoJson from 'test/fixtures/trip-geojson';
import {logStep} from '../../scripts/log';
import {IntlWrapper} from './component-utils';
-import mapState from '../../src/reducers/map-state';
+import mapState from 'reducers/map-state';
export const dataId = '0dj3h';
export const timeFilter = [{name: 'utc_timestamp', value: [1474071095000, 1474071608000]}];
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index e52eb8c09..6dba80ec4 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -35,10 +35,10 @@ import visStateReducer from 'reducers/vis-state';
import coreReducer from 'reducers/core';
import {updateVisData} from 'actions/vis-state-actions';
import {receiveMapConfig, addDataToMap} from 'actions/actions';
-import {getDefaultInteraction} from 'utils/interaction-utils';
import {processKeplerglJSON} from '@kepler.gl/processors';
+import {defaultInteractionConfig} from 'reducers/vis-state-updaters';
-import {createDataContainer} from 'utils/table-utils';
+import {createDataContainer} from 'reducers/table-utils';
// fixtures
import {
@@ -767,12 +767,11 @@ test('VisStateMerger.v0 -> mergeInteractions -> toWorkingState', t => {
// load data into reducer
const stateWData = visStateReducer(mergedState, updateVisData(parsedData));
- const defaultInteraction = getDefaultInteraction();
const expectedInteractions = {
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: true,
config: {
compareMode: false,
@@ -868,7 +867,6 @@ test('VisStateMerger.v1 -> mergeInteractions -> toEmptyState', t => {
// merge interactions
const mergedState = mergeInteractions(oldState.visState, parsedInteraction);
- const defaultInteraction = getDefaultInteraction();
Object.keys(oldVisState).forEach(key => {
if (key === 'interactionToBeMerged') {
@@ -901,9 +899,9 @@ test('VisStateMerger.v1 -> mergeInteractions -> toEmptyState', t => {
t.deepEqual(
mergedState.interactionConfig,
{
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: false,
config: {
fieldsToShow: {},
@@ -912,7 +910,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toEmptyState', t => {
}
},
brush: {
- ...defaultInteraction.brush,
+ ...defaultInteractionConfig.brush,
enabled: false,
config: {
size: 1
@@ -976,7 +974,6 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
// merge interactions
const mergedState = mergeInteractions(oldState.visState, parsedInteraction);
- const defaultInteraction = getDefaultInteraction();
const expectedInteractionToBeMerged = {
tooltip: {
@@ -1011,9 +1008,9 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
t.deepEqual(
mergedState.interactionConfig,
{
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: false,
config: {
compareMode: false,
@@ -1068,7 +1065,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
},
brush: {
- ...defaultInteraction.brush,
+ ...defaultInteractionConfig.brush,
enabled: false,
config: {
size: 1
@@ -1076,7 +1073,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
},
coordinate: {
- ...defaultInteraction.coordinate,
+ ...defaultInteractionConfig.coordinate,
enabled: false
}
},
@@ -1093,9 +1090,9 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
const stateWData = visStateReducer(mergedState, updateVisData(parsedData));
const expectedInteractions = {
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: false,
config: {
compareMode: false,
@@ -1163,7 +1160,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {
}
},
brush: {
- ...defaultInteraction.brush,
+ ...defaultInteractionConfig.brush,
enabled: false,
config: {size: 1}
}
@@ -1187,7 +1184,6 @@ test('VisStateMerger.v1 -> mergeInteractions -> coordinate', t => {
// merge interactions
const mergedState = mergeInteractions(oldState.visState, parsedInteraction);
- const defaultInteraction = getDefaultInteraction();
const expectedInteractionToBeMerged = {};
@@ -1202,22 +1198,22 @@ test('VisStateMerger.v1 -> mergeInteractions -> coordinate', t => {
t.deepEqual(
mergedState.interactionConfig,
{
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: false
},
brush: {
- ...defaultInteraction.brush,
+ ...defaultInteractionConfig.brush,
config: {
size: 1
}
},
coordinate: {
- ...defaultInteraction.coordinate,
+ ...defaultInteractionConfig.coordinate,
enabled: true
}
},
@@ -1234,9 +1230,9 @@ test('VisStateMerger.v1 -> mergeInteractions -> coordinate', t => {
const stateWData = visStateReducer(mergedState, updateVisData(parsedData));
const expectedInteractions = {
- ...defaultInteraction,
+ ...defaultInteractionConfig,
tooltip: {
- ...defaultInteraction.tooltip,
+ ...defaultInteractionConfig.tooltip,
enabled: false,
config: {
compareMode: false,
@@ -1268,12 +1264,12 @@ test('VisStateMerger.v1 -> mergeInteractions -> coordinate', t => {
}
},
brush: {
- ...defaultInteraction.brush,
+ ...defaultInteractionConfig.brush,
enabled: false,
config: {size: 1}
},
coordinate: {
- ...defaultInteraction.coordinate,
+ ...defaultInteractionConfig.coordinate,
enabled: true
}
};
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 3f47f1d4a..be3edf7db 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -32,13 +32,12 @@ import reducer from 'reducers/vis-state';
import {INITIAL_VIS_STATE, DEFAULT_ANIMATION_CONFIG} from 'reducers/vis-state-updaters';
import {serializeLayer} from 'reducers/vis-state-merger';
-import {getDefaultInteraction} from 'utils/interaction-utils';
-import {getDefaultFilter} from 'utils/filter-utils';
-import {createNewDataEntry} from 'utils/dataset-utils';
-import {maybeToDate} from 'utils/data-utils';
-import KeplerTable from 'utils/table-utils/kepler-table';
+import KeplerTable from 'reducers/table-utils';
import {processCsvData, processGeojson} from '@kepler.gl/processors';
+import {defaultInteractionConfig} from 'reducers/vis-state-updaters';
import {Layer, KeplerGlLayers} from '@kepler.gl/layers';
+import {getDefaultFilter, createNewDataEntry} from 'reducers';
+import {createDataContainer, maybeToDate} from 'reducers/table-utils';
import {
ALL_FIELD_TYPES,
EDITOR_MODES,
@@ -49,8 +48,6 @@ import {
const {ArcLayer, PointLayer, GeojsonLayer, LineLayer, TripLayer} = KeplerGlLayers;
-import {createDataContainer} from 'utils/table-utils';
-
// fixtures
import testData, {mergedTimeFilter, testFields, testAllData} from 'test/fixtures/test-csv-data';
import {
@@ -3323,8 +3320,6 @@ test('#visStateReducer -> TOGGLE_LAYER_ANIMATION', t => {
});
test('#visStateReducer -> INTERACTION_CONFIG_CHANGE', t => {
- const defaultInteractionConfig = getDefaultInteraction();
-
const brushConfig = {
...defaultInteractionConfig.brush,
enabled: true
@@ -3382,7 +3377,6 @@ test('#visStateReducer -> MAP_CLICK', t => {
});
test('#visStateReducer -> MOUSE_MOVE', t => {
- const defaultInteractionConfig = getDefaultInteraction();
const initialState = StateWFiles.visState;
const evt = {
point: [10, 20],
diff --git a/test/node/utils/aggregate-utils-test.js b/test/node/utils/aggregate-utils-test.js
index 11ea35668..17585faf2 100644
--- a/test/node/utils/aggregate-utils-test.js
+++ b/test/node/utils/aggregate-utils-test.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import test from 'tape';
-import {getFrequency, getMode, aggregate} from 'utils/aggregate-utils';
+import {getFrequency, getMode, aggregate} from '../../../src/utils';
import {AGGREGATION_TYPES} from '@kepler.gl/constants';
test('AggregateUtils - GetFrequency', t => {
diff --git a/test/node/utils/color-util-test.js b/test/node/utils/color-util-test.js
index 6f78d4787..af4fe62c3 100644
--- a/test/node/utils/color-util-test.js
+++ b/test/node/utils/color-util-test.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import test from 'tape';
-import {createLinearGradient} from 'utils/color-utils';
+import {createLinearGradient} from '../../../src/utils';
test('createLinearGradient', t => {
let colors = [[100, 100, 100]];
diff --git a/test/node/utils/data-container-test.js b/test/node/utils/data-container-test.js
index f0c89bd9d..da7106c1f 100644
--- a/test/node/utils/data-container-test.js
+++ b/test/node/utils/data-container-test.js
@@ -20,7 +20,7 @@
import test from 'tape';
-import {createDataContainer, createIndexedDataContainer} from 'utils/table-utils/';
+import {createDataContainer, createIndexedDataContainer} from 'reducers/table-utils';
const data = [
[10, 20], // 0
diff --git a/test/node/utils/data-processor-test.js b/test/node/utils/data-processor-test.js
index 77df94ddd..15b5c0ea2 100644
--- a/test/node/utils/data-processor-test.js
+++ b/test/node/utils/data-processor-test.js
@@ -43,19 +43,22 @@ import {
} from 'test/fixtures/geojson';
import {
- ACCEPTED_ANALYZER_TYPES,
- analyzerTypeToFieldType,
- formatCsv,
- getFieldsFromData,
- getSampleForTypeAnalyze,
parseCsvRowsByFieldType,
processCsvData,
processGeojson,
- processRowObject,
- validateInputData
+ processRowObject
} from '@kepler.gl/processors';
-import {createDataContainer} from 'utils/table-utils';
+import {
+ ACCEPTED_ANALYZER_TYPES,
+ analyzerTypeToFieldType,
+ getSampleForTypeAnalyze,
+ validateInputData,
+ getFieldsFromData
+} from '@kepler.gl/utils';
+
+import {createDataContainer} from 'reducers/table-utils';
+import {formatCsv} from 'reducers';
import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
import {cmpFields} from '../../helpers/comparison-utils';
diff --git a/test/node/utils/data-scale-utils-test.js b/test/node/utils/data-scale-utils-test.js
index 8293bf438..7b6d56b8b 100644
--- a/test/node/utils/data-scale-utils-test.js
+++ b/test/node/utils/data-scale-utils-test.js
@@ -19,13 +19,9 @@
// THE SOFTWARE.
import test from 'tape';
-import {
- getOrdinalDomain,
- getQuantileDomain,
- getLinearDomain,
- getLogDomain
-} from 'utils/data-scale-utils';
-import {createDataContainer} from 'utils/table-utils';
+import {getOrdinalDomain, getQuantileDomain, getLinearDomain, getLogDomain} from 'reducers';
+
+import {createDataContainer} from 'reducers/table-utils';
function numberSort(a, b) {
return a - b;
diff --git a/test/node/utils/data-utils-test.js b/test/node/utils/data-utils-test.js
index aa13c6d9a..1ee2d4ea2 100644
--- a/test/node/utils/data-utils-test.js
+++ b/test/node/utils/data-utils-test.js
@@ -30,7 +30,7 @@ import {
arrayMove,
getFormatter,
defaultFormatter
-} from 'utils/data-utils';
+} from '@kepler.gl/utils';
import {ALL_FIELD_TYPES} from 'constants';
test('dataUtils -> clamp', t => {
diff --git a/test/node/utils/dataset-utils-test.js b/test/node/utils/dataset-utils-test.js
index ed37f6408..aedca43ca 100644
--- a/test/node/utils/dataset-utils-test.js
+++ b/test/node/utils/dataset-utils-test.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import test from 'tape';
-import {findDefaultColorField, createNewDataEntry} from 'utils/dataset-utils';
+import {findDefaultColorField, createNewDataEntry} from '../../../src/utils';
import {processCsvData} from '@kepler.gl/processors';
diff --git a/test/node/utils/export-utils-test.js b/test/node/utils/export-utils-test.js
index 7f9aa91f5..e4ce67daf 100644
--- a/test/node/utils/export-utils-test.js
+++ b/test/node/utils/export-utils-test.js
@@ -28,9 +28,8 @@ import {
getScaleFromImageSize,
isMSEdge,
calculateExportImageSize
- // dataURItoBlob
-} from 'utils/export-utils';
-import {EXPORT_IMG_RATIOS, RESOLUTIONS} from '../../../src/constants';
+} from '@kepler.gl/utils';
+import {EXPORT_IMG_RATIOS, RESOLUTIONS} from '@kepler.gl/constants';
test('exportUtils -> ExportJson', t => {
const state = keplerGlReducer(undefined, registerEntry({id: 'test'})).test;
diff --git a/test/node/utils/filter-utils-test.js b/test/node/utils/filter-utils-test.js
index aea2195f2..7a1b389b5 100644
--- a/test/node/utils/filter-utils-test.js
+++ b/test/node/utils/filter-utils-test.js
@@ -21,26 +21,26 @@
import test from 'tape';
import moment from 'moment';
+import {isValidFilterValue} from '@kepler.gl/utils';
+
import {
adjustValueToFilterDomain,
getFilterFunction,
getDefaultFilter,
validatePolygonFilter,
generatePolygonFilter,
- isValidFilterValue,
isInPolygon,
diffFilters,
getHistogram,
- getTimestampFieldDomain
-} from 'utils/filter-utils';
+ getTimestampFieldDomain,
+ getDatasetFieldIndexForFilter
+} from '../../../src/reducers';
-import {getDatasetFieldIndexForFilter} from 'utils/gpu-filter-utils';
+import {createDataContainer} from 'reducers/table-utils';
import {FILTER_TYPES} from '@kepler.gl/constants';
import {mockPolygonFeature, mockPolygonData} from '../../fixtures/polygon';
-import {createDataContainer} from 'utils/table-utils';
-
/* eslint-disable max-statements */
test('filterUtils -> adjustValueToFilterDomain', t => {
// TODO: needs id
diff --git a/test/node/utils/gpu-filter-utils-test.js b/test/node/utils/gpu-filter-utils-test.js
index 207df82de..1515b20cf 100644
--- a/test/node/utils/gpu-filter-utils-test.js
+++ b/test/node/utils/gpu-filter-utils-test.js
@@ -24,7 +24,7 @@ import {
assignGpuChannel,
assignGpuChannels,
getDatasetFieldIndexForFilter
-} from 'utils/gpu-filter-utils';
+} from 'reducers';
test('gpuFilterUtils -> resetFilterGpuMode', t => {
const testFilters = [
diff --git a/test/node/utils/interaction-utils-test.js b/test/node/utils/interaction-utils-test.js
index 43213ca19..32fb0e660 100644
--- a/test/node/utils/interaction-utils-test.js
+++ b/test/node/utils/interaction-utils-test.js
@@ -24,7 +24,7 @@ import {
getTooltipDisplayValue,
getTooltipDisplayDeltaValue,
TOOLTIP_MINUS_SIGN
-} from 'utils/interaction-utils';
+} from 'reducers';
import {DEFAULT_TOOLTIP_FIELDS, COMPARE_TYPES} from '@kepler.gl/constants';
import {StateWTooltipFormat, testGeoJsonDataId} from 'test/helpers/mock-state';
diff --git a/test/node/utils/kepler-table-test.js b/test/node/utils/kepler-table-test.js
index c5f2a2ac5..37d0a8782 100644
--- a/test/node/utils/kepler-table-test.js
+++ b/test/node/utils/kepler-table-test.js
@@ -22,9 +22,8 @@ import test from 'tape';
import moment from 'moment';
import testData, {numericRangesCsv, testFields} from 'test/fixtures/test-csv-data';
-import {getFilterFunction} from 'utils/filter-utils';
-import {preciseRound} from 'utils/data-utils';
-import {createNewDataEntry} from 'utils/dataset-utils';
+import {preciseRound} from '@kepler.gl/utils';
+import {getFilterFunction, createNewDataEntry} from 'reducers';
import {processCsvData} from '@kepler.gl/processors';
import {cmpFields} from '../../helpers/comparison-utils';
diff --git a/test/node/utils/layer-utils-test.js b/test/node/utils/layer-utils-test.js
index a8a8297e1..14bd019c8 100644
--- a/test/node/utils/layer-utils-test.js
+++ b/test/node/utils/layer-utils-test.js
@@ -20,12 +20,10 @@
import test from 'tape';
import cloneDeep from 'lodash.clonedeep';
-import {findDefaultLayer, getLayerHoverProp} from 'utils/layer-utils';
-import {createNewDataEntry} from 'utils/dataset-utils';
-import KeplerTable, {findPointFieldPairs} from 'utils/table-utils/kepler-table';
import {processCsvData, processGeojson} from '@kepler.gl/processors';
-import {GEOJSON_FIELDS} from '@kepler.gl/constants';
import {LayerClasses, KeplerGlLayers} from '@kepler.gl/layers';
+import {GEOJSON_FIELDS} from '@kepler.gl/constants';
+import {findDefaultLayer, getLayerHoverProp, createNewDataEntry} from '../../../src/reducers';
import {StateWTripGeojson, StateWFiles} from 'test/helpers/mock-state';
const {PointLayer, ArcLayer, GeojsonLayer, LineLayer} = KeplerGlLayers;
@@ -35,8 +33,11 @@ import {cmpLayers} from 'test/helpers/comparison-utils';
import {getNextColorMakerValue} from 'test/helpers/layer-utils';
import tripGeojson, {timeStampDomain, tripBounds} from 'test/fixtures/trip-geojson';
import {geoJsonWithStyle} from 'test/fixtures/geojson';
-
-import {createDataContainer} from 'utils/table-utils';
+import {
+ KeplerTable,
+ findPointFieldPairs,
+ createDataContainer
+} from '../../../src/reducers/table-utils';
test('layerUtils -> findDefaultLayer.1', t => {
const inputFields = [
diff --git a/test/node/utils/map-info-utils-test.js b/test/node/utils/map-info-utils-test.js
index 755a57788..612f9e049 100644
--- a/test/node/utils/map-info-utils-test.js
+++ b/test/node/utils/map-info-utils-test.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import test from 'tape';
-import {isValidMapInfo} from 'utils/map-info-utils';
+import {isValidMapInfo} from '../../../src/utils';
test('mapInfoUtils -> isValidMapInfo', t => {
t.equal(
diff --git a/test/node/utils/mapbox-gl-style-editor-test.js b/test/node/utils/mapbox-gl-style-editor-test.js
index 73d617137..47bc2a5db 100644
--- a/test/node/utils/mapbox-gl-style-editor-test.js
+++ b/test/node/utils/mapbox-gl-style-editor-test.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import test from 'tape';
-import {mergeLayerGroupVisibility} from 'utils/map-style-utils/mapbox-gl-style-editor';
+import {mergeLayerGroupVisibility} from '../../../src/utils';
test('mapbox.gl Style Editor -> mergeLayerGroupVisibility', t => {
const defaultLG = {
diff --git a/test/node/utils/notifications-utils-test.js b/test/node/utils/notifications-utils-test.js
index 2d38a447e..b767e164e 100644
--- a/test/node/utils/notifications-utils-test.js
+++ b/test/node/utils/notifications-utils-test.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import test from 'tape';
-import {errorNotification, successNotification} from 'utils/notifications-utils';
+import {errorNotification, successNotification} from '../../../src/utils';
test('#notificationsUtils -> errorNotification', t => {
const notification = errorNotification({message: 'test', id: 'test-1'});
diff --git a/test/node/utils/util-test.js b/test/node/utils/util-test.js
index 6e7c2f8d2..082bdc609 100644
--- a/test/node/utils/util-test.js
+++ b/test/node/utils/util-test.js
@@ -27,7 +27,7 @@ import {
camelize,
capitalizeFirstLetter,
arrayInsert
-} from 'utils/utils';
+} from '../../../src/utils';
test('Utils -> set', t => {
const obj1 = {map: {map1: 'world'}};
diff --git a/website/src/components/footer.js b/website/src/components/footer.js
index f5f58be28..07806e73a 100644
--- a/website/src/components/footer.js
+++ b/website/src/components/footer.js
@@ -22,7 +22,7 @@ import React, {PureComponent} from 'react';
import styled from 'styled-components';
import {FacebookIcon, FacebookShareButton, TwitterIcon, TwitterShareButton} from 'react-share';
-import {cdnUrl} from '../utils';
+import {cdnUrl} from '@kepler.gl/utils';
import {LinkButton} from './common/styled-components';
import {media} from '../styles';
import MapboxLogo from './mapbox-logo';