Skip to content

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

[Feat] Add neighbor column mode to arc layer, support arc from hex (#2665)

Igor Dykhtab6ac65405158
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.js
index d989743b4..d96c397d1 100644
--- a/examples/demo-app/src/app.js
+++ b/examples/demo-app/src/app.js
@@ -43,8 +43,8 @@ import sampleS2Data, {config as s2MapConfig, dataId as s2DataId} from './data/sa
import sampleAnimateTrip, {animateTripDataId} 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';
+import sampleRowData, {config as rowDataConfig} from './data/sample-row-data';
+import {processCsvData, processGeojson, processRowObject} from '@kepler.gl/processors';
/* eslint-enable no-unused-vars */
const BannerHeight = 48;
@@ -178,7 +178,25 @@ class App extends Component {
// this._loadH3HexagonData();
// this._loadS2Data();
// this._loadScenegraphLayer();
- this._loadGpsData();
+ // this._loadGpsData();
+ // this._loadRowData();
+ }
+
+ _loadRowData() {
+ this.props.dispatch(
+ addDataToMap({
+ datasets: [
+ {
+ info: {
+ label: 'Sample Visit Data',
+ id: 'sample_visit_data'
+ },
+ data: processRowObject(sampleRowData)
+ }
+ ],
+ config: rowDataConfig
+ })
+ );
}
_loadPointData() {
diff --git a/examples/demo-app/src/data/sample-row-data.js b/examples/demo-app/src/data/sample-row-data.js
new file mode 100644
index 000000000..4c662022d
--- /dev/null
+++ b/examples/demo-app/src/data/sample-row-data.js
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+const data = [
+ {
+ venue_id: '7c69e9',
+ count: 10,
+ latitude: 41.852015,
+ longitude: -87.616047,
+ neighbors: [1, 2],
+ 'source hex_id': '8a2664c1b74ffff',
+ 'target latitude': 41.946969,
+ 'target longitude': -87.693607,
+ 'target hex_id': '8a2664ca51b7fff'
+ },
+ {
+ venue_id: 'fe26e3',
+ count: 22,
+ latitude: 41.946969,
+ longitude: -87.693607,
+ neighbors: [2, 3],
+ 'source hex_id': '8a2664ca51b7fff',
+ 'target latitude': 41.7552452681605,
+ 'target longitude': -87.6322426600563,
+ 'target hex_id': '8a2664cc3757fff'
+ },
+ {
+ venue_id: '5f3ec9',
+ count: 5,
+ latitude: 41.9228189446294,
+ longitude: -87.7459144592286,
+ neighbors: [3, 4],
+ 'source hex_id': '8a2664ca22dffff',
+ 'target latitude': 41.7552452681605,
+ 'target longitude': -87.6322426600563,
+ 'target hex_id': '8a2664cc3757fff'
+ },
+ {
+ venue_id: 'fe625f',
+ count: 11,
+ latitude: 41.9458364,
+ longitude: -87.7474061,
+ neighbors: [4, 5, 6],
+ 'source hex_id': '8a2664ca66c7fff',
+ 'target latitude': 41.990071,
+ 'target longitude': -87.710537,
+ 'target hex_id': '8a2664d8ad97fff'
+ },
+ {
+ venue_id: '7b1fe3',
+ count: 14,
+ latitude: 41.879519,
+ longitude: -87.6335512,
+ neighbors: [5, 6],
+ 'source hex_id': '8a2664c1a89ffff',
+ 'target latitude': 41.8801791917474,
+ 'target longitude': -87.7507109194994,
+ 'target hex_id': '8a2664c81567fff'
+ },
+ {
+ venue_id: 'd16c1b',
+ count: 8,
+ latitude: 41.7552452681605,
+ longitude: -87.6322426600563,
+ neighbors: [6, 7],
+ 'source hex_id': '8a2664cc3757fff',
+ 'target latitude': 41.9760432,
+ 'target longitude': -87.7082406,
+ 'target hex_id': '8a2664d8a71ffff'
+ },
+ {
+ venue_id: '5f3be3',
+ count: 6,
+ latitude: 41.990071,
+ longitude: -87.710537,
+ neighbors: [7, 8],
+ 'source hex_id': '8a2664d8ad97fff',
+ 'target latitude': 41.7552452681605,
+ 'target longitude': -87.6322426600563,
+ 'target hex_id': '8a2664cc3757fff'
+ },
+ {
+ venue_id: 'eeea20',
+ count: 5,
+ latitude: 41.8801791917474,
+ longitude: -87.7507109194994,
+ neighbors: [8, 9],
+ 'source hex_id': '8a2664c81567fff',
+ 'target latitude': 41.7753234651629,
+ 'target longitude': -87.6832077690278,
+ 'target hex_id': '8a2664cd1197fff'
+ }
+];
+
+export const config = {
+ version: 'v1',
+ config: {
+ visState: {
+ filters: [],
+ layers: [
+ {
+ id: 'iulge5',
+ type: 'point',
+ config: {
+ dataId: 'sample_visit_data',
+ label: 'point',
+ columns: {
+ lat: 'latitude',
+ lng: 'longitude',
+ neighbors: 'neighbors'
+ },
+ isVisible: true,
+ visConfig: {
+ radius: 20,
+ opacity: 1,
+ allowHover: true,
+ showNeighborOnHover: true,
+ showHighlightColor: false
+ }
+ },
+ visualChannels: {
+ colorField: {
+ name: 'count',
+ type: 'integer'
+ },
+ colorScale: 'quantile'
+ }
+ }
+ ]
+ }
+ }
+};
+export default data;
diff --git a/src/components/src/common/field-selector.tsx b/src/components/src/common/field-selector.tsx
index 8da962069..92e8f7df0 100644
--- a/src/components/src/common/field-selector.tsx
+++ b/src/components/src/common/field-selector.tsx
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
+import classnames from 'classnames';
import React, {Component, ComponentType} from 'react';
import styled from 'styled-components';
import {createSelector} from 'reselect';
@@ -25,7 +26,12 @@ const StyledFieldListItem = styled.div`
flex-direction: row;
align-items: center;
`;
-
+const StyledFieldSelector = styled.div`
+ .item-selector__dropdown {
+ // smaller padding on the side to accomodate field token
+ padding: 0 6px;
+ }
+`;
export type FieldListItemFactoryProps = {
value: Field;
displayOption: (field: Field) => string;
@@ -97,6 +103,7 @@ interface FieldSelectorFactoryProps {
CustomChickletComponent?: ComponentType<any>;
size?: string;
reorderItems?: (newOrder: any) => void;
+ className?: string;
}
function noop() {
return;
@@ -164,7 +171,7 @@ function FieldSelectorFactory(
render() {
return (
- <div className="field-selector">
+ <StyledFieldSelector className={classnames('field-selector', this.props.className)}>
<ItemSelector
getOptionValue={d => d}
closeOnSelect={this.props.closeOnSelect}
@@ -187,7 +194,7 @@ function FieldSelectorFactory(
DropdownHeaderComponent={this.props.suggested ? SuggestedFieldHeader : null}
CustomChickletComponent={this.props.CustomChickletComponent}
/>
- </div>
+ </StyledFieldSelector>
);
}
}
diff --git a/src/components/src/side-panel/layer-panel/column-selector.tsx b/src/components/src/side-panel/layer-panel/column-selector.tsx
index 1a1364d02..09188f72e 100644
--- a/src/components/src/side-panel/layer-panel/column-selector.tsx
+++ b/src/components/src/side-panel/layer-panel/column-selector.tsx
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import React from 'react';
+import React, {useMemo, ReactNode} from 'react';
import styled from 'styled-components';
import {FormattedMessage} from '@kepler.gl/localization';
import {PanelLabel} from '../../common/styled-components';
@@ -25,6 +25,7 @@ export type ColumnSelectorProps<FieldOption extends MinimalField> = {
| null
) => void;
fieldPairs: EnhancedFieldPair[] | null;
+ isActive?: boolean;
};
const ColumnRow = styled.div`
@@ -34,17 +35,23 @@ const ColumnRow = styled.div`
`;
const ColumnName = styled.div`
- width: 27%;
+ width: 32%;
line-height: 1.2;
padding-right: 6px;
`;
const ColumnSelect = styled.div`
- width: 73%;
+ width: 68%;
`;
ColumnSelectorFactory.deps = [FieldSelectorFactory];
+const ColumnPanelLabel = styled(PanelLabel).attrs<{children: ReactNode}>({
+ className: 'side-panel-subpanel__label'
+})`
+ font-size: 10px;
+`;
+
function ColumnSelectorFactory(FieldSelector: ReturnType<typeof FieldSelectorFactory>) {
const ColumnSelector: React.FC<ColumnSelectorProps<any>> = ({
column,
@@ -52,27 +59,34 @@ function ColumnSelectorFactory(FieldSelector: ReturnType<typeof FieldSelectorFac
label,
allFields,
onSelect,
- fieldPairs
- }) => (
- <ColumnRow className="layer-config__column__selector">
- <ColumnName className="layer-config__column__name">
- <PanelLabel>
- <FormattedMessage id={`columns.${label}`} />
- {!column.optional ? ` *` : null}
- </PanelLabel>
- </ColumnName>
- <ColumnSelect className="layer-config__column__select">
- <FieldSelector
- suggested={fieldPairs}
- error={!validateColumn(column, columns, allFields)}
- fields={allFields}
- value={column.value}
- erasable={Boolean(column.optional)}
- onSelect={onSelect}
- />
- </ColumnSelect>
- </ColumnRow>
- );
+ fieldPairs,
+ isActive = true
+ }) => {
+ const isError = useMemo(
+ () => isActive && !validateColumn(column, columns, allFields),
+ [isActive, column, columns, allFields]
+ );
+ return (
+ <ColumnRow className="layer-config__column__selector">
+ <ColumnName className="layer-config__column__name">
+ <ColumnPanelLabel>
+ <FormattedMessage id={`columns.${label}`} />
+ {!column.optional ? ` *` : null}
+ </ColumnPanelLabel>
+ </ColumnName>
+ <ColumnSelect className="layer-config__column__select">
+ <FieldSelector
+ suggested={fieldPairs as any}
+ error={isError}
+ fields={allFields}
+ value={column.value}
+ erasable
+ onSelect={onSelect}
+ />
+ </ColumnSelect>
+ </ColumnRow>
+ );
+ };
return ColumnSelector;
}
diff --git a/src/components/src/side-panel/layer-panel/layer-column-config.tsx b/src/components/src/side-panel/layer-panel/layer-column-config.tsx
index 704011430..156097ce5 100644
--- a/src/components/src/side-panel/layer-panel/layer-column-config.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-column-config.tsx
@@ -27,6 +27,7 @@ export type LayerColumnConfigProps<FieldOption extends MinimalField> = {
columnPairs?: ColumnPairs | null;
fieldPairs?: FieldPair[];
columnLabels: ColumnLabels | null;
+ isActive: boolean;
};
/**
@@ -61,7 +62,8 @@ function LayerColumnConfigFactory(ColumnSelector: ReturnType<typeof ColumnSelect
fields,
updateLayerConfig,
assignColumn,
- assignColumnPairs
+ assignColumnPairs,
+ isActive
}) => {
const enhancedFieldPairs: EnhancedFieldPair[] | null = useMemo(
() =>
@@ -109,6 +111,7 @@ function LayerColumnConfigFactory(ColumnSelector: ReturnType<typeof ColumnSelect
key
)}
onSelect={val => onUpdateColumn(key, val)}
+ isActive={isActive}
/>
))}
</div>
diff --git a/src/components/src/side-panel/layer-panel/layer-column-mode-config.tsx b/src/components/src/side-panel/layer-panel/layer-column-mode-config.tsx
index 1ebc0294a..db4e951c8 100644
--- a/src/components/src/side-panel/layer-panel/layer-column-mode-config.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-column-mode-config.tsx
@@ -15,7 +15,7 @@ import {MinimalField} from '../../common/field-selector';
import PanelHeaderActionFactory from '../panel-header-action';
import LayerColumnConfigFactory from './layer-column-config';
import {FormattedMessage} from '@kepler.gl/localization';
-import {assignColumnsByColumnMode, Layer, LayerInfoModal, LayerBaseConfig} from '@kepler.gl/layers';
+import {Layer, LayerInfoModal, LayerBaseConfig} from '@kepler.gl/layers';
import {SupportedColumnMode, FieldPair, LayerColumns} from '@kepler.gl/types';
import {Help} from '../../common/icons';
@@ -79,15 +79,22 @@ const ConfigPanesContainer = styled.div`
interface FieldOption extends MinimalField {
fieldIdx: number;
}
-
+type ColumnModeConfig = {
+ key: string;
+ label: string;
+ columns: LayerColumns;
+};
export type ColumnModeConfigProps = {
supportedColumnModes: SupportedColumnMode[] | null;
selectedColumnMode?: string;
id: string;
columns: LayerColumns;
- renderColumnConfig: (mode: {key: string; label: string; columns: any}) => JSX.Element;
- selectColumnMode: (mode: SupportedColumnMode) => void;
- getHelpHandler?: (mode: SupportedColumnMode) => (() => void) | null;
+ renderColumnConfig: (
+ mode: {key: string; label: string; columns: any},
+ selected: boolean
+ ) => JSX.Element;
+ selectColumnMode: (mode: ColumnModeConfig) => void;
+ getHelpHandler?: (mode: ColumnModeConfig) => (() => void) | null;
};
ColumnModeConfigFactory.deps = [PanelHeaderActionFactory];
@@ -136,10 +143,12 @@ export function ColumnModeConfigFactory(
) : null}
<ConfigPanesContainer>
{columnModes.map((modeConfig, i) => {
- const columnPanel = renderColumnConfig(modeConfig);
+ const {key: columnMode, label} = modeConfig;
+
+ const isSelected = selectedColumnMode === columnMode || columnModes.length === 1;
+ const columnPanel = renderColumnConfig(modeConfig, isSelected);
const helpHandler = getHelpHandler(modeConfig);
const selectColumnModeHandler = () => selectColumnMode(modeConfig);
- const {key: columnMode, label} = modeConfig;
return (
<Fragment key={columnMode}>
@@ -155,7 +164,7 @@ export function ColumnModeConfigFactory(
<Checkbox
type="radio"
name={`layer-${id}-input-modes`}
- checked={selectedColumnMode === columnMode}
+ checked={isSelected}
id={`${id}-input-column-${columnMode}`}
label={label}
onChange={selectColumnModeHandler}
@@ -222,19 +231,13 @@ function LayerColumnModeConfigFactory(
const selectColumnMode = useCallback(
({key: columnMode}) => {
- const updatedColumns = assignColumnsByColumnMode({
- columns,
- supportedColumnModes,
- columnMode
- });
-
- updateLayerConfig({columnMode, columns: updatedColumns});
+ updateLayerConfig({columnMode});
},
- [updateLayerConfig, columns, supportedColumnModes]
+ [updateLayerConfig]
);
const renderColumnConfig = useCallback(
- ({key: columnMode, label, columns: cols}) => (
+ ({key: columnMode, label, columns: cols}, isSelected) => (
<LayerColumnConfig
columnPairs={layer.columnPairs}
columns={cols}
@@ -243,7 +246,15 @@ function LayerColumnModeConfigFactory(
columnLabels={layer.columnLabels}
fields={fields}
fieldPairs={fieldPairs}
- updateLayerConfig={updateLayerConfig}
+ updateLayerConfig={config =>
+ updateLayerConfig({
+ ...config,
+ // if column mode not currently selected
+ // set column mode along with the columns
+ ...(!isSelected && columnMode !== 'defaut' ? {columnMode} : {})
+ })
+ }
+ isActive={isSelected}
/>
),
[layer, updateLayerConfig, fieldPairs, fields]
diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
index efb732b0b..c9993adb8 100644
--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx
+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx
@@ -263,6 +263,21 @@ export default function LayerConfiguratorFactory(
updateLayerTextLabel={this.props.updateLayerTextLabel}
textLabel={layer.config.textLabel}
/>
+
+ {/* Interaction */}
+ <LayerConfigGroup label={'layer.interaction'} collapsible>
+ <VisConfigSwitch {...layer.visConfigSettings.allowHover} {...visConfiguratorProps} />
+ <ConfigGroupCollapsibleContent>
+ <VisConfigSwitch
+ {...layer.visConfigSettings.showNeighborOnHover}
+ {...visConfiguratorProps}
+ />
+ <VisConfigSwitch
+ {...layer.visConfigSettings.showHighlightColor}
+ {...visConfiguratorProps}
+ />
+ </ConfigGroupCollapsibleContent>
+ </LayerConfigGroup>
</StyledLayerVisualConfigurator>
);
}
diff --git a/src/constants/src/layers.ts b/src/constants/src/layers.ts
index c3252a40a..365b10675 100644
--- a/src/constants/src/layers.ts
+++ b/src/constants/src/layers.ts
@@ -25,7 +25,8 @@ export const PROPERTY_GROUPS = keyMirror({
// for heatmap aggregation
cell: null,
precision: null,
- display: null
+ display: null,
+ interaction: null
});
export const DEFAULT_LAYER_OPACITY = 0.8;
@@ -451,6 +452,27 @@ export const LAYER_VIS_CONFIGS: LayerVisConfigSettings = {
label: 'layerVisConfigs.darkModeEnabled',
property: 'darkBaseMapEnabled',
group: PROPERTY_GROUPS.display
+ },
+ allowHover: {
+ type: 'boolean',
+ defaultValue: true,
+ label: 'layerVisConfigs.allowHover',
+ group: PROPERTY_GROUPS.interaction,
+ property: 'allowHover'
+ },
+ showNeighborOnHover: {
+ type: 'boolean',
+ defaultValue: false,
+ label: 'layerVisConfigs.showNeighborOnHover',
+ group: PROPERTY_GROUPS.interaction,
+ property: 'showNeighborOnHover'
+ },
+ showHighlightColor: {
+ type: 'boolean',
+ defaultValue: true,
+ label: 'layerVisConfigs.showHighlightColor',
+ group: PROPERTY_GROUPS.interaction,
+ property: 'showHighlightColor'
}
};
diff --git a/src/layers/src/arc-layer/arc-layer.ts b/src/layers/src/arc-layer/arc-layer.ts
index 7a7f1b1ef..f1bdc226c 100644
--- a/src/layers/src/arc-layer/arc-layer.ts
+++ b/src/layers/src/arc-layer/arc-layer.ts
@@ -5,10 +5,12 @@ import Layer, {
LayerBaseConfig,
LayerColorConfig,
LayerSizeConfig,
- LayerBounds
+ LayerBounds,
+ LayerBaseConfigPartial
} from '../base-layer';
import {BrushingExtension} from '@deck.gl/extensions';
import {ArcLayer as DeckArcLayer} from '@deck.gl/layers';
+import {h3ToGeo} from 'h3-js';
import {hexToRgb, DataContainerInterface} from '@kepler.gl/utils';
import ArcLayerIcon from './arc-layer-icon';
@@ -38,10 +40,16 @@ export type ArcLayerVisConfigSettings = {
};
export type ArcLayerColumnsConfig = {
+ // COLUMN_MODE_POINTS required columns
lat0: LayerColumn;
lat1: LayerColumn;
lng0: LayerColumn;
lng1: LayerColumn;
+
+ // COLUMN_MODE_NEIGHBORS required columns
+ lat: LayerColumn;
+ lng: LayerColumn;
+ neighbors: LayerColumn;
};
export type ArcLayerVisConfig = {
@@ -68,25 +76,16 @@ export type ArcLayerData = {
export type ArcLayerMeta = {
bounds: LayerBounds;
};
-export const arcPosAccessor =
- ({lat0, lng0, lat1, lng1}: ArcLayerColumnsConfig) =>
- (dc: DataContainerInterface) =>
- d =>
- [
- dc.valueAt(d.index, lng0.fieldIdx),
- dc.valueAt(d.index, lat0.fieldIdx),
- 0,
- dc.valueAt(d.index, lng1.fieldIdx),
- dc.valueAt(d.index, lat1.fieldIdx),
- 0
- ];
export const arcRequiredColumns = ['lat0', 'lng0', 'lat1', 'lng1'];
+export const neighborRequiredColumns = ['lat', 'lng', 'neighbors'];
+
export const arcColumnLabels = {
lat0: 'arc.lat0',
lng0: 'arc.lng0',
lat1: 'arc.lat1',
- lng1: 'arc.lng1'
+ lng1: 'arc.lng1',
+ neighbors: 'neighbors'
};
export const arcVisConfigs: {
@@ -103,6 +102,83 @@ export const arcVisConfigs: {
targetColor: 'targetColor'
};
+export const COLUMN_MODE_POINTS = 'points';
+export const COLUMN_MODE_NEIGHBORS = 'neighbors';
+const SUPPORTED_COLUMN_MODES = [
+ {
+ key: COLUMN_MODE_POINTS,
+ label: 'Points',
+ requiredColumns: arcRequiredColumns
+ },
+ {
+ key: COLUMN_MODE_NEIGHBORS,
+ label: 'Point and Neighbors',
+ requiredColumns: neighborRequiredColumns
+ }
+];
+const DEFAULT_COLUMN_MODE = COLUMN_MODE_POINTS;
+
+export function getPositionFromHexValue(token) {
+ const pos = h3ToGeo(token);
+
+ if (Array.isArray(pos) && pos.every(Number.isFinite)) {
+ return [pos[1], pos[0]];
+ }
+ return null;
+}
+
+function maybeHexToGeo(
+ dc: DataContainerInterface,
+ d: {index: number},
+ lat: LayerColumn,
+ lng: LayerColumn
+) {
+ // lat or lng column could be hex column
+ // we assume string value is hex and try to convert it to geo lat lng
+ const latVal = dc.valueAt(d.index, lat.fieldIdx);
+ const lngVal = dc.valueAt(d.index, lng.fieldIdx);
+
+ return typeof latVal === 'string'
+ ? getPositionFromHexValue(latVal)
+ : typeof lngVal === 'string'
+ ? getPositionFromHexValue(lngVal)
+ : null;
+}
+
+function isOtherFieldString(columns, allFields, key) {
+ const field = allFields[columns[key].fieldIdx];
+ return field && field.type === 'string';
+}
+export const arcPosAccessor =
+ ({lat0, lng0, lat1, lng1, lat, lng}: ArcLayerColumnsConfig, columnMode) =>
+ (dc: DataContainerInterface) => {
+ if (columnMode === COLUMN_MODE_POINTS) {
+ return d => {
+ // lat or lng column could be hex column
+ // we assume string value is hex and try to convert it to geo lat lng
+ const startPos = maybeHexToGeo(dc, d, lat0, lng0);
+ const endPos = maybeHexToGeo(dc, d, lat1, lng1);
+ return [
+ startPos ? startPos[0] : dc.valueAt(d.index, lng0.fieldIdx),
+ startPos ? startPos[1] : dc.valueAt(d.index, lat0.fieldIdx),
+ 0,
+ endPos ? endPos[0] : dc.valueAt(d.index, lng1.fieldIdx),
+ endPos ? endPos[1] : dc.valueAt(d.index, lat1.fieldIdx),
+ 0
+ ];
+ };
+ }
+ return d => {
+ const startPos = maybeHexToGeo(dc, d, lat, lng);
+ // only return source point if columnMode is COLUMN_MODE_NEIGHBORS
+
+ return [
+ startPos ? startPos[0] : dc.valueAt(d.index, lng.fieldIdx),
+ startPos ? startPos[1] : dc.valueAt(d.index, lat.fieldIdx),
+ 0
+ ];
+ };
+ };
export default class ArcLayer extends Layer {
declare visConfigSettings: ArcLayerVisConfigSettings;
declare config: ArcLayerConfig;
@@ -113,7 +189,7 @@ export default class ArcLayer extends Layer {
this.registerVisConfig(arcVisConfigs);
this.getPositionAccessor = (dataContainer: DataContainerInterface) =>
- arcPosAccessor(this.config.columns)(dataContainer);
+ arcPosAccessor(this.config.columns, this.config.columnMode)(dataContainer);
}
get type() {
@@ -128,11 +204,7 @@ export default class ArcLayer extends Layer {
return ArcLayerIcon;
}
- get requiredLayerColumns() {
- return arcRequiredColumns;
- }
-
- get columnLabels() {
+ get columnLabels(): Record<string, string> {
return arcColumnLabels;
}
@@ -140,6 +212,10 @@ export default class ArcLayer extends Layer {
return this.defaultLinkColumnPairs;
}
+ get supportedColumnModes() {
+ return SUPPORTED_COLUMN_MODES;
+ }
+
get visualChannels() {
return {
sourceColor: {
@@ -164,6 +240,33 @@ export default class ArcLayer extends Layer {
};
}
+ get columnValidators() {
+ // if one of the lat or lng column is string type, we allow it
+ // will try to pass it as hex
+ return {
+ lat0: (column, columns, allFields) => isOtherFieldString(columns, allFields, 'lng0'),
+ lng0: (column, columns, allFields) => isOtherFieldString(columns, allFields, 'lat0'),
+ lat1: (column, columns, allFields) => isOtherFieldString(columns, allFields, 'lng1'),
+ lng1: (column, columns, allFields) => isOtherFieldString(columns, allFields, 'lat1'),
+ lat: (column, columns, allFields) => isOtherFieldString(columns, allFields, 'lng'),
+ lng: (column, columns, allFields) => isOtherFieldString(columns, allFields, 'lat')
+ };
+ }
+
+ hasAllColumns() {
+ const {columns} = this.config;
+ if (this.config.columnMode === COLUMN_MODE_POINTS) {
+ // TODO - this does not have access to allFields...
+ // So we can't do the same validation as for the field errors
+ const hasStart = this.hasColumnValue(columns.lat0) || this.hasColumnValue(columns.lng0);
+ const hasEnd = this.hasColumnValue(columns.lat1) || this.hasColumnValue(columns.lng1);
+ return hasStart && hasEnd;
+ }
+ const hasStart = this.hasColumnValue(columns.lat) || this.hasColumnValue(columns.lng);
+ const hasNeibors = this.hasColumnValue(columns.neighbors);
+ return hasStart && hasNeibors;
+ }
+
static findDefaultLayerProps({fieldPairs = []}: KeplerTable): {
props: {color?: RGBColor; columns: ArcLayerColumnsConfig; label: string}[];
} {
@@ -175,25 +278,38 @@ export default class ArcLayer extends Layer {
color: RGBColor;
columns: ArcLayerColumnsConfig;
label: string;
- isVisible: boolean;
} = {
color: hexToRgb(DEFAULT_LAYER_COLOR.tripArc),
// connect the first two point layer with arc
+ // @ts-expect-error separate types for point / neighbor columns
columns: {
lat0: fieldPairs[0].pair.lat,
lng0: fieldPairs[0].pair.lng,
lat1: fieldPairs[1].pair.lat,
lng1: fieldPairs[1].pair.lng
},
- label: `${fieldPairs[0].defaultName} -> ${fieldPairs[1].defaultName} arc`,
- // set initial visiblity to false, because arcs tend to be too musy
- isVisible: false
+ label: `${fieldPairs[0].defaultName} -> ${fieldPairs[1].defaultName} arc`
};
return {props: [props]};
}
- calculateDataAttribute({filteredIndex}, getPosition) {
+ getDefaultLayerConfig(props: LayerBaseConfigPartial) {
+ const defaultLayerConfig = super.getDefaultLayerConfig(props);
+
+ return {
+ ...defaultLayerConfig,
+ columnMode: props?.columnMode ?? DEFAULT_COLUMN_MODE
+ };
+ }
+
+ calculateDataAttributeForPoints(
+ {
+ dataContainer,
+ filteredIndex
+ }: {dataContainer: DataContainerInterface; filteredIndex: number[]},
+ getPosition
+ ) {
const data: ArcLayerData[] = [];
for (let i = 0; i < filteredIndex.length; i++) {
const index = filteredIndex[i];
@@ -209,10 +325,56 @@ export default class ArcLayer extends Layer {
});
}
}
+ return data;
+ }
+
+ calculateDataAttributeForPointNNeighbors(
+ {
+ dataContainer,
+ filteredIndex
+ }: {dataContainer: DataContainerInterface; filteredIndex: number[]},
+ getPosition
+ ) {
+ const data: {index: number; sourcePosition: number[]; targetPosition: number[]}[] = [];
+ for (let i = 0; i < filteredIndex.length; i++) {
+ const index = filteredIndex[i];
+ const pos = getPosition({index});
+ // if doesn't have point lat or lng, do not add the point
+ // deck.gl can't handle position = null
+ if (pos.every(Number.isFinite)) {
+ // push all neibors
+ const neighborIdx = this.config.columns.neighbors.value
+ ? dataContainer.valueAt(index, this.config.columns.neighbors.fieldIdx)
+ : [];
+ if (Array.isArray(neighborIdx)) {
+ neighborIdx.forEach(idx => {
+ // TODO prevent row materialization here
+ const tPos = dataContainer.rowAsArray(idx) ? getPosition({index: idx}) : null;
+ if (tPos && tPos.every(Number.isFinite)) {
+ data.push({
+ index,
+ sourcePosition: [pos[0], pos[1], pos[2]],
+ targetPosition: [tPos[0], tPos[1], tPos[2]]
+ });
+ }
+ });
+ }
+ }
+ }
return data;
}
+ calculateDataAttribute({dataContainer, filteredIndex}: KeplerTable, getPosition) {
+ if (this.config.columnMode === COLUMN_MODE_POINTS) {
+ return this.calculateDataAttributeForPoints({dataContainer, filteredIndex}, getPosition);
+ }
+ return this.calculateDataAttributeForPointNNeighbors(
+ {dataContainer, filteredIndex},
+ getPosition
+ );
+ }
+
formatLayerData(datasets, oldLayerData) {
if (this.config.dataId === null) {
return {};
@@ -236,10 +398,17 @@ export default class ArcLayer extends Layer {
const pos = getPosition(d);
return [pos[0], pos[1]];
});
- const tBounds = this.getPointsBounds(dataContainer, d => {
- const pos = getPosition(d);
- return [pos[3], pos[4]];
- });
+
+ let tBounds: number[] | null = [];
+ if (this.config.columnMode === COLUMN_MODE_POINTS) {
+ tBounds = this.getPointsBounds(dataContainer, d => {
+ const pos = getPosition(d);
+ return [pos[3], pos[4]];
+ });
+ } else {
+ // when columnMode is neighbors, it reference the same collection of points
+ tBounds = sBounds;
+ }
const bounds =
tBounds && sBounds
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index 831e0083f..b9b2e4544 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -10,7 +10,6 @@ import {TextLayer} from '@deck.gl/layers';
import DefaultLayerIcon from './default-layer-icon';
import {diffUpdateTriggers} from './layer-update';
-import {assignColumnsByColumnMode} from './layer-utils';
import {
ALL_FIELD_TYPES,
@@ -367,10 +366,17 @@ class Layer {
*/
get defaultLinkColumnPairs(): ColumnPairs {
return {
+ lat: {pair: ['lng', 'alt'], fieldPairKey: 'lat'},
+ lng: {pair: ['lat', 'alt'], fieldPairKey: 'lng'},
+ alt: {pair: ['lng', 'lat'], fieldPairKey: 'altitude'},
+
lat0: {pair: 'lng0', fieldPairKey: 'lat'},
lng0: {pair: 'lat0', fieldPairKey: 'lng'},
+ alt0: {pair: ['lng0', 'lat0'], fieldPairKey: 'altitude'},
+
lat1: {pair: 'lng1', fieldPairKey: 'lat'},
- lng1: {pair: 'lat1', fieldPairKey: 'lng'}
+ lng1: {pair: 'lat1', fieldPairKey: 'lng'},
+ alt1: {pair: ['lng1', 'lat1'], fieldPairKey: 'altitude'}
};
}
@@ -794,11 +800,7 @@ class Layer {
const columns = {...required, ...optional};
- return assignColumnsByColumnMode({
- columns,
- supportedColumnModes: this.supportedColumnModes,
- columnMode: this.config.columnMode
- });
+ return columns;
}
updateLayerConfig<LayerConfig extends LayerBaseConfig = LayerBaseConfig>(
@@ -933,18 +935,31 @@ class Layer {
this.updateLayerVisConfig({[prop]: update});
}
}
-
+ hasColumnValue(column?: LayerColumn) {
+ return Boolean(column && column.value && column.fieldIdx > -1);
+ }
+ hasRequiredColumn(column?: LayerColumn) {
+ return Boolean(column && (column.optional || this.hasColumnValue(column)));
+ }
/**
* Check whether layer has all columns
* @returns yes or no
*/
hasAllColumns(): boolean {
- const {columns} = this.config;
- return (
+ const {columns, columnMode} = this.config;
+ // if layer has different column mode, check if have all required columns of current column Mode
+ if (columnMode) {
+ const currentColumnModes = (this.supportedColumnModes || []).find(
+ colMode => colMode.key === columnMode
+ );
+ return Boolean(
+ currentColumnModes !== undefined &&
+ currentColumnModes.requiredColumns?.every(colKey => this.hasColumnValue(columns[colKey]))
+ );
+ }
+ return Boolean(
columns &&
- Object.values(columns).every((column?: LayerColumn) => {
- return Boolean(column && (column.optional || (column.value && column.fieldIdx > -1)));
- })
+ Object.values(columns).every((column?: LayerColumn) => this.hasRequiredColumn(column))
);
}
diff --git a/src/layers/src/geojson-layer/geojson-layer.ts b/src/layers/src/geojson-layer/geojson-layer.ts
index 0ad0eefcf..568692e77 100644
--- a/src/layers/src/geojson-layer/geojson-layer.ts
+++ b/src/layers/src/geojson-layer/geojson-layer.ts
@@ -24,13 +24,13 @@ import {
GeojsonDataMaps,
DeckGlGeoTypes,
detectTableColumns,
- COLUMN_MODE_GEOJSON
+ COLUMN_MODE_GEOJSON,
+ applyFiltersToTableColumns
} from './geojson-utils';
import {
getGeojsonLayerMetaFromArrow,
isLayerHoveredFromArrow,
- getHoveredObjectFromArrow,
- assignColumnsByColumnMode
+ getHoveredObjectFromArrow
} from '../layer-utils';
import GeojsonLayerIcon from './geojson-layer-icon';
import {
@@ -429,8 +429,10 @@ export default class GeoJsonLayer extends Layer {
return null;
}
- calculateDataAttribute({dataContainer, filteredIndex}) {
+ calculateDataAttribute(dataset: KeplerTable, getPosition) {
+ const {dataContainer, filteredIndex} = dataset;
if (dataContainer instanceof ArrowDataContainer) {
+ // TODO add columnMode logic here for ArrowDataContainer?
// filter geojson/arrow table by values and make a partial copy of the raw table are expensive
// so we will use filteredIndex to create an attribute e.g. filteredIndex [0|1] for GPU filtering
// in deck.gl layer, see: FilterArrowExtension in @kepler.gl/deckgl-layers
@@ -454,7 +456,17 @@ export default class GeoJsonLayer extends Layer {
}
// for geojson, this should work as well and more efficient. But we need to update some test cases e.g. #GeojsonLayer -> formatLayerData
- return filteredIndex.map(i => this.dataToFeature[i]).filter(d => d);
+ switch (this.config.columnMode) {
+ case COLUMN_MODE_GEOJSON: {
+ return filteredIndex.map(i => this.dataToFeature[i]).filter(d => d);
+ }
+
+ case COLUMN_MODE_TABLE:
+ return applyFiltersToTableColumns(dataset, this.dataToFeature);
+
+ default:
+ return [];
+ }
}
formatLayerData(datasets, oldLayerData) {
@@ -557,14 +569,8 @@ export default class GeoJsonLayer extends Layer {
// find columns from lat, lng, id, and ts
const columnConfig = detectTableColumns(dataset, this.config.columns, 'sortBy');
if (columnConfig) {
- const columns = assignColumnsByColumnMode({
- columns: columnConfig.columns,
- supportedColumnModes: this.supportedColumnModes,
- columnMode: COLUMN_MODE_TABLE
- });
this.updateLayerConfig({
...columnConfig,
- columns,
columnMode: COLUMN_MODE_TABLE
});
}
diff --git a/src/layers/src/geojson-layer/geojson-utils.ts b/src/layers/src/geojson-layer/geojson-utils.ts
index d728b9194..7a20ec6c2 100644
--- a/src/layers/src/geojson-layer/geojson-utils.ts
+++ b/src/layers/src/geojson-layer/geojson-utils.ts
@@ -16,8 +16,8 @@ import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
import {LayerColumns} from '@kepler.gl/types';
import {KeplerTable} from '@kepler.gl/table';
-import {LayerBaseConfig} from '../base-layer';
import {GeojsonLayerMetaProps, assignPointPairToLayerColumn} from '../layer-utils';
+import {LayerBaseConfig} from '../base-layer';
export type GetFeature = (d: any) => Feature;
export type GeojsonDataMaps = (Feature | BinaryFeatureCollection | null)[];
@@ -378,3 +378,40 @@ export function detectTableColumns(
return null;
}
+
+export function applyFiltersToTableColumns(
+ dataset: KeplerTable,
+ dataToFeature: GeojsonDataMaps
+): GeojsonDataMaps {
+ const {dataContainer, filteredIndex} = dataset;
+ if (filteredIndex.length === dataContainer.numRows()) {
+ // Only apply the filtering when something is to be filtered out
+ return dataToFeature;
+ }
+
+ const filteredIndexSet = new Set(filteredIndex);
+ const filteredFeatures: GeojsonDataMaps = [];
+ for (const feature of dataToFeature) {
+ // @ts-expect-error geometry.coordinates not available for GeometryCollection
+ const filteredCoords = feature.geometry.coordinates.filter(c =>
+ filteredIndexSet.has(c.datumIndex)
+ );
+ if (filteredCoords.length > 0 && feature) {
+ filteredFeatures.push({
+ ...feature,
+ geometry: {
+ // @ts-expect-error BinaryFeatureCollection
+ ...feature.geometry,
+ coordinates: filteredCoords
+ },
+ properties: {
+ // @ts-expect-error BinaryFeatureCollection
+ ...feature.properties,
+ // @ts-expect-error BinaryFeatureCollection
+ values: feature.geometry.coordinates.map(c => dataContainer.rowAsArray(c.datumIndex))
+ }
+ });
+ }
+ }
+ return filteredFeatures;
+}
diff --git a/src/layers/src/layer-utils.ts b/src/layers/src/layer-utils.ts
index 380ee758e..bf1b8d04a 100644
--- a/src/layers/src/layer-utils.ts
+++ b/src/layers/src/layer-utils.ts
@@ -3,7 +3,7 @@
import * as arrow from 'apache-arrow';
import {Feature, BBox} from 'geojson';
-import {Field, FieldPair, SupportedColumnMode, LayerColumns} from '@kepler.gl/types';
+import {Field, FieldPair, SupportedColumnMode} from '@kepler.gl/types';
import {DataContainerInterface} from '@kepler.gl/utils';
import {
getBinaryGeometriesFromArrow,
@@ -140,33 +140,3 @@ export function getColumnModeRequiredColumns(
): string[] | undefined {
return supportedColumnModes?.find(({key}) => key === columnMode)?.requiredColumns;
}
-
-/**
- * Assign column optional prop based on column mode
- */
-export function assignColumnsByColumnMode({
- columns,
- supportedColumnModes,
- columnMode
-}: {
- columns: LayerColumns;
- supportedColumnModes: SupportedColumnMode[] | null;
- columnMode: string | undefined;
-}): LayerColumns {
- const requiredColumns = getColumnModeRequiredColumns(supportedColumnModes, columnMode);
-
- if (requiredColumns) {
- return Object.entries(columns).reduce(
- (acc, [columnKey, column]) => ({
- ...acc,
- [columnKey]: {
- ...column,
- optional: !requiredColumns?.includes(columnKey)
- }
- }),
- {}
- );
- }
-
- return columns;
-}
diff --git a/src/layers/src/line-layer/line-layer.ts b/src/layers/src/line-layer/line-layer.ts
index 1c6f995f2..102027770 100644
--- a/src/layers/src/line-layer/line-layer.ts
+++ b/src/layers/src/line-layer/line-layer.ts
@@ -29,12 +29,19 @@ export type LineLayerVisConfigSettings = {
};
export type LineLayerColumnsConfig = {
+ // COLUMN_MODE_POINTS required columns
lat0: LayerColumn;
lng0: LayerColumn;
lat1: LayerColumn;
lng1: LayerColumn;
alt0?: LayerColumn;
alt1?: LayerColumn;
+
+ // COLUMN_MODE_NEIGHBORS required columns
+ lat: LayerColumn;
+ lng: LayerColumn;
+ alt: LayerColumn;
+ neighbors: LayerColumn;
};
export type LineLayerVisConfig = {
@@ -51,19 +58,6 @@ export type LineLayerConfig = Merge<
{columns: LineLayerColumnsConfig; visConfig: LineLayerVisConfig}
>;
-export const linePosAccessor =
- ({lat0, lng0, lat1, lng1, alt0, alt1}: LineLayerColumnsConfig) =>
- (dc: DataContainerInterface) =>
- d =>
- [
- dc.valueAt(d.index, lng0.fieldIdx),
- dc.valueAt(d.index, lat0.fieldIdx),
- alt0 && alt0.fieldIdx > -1 ? dc.valueAt(d.index, alt0.fieldIdx) : 0,
- dc.valueAt(d.index, lng1.fieldIdx),
- dc.valueAt(d.index, lat1.fieldIdx),
- alt1 && alt1?.fieldIdx > -1 ? dc.valueAt(d.index, alt1.fieldIdx) : 0
- ];
-
export const lineRequiredColumns: ['lat0', 'lng0', 'lat1', 'lng1'] = [
'lat0',
'lng0',
@@ -71,6 +65,8 @@ export const lineRequiredColumns: ['lat0', 'lng0', 'lat1', 'lng1'] = [
'lng1'
];
export const lineOptionalColumns: ['alt0', 'alt1'] = ['alt0', 'alt1'];
+export const neighborRequiredColumns = ['lat', 'lng', 'neighbors'];
+export const neighborOptionalColumns = ['alt'];
export const lineColumnLabels = {
lat0: 'arc.lat0',
@@ -100,6 +96,44 @@ export const lineVisConfigs: {
}
};
+export const COLUMN_MODE_POINTS = 'points';
+export const COLUMN_MODE_NEIGHBORS = 'neighbors';
+const SUPPORTED_COLUMN_MODES = [
+ {
+ key: COLUMN_MODE_POINTS,
+ label: 'Points',
+ requiredColumns: lineRequiredColumns,
+ optionalColumns: lineOptionalColumns
+ },
+ {
+ key: COLUMN_MODE_NEIGHBORS,
+ label: 'Point and Neighbors',
+ requiredColumns: neighborRequiredColumns,
+ optionalColumns: neighborOptionalColumns
+ }
+];
+// const DEFAULT_COLUMN_MODE = COLUMN_MODE_POINTS;
+
+export const linePosAccessor =
+ ({lat0, lng0, lat1, lng1, alt0, alt1, lat, lng, alt}: LineLayerColumnsConfig, columnMode) =>
+ (dc: DataContainerInterface) => {
+ return columnMode === COLUMN_MODE_POINTS
+ ? d => [
+ dc.valueAt(d.index, lng0.fieldIdx),
+ dc.valueAt(d.index, lat0.fieldIdx),
+ alt0 && alt0.fieldIdx > -1 ? dc.valueAt(d.index, alt0.fieldIdx) : 0,
+ dc.valueAt(d.index, lng1.fieldIdx),
+ dc.valueAt(d.index, lat1.fieldIdx),
+ alt1 && alt1?.fieldIdx > -1 ? dc.valueAt(d.index, alt1.fieldIdx) : 0
+ ]
+ : // only return source point if columnMode is COLUMN_MODE_NEIGHBORS
+ d => [
+ dc.valueAt(d.index, lng.fieldIdx),
+ dc.valueAt(d.index, lat.fieldIdx),
+ alt?.fieldIdx > -1 ? dc.valueAt(d.index, alt.fieldIdx) : 0
+ ];
+ };
+
export default class LineLayer extends ArcLayer {
declare visConfigSettings: LineLayerVisConfigSettings;
declare config: LineLayerConfig;
@@ -109,7 +143,7 @@ export default class LineLayer extends ArcLayer {
this.registerVisConfig(lineVisConfigs);
this.getPositionAccessor = (dataContainer: DataContainerInterface) =>
- linePosAccessor(this.config.columns)(dataContainer);
+ linePosAccessor(this.config.columns, this.config.columnMode)(dataContainer);
}
get type() {
@@ -120,16 +154,16 @@ export default class LineLayer extends ArcLayer {
return LineLayerIcon;
}
- get requiredLayerColumns() {
- return lineRequiredColumns;
+ get columnLabels() {
+ return lineColumnLabels;
}
- get optionalColumns() {
- return lineOptionalColumns;
+ get columnPairs() {
+ return this.defaultLinkColumnPairs;
}
- get columnLabels() {
- return lineColumnLabels;
+ get supportedColumnModes() {
+ return SUPPORTED_COLUMN_MODES;
}
get visualChannels() {
@@ -147,15 +181,26 @@ export default class LineLayer extends ArcLayer {
if (fieldPairs.length < 2) {
return {props: []};
}
+
+ const defaultAltColumn = {value: null, fieldIdx: -1, optional: true};
const props: {columns: LineLayerColumnsConfig; label: string; isVisible: boolean} = {
// connect the first two point layer with line
+ // TODO: fill default columns by parsing supported_column_modes
columns: {
lat0: fieldPairs[0].pair.lat,
lng0: fieldPairs[0].pair.lng,
- alt0: {value: null, fieldIdx: -1, optional: true},
+ alt0: fieldPairs[0].pair.altitude
+ ? {...defaultAltColumn, ...fieldPairs[0].pair.altitude}
+ : {...defaultAltColumn},
lat1: fieldPairs[1].pair.lat,
lng1: fieldPairs[1].pair.lng,
- alt1: {value: null, fieldIdx: -1, optional: true}
+ alt1: fieldPairs[1].pair.altitude
+ ? {...defaultAltColumn, ...fieldPairs[1].pair.altitude}
+ : {...defaultAltColumn},
+ lat: {...defaultAltColumn},
+ lng: {...defaultAltColumn},
+ alt: {...defaultAltColumn},
+ neighbors: {...defaultAltColumn}
},
label: `${fieldPairs[0].defaultName} -> ${fieldPairs[1].defaultName} line`,
isVisible: false
diff --git a/src/layers/src/point-layer/point-layer.ts b/src/layers/src/point-layer/point-layer.ts
index 3346894cb..9e9320476 100644
--- a/src/layers/src/point-layer/point-layer.ts
+++ b/src/layers/src/point-layer/point-layer.ts
@@ -51,6 +51,7 @@ export type PointLayerColumnsConfig = {
lat: LayerColumn;
lng: LayerColumn;
altitude?: LayerColumn;
+ neighbors?: LayerColumn;
};
export type PointLayerVisConfig = {
@@ -64,6 +65,9 @@ export type PointLayerVisConfig = {
strokeColorRange: ColorRange;
radiusRange: [number, number];
filled: boolean;
+ allowHover: boolean;
+ showNeighborOnHover: boolean;
+ showHighlightColor: boolean;
};
export type PointLayerVisualChannelConfig = LayerColorConfig &
LayerSizeConfig &
@@ -77,6 +81,7 @@ export type PointLayerConfig = Merge<
export type PointLayerData = {
position: number[];
index: number;
+ neighbors: any[];
};
export const pointPosAccessor =
@@ -90,7 +95,7 @@ export const pointPosAccessor =
];
export const pointRequiredColumns: ['lat', 'lng'] = ['lat', 'lng'];
-export const pointOptionalColumns: ['altitude'] = ['altitude'];
+export const pointOptionalColumns: ['altitude', 'neighbors'] = ['altitude', 'neighbors'];
const brushingExtension = new BrushingExtension();
@@ -105,6 +110,9 @@ export const pointVisConfigs: {
strokeColorRange: 'strokeColorRange';
radiusRange: 'radiusRange';
filled: VisConfigBoolean;
+ allowHover: 'allowHover';
+ showNeighborOnHover: 'showNeighborOnHover';
+ showHighlightColor: 'showHighlightColor';
} = {
radius: 'radius',
fixedRadius: 'fixedRadius',
@@ -121,7 +129,10 @@ export const pointVisConfigs: {
label: 'layer.fillColor',
defaultValue: true,
property: 'filled'
- }
+ },
+ allowHover: 'allowHover',
+ showNeighborOnHover: 'showNeighborOnHover',
+ showHighlightColor: 'showHighlightColor'
};
export default class PointLayer extends Layer {
@@ -260,11 +271,19 @@ export default class PointLayer extends Layer {
};
}
- calculateDataAttribute({filteredIndex}: KeplerTable, getPosition) {
+ calculateDataAttribute({filteredIndex, dataContainer}: KeplerTable, getPosition) {
const data: PointLayerData[] = [];
for (let i = 0; i < filteredIndex.length; i++) {
const index = filteredIndex[i];
+ let neighbors;
+
+ if (this.config.columns.neighbors?.value) {
+ const {fieldIdx} = this.config.columns.neighbors;
+ neighbors = Array.isArray(dataContainer.valueAt(index, fieldIdx))
+ ? dataContainer.valueAt(index, fieldIdx)
+ : [];
+ }
const pos = getPosition({index});
// if doesn't have point lat or lng, do not add the point
@@ -272,7 +291,9 @@ export default class PointLayer extends Layer {
if (pos.every(Number.isFinite)) {
data.push({
position: pos,
- index
+ // index is important for filter
+ index,
+ neighbors
});
}
}
@@ -315,8 +336,9 @@ export default class PointLayer extends Layer {
this.updateMeta({bounds});
}
+ // eslint-disable-next-line complexity
renderLayer(opts) {
- const {data, gpuFilter, objectHovered, mapState, interactionConfig} = opts;
+ const {data, gpuFilter, objectHovered, mapState, interactionConfig, dataset} = opts;
// if no field size is defined we need to pass fixed radius = false
const fixedRadius = this.config.visConfig.fixedRadius && Boolean(this.config.sizeField);
@@ -349,6 +371,20 @@ export default class PointLayer extends Layer {
...brushingProps
};
const hoveredObject = this.hasHoveredObject(objectHovered);
+ const {showNeighborOnHover, allowHover} = this.config.visConfig;
+ let neighborsData = [];
+ if (allowHover && showNeighborOnHover && hoveredObject) {
+ // find neighbor
+ neighborsData = (hoveredObject.neighbors || [])
+ .map(idx => ({
+ // TODO do we really need to pass data here?
+ data: dataset.dataContainer.rowAsArray(idx),
+ // position: pos,
+ // index is important for filter
+ index: idx
+ }))
+ .filter(d => d.data);
+ }
return [
new ScatterplotLayer({
@@ -362,7 +398,10 @@ export default class PointLayer extends Layer {
},
lineWidthUnits: 'pixels',
updateTriggers,
- extensions
+ extensions,
+ opacity: hoveredObject && showNeighborOnHover ? 0.2 : this.config.visConfig.opacity,
+ pickable: allowHover,
+ autoHighlight: false
}),
// hover layer
...(hoveredObject
@@ -371,9 +410,13 @@ export default class PointLayer extends Layer {
...this.getDefaultHoverLayerProps(),
...layerProps,
visible: defaultLayerProps.visible,
- data: [hoveredObject],
- getLineColor: this.config.highlightColor,
- getFillColor: this.config.highlightColor,
+ data: [...neighborsData, hoveredObject],
+ getLineColor: this.config.visConfig.showHighlightColor
+ ? this.config.highlightColor
+ : data.getLineColor,
+ getFillColor: this.config.visConfig.showHighlightColor
+ ? this.config.highlightColor
+ : data.getFillColor,
getRadius: data.getRadius,
getPosition: data.getPosition
})
diff --git a/src/layers/src/trip-layer/trip-layer.ts b/src/layers/src/trip-layer/trip-layer.ts
index 0a6fc30b3..01e8099a1 100644
--- a/src/layers/src/trip-layer/trip-layer.ts
+++ b/src/layers/src/trip-layer/trip-layer.ts
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {Feature} from 'geojson';
import memoize from 'lodash.memoize';
import uniq from 'lodash.uniq';
import Layer, {LayerBaseConfig, defaultGetFieldValue} from '../base-layer';
@@ -16,11 +15,11 @@ import {
getGeojsonFeatureTypes,
GeojsonDataMaps,
detectTableColumns,
- groupColumnsAsGeoJson
+ groupColumnsAsGeoJson,
+ applyFiltersToTableColumns
} from '../geojson-layer/geojson-utils';
import {isTripGeoJsonField, parseTripGeoJsonTimestamp} from './trip-utils';
-import {assignColumnsByColumnMode} from '../layer-utils';
import TripInfoModalFactory from './trip-info-modal';
import {bisectRight} from 'd3-array';
import {
@@ -295,44 +294,22 @@ export default class TripLayer extends Layer {
}
calculateDataAttribute(dataset: KeplerTable, getPosition) {
- if (this.config.columnMode === COLUMN_MODE_GEOJSON) {
- return dataset.filteredIndex
- .map(i => this.dataToFeature[i])
- .filter((d: unknown) => d && (d as Feature).geometry.type === 'LineString');
- }
- if (dataset.filteredIndex.length === dataset.dataContainer.numRows()) {
- // Only apply the filtering when something is to be filtered out
- return this.dataToFeature;
- }
-
- const filteredIndexSet = new Set(dataset.filteredIndex);
- const filteredFeatures: any[] = [];
- for (const feature of this.dataToFeature) {
- // @ts-expect-error fix type or expected?
- const filteredCoords = feature?.geometry.coordinates.filter(c =>
- // TODO: is it necessary to filter coords, or can we assume they are never filtered?
- filteredIndexSet.has(c.datumIndex)
- );
- if (filteredCoords.length > 0) {
- filteredFeatures.push({
- ...feature,
- geometry: {
- // @ts-expect-error fix type or expected?
- ...feature.geometry,
- coordinates: filteredCoords
- },
- properties: {
- // @ts-expect-error fix type or expected?
- ...feature.properties,
- // @ts-expect-error fix type or expected?
- values: feature.geometry.coordinates.map(c =>
- dataset.dataContainer.rowAsArray(c.datumIndex)
- )
- }
- });
+ switch (this.config.columnMode) {
+ case COLUMN_MODE_GEOJSON: {
+ return (
+ dataset.filteredIndex
+ .map(i => this.dataToFeature[i])
+ // TODO d can be BinaryFeatureCollection, fix logic
+ .filter(d => d && (d as any).geometry?.type === 'LineString')
+ );
}
+
+ case COLUMN_MODE_TABLE:
+ return applyFiltersToTableColumns(dataset, this.dataToFeature);
+
+ default:
+ return [];
}
- return filteredFeatures;
}
formatLayerData(datasets: Datasets, oldLayerData) {
@@ -418,14 +395,8 @@ export default class TripLayer extends Layer {
// find columns from lat, lng, id, and ts
const columnConfig = detectTableColumns(dataset, this.config.columns);
if (columnConfig) {
- const columns = assignColumnsByColumnMode({
- columns: columnConfig.columns,
- supportedColumnModes: this.supportedColumnModes,
- columnMode: COLUMN_MODE_TABLE
- });
this.updateLayerConfig({
...columnConfig,
- columns,
columnMode: COLUMN_MODE_TABLE
});
}
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index 64b1e6949..be09529d8 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -114,7 +114,8 @@ export default {
'3d': '3D'
},
layerUpdateError:
- 'An error occurred during layer update: {errorMessage}. Make sure the format of the input data is valid.'
+ 'An error occurred during layer update: {errorMessage}. Make sure the format of the input data is valid.',
+ interaction: 'Interaction'
},
layerVisConfigs: {
angle: 'Angle',
@@ -157,6 +158,9 @@ export default {
heightRange: 'Height Range',
fixedHeight: 'Fixed height',
fixedHeightDescription: 'Use height without modifications',
+ allowHover: 'Allow Hover',
+ showNeighborOnHover: 'Highlight Neighbors On Hover',
+ showHighlightColor: 'Show highlight Color',
heightMultiplier: 'Height Multiplier',
darkModeEnabled: 'Dark base map'
},
@@ -516,19 +520,21 @@ ${'```'}
columns: {
title: 'Columns',
lat: 'lat',
- lng: 'lon',
+ lng: 'lng',
altitude: 'altitude',
+ alt: 'altitude',
id: 'id',
timestamp: 'time',
icon: 'icon',
geojson: 'geojson',
token: 'token',
sortBy: 'sort by',
+ neighbors: 'neighbors',
arc: {
- lat0: 'source lat',
- lng0: 'source lng',
- lat1: 'target lat',
- lng1: 'target lng'
+ lat0: 'source lat or hex id',
+ lng0: 'source lng or hex id',
+ lat1: 'target lat or hex id',
+ lng1: 'target lng or hex id'
},
line: {
alt0: 'source altitude',
diff --git a/src/reducers/src/layer-utils.ts b/src/reducers/src/layer-utils.ts
index 65ae10e39..0571447c5 100644
--- a/src/reducers/src/layer-utils.ts
+++ b/src/reducers/src/layer-utils.ts
@@ -52,6 +52,7 @@ export function findDefaultLayer(dataset: KeplerTable, layerClasses: LayerClasse
if (!dataset) {
return [];
}
+
const layerProps = (Object.keys(layerClasses) as Array<keyof LayerClassesType>).reduce(
(previous, lc) => {
const result: FindDefaultLayerPropsReturnValue =
@@ -66,7 +67,9 @@ export function findDefaultLayer(dataset: KeplerTable, layerClasses: LayerClasse
props.map(p => ({
...p,
type: lc,
- dataId: dataset.id
+ dataId: dataset.id,
+ // set arc layer initial visiblity to false, because arcs tend to be too musy
+ ...(lc === 'arc' || lc === 'line' ? {isVisible: false} : {})
}))
);
},
@@ -234,7 +237,8 @@ export function renderDeckGlLayer(props: any, layerCallbacks: {[key: string]: an
mapState,
animationConfig,
objectHovered,
- visible
+ visible,
+ dataset
});
}
diff --git a/src/reducers/src/vis-state-merger.ts b/src/reducers/src/vis-state-merger.ts
index beab0b7c1..231e1a553 100644
--- a/src/reducers/src/vis-state-merger.ts
+++ b/src/reducers/src/vis-state-merger.ts
@@ -640,6 +640,9 @@ export function validateSavedLayerColumns(
return rv;
}
+/**
+ * Validate layer column
+ */
export function validateColumn(
column: LayerColumn & {validator?: typeof validateColumn},
columns: LayerColumns,
@@ -771,6 +774,37 @@ export function validateLayersByDatasets(
return {validated, failed};
}
+
+/**
+ * Get required columns for validation based on column mode
+ */
+function _getColumnConfigForValidation(newLayer) {
+ // find column fieldIdx
+ let columnConfig = newLayer.getLayerColumns();
+ // if columnMode is defined, find column mode config
+ const colModeConfig = newLayer.config.columnMode
+ ? (newLayer.supportedColumnModes || []).find(
+ colMode => colMode.key === newLayer.config.columnMode
+ )
+ : null;
+
+ if (colModeConfig) {
+ // only validate columns in column mode
+ columnConfig = [
+ ...(colModeConfig.requiredColumns || []),
+ ...(colModeConfig.optionalColumns || [])
+ ].reduce(
+ (accu, key) => ({
+ ...accu,
+ [key]: columnConfig[key]
+ }),
+ {}
+ );
+ }
+
+ return columnConfig;
+}
+
/**
* Validate saved layer config with new data,
* update fieldIdx based on new fields
@@ -804,8 +838,8 @@ export function validateLayerWithData(
highlightColor: savedLayer.config.highlightColor
});
- // find column fieldIdx
- const columnConfig = newLayer.getLayerColumns();
+ const columnConfig = _getColumnConfigForValidation(newLayer);
+
if (Object.keys(columnConfig)) {
const columns = validateSavedLayerColumns(
fields,
@@ -814,7 +848,12 @@ export function validateLayerWithData(
options
);
if (columns) {
- newLayer.updateLayerConfig({columns});
+ newLayer.updateLayerConfig({
+ columns: {
+ ...newLayer.config.columns,
+ ...columns
+ }
+ });
} else if (!options.allowEmptyColumn) {
return null;
}
diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts
index 105e8bd7d..da6173d35 100644
--- a/src/reducers/src/vis-state-updaters.ts
+++ b/src/reducers/src/vis-state-updaters.ts
@@ -651,6 +651,7 @@ export function layerDataIdChangeUpdater(
const idx = state.layers.findIndex(l => l.id === oldLayer.id);
let newLayer = oldLayer.updateLayerConfig({dataId});
+
// this may happen when a layer is new (type: null and no columns) but it's not ready to be saved
if (newLayer.isValidToSave()) {
const validated = validateExistingLayerWithData(
diff --git a/src/types/layers.d.ts b/src/types/layers.d.ts
index c2c3f47dc..1b37cf7e1 100644
--- a/src/types/layers.d.ts
+++ b/src/types/layers.d.ts
@@ -57,7 +57,7 @@ export type EnhancedFieldPair = {
export type SupportedColumnMode = {
key: string;
label: string;
- requiredColumns?: string[];
+ requiredColumns: string[];
optionalColumns?: string[];
hasHelp?: boolean;
};
@@ -259,6 +259,9 @@ export type LayerVisConfigSettings = {
heatmapRadius: VisConfigNumber;
darkBaseMapEnabled: VisConfigBoolean;
fixedHeight: VisConfigBoolean;
+ allowHover: VisConfigBoolean;
+ showNeighborOnHover: VisConfigBoolean;
+ showHighlightColor: VisConfigBoolean;
};
// TODO: Move this to individual layers
@@ -308,6 +311,7 @@ export type TextConfigSelect = {
multiSelect: boolean;
searchable: boolean;
};
+
export type TextConfigNumber = {
type: 'number';
range: number[];
@@ -317,6 +321,7 @@ export type TextConfigNumber = {
label: string;
showInput: boolean;
};
+
export type LayerTextConfig = {
fontSize: TextConfigNumber;
outlineWidth: TextConfigNumber;
diff --git a/test/browser-headless/component/map-container-test.js b/test/browser-headless/component/map-container-test.js
index 4e09965bf..5ac69eda6 100644
--- a/test/browser-headless/component/map-container-test.js
+++ b/test/browser-headless/component/map-container-test.js
@@ -143,16 +143,11 @@ test('MapContainerFactory - _renderDeckOverlay', t => {
events: [{type: 'mousemove', x: 200, y: 200}, {wait: 50}],
onBeforeEvents,
// eslint-disable-next-line max-statements
- onAfterEvents: ({layers}) => {
+ onAfterEvents: () => {
assert.is(hoverEvents.length, 1, 'onHover is called');
assert.is(hoverEvents[0].info.index, 15, 'object is picked');
assert.is(hoverEvents[0].info.picked, true, 'object is picked');
assert.is(hoverEvents[0].info.mapIndex, 0, 'onHover includes mapIndex value');
- assert.deepEqual(
- layers[0].state.model.getUniforms().picking_uSelectedColor,
- [16, 0, 0],
- 'autoHighlight parameter is set'
- );
[
// test picking info
@@ -181,6 +176,7 @@ test('MapContainerFactory - _renderDeckOverlay', t => {
// asign info object to to state and test map popover
const propsWithHoverInfo = {
...initialProps,
+ mapboxApiAccessToken: 'pyx-11',
visState: {
...initialProps.visState,
hoverInfo: hoverEvents[0].info,
diff --git a/test/browser/components/side-panel/layer-configurator-test.js b/test/browser/components/side-panel/layer-configurator-test.js
index 3242e88cd..49b26c5d8 100644
--- a/test/browser/components/side-panel/layer-configurator-test.js
+++ b/test/browser/components/side-panel/layer-configurator-test.js
@@ -160,8 +160,8 @@ test('Components -> LayerConfigurator.mount -> LayerColumnConfig', t => {
t.equal(
baseConfigGroup.find(LayerColumnConfig).at(0).find(ColumnSelector).length,
- 3,
- 'Should render 3 ColumnSelector'
+ 4,
+ 'Should render 4 ColumnSelector'
);
// open fieldSelector
@@ -213,7 +213,8 @@ test('Components -> LayerConfigurator.mount -> LayerColumnConfig', t => {
value: 'gps_data.lng',
fieldIdx: 2
},
- altitude: {value: null, fieldIdx: -1, optional: true}
+ altitude: {value: null, fieldIdx: -1, optional: true},
+ neighbors: {value: null, fieldIdx: -1, optional: true}
}
}
],
@@ -245,7 +246,8 @@ test('Components -> LayerConfigurator.mount -> LayerColumnConfig', t => {
// value: 'gps_data.lng',
// fieldIdx: 2
// },
- // altitude: {value: null, fieldIdx: -1, optional: true}
+ // altitude: {value: null, fieldIdx: -1, optional: true},
+ // neighbors: {value: null, fieldIdx: -1, optional: true}
// }
// }
// ],
@@ -351,18 +353,10 @@ test('Components -> LayerConfigurator.mount -> LayerColumnModeConfig ', t => {
updateLayerConfigSpy.args[0],
[
{
- columnMode: 'table',
- columns: {
- geojson: {value: '_geojson', fieldIdx: 0, optional: true},
- id: {value: null, fieldIdx: -1, optional: false},
- lat: {value: null, fieldIdx: -1, optional: false},
- lng: {value: null, fieldIdx: -1, optional: false},
- altitude: {value: null, fieldIdx: -1, optional: true},
- timestamp: {value: null, fieldIdx: -1, optional: false}
- }
+ columnMode: 'table'
}
],
- 'should update columnMode and columns'
+ 'should update columnMode'
);
t.end();
diff --git a/test/browser/layer-tests/arc-layer-specs.js b/test/browser/layer-tests/arc-layer-specs.js
index cd14ea920..ae4e5cd68 100644
--- a/test/browser/layer-tests/arc-layer-specs.js
+++ b/test/browser/layer-tests/arc-layer-specs.js
@@ -14,10 +14,12 @@ import {
preparedFilterDomain0,
arcLayerMeta
} from 'test/helpers/layer-utils';
-
+import testArcData, {arcFromHex, arcFromNeighbor} from 'test/fixtures/test-arc-data';
+import {StateWArcNeighbors} from 'test/helpers/mock-state';
import {PROJECTED_PIXEL_SIZE_MULTIPLIER} from '@kepler.gl/constants';
import {KeplerGlLayers} from '@kepler.gl/layers';
import {copyTableAndUpdate} from '@kepler.gl/table';
+import {h3ToGeo} from 'h3-js';
const {ArcLayer} = KeplerGlLayers;
const columns = {
@@ -285,6 +287,88 @@ test('#ArcLayer -> formatLayerData', t => {
'getFilterValue should return [value, 0, 0, 0]'
);
}
+ },
+ {
+ name: 'Arc data from neighbors',
+ layer: arcFromNeighbor,
+ datasets: StateWArcNeighbors.visState.datasets,
+ assert: result => {
+ const {layerData} = result;
+ const expectedLayerData = {
+ data: [
+ {
+ index: 0,
+ sourcePosition: [testArcData[0].longitude, testArcData[0].latitude, 0],
+ targetPosition: [testArcData[1].longitude, testArcData[1].latitude, 0]
+ },
+ {
+ index: 0,
+ sourcePosition: [testArcData[0].longitude, testArcData[0].latitude, 0],
+ targetPosition: [testArcData[2].longitude, testArcData[2].latitude, 0]
+ },
+ {
+ index: 1,
+ sourcePosition: [testArcData[1].longitude, testArcData[1].latitude, 0],
+ targetPosition: [testArcData[2].longitude, testArcData[2].latitude, 0]
+ }
+ ],
+ getFilterValue: () => {},
+ getSourceColor: () => {},
+ getTargetColor: () => {},
+ getWidth: () => {}
+ };
+ // index 18, 19 does not have valid neighbors
+ t.equal(layerData.data.length, 38, 'should format 41 rows');
+
+ for (let i = 0; i < 3; i++) {
+ t.deepEqual(
+ layerData.data[i],
+ expectedLayerData.data[i],
+ 'should format correct arc layerData data'
+ );
+ }
+ }
+ },
+ {
+ name: 'Arc data from hex',
+ layer: arcFromHex,
+ datasets: StateWArcNeighbors.visState.datasets,
+ assert: result => {
+ const {layerData} = result;
+ const expectedLayerData = {
+ data: [
+ {
+ index: 0,
+ sourcePosition: [...h3ToGeo(testArcData[0]['source hex_id']).reverse(), 0],
+ targetPosition: [...h3ToGeo(testArcData[0]['target hex_id']).reverse(), 0]
+ },
+ {
+ index: 1,
+ sourcePosition: [...h3ToGeo(testArcData[1]['source hex_id']).reverse(), 0],
+ targetPosition: [...h3ToGeo(testArcData[1]['target hex_id']).reverse(), 0]
+ },
+ {
+ index: 2,
+ sourcePosition: [...h3ToGeo(testArcData[2]['source hex_id']).reverse(), 0],
+ targetPosition: [...h3ToGeo(testArcData[2]['target hex_id']).reverse(), 0]
+ }
+ ],
+ getFilterValue: () => {},
+ getSourceColor: () => {},
+ getTargetColor: () => {},
+ getWidth: () => {}
+ };
+ // index 18, 19 does not have valid neighbors
+ t.equal(layerData.data.length, 20, 'should format 20 rows');
+
+ for (let i = 0; i < 3; i++) {
+ t.deepEqual(
+ layerData.data[i],
+ expectedLayerData.data[i],
+ 'should format correct arc layerData data'
+ );
+ }
+ }
}
];
diff --git a/test/browser/layer-tests/point-layer-specs.js b/test/browser/layer-tests/point-layer-specs.js
index 56ad5d876..f87c18145 100644
--- a/test/browser/layer-tests/point-layer-specs.js
+++ b/test/browser/layer-tests/point-layer-specs.js
@@ -15,7 +15,8 @@ import {
pointLayerMeta,
fieldDomain
} from 'test/helpers/layer-utils';
-
+import testArcData, {pointFromNeighbor} from 'test/fixtures/test-arc-data';
+import {StateWArcNeighbors} from 'test/helpers/mock-state';
import {copyTableAndUpdate} from '@kepler.gl/table';
import {KeplerGlLayers} from '@kepler.gl/layers';
import {INITIAL_MAP_STATE} from '@kepler.gl/reducers';
@@ -112,11 +113,13 @@ test('#PointLayer -> formatLayerData', t => {
data: [
{
index: 0,
- position: [testRows[0][2], testRows[0][1], testRows[0][7]]
+ position: [testRows[0][2], testRows[0][1], testRows[0][7]],
+ neighbors: undefined
},
{
index: 4,
- position: [testRows[4][2], testRows[4][1], testRows[4][7]]
+ position: [testRows[4][2], testRows[4][1], testRows[4][7]],
+ neighbors: undefined
}
],
getFilterValue: () => {},
@@ -222,11 +225,13 @@ test('#PointLayer -> formatLayerData', t => {
data: [
{
index: 0,
- position: [testRows[0][2], testRows[0][1], 0]
+ position: [testRows[0][2], testRows[0][1], 0],
+ neighbors: undefined
},
{
index: 4,
- position: [testRows[4][2], testRows[4][1], 0]
+ position: [testRows[4][2], testRows[4][1], 0],
+ neighbors: undefined
}
],
getFilterValue: () => {},
@@ -314,11 +319,13 @@ test('#PointLayer -> formatLayerData', t => {
data: [
{
index: 0,
- position: [testRows[0][2], testRows[0][1], 0]
+ position: [testRows[0][2], testRows[0][1], 0],
+ neighbors: undefined
},
{
index: 4,
- position: [testRows[4][2], testRows[4][1], 0]
+ position: [testRows[4][2], testRows[4][1], 0],
+ neighbors: undefined
}
],
getFilterValue: () => {},
@@ -397,11 +404,13 @@ test('#PointLayer -> formatLayerData', t => {
data: [
{
index: 0,
- position: [testRows[0][2], testRows[0][1], 0]
+ position: [testRows[0][2], testRows[0][1], 0],
+ neighbors: undefined
},
{
index: 4,
- position: [testRows[4][2], testRows[4][1], 0]
+ position: [testRows[4][2], testRows[4][1], 0],
+ neighbors: undefined
}
],
getFilterValue: () => {},
@@ -426,6 +435,36 @@ test('#PointLayer -> formatLayerData', t => {
// getRadius should be a constant because sizeField is null
t.equal(layerData.getRadius, 1, 'getRadius should return current radius');
}
+ },
+ {
+ name: 'Arc data from neighbors',
+ layer: pointFromNeighbor,
+ datasets: StateWArcNeighbors.visState.datasets,
+ assert: result => {
+ const {layerData} = result;
+ const expectedLayerData = {
+ data: [
+ {
+ index: 0,
+ position: [testArcData[0].longitude, testArcData[0].latitude, 0],
+ neighbors: testArcData[0].neighbors
+ },
+ {
+ index: 1,
+ position: [testArcData[1].longitude, testArcData[1].latitude, 0],
+ neighbors: testArcData[1].neighbors
+ }
+ ]
+ };
+
+ for (let i = 0; i < 2; i++) {
+ t.deepEqual(
+ layerData.data[i],
+ expectedLayerData.data[i],
+ 'should format correct point layerData data with neighbors'
+ );
+ }
+ }
}
];
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index a1c7fb694..62c5943f7 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -1047,7 +1047,10 @@ mergedLayer0.config = {
colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
},
strokeColor: [76, 154, 78],
- radiusRange: [1, 100]
+ radiusRange: [1, 100],
+ allowHover: true,
+ showNeighborOnHover: false,
+ showHighlightColor: true
}
};
@@ -1190,7 +1193,10 @@ mergedLayer2.config = {
},
strokeColor: [218, 112, 191],
fixedRadius: false,
- radiusRange: [1, 854.16]
+ radiusRange: [1, 854.16],
+ allowHover: true,
+ showNeighborOnHover: false,
+ showHighlightColor: true
},
animation: {enabled: false}
};
diff --git a/test/fixtures/state-saved-v1-3.js b/test/fixtures/state-saved-v1-3.js
index a37d7a757..d4d83e847 100644
--- a/test/fixtures/state-saved-v1-3.js
+++ b/test/fixtures/state-saved-v1-3.js
@@ -396,7 +396,10 @@ mergedLayer0.config = {
reversed: true
},
radiusRange: [0, 50],
- strokeColor: [18, 147, 154]
+ strokeColor: [18, 147, 154],
+ allowHover: true,
+ showNeighborOnHover: false,
+ showHighlightColor: true
},
animation: {enabled: false}
};
diff --git a/test/fixtures/state-saved-v1-4.js b/test/fixtures/state-saved-v1-4.js
index fb40d101a..38f39c546 100644
--- a/test/fixtures/state-saved-v1-4.js
+++ b/test/fixtures/state-saved-v1-4.js
@@ -250,7 +250,10 @@ mergedLayer0.config = {
colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
},
strokeColor: [23, 184, 190, 255],
- radiusRange: [0, 50]
+ radiusRange: [0, 50],
+ allowHover: true,
+ showNeighborOnHover: false,
+ showHighlightColor: true
},
animation: {enabled: false}
};
diff --git a/test/fixtures/test-arc-data.js b/test/fixtures/test-arc-data.js
new file mode 100644
index 000000000..6f7253fa5
--- /dev/null
+++ b/test/fixtures/test-arc-data.js
@@ -0,0 +1,294 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+export default [
+ {
+ venue_id: '7c69e9',
+ count: 10,
+ latitude: 41.852015,
+ longitude: -87.616047,
+ neighbors: [1, 2],
+ 'source hex_id': '8a2664c1b74ffff',
+ 'target latitude': 41.946969,
+ 'target longitude': -87.693607,
+ 'target hex_id': '8a2664ca51b7fff'
+ },
+ {
+ venue_id: 'fe26e3',
+ count: 22,
+ latitude: 41.946969,
+ longitude: -87.693607,
+ neighbors: [2, 3],
+ 'source hex_id': '8a2664ca51b7fff',
+ 'target latitude': 41.7552452681605,
+ 'target longitude': -87.6322426600563,
+ 'target hex_id': '8a2664cc3757fff'
+ },
+ {
+ venue_id: '5f3ec9',
+ count: 5,
+ latitude: 41.9228189446294,
+ longitude: -87.7459144592286,
+ neighbors: [3, 4],
+ 'source hex_id': '8a2664ca22dffff',
+ 'target latitude': 41.7552452681605,
+ 'target longitude': -87.6322426600563,
+ 'target hex_id': '8a2664cc3757fff'
+ },
+ {
+ venue_id: 'fe625f',
+ count: 11,
+ latitude: 41.9458364,
+ longitude: -87.7474061,
+ neighbors: [4, 5, 6],
+ 'source hex_id': '8a2664ca66c7fff',
+ 'target latitude': 41.990071,
+ 'target longitude': -87.710537,
+ 'target hex_id': '8a2664d8ad97fff'
+ },
+ {
+ venue_id: '7b1fe3',
+ count: 14,
+ latitude: 41.879519,
+ longitude: -87.6335512,
+ neighbors: [5, 6],
+ 'source hex_id': '8a2664c1a89ffff',
+ 'target latitude': 41.8801791917474,
+ 'target longitude': -87.7507109194994,
+ 'target hex_id': '8a2664c81567fff'
+ },
+ {
+ venue_id: 'd16c1b',
+ count: 8,
+ latitude: 41.7552452681605,
+ longitude: -87.6322426600563,
+ neighbors: [6, 7],
+ 'source hex_id': '8a2664cc3757fff',
+ 'target latitude': 41.9760432,
+ 'target longitude': -87.7082406,
+ 'target hex_id': '8a2664d8a71ffff'
+ },
+ {
+ venue_id: '5f3be3',
+ count: 6,
+ latitude: 41.990071,
+ longitude: -87.710537,
+ neighbors: [7, 8],
+ 'source hex_id': '8a2664d8ad97fff',
+ 'target latitude': 41.7552452681605,
+ 'target longitude': -87.6322426600563,
+ 'target hex_id': '8a2664cc3757fff'
+ },
+ {
+ venue_id: 'eeea20',
+ count: 5,
+ latitude: 41.8801791917474,
+ longitude: -87.7507109194994,
+ neighbors: [8, 9],
+ 'source hex_id': '8a2664c81567fff',
+ 'target latitude': 41.7753234651629,
+ 'target longitude': -87.6832077690278,
+ 'target hex_id': '8a2664cd1197fff'
+ },
+ {
+ venue_id: '352fe3',
+ count: 10,
+ latitude: 41.9760432,
+ longitude: -87.7082406,
+ neighbors: [9, 10],
+ 'source hex_id': '8a2664d8a71ffff',
+ 'target latitude': 41.8667365110101,
+ 'target longitude': -87.7061694860458,
+ 'target hex_id': '8a2664cab41ffff'
+ },
+ {
+ venue_id: 'd16c1b',
+ count: 9,
+ latitude: 41.7552452681605,
+ longitude: -87.6322426600563,
+ neighbors: [10, 11],
+ 'source hex_id': '8a2664cc3757fff',
+ 'target latitude': 41.9458364,
+ 'target longitude': -87.7474061,
+ 'target hex_id': '8a2664ca66c7fff'
+ },
+ {
+ venue_id: '059ad8',
+ count: 6,
+ latitude: 41.7753234651629,
+ longitude: -87.6832077690278,
+ neighbors: [11, 12],
+ 'source hex_id': '8a2664cd1197fff',
+ 'target latitude': 41.9307572879845,
+ 'target longitude': -87.6434218883514,
+ 'target hex_id': '8a2664c1009ffff'
+ },
+ {
+ venue_id: '80172c',
+ count: 5,
+ latitude: 41.8667365110101,
+ longitude: -87.7061694860458,
+ neighbors: [12, 13],
+ 'source hex_id': '8a2664cab41ffff',
+ 'target latitude': 41.852015,
+ 'target longitude': -87.616047,
+ 'target hex_id': '8a2664c1b74ffff'
+ },
+ {
+ venue_id: 'fe625f',
+ count: 14,
+ latitude: 41.9458364,
+ longitude: -87.7474061,
+ neighbors: [13, 14],
+ 'source hex_id': '8a2664ca66c7fff',
+ 'target latitude': 41.946969,
+ 'target longitude': -87.693607,
+ 'target hex_id': '8a2664ca51b7fff'
+ },
+ {
+ venue_id: 'e41fe3',
+ count: 22,
+ latitude: 41.9307572879845,
+ longitude: -87.6434218883514,
+ neighbors: [14, 15],
+ 'source hex_id': '8a2664c1009ffff',
+ 'target latitude': 41.9228189446294,
+ 'target longitude': -87.7459144592286,
+ 'target hex_id': '8a2664ca22dffff'
+ },
+ {
+ venue_id: 'e12ee3',
+ count: 7,
+ latitude: 41.99558699394,
+ longitude: -87.6599389314652,
+ neighbors: [15, 16],
+ 'source hex_id': '8a2664d8c2f7fff',
+ 'target latitude': 41.9458364,
+ 'target longitude': -87.7474061,
+ 'target hex_id': '8a2664ca66c7fff'
+ },
+ {
+ venue_id: 'ac29e3',
+ count: 18,
+ latitude: 41.8008800318507,
+ longitude: -87.5880885869265,
+ neighbors: [16, 17],
+ 'source hex_id': '8a2664ce3637fff',
+ 'target latitude': 41.7552452681605,
+ 'target longitude': -87.6322426600563,
+ 'target hex_id': '8a2664cc3757fff'
+ },
+ {
+ venue_id: 'c236e3',
+ count: 8,
+ latitude: 41.9641381521923,
+ longitude: -87.7086424036042,
+ neighbors: [17, 18],
+ 'source hex_id': '8a2664ca489ffff',
+ 'target latitude': 41.7753234651629,
+ 'target longitude': -87.6832077690278,
+ 'target hex_id': '8a2664cd1197fff'
+ },
+ {
+ venue_id: '1b21e3',
+ count: 20,
+ latitude: 41.9171668642571,
+ longitude: -87.6869366271512,
+ neighbors: [18, 19],
+ 'source hex_id': '8a2664cacd97fff',
+ 'target latitude': 41.8667365110101,
+ 'target longitude': -87.7061694860458,
+ 'target hex_id': '8a2664cab41ffff'
+ },
+ {
+ venue_id: '6a9d00',
+ count: 13,
+ latitude: 41.7923696161345,
+ longitude: -87.7899415791035,
+ neighbors: [19, 20],
+ 'source hex_id': '8a2664520797fff',
+ 'target latitude': 41.9458364,
+ 'target longitude': -87.7474061,
+ 'target hex_id': '8a2664ca66c7fff'
+ },
+ {
+ venue_id: 'fd31e3',
+ count: 8,
+ latitude: 41.887104,
+ longitude: -87.623222,
+ neighbors: [20, 21],
+ 'source hex_id': '8a2664c1e21ffff',
+ 'target latitude': 41.9307572879845,
+ 'target longitude': -87.6434218883514,
+ 'target hex_id': '8a2664c1009ffff'
+ }
+];
+
+export const dataId = 'test-arc-data';
+export const arcDataInfo = {
+ id: dataId,
+ label: 'Arc Row Data',
+ color: [155, 155, 155]
+};
+
+export const pointFromNeighbor = {
+ id: 'point-1',
+ type: 'point',
+ config: {
+ dataId,
+ label: 'point',
+ columns: {
+ lat: 'latitude',
+ lng: 'longitude',
+ neighbors: 'neighbors'
+ },
+ isVisible: true,
+ visConfig: {
+ radius: 20,
+ opacity: 1,
+ allowHover: true,
+ showNeighborOnHover: true,
+ showHighlightColor: false
+ }
+ }
+};
+
+export const arcFromHex = {
+ id: 'arc-1',
+ type: 'arc',
+ config: {
+ dataId,
+ label: 'arc',
+ columnMode: 'points',
+ columns: {
+ lat0: 'source hex_id',
+ lat1: 'target hex_id'
+ },
+ isVisible: true
+ }
+};
+
+export const arcFromNeighbor = {
+ id: 'arc-2',
+ type: 'arc',
+ config: {
+ dataId,
+ columnMode: 'neighbors',
+ label: 'arc from neighbors',
+ columns: {
+ lat: 'latitude',
+ lng: 'longitude',
+ neighbors: 'neighbors'
+ },
+ isVisible: true
+ }
+};
+
+export const config = {
+ version: 'v1',
+ config: {
+ visState: {
+ layers: [pointFromNeighbor, arcFromHex, arcFromNeighbor]
+ }
+ }
+};
diff --git a/test/helpers/comparison-utils.js b/test/helpers/comparison-utils.js
index 6bc364915..6289d8163 100644
--- a/test/helpers/comparison-utils.js
+++ b/test/helpers/comparison-utils.js
@@ -79,6 +79,7 @@ export function cmpLayers(t, expectedLayer, actualLayer, opt = {}) {
} else {
cmpObjectKeys(t, expectedLayer.config, actualLayer.config, `layer.${actualLayer.id}`);
+ // eslint-disable-next-line complexity
Object.keys(expectedLayer.config).forEach(key => {
// test everything except color and id, which are auto generated
// also skip functions
@@ -117,6 +118,8 @@ export function cmpLayers(t, expectedLayer, actualLayer, opt = {}) {
case 'colorField':
case 'sizeField':
case 'heightField':
+ case 'columns':
+ break;
case 'strokeColorField':
cmpField(
t,
@@ -254,6 +257,26 @@ export function cmpDatasets(t, expectedDatasets, actualDatasets) {
export function assertDatasetIsTable(t, dataset) {
t.ok(dataset instanceof KeplerTable, `${dataset.label || 'dataset'} should be a KeplerTable`);
}
+export function cmpColumns(t, expectedColumns, actualColumns, layerName) {
+ cmpObjectKeys(t, expectedColumns, actualColumns, `${layerName}.config.columns`);
+
+ Object.keys(expectedColumns).forEach(key => {
+ if (expectedColumns[key].validator) {
+ // validator is a function, we only test its existence
+ t.ok(
+ actualColumns[key].validator,
+ `${layerName}.config.columns.${key} should have validator`
+ );
+
+ // eslint-disable-next-line no-unused-vars
+ const {validater: _a, ...restPropsA} = actualColumns[key];
+ // eslint-disable-next-line no-unused-vars
+ const {validater: _e, ...restPropsE} = expectedColumns[key];
+
+ t.deepEqual(restPropsA, restPropsE, `${layerName}.config.columns.${key} should have correct`);
+ }
+ });
+}
export function cmpDataset(t, expectedDataset, actualDataset, opt = {}) {
assertDatasetIsTable(t, actualDataset);
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index dde2f32ff..185d3c419 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -41,8 +41,9 @@ import tripCsvData, {
tripCsvDataInfo,
expectedTripLayerConfig
} from '../fixtures/test-trip-csv-data';
+import testArcData, {arcDataInfo, config as arcDataConfig} from '../fixtures/test-arc-data';
import tripGeojson, {tripDataInfo} from '../fixtures/trip-geojson';
-import {processCsvData, processGeojson} from '@kepler.gl/processors';
+import {processCsvData, processGeojson, processRowObject} from '@kepler.gl/processors';
import {MOCK_MAP_STYLE} from './mock-map-styles';
const geojsonFields = cloneDeep(fields);
@@ -179,6 +180,31 @@ export function mockStateWithTripTable(state) {
return updatedState;
}
+export function mockStateWithArcNeighbors(state) {
+ const initialState = cloneDeep(state || InitialState);
+ const updatedState = applyActions(keplerGlReducer, initialState, [
+ {
+ action: addDataToMap,
+ payload: [
+ {
+ datasets: {info: arcDataInfo, data: processRowObject(testArcData)},
+ config: arcDataConfig
+ }
+ ]
+ }
+ ]);
+
+ test(t => {
+ t.equal(updatedState.visState.layers.length, 3, 'should create 3 layers');
+ t.equal(updatedState.visState.layers[0].type, 'point', 'should create point layer');
+ t.equal(updatedState.visState.layers[1].type, 'arc', 'should create arc layer');
+ t.equal(updatedState.visState.layers[2].type, 'arc', 'should create arc layer');
+ t.end();
+ });
+
+ return updatedState;
+}
+
export function mockStateWithFilters(state) {
const initialState = state || mockStateWithFileUpload();
@@ -758,7 +784,10 @@ export const expectedSavedLayer1 = {
},
strokeColorRange: DEFAULT_COLOR_RANGE,
strokeColor: null,
- radiusRange: [0, 50]
+ radiusRange: [0, 50],
+ allowHover: true,
+ showNeighborOnHover: false,
+ showHighlightColor: true
}
},
visualChannels: {
@@ -803,7 +832,10 @@ export const expectedLoadedLayer1 = {
strokeColorRange: DEFAULT_COLOR_RANGE,
filled: true,
strokeColor: null,
- radiusRange: [0, 50]
+ radiusRange: [0, 50],
+ allowHover: true,
+ showNeighborOnHover: false,
+ showHighlightColor: true
},
colorField: {
name: 'gps_data.types',
@@ -939,7 +971,7 @@ export const StateWMultiH3Layers = mockStateWithMultipleH3Layers();
export const StateWithGeocoderDataset = mockStateWithGeocoderDataset();
export const StateWLayerStyle = mockStateWithLayerStyling();
export const StateWTripTable = mockStateWithTripTable();
-
+export const StateWArcNeighbors = mockStateWithArcNeighbors();
export const expectedSavedTripLayer = {
id: 'trip-0',
type: 'trip',
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 1e556d54a..611562a46 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -22,12 +22,7 @@ import {
} from '@kepler.gl/reducers';
import {processCsvData, processGeojson} from '@kepler.gl/processors';
-import {
- Layer,
- KeplerGlLayers,
- COLUMN_MODE_TABLE,
- assignColumnsByColumnMode
-} from '@kepler.gl/layers';
+import {Layer, KeplerGlLayers, COLUMN_MODE_TABLE} from '@kepler.gl/layers';
import {KeplerTable, createNewDataEntry, maybeToDate} from '@kepler.gl/table';
import {createDataContainer, getDefaultFilter} from '@kepler.gl/utils';
import {
@@ -678,27 +673,20 @@ test('#visStateReducer -> LAYER_CONFIG_CHANGE -> columnMode', t => {
// trip Layer
const tripLayer = updatedState2.layers[0];
- const updatedColumns = assignColumnsByColumnMode({
- columns: tripLayer.config.columns,
- supportedColumnModes: tripLayer.supportedColumnModes,
- columnMode: COLUMN_MODE_TABLE
- });
-
- // update trip layer column mode and columns
+ // update trip layer column mode
const nextState = reducer(
updatedState2,
VisStateActions.layerConfigChange(tripLayer, {
- columnMode: COLUMN_MODE_TABLE,
- columns: updatedColumns
+ columnMode: COLUMN_MODE_TABLE
})
);
const expectedLayerConfigColumns = {
- geojson: {value: null, fieldIdx: -1, optional: true},
- id: {value: null, fieldIdx: -1, optional: false},
- lat: {value: 'location-lat', fieldIdx: 2, optional: false},
- lng: {value: 'location-lng', fieldIdx: 1, optional: false},
- timestamp: {value: null, fieldIdx: -1, optional: false},
+ geojson: {value: null, fieldIdx: -1},
+ id: {value: null, fieldIdx: -1},
+ lat: {value: 'location-lat', fieldIdx: 2},
+ lng: {value: 'location-lng', fieldIdx: 1},
+ timestamp: {value: null, fieldIdx: -1},
altitude: {value: 'location-alt', fieldIdx: 6, optional: true}
};
t.deepEqual(
@@ -718,9 +706,9 @@ test('#visStateReducer -> LAYER_CONFIG_CHANGE -> columnMode', t => {
nextState,
VisStateActions.layerConfigChange(nextState.layers[0], {
columns: {
- ...updatedColumns,
- timestamp: {value: 'timestamp', fieldIdx: 0, optional: true},
- id: {value: 'name', fieldIdx: 5, optional: true}
+ ...expectedLayerConfigColumns,
+ timestamp: {value: 'timestamp', fieldIdx: 0},
+ id: {value: 'name', fieldIdx: 5}
}
})
);
@@ -768,16 +756,9 @@ test('visStateReducer -> layerDataIdChangeUpdater', t => {
const updatedLayer = nextState.layers[0];
t.equal(updatedLayer.config.dataId, testGeoJsonDataId, 'should update point layer dataId');
- t.deepEqual(
- updatedLayer.config.columns,
- {
- altitude: {value: null, fieldIdx: -1, optional: true},
- lat: {value: null, fieldIdx: -1},
- lng: {value: null, fieldIdx: -1}
- },
- 'should not update point layer column'
- );
- t.equal(updatedLayer.config.colorField, null, 'should not update point layer colorField');
+ const expectedLayerColumns = new PointLayer({}).config.columns;
+ t.deepEqual(updatedLayer.config.columns, expectedLayerColumns, 'should reset point layer column');
+ t.equal(updatedLayer.config.colorField, null, 'should not assign point layer colorField');
// add layer
const nextState1 = reducer(nextState, VisStateActions.addLayer());
@@ -882,7 +863,8 @@ test('visStateReducer -> layerDataIdChangeUpdater -> validation', t => {
{
altitude: {value: null, fieldIdx: -1, optional: true},
lat: {value: 'gps_data.lat', fieldIdx: 1},
- lng: {value: 'gps_data.lng', fieldIdx: 2}
+ lng: {value: 'gps_data.lng', fieldIdx: 2},
+ neighbors: {value: null, fieldIdx: -1, optional: true}
},
'should update point layer column'
);
@@ -2048,7 +2030,8 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
columns: {
lat: {value: 'gps_data.lat', fieldIdx: 1},
lng: {value: 'gps_data.lng', fieldIdx: 2},
- altitude: {value: null, fieldIdx: -1, optional: true}
+ altitude: {value: null, fieldIdx: -1, optional: true},
+ neighbors: {value: null, fieldIdx: -1, optional: true}
}
});
@@ -2224,12 +2207,12 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
const expectedLayerData1 = {
data: [
- {index: 17, position: [31.2165983, 30.0538936, 0]},
- {index: 18, position: [31.2148748, 30.060911, 0]},
- {index: 19, position: [31.2212278, 30.060334, 0]},
- {index: 20, position: [31.2288985, 30.0554663, 0]},
- {index: 21, position: [31.2187021, 30.0614122, 0]},
- {index: 22, position: [31.2191059, 30.0612697, 0]}
+ {index: 17, position: [31.2165983, 30.0538936, 0], neighbors: undefined},
+ {index: 18, position: [31.2148748, 30.060911, 0], neighbors: undefined},
+ {index: 19, position: [31.2212278, 30.060334, 0], neighbors: undefined},
+ {index: 20, position: [31.2288985, 30.0554663, 0], neighbors: undefined},
+ {index: 21, position: [31.2187021, 30.0614122, 0], neighbors: undefined},
+ {index: 22, position: [31.2191059, 30.0612697, 0], neighbors: undefined}
],
getPosition: () => {},
getColor: () => {},
diff --git a/test/node/utils/layer-utils-test.js b/test/node/utils/layer-utils-test.js
index fc3493dbc..740b785ef 100644
--- a/test/node/utils/layer-utils-test.js
+++ b/test/node/utils/layer-utils-test.js
@@ -318,7 +318,7 @@ test('layerUtils -> findDefaultLayer.2', t => {
expected.updateLayerVisConfig({filled: true, stroked: false});
- const layers = findDefaultLayer(dataset, KeplerGlLayers);
+ const layers = findDefaultLayer(dataset, LayerClasses);
t.equal(layers.length, 1, 'number of layers found');
cmpLayers(t, expected, layers[0]);
@@ -364,7 +364,7 @@ test('layerUtils -> findDefaultLayer.3', t => {
];
const fieldPairs = findPointFieldPairs(inputFields);
- const layers = findDefaultLayer({fields: inputFields, fieldPairs, id: dataId}, KeplerGlLayers);
+ const layers = findDefaultLayer({fields: inputFields, fieldPairs, id: dataId}, LayerClasses);
t.equal(layers.length, 1, 'number of layers found');
layers.forEach((l, i) => cmpLayers(t, outputLayers[i], l));
@@ -498,7 +498,7 @@ test('layerUtils -> findDefaultLayer.4', t => {
];
const fieldPairs = findPointFieldPairs(inputFields);
- const layers = findDefaultLayer({fields: inputFields, fieldPairs, id: dataId}, KeplerGlLayers);
+ const layers = findDefaultLayer({fields: inputFields, fieldPairs, id: dataId}, LayerClasses);
t.equal(layers.length, outputLayers.length, 'number of layers found');
layers.forEach((l, i) => cmpLayers(t, outputLayers[i], l));
@@ -520,7 +520,7 @@ test('layerUtils -> findDefaultLayer.5', t => {
];
const fieldPairs = findPointFieldPairs(inputFields);
- const layers = findDefaultLayer({fields: inputFields, fieldPairs, id: 'yo'}, KeplerGlLayers);
+ const layers = findDefaultLayer({fields: inputFields, fieldPairs, id: 'yo'}, LayerClasses);
t.equal(layers.length, 0, 'number of layers found');
@@ -629,7 +629,7 @@ test('layerUtils -> findDefaultLayer:GeojsonLayer', t => {
fieldPairs: [],
dataContainer
},
- KeplerGlLayers
+ LayerClasses
);
cmpLayers(t, [expected1, expected2], geojsonLayers);
@@ -676,7 +676,7 @@ test('layerUtils -> findDefaultLayer:GeojsonLayer.wkt', t => {
const geojsonLayers = findDefaultLayer(
{fields, id: dataId, label, fieldPairs: [], dataContainer},
- KeplerGlLayers
+ LayerClasses
);
cmpLayers(t, [expected1, expected2], geojsonLayers);
@@ -697,7 +697,7 @@ test('layerUtils -> findDefaultLayer:GeojsonWithStyle', t => {
fieldPairs: [],
dataContainer
},
- KeplerGlLayers
+ LayerClasses
);
t.equal(geojsonLayers.length, 1, 'should find 1 layer');
@@ -736,7 +736,7 @@ test('layerUtils -> findDefaultLayer:IconLayer', t => {
id: 'meow',
allData: []
},
- KeplerGlLayers
+ LayerClasses
).filter(l => l.type === 'icon').length,
0,
'should find no icon layer'
@@ -751,7 +751,7 @@ test('layerUtils -> findDefaultLayer:IconLayer', t => {
fieldPairs: fieldPairsWIcon,
id: 'meow'
},
- KeplerGlLayers
+ LayerClasses
).filter(l => l.type === 'icon');
t.equal(iconLayers.length, 1, 'should find 1 icon layer');
@@ -766,7 +766,7 @@ test('layerUtils -> findDefaultLayer:IconLayer', t => {
fieldPairs: fieldPairsW2Icon,
id: 'meow'
},
- KeplerGlLayers
+ LayerClasses
).filter(l => l.type === 'icon');
t.equal(iconLayers.length, 2, 'should find 2 icon layers');
@@ -785,11 +785,11 @@ test('layerUtils -> findDefaultLayer: TripLayer', t => {
dataId: 'trip_data',
label: 'Trip Data',
columns: {
- geojson: {value: '_geojson', fieldIdx: 0, optional: false},
- id: {value: null, fieldIdx: -1, optional: true},
- lat: {value: null, fieldIdx: -1, optional: true},
- lng: {value: null, fieldIdx: -1, optional: true},
- timestamp: {value: null, fieldIdx: -1, optional: true},
+ geojson: {value: '_geojson', fieldIdx: 0},
+ id: {value: null, fieldIdx: -1},
+ lat: {value: null, fieldIdx: -1},
+ lng: {value: null, fieldIdx: -1},
+ timestamp: {value: null, fieldIdx: -1},
altitude: {value: null, fieldIdx: -1, optional: true}
},
isVisible: true,