Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Feat] Improve fieldpair detection logic, add altitude (#1968)
Igor Dykhtad77ffcb45589
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.jsindex 4ca889ca7..b40d84957 100644--- a/examples/demo-app/src/app.js+++ b/examples/demo-app/src/app.js@@ -59,6 +59,7 @@ import sampleH3Data, {config as h3MapConfig} from './data/sample-hex-id-csv';import sampleS2Data, {config as s2MapConfig, dataId as s2DataId} from './data/sample-s2-data';import sampleAnimateTrip from './data/sample-animate-trip-data';import sampleIconCsv, {config as savedMapConfig} from './data/sample-icon-csv';+import sampleGpsData from './data/sample-gps-data';import {processCsvData, processGeojson} from 'kepler.gl/processors';/* eslint-enable no-unused-vars */@@ -178,13 +179,14 @@ class App extends Component {}_loadSampleData() {- this._loadPointData();+ // this._loadPointData();// this._loadGeojsonData();this._loadTripGeoJson();// this._loadIconData();// this._loadH3HexagonData();// this._loadS2Data();// this._loadScenegraphLayer();+ this._loadGpsData();}_loadPointData() {@@ -334,6 +336,24 @@ class App extends Component {);}+ _loadGpsData() {+ this.props.dispatch(+ addDataToMap({+ datasets: [+ {+ info: {+ label: 'Gps Data',+ id: 'gps-data'+ },+ data: processCsvData(sampleGpsData)+ }+ ],+ options: {+ keepExistingConfig: true+ }+ })+ );+ }_toggleCloudModal = () => {// TODO: this lives only in the demo hence we use the state for now// REFCOTOR using reduxdiff --git a/examples/demo-app/src/data/sample-gps-data.js b/examples/demo-app/src/data/sample-gps-data.jsnew file mode 100644index 000000000..ebb7d345e--- /dev/null+++ b/examples/demo-app/src/data/sample-gps-data.js@@ -0,0 +1,100 @@+// 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 gps = `timestamp,location-lng,location-lat,ground-speed,heading,id,location-alt+2014-08-01 00:00:23.000,90.2266981,27.6162803,0.22,0.0,Thang Kaar Thuub (3552),3217.0+2014-08-01 00:10:07.000,90.2266713,27.6162513,0.27,140.9,Thang Kaar Thuub (3552),3212.3+2014-08-01 00:20:07.000,90.2267115,27.6162102,0.27,110.1,Thang Kaar Thuub (3552),3209.1+2014-08-01 00:30:07.000,90.2267409,27.6162514,0.32,0.0,Thang Kaar Thuub (3552),3206.2+2014-08-01 00:40:07.000,90.2265545,27.6163481,0.46,0.0,Thang Kaar Thuub (3552),3231.3+2014-08-01 00:50:07.000,90.2269491,27.6161884,0.51,0.0,Thang Kaar Thuub (3552),3178.8+2014-08-01 01:00:07.000,90.2265336,27.6163122,0.3,99.61,Thang Kaar Thuub (3552),3257.2+2014-08-01 01:10:07.000,90.2267568,27.6162647,0.33,0.0,Thang Kaar Thuub (3552),3192.5+2014-08-01 01:20:07.000,90.2267296,27.6163003,0.43,0.0,Thang Kaar Thuub (3552),3199.2+2014-08-01 01:30:16.000,90.2267121,27.6163019,0.09,172.36,Thang Kaar Thuub (3552),3222.9+2014-08-01 01:40:21.000,90.2267198,27.6163409,0.07,0.0,Thang Kaar Thuub (3552),3216.7+2014-08-01 01:50:06.000,90.2266872,27.6162974,0.26,105.51,Thang Kaar Thuub (3552),3215.5+2014-08-01 02:00:06.000,90.2266652,27.6162898,0.5,157.94,Thang Kaar Thuub (3552),3219.6+2014-08-01 02:10:07.000,90.2266452,27.6163351,0.18,160.56,Thang Kaar Thuub (3552),3220.4+2014-08-01 02:20:07.000,90.2266829,27.6162774,0.22,169.74,Thang Kaar Thuub (3552),3216.9+2014-08-01 02:30:07.000,90.2266533,27.6162986,0.25,145.49,Thang Kaar Thuub (3552),3224.0+2014-08-01 02:40:07.000,90.2267379,27.6162983,0.21,195.95,Thang Kaar Thuub (3552),3225.6+2014-08-01 02:50:07.000,90.226692,27.616304,0.19,0.0,Thang Kaar Thuub (3552),3211.8+2014-08-01 03:00:07.000,90.2266683,27.6163021,0.28,0.0,Thang Kaar Thuub (3552),3227.1+2014-08-01 03:10:06.000,90.2266718,27.6162954,0.24,138.94,Thang Kaar Thuub (3552),3225.1+2014-08-01 03:20:07.000,90.2267475,27.6162578,0.06,0.0,Thang Kaar Thuub (3552),3218.9+2014-08-01 03:30:07.000,90.2266495,27.6163363,0.05,0.0,Thang Kaar Thuub (3552),3209.9+2014-08-01 03:40:07.000,90.2266573,27.6162552,0.33,278.53,Thang Kaar Thuub (3552),3216.8+2014-08-01 03:50:06.000,90.200501,27.5963135,11.97,248.38,Thang Kaar Thuub (3552),3150.4+2014-08-01 04:00:23.000,90.2029316,27.592159,11.09,102.89,Thang Kaar Thuub (3552),3173.1+2014-08-01 04:10:06.000,90.1979269,27.5900334,14.89,226.1,Thang Kaar Thuub (3552),3078.8+2014-08-01 04:20:06.000,90.1599981,27.5889937,9.36,214.3,Thang Kaar Thuub (3552),3219.6+2014-08-01 04:30:06.000,90.1304977,27.5797384,17.17,256.9,Thang Kaar Thuub (3552),3066.5+2014-08-01 04:40:06.000,90.0803941,27.5599255,10.13,278.53,Thang Kaar Thuub (3552),3100.0+2014-08-01 04:50:06.000,90.0107878,27.5658968,11.39,235.93,Thang Kaar Thuub (3552),2666.8+2014-08-01 05:00:06.000,89.9490298,27.5345735,9.28,214.3,Thang Kaar Thuub (3552),2309.5+2014-08-01 06:42:41.000,82.1138274,27.4378974,15.95,64.23,Thang Kaar Ngang Ka (4002),966.3+2014-08-01 06:42:42.000,82.1139649,27.4379582,14.9,62.91,Thang Kaar Ngang Ka (4002),969.9+2014-08-01 06:42:43.000,82.1140881,27.4380211,13.67,58.33,Thang Kaar Ngang Ka (4002),972.8+2014-08-01 06:42:44.000,82.1141907,27.4380927,12.54,48.5,Thang Kaar Ngang Ka (4002),974.6+2014-08-01 06:42:45.000,82.114263,27.4381765,11.44,32.11,Thang Kaar Ngang Ka (4002),975.2+2014-08-01 06:42:46.000,82.1143013,27.438272,11.35,13.76,Thang Kaar Ngang Ka (4002),975.8+2014-08-01 06:42:47.000,82.11431,27.4383692,10.8,0.66,Thang Kaar Ngang Ka (4002),977.7+2014-08-01 06:42:48.000,82.1142962,27.4384518,8.76,346.69,Thang Kaar Ngang Ka (4002),980.6+2014-08-01 06:42:49.000,82.1142637,27.4385091,6.63,325.71,Thang Kaar Ngang Ka (4002),983.6+2014-08-01 06:42:50.000,82.1142176,27.4385368,5.34,292.95,Thang Kaar Ngang Ka (4002),985.9+2014-08-01 06:42:51.000,82.1141648,27.4385357,5.47,258.87,Thang Kaar Ngang Ka (4002),987.5+2014-08-01 06:42:52.000,82.1141123,27.4385072,6.58,232.0,Thang Kaar Ngang Ka (4002),988.8+2014-08-01 06:42:53.000,82.1140662,27.4384524,8.17,211.68,Thang Kaar Ngang Ka (4002),990.3+2014-08-01 06:42:54.000,82.1140376,27.4383744,9.62,192.68,Thang Kaar Ngang Ka (4002),992.1+2014-08-01 06:42:55.000,82.114036,27.4382797,10.99,176.29,Thang Kaar Ngang Ka (4002),994.3+2014-08-01 06:42:56.000,82.1140666,27.438175,12.55,161.22,Thang Kaar Ngang Ka (4002),996.5+2014-08-01 06:42:57.000,82.1141258,27.4380679,13.64,150.73,Thang Kaar Ngang Ka (4002),998.2+2014-08-01 06:42:58.000,82.1142042,27.4379617,14.34,144.83,Thang Kaar Ngang Ka (4002),999.3+2014-08-01 06:42:59.000,82.1142915,27.4378567,14.58,142.21,Thang Kaar Ngang Ka (4002),1000.9+2014-08-01 06:43:00.000,82.1143788,27.4377539,14.18,142.21,Thang Kaar Ngang Ka (4002),1002.5+2014-08-01 06:43:01.000,82.1144592,27.4376522,13.65,145.49,Thang Kaar Ngang Ka (4002),1004.0+2014-08-01 06:43:02.000,82.1145274,27.4375495,13.09,150.73,Thang Kaar Ngang Ka (4002),1004.7+2014-08-01 06:43:03.000,82.1145875,27.4374392,13.84,154.66,Thang Kaar Ngang Ka (4002),1005.1+2014-08-01 06:43:04.000,82.1146421,27.4373208,14.33,157.94,Thang Kaar Ngang Ka (4002),1006.1+2014-08-01 06:43:05.000,82.1146882,27.4372001,14.03,161.87,Thang Kaar Ngang Ka (4002),1007.5+2014-08-01 06:43:06.000,82.1147188,27.4370782,13.75,169.08,Thang Kaar Ngang Ka (4002),1009.8+2014-08-01 06:43:07.000,82.1147296,27.4369611,12.75,177.6,Thang Kaar Ngang Ka (4002),1012.1+2014-08-01 06:43:08.000,82.1147213,27.4368536,11.67,186.12,Thang Kaar Ngang Ka (4002),1014.2+2014-08-01 06:43:09.000,82.1146955,27.4367568,10.77,195.95,Thang Kaar Ngang Ka (4002),1017.1+2014-08-01 06:43:10.000,82.1146547,27.436676,9.5,207.75,Thang Kaar Ngang Ka (4002),1020.1+2014-08-01 06:43:11.000,82.1145999,27.4366146,8.5,222.82,Thang Kaar Ngang Ka (4002),1023.3+2014-08-01 06:43:12.000,82.1145381,27.4365653,8.12,230.03,Thang Kaar Ngang Ka (4002),1026.2+2014-08-01 06:43:13.000,82.1144759,27.4365206,7.87,230.69,Thang Kaar Ngang Ka (4002),1028.2+2014-08-01 06:43:14.000,82.1144131,27.4364746,8.14,230.03,Thang Kaar Ngang Ka (4002),1029.8+2014-08-01 06:43:15.000,82.1143506,27.43643,7.86,231.34,Thang Kaar Ngang Ka (4002),1030.8+2014-08-01 06:43:16.000,82.1142864,27.4363918,7.6,237.9,Thang Kaar Ngang Ka (4002),1031.0+2014-08-01 06:43:17.000,82.1142171,27.4363629,7.58,247.73,Thang Kaar Ngang Ka (4002),1031.9+2014-08-01 06:43:18.000,82.114145,27.4363437,7.43,255.59,Thang Kaar Ngang Ka (4002),1033.1+2014-08-01 06:43:19.000,82.1140733,27.4363307,7.17,259.52,Thang Kaar Ngang Ka (4002),1034.5+2014-08-01 06:43:20.000,82.114004,27.4363217,6.85,262.14,Thang Kaar Ngang Ka (4002),1035.6+2014-08-01 06:43:21.000,82.1139337,27.4363205,7.05,271.32,Thang Kaar Ngang Ka (4002),1036.6+2014-08-01 06:43:22.000,82.1138619,27.4363266,7.2,276.56,Thang Kaar Ngang Ka (4002),1037.3+2014-08-01 06:43:23.000,82.1137874,27.4363359,7.56,277.87,Thang Kaar Ngang Ka (4002),1038.6+2014-08-01 06:43:24.000,82.1137119,27.4363441,7.51,275.91,Thang Kaar Ngang Ka (4002),1040.2+2014-08-01 06:43:25.000,82.1136379,27.4363491,7.29,273.29,Thang Kaar Ngang Ka (4002),1041.4+2014-08-01 06:43:26.000,82.1135644,27.4363482,7.29,267.39,Thang Kaar Ngang Ka (4002),1043.2`;++export default gps;diff --git a/src/components/src/common/checkbox.tsx b/src/components/src/common/checkbox.tsxindex 0750a0997..e6a2add82 100644--- a/src/components/src/common/checkbox.tsx+++ b/src/components/src/common/checkbox.tsx@@ -37,8 +37,8 @@ const StyledCheckboxInput = styled.label`${props => props.theme.inputCheckbox};`;-const StyledRadiuInput = styled.label`- ${props => props.theme.inputRadio};+const StyledRadiuInput = styled.label<StyledSwitchInputProps>`+ ${props => (props.secondary ? props.theme.secondaryRadio : props.theme.inputRadio)};`;const HiddenInput = styled.input`@@ -100,7 +100,7 @@ export default class Checkbox extends Component<CheckboxProps> {render() {const inputProps = {- ...pick(this.props, ['checked', 'disabled', 'id', 'onChange', 'value']),+ ...pick(this.props, ['checked', 'disabled', 'id', 'onChange', 'value', 'secondary']),type: 'checkbox',onFocus: this.handleFocus,onBlur: this.handleBlurdiff --git a/src/components/src/index.ts b/src/components/src/index.tsindex 88a130660..83b31cf27 100644--- a/src/components/src/index.ts+++ b/src/components/src/index.ts@@ -26,6 +26,7 @@ import RangeSliderFactory from './common/range-slider';import VisConfigSliderFactory from './side-panel/layer-panel/vis-config-slider';import VisConfigSwitchFactory from './side-panel/layer-panel/vis-config-switch';import LayerConfigGroupFactory from './side-panel/layer-panel/layer-config-group';+import LayerColumnConfigFactory from './side-panel/layer-panel/layer-column-config';import {ChannelByValueSelectorFactory} from './side-panel/layer-panel/layer-configurator';import FieldSelectorFactory, {FieldListItemFactoryFactory} from './common/field-selector';import FieldTokenFactory from './common/field-token';@@ -301,6 +302,7 @@ export const RangeSlider = appInjector.get(RangeSliderFactory);export const VisConfigSlider = appInjector.get(VisConfigSliderFactory);export const VisConfigSwitch = appInjector.get(VisConfigSwitchFactory);export const LayerConfigGroup = appInjector.get(LayerConfigGroupFactory);+export const LayerColumnConfig = appInjector.get(LayerColumnConfigFactory);export const ChannelByValueSelector = appInjector.get(ChannelByValueSelectorFactory);export const FieldSelector = appInjector.get(FieldSelectorFactory);export const FieldToken = appInjector.get(FieldTokenFactory);@@ -315,6 +317,7 @@ export {VisConfigSliderFactory,VisConfigSwitchFactory,LayerConfigGroupFactory,+ LayerColumnConfigFactory,ChannelByValueSelectorFactory,FieldListItemFactoryFactory,InfoHelperFactorydiff --git a/src/components/src/side-panel/layer-panel/layer-config-group.tsx b/src/components/src/side-panel/layer-panel/layer-config-group.tsxindex 29284905b..d89baa40d 100644--- a/src/components/src/side-panel/layer-panel/layer-config-group.tsx+++ b/src/components/src/side-panel/layer-panel/layer-config-group.tsx@@ -18,8 +18,7 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React, {Component} from 'react';-import {polyfill} from 'react-lifecycles-compat';+import React, {useCallback, useState} from 'react';import styled from 'styled-components';import classnames from 'classnames';import {FormattedMessage} from 'react-intl';@@ -90,7 +89,9 @@ export const StyledLayerConfigGroup = styled.div`}`;-const StyledConfigGroupHeader = styled.div`+const StyledConfigGroupHeader = styled.div.attrs({+ className: 'layer-config-group__header'+})`display: flex;align-items: center;justify-content: space-between;@@ -157,75 +158,56 @@ LayerConfigGroupFactory.deps = [LayerConfigGroupLabelFactory];function LayerConfigGroupFactory(LayerConfigGroupLabel: ReturnType<typeof LayerConfigGroupLabelFactory>-): React.ComponentType<LayerConfigGroupProps> {- class LayerConfigGroup extends Component<LayerConfigGroupProps> {- static defaultProps = {- collapsible: false,- expanded: false,- onChange: () => {},- description: '',- disabled: false- };-- static getDerivedStateFromProps(props, state) {- // invoked after a component is instantiated as well as before it is re-rendered- if (props.expanded && state.collapsed) {- return {collapsed: false};- }-- return null;- }-- state = {- collapsed: true- };-- render() {- const {- label,- children,- property,- layer,- onChange,- collapsible,- description,- disabled- } = this.props;-- const {collapsed} = this.state;-- return (- <StyledLayerConfigGroup className={classnames('layer-config-group', {collapsed, disabled})}>- <StyledConfigGroupHeader- className="layer-config-group__header"- onClick={() => this.setState({collapsed: !this.state.collapsed})}- >- <LayerConfigGroupLabel label={label} description={description} />- <StyledLayerConfigGroupAction className="layer-config-group__action">- {property ? (- <Switch- checked={layer?.config.visConfig[property]}- id={`${layer?.id}-${property}`}- onChange={() => onChange?.({[property]: !layer?.config.visConfig[property]})}- />- ) : null}- {collapsible ? <VertThreeDots height="18px" /> : null}- </StyledLayerConfigGroupAction>- </StyledConfigGroupHeader>- <ConfigGroupContent- className={classnames('layer-config-group__content', {- disabled: property && !layer?.config.visConfig[property]- })}- >- {children}- </ConfigGroupContent>- </StyledLayerConfigGroup>- );- }- }-- polyfill(LayerConfigGroup);-+) {+ const LayerConfigGroup: React.FC<LayerConfigGroupProps> = ({+ label,+ children,+ property,+ layer,+ onChange,+ collapsible,+ description,+ disabled,+ expanded+ }) => {+ const [collapsed, toggleCollapsed] = useState(!expanded);+ const onToggleCollapsed = useCallback(() => {+ toggleCollapsed(!collapsed);+ }, [collapsed, toggleCollapsed]);++ return (+ <StyledLayerConfigGroup className={classnames('layer-config-group', {collapsed, disabled})}>+ <StyledConfigGroupHeader onClick={onToggleCollapsed}>+ <LayerConfigGroupLabel label={label} description={description} />+ <StyledLayerConfigGroupAction className="layer-config-group__action">+ {property ? (+ <Switch+ checked={layer?.config.visConfig[property]}+ id={`${layer?.id}-${property}`}+ onChange={() => onChange?.({[property]: !layer?.config.visConfig[property]})}+ />+ ) : null}+ {collapsible ? <VertThreeDots height="18px" /> : null}+ </StyledLayerConfigGroupAction>+ </StyledConfigGroupHeader>+ <ConfigGroupContent+ className={classnames('layer-config-group__content', {+ disabled: property && !layer?.config.visConfig[property]+ })}+ >+ {children}+ </ConfigGroupContent>+ </StyledLayerConfigGroup>+ );+ };++ LayerConfigGroup.defaultProps = {+ collapsible: false,+ expanded: false,+ onChange: () => {},+ description: '',+ disabled: false+ };return LayerConfigGroup;}diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsxindex d925a5c70..94f447759 100644--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx@@ -1031,24 +1031,26 @@ export default function LayerConfiguratorFactory(// @ts-ignoreonSelect={updateLayerType}/>- <SourceDataSelector- datasets={datasets}- id={layer.id}- dataId={config.dataId}- // @ts-ignore- onSelect={(value: string) => updateLayerConfig({dataId: value})}- />- <LayerColumnConfig- columnPairs={layer.columnPairs}- columns={layer.config.columns}- assignColumnPairs={layer.assignColumnPairs.bind(layer)}- assignColumn={layer.assignColumn.bind(layer)}- // @ts-ignore- columnLabels={layer.columnLabels}- fields={fields}- fieldPairs={fieldPairs}- updateLayerConfig={updateLayerConfig}- />+ <ConfigGroupCollapsibleContent>+ <SourceDataSelector+ datasets={datasets}+ id={layer.id}+ dataId={config.dataId}+ // @ts-ignore+ onSelect={(value: string) => updateLayerConfig({dataId: value})}+ />+ <LayerColumnConfig+ columnPairs={layer.columnPairs}+ columns={layer.config.columns}+ assignColumnPairs={layer.assignColumnPairs.bind(layer)}+ assignColumn={layer.assignColumn.bind(layer)}+ // @ts-ignore+ columnLabels={layer.columnLabels}+ fields={fields}+ fieldPairs={fieldPairs}+ updateLayerConfig={updateLayerConfig}+ />+ </ConfigGroupCollapsibleContent></LayerConfigGroup>{renderTemplate &&this[renderTemplate] &&diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.tsindex ada894af8..2e60ebe72 100644--- a/src/constants/src/default-settings.ts+++ b/src/constants/src/default-settings.ts@@ -275,9 +275,11 @@ export const ICON_FIELDS = {export const TRIP_POINT_FIELDS: [string, string][] = [['lat', 'lng'],['lat', 'lon'],+ ['lat', 'long'],['latitude', 'longitude']];+export const ALTITUDE_FIELDS = ['alt', 'altitude'];export const TRIP_ARC_FIELDS = {lat0: 'begintrip',lng0: 'begintrip',diff --git a/src/layers/src/icon-layer/icon-layer.ts b/src/layers/src/icon-layer/icon-layer.tsindex 0d01af7f1..01d70479a 100644--- a/src/layers/src/icon-layer/icon-layer.ts+++ b/src/layers/src/icon-layer/icon-layer.ts@@ -27,6 +27,7 @@ import IconLayerIcon from './icon-layer-icon';import {ICON_FIELDS, CLOUDFRONT, ColorRange} from '@kepler.gl/constants';import IconInfoModalFactory from './icon-info-modal';import Layer, {LayerBaseConfig, LayerColumn} from '../base-layer';+import {assignPointPairToLayerColumn} from '../layer-utils';import {getTextOffsetByRadius, formatTextLabelData} from '../layer-text-label';import {default as KeplerTable, DataContainerInterface} from '@kepler.gl/table';import {@@ -234,12 +235,12 @@ export default class IconLayer extends Layer {// create icon layers for first point pairconst ptPair = fieldPairs[0];+ const columns = assignPointPairToLayerColumn(ptPair, true);const props = iconFields.map(iconField => ({label: iconField.name.replace(/[_,.]+/g, ' ').trim(),columns: {- lat: ptPair.pair.lat,- lng: ptPair.pair.lng,+ ...columns,icon: {value: iconField.name,fieldIdx: iconField.fieldIdxdiff --git a/src/layers/src/layer-utils.ts b/src/layers/src/layer-utils.tsnew file mode 100644index 000000000..c17475747--- /dev/null+++ b/src/layers/src/layer-utils.ts@@ -0,0 +1,36 @@+// 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 {FieldPair} from '@kepler.gl/types';++export function assignPointPairToLayerColumn(pair: FieldPair, hasAlt: boolean) {+ const {lat, lng, alt} = pair.pair;+ if (!hasAlt) {+ return {lat, lng};+ }++ const defaultAltColumn = {value: null, fieldIdx: -1, optional: true};++ return {+ lat,+ lng,+ altitude: alt ? {...defaultAltColumn, ...alt} : defaultAltColumn+ };+}diff --git a/src/layers/src/point-layer/point-layer.ts b/src/layers/src/point-layer/point-layer.tsindex 0f35598d7..ca6b3c0a4 100644--- a/src/layers/src/point-layer/point-layer.ts+++ b/src/layers/src/point-layer/point-layer.ts@@ -40,6 +40,7 @@ import {} from '@kepler.gl/constants';import {getTextOffsetByRadius, formatTextLabelData} from '../layer-text-label';+import {assignPointPairToLayerColumn} from '../layer-utils';import {Merge,RGBColor,@@ -66,7 +67,7 @@ export type PointLayerVisConfigSettings = {export type PointLayerColumnsConfig = {lat: LayerColumn;lng: LayerColumn;- altitude: LayerColumn;+ altitude?: LayerColumn;};export type PointLayerVisConfig = {@@ -234,8 +235,6 @@ export default class PointLayer extends Layer {// Make layer for each pairfieldPairs.forEach(pair => {const latField = pair.pair.lat;- const lngField = pair.pair.lng;- const layerName = pair.defaultName;const prop: {label: string;@@ -243,7 +242,7 @@ export default class PointLayer extends Layer {isVisible?: boolean;columns?: PointLayerColumnsConfig;} = {- label: layerName.length ? layerName : 'Point'+ label: pair.defaultName || 'Point'};// default layer color for begintrip and dropoff point@@ -255,12 +254,7 @@ export default class PointLayer extends Layer {if (props.length === 0) {prop.isVisible = true;}-- prop.columns = {- lat: latField,- lng: lngField,- altitude: {value: null, fieldIdx: -1, optional: true}- };+ prop.columns = assignPointPairToLayerColumn(pair, true);props.push(prop);});@@ -377,7 +371,7 @@ export default class PointLayer extends Layer {...data,parameters: {// circles will be flat on the map when the altitude column is not used- depthTest: this.config.columns.altitude?.fieldIdx > -1+ depthTest: (this.config.columns.altitude?.fieldIdx as number) > -1},lineWidthUnits: 'pixels',updateTriggers,diff --git a/src/layers/src/trip-layer/trip-layer.ts b/src/layers/src/trip-layer/trip-layer.tsindex 62870162b..70defdb70 100644--- a/src/layers/src/trip-layer/trip-layer.ts+++ b/src/layers/src/trip-layer/trip-layer.ts@@ -136,6 +136,10 @@ export default class TripLayer extends Layer {return TripLayerIcon;}+ get columnPairs() {+ return this.defaultPointColumnPairs;+ }+get requiredLayerColumns() {return geoJsonRequiredColumns;}@@ -194,29 +198,29 @@ export default class TripLayer extends Layer {const geoJsonColumns = this.findDefaultColumnField(defaultColumns, fields);- const tripColumns = (geoJsonColumns || []).filter(col =>+ const tripGeojsonColumns = (geoJsonColumns || []).filter(col =>isTripGeoJsonField(dataContainer, fields[col.geojson.fieldIdx]));- if (!tripColumns.length) {- return {props: []};+ if (tripGeojsonColumns.length) {+ return {+ props: tripGeojsonColumns.map(columns => ({+ label: (typeof label === 'string' && label.replace(/\.[^/.]+$/, '')) || this.type,+ columns,+ isVisible: true+ })),++ // if a geojson layer is created from this column, delete it+ foundLayers: foundLayers.filter(+ prop =>+ prop.type !== 'geojson' ||+ prop.dataId !== id ||+ !tripGeojsonColumns.find(c => prop.columns.geojson.name === c.geojson.name)+ )+ };}- return {- props: tripColumns.map(columns => ({- label: (typeof label === 'string' && label.replace(/\.[^/.]+$/, '')) || this.type,- columns,- isVisible: true- })),-- // if a geojson layer is created from this column, delete it- foundLayers: foundLayers.filter(- prop =>- prop.type !== 'geojson' ||- prop.dataId !== id ||- !tripColumns.find(c => prop.columns.geojson.name === c.geojson.name)- )- };+ return {props: []};}getDefaultLayerConfig(props) {diff --git a/src/reducers/src/export-utils.ts b/src/reducers/src/export-utils.tsindex 9f738730e..f6317c1e1 100644--- a/src/reducers/src/export-utils.ts+++ b/src/reducers/src/export-utils.ts@@ -24,7 +24,12 @@ import {csvFormatRows} from 'd3-dsv';import {EXPORT_DATA_TYPE} from '@kepler.gl/constants';import {Field} from '@kepler.gl/types';-import {createIndexedDataContainer, DataContainerInterface, Datasets} from '@kepler.gl/table';+import {+ createIndexedDataContainer,+ DataContainerInterface,+ Datasets,+ KeplerTable+} from '@kepler.gl/table';import {parseFieldValue} from '@kepler.gl/utils';import {downloadFile, DEFAULT_DATA_NAME} from '@kepler.gl/utils';@@ -48,7 +53,7 @@ export function exportData(state: StateType, options) {}selectedDatasets.forEach(selectedData => {- const {dataContainer, fields, label, filteredIdxCPU = []} = selectedData;+ const {dataContainer, fields, label, filteredIdxCPU = []} = selectedData as KeplerTable;const toExport = filtered? createIndexedDataContainer(dataContainer, filteredIdxCPU): dataContainer;diff --git a/src/reducers/src/layer-utils.ts b/src/reducers/src/layer-utils.tsindex 25e4fe7f1..3116d578f 100644--- a/src/reducers/src/layer-utils.ts+++ b/src/reducers/src/layer-utils.ts@@ -45,11 +45,11 @@ export type LayersToRender = {export type AggregationLayerHoverData = {points: any[]; colorValue?: any; elevationValue?: any};export type LayerHoverProp = {- data: any[] | AggregationLayerHoverData;+ data: DataRow | AggregationLayerHoverData | null;fields: Field[];fieldsToShow: TooltipField[];layer: Layer;- primaryData?: any[] | AggregationLayerHoverData;+ primaryData?: DataRow | AggregationLayerHoverData | null;compareType?: CompareType;};@@ -150,7 +150,6 @@ export function getLayerHoverProp({const fieldsToShow = interactionConfig.tooltip.config.fieldsToShow[dataId];return {- // @ts-expect-errordata,fields,fieldsToShow,diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.tsindex ca71a9643..0806c95e4 100644--- a/src/reducers/src/vis-state-updaters.ts+++ b/src/reducers/src/vis-state-updaters.ts@@ -507,7 +507,8 @@ function setInitialLayerConfig(layer, datasets, layerClasses) {...props[0],label: newLayer.config.label,dataId: newLayer.config.dataId,- isVisible: true+ isVisible: true,+ isConfigActive: newLayer.config.isConfigActive});return typeof newLayer.setInitialLayerConfig === 'function'@@ -538,7 +539,9 @@ export function layerTypeChangeUpdater(return state;}let newLayer = new state.layerClasses[newType]({- label: oldLayer.config.label+ // keep old layer lable and isConfigActive+ label: oldLayer.config.label,+ isConfigActive: oldLayer.config.isConfigActive});if (!oldLayer.type) {@@ -1922,7 +1925,7 @@ export function addDefaultLayers(datasets: Datasets): {state: VisState; newLayers: Layer[]} {const empty: Layer[] = [];- const defaultLayers = Object.values(datasets).reduce((accu, dataset) => {+ const defaultLayers = Object.values(datasets).reduce((accu: Layer[], dataset) => {const foundLayers = findDefaultLayer(dataset, state.layerClasses);return foundLayers && foundLayers.length ? accu.concat(foundLayers) : accu;}, empty);diff --git a/src/styles/src/base.ts b/src/styles/src/base.tsindex ce5bb037e..da92cab1e 100644--- a/src/styles/src/base.ts+++ b/src/styles/src/base.ts@@ -752,6 +752,26 @@ const inputCheckbox = css`}`;+const radioTrack = css`+ ${props => props.theme.checkboxBox}+ width: ${props => props.theme.radioRadius * 2}px;+ height: ${props => props.theme.radioRadius * 2}px;+ border-radius: ${props => props.theme.radioBorderRadius}px;+ background-color: ${props => props.theme.switchTrackBgd};+ border-color: ${props => props.theme.radioBorderColor};+`;++const radioButton = css`+ border: 0;+ display: table;+ top: ${props => props.theme.radioRadius - props.theme.radioButtonRadius}px;+ left: ${props => props.theme.radioRadius - props.theme.radioButtonRadius}px;+ width: ${props => props.theme.radioButtonRadius * 2}px;+ height: ${props => props.theme.radioButtonRadius * 2}px;+ border-radius: ${props => props.theme.radioButtonRadius * 2}px;+ background-color: ${props => props.theme.radioButtonBgdColor};+`;+const inputRadio = css`${props => props.theme.inputCheckbox}padding-left: ${props => props.theme.radioRadius * 2 + 8}px;@@ -762,23 +782,25 @@ const inputRadio = css`cursor: pointer;:before {- ${props => props.theme.checkboxBox}- width: ${props => props.theme.radioRadius * 2}px;- height: ${props => props.theme.radioRadius * 2}px;- border-radius: ${props => props.theme.radioBorderRadius}px;- background-color: ${props => props.theme.switchTrackBgd};- border-color: ${props => props.theme.radioBorderColor};+ ${props => props.theme.radioTrack}+ }++ :after {+ ${props => props.theme.radioButton}+ }+`;++const secondaryRadio = css<SwitchableProps>`+ ${props => props.theme.inputRadio}++ :before {+ ${props => props.theme.radioTrack} background: ${props => props.theme.secondarySwitchTrackBgd};}:after {- top: ${props => props.theme.radioRadius - props.theme.radioButtonRadius}px;- left: ${props => props.theme.radioRadius - props.theme.radioButtonRadius}px;- display: table;- width: ${props => props.theme.radioButtonRadius * 2}px;- height: ${props => props.theme.radioButtonRadius * 2}px;- border-radius: ${props => props.theme.radioButtonRadius * 2}px;- border: 0;- background-color: ${props => props.theme.radioButtonBgdColor};+ ${props => props.theme.radioButton}+ background: ${props =>+ props.checked ? props.theme.switchBtnBgdActive : props.theme.secondarySwitchBtnBgd};}`;@@ -1209,6 +1231,9 @@ export const theme = {radioBorderColor,radioButtonRadius,radioButtonBgdColor,+ radioTrack,+ radioButton,+ secondaryRadio,// ButtonbtnFontFamily,diff --git a/src/table/src/kepler-table.ts b/src/table/src/kepler-table.tsindex 6990f298c..615632483 100644--- a/src/table/src/kepler-table.ts+++ b/src/table/src/kepler-table.ts@@ -22,7 +22,13 @@ import {console as Console} from 'global/console';import {ascending, descending} from 'd3-array';// import {validateInputData} from 'processors/data-processor';-import {TRIP_POINT_FIELDS, SORT_ORDER, ALL_FIELD_TYPES, SCALE_TYPES} from '@kepler.gl/constants';+import {+ TRIP_POINT_FIELDS,+ SORT_ORDER,+ ALL_FIELD_TYPES,+ ALTITUDE_FIELDS,+ 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';@@ -473,14 +479,25 @@ export type Datasets = {};// HELPER FUNCTIONS (MAINLY EXPORTED FOR TEST...)+// have to double excape+const specialCharacterSet = `[#_&@\\.\\-\\ ]`;-export function removeSuffixAndDelimiters(layerName, suffix) {- return layerName- .replace(new RegExp(suffix, 'ig'), '')- .replace(/[_,.]+/g, ' ')- .trim();+function foundMatchingFields(re, suffixPair, allNames, fieldName) {+ const partnerIdx = allNames.findIndex(+ d => d === fieldName.replace(re, match => match.replace(suffixPair[0], suffixPair[1]))+ );+ let altIdx = -1;+ if (partnerIdx > -1) {+ // if found partner, go on and look for altitude+ ALTITUDE_FIELDS.some(alt => {+ altIdx = allNames.findIndex(+ d => d === fieldName.replace(re, match => match.replace(suffixPair[0], alt))+ );+ return altIdx > -1;+ });+ }+ return {partnerIdx, altIdx};}-/*** Find point fields pairs from fields*@@ -495,18 +512,18 @@ export function findPointFieldPairs(fields: Field[]): FieldPair[] {return allNames.reduce((carry, fieldName, idx) => {// This search for pairs will early exit if found.for (const suffixPair of TRIP_POINT_FIELDS) {- // match first suffix```- if (fieldName.endsWith(suffixPair[0])) {- // match second suffix- const otherPattern = new RegExp(`${suffixPair[0]}\$`);- const partner = fieldName.replace(otherPattern, suffixPair[1]);+ // match first suffix+ // (^|[#_&@\.\-\ ])lat([#_&@\.\-\ ]|$)+ const re = new RegExp(`(^|${specialCharacterSet})${suffixPair[0]}(${specialCharacterSet}|$)`);++ if (re.test(fieldName)) {+ const {partnerIdx, altIdx} = foundMatchingFields(re, suffixPair, allNames, fieldName);- const partnerIdx = allNames.findIndex(d => d === partner);if (partnerIdx > -1) {- const defaultName = removeSuffixAndDelimiters(fieldName, suffixPair[0]);+ const trimName = fieldName.replace(re, '').trim();carry.push({- defaultName,+ defaultName: trimName || 'point',pair: {lat: {fieldIdx: idx,@@ -515,7 +532,15 @@ export function findPointFieldPairs(fields: Field[]): FieldPair[] {lng: {fieldIdx: partnerIdx,value: fields[partnerIdx].name- }+ },+ ...(altIdx > -1+ ? {+ alt: {+ fieldIdx: altIdx,+ value: fields[altIdx].name+ }+ }+ : {})},suffix: suffixPair});diff --git a/test/browser-headless/component/map-container-test.js b/test/browser-headless/component/map-container-test.jsindex 11cbfd713..66698e9dd 100644--- a/test/browser-headless/component/map-container-test.js+++ b/test/browser-headless/component/map-container-test.js@@ -245,7 +245,7 @@ test('MapContainerFactory - _renderDeckOverlay', t => {['gps_data.types', 'driver_analytics'],['epoch', '1472754400000'],['has_result', ''],- ['id', '1']+ ['uid', '1']];for (let i = 0; i < 5; i++) {diff --git a/test/browser/components/filters/time-widget-test.js b/test/browser/components/filters/time-widget-test.jsindex 458c1e21d..a4eec6c81 100644--- a/test/browser/components/filters/time-widget-test.js+++ b/test/browser/components/filters/time-widget-test.js@@ -108,7 +108,7 @@ test('Components -> TimeWidget.mount -> with time filter', t => {.props().fields;t.deepEqual(yAxisFields.map(f => f.name),- ['gps_data.lat', 'gps_data.lng', 'id'],+ ['gps_data.lat', 'gps_data.lng', 'uid'],'should only pass real / integer fields to yAxis');diff --git a/test/browser/components/modals/data-table-modal-test.js b/test/browser/components/modals/data-table-modal-test.jsindex 9cf9fb845..69257ad12 100644--- a/test/browser/components/modals/data-table-modal-test.js+++ b/test/browser/components/modals/data-table-modal-test.js@@ -56,7 +56,7 @@ const expectedCellSizeCache = {'gps_data.types': {row: 125, header: 123},epoch: {row: 121, header: 90},has_result: {row: 75, header: 99},- id: {row: 75, header: 90},+ uid: {row: 75, header: 90},time: {row: 180, header: 90},begintrip_ts_utc: {row: 182, header: 129},begintrip_ts_local: {row: 182, header: 137},@@ -71,7 +71,7 @@ const expectedExpandedCellSize = {'gps_data.types': 125,epoch: 121,has_result: 75,- id: 75,+ uid: 75,time: 180,begintrip_ts_utc: 182,begintrip_ts_local: 182,@@ -155,7 +155,7 @@ test('Components -> DataTableModal.render: csv 1', t => {'gps_data.types','epoch','has_result',- 'id',+ 'uid','time','begintrip_ts_utc','begintrip_ts_local',@@ -169,7 +169,7 @@ test('Components -> DataTableModal.render: csv 1', t => {'gps_data.types': {name: 'gps_data.types', type: 'string'},epoch: {name: 'epoch', type: 'timestamp'},has_result: {name: 'has_result', type: 'boolean'},- id: {name: 'id', type: 'integer'},+ uid: {name: 'uid', type: 'integer'},time: {name: 'time', type: 'timestamp'},begintrip_ts_utc: {name: 'begintrip_ts_utc', type: 'timestamp'},begintrip_ts_local: {name: 'begintrip_ts_local', type: 'timestamp'},@@ -256,7 +256,6 @@ test('Components -> DataTableModal -> render DataTable: csv 1', t => {const wrapper = mountWithTheme(<DataTableModal datasets={StateWFiles.visState.datasets} dataId={testCsvDataId} />);-t.equal(wrapper.find(DataTable).length, 1, 'should render 1 DataTable');const props = wrapper@@ -412,7 +411,7 @@ test('Components -> DataTableModal -> render DataTable: sort and pin', t => {'gps_data.lng','gps_data.types','epoch',- 'id',+ 'uid','time','begintrip_ts_utc','begintrip_ts_local',diff --git a/test/browser/components/side-panel/filter-manager-test.js b/test/browser/components/side-panel/filter-manager-test.jsindex 17eab8258..bddeabaac 100644--- a/test/browser/components/side-panel/filter-manager-test.js+++ b/test/browser/components/side-panel/filter-manager-test.js@@ -220,7 +220,7 @@ test('Components -> FilterManager.mount -> with supportedFilterTypes', t => {t.deepEqual(fieldOptions.map(f => f.name),- ['gps_data.lat', 'gps_data.lng', 'id'],+ ['gps_data.lat', 'gps_data.lng', 'uid'],'should only pass real / integer fields');diff --git a/test/browser/components/side-panel/layer-configurator-test.js b/test/browser/components/side-panel/layer-configurator-test.jsindex 0e75ba75b..79dbeca41 100644--- a/test/browser/components/side-panel/layer-configurator-test.js+++ b/test/browser/components/side-panel/layer-configurator-test.js@@ -24,12 +24,30 @@ import React from 'react';import test from 'tape';import sinon from 'sinon';-import {LayerConfiguratorFactory, appInjector} from '@kepler.gl/components';-import {StateWFiles, testCsvDataId} from 'test/helpers/mock-state';-import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';+import {+ LayerConfiguratorFactory,+ LayerColumnConfigFactory,+ LayerConfigGroupFactory,+ FieldSelectorFactory,+ ColumnSelectorFactory,+ appInjector+} from '@kepler.gl/components';++import {StateWFiles, StateWTripGeojson, testCsvDataId} from 'test/helpers/mock-state';+import {+ IntlWrapper,+ mountWithTheme,+ clickItemSelector,+ getItemSelectorListText,+ clickItemSelectList+} from 'test/helpers/component-utils';// componentsconst LayerConfigurator = appInjector.get(LayerConfiguratorFactory);+const LayerColumnConfig = appInjector.get(LayerColumnConfigFactory);+const LayerConfigGroup = appInjector.get(LayerConfigGroupFactory);+const ColumnSelector = appInjector.get(ColumnSelectorFactory);+const FieldSelector = appInjector.get(FieldSelectorFactory);// componentsconst openModal = () => {};@@ -53,7 +71,7 @@ const defaultProps = {updateLayerVisConfig};-test('Components -> LayerConfigurator.mount -> defaut prop', t => {+test('Components -> LayerConfigurator.mount -> defaut prop 1', t => {// mountlet wrapper;t.doesNotThrow(() => {@@ -128,3 +146,163 @@ test('Components -> LayerConfigurator.mount -> defaut prop', t => {t.end();});++test('Components -> LayerConfigurator.mount -> defaut prop 2', t => {+ // mount+ const updateLayerConfigSpy = sinon.spy();++ let wrapper;+ t.doesNotThrow(() => {+ wrapper = mountWithTheme(+ <IntlWrapper>+ <LayerConfigurator {...defaultProps} updateLayerConfig={updateLayerConfigSpy} />+ </IntlWrapper>+ );+ }, 'LayerConfigurator should not fail without props');+ const baseConfigGroup = wrapper.find(LayerConfigGroup).at(0);++ t.equal(baseConfigGroup.find(LayerColumnConfig).length, 1, 'should render 1 LayerColumnConfig');++ t.equal(+ baseConfigGroup+ .find(LayerColumnConfig)+ .at(0)+ .find(ColumnSelector).length,+ 3,+ 'Should render 3 ColumnSelector'+ );++ // open fieldSelector+ // t.equal(+ const fieldSelector = baseConfigGroup+ .find(LayerColumnConfig)+ .at(0)+ .find(ColumnSelector)+ .at(0)+ .find(FieldSelector)+ .at(0);++ // open dropdown+ clickItemSelector(fieldSelector);+ const fieldSelector2 = wrapper+ .find(LayerColumnConfig)+ .at(0)+ .find(ColumnSelector)+ .at(0)+ .find(FieldSelector)+ .at(0);++ t.equal(fieldSelector2.find('.list__item.fixed').length, 1, 'should render 1 fixed item');++ t.equal(+ getItemSelectorListText(fieldSelector2, 0),+ 'gps_data',+ 'should render correct field pair name'+ );++ // click list item suggested field pair+ clickItemSelectList(fieldSelector2, 0);++ t.ok(updateLayerConfigSpy.calledOnce, 'should call updateLayerConfigSpy');+ t.deepEqual(+ updateLayerConfigSpy.args[0],+ [+ {+ columns: {+ lat: {+ value: 'gps_data.lat',+ fieldIdx: 1+ },+ lng: {+ value: 'gps_data.lng',+ fieldIdx: 2+ },+ altitude: {value: null, fieldIdx: -1, optional: true}+ }+ }+ ],+ 'should update field pairs'+ );+ t.equal(+ getItemSelectorListText(fieldSelector2, 2),+ 'gps_data.lng',+ 'should render correct field pair name'+ );++ // click single column+ clickItemSelectList(fieldSelector2, 2);++ t.ok(updateLayerConfigSpy.calledTwice, 'should call updateLayerConfigSpy');+ t.deepEqual(+ updateLayerConfigSpy.args[1],+ [+ {+ columns: {+ lat: {+ value: 'gps_data.lng',+ fieldIdx: 2+ },+ lng: {+ value: 'gps_data.lng',+ fieldIdx: 2+ },+ altitude: {value: null, fieldIdx: -1, optional: true}+ }+ }+ ],+ 'should update single column'+ );+ t.end();+});++test('Components -> LayerConfigurator.mount -> collapsed / expand config group ', t => {+ const propsWithTripLayer = {+ ...defaultProps,+ layer: StateWTripGeojson.visState.layers[0],+ datasets: StateWTripGeojson.visState.datasets+ };++ let wrapper;+ t.doesNotThrow(() => {+ wrapper = mountWithTheme(+ <IntlWrapper>+ <LayerConfigurator {...propsWithTripLayer} />+ </IntlWrapper>+ );+ }, 'LayerConfigurator should not fail without props');++ const component = wrapper.find(LayerConfigurator).instance();+ t.equal(+ wrapper+ .find(LayerConfigGroup)+ .at(0)+ .find('.layer-config-group.collapsed').length,+ 3,+ 'LayerConfigGroup should be collapsed'+ );++ const spy = sinon.spy(component, '_renderScatterplotLayerConfig');+ const spy2 = sinon.spy(component, '_renderTripLayerConfig');+ component.forceUpdate();+ wrapper.update();++ t.ok(spy.notCalled, 'should not call _renderScatterplotLayerConfig');+ t.ok(spy2.calledOnce, 'should call _renderTripLayerConfig');++ // click layer config group header+ wrapper+ .find('.layer-config-group__header')+ .at(0)+ .simulate('click');++ t.equal(+ wrapper+ .find(LayerConfigGroup)+ .at(0)+ .find('.layer-config-group.collapsed').length,+ 0,+ 'LayerConfigGroup should be expanded'+ );++ t.end();+});diff --git a/test/browser/file-handler-test.js b/test/browser/file-handler-test.jsindex 15602f1bf..754d18738 100644--- a/test/browser/file-handler-test.js+++ b/test/browser/file-handler-test.js@@ -101,7 +101,7 @@ test('#file-handler -> readFileInBatches.csv -> processFileData', async t => {'gps_data.types','epoch','has_result',- 'id',+ 'uid','time','begintrip_ts_utc','begintrip_ts_local',diff --git a/test/fixtures/test-csv-data.js b/test/fixtures/test-csv-data.jsindex b708ad4de..950bfd4ea 100644--- a/test/fixtures/test-csv-data.js+++ b/test/fixtures/test-csv-data.js@@ -19,7 +19,7 @@// THE SOFTWARE./* eslint-disable max-len */-const data = `gps_data.utc_timestamp,gps_data.lat,gps_data.lng,gps_data.types,epoch,has_result,id,time,begintrip_ts_utc,begintrip_ts_local,date+const data = `gps_data.utc_timestamp,gps_data.lat,gps_data.lng,gps_data.types,epoch,has_result,uid,time,begintrip_ts_utc,begintrip_ts_local,date2016-09-17 00:09:55,29.9900937,31.2590542,driver_analytics_0,1472688000000,False,1,2016-09-23T00:00:00.000Z,2016-10-01 09:41:39+00:00,2016-10-01 09:41:39+00:00,2016-09-232016-09-17 00:10:56,29.9927699,31.2461142,driver_analytics,1472688000000,False,2,2016-09-23T00:00:00.000Z,2016-10-01 09:46:37+00:00,2016-10-01 16:46:37+00:00,2016-09-232016-09-17 00:11:56,29.9907261,31.2312742,driver_analytics,1472688000000,False,3,2016-09-23T00:00:00.000Z,,,2016-09-23@@ -255,7 +255,7 @@ export const sampleConfig = {config};-export const dataWithNulls = `gps_data.utc_timestamp,gps_data.lat,gps_data.lng,gps_data.types,epoch,has_result,id,time,begintrip_ts_utc,begintrip_ts_local,date+export const dataWithNulls = `gps_data.utc_timestamp,gps_data.lat,gps_data.lng,gps_data.types,epoch,has_result,uid,time,begintrip_ts_utc,begintrip_ts_local,dateNull,29.9900937,31.2590542,driver_analytics_0,1472688000000,False,1,2016-09-23T00:00:00.000Z,2016-10-01 09:41:39+00:00,2016-10-01 09:41:39+00:00,2016-09-232016-09-17 00:10:56,29.9927699,31.2461142,null,1472688000000,False,null,2016-09-23T00:00:00.000Z,2016-10-01 09:46:37+00:00,2016-10-01 16:46:37+00:00,2016-09-232016-09-17 00:11:56,29.9907261,NaN,driver_analytics,1472688000000,False,3,2016-09-23T00:00:00.000Z,,,2016-09-23@@ -529,9 +529,9 @@ export const testFields = [{type: 'integer',fieldIdx: 6,- name: 'id',- id: 'id',- displayName: 'id',+ name: 'uid',+ id: 'uid',+ displayName: 'uid',format: '',analyzerType: 'INT',valueAccessor: dc => d => {@@ -588,6 +588,22 @@ export const testFields = [}];+export const testCsvFieldPairs = [+ {+ defaultName: 'gps_data',+ pair: {+ lat: {+ value: 'gps_data.lat',+ fieldIdx: 1+ },+ lng: {+ value: 'gps_data.lng',+ fieldIdx: 2+ }+ },+ suffix: ['lat', 'lng']+ }+];export const timeMappedValue = [1474588800000,1474588800000,diff --git a/test/helpers/component-utils.js b/test/helpers/component-utils.jsindex f0250560f..c66de75fa 100644--- a/test/helpers/component-utils.js+++ b/test/helpers/component-utils.js@@ -25,6 +25,7 @@ import {theme} from '@kepler.gl/styles';import {ThemeProvider} from 'styled-components';import {IntlProvider} from 'react-intl';import {messages} from '@kepler.gl/localization';+import {Typeahead} from '@kepler.gl/components';export function mountWithTheme(node, options) {return mount(node, {@@ -43,3 +44,29 @@ export const IntlWrapper = ({children, locale = 'en'}) => (export function mockHTMLElementClientSize(prop, value) {return sinon.stub(HTMLElement.prototype, prop).get(() => value);}++export function clickItemSelector(itemSelector) {+ itemSelector+ .find('.item-selector__dropdown')+ .at(0)+ .simulate('click');+}++export function clickItemSelectList(itemSelector, itemIndex) {+ itemSelector+ .find(Typeahead)+ .at(0)+ .find('.list__item')+ .at(itemIndex)+ .simulate('click');+}++export function getItemSelectorListText(itemSelector, itemIndex) {+ return itemSelector+ .find(Typeahead)+ .at(0)+ .find('.list__item')+ .at(itemIndex)+ .find('.list__item__anchor')+ .text();+}diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.jsindex 67b9a0959..08a4fa4ae 100644--- a/test/helpers/mock-state.js+++ b/test/helpers/mock-state.js@@ -664,7 +664,7 @@ export const expectedSavedLayer1 = {type: 'point',config: {dataId: testCsvDataId,- label: 'gps data',+ label: 'gps_data',highlightColor: DEFAULT_HIGHLIGHT_COLOR,color: [0, 0, 0],columns: {@@ -720,7 +720,7 @@ export const expectedLoadedLayer1 = {type: 'point',config: {dataId: testCsvDataId,- label: 'gps data',+ label: 'gps_data',highlightColor: DEFAULT_HIGHLIGHT_COLOR,color: [0, 0, 0],columns: {diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.jsindex 779df0ca4..77af02026 100644--- a/test/node/reducers/vis-state-merger-test.js+++ b/test/node/reducers/vis-state-merger-test.js@@ -795,7 +795,7 @@ test('VisStateMerger.v0 -> mergeInteractions -> toWorkingState', t => {format: null},{- name: 'id',+ name: 'uid',format: null}],@@ -1034,7 +1034,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {format: null},{- name: 'id',+ name: 'uid',format: null}],@@ -1116,7 +1116,7 @@ test('VisStateMerger.v1 -> mergeInteractions -> toWorkingState', t => {format: null},{- name: 'id',+ name: 'uid',format: null}],diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.jsindex a282e153b..21efbae44 100644--- a/test/node/reducers/vis-state-test.js+++ b/test/node/reducers/vis-state-test.js@@ -55,7 +55,12 @@ import {const {ArcLayer, PointLayer, GeojsonLayer, LineLayer, TripLayer} = KeplerGlLayers;// fixtures-import testData, {mergedTimeFilter, testFields, testAllData} from 'test/fixtures/test-csv-data';+import testData, {+ mergedTimeFilter,+ testFields,+ testAllData,+ testCsvFieldPairs+} from 'test/fixtures/test-csv-data';import {geojsonData,geoJsonTripFilterProps,@@ -161,7 +166,36 @@ const expectedFields = [valueAccessor: values => values[3]}];-+const expectedFieldParis = [+ {+ defaultName: 'start_point',+ pair: {+ lat: {+ value: 'start_point_lat',+ fieldIdx: 0+ },+ lng: {+ value: 'start_point_lng',+ fieldIdx: 1+ }+ },+ suffix: ['lat', 'lng']+ },+ {+ defaultName: 'end_point',+ pair: {+ lat: {+ value: 'end_point_lat',+ fieldIdx: 2+ },+ lng: {+ value: 'end_point_lng',+ fieldIdx: 3+ }+ },+ suffix: ['lat', 'lng']+ }+];const mockFilter = {fieldIdx: 0,name: mockData.fields[0].name,@@ -1097,7 +1131,7 @@ test('#visStateReducer -> DUPLICATE_LAYER', t => {id: layerCopied.id,config: {...layerToCopy.config,- label: 'Copy of gps data'+ label: 'Copy of gps_data'}};@@ -1123,7 +1157,7 @@ test('#visStateReducer -> DUPLICATE_LAYER', t => {id: layerCopied1.id,config: {...layerToCopy.config,- label: 'Copy of gps data 1'+ label: 'Copy of gps_data 1'}};t.deepEqual(layerCopied1, expectedLayer1, 'should copy layer config correctly');@@ -1148,7 +1182,7 @@ test('#visStateReducer -> DUPLICATE_LAYER', t => {id: layerCopied2.id,config: {...layerToCopy.config,- label: 'Copy of gps data 2'+ label: 'Copy of gps_data 2'}};t.deepEqual(layerCopied2, expectedLayer2, 'should copy layer config correctly');@@ -1243,36 +1277,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {color: 'donnot test me',id: 'smoothie',label: 'exciting dataset',- fieldPairs: [- {- defaultName: 'start point',- pair: {- lat: {- value: 'start_point_lat',- fieldIdx: 0- },- lng: {- value: 'start_point_lng',- fieldIdx: 1- }- },- suffix: ['lat', 'lng']- },- {- defaultName: 'end point',- pair: {- lat: {- value: 'end_point_lat',- fieldIdx: 2- },- lng: {- value: 'end_point_lng',- fieldIdx: 3- }- },- suffix: ['lat', 'lng']- }- ],+ fieldPairs: expectedFieldParis,metadata: {id: 'smoothie', label: 'exciting dataset', album: 'taro_and_blue', format: ''},type: '',supportedFilterTypes: null,@@ -1286,7 +1291,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {const expectedArcLayer = new ArcLayer({dataId: 'smoothie',- label: 'start point -> end point arc',+ label: 'start_point -> end_point arc',columns: {lat0: {fieldIdx: 0, value: 'start_point_lat'},lng0: {fieldIdx: 1, value: 'start_point_lng'},@@ -1297,7 +1302,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {const expectedLineLayer = new LineLayer({dataId: 'smoothie',- label: 'start point -> end point line',+ label: 'start_point -> end_point line',columns: {lat0: {fieldIdx: 0, value: 'start_point_lat'},lng0: {fieldIdx: 1, value: 'start_point_lng'},@@ -1318,7 +1323,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {const expectedPointLayer1 = new PointLayer({dataId: 'smoothie',- label: 'start point',+ label: 'start_point',columns: {lat: {fieldIdx: 0, value: 'start_point_lat'},lng: {fieldIdx: 1, value: 'start_point_lng'},@@ -1333,7 +1338,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {const expectedPointLayer2 = new PointLayer({dataId: 'smoothie',- label: 'end point',+ label: 'end_point',columns: {lat: {fieldIdx: 2, value: 'end_point_lat'},lng: {fieldIdx: 3, value: 'end_point_lng'},@@ -1451,36 +1456,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.3 -> merge w/ existing state', t => {},id: 'smoothie',label: 'smoothie and milkshake',- fieldPairs: [- {- defaultName: 'start point',- pair: {- lat: {- value: 'start_point_lat',- fieldIdx: 0- },- lng: {- value: 'start_point_lng',- fieldIdx: 1- }- },- suffix: ['lat', 'lng']- },- {- defaultName: 'end point',- pair: {- lat: {- value: 'end_point_lat',- fieldIdx: 2- },- lng: {- value: 'end_point_lng',- fieldIdx: 3- }- },- suffix: ['lat', 'lng']- }- ]+ fieldPairs: expectedFieldParis}};@@ -1806,36 +1782,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {color: 'donot test me',id: 'smoothie',label: 'smoothie and milkshake',- fieldPairs: [- {- defaultName: 'start point',- pair: {- lat: {- value: 'start_point_lat',- fieldIdx: 0- },- lng: {- value: 'start_point_lng',- fieldIdx: 1- }- },- suffix: ['lat', 'lng']- },- {- defaultName: 'end point',- pair: {- lat: {- value: 'end_point_lat',- fieldIdx: 2- },- lng: {- value: 'end_point_lng',- fieldIdx: 3- }- },- suffix: ['lat', 'lng']- }- ],+ fieldPairs: expectedFieldParis,changedFilters: {dynamicDomain: {'38chejr': 'added'},fixedDomain: null,@@ -1974,7 +1921,7 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {const expectedLayer1 = new PointLayer({isVisible: true,dataId: 'smoothie',- label: 'gps data',+ label: 'gps_data',columns: {lat: {value: 'gps_data.lat', fieldIdx: 1},lng: {value: 'gps_data.lng', fieldIdx: 2},@@ -2104,22 +2051,7 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {result: [0, 0, 0, 0]}},- fieldPairs: [- {- defaultName: 'gps data',- pair: {- lat: {- value: 'gps_data.lat',- fieldIdx: 1- },- lng: {- value: 'gps_data.lng',- fieldIdx: 2- }- },- suffix: ['lat', 'lng']- }- ],+ fieldPairs: testCsvFieldPairs,changedFilters: {dynamicDomain: null, fixedDomain: null, cpu: null, gpu: null}};@@ -2696,7 +2628,7 @@ test('#visStateReducer -> SET_FILTER_PLOT', t => {);// find id which is an integer field- const yAxisField = stateWithFilterName.datasets.smoothie.fields.find(f => f.name === 'id');+ const yAxisField = stateWithFilterName.datasets.smoothie.fields.find(f => f.name === 'uid');// set filterPlot yAxisconst stateWithFilterPlot = reducer(@@ -2716,16 +2648,7 @@ test('#visStateReducer -> SET_FILTER_PLOT', t => {value: [1474070995000, 1474072208000],step: 1000,plotType: 'lineChart',- yAxis: {- type: 'integer',- name: 'id',- displayName: 'id',- id: 'id',- format: '',- fieldIdx: 6,- analyzerType: 'INT',- valueAccessor: values => values[6]- },+ yAxis: yAxisField,interval: null,lineChart: {series: [@@ -3108,7 +3031,7 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {format: null},{- name: 'id',+ name: 'uid',format: null}]diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.jsindex 4b89e1716..aa3588fc0 100644--- a/test/node/schemas/vis-state-schema-test.js+++ b/test/node/schemas/vis-state-schema-test.js@@ -171,7 +171,7 @@ test('#visStateSchema -> v1 -> save load interaction', t => {format: null},{- name: 'id',+ name: 'uid',format: null}],diff --git a/test/node/utils/kepler-table-test.js b/test/node/utils/kepler-table-test.jsindex e20f2f582..d4a89315b 100644--- a/test/node/utils/kepler-table-test.js+++ b/test/node/utils/kepler-table-test.js@@ -23,7 +23,7 @@ import moment from 'moment';import testData, {numericRangesCsv, testFields} from 'test/fixtures/test-csv-data';import {preciseRound} from '@kepler.gl/utils';-import {createNewDataEntry, getFilterFunction} from '@kepler.gl/table';+import {createNewDataEntry, getFilterFunction, findPointFieldPairs} from '@kepler.gl/table';import {processCsvData} from '@kepler.gl/processors';import {cmpFields} from '../../helpers/comparison-utils';@@ -260,3 +260,128 @@ test('KeplerTable -> getColumnFilterDomain -> numeric', async t => {t.end();});++test('KeplerTable -> findPointFieldPairs', t => {+ const TASE_CASE = [+ {+ fields: [+ 'point-lat',+ 'point-lng',+ 'long',+ 'lat',+ 'poi_latitude',+ 'poi_longitude',+ 'latino',+ 'lngtino',+ 'lat.1',+ 'lng.1'+ ],+ expected: [+ {+ defaultName: 'point',+ pair: {+ lat: {+ fieldIdx: 0,+ value: 'point-lat'+ },+ lng: {+ fieldIdx: 1,+ value: 'point-lng'+ }+ },+ suffix: ['lat', 'lng']+ },+ {+ defaultName: 'point',+ pair: {+ lat: {+ fieldIdx: 3,+ value: 'lat'+ },+ lng: {+ fieldIdx: 2,+ value: 'long'+ }+ },+ suffix: ['lat', 'long']+ },+ {+ defaultName: 'poi',+ pair: {+ lat: {+ fieldIdx: 4,+ value: 'poi_latitude'+ },+ lng: {+ fieldIdx: 5,+ value: 'poi_longitude'+ }+ },+ suffix: ['latitude', 'longitude']+ },+ {+ defaultName: '1',+ pair: {+ lat: {+ fieldIdx: 8,+ value: 'lat.1'+ },+ lng: {+ fieldIdx: 9,+ value: 'lng.1'+ }+ },+ suffix: ['lat', 'lng']+ }+ ]+ },+ {+ fields: ['point.lat', 'point.long', 'point.altitude', 'latitude', 'longitude'],+ expected: [+ {+ defaultName: 'point',+ pair: {+ lat: {+ fieldIdx: 0,+ value: 'point.lat'+ },+ lng: {+ fieldIdx: 1,+ value: 'point.long'+ },+ alt: {+ fieldIdx: 2,+ value: 'point.altitude'+ }+ },+ suffix: ['lat', 'long']+ },+ {+ defaultName: 'point',+ pair: {+ lat: {+ fieldIdx: 3,+ value: 'latitude'+ },+ lng: {+ fieldIdx: 4,+ value: 'longitude'+ }+ },+ suffix: ['latitude', 'longitude']+ }+ ]+ }+ ];++ TASE_CASE.forEach(({fields, expected}) => {+ const found = findPointFieldPairs(fields.map(f => ({name: f})));++ t.equal(expected.length, found.length, `should found ${expected.length} pairs`);+ expected.forEach((pair, index) => {+ t.deepEqual(found[index], pair, 'should found correct point pair');+ });+ });++ t.end();+});diff --git a/test/node/utils/layer-utils-test.js b/test/node/utils/layer-utils-test.jsindex e5388f559..190913272 100644--- a/test/node/utils/layer-utils-test.js+++ b/test/node/utils/layer-utils-test.js@@ -89,6 +89,7 @@ test('layerUtils -> findDefaultLayer.1', t => {},// non layer//+{name: 'non_layer_longitude.alt',fieldIdx: 10@@ -96,6 +97,10 @@ test('layerUtils -> findDefaultLayer.1', t => {{name: 'non_layer_latitude.alt',fieldIdx: 11+ },+ {+ name: 'non_layer_altitude.alt',+ fieldIdx: 12}];@@ -123,7 +128,7 @@ test('layerUtils -> findDefaultLayer.1', t => {}}),new PointLayer({- label: 'two two',+ label: 'two_two',dataId,columns: {lat: {@@ -161,7 +166,7 @@ test('layerUtils -> findDefaultLayer.1', t => {}}),new PointLayer({- label: 'four',+ label: 'four._',dataId,columns: {lat: {@@ -180,7 +185,7 @@ test('layerUtils -> findDefaultLayer.1', t => {}}),new PointLayer({- label: 'Point',+ label: 'point',dataId,columns: {lat: {@@ -198,8 +203,27 @@ test('layerUtils -> findDefaultLayer.1', t => {}}}),+ new PointLayer({+ label: 'non_layeralt',+ dataId,+ columns: {+ lat: {+ value: 'non_layer_latitude.alt',+ fieldIdx: 11+ },+ lng: {+ value: 'non_layer_longitude.alt',+ fieldIdx: 10+ },+ altitude: {+ value: 'non_layer_altitude.alt',+ fieldIdx: 12,+ optional: true+ }+ }+ }),new ArcLayer({- label: 'one -> two two arc',+ label: 'one -> two_two arc',dataId,columns: {lat0: {@@ -221,7 +245,7 @@ test('layerUtils -> findDefaultLayer.1', t => {}}),new LineLayer({- label: 'one -> two two line',+ label: 'one -> two_two line',dataId,columns: {lat0: {