Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Chore]: Technical: Translate index and other files (#1745)
Maksim Suslov4a687ed465b6
diff --git a/src/reducers/vis-state-updaters.ts b/src/reducers/vis-state-updaters.tsindex 957bb4bfc..7ed649380 100644--- a/src/reducers/vis-state-updaters.ts+++ b/src/reducers/vis-state-updaters.ts@@ -59,7 +59,8 @@ import {createNewDataEntry} from 'utils/dataset-utils';import {pinTableColumns,sortDatasetByColumn,- copyTableAndUpdate+ copyTableAndUpdate,+ Field} from 'utils/table-utils/kepler-table';import {set, toArray, arrayInsert, generateHashId} from 'utils/utils';@@ -100,7 +101,7 @@ import * as VisStateActions from 'actions/vis-state-actions';import * as MapStateActions from 'actions/map-state-actions';import ActionTypes from 'constants/action-types';import {LoaderObject} from '@loaders.gl/loader-utils';-import {KeplerTable, Field} from 'utils';+import {KeplerTable} from 'utils';export type HistogramBin = {x0: number | undefined;diff --git a/src/utils/index.d.ts b/src/utils/index.d.tsdeleted file mode 100644index 4ccd92b1b..000000000--- a/src/utils/index.d.ts+++ /dev/null@@ -1,14 +0,0 @@-export {updateAllLayerDomainData} from '../reducers/vis-state-updaters';-export {default as KeplerTable, Field, findPointFieldPairs, copyTableAndUpdate} from './table-utils/kepler-table';-export {downloadFile} from './export-utils';-export {containValidTime} from '../layers/trip-layer/trip-utils';-export {validateLayersByDatasets} from '../reducers/vis-state-merger';-export * from './color-utils';-export * from './data-scale-utils';-export * from './data-utils';-export * from './dataset-utils';-export * from './filter-utils';-export * from './gpu-filter-utils';-export * from './interaction-utils';-export * from './layer-utils';-export * from './observe-dimensions';diff --git a/src/utils/index.js b/src/utils/index.tssimilarity index 89%rename from src/utils/index.jsrename to src/utils/index.tsindex 9674dbc07..bcddfec72 100644--- a/src/utils/index.js+++ b/src/utils/index.ts@@ -53,3 +53,12 @@ export {copyTableAndUpdate} from './table-utils/kepler-table';export {createDataContainer, createIndexedDataContainer} from './table-utils/data-container-utils';++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';diff --git a/src/utils/interaction-utils.d.ts b/src/utils/interaction-utils.d.tsdeleted file mode 100644index 081eab4eb..000000000--- a/src/utils/interaction-utils.d.ts+++ /dev/null@@ -1,37 +0,0 @@-import {InteractionConfig, Field, TooltipField, CompareType} from '../reducers/vis-state-updaters';-import {DataRow} from './table-utils/data-row';--/**- * Minus sign used in tooltip formatting.- */-export const TOOLTIP_MINUS_SIGN: string;--export const BRUSH_CONFIG: {- range: [number, number];-};--export function getDefaultInteraction(): InteractionConfig;--export function findFieldsToShow(p: {- fields: Field[];- id: string;- maxDefaultTooltips: number;-}): {- [key: string]: string[];-};--export function getTooltipDisplayDeltaValue(args: {- item: TooltipField;- field: Field;- data: DataRow;- fieldIdx: number;- primaryData: DataRow;- compareType: CompareType;-}): string | null;--export function getTooltipDisplayValue(args: {- item: TooltipField;- field: Field;- data: DataRow;- fieldIdx: number;-}): string;diff --git a/src/utils/interaction-utils.js b/src/utils/interaction-utils.tssimilarity index 83%rename from src/utils/interaction-utils.jsrename to src/utils/interaction-utils.tsindex 298d3b789..fc7d5dad6 100644--- a/src/utils/interaction-utils.js+++ b/src/utils/interaction-utils.ts@@ -33,13 +33,17 @@ import {import {Messages, Crosshairs, CursorClick, Pin} from 'components/common/icons/index';import {TOOLTIP_FORMATS, TOOLTIP_KEY, COMPARE_TYPES} from 'constants/tooltip';-// \u2212 is the minus sign that d3-format uses for decimal number formatting-export const TOOLTIP_MINUS_SIGN = '\u2212';+import {InteractionConfig, TooltipField, CompareType} from '../reducers/vis-state-updaters';+import {DataRow} from './table-utils/data-row';+import {Field} from './table-utils/kepler-table';/**- * @type {typeof import('./interaction-utils').getDefaultInteraction}+ * Minus sign used in tooltip formatting.+ * \u2212 is the minus sign that d3-format uses for decimal number formatting*/-export function getDefaultInteraction() {+export const TOOLTIP_MINUS_SIGN = '\u2212';++export function getDefaultInteraction(): InteractionConfig {return {tooltip: {id: 'tooltip',@@ -79,14 +83,23 @@ export function getDefaultInteraction() {};}-export const BRUSH_CONFIG = {+export const BRUSH_CONFIG: {+ range: [number, number];+} = {range: [0, 50]};-/**- * @type {typeof import('./interaction-utils').findFieldsToShow}- */-export function findFieldsToShow({fields, id, maxDefaultTooltips}) {+export function findFieldsToShow({+ fields,+ id,+ maxDefaultTooltips+}: {+ fields: Field[];+ id: string;+ maxDefaultTooltips: number;+}): {+ [key: string]: string[];+} {// first find default tooltip fields for tripsconst fieldsToShow = DEFAULT_TOOLTIP_FIELDS.reduce((prev, curr) => {if (fields.find(({name}) => curr.name === name)) {@@ -137,8 +150,15 @@ export function getTooltipDisplayDeltaValue({data,fieldIdx,item-}) {- let displayDeltaValue = null;+}: {+ item: TooltipField;+ field: Field;+ data: DataRow;+ fieldIdx: number;+ primaryData: DataRow;+ compareType: CompareType;+}): string | null {+ let displayDeltaValue: string | null = null;if (primaryData &&@@ -170,10 +190,17 @@ export function getTooltipDisplayDeltaValue({return displayDeltaValue;}-/**- * @type {typeof import('./interaction-utils').getTooltipDisplayValue}- */-export function getTooltipDisplayValue({item, field, data, fieldIdx}) {+export function getTooltipDisplayValue({+ item,+ field,+ data,+ fieldIdx+}: {+ item: TooltipField;+ field: Field;+ data: DataRow;+ fieldIdx: number;+}): string {const dataValue = data.valueAt(fieldIdx);if (!notNullorUndefined(dataValue)) {return '';diff --git a/src/utils/layer-utils.d.ts b/src/utils/layer-utils.d.tsdeleted file mode 100644index b6ce59de7..000000000--- a/src/utils/layer-utils.d.ts+++ /dev/null@@ -1,69 +0,0 @@-// Copyright (c) 2020 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 {Layer, LayerClassesType} from 'layers';-import {VisState, Dataset, TooltipField, CompareType, SplitMapLayers} from 'reducers/vis-state-updaters';--export function calculateLayerData(- layer: Layer,- state: VisState,- oldLayerData?: any-): {- layerData: any;- layer: Layer;-};--export type LayersToRender = {- [layerId: string]: boolean;-};--export type LayerHoverProp = {- data: any[];- fields: Field[];- fieldsToShow: TooltipField[];- layer: Layer;- primaryData?: any[];- compareType?: CompareType-};--export function findDefaultLayer(dataset: Dataset, layerClasses: LayerClassesType): Layer[];-export function getLayerHoverProp(arg: {- interactionConfig: VisState['interactionConfig'];- hoverInfo: VisState['hoverInfo'];- layers: VisState['layers'];- layersToRender: LayersToRender;- datasets: VisState['datasets'];-}): LayerHoverProp | null;--export function renderDeckGlLayer(props: any, layerCallbacks: {[key]: any}, idx: number);--export function prepareLayersToRender(- layers: Layer,- layerData: VisState['layerData'],- mapLayers?: SplitMapLayers): {- [key: string]: boolean;-}--export function prepareLayersForDeck(- layers: Layer,- layerData: VisState['layerData'],-): {- [key: string]: boolean;-}\ No newline at end of filediff --git a/src/utils/layer-utils.js b/src/utils/layer-utils.tssimilarity index 69%rename from src/utils/layer-utils.jsrename to src/utils/layer-utils.tsindex e0164c79f..7170ad623 100644--- a/src/utils/layer-utils.js+++ b/src/utils/layer-utils.ts@@ -20,32 +20,52 @@import {OVERLAY_TYPE} from 'layers/base-layer';import {GEOCODER_LAYER_ID} from 'constants/default-settings';+import {Layer, LayerClassesType} from 'layers';+import {VisState, TooltipField, CompareType, SplitMapLayers} from 'reducers/vis-state-updaters';+import KeplerTable, {Field} from './table-utils/kepler-table';++export type LayersToRender = {+ [layerId: string]: boolean;+};++export type LayerHoverProp = {+ data: any[];+ fields: Field[];+ fieldsToShow: TooltipField[];+ layer: Layer;+ primaryData?: any[];+ compareType?: CompareType;+};/*** Find default layers from fields- * @type {typeof import('./layer-utils').findDefaultLayer}*/-export function findDefaultLayer(dataset, layerClasses) {+export function findDefaultLayer(dataset: KeplerTable, layerClasses: LayerClassesType): Layer[] {if (!dataset) {return [];}- const layerProps = Object.keys(layerClasses).reduce((previous, lc) => {- const result =- typeof layerClasses[lc].findDefaultLayerProps === 'function'- ? layerClasses[lc].findDefaultLayerProps(dataset, previous)- : {props: []};-- const props = Array.isArray(result) ? result : result.props || [];- const foundLayers = result.foundLayers || previous;-- return foundLayers.concat(- props.map(p => ({- ...p,- type: lc,- dataId: dataset.id- }))- );- }, []);+ const layerProps = (Object.keys(layerClasses) as Array<keyof LayerClassesType>).reduce(+ (previous, lc) => {+ const result =+ // @ts-expect-error+ typeof layerClasses[lc].findDefaultLayerProps === 'function'+ ? // @ts-expect-error+ layerClasses[lc].findDefaultLayerProps(dataset, previous)+ : {props: []};++ const props = Array.isArray(result) ? result : result.props || [];+ const foundLayers = result.foundLayers || previous;++ return foundLayers.concat(+ props.map(p => ({+ ...p,+ type: lc,+ dataId: dataset.id+ }))+ );+ },+ [] as LayerClassesType[keyof LayerClassesType][]+ );// go through all layerProps to create layerreturn layerProps.map(props => {@@ -59,9 +79,15 @@ export function findDefaultLayer(dataset, layerClasses) {/*** calculate layer data based on layer type, col Config,* return updated layer if colorDomain, dataMap has changed- * @type {typeof import('./layer-utils').calculateLayerData}*/-export function calculateLayerData(layer, state, oldLayerData) {+export function calculateLayerData(+ layer: Layer,+ state: VisState,+ oldLayerData?: any+): {+ layerData: any;+ layer: Layer;+} {const {type} = layer;if (!type || !layer.hasAllColumns() || !layer.config.dataId) {@@ -82,7 +108,13 @@ export function getLayerHoverProp({layers,layersToRender,datasets-}) {+}: {+ interactionConfig: VisState['interactionConfig'];+ hoverInfo: VisState['hoverInfo'];+ layers: VisState['layers'];+ layersToRender: LayersToRender;+ datasets: VisState['datasets'];+}): LayerHoverProp | null {if (interactionConfig.tooltip.enabled && hoverInfo && hoverInfo.picked) {// if anything hoveredconst {object, layer: overlay} = hoverInfo;@@ -114,7 +146,7 @@ export function getLayerHoverProp({return null;}-export function renderDeckGlLayer(props, layerCallbacks, idx) {+export function renderDeckGlLayer(props: any, layerCallbacks: {[key: string]: any}, idx: number) {const {datasets,layers,@@ -160,11 +192,17 @@ export function isLayerVisible(layer, mapLayers) {// Prepare a dict of layers rendered by the deck.gl// Note, isVisible: false layer is passed to deck.gl here// return {[id]: true \ false}-export function prepareLayersForDeck(layers, layerData) {+export function prepareLayersForDeck(+ layers: Layer[],+ layerData: VisState['layerData']+): {+ [key: string]: boolean;+} {return layers.reduce((accu, layer, idx) => ({...accu,[layer.id]:+ // @ts-expect-errorisLayerRenderable(layer, layerData[idx]) && layer.overlayType === OVERLAY_TYPE.deckgl}),{}@@ -174,7 +212,13 @@ export function prepareLayersForDeck(layers, layerData) {// Prepare a dict of rendered layers rendered in the map// This includes only the visibile layers for single map view and split map view// return {[id]: true \ false}-export function prepareLayersToRender(layers, layerData, mapLayers) {+export function prepareLayersToRender(+ layers: Layer[],+ layerData: VisState['layerData'],+ mapLayers?: SplitMapLayers+): {+ [key: string]: boolean;+} {return layers.reduce((accu, layer, idx) => ({...accu,diff --git a/src/utils/observe-dimensions.d.ts b/src/utils/observe-dimensions.d.tsdeleted file mode 100644index 70476c66b..000000000--- a/src/utils/observe-dimensions.d.ts+++ /dev/null@@ -1,18 +0,0 @@-import {RefObject} from 'react';--export interface Dimensions {- readonly height: number;- readonly width: number;-}--export default function useDimensions<T extends Element>(- throttleDelay?: number-): [RefObject<T>, Dimensions | undefined];--export function observeDimensions(- target: Element,- handleResize: (size: Dimensions) => void,- throttleDelay?: number-);--export function unobserveDimensions(target: Element);diff --git a/src/utils/observe-dimensions.js b/src/utils/observe-dimensions.tssimilarity index 87%rename from src/utils/observe-dimensions.jsrename to src/utils/observe-dimensions.tsindex 9f54fa81f..f2adadd6f 100644--- a/src/utils/observe-dimensions.js+++ b/src/utils/observe-dimensions.ts@@ -21,6 +21,12 @@import throttle from 'lodash.throttle';import {useEffect, useRef, useState} from 'react';import ResizeObserver from 'resize-observer-polyfill';+import {RefObject} from 'react';++export interface Dimensions {+ readonly height: number;+ readonly width: number;+}const DEFAULT_THROTTLE_DELAY = 100;@@ -51,13 +57,17 @@ function getObserverRegistry() {return _observerRegistry;}-export function observeDimensions(target, handleResize, throttleDelay = DEFAULT_THROTTLE_DELAY) {+export function observeDimensions(+ target: Element,+ handleResize: (size: Dimensions) => void,+ throttleDelay = DEFAULT_THROTTLE_DELAY+) {const registry = getObserverRegistry();const handler = throttleDelay > 0 ? throttle(handleResize, throttleDelay) : handleResize;registry.subscribe(target, entry => handler(getSize(target, entry)));}-export function unobserveDimensions(target) {+export function unobserveDimensions(target: Element) {const registry = getObserverRegistry();registry.unsubscribe(target);}@@ -79,10 +89,12 @@ function getSize(node, entry) {* const [ref, dimensions] = useDimensions<HTMLDivElement>();** @param throttleDelay- * @returns {[React.RefObject<Element>, {width: number, height: number} | null]}+ * @returns*/-export default function useDimensions(throttleDelay = DEFAULT_THROTTLE_DELAY) {- const ref = useRef(null);+export default function useDimensions<T extends Element>(+ throttleDelay = DEFAULT_THROTTLE_DELAY+): [RefObject<T>, Dimensions | null] {+ const ref = useRef<T>(null);const [size, setSize] = useState(null);useEffect(() => {diff --git a/src/utils/table-utils/data-row.jdoc.ts b/src/utils/table-utils/data-row.jdoc.tsdeleted file mode 100644index 1a715468d..000000000--- a/src/utils/table-utils/data-row.jdoc.ts+++ /dev/null@@ -1,67 +0,0 @@-// TODO: Move JDoc to correct place-// @ts-nocheck-import {DataContainerInterface} from './data-container-interface';--/**- * Setting for shared row optimization.- * - False/undefined indicates that unique row objects should be used (default).- * - True indicates that a single temporary row object should be created and used without extra allocations.- * - A DataRow object indicates that the row should be used as a temporary shared row.- * When used, the content of the shared row isn't preserved between calls.- */-export type SharedRowOptions = DataRow | boolean | undefined;--/**- * Return type for createSharedRow:- * - DataRow object that should be used as shared row.- * - Falsy values indicate that shared row object shouldn't be used.- */-export type SharedRowOptionsResult = DataRow | false | undefined;--export class DataRow {- /**- * Creates new DataRow.- * @param dataContainer Data container where data is stored. Can be initialized with null for shared rows.- * @param rowIndex Index of a row in the data container.- */- constructor(dataContainer: DataContainerInterface | null, rowIndex: number);-- /**- * Conditionally creates a DataRow object.- * @param sharedRowDesc Accepts forllowing options:- * - true indicates that new DataRow should be created.- * - falsy value or a DataRow object is passed through without any change.- * @returns A new DataRow object or unchanged input argument.- */- static createSharedRow(sharedRowDesc: SharedRowOptions): SharedRowOptionsResult;-- /**- * Returns the value stored at the specified index in the row.- * @param index Index of the requested field in the row.- * @returns Value at the index.- */- valueAt(index: number): any;-- /**- * Returns the row represented as an array.- * @returns The row represented as an array.- */- values(): any[];-- /**- * Setup a row object. The method is used by shared rows to prevent excessive allocations.- * @param dataContainer Data container.- * @param rowIndex Index of a row in the data container.- */- setSource(dataContainer: DataContainerInterface, rowIndex: number): void;-- /**- * Creates a new array populated with the results of calling the provided function- * on every element of the row.- * @param func The callback is called with the following arguments:- * - elem: The current element being processed in the row.- * - index: The index of the current element being processed in the row.- * @returns A new array with each element being the result of the func callback.- */- map(func: (elem: any, index: number) => any): any[];-}diff --git a/src/utils/table-utils/data-row.ts b/src/utils/table-utils/data-row.tsindex 24d42eb39..26e7e9d2c 100644--- a/src/utils/table-utils/data-row.ts+++ b/src/utils/table-utils/data-row.ts@@ -20,7 +20,19 @@import {DataContainerInterface} from './data-container-interface';+/**+ * Setting for shared row optimization.+ * - False/undefined indicates that unique row objects should be used (default).+ * - True indicates that a single temporary row object should be created and used without extra allocations.+ * - A DataRow object indicates that the row should be used as a temporary shared row.+ * When used, the content of the shared row isn't preserved between calls.+ */export type SharedRowOptions = DataRow | boolean | undefined;+/**+ * Return type for createSharedRow:+ * - DataRow object that should be used as shared row.+ * - Falsy values indicate that shared row object shouldn't be used.+ */export type SharedRowOptionsResult = DataRow | false | undefined;export class DataRow {@@ -28,11 +40,23 @@ export class DataRow {_rowIndex: number;+ /**+ * Creates new DataRow.+ * @param dataContainer Data container where data is stored. Can be initialized with null for shared rows.+ * @param rowIndex Index of a row in the data container.+ */constructor(dataContainer: DataContainerInterface | null, rowIndex: number) {this._dataContainer = dataContainer;this._rowIndex = rowIndex;}+ /**+ * Conditionally creates a DataRow object.+ * @param sharedRowDesc Accepts forllowing options:+ * - true indicates that new DataRow should be created.+ * - falsy value or a DataRow object is passed through without any change.+ * @returns A new DataRow object or unchanged input argument.+ */static createSharedRow(sharedRowDesc: SharedRowOptions): SharedRowOptionsResult {if (sharedRowDesc === true) {return new DataRow(null, 0);@@ -40,19 +64,41 @@ export class DataRow {return sharedRowDesc;}+ /**+ * Returns the value stored at the specified index in the row.+ * @param columnIndex Index of the requested field in the row.+ * @returns Value at the index.+ */valueAt(columnIndex: number): any {return this._dataContainer?.valueAt(this._rowIndex, columnIndex);}+ /**+ * Returns the row represented as an array.+ * @returns The row represented as an array.+ */values(): any[] {return this._dataContainer ? this._dataContainer.rowAsArray(this._rowIndex) : [];}+ /**+ * Setup a row object. The method is used by shared rows to prevent excessive allocations.+ * @param dataContainer Data container.+ * @param rowIndex Index of a row in the data container.+ */setSource(dataContainer: DataContainerInterface, rowIndex: number): void {this._dataContainer = dataContainer;this._rowIndex = rowIndex;}+ /**+ * Creates a new array populated with the results of calling the provided function+ * on every element of the row.+ * @param handler The callback is called with the following arguments:+ * - elem: The current element being processed in the row.+ * - index: The index of the current element being processed in the row.+ * @returns A new array with each element being the result of the func callback.+ */map(handler: (elem: any, index: number) => any): any[] {const numColumns = this._dataContainer?.numColumns() || 0;const out: any[] = [];