Skip to content

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

[Chore] expose functions and types to fix deep import issues (#2250)

Igor Df6be2491b38a
diff --git a/src/actions/src/index.ts b/src/actions/src/index.ts
index 3552d96c4..ddbd2effe 100644
--- a/src/actions/src/index.ts
+++ b/src/actions/src/index.ts
@@ -48,6 +48,5 @@ export {
wrapTo
} from './action-wrapper';
-export {ACTION_PREFIX} from './action-types';
-export {default as ActionTypes} from './action-types';
+export {default as ActionTypes, ACTION_PREFIX} from './action-types';
export {ActionTypes as ProviderActionTypes} from './provider-actions';
diff --git a/src/reducers/src/layer-utils.ts b/src/reducers/src/layer-utils.ts
index 38a9ee1a2..bb32f9d83 100644
--- a/src/reducers/src/layer-utils.ts
+++ b/src/reducers/src/layer-utils.ts
@@ -97,7 +97,7 @@ export function findDefaultLayer(dataset: KeplerTable, layerClasses: LayerClasse
});
}
-type MinVisState = {
+type MinVisStateForLayerData = {
datasets: VisState['datasets'];
animationConfig: VisState['animationConfig'];
};
@@ -108,7 +108,7 @@ type MinVisState = {
* Also, returns updated layer in case the input layer was in invalid state.
* Adds an error message to the layer in case of an exception.
*/
-export function calculateLayerData<S extends MinVisState>(
+export function calculateLayerData<S extends MinVisStateForLayerData>(
layer: Layer,
state: S,
oldLayerData?: any
diff --git a/src/utils/src/data-scale-utils.ts b/src/utils/src/data-scale-utils.ts
index dec865237..8c0cb0c3e 100644
--- a/src/utils/src/data-scale-utils.ts
+++ b/src/utils/src/data-scale-utils.ts
@@ -18,8 +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 {extent} from 'd3-array';
+
+import {notNullorUndefined, unique} from './data-utils';
import {DataContainerInterface} from './data-container-interface';
type dataValueAccessor = <T>(param: T) => T;
diff --git a/src/utils/src/data-utils.ts b/src/utils/src/data-utils.ts
index 7d3e7db51..e46ec7b2f 100644
--- a/src/utils/src/data-utils.ts
+++ b/src/utils/src/data-utils.ts
@@ -19,6 +19,9 @@
// THE SOFTWARE.
import assert from 'assert';
+import {format as d3Format} from 'd3-format';
+import moment from 'moment-timezone';
+
import {
ALL_FIELD_TYPES,
TOOLTIP_FORMATS,
@@ -26,12 +29,11 @@ import {
TOOLTIP_KEY,
TooltipFormat
} from '@kepler.gl/constants';
-import {format as d3Format} from 'd3-format';
-import {bisectLeft} from 'd3-array';
-import moment from 'moment-timezone';
-
import {Millisecond, Field, ColMetaProps} from '@kepler.gl/types';
+import {snapToMarks} from './plot';
+import {isPlainObject} from './utils';
+
export type FieldFormatter = (value: any) => string;
/**
@@ -115,14 +117,6 @@ export function isNumber(d: any): boolean {
return Number.isFinite(d);
}
-/**
- * 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
@@ -199,23 +193,6 @@ export function getRoundingDecimalFromStep(step: number): number {
return splitZero[1].length;
}
-/**
- * Use in slider, given a number and an array of numbers, return the nears number from the array
- * @param value
- * @param marks
- */
-export function snapToMarks(value: number, marks: number[]): number {
- // always use bin x0
- const i = bisectLeft(marks, value);
- if (i === 0) {
- return marks[i];
- } else if (i === marks.length) {
- return marks[i - 1];
- }
- const idx = marks[i] - value < value - marks[i - 1] ? i : i - 1;
- return marks[idx];
-}
-
/**
* If marks is provided, snap to marks, if not normalize to step
* @param val
@@ -230,6 +207,7 @@ export function normalizeSliderValue(
marks?: number[]
): number {
if (marks && marks.length) {
+ // Use in slider, given a number and an array of numbers, return the nears number from the array
return snapToMarks(val, marks);
}
diff --git a/src/utils/src/dataset-utils.ts b/src/utils/src/dataset-utils.ts
index c805c6d65..596ac32d7 100644
--- a/src/utils/src/dataset-utils.ts
+++ b/src/utils/src/dataset-utils.ts
@@ -39,7 +39,8 @@ import {
} from '@kepler.gl/types';
import {TooltipFormat} from '@kepler.gl/constants';
-import {notNullorUndefined, isPlainObject, getFormatter} from './data-utils';
+import {isPlainObject} from './utils';
+import {notNullorUndefined, getFormatter} from './data-utils';
import {getFormatValue} from './format';
import {range} from 'd3-array';
import {hexToRgb} from './color-utils';
diff --git a/src/utils/src/filter-utils.ts b/src/utils/src/filter-utils.ts
index 747127fbf..6a5a9dd76 100644
--- a/src/utils/src/filter-utils.ts
+++ b/src/utils/src/filter-utils.ts
@@ -1138,9 +1138,9 @@ export function filterDatasetCPU<T extends StateType<K, L>, K extends KeplerTabl
/**
* Validate parsed filters with datasets and add filterProps to field
*/
-type MinVisState = Pick<VisState, 'layers' | 'datasets' | 'isMergingDatasets'>;
+type MinVisStateForFilter = Pick<VisState, 'layers' | 'datasets' | 'isMergingDatasets'>;
export function validateFiltersUpdateDatasets<
- S extends MinVisState,
+ S extends MinVisStateForFilter,
K extends KeplerTableModel<K, L>,
L extends {config: {dataId: string | null; label: string}; id: string}
>(
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index 753f98969..fa62f984b 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -38,36 +38,7 @@ 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,
- roundToFour,
- getBooleanFormatter,
- applyCustomFormat,
- datetimeFormatter,
- formatNumber,
- getColumnFormatter
-} from './data-utils';
+export * from './data-utils';
export {getTimelineFromAnimationConfig, getTimelineFromFilter, SAMPLE_TIMELINE, TIMELINE_MODES} from './time';
export {
@@ -107,11 +78,7 @@ export {
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 * from './observe-dimensions';
export {validateBounds, getCenterAndZoomFromBounds, normalizeEvent, MAPBOX_TILE_SIZE} from './projection-utils';
export {validateToken} from './mapbox-utils';
export {
@@ -125,31 +92,9 @@ export {
mergeLayerGroupVisibility
} from './map-style-utils/mapbox-gl-style-editor';
export {isValidMapInfo} from './map-info-utils';
-export {
- generateHashId,
- isChrome,
- capitalizeFirstLetter,
- camelToTitle,
- camelize,
- toArray,
- insertValue,
- isObject,
- set,
- getError,
- arrayInsert,
- isTest,
- filterObjectByPredicate,
- isFunction,
- hasMobileWidth,
- hasPortableWidth,
- findById
-} from './utils';
-export {
- addNewLayersToSplitMap,
- removeLayerFromSplitMaps,
- getInitialMapLayersForSplitMap,
- computeSplitMapLayers
-} from './split-map-utils';
+export * from './utils';
+export * from './split-map-utils';
+export {snapToMarks} from './plot';
// Mapbox
export {transformRequest, isStyleUsingMapboxTiles} from './map-style-utils/mapbox-utils';
@@ -160,55 +105,7 @@ export {onViewPortChange, getMapLayersFromSplitMaps, getViewportFromMapState} fr
export {createDataContainer, createIndexedDataContainer, getSampleData as getSampleContainerData} from './data-container-utils';
export type {DataContainerInterface} from './data-container-interface';
export type {FilterResult, FilterChanged, dataValueAccessor} from './filter-utils'
-export {
- TimestampStepMap,
- histogramBins,
- enlargedHistogramBins,
- FILTER_UPDATER_PROPS,
- LIMITED_FILTER_EFFECT_PROPS,
- FILTER_COMPONENTS,
- DEFAULT_FILTER_STRUCTURE,
- FILTER_ID_LENGTH,
- LAYER_FILTERS,
- getDefaultFilter,
- shouldApplyFilter,
- validatePolygonFilter,
- validateFilter,
- validateFilterWithData,
- getFilterProps,
- getPolygonFilterFunctor,
- getFilterFunction,
- updateFilterDataId,
- filterDataByFilterTypes,
- getFilterRecord,
- diffFilters,
- adjustValueToFilterDomain,
- getNumericFieldDomain,
- getNumericStepSize,
- getTimestampFieldDomain,
- histogramConstruct,
- getHistogram,
- formatNumberByStep,
- isInRange,
- isInPolygon,
- isValidTimeDomain,
- getTimeWidgetTitleFormatter,
- getTimeWidgetHintFormatter,
- isFilterValidToSave,
- isValidFilterValue,
- isSideFilter,
- getFilterPlot,
- getDefaultFilterPlotType,
- applyFiltersToDatasets,
- applyFilterFieldName,
- mergeFilterDomainStep,
- featureToFilterValue,
- getFilterIdInFeature,
- generatePolygonFilter,
- filterDatasetCPU,
- validateFiltersUpdateDatasets,
- getIntervalBins
-} from "./filter-utils";
+export * from "./filter-utils";
export {
getQuantileDomain,
diff --git a/src/utils/src/plot.ts b/src/utils/src/plot.ts
new file mode 100644
index 000000000..ed2558ea3
--- /dev/null
+++ b/src/utils/src/plot.ts
@@ -0,0 +1,38 @@
+// Copyright (c) 2023 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import {bisectLeft} from 'd3-array';
+
+/**
+ * Use in slider, given a number and an array of numbers, return the nears number from the array
+ * @param value
+ * @param marks
+ */
+export function snapToMarks(value: number, marks: number[]): number {
+ // always use bin x0
+ const i = bisectLeft(marks, value);
+ if (i === 0) {
+ return marks[i];
+ } else if (i === marks.length) {
+ return marks[i - 1];
+ }
+ const idx = marks[i] - value < value - marks[i - 1] ? i : i - 1;
+ return marks[idx];
+}
diff --git a/src/utils/src/utils.ts b/src/utils/src/utils.ts
index a4fd06090..6221dd6b3 100644
--- a/src/utils/src/utils.ts
+++ b/src/utils/src/utils.ts
@@ -120,6 +120,14 @@ export function isObject(value): boolean {
return value !== null && (typeof value === 'object' || typeof value === 'function');
}
+/**
+ * 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);
+}
+
const setPath = <T extends any[] | object>(
[key, ...next]: (string | number)[],
value: any,