Skip to content

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

[feat] Time filter syncing (#2690)

Igor Dykhtad6082fe6c302
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.js
index e5e3bdfb1..1bba15129 100644
--- a/examples/demo-app/src/app.js
+++ b/examples/demo-app/src/app.js
@@ -6,6 +6,7 @@ import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
import styled, {ThemeProvider} from 'styled-components';
import window from 'global/window';
import {connect} from 'react-redux';
+import cloneDeep from 'lodash.clonedeep';
import {theme} from '@kepler.gl/styles';
import Banner from './components/banner';
@@ -205,11 +206,25 @@ class App extends Component {
datasets: [
{
info: {
- label: 'Sample Taxi Trips in New York City',
+ label: 'Sample Taxi Trips 1',
id: 'test_trip_data',
color: [255, 0, 0]
},
- data: sampleTripData
+ data: {
+ rows: sampleTripData.rows.slice(0, 20),
+ fields: cloneDeep(sampleTripData.fields)
+ }
+ },
+ {
+ info: {
+ label: 'Sample Taxi Trips 2',
+ id: 'test_trip_data_2',
+ color: [0, 255, 0]
+ },
+ data: {
+ rows: sampleTripData.rows.slice(5, sampleTripData.rows.length),
+ fields: cloneDeep(sampleTripData.fields)
+ }
}
],
options: {
diff --git a/examples/demo-app/src/data/sample-trip-data.js b/examples/demo-app/src/data/sample-trip-data.js
index 449b50ae6..48d9e6e47 100644
--- a/examples/demo-app/src/data/sample-trip-data.js
+++ b/examples/demo-app/src/data/sample-trip-data.js
@@ -4053,7 +4053,7 @@ export const sampleTripDataConfig = {
{
dataId: 'test_trip_data',
name: 'tpep_pickup_datetime',
- enlarged: true
+ view: 'enlarged'
},
{
dataId: 'test_trip_data',
diff --git a/package.json b/package.json
index 08eb02306..1da461868 100644
--- a/package.json
+++ b/package.json
@@ -138,7 +138,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
- "@types/d3-array": "^2.0.0",
+ "@types/d3-array": "^2.8.0",
"@types/d3-scale": "^3.2.2",
"@types/geojson": "^7946.0.8",
"@types/jsdom": "^21.1.1",
diff --git a/src/actions/src/vis-state-actions.ts b/src/actions/src/vis-state-actions.ts
index d7f256cbf..648fb9ac6 100644
--- a/src/actions/src/vis-state-actions.ts
+++ b/src/actions/src/vis-state-actions.ts
@@ -292,7 +292,7 @@ export function interactionConfigChange(
export type SetFilterUpdaterAction = {
idx: number;
- prop: string;
+ prop: string | string[];
value: any;
valueIndex?: number;
};
@@ -301,6 +301,8 @@ export type SetFilterUpdaterAction = {
* @memberof visStateActions
* @param idx -`idx` of filter to be updated
* @param prop - `prop` of filter, e,g, `dataId`, `name`, `value`
+ * or an array e.g. ['idx', 'name']. in that case the value
+ * should also be an array of the corresponding values (by index)
* @param value - new value
* @param valueIndex - dataId index
* @returns action
@@ -308,7 +310,7 @@ export type SetFilterUpdaterAction = {
*/
export function setFilter(
idx: number,
- prop: string,
+ prop: string | string[],
value: any,
valueIndex?: number
): Merge<SetFilterUpdaterAction, {type: typeof ActionTypes.SET_FILTER}> {
@@ -1134,9 +1136,13 @@ export function toggleLayerForMap(
};
}
+type FilterPlotNewProp = {
+ yAxis?: null | Record<string, any>;
+ plotType?: {type: string};
+};
export type SetFilterPlotUpdaterAction = {
idx: number;
- newProp: object;
+ newProp: FilterPlotNewProp;
valueIndex?: number;
};
/**
@@ -1150,7 +1156,7 @@ export type SetFilterPlotUpdaterAction = {
*/
export function setFilterPlot(
idx: number,
- newProp: object,
+ newProp: FilterPlotNewProp,
valueIndex?: number
): Merge<SetFilterPlotUpdaterAction, {type: typeof ActionTypes.SET_FILTER_PLOT}> {
return {
diff --git a/src/components/package.json b/src/components/package.json
index 041e3e2ca..ef84d511d 100644
--- a/src/components/package.json
+++ b/src/components/package.json
@@ -54,7 +54,7 @@
"@nebula.gl/edit-modes": "1.0.2-alpha.1",
"@tippyjs/react": "^4.2.0",
"@types/classnames": "^2.3.1",
- "@types/d3-array": "^2.0.0",
+ "@types/d3-array": "^2.8.0",
"@types/d3-brush": "^3.0.1",
"@types/d3-scale": "^3.2.2",
"@types/d3-selection": "^3.0.2",
diff --git a/src/components/src/common/field-selector.tsx b/src/components/src/common/field-selector.tsx
index 92e8f7df0..ecf51ba06 100644
--- a/src/components/src/common/field-selector.tsx
+++ b/src/components/src/common/field-selector.tsx
@@ -95,6 +95,7 @@ interface FieldSelectorFactoryProps {
inputTheme?: string;
placeholder?: string;
erasable?: boolean;
+ disabled?: boolean;
error?: boolean;
multiSelect?: boolean;
closeOnSelect?: boolean;
@@ -114,6 +115,7 @@ function FieldSelectorFactory(
class FieldSelector extends Component<FieldSelectorFactoryProps> {
static defaultProps = {
erasable: true,
+ disabled: false,
error: false,
fields: [],
onSelect: noop,
@@ -174,6 +176,7 @@ function FieldSelectorFactory(
<StyledFieldSelector className={classnames('field-selector', this.props.className)}>
<ItemSelector
getOptionValue={d => d}
+ disabled={this.props.disabled}
closeOnSelect={this.props.closeOnSelect}
displayOption={defaultDisplayOption}
filterOption="displayName"
diff --git a/src/components/src/common/histogram-plot.tsx b/src/components/src/common/histogram-plot.tsx
index 63fe51075..218808b0a 100644
--- a/src/components/src/common/histogram-plot.tsx
+++ b/src/components/src/common/histogram-plot.tsx
@@ -3,10 +3,9 @@
import React, {ReactElement, useMemo} from 'react';
import {scaleLinear} from 'd3-scale';
-import {max} from 'd3-array';
import {hcl} from 'd3-color';
+import {min, max} from 'd3-array';
import styled from 'styled-components';
-import {HistogramBin} from '@kepler.gl/types';
const histogramStyle = {
highlightW: 0.7,
@@ -37,77 +36,125 @@ interface HistogramPlotProps {
height: number;
margin: {top: number; bottom: number; left: number; right: number};
isRanged?: boolean;
- histogram: HistogramBin[];
value: number[];
brushComponent?: ReactElement;
+ histogramsByGroup: any;
+ colorsByGroup: any;
+ countProp: any;
+ range: any;
}
function HistogramPlotFactory() {
const HistogramPlot = ({
width,
height,
+ histogramsByGroup,
+ colorsByGroup,
+ countProp = 'count',
margin,
isRanged,
- histogram,
+ range,
value,
brushComponent
}: HistogramPlotProps) => {
const undefinedToZero = (x: number | undefined) => (x ? x : 0);
- const domain = useMemo(
+ const groupKeys = useMemo(
() =>
- [histogram[0].x0, histogram[histogram.length - 1].x1].map(item => undefinedToZero(item)),
- [histogram]
+ Object.keys(histogramsByGroup)
+ // only keep non-empty groups
+ .filter(key => histogramsByGroup[key]?.length > 0),
+ [histogramsByGroup]
);
- const dataId = Object.keys(histogram[0]).filter(k => k !== 'x0' && k !== 'x1')[0];
- // use 1st for now
- const getValue = useMemo(() => d => d[dataId], [dataId]);
+ const domain = useMemo(
+ () =>
+ range ?? [
+ min(groupKeys, key => histogramsByGroup[key][0].x0),
+ max(groupKeys, key => histogramsByGroup[key][histogramsByGroup[key].length - 1].x1)
+ ],
+ [range, histogramsByGroup, groupKeys]
+ );
const x = useMemo(() => scaleLinear().domain(domain).range([0, width]), [domain, width]);
const y = useMemo(
() =>
scaleLinear()
- .domain([0, Number(max(histogram, getValue))])
+ .domain([
+ 0,
+ Math.max(
+ Number(
+ max(groupKeys, key => max(histogramsByGroup[key], (d: number[]) => d[countProp]))
+ ),
+ 1
+ )
+ ])
.range([0, height]),
- [histogram, height, getValue]
+ [histogramsByGroup, groupKeys, height, countProp]
);
- const barWidth = width / histogram.length;
+ const barWidth = useMemo(() => {
+ const maxBins = max(groupKeys, key => {
+ if (histogramsByGroup[key].length > 1)
+ return (
+ (domain[1] - domain[0]) / (histogramsByGroup[key][1].x1 - histogramsByGroup[key][1].x0)
+ );
+ // TODO this part should be removed with follow ups
+ return (
+ (domain[1] - domain[0]) / (histogramsByGroup[key][0].x1 - histogramsByGroup[key][0].x0)
+ );
+ });
+ if (!maxBins) return 0;
+ return width / maxBins / groupKeys.length;
+ }, [histogramsByGroup, domain, groupKeys, width]);
return (
<HistogramWrapper width={width} height={height} style={{marginTop: `${margin.top}px`}}>
- <g className="histogram-bars">
- {histogram.map(bar => {
- const inRange =
- undefinedToZero(bar.x1) <= value[1] && undefinedToZero(bar.x0) >= value[0];
- const wRatio = inRange ? histogramStyle.highlightW : histogramStyle.unHighlightedW;
- const startX = x(undefinedToZero(bar.x0)) + (barWidth * (1 - wRatio)) / 2;
- if (startX > 0 && startX + barWidth * histogramStyle.unHighlightedW <= width) {
- return (
- <Bar
- inRange={inRange}
- key={bar.x0}
- height={y(getValue(bar))}
- width={barWidth * wRatio}
- x={startX}
- rx={1}
- ry={1}
- y={height - y(getValue(bar))}
- />
- );
- }
- return null;
- })}
- </g>
+ {groupKeys.map((key, i) => (
+ <g key={key} className="histogram-bars">
+ {histogramsByGroup[key].map(bar => {
+ const inRange =
+ undefinedToZero(bar.x1) <= value[1] && undefinedToZero(bar.x0) >= value[0];
+ const wRatio = inRange ? histogramStyle.highlightW : histogramStyle.unHighlightedW;
+ const startX =
+ x(undefinedToZero(bar.x0)) + barWidth * i + (barWidth * (1 - wRatio)) / 2;
+ if (startX > 0 && startX + barWidth * histogramStyle.unHighlightedW <= width) {
+ return (
+ <Bar
+ inRange={inRange}
+ color={colorsByGroup ? colorsByGroup[key] : undefined}
+ key={bar.x0}
+ height={y(bar[countProp])}
+ width={barWidth * wRatio}
+ x={startX}
+ rx={1}
+ ry={1}
+ y={height - y(bar[countProp])}
+ />
+ );
+ }
+ return null;
+ })}
+ </g>
+ ))}
<g transform={`translate(${isRanged ? 0 : barWidth / 2}, 0)`}>{brushComponent}</g>
</HistogramWrapper>
);
};
- const EmpptyOrPlot = props =>
- !props.histogram || !props.histogram.length ? null : <HistogramPlot {...props} />;
+ const HistogramPlotWithGroups = props => {
+ const groups = useMemo(
+ () => (props.histogramsByGroup ? Object.keys(props.histogramsByGroup) : null),
+ [props.histogramsByGroup]
+ );
+
+ if (!groups?.length) {
+ return null;
+ }
+
+ return <HistogramPlot {...props} />;
+ };
- return EmpptyOrPlot;
+ return HistogramPlotWithGroups;
}
export default HistogramPlotFactory;
diff --git a/src/components/src/common/line-chart.tsx b/src/components/src/common/line-chart.tsx
index a86f5f8e8..77d4220c6 100644
--- a/src/components/src/common/line-chart.tsx
+++ b/src/components/src/common/line-chart.tsx
@@ -105,13 +105,29 @@ function LineChartFactory() {
timezone,
timeFormat
}: LineChartProps) => {
- const {series, yDomain} = lineChart || {};
+ const {yDomain, xDomain} = lineChart || {};
+ // @ts-expect-error seems lineChart.series has ambiguous types. Requires refactoring.
+ const series: {lines: any[]; markers: any[]} = lineChart?.series;
+ const paddedYDomain = useMemo(
+ () =>
+ yDomain && yDomain[0] && yDomain[1]
+ ? [yDomain[0], yDomain[1] + (yDomain[1] - yDomain[0]) * 0.2]
+ : [],
+ [yDomain]
+ );
const brushData = useMemo(() => {
- return series && series[0] && series[0].x && yDomain && yDomain[1]
- ? [{x: series[0].x, y: yDomain[1], customComponent: () => brushComponent}]
+ return xDomain && paddedYDomain
+ ? [
+ {
+ x: xDomain[0],
+ y: paddedYDomain[1],
+ customComponent: () => brushComponent
+ }
+ ]
: [];
- }, [series, yDomain, brushComponent]);
+ }, [xDomain, paddedYDomain, brushComponent]);
+
const hintFormatter = useMemo(
() => datetimeFormatter(timezone)(timeFormat),
[timezone, timeFormat]
@@ -127,14 +143,19 @@ function LineChartFactory() {
onMouseLeave={() => {
onMouseMove(null);
}}
+ yDomain={paddedYDomain}
+ xDomain={xDomain}
>
<HorizontalGridLines tickTotal={3} />
- <LineSeries
- style={{fill: 'none'}}
- color={color}
- data={series}
- onNearestX={enableChartHover ? onMouseMove : undefined}
- />
+ {series.lines.map((d, i) => (
+ <LineSeries
+ key={i}
+ style={{fill: 'none'}}
+ color={color}
+ data={d}
+ onNearestX={series.markers.length || !enableChartHover ? undefined : onMouseMove}
+ />
+ ))}
<MarkSeries data={hoveredDP ? [hoveredDP] : []} color={color} />
<CustomSVGSeries data={brushData} />
{isEnlarged && <YAxis tickTotal={3} />}
diff --git a/src/components/src/common/loading-spinner.tsx b/src/components/src/common/loading-spinner.tsx
index 0b30eb664..cc356faf5 100644
--- a/src/components/src/common/loading-spinner.tsx
+++ b/src/components/src/common/loading-spinner.tsx
@@ -39,6 +39,7 @@ const LoadingWrapper = styled.div<LoadingWrapperProps>`
interface LoadingSpinnerProps {
size?: number;
color?: string;
+ borderColor?: string;
strokeWidth?: number;
gap?: number;
}
@@ -46,10 +47,13 @@ interface LoadingSpinnerProps {
const LoadingSpinner: React.FC<LoadingSpinnerProps> = ({
size = 32,
color = '',
+ borderColor = '',
strokeWidth = 3,
gap = 2
}) => (
- <LoadingWrapper style={{width: `${size}px`, height: `${size}px`, padding: `${gap}px`}}>
+ <LoadingWrapper
+ style={{width: `${size}px`, height: `${size}px`, padding: `${gap}px`, borderColor}}
+ >
<Loader
color={color}
style={{
diff --git a/src/components/src/common/radius-legend.tsx b/src/components/src/common/radius-legend.tsx
index 354f5c062..708193b8a 100644
--- a/src/components/src/common/radius-legend.tsx
+++ b/src/components/src/common/radius-legend.tsx
@@ -1,3 +1,6 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
import React, {useMemo, FC} from 'react';
import styled from 'styled-components';
import {scaleSqrt} from 'd3-scale';
diff --git a/src/components/src/common/range-plot.tsx b/src/components/src/common/range-plot.tsx
index 2b5809c23..471221b53 100644
--- a/src/components/src/common/range-plot.tsx
+++ b/src/components/src/common/range-plot.tsx
@@ -1,14 +1,16 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import React, {useState, useCallback} from 'react';
+import React, {useCallback, useMemo, useState, useEffect} from 'react';
import styled, {withTheme} from 'styled-components';
import RangeBrushFactory, {OnBrush, RangeBrushProps} from './range-brush';
import HistogramPlotFactory from './histogram-plot';
import LineChartFactory, {HoverDP} from './line-chart';
-import {isTest, hasMobileWidth} from '@kepler.gl/utils';
+import {hasMobileWidth, isTest} from '@kepler.gl/utils';
+import {PLOT_TYPES} from '@kepler.gl/constants';
+import LoadingSpinner from './loading-spinner';
import {breakPointValues} from '@kepler.gl/styles';
-import {LineChart, Filter} from '@kepler.gl/types';
+import {LineChart as LineChartType, Filter, Bins} from '@kepler.gl/types';
import {Datasets} from '@kepler.gl/table';
const StyledRangePlot = styled.div`
@@ -22,9 +24,12 @@ interface RangePlotProps {
range: number[];
value: number[];
width: number;
- plotType?: string;
- lineChart?: LineChart;
- histogram?: {x0: number; x1: number}[];
+ plotType: {
+ [key: string]: any;
+ };
+ lineChart?: LineChartType;
+ bins?: Bins;
+
isEnlarged?: boolean;
isRanged?: boolean;
theme: any;
@@ -39,26 +44,46 @@ interface RangePlotProps {
invertTrendColor?: boolean;
}
+type WithPlotLoadingProps = RangePlotProps &
+ Partial<RangeBrushProps> & {
+ setFilterPlot: any;
+ };
+
RangePlotFactory.deps = [RangeBrushFactory, HistogramPlotFactory, LineChartFactory];
+const isHistogramPlot = plotType => plotType?.type === PLOT_TYPES.histogram;
+const isLineChart = plotType => plotType?.type === PLOT_TYPES.lineChart;
+const hasHistogram = (plotType, bins) => isHistogramPlot(plotType) && bins;
+const hasLineChart = (plotType, lineChart) => isLineChart(plotType) && lineChart;
+
export default function RangePlotFactory(
RangeBrush: ReturnType<typeof RangeBrushFactory>,
HistogramPlot: ReturnType<typeof HistogramPlotFactory>,
LineChartPlot: ReturnType<typeof LineChartFactory>
) {
const RangePlot = ({
+ bins,
onBrush,
range,
value,
width,
plotType,
lineChart,
- histogram,
isEnlarged,
isRanged,
theme,
...chartProps
}: RangePlotProps & Partial<RangeBrushProps>) => {
+ const groupColors = useMemo(() => {
+ const dataIds = bins ? Object.keys(bins) : [];
+ return plotType.colorsByDataId
+ ? dataIds.reduce((acc, dataId) => {
+ acc[dataId] = plotType.colorsByDataId[dataId];
+ return acc;
+ }, {})
+ : null;
+ }, [bins, plotType.colorsByDataId]);
+
const [brushing, setBrushing] = useState(false);
const [hoveredDP, onMouseMove] = useState<HoverDP | null>(null);
const [enableChartHover, setEnableChartHover] = useState(false);
@@ -121,6 +146,63 @@ export default function RangePlotFactory(
...chartProps
};
+ return isLineChart(plotType) && lineChart ? (
+ <LineChartPlot lineChart={lineChart} {...commonProps} />
+ ) : (
+ <HistogramPlot
+ histogramsByGroup={bins}
+ colorsByGroup={groupColors}
+ range={range}
+ {...commonProps}
+ />
+ );
+ };
+
+ const RangePlotWithTheme = withTheme(RangePlot);
+
+ // a container to render spinner or message when the data is too big
+ // to generate a plot
+ const WithPlotLoading = ({
+ lineChart,
+ plotType,
+ bins,
+ setFilterPlot,
+ isEnlarged,
+ theme,
+ ...otherProps
+ }: WithPlotLoadingProps) => {
+ const [isLoading, setIsLoading] = useState(false);
+ // eslint-disable-next-line complexity
+ useEffect(() => {
+ if (!plotType && !isLoading) {
+ // if plotType is undefined. this shouldn't happen
+ setIsLoading(true);
+ setFilterPlot({
+ plotType: {
+ type: PLOT_TYPES.histogram
+ }
+ });
+ } else if (isHistogramPlot(plotType) && !bins && !isLoading) {
+ setIsLoading(true);
+ // load histogram
+ setFilterPlot({
+ plotType: {
+ type: PLOT_TYPES.histogram
+ }
+ });
+ } else if (isLineChart(plotType) && !lineChart && !isLoading) {
+ // load linechart
+ setIsLoading(true);
+ setFilterPlot({
+ plotType: {
+ type: PLOT_TYPES.lineChart
+ }
+ });
+ } else if (isLoading && (hasHistogram(plotType, bins) || hasLineChart(plotType, lineChart))) {
+ setIsLoading(false);
+ }
+ }, [plotType, bins, lineChart, setFilterPlot, isLoading, setIsLoading]);
+
return (
<StyledRangePlot
style={{
@@ -134,14 +216,30 @@ export default function RangePlotFactory(
}}
className="kg-range-slider__plot"
>
- {plotType === 'lineChart' && lineChart ? (
- <LineChartPlot lineChart={lineChart} {...commonProps} />
+ {isLoading ? (
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ width: '100%'
+ }}
+ >
+ <LoadingSpinner borderColor="transparent" size={40} />
+ </div>
) : (
- <HistogramPlot histogram={histogram} {...commonProps} />
+ <RangePlotWithTheme
+ lineChart={lineChart}
+ bins={bins}
+ plotType={plotType}
+ isEnlarged={isEnlarged}
+ theme={theme}
+ {...otherProps}
+ />
)}
</StyledRangePlot>
);
};
- return withTheme(RangePlot);
+ return withTheme(WithPlotLoading);
}
diff --git a/src/components/src/common/range-slider.tsx b/src/components/src/common/range-slider.tsx
index 6a6fe1288..750b16739 100644
--- a/src/components/src/common/range-slider.tsx
+++ b/src/components/src/common/range-slider.tsx
@@ -10,8 +10,9 @@ import Slider from './slider/slider';
import {Input} from './styled-components';
import {observeDimensions, unobserveDimensions, roundValToStep, clamp} from '@kepler.gl/utils';
-import {LineChart, Filter} from '@kepler.gl/types';
+import {LineChart, Filter, Bins} from '@kepler.gl/types';
import {Datasets} from '@kepler.gl/table';
+import {ActionHandler, setFilterPlot} from '@kepler.gl/actions';
interface SliderInputProps {
flush?: boolean;
@@ -49,7 +50,8 @@ interface RangeSliderProps {
value0: number;
value1: number;
onChange?: (val: number[], e?: Event | null) => void; // TODO
- histogram?: any[];
+ setFilterPlot?: ActionHandler<typeof setFilterPlot>;
+ bins?: Bins;
isRanged?: boolean;
isEnlarged?: boolean;
showInput?: boolean;
@@ -63,7 +65,9 @@ interface RangeSliderProps {
playbackControlWidth?: number;
lineChart?: LineChart;
marks?: number[];
- plotType?: string;
+ plotType?: {
+ [key: string]: any;
+ };
plotValue?: number[];
animationWindow?: string;
@@ -211,8 +215,9 @@ export default function RangeSliderFactory(
const {
isRanged,
showInput,
- histogram,
+ bins,
lineChart,
+ plotType,
invertTrendColor,
range,
onChange = noop,
@@ -221,6 +226,7 @@ export default function RangeSliderFactory(
timezone,
timeFormat,
playbackControlWidth,
+ setFilterPlot,
animationWindow,
filter,
datasets
@@ -228,7 +234,7 @@ export default function RangeSliderFactory(
const {width} = this.state;
const plotWidth = Math.max(width - Number(sliderHandleWidth), 0);
- const renderPlot = (histogram && histogram.length) || lineChart;
+ const hasPlot = plotType?.type;
return (
<div
className="kg-range-slider"
@@ -237,12 +243,12 @@ export default function RangeSliderFactory(
>
{Array.isArray(range) && range.every(Number.isFinite) && (
<>
- {renderPlot ? (
+ {hasPlot ? (
<RangePlot
- histogram={histogram}
- lineChart={this.props.lineChart}
+ bins={bins}
+ lineChart={lineChart}
+ plotType={plotType}
invertTrendColor={invertTrendColor}
- plotType={this.props.plotType}
isEnlarged={this.props.isEnlarged}
onBrush={(val0, val1) => onChange([val0, val1])}
marks={this.props.marks}
@@ -257,6 +263,7 @@ export default function RangeSliderFactory(
timezone={timezone}
timeFormat={timeFormat}
playbackControlWidth={playbackControlWidth}
+ setFilterPlot={setFilterPlot}
/>
) : null}
<SliderWrapper
diff --git a/src/components/src/common/time-range-slider.tsx b/src/components/src/common/time-range-slider.tsx
index 050874f0c..0ff73e3ae 100644
--- a/src/components/src/common/time-range-slider.tsx
+++ b/src/components/src/common/time-range-slider.tsx
@@ -9,7 +9,8 @@ import RangeSliderFactory from './range-slider';
import TimeSliderMarkerFactory from './time-slider-marker';
import PlaybackControlsFactory from './animation-control/playback-controls';
import TimeRangeSliderTimeTitleFactory from './time-range-slider-time-title';
-import {HistogramBin, LineChart, Timeline} from '@kepler.gl/types';
+import {LineChart, Timeline} from '@kepler.gl/types';
+import {ActionHandler, setFilterPlot} from '@kepler.gl/actions';
import AnimationControlFactory from './animation-control/animation-control';
const animationControlWidth = 176;
@@ -27,8 +28,10 @@ type TimeRangeSliderProps = {
isAnimating: boolean;
timeFormat: string;
timezone?: string | null;
- histogram?: HistogramBin[];
- plotType?: string;
+ timeBins?: object;
+ plotType?: {
+ [key: string]: any;
+ };
lineChart?: LineChart;
step: number;
isAnimatable?: boolean;
@@ -38,6 +41,7 @@ type TimeRangeSliderProps = {
toggleAnimation: () => void;
updateAnimationSpeed?: (val: number) => void;
setFilterAnimationWindow?: (id: string) => void;
+ setFilterPlot?: ActionHandler<typeof setFilterPlot>;
onChange: (v: number[]) => void;
timeline: Timeline;
invertTrendColor?: boolean;
@@ -69,6 +73,13 @@ TimeRangeSliderFactory.deps = [
AnimationControlFactory
];
+export function getTimeBinsForInterval(timeBins, interval) {
+ return Object.keys(timeBins).reduce((acc, dataId) => {
+ acc[dataId] = timeBins[dataId][interval];
+ return acc;
+ }, {});
+}
+
export default function TimeRangeSliderFactory(
PlaybackControls: ReturnType<typeof PlaybackControlsFactory>,
RangeSlider: ReturnType<typeof RangeSliderFactory>,
@@ -87,7 +98,7 @@ export default function TimeRangeSliderFactory(
resetAnimation,
timeFormat,
timezone,
- histogram,
+ timeBins,
plotType,
lineChart,
invertTrendColor,
@@ -99,10 +110,15 @@ export default function TimeRangeSliderFactory(
setFilterAnimationWindow,
toggleAnimation,
onChange,
+ setFilterPlot,
timeline
} = props;
const throttledOnchange = useMemo(() => throttle(onChange, 20), [onChange]);
+ const binsForInterval = useMemo(() => getTimeBinsForInterval(timeBins, plotType?.interval), [
+ timeBins,
+ plotType?.interval
+ ]);
const style = useMemo(
() => ({
@@ -130,7 +146,7 @@ export default function TimeRangeSliderFactory(
range={domain}
value0={value[0]}
value1={value[1]}
- histogram={histogram}
+ bins={binsForInterval}
lineChart={lineChart}
invertTrendColor={invertTrendColor}
plotType={plotType}
@@ -141,6 +157,7 @@ export default function TimeRangeSliderFactory(
xAxis={TimeSliderMarker}
timezone={timezone}
timeFormat={timeFormat}
+ setFilterPlot={setFilterPlot}
/>
</div>
) : (
diff --git a/src/components/src/filter-animation-controller.tsx b/src/components/src/filter-animation-controller.tsx
index 9163dd238..ea31c109f 100644
--- a/src/components/src/filter-animation-controller.tsx
+++ b/src/components/src/filter-animation-controller.tsx
@@ -2,7 +2,7 @@
// Copyright contributors to the kepler.gl project
import React, {useCallback, useMemo} from 'react';
-import {getIntervalBins, getTimelineFromFilter} from '@kepler.gl/utils';
+import {getBinThresholds, getTimelineFromFilter} from '@kepler.gl/utils';
import {TimeRangeFilter} from '@kepler.gl/types';
import {ANIMATION_WINDOW} from '@kepler.gl/constants';
import AnimationControllerFactory from './common/animation-control/animation-controller';
@@ -32,22 +32,32 @@ function FilterAnimationControllerFactory(
setFilterAnimationTime,
children
}) => {
- const intervalBins = useMemo(() => getIntervalBins(filter), [filter]);
+ const binThresholds = useMemo(() => {
+ return getBinThresholds(filter.plotType?.interval, filter.domain);
+ }, [filter.plotType?.interval, filter.domain]);
- const steps = useMemo(
- () => (intervalBins ? intervalBins.map(x => x.x0) : null),
- [intervalBins]
- );
+ const steps = useMemo(() => {
+ if (binThresholds) {
+ const thresholds = [...binThresholds];
+ // pop last threshold
+ thresholds.pop();
+ return thresholds;
+ }
+
+ return null;
+ }, [binThresholds]);
const updateAnimation = useCallback(
value => {
switch (filter.animationWindow) {
case ANIMATION_WINDOW.interval: {
const idx = value[1];
- setFilterAnimationTime(filterIdx, 'value', [
- intervalBins[idx].x0,
- intervalBins[idx].x1 - 1
- ]);
+ if (idx < binThresholds.length - 1) {
+ setFilterAnimationTime(filterIdx, 'value', [
+ binThresholds[idx],
+ binThresholds[idx + 1] - 1
+ ]);
+ }
break;
}
default:
@@ -55,7 +65,7 @@ function FilterAnimationControllerFactory(
break;
}
},
- [filterIdx, intervalBins, filter.animationWindow, setFilterAnimationTime]
+ [filterIdx, binThresholds, filter.animationWindow, setFilterAnimationTime]
);
// if filter is synced merge the filter and animation config
diff --git a/src/components/src/filters/filter-panels/filter-panel-with-field-select.tsx b/src/components/src/filters/filter-panels/filter-panel-with-field-select.tsx
index 8763bfda6..cb6ffa79e 100644
--- a/src/components/src/filters/filter-panels/filter-panel-with-field-select.tsx
+++ b/src/components/src/filters/filter-panels/filter-panel-with-field-select.tsx
@@ -41,7 +41,7 @@ function FieldPanelWithFieldSelectFactory(
);
const onSourceDataSelector = useCallback(
- value => setFilter(idx, 'dataId', [value]),
+ value => setFilter(idx, 'dataId', value, 0),
[idx, setFilter]
);
@@ -81,7 +81,6 @@ function FieldPanelWithFieldSelectFactory(
<SourceDataSelector
inputTheme="secondary"
datasets={datasets}
- disabled={filter.freeze}
dataId={filter.dataId}
onSelect={onSourceDataSelector}
/>
diff --git a/src/components/src/filters/filter-panels/new-filter-panel.tsx b/src/components/src/filters/filter-panels/new-filter-panel.tsx
index 4ec5031e5..7844b2b7b 100644
--- a/src/components/src/filters/filter-panels/new-filter-panel.tsx
+++ b/src/components/src/filters/filter-panels/new-filter-panel.tsx
@@ -38,7 +38,7 @@ function NewFilterPanelFactory(
);
const onSourceDataSelector = useCallback(
- value => setFilter(idx, 'dataId', value),
+ value => setFilter(idx, 'dataId', value, 0),
[idx, setFilter]
);
@@ -64,7 +64,6 @@ function NewFilterPanelFactory(
<SourceDataSelector
inputTheme="secondary"
datasets={datasets}
- disabled={filter.freeze}
dataId={filter.dataId}
onSelect={onSourceDataSelector}
/>
diff --git a/src/components/src/filters/filter-panels/range-filter-panel.tsx b/src/components/src/filters/filter-panels/range-filter-panel.tsx
index c38eccf4e..796b10eab 100644
--- a/src/components/src/filters/filter-panels/range-filter-panel.tsx
+++ b/src/components/src/filters/filter-panels/range-filter-panel.tsx
@@ -14,8 +14,12 @@ function RangeFilterPanelFactory(
RangeFilterComponent: ReturnType<typeof RangeFilterFactory>
) {
const RangeFilterPanel: FilterPanelComponent<RangeFilter> = React.memo(
- ({idx, datasets, allAvailableFields, filter, removeFilter, setFilter}) => {
+ ({idx, datasets, allAvailableFields, filter, removeFilter, setFilter, setFilterPlot}) => {
const onSetFilter = useCallback(value => setFilter(idx, 'value', value), [idx, setFilter]);
+ const onSetFilterPlot = useCallback(
+ (newProp, valueIndex) => setFilterPlot(idx, newProp, valueIndex),
+ [idx, setFilterPlot]
+ );
return (
<div className="range-filter-panel">
@@ -29,7 +33,11 @@ function RangeFilterPanelFactory(
>
{filter.type && (
<div className="filter-panel__filter">
- <RangeFilterComponent filter={filter} setFilter={onSetFilter} />
+ <RangeFilterComponent
+ filter={filter}
+ setFilter={onSetFilter}
+ setFilterPlot={onSetFilterPlot}
+ />
</div>
)}
</FieldPanelWithFieldSelect>
diff --git a/src/components/src/filters/filter-panels/time-range-filter-panel.tsx b/src/components/src/filters/filter-panels/time-range-filter-panel.tsx
index 2615b1340..760f778c6 100644
--- a/src/components/src/filters/filter-panels/time-range-filter-panel.tsx
+++ b/src/components/src/filters/filter-panels/time-range-filter-panel.tsx
@@ -4,23 +4,56 @@
import React, {useCallback, useMemo} from 'react';
import styled from 'styled-components';
import TimeRangeFilterFactory from '../time-range-filter';
-import {Clock} from '../../common/icons';
+import {Add, Clock} from '../../common/icons';
import FieldPanelWithFieldSelectFactory from './filter-panel-with-field-select';
import {TimeRangeFilterPanelComponent} from './types';
import {isSideFilter, getTimelineFromFilter} from '@kepler.gl/utils';
+import FilterPanelHeaderFactory from '../../side-panel/filter-panel/filter-panel-header';
+import PanelHeaderActionFactory from '../../side-panel/panel-header-action';
+import SourceDataSelectorFactory from '../../side-panel/common/source-data-selector';
+import FieldSelectorFactory from '../../common/field-selector';
+import {FormattedMessage} from '@kepler.gl/localization';
+import {Button, StyledFilterContent} from '../../common/styled-components';
+import {getSupportedFilterFields} from './new-filter-panel';
+import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
+import TippyTooltip from '../../common/tippy-tooltip';
-TimeRangeFilterPanelFactory.deps = [FieldPanelWithFieldSelectFactory, TimeRangeFilterFactory];
+const SyncedDatasetsArea = styled.div`
+ display: flex;
+ flex-direction: column;
+ & > * + * {
+ margin-top: 10px;
+ }
+`;
+
+const SyncedDatasetFieldArea = styled.div`
+ padding: 10px;
+ border: ${props => props.theme.panelBorder};
+ .side-panel-section {
+ margin-bottom: 0;
+ }
+ & > * + * {
+ margin-top: 10px;
+ }
+`;
+
+TimeRangeFilterPanelFactory.deps = [
+ FieldPanelWithFieldSelectFactory,
+ TimeRangeFilterFactory,
+ FilterPanelHeaderFactory,
+ SourceDataSelectorFactory,
+ FieldSelectorFactory,
+ PanelHeaderActionFactory
+];
function TimeRangeFilterPanelFactory(
FieldPanelWithFieldSelect: ReturnType<typeof FieldPanelWithFieldSelectFactory>,
- TimeRangeFilter: ReturnType<typeof TimeRangeFilterFactory>
+ TimeRangeFilter: ReturnType<typeof TimeRangeFilterFactory>,
+ FilterPanelHeader: ReturnType<typeof FilterPanelHeaderFactory>,
+ SourceDataSelector: ReturnType<typeof SourceDataSelectorFactory>,
+ FieldSelector: ReturnType<typeof FieldSelectorFactory>,
+ PanelHeaderAction: ReturnType<typeof PanelHeaderActionFactory>
) {
- const StyledFieldPanelWithFieldSelect = styled(FieldPanelWithFieldSelect)`
- .field-selector {
- width: 90%;
- }
- `;
-
const TimeRangeFilterPanel: TimeRangeFilterPanelComponent = React.memo(
({
idx,
@@ -29,10 +62,25 @@ function TimeRangeFilterPanelFactory(
filter,
enlargeFilter,
setFilter,
+ setFilterPlot,
removeFilter,
toggleAnimation
}) => {
- const onSetFilter = useCallback(value => setFilter(idx, 'value', value), [idx, setFilter]);
+ const onSetFilterValue = useCallback(value => setFilter(idx, 'value', value), [
+ idx,
+ setFilter
+ ]);
+
+ const totalDatasetsNum = useMemo(() => Object.keys(datasets).length, [datasets]);
+ const datasetsWithTime = useMemo(() => getDatasetsWithTimeField(datasets), [datasets]);
+ const datasetsWithTimeNum = useMemo(() => Object.keys(datasetsWithTime).length, [
+ datasetsWithTime
+ ]);
+ const filterDatasetsNum = useMemo(() => filter.dataId.length, [filter]);
+ const onSetFilterPlot = useCallback(
+ (newProp, valueIndex) => setFilterPlot(idx, newProp, valueIndex),
+ [idx, setFilterPlot]
+ );
const isEnlarged = useMemo(() => !isSideFilter(filter), [filter]);
@@ -49,32 +97,151 @@ function TimeRangeFilterPanelFactory(
[filter.id, isEnlarged, enlargeFilter]
);
+ const onAddSyncedFilter = () => {
+ const nextId = Object.keys(datasetsWithTime).find(id => !filter.dataId.includes(id));
+ if (!nextId) return;
+ const timeFieldNames = getTimeFields(datasets[nextId])?.map(f => f.name);
+ if (!timeFieldNames || timeFieldNames.length < 1) return;
+ const nextName = timeFieldNames.includes(filter.name[0])
+ ? filter.name[0]
+ : timeFieldNames[0];
+ setFilter(idx, ['dataId', 'name'], [nextId, nextName], filter.dataId.length);
+ };
+
+ const onRemoveSyncedFilter = valueIndex => {
+ setFilter(idx, 'dataId', null, valueIndex);
+ };
+
+ const onSelectSyncedDataset = (datasetId, valueIndex) => {
+ setFilter(idx, 'dataId', datasetId, valueIndex);
+ };
+
+ const onFieldSelector = (field, valueIndex) => setFilter(idx, 'name', field.name, valueIndex);
+
+ const onSourceDataSelector = useCallback(value => setFilter(idx, 'dataId', value, 0), [
+ idx,
+ setFilter
+ ]);
+
+ const dataset = datasets[filter.dataId[0]];
+ const supportedFields = useMemo(
+ () => getSupportedFilterFields(dataset.supportedFilterTypes, allAvailableFields),
+ [dataset.supportedFilterTypes, allAvailableFields]
+ );
+
const timeline = getTimelineFromFilter(filter);
return (
<>
- <StyledFieldPanelWithFieldSelect
- allAvailableFields={allAvailableFields}
- datasets={datasets}
- filter={filter}
+ <FilterPanelHeader
+ datasets={[dataset]}
+ allAvailableFields={supportedFields}
idx={idx}
+ filter={filter}
removeFilter={removeFilter}
- setFilter={setFilter}
- panelActions={panelActions}
>
+ <FieldSelector
+ inputTheme="secondary"
+ fields={supportedFields}
+ value={Array.isArray(filter.name) ? filter.name[0] : filter.name}
+ erasable={false}
+ onSelect={field => onFieldSelector(field, 0)}
+ />
+ {panelActions &&
+ panelActions.map(panelAction => (
+ <PanelHeaderAction
+ id={panelAction.id}
+ key={panelAction.id}
+ onClick={panelAction.onClick}
+ tooltip={panelAction.tooltip}
+ IconComponent={panelAction.iconComponent}
+ active={panelAction.active}
+ />
+ ))}
+ </FilterPanelHeader>
+ <StyledFilterContent className="filter-panel__content">
+ {totalDatasetsNum > 1 && (
+ <SyncedDatasetsArea>
+ {/* Only shon when there fiter is not synced */}
+ <SourceDataSelector
+ inputTheme="secondary"
+ datasets={datasets}
+ dataId={Array.isArray(filter.dataId) ? filter.dataId[0] : filter.dataId}
+ onSelect={onSourceDataSelector}
+ />
+
+ {filter.dataId.slice(1).map((dataId, index) => {
+ const filteredDatasets = {...datasets};
+ for (const id of filter.dataId) {
+ // remove others which are already in the filter
+ if (id !== dataId) delete filteredDatasets[id];
+ }
+ const valueIndex = index + 1;
+ return (
+ <SyncedDatasetFieldArea key={dataId}>
+ <FilterPanelHeader
+ datasets={[datasets[dataId]]}
+ allAvailableFields={supportedFields}
+ idx={idx}
+ filter={filter}
+ removeFilter={() => onRemoveSyncedFilter(valueIndex)}
+ >
+ <FieldSelector
+ inputTheme="secondary"
+ fields={getTimeFields(datasets[dataId])}
+ value={filter.name[valueIndex]}
+ erasable={false}
+ onSelect={field => onFieldSelector(field, valueIndex)}
+ />
+ </FilterPanelHeader>
+
+ <SourceDataSelector
+ inputTheme="secondary"
+ datasets={filteredDatasets}
+ disabled={filterDatasetsNum >= datasetsWithTimeNum}
+ dataId={dataId}
+ onSelect={datasetId => onSelectSyncedDataset(datasetId, valueIndex)}
+ />
+ </SyncedDatasetFieldArea>
+ );
+ })}
+
+ {filterDatasetsNum < datasetsWithTimeNum && (
+ <div>
+ <TippyTooltip
+ delay={[500, 0]}
+ placement="top"
+ render={() => (
+ <div>
+ <FormattedMessage id={'tooltip.timeFilterSync'} />
+ </div>
+ )}
+ >
+ <Button className="add-sync-dataset" small={true} onClick={onAddSyncedFilter}>
+ <Add height="12px" />
+ <FormattedMessage id={'filterManager.timeFilterSync'} />
+ </Button>
+ </TippyTooltip>
+ </div>
+ )}
+ </SyncedDatasetsArea>
+ )}
{filter.type && !isEnlarged && (
<div className="filter-panel__filter">
<TimeRangeFilter
filter={filter}
+ datasets={datasets}
+ idx={idx}
toggleAnimation={toggleAnimation}
- setFilter={onSetFilter}
+ setFilter={onSetFilterValue}
+ setFilterPlot={onSetFilterPlot}
isAnimatable
hideTimeTitle
timeline={timeline}
/>
</div>
)}
- </StyledFieldPanelWithFieldSelect>
+ </StyledFilterContent>
</>
);
}
@@ -86,3 +253,20 @@ function TimeRangeFilterPanelFactory(
}
export default TimeRangeFilterPanelFactory;
+
+const TIME_FIELD_ANALYZER_TYPES = ['DATE', 'TIME', 'DATETIME'];
+
+function getDatasetsWithTimeField(datasets) {
+ const rv = {};
+ for (const id of Object.keys(datasets)) {
+ // TODO: change to
+ if (datasets[id].fields.some(f => f.type === ALL_FIELD_TYPES.timestamp)) {
+ rv[id] = datasets[id];
+ }
+ }
+ return rv;
+}
+
+function getTimeFields(dataset) {
+ return dataset.fields.filter(f => TIME_FIELD_ANALYZER_TYPES.includes(f.analyzerType));
+}
diff --git a/src/components/src/filters/filter-panels/types.ts b/src/components/src/filters/filter-panels/types.ts
index ac57b3f50..a17c5210d 100644
--- a/src/components/src/filters/filter-panels/types.ts
+++ b/src/components/src/filters/filter-panels/types.ts
@@ -5,6 +5,7 @@ import {FunctionComponent, ComponentType, ReactNode} from 'react';
import {Filter, PolygonFilter, TimeRangeFilter, Field} from '@kepler.gl/types';
import {Layer} from '@kepler.gl/layers';
import {Datasets} from '@kepler.gl/table';
+import {setFilter, setFilterPlot} from '@kepler.gl/actions';
interface PanelAction {
id: string;
@@ -20,7 +21,8 @@ export interface FilterPanelProps<F = Filter> {
allAvailableFields: Field[];
filter: F;
removeFilter: () => void;
- setFilter: (idx: number, field: string, value: any) => void;
+ setFilter: (...args: Parameters<typeof setFilter>) => void;
+ setFilterPlot: (...args: Parameters<typeof setFilterPlot>) => void;
children?: ReactNode;
}
export interface PolygonFilterPanelProps extends FilterPanelProps<PolygonFilter> {
@@ -38,5 +40,6 @@ export interface FilterPanelWithFieldSelectProps extends FilterPanelProps {
export type FilterPanelComponent<F> = FunctionComponent<FilterPanelProps<F>>;
export type PolygonFilterPanelComponent = FunctionComponent<PolygonFilterPanelProps>;
export type TimeRangeFilterPanelComponent = FunctionComponent<TimeRangeFilterPanelProps>;
-export type FilterPanelWithFieldSelectComponent =
- FunctionComponent<FilterPanelWithFieldSelectProps>;
+export type FilterPanelWithFieldSelectComponent = FunctionComponent<
+ Omit<FilterPanelWithFieldSelectProps, 'setFilterPlot'>
+>;
diff --git a/src/components/src/filters/range-filter.tsx b/src/components/src/filters/range-filter.tsx
index 8b72d8e99..076a190dd 100644
--- a/src/components/src/filters/range-filter.tsx
+++ b/src/components/src/filters/range-filter.tsx
@@ -9,20 +9,25 @@ import {RangeFilterProps} from './types';
RangeFilterFactory.deps = [RangeSliderFactory];
export default function RangeFilterFactory(RangeSlider: ReturnType<typeof RangeSliderFactory>) {
- const RangeFilter: React.FC<RangeFilterProps> = ({filter, setFilter}) => (
- <div>
- <RangeSlider
- range={filter.domain}
- value0={filter.value[0]}
- value1={filter.value[1]}
- step={filter.step}
- histogram={filter.histogram}
- isEnlarged={filter.view === FILTER_VIEW_TYPES.enlarged}
- onChange={setFilter}
- inputTheme="secondary"
- />
- </div>
- );
+ const RangeFilter: React.FC<RangeFilterProps> = ({filter, setFilter, setFilterPlot}) => {
+ const isEnlarged = filter.view === FILTER_VIEW_TYPES.enlarged;
+ return (
+ <div>
+ <RangeSlider
+ range={filter.domain}
+ value0={filter.value[0]}
+ value1={filter.value[1]}
+ step={filter.step}
+ bins={filter.bins}
+ isEnlarged={isEnlarged}
+ onChange={setFilter}
+ setFilterPlot={setFilterPlot}
+ inputTheme="secondary"
+ plotType={filter.plotType}
+ />
+ </div>
+ );
+ };
return RangeFilter;
}
diff --git a/src/components/src/filters/time-range-filter.tsx b/src/components/src/filters/time-range-filter.tsx
index 668aa325f..29ee1cf97 100644
--- a/src/components/src/filters/time-range-filter.tsx
+++ b/src/components/src/filters/time-range-filter.tsx
@@ -9,7 +9,7 @@ import {TimeRangeFilterProps} from './types';
/*
* TimeRangeFilter -> TimeRangeSlider -> RangeSlider
*/
-export function timeRangeSliderFieldsSelector(filter: TimeRangeFilter) {
+export function timeRangeSliderFieldsSelector(filter: TimeRangeFilter, datasets) {
const hasUserFormat = typeof filter.timeFormat === 'string';
const timeFormat =
(hasUserFormat ? filter.timeFormat : filter.defaultTimeFormat) || DEFAULT_TIME_FORMAT;
@@ -17,19 +17,19 @@ export function timeRangeSliderFieldsSelector(filter: TimeRangeFilter) {
return {
id: filter.id,
domain: filter.domain,
- bins: filter.bins,
+ timeBins: filter.timeBins,
value: filter.value,
plotType: filter.plotType,
lineChart: filter.lineChart,
yAxis: filter.yAxis,
step: filter.step,
speed: filter.speed,
- histogram:
- filter.view === FILTER_VIEW_TYPES.enlarged ? filter.enlargedHistogram : filter.histogram,
animationWindow: filter.animationWindow,
isAnimating: filter.isAnimating,
timezone: filter.timezone,
timeFormat,
+ filter,
+ datasets,
isMinified: filter.view === FILTER_VIEW_TYPES.minified,
isEnlarged: filter.view === FILTER_VIEW_TYPES.enlarged
};
@@ -40,15 +40,18 @@ TimeRangeFilterFactory.deps = [TimeRangeSliderFactory];
function TimeRangeFilterFactory(TimeRangeSlider: ReturnType<typeof TimeRangeSliderFactory>) {
const TimeRangeFilterComponent: React.FC<TimeRangeFilterProps> = ({
filter,
+ datasets,
setFilter,
+ setFilterPlot,
isAnimatable,
toggleAnimation,
hideTimeTitle,
timeline
}) => (
<TimeRangeSlider
- {...timeRangeSliderFieldsSelector(filter)}
+ {...timeRangeSliderFieldsSelector(filter, datasets)}
onChange={setFilter}
+ setFilterPlot={setFilterPlot}
toggleAnimation={toggleAnimation}
isAnimatable={isAnimatable}
hideTimeTitle={hideTimeTitle}
diff --git a/src/components/src/filters/time-widget-top.tsx b/src/components/src/filters/time-widget-top.tsx
index f65b3b127..3fba9dbbd 100644
--- a/src/components/src/filters/time-widget-top.tsx
+++ b/src/components/src/filters/time-widget-top.tsx
@@ -89,7 +89,6 @@ function TimeWidgetTopFactory(FieldSelector: ReturnType<typeof FieldSelectorFact
readOnly,
datasets,
setFilterPlot,
- index,
onClose,
isMinified,
onToggleMinify
@@ -102,8 +101,8 @@ function TimeWidgetTopFactory(FieldSelector: ReturnType<typeof FieldSelectorFact
[datasets, filter.dataId]
);
const _setFilterPlotYAxis = useCallback(
- value => setFilterPlot(index, {yAxis: value}),
- [setFilterPlot, index]
+ value => setFilterPlot({yAxis: value}),
+ [setFilterPlot]
);
return (
diff --git a/src/components/src/filters/time-widget.tsx b/src/components/src/filters/time-widget.tsx
index d3d2360b5..f435838b9 100644
--- a/src/components/src/filters/time-widget.tsx
+++ b/src/components/src/filters/time-widget.tsx
@@ -58,13 +58,18 @@ function TimeWidgetFactory(
[setFilterAnimationTime, index]
);
+ const _setFilterPlot = useCallback(
+ (newProp, valueIndex) => setFilterPlot(index, newProp, valueIndex),
+ [index, setFilterPlot]
+ );
+
return (
<TimeBottomWidgetInner className="bottom-widget--inner">
<TimeWidgetTop
filter={filter}
readOnly={readOnly}
datasets={datasets}
- setFilterPlot={setFilterPlot}
+ setFilterPlot={_setFilterPlot}
index={index}
onClose={onClose}
onToggleMinify={_onToggleMinify}
@@ -73,7 +78,7 @@ function TimeWidgetFactory(
{/* Once AnimationControl is able to display large timeline*/}
{/* we can replace TimeRangeSlider with AnimationControl*/}
<TimeRangeSlider
- {...timeRangeSliderFieldsSelector(filter)}
+ {...timeRangeSliderFieldsSelector(filter, datasets)}
onChange={timeSliderOnChange}
toggleAnimation={_toggleAnimation}
updateAnimationSpeed={_updateAnimationSpeed}
@@ -81,6 +86,7 @@ function TimeWidgetFactory(
hideTimeTitle={showTimeDisplay}
resetAnimation={resetAnimation}
isAnimatable={isAnimatable}
+ setFilterPlot={_setFilterPlot}
isMinified={isMinified}
timeline={timeline}
/>
diff --git a/src/components/src/filters/types.ts b/src/components/src/filters/types.ts
index 07cf754cc..75c093105 100644
--- a/src/components/src/filters/types.ts
+++ b/src/components/src/filters/types.ts
@@ -33,15 +33,19 @@ export type TopSectionWrapperProps = {
export type RangeFilterProps = {
filter: RangeFilter;
setFilter: (v: number[]) => void;
+ setFilterPlot?: ActionHandler<typeof setFilterPlot>;
};
export type TimeRangeFilterProps = {
+ idx: number;
filter: TimeRangeFilter;
isAnimatable: boolean;
hideTimeTitle: boolean;
setFilter: (v: number[]) => void;
+ setFilterPlot: ActionHandler<typeof setFilterPlot>;
toggleAnimation: () => void;
timeline: Timeline;
+ datasets: Datasets;
};
export type SingleSelectFilterProps = {
@@ -60,7 +64,7 @@ export type TimeWidgetTopProps = {
filter: Filter;
readOnly: boolean;
datasets: Datasets;
- setFilterPlot: ActionHandler<typeof setFilterPlot>;
+ setFilterPlot: (newProp, valueIndex?: number) => void;
index: number;
onClose: () => void;
onToggleMinify: () => void;
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 2c16cc034..6d1357341 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -335,15 +335,15 @@ export default function MapContainerFactory(
primary: true
};
+ constructor(props) {
+ super(props);
+ }
+
state = {
// Determines whether attribution should be visible based the result of loading the map style
showMapboxAttribution: true
};
- constructor(props) {
- super(props);
- }
-
componentDidMount() {
if (!this._ref.current) {
return;
diff --git a/src/components/src/side-panel/filter-manager.tsx b/src/components/src/side-panel/filter-manager.tsx
index 1451a7965..425e43736 100644
--- a/src/components/src/side-panel/filter-manager.tsx
+++ b/src/components/src/side-panel/filter-manager.tsx
@@ -74,8 +74,14 @@ function FilterManagerFactory(
isAnyFilterAnimating,
visStateActions
}: FilterListProps) => {
- const {removeFilter, setFilter, toggleFilterAnimation, toggleFilterFeature, setFilterView} =
- visStateActions;
+ const {
+ removeFilter,
+ setFilter,
+ setFilterPlot,
+ toggleFilterAnimation,
+ toggleFilterFeature,
+ setFilterView
+ } = visStateActions;
const filterPanelCallbacks = useMemo(() => {
return filtersByIndex.reduce(
@@ -112,6 +118,7 @@ function FilterManagerFactory(
toggleAnimation={filterPanelCallbacks[filter.id].toggleAnimation}
toggleFilterFeature={filterPanelCallbacks[filter.id].toggleFilterFeature}
setFilter={setFilter}
+ setFilterPlot={setFilterPlot}
/>
))}
</SidePanelSection>
diff --git a/src/components/src/side-panel/filter-panel/filter-panel-header.tsx b/src/components/src/side-panel/filter-panel/filter-panel-header.tsx
index 0b6352496..21572ed8a 100644
--- a/src/components/src/side-panel/filter-panel/filter-panel-header.tsx
+++ b/src/components/src/side-panel/filter-panel/filter-panel-header.tsx
@@ -7,7 +7,7 @@ import PanelHeaderActionFactory from '../../side-panel/panel-header-action';
import {Trash} from '../../common/icons';
import {createLinearGradient} from '@kepler.gl/utils';
import {StyledPanelHeader, StyledPanelHeaderProps} from '../../common/styled-components';
-import {RGBColor, Filter} from '@kepler.gl/types';
+import {RGBColor, Filter, Field} from '@kepler.gl/types';
import {KeplerTable} from '@kepler.gl/table';
interface StyledFilterHeaderProps extends StyledPanelHeaderProps {
@@ -44,6 +44,8 @@ export type FilterPanelHeaderProps = {
actionIcons?: {
delete: ComponentType;
};
+ allAvailableFields?: Field[];
+ idx?: number;
children: React.ReactNode;
};
diff --git a/src/constants/src/index.ts b/src/constants/src/index.ts
index 3de256605..4a341a94a 100644
--- a/src/constants/src/index.ts
+++ b/src/constants/src/index.ts
@@ -13,3 +13,4 @@ export * from './tooltip';
export * from './user-feedbacks';
export * from './user-guides';
export * from './dnd-layer-items';
+export * from './time';
diff --git a/src/constants/src/plot.ts b/src/constants/src/plot.ts
new file mode 100644
index 000000000..45cb2307e
--- /dev/null
+++ b/src/constants/src/plot.ts
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import keyMirror from 'keymirror';
+
+export const PLOT_TYPES = keyMirror({
+ histogram: null,
+ lineChart: null
+});
diff --git a/src/constants/src/time.ts b/src/constants/src/time.ts
new file mode 100644
index 000000000..562d13ab0
--- /dev/null
+++ b/src/constants/src/time.ts
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import keyMirror from 'keymirror';
+import {AGGREGATION_TYPES, PLOT_TYPES} from './';
+
+import {
+ utcDay,
+ utcHour,
+ utcMillisecond,
+ utcMinute,
+ utcMonth,
+ utcSecond,
+ utcWeek,
+ utcYear
+} from 'd3-time';
+
+type ValueOf<T> = T[keyof T];
+
+export interface IntervalOption {
+ label: string;
+ id: string;
+}
+
+export interface TimeAggregation {
+ label: string;
+ id: string;
+}
+
+export interface TimeIntervals {
+ year: any;
+ month: any;
+ week: any;
+ day: any;
+ hour: any;
+ minute: any;
+ second: any;
+ millisecond: any;
+}
+
+export interface Durations {
+ years: number;
+ months: number;
+ weeks: number;
+ days: number;
+ hours: number;
+ minutes: number;
+ seconds: number;
+ milliseconds: number;
+}
+
+export interface AnimatinWindow {
+ free: string;
+ interval: string;
+}
+
+export type TimeInterval = string; // TODO: TimeInterval should be an enum
+
+export interface TickInterval {
+ interval: TimeInterval;
+ step: number;
+ duration: number;
+}
+
+export interface TickIntervals {
+ [key: ValueOf<Interval>]: TickInterval;
+}
+
+export interface Interval {
+ '1-second': string;
+ '5-second': string;
+ '15-second': string;
+ '30-second': string;
+ '1-minute': string;
+ '5-minute': string;
+ '15-minute': string;
+ '30-minute': string;
+ '1-hour': string;
+ '3-hour': string;
+ '6-hour': string;
+ '12-hour': string;
+ '1-day': string;
+ '2-day': string;
+ '1-week': string;
+ '1-month': string;
+ '3-month': string;
+ '1-year': string;
+}
+
+export interface AnimationType {
+ continuous: string;
+ interval: string;
+}
+
+export type AnimationWindow = any;
+
+export const durationMillisecond = 1;
+export const durationSecond = 1000;
+export const durationMinute = durationSecond * 60;
+export const durationHour = durationMinute * 60;
+export const durationDay = durationHour * 24;
+export const durationWeek = durationDay * 7;
+export const durationMonth = durationDay * 30;
+export const durationYear = durationDay * 365;
+
+// moment.duration functions
+export const DURATIONS: Durations = {
+ years: durationYear,
+ months: durationMonth,
+ weeks: durationWeek,
+ days: durationDay,
+ hours: durationHour,
+ minutes: durationMinute,
+ seconds: durationSecond,
+ milliseconds: durationMillisecond
+};
+
+// interval key to d3 time interval function
+export const TIME_INTERVALS: TimeIntervals = {
+ year: utcYear,
+ month: utcMonth,
+ week: utcWeek,
+ day: utcDay,
+ hour: utcHour,
+ minute: utcMinute,
+ second: utcSecond,
+ millisecond: utcMillisecond
+};
+
+export const INTERVAL: Interval = keyMirror({
+ '1-second': null,
+ '5-second': null,
+ '15-second': null,
+ '30-second': null,
+ '1-minute': null,
+ '5-minute': null,
+ '15-minute': null,
+ '30-minute': null,
+ '1-hour': null,
+ '3-hour': null,
+ '6-hour': null,
+ '12-hour': null,
+ '1-day': null,
+ '2-day': null,
+ '1-week': null,
+ '1-month': null,
+ '3-month': null,
+ '1-year': null
+});
+
+// interval eligible for calculate week over week
+export const WOW: {
+ [key: ValueOf<Interval>]: number;
+} = {
+ [INTERVAL['1-day']]: 7,
+ [INTERVAL['1-week']]: 1
+};
+
+export const INTERVAL_OPTIONS: IntervalOption[] = Object.keys(INTERVAL).map(id => {
+ const [step, interval] = id.split('-');
+ // capitalizeFirstLetter(interval)
+ return {id, label: `${step} ${interval}`};
+});
+
+export const TICK_INTERVALS: TickIntervals = {
+ [INTERVAL['1-millisecond']]: {interval: 'millisecond', step: 1, duration: durationMillisecond},
+ [INTERVAL['1-second']]: {interval: 'second', step: 1, duration: durationSecond},
+ [INTERVAL['5-second']]: {interval: 'second', step: 5, duration: 5 * durationSecond},
+ [INTERVAL['15-second']]: {interval: 'second', step: 15, duration: 15 * durationSecond},
+ [INTERVAL['30-second']]: {interval: 'second', step: 30, duration: 30 * durationSecond},
+ [INTERVAL['1-minute']]: {interval: 'minute', step: 1, duration: durationMinute},
+ [INTERVAL['5-minute']]: {interval: 'minute', step: 5, duration: 5 * durationMinute},
+ [INTERVAL['15-minute']]: {interval: 'minute', step: 15, duration: 15 * durationMinute},
+ [INTERVAL['30-minute']]: {interval: 'minute', step: 30, duration: 30 * durationMinute},
+ [INTERVAL['1-hour']]: {interval: 'hour', step: 1, duration: durationHour},
+ [INTERVAL['3-hour']]: {interval: 'hour', step: 3, duration: 3 * durationHour},
+ [INTERVAL['6-hour']]: {interval: 'hour', step: 6, duration: 6 * durationHour},
+ [INTERVAL['12-hour']]: {interval: 'hour', step: 12, duration: 12 * durationHour},
+ [INTERVAL['1-day']]: {interval: 'day', step: 1, duration: durationDay},
+ [INTERVAL['2-day']]: {interval: 'day', step: 2, duration: 2 * durationDay},
+ [INTERVAL['1-week']]: {interval: 'week', step: 1, duration: durationWeek},
+ [INTERVAL['1-month']]: {interval: 'month', step: 1, duration: durationMonth},
+ [INTERVAL['3-month']]: {interval: 'month', step: 3, duration: 3 * durationMonth},
+ [INTERVAL['1-year']]: {interval: 'year', step: 1, duration: durationYear}
+};
+
+export const PLOT_TYPE_OPTIONS = {
+ [PLOT_TYPES.lineChart]: {
+ id: PLOT_TYPES.lineChart,
+ label: 'Chart',
+ icon: 'LineChart'
+ },
+ [PLOT_TYPES.histogram]: {
+ id: PLOT_TYPES.histogram,
+ label: 'Histogram',
+ icon: 'Histogram'
+ }
+};
+
+export const BINS_LARGE = 100;
+export const BINS = 30;
+
+export const TIME_AGGREGATION: TimeAggregation[] = [
+ {
+ id: AGGREGATION_TYPES.average,
+ label: 'Average'
+ },
+ {
+ id: AGGREGATION_TYPES.sum,
+ label: 'Sum'
+ },
+ {
+ id: AGGREGATION_TYPES.maximum,
+ label: 'Maximum'
+ },
+ {
+ id: AGGREGATION_TYPES.minimum,
+ label: 'Minimum'
+ },
+ {
+ id: AGGREGATION_TYPES.median,
+ label: 'Median'
+ },
+ {
+ id: AGGREGATION_TYPES.stdev,
+ label: 'Std Deviation'
+ }
+];
+
+export const ANIMATION_TYPE: AnimationType = keyMirror({
+ interval: null,
+ continuous: null
+});
diff --git a/src/deckgl-layers/package.json b/src/deckgl-layers/package.json
index 87c2068f8..268ebc190 100644
--- a/src/deckgl-layers/package.json
+++ b/src/deckgl-layers/package.json
@@ -42,7 +42,7 @@
"@luma.gl/core": "^8.5.20",
"@mapbox/geo-viewport": "^0.4.1",
"@mapbox/vector-tile": "^1.3.1",
- "@types/d3-array": "^2.0.0",
+ "@types/d3-array": "^2.8.0",
"@types/geojson": "^7946.0.8",
"@types/lodash.memoize": "^4.1.7",
"@types/supercluster": "^7.1.0",
diff --git a/src/layers/src/mapbox-utils.ts b/src/layers/src/mapbox-utils.ts
index 45ad5c6b6..f0ea0afb9 100644
--- a/src/layers/src/mapbox-utils.ts
+++ b/src/layers/src/mapbox-utils.ts
@@ -184,13 +184,13 @@ export function gpuFilterToMapboxFilter(gpuFilter) {
// [">=", key, value]
// ["<=", key, value]
- const expressions = Object.values(filterValueUpdateTriggers).reduce(
- (accu: any[], name, i) =>
- name
+ const expressions = Object.values(filterValueUpdateTriggers as ({name: string} | null)[]).reduce(
+ (accu: any[], gpu, i) =>
+ gpu?.name
? [
...accu,
- ['>=', prefixGpuField(name), filterRange[i][0]],
- ['<=', prefixGpuField(name), filterRange[i][1]]
+ ['>=', prefixGpuField(gpu.name), filterRange[i][0]],
+ ['<=', prefixGpuField(gpu.name), filterRange[i][1]]
]
: accu,
condition
diff --git a/src/layers/src/mapboxgl-layer.ts b/src/layers/src/mapboxgl-layer.ts
index 0f06924ae..3e23efa19 100644
--- a/src/layers/src/mapboxgl-layer.ts
+++ b/src/layers/src/mapboxgl-layer.ts
@@ -131,10 +131,10 @@ class MapboxLayerGL extends Layer {
const getPropertyFromFilter = hasFilter
? d => {
const filterValue = valueAccessor(d);
- return Object.values(filterValueUpdateTriggers).reduce<{[id: string]: number | number[]}>(
- (accu: any, name, i) => ({
+ return Object.values(filterValueUpdateTriggers as ({name: string} | null)[]).reduce(
+ (accu: any, gpu, i) => ({
...accu,
- ...(name ? {[prefixGpuField(name)]: filterValue[i]} : {})
+ ...(gpu?.name ? {[prefixGpuField(gpu.name)]: filterValue[i]} : {})
}),
{} as {[id: string]: number | number[]}
);
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index 60b1ab10d..8aadbcc63 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -194,7 +194,9 @@ export default {
howTo: 'How to'
},
filterManager: {
- addFilter: 'Add Filter'
+ addFilter: 'Add Filter',
+ timeFilterSync: 'Sync with…',
+ column: 'Column'
},
datasetTitle: {
showDataTable: 'Show data table',
@@ -228,6 +230,7 @@ export default {
removeBaseMapStyle: 'Remove base map style',
delete: 'Delete',
timePlayback: 'Time Playback',
+ timeFilterSync: 'Sync with a column from another dataset',
cloudStorage: 'Cloud Storage',
'3DMap': '3D Map',
animationByWindow: 'Moving Time Window',
diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts
index da6173d35..04afb0e28 100644
--- a/src/reducers/src/vis-state-updaters.ts
+++ b/src/reducers/src/vis-state-updaters.ts
@@ -48,6 +48,7 @@ import {
parseFieldValue,
applyFilterFieldName,
applyFiltersToDatasets,
+ adjustValueToFilterDomain,
featureToFilterValue,
filterDatasetCPU,
FILTER_UPDATER_PROPS,
@@ -56,10 +57,9 @@ import {
getFilterIdInFeature,
getTimeWidgetTitleFormatter,
isInRange,
- LIMITED_FILTER_EFFECT_PROPS,
- updateFilterDataId,
- getFilterPlot,
- getDefaultFilterPlotType
+ mergeFilterDomainStep,
+ updateFilterPlot,
+ removeFilterPlot
} from '@kepler.gl/utils';
// Mergers
@@ -81,7 +81,8 @@ import {
MAX_DEFAULT_TOOLTIPS,
DEFAULT_TEXT_LABEL,
COMPARE_TYPES,
- LIGHT_AND_SHADOW_EFFECT
+ LIGHT_AND_SHADOW_EFFECT,
+ PLOT_TYPES
} from '@kepler.gl/constants';
import {
pick_,
@@ -887,6 +888,7 @@ export function setFilterAnimationWindowUpdater(
)
};
}
+
/**
* Update filter property
* @memberof visStateUpdaters
@@ -896,55 +898,164 @@ export function setFilterUpdater(
state: VisState,
action: VisStateActions.SetFilterUpdaterAction
): VisState {
- const {idx, prop, value, valueIndex = 0} = action;
+ const {idx, valueIndex = 0} = action;
const oldFilter = state.filters[idx];
-
if (!oldFilter) {
Console.error(`filters.${idx} is undefined`);
return state;
}
- let newFilter = set([prop], value, oldFilter);
+ if (
+ Array.isArray(action.prop) &&
+ (!Array.isArray(action.value) || action.prop.length !== action.value.length)
+ ) {
+ Console.error('Expecting value to be an array of the same length, since prop is an array');
+ return state;
+ }
+ // convert prop and value to array
+ const props = toArray(action.prop);
+ const values = Array.isArray(action.prop) ? toArray(action.value) : [action.value];
+
+ let newFilter = oldFilter;
let newState = state;
- const {dataId} = newFilter;
+ let datasetIdsToFilter: string[] = [];
+ for (let i = 0; i < props.length; i++) {
+ const prop = props[i];
+ const value = values[i];
+ const res = _updateFilterProp(newState, newFilter, prop, value, valueIndex);
+ newFilter = res.filter;
+ newState = res.state;
+ datasetIdsToFilter = datasetIdsToFilter.concat(res.datasetIdsToFilter);
+ }
+
+ const enlargedFilter = state.filters.find(f => f.view === FILTER_VIEW_TYPES.enlarged);
+
+ if (enlargedFilter && enlargedFilter.id !== newFilter.id) {
+ // there should be only one enlarged filter
+ newFilter.view = FILTER_VIEW_TYPES.side;
+ }
+
+ // save new filters to newState
+ newState = set(['filters', idx], newFilter, newState);
+
+ // filter data
+ const filteredDatasets = applyFiltersToDatasets(
+ uniq(datasetIdsToFilter),
+ newState.datasets,
+ newState.filters,
+ newState.layers
+ );
+
+ newState = set(['datasets'], filteredDatasets, newState);
+
+ // need to update filterPlot after filter Dataset for plot to update on filtered result
+ const filterWithPLot = updateFilterPlot(newState.datasets, newState.filters[idx]);
+
+ newState = set(['filters', idx], filterWithPLot, newState);
+
+ // dataId is an array
+ // pass only the dataset we need to update
+ newState = updateAllLayerDomainData(newState, datasetIdsToFilter, newFilter);
+
+ return newState;
+}
+function _updateFilterDataIdAtValueIndex(filter, valueIndex, value, datasets) {
+ let newFilter = filter;
+ if (filter.dataId[valueIndex]) {
+ // if dataId already exist
+ newFilter = _removeFilterDataIdAtValueIndex(filter, valueIndex, datasets);
+ }
+ if (value) {
+ const nextValue = newFilter.dataId.slice();
+ nextValue[valueIndex] = value;
+ newFilter = set(['dataId'], nextValue, newFilter);
+ }
+ return newFilter;
+}
+
+function _removeFilterDataIdAtValueIndex(filter, valueIndex, datasets) {
+ const dataId = filter.dataId[valueIndex];
+
+ if (filter.dataId.length === 1 && valueIndex === 0) {
+ // if remove the only dataId, create an empty filter instead;
+ return getDefaultFilter({id: filter.id});
+ }
+
+ if (dataId) {
+ filter = removeFilterPlot(filter, dataId);
+ }
+
+ for (const prop of ['dataId', 'name', 'fieldIdx', 'gpuChannel']) {
+ if (Array.isArray(filter[prop])) {
+ const nextVal = filter[prop].slice();
+ nextVal.splice(valueIndex, 1);
+ filter = set([prop], nextVal, filter);
+ }
+ }
+
+ // mergeFieldDomain for the remaining fields
+ // @ts-expect-error figure out correct types to use with mergeFilterDomainStep
+ let domainSteps: Filter & {step?: number | undefined} = {};
+ filter.dataId.forEach((filterDataId, idx) => {
+ const dataset = datasets[filterDataId];
+ const filterProps = dataset.getColumnFilterProps(filter.name[idx]);
+ // @ts-expect-error figure out correct types to use with mergeFilterDomainStep
+ domainSteps = mergeFilterDomainStep(domainSteps, filterProps);
+ });
+
+ const nextFilter = {
+ ...filter,
+ // value: nextValue,
+ domain: domainSteps.domain,
+ step: domainSteps.step
+ };
- // Ensuring backward compatibility
- let datasetIds = toArray(dataId);
+ const nextValue = adjustValueToFilterDomain(nextFilter.value, nextFilter);
+ return {
+ ...nextFilter,
+ value: nextValue
+ };
+}
+/***
+ * Updates a single property of a filter
+ */
+function _updateFilterProp(state, filter, prop, value, valueIndex, datasetIds?) {
+ let datasetIdsToFilter: string[] = [];
switch (prop) {
- // TODO: Next PR for UI if we update dataId, we need to consider two cases:
+ // TODO: Next PR for UI if we update filterDataId, we need to consider two cases:
// 1. dataId is empty: create a default filter
// 2. Add a new dataset id
- case FILTER_UPDATER_PROPS.dataId:
- // if trying to update filter dataId. create an empty new filter
- newFilter = updateFilterDataId(dataId);
+ case FILTER_UPDATER_PROPS.dataId: {
+ const oldDataId = [...filter.dataId];
+ filter = _updateFilterDataIdAtValueIndex(filter, valueIndex, value, state.datasets);
+ datasetIdsToFilter = uniq([...oldDataId, ...filter.dataId]);
break;
-
+ }
case FILTER_UPDATER_PROPS.name: {
// we are supporting the current functionality
// TODO: Next PR for UI filter name will only update filter name but it won't have side effects
// we are gonna use pair of datasets and fieldIdx to update the filter
- const datasetId = newFilter.dataId[valueIndex];
+ const datasetId = filter.dataId[valueIndex];
const {filter: updatedFilter, dataset: newDataset} = applyFilterFieldName(
- newFilter,
+ filter,
state.datasets[datasetId],
value,
valueIndex,
- {mergeDomain: false}
+ {mergeDomain: valueIndex > 0}
);
- if (!updatedFilter) {
- return state;
- }
-
- newFilter = updatedFilter;
+ if (updatedFilter) {
+ filter = updatedFilter;
+ if (filter.gpu) {
+ filter = setFilterGpuMode(filter, state.filters);
+ filter = assignGpuChannel(filter, state.filters);
+ }
+ state = set(['datasets', datasetId], newDataset, state);
+ // remove filter Plot at datasetId, so it will be recalculated
+ filter = removeFilterPlot(filter, datasetId);
- if (newFilter.gpu) {
- newFilter = setFilterGpuMode(newFilter, state.filters);
- newFilter = assignGpuChannel(newFilter, state.filters);
+ datasetIdsToFilter = updatedFilter.dataId;
}
-
- newState = set(['datasets', datasetId], newDataset, state);
-
// only filter the current dataset
break;
}
@@ -953,7 +1064,7 @@ export function setFilterUpdater(
// - check for layerId changes (XOR works because of string values)
// if no differences between layerIds, don't do any filtering
// @ts-ignore
- const layerIdDifference = xor(newFilter.layerId, oldFilter.layerId);
+ const layerIdDifference = xor(value, filter.layerId);
const layerDataIds = uniq<string>(
layerIdDifference
@@ -967,11 +1078,11 @@ export function setFilterUpdater(
);
// only filter datasetsIds
- datasetIds = layerDataIds;
+ datasetIdsToFilter = layerDataIds;
// Update newFilter dataIds
const newDataIds = uniq<string>(
- newFilter.layerId
+ value
?.map(lid =>
get(
state.layers.find(l => l.id === lid),
@@ -981,49 +1092,22 @@ export function setFilterUpdater(
.filter(d => d) as string[]
);
- newFilter = {
- ...newFilter,
+ filter = {
+ ...filter,
+ layerId: value,
dataId: newDataIds
};
-
break;
}
default:
+ filter = set([prop], value, filter);
+ datasetIdsToFilter = [...filter.dataId];
break;
}
- const enlargedFilter = state.filters.find(f => f.view === FILTER_VIEW_TYPES.enlarged);
-
- if (enlargedFilter && enlargedFilter.id !== newFilter.id) {
- // there should be only one enlarged filter
- newFilter.view = FILTER_VIEW_TYPES.side;
- }
-
- // save new filters to newState
- newState = set(['filters', idx], newFilter, newState);
-
- // if we are currently setting a prop that only requires to filter the current
- // dataset we will pass only the current dataset to applyFiltersToDatasets and
- // updateAllLayerDomainData otherwise we pass the all list of datasets as defined in dataId
- const datasetIdsToFilter = LIMITED_FILTER_EFFECT_PROPS[prop]
- ? [datasetIds[valueIndex]]
- : datasetIds;
-
- // filter data
- const filteredDatasets = applyFiltersToDatasets(
- datasetIdsToFilter,
- newState.datasets,
- newState.filters,
- newState.layers
- );
-
- newState = set(['datasets'], filteredDatasets, newState);
- // dataId is an array
- // pass only the dataset we need to update
- newState = updateAllLayerDomainData(newState, datasetIdsToFilter, newFilter);
-
- return newState;
+ return {filter, datasetIds, datasetIdsToFilter, state};
}
+/* eslint-enable max-statements */
/**
* Set the property of a filter plot
@@ -1034,20 +1118,24 @@ export const setFilterPlotUpdater = (
state: VisState,
{idx, newProp, valueIndex = 0}: VisStateActions.SetFilterPlotUpdaterAction
): VisState => {
- let newFilter = {...state.filters[idx], ...newProp};
- const prop = Object.keys(newProp)[0];
- if (prop === 'yAxis') {
- const plotType = getDefaultFilterPlotType(newFilter);
- // TODO: plot is not supported in multi dataset filter for now
- if (plotType) {
- newFilter = {
- ...newFilter,
- ...getFilterPlot({...newFilter, plotType}, state.datasets[newFilter.dataId[valueIndex]]),
- plotType
- };
+ if (!state.filters[idx]) {
+ Console.error(`filters[${idx}] is undefined`);
+ return state;
+ }
+ let newFilter = state.filters[idx];
+
+ for (const prop in newProp) {
+ if (prop === 'plotType') {
+ newFilter = pick_('plotType')(merge_(newProp.plotType))(newFilter);
+ } else if (prop === 'yAxis') {
+ const chartType = newProp.yAxis ? PLOT_TYPES.lineChart : PLOT_TYPES.histogram;
+
+ newFilter = pick_('plotType')(merge_({type: chartType}))(merge_(newProp)(newFilter));
}
}
+ newFilter = updateFilterPlot(state.datasets, newFilter);
+
return {
...state,
filters: state.filters.map((f, i) => (i === idx ? newFilter : f))
@@ -1634,8 +1722,18 @@ export function removeDatasetUpdater<T extends VisState>(
datasets: newDatasets
});
- // remove filters
- const filters = newState.filters.filter(filter => !filter.dataId.includes(datasetKey));
+ // update filters
+ const filters: Filter[] = [];
+ for (const filter of newState.filters) {
+ const valueIndex = filter.dataId.indexOf(datasetKey);
+ if (valueIndex >= 0 && filter.dataId.length > 1) {
+ // only remove one synced dataset from the filter
+ filters.push(_removeFilterDataIdAtValueIndex(filter, valueIndex, datasets));
+ } else if (valueIndex < 0) {
+ // leave the filter as is
+ filters.push(filter);
+ }
+ }
newState = {...newState, filters};
diff --git a/src/schemas/src/vis-state-schema.ts b/src/schemas/src/vis-state-schema.ts
index 2807280e9..29927e9cf 100644
--- a/src/schemas/src/vis-state-schema.ts
+++ b/src/schemas/src/vis-state-schema.ts
@@ -764,6 +764,19 @@ export class SplitMapsSchema extends Schema {
};
}
}
+export class PlotTypeSchema extends Schema {
+ key = 'plotType';
+ load(plotType) {
+ if (typeof plotType === 'string') {
+ return {
+ plotType: {
+ type: plotType
+ }
+ };
+ }
+ return {plotType};
+ }
+}
export const effectPropsV1 = {
id: null,
@@ -811,7 +824,9 @@ export class EffectsSchema extends Schema {
export const filterPropsV1 = {
...filterPropsV0,
- plotType: null,
+ plotType: new PlotTypeSchema({
+ version: VERSIONS.v1
+ }),
animationWindow: null,
yAxis: new DimensionFieldSchema({
version: VERSIONS.v1,
diff --git a/src/table/package.json b/src/table/package.json
index daa53b553..2885c09c2 100644
--- a/src/table/package.json
+++ b/src/table/package.json
@@ -34,7 +34,7 @@
"@kepler.gl/layers": "3.0.0",
"@kepler.gl/types": "3.0.0",
"@kepler.gl/utils": "3.0.0",
- "@types/d3-array": "^2.0.0",
+ "@types/d3-array": "^2.8.0",
"@types/lodash.uniq": "^4.5.7",
"d3-array": "^2.8.0",
"global": "^4.3.0",
diff --git a/src/table/src/gpu-filter-utils.ts b/src/table/src/gpu-filter-utils.ts
index d4d000442..1ad9f7467 100644
--- a/src/table/src/gpu-filter-utils.ts
+++ b/src/table/src/gpu-filter-utils.ts
@@ -221,6 +221,12 @@ export function getGpuFilterProps(filters: Filter[], dataId: string, fields: Fie
filterRange[i][1] = filter ? filter.value[1] - filter.domain?.[0] : 0;
triggers[`gpuFilter_${i}`] = filter ? filter.name[filter.dataId.indexOf(dataId)] : null;
+ triggers[`gpuFilter_${i}`] = filter
+ ? {
+ name: filter.name[filter.dataId.indexOf(dataId)],
+ domain0: filter.domain?.[0]
+ }
+ : null;
channels.push(filter);
}
diff --git a/src/table/src/kepler-table.ts b/src/table/src/kepler-table.ts
index 09171fd94..367bd7bee 100644
--- a/src/table/src/kepler-table.ts
+++ b/src/table/src/kepler-table.ts
@@ -19,7 +19,11 @@ import {
Filter,
ProtoDataset,
FilterRecord,
- FilterDatasetOpt
+ FilterDatasetOpt,
+ RangeFieldDomain,
+ SelectFieldDomain,
+ MultiSelectFieldDomain,
+ TimeRangeFieldDomain
} from '@kepler.gl/types';
import {getGpuFilterProps, getDatasetFieldIndexForFilter} from './gpu-filter-utils';
@@ -44,7 +48,8 @@ import {
getOrdinalDomain,
getQuantileDomain,
DataContainerInterface,
- notNullorUndefined
+ notNullorUndefined,
+ FilterChanged
} from '@kepler.gl/utils';
export type GpuFilter = {
@@ -58,6 +63,35 @@ export type GpuFilter = {
) => (d: any) => (number | number[])[];
};
+export type FilterProps =
+ | NumericFieldFilterProps
+ | BooleanFieldFilterProps
+ | StringFieldFilterProps
+ | TimeFieldFilterProps;
+
+export type NumericFieldFilterProps = RangeFieldDomain & {
+ value: [number, number];
+ type: string;
+ typeOptions: string[];
+ gpu: boolean;
+};
+export type BooleanFieldFilterProps = SelectFieldDomain & {
+ type: string;
+ value: boolean;
+ gpu: boolean;
+};
+export type StringFieldFilterProps = MultiSelectFieldDomain & {
+ type: string;
+ value: string[];
+ gpu: boolean;
+};
+export type TimeFieldFilterProps = TimeRangeFieldDomain & {
+ type: string;
+ fixedDomain: boolean;
+ value: number[];
+ gpu: boolean;
+};
+
// Unique identifier of each field
const FID_KEY = 'name';
@@ -95,7 +129,7 @@ class KeplerTable {
gpuFilter: GpuFilter;
filterRecord?: FilterRecord;
filterRecordCPU?: FilterRecord;
- changedFilters?: any;
+ changedFilters?: FilterChanged;
// table-injected metadata
sortColumn?: {
@@ -301,7 +335,7 @@ class KeplerTable {
this.filterRecord = filterRecord;
this.gpuFilter = getGpuFilterProps(filters, dataId, fields);
- // const newDataset = set(['filterRecord'], filterRecord, dataset);
+ this.changedFilters = diffFilters(filterRecord, oldFilterRecord);
if (!filters.length) {
this.filteredIndex = this.allIndexes;
@@ -309,8 +343,6 @@ class KeplerTable {
return this;
}
- this.changedFilters = diffFilters(filterRecord, oldFilterRecord);
-
// generate 2 sets of filter result
// filteredIndex used to calculate layer data
// filteredIndexForDomain used to calculate layer Domain
diff --git a/src/types/layers.d.ts b/src/types/layers.d.ts
index 135510f8e..092b16ac6 100644
--- a/src/types/layers.d.ts
+++ b/src/types/layers.d.ts
@@ -106,7 +106,7 @@ export type Field = {
type: string;
fieldIdx: number;
valueAccessor(v: {index: number}): any;
- filterProps?: any;
+ filterProps?: FilterProps;
metadata?: any;
displayFormat?: string;
};
diff --git a/src/types/reducers.d.ts b/src/types/reducers.d.ts
index 71a0401b7..217cbbafa 100644
--- a/src/types/reducers.d.ts
+++ b/src/types/reducers.d.ts
@@ -32,21 +32,14 @@ export type MapState = {
export type Bounds = [number, number, number, number];
-export type HistogramBin = {
- x0: number | undefined;
- x1: number | undefined;
- count: number;
-};
-
export type RangeFieldDomain = {
- domain: [number, number];
+ domain: number[];
step: number;
- histogram: HistogramBin[];
- enlargedHistogram: HistogramBin[];
+ bins?: Bins;
};
export type SelectFieldDomain = {
- domain: [true, false];
+ domain: boolean[];
};
export type MultiSelectFieldDomain = {
domain: string[];
@@ -55,8 +48,7 @@ export type MultiSelectFieldDomain = {
export type TimeRangeFieldDomain = {
domain: [number, number];
step: number;
- histogram: HistogramBin[];
- enlargedHistogram: HistogramBin[];
+ timeBins?: TimeBins;
mappedValue: (Millisecond | null)[];
// auto generated based on time domain
defaultTimeFormat?: string | null;
@@ -71,10 +63,17 @@ export type FieldDomain =
| SelectFieldDomain
| MultiSelectFieldDomain;
+export interface LineDatum {
+ x: number;
+ y: number;
+ delta: string;
+ pct: number | null;
+}
+
export type LineChart = {
series: {x: number; y: number}[];
- yDomain: [number, number];
- xDomain: [number, number];
+ yDomain: number[] | undefined[];
+ xDomain: number[];
};
type FilterViewType = 'side' | 'enlarged' | 'minified';
@@ -84,8 +83,6 @@ export type FilterBase<L extends LineChart> = {
id: string;
enabled: boolean;
- freeze: boolean;
-
// time range filter specific
fixedDomain: boolean;
view: FilterViewType;
@@ -103,7 +100,9 @@ export type FilterBase<L extends LineChart> = {
// plot
yAxis: Field | null;
- plotType: string;
+ plotType: {
+ [key: string]: any;
+ };
lineChart?: L;
// gpu filter
gpu: boolean;
@@ -121,6 +120,9 @@ export type RangeFilter = FilterBase<LineChart> &
value: [number, number];
fixedDomain: true;
typeOptions: ['range'];
+ plotType: {
+ [key: string]: any;
+ };
};
export type SelectFilter = FilterBase<LineChart> &
@@ -143,7 +145,6 @@ export type TimeRangeFilter = FilterBase<LineChart> &
fieldType: 'timestamp';
fixedDomain: true;
value: [number, number];
- bins?: object;
plotType: {
[key: string]: any;
};
@@ -166,6 +167,31 @@ export type Filter =
| MultiSelectFilter
| PolygonFilter;
+export interface Bin {
+ count: number;
+ indexes: number[];
+ x0: number;
+ x1: number;
+}
+
+export interface Bins {
+ [dataId: string]: Bin[];
+}
+
+export interface TimeBins {
+ [dataId: string]: {
+ [interval: string]: Bin[];
+ };
+}
+
+export interface PlotType {
+ interval: ValueOf<Interval>;
+ type: ValueOf<PlotTypes>;
+ aggregation: ValueOf<AggregationTypes>;
+ defaultTimeFormat: string;
+ colorsByDataId?: {[dataId: string]: string};
+}
+
export type Feature = {
id: string;
properties: any;
diff --git a/src/utils/package.json b/src/utils/package.json
index 368782c0f..5012582d1 100644
--- a/src/utils/package.json
+++ b/src/utils/package.json
@@ -37,7 +37,7 @@
"@mapbox/geo-viewport": "^0.4.1",
"@turf/boolean-within": "^6.0.1",
"@turf/helpers": "^6.1.4",
- "@types/d3-array": "^2.0.0",
+ "@types/d3-array": "^2.8.0",
"@types/keymirror": "^0.1.1",
"@types/lodash.clonedeep": "^4.5.7",
"@types/lodash.get": "^4.4.6",
diff --git a/src/utils/src/aggregate-utils.ts b/src/utils/src/aggregate-utils.ts
deleted file mode 100644
index 30cf78a41..000000000
--- a/src/utils/src/aggregate-utils.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright contributors to the kepler.gl project
-
-import {deviation, min, max, mean, median, sum, variance} from 'd3-array';
-import {AGGREGATION_TYPES} from '@kepler.gl/constants';
-
-export const getFrequency = data =>
- data.reduce(
- (uniques, val) => ({
- ...uniques,
- [val]: (uniques[val] || 0) + 1
- }),
- {}
- );
-
-export const getMode = data => {
- const occur = getFrequency(data);
- return Object.keys(occur).reduce(
- (prev, key) => (occur[prev] >= occur[key] ? prev : key),
- Object.keys(occur)[0]
- );
-};
-
-export function aggregate(data, technique) {
- switch (technique) {
- case AGGREGATION_TYPES.average:
- return mean(data);
- case AGGREGATION_TYPES.countUnique:
- return Object.keys(
- data.reduce((uniques, val) => {
- uniques[val] = uniques[val] || 0;
- uniques[val] += 1;
- return uniques;
- }, {})
- ).length;
- case AGGREGATION_TYPES.mode:
- return getMode(data);
-
- case AGGREGATION_TYPES.maximum:
- return max(data);
- case AGGREGATION_TYPES.minimum:
- return min(data);
- case AGGREGATION_TYPES.median:
- return median(data);
- case AGGREGATION_TYPES.stdev:
- return deviation(data);
- case AGGREGATION_TYPES.sum:
- return sum(data);
- case AGGREGATION_TYPES.variance:
- return variance(data);
- default:
- return data.length;
- }
-}
diff --git a/src/utils/src/aggregation.ts b/src/utils/src/aggregation.ts
new file mode 100644
index 000000000..936a3d728
--- /dev/null
+++ b/src/utils/src/aggregation.ts
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import {deviation, min, max, mean, median, sum, variance} from 'd3-array';
+import {ValueOf} from '@kepler.gl/types';
+import {AGGREGATION_TYPES, AggregationTypes} from '@kepler.gl/constants';
+const identity = d => d;
+
+export const getFrequency = (
+ data: any[],
+ accessor: (any: any) => any = identity
+): {[key: string | number]: number} => {
+ const occur = {};
+ for (let i = 0; i < data.length; i++) {
+ const val = accessor(data[i]);
+ occur[val] = (occur[val] || 0) + 1;
+ }
+ return occur;
+};
+
+export const getMode = (data, accessor) => {
+ const occur = getFrequency(data, accessor);
+ return Object.keys(occur).reduce(
+ (prev, key) => (occur[prev] >= occur[key] ? prev : key),
+ Object.keys(occur)[0]
+ );
+};
+
+export const countUnique = (data, accessor = identity) => {
+ return Object.keys(
+ data.reduce((uniques, d) => {
+ const val = accessor(d);
+ uniques[val] = uniques[val] || 0;
+ uniques[val] += 1;
+ return uniques;
+ }, {})
+ ).length;
+};
+
+export const percentMean = (data, accessor) => {
+ const {getNumerator, getDenominator} = accessor;
+ const denominator = aggregate(data, AGGREGATION_TYPES.sum, getDenominator);
+ if (denominator <= 0) {
+ return 0;
+ }
+ const result = aggregate(data, AGGREGATION_TYPES.sum, getNumerator) / denominator;
+ return result;
+};
+
+export function aggregate(
+ data: any[],
+ technique: ValueOf<AggregationTypes>,
+ accessor: (any: any) => any = identity
+): any {
+ switch (technique) {
+ case AGGREGATION_TYPES.average:
+ return mean(data, accessor);
+ case 'mean_of_percent':
+ return percentMean(data, accessor);
+ case AGGREGATION_TYPES.countUnique:
+ return countUnique(data, accessor);
+ case AGGREGATION_TYPES.mode:
+ return getMode(data, accessor);
+ case AGGREGATION_TYPES.maximum:
+ return max(data, accessor);
+ case AGGREGATION_TYPES.minimum:
+ return min(data, accessor);
+ case AGGREGATION_TYPES.median:
+ return median(data, accessor);
+ case AGGREGATION_TYPES.stdev:
+ return deviation(data, accessor);
+ case AGGREGATION_TYPES.sum:
+ return sum(data, accessor);
+ case AGGREGATION_TYPES.variance:
+ return variance(data, accessor);
+ default:
+ return data.length;
+ }
+}
+
+export const AGGREGATION_NAME: {
+ [key: string]: string;
+} = {
+ [AGGREGATION_TYPES.average]: 'Average',
+ [AGGREGATION_TYPES.countUnique]: 'Number of Unique',
+ [AGGREGATION_TYPES.mode]: 'Most Often',
+ [AGGREGATION_TYPES.maximum]: 'Max',
+ [AGGREGATION_TYPES.minimum]: 'Min',
+ [AGGREGATION_TYPES.median]: 'Median',
+ [AGGREGATION_TYPES.stdev]: 'Std Deviation',
+ [AGGREGATION_TYPES.sum]: 'Total',
+ [AGGREGATION_TYPES.variance]: 'Variance'
+};
+
+// ratio: both denominator & numerator precent
+// average, min, max, median,
diff --git a/src/utils/src/data-utils.ts b/src/utils/src/data-utils.ts
index 13638902b..4c62a8341 100644
--- a/src/utils/src/data-utils.ts
+++ b/src/utils/src/data-utils.ts
@@ -96,7 +96,7 @@ export function notNullorUndefined<T extends NonNullable<any>>(d: T | null | und
/**
* Whether d is a number, this filtered out NaN as well
*/
-export function isNumber(d: any): boolean {
+export function isNumber(d: unknown): d is number {
return Number.isFinite(d);
}
@@ -427,3 +427,7 @@ export function datetimeFormatter(
: // return empty string instead of 'Invalid date' if ts is undefined/null
format => ts => ts ? moment.utc(ts).format(format) : '';
}
+
+export function notNullOrUndefined(d: any): boolean {
+ return d !== undefined && d !== null;
+}
diff --git a/src/utils/src/filter-utils.ts b/src/utils/src/filter-utils.ts
index 0c7669d7f..8ab08627c 100644
--- a/src/utils/src/filter-utils.ts
+++ b/src/utils/src/filter-utils.ts
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {ascending, extent, histogram as d3Histogram, ticks} from 'd3-array';
import keyMirror from 'keymirror';
-import Console from 'global/console';
import get from 'lodash.get';
import isEqual from 'lodash.isequal';
+import {ascending, extent} from 'd3-array';
import booleanWithin from '@turf/boolean-within';
import {point as turfPoint} from '@turf/helpers';
@@ -23,7 +22,6 @@ import * as ScaleUtils from './data-scale-utils';
import {h3IsValid} from 'h3-js';
import {
- Millisecond,
Entries,
Field,
ParsedFilter,
@@ -32,10 +30,10 @@ import {
PolygonFilter,
FieldDomain,
TimeRangeFieldDomain,
- HistogramBin,
Feature,
FeatureValue,
LineChart,
+ RangeFilter,
TimeRangeFilter,
RangeFieldDomain,
FilterDatasetOpt,
@@ -46,6 +44,7 @@ import {DataContainerInterface} from './data-container-interface';
import {generateHashId, set, toArray} from './utils';
import {notNullorUndefined, timeToUnixMilli, unique} from './data-utils';
import {getCentroid} from './h3-utils';
+import {updateTimeFilterPlotType, updateRangeFilterPlotType} from './plot';
export const durationSecond = 1000;
export const durationMinute = durationSecond * 60;
@@ -78,35 +77,12 @@ export const TimestampStepMap = [
{max: Number.POSITIVE_INFINITY, step: 1000}
];
-export const histogramBins = 30;
-export const enlargedHistogramBins = 100;
-
export const FILTER_UPDATER_PROPS = keyMirror({
dataId: null,
name: null,
layerId: null
});
-export const LIMITED_FILTER_EFFECT_PROPS = keyMirror({
- [FILTER_UPDATER_PROPS.name]: null
-});
-/**
- * Max number of filter value buffers that deck.gl provides
- */
-
-const SupportedPlotType = {
- [FILTER_TYPES.timeRange]: {
- default: 'histogram',
- [ALL_FIELD_TYPES.integer]: 'lineChart',
- [ALL_FIELD_TYPES.real]: 'lineChart'
- },
- [FILTER_TYPES.range]: {
- default: 'histogram',
- [ALL_FIELD_TYPES.integer]: 'lineChart',
- [ALL_FIELD_TYPES.real]: 'lineChart'
- }
-};
-
export const FILTER_COMPONENTS = {
[FILTER_TYPES.select]: 'SingleSelectFilter',
[FILTER_TYPES.multiSelect]: 'MultiSelectFilter',
@@ -117,7 +93,6 @@ export const FILTER_COMPONENTS = {
export const DEFAULT_FILTER_STRUCTURE = {
dataId: [], // [string]
- freeze: false,
id: null,
enabled: true,
@@ -136,9 +111,10 @@ export const DEFAULT_FILTER_STRUCTURE = {
value: null,
// plot
- plotType: PLOT_TYPES.histogram,
+ plotType: {
+ type: PLOT_TYPES.histogram
+ },
yAxis: null,
- interval: null,
// mode
gpu: false
@@ -230,7 +206,6 @@ export function validatePolygonFilter<K extends KeplerTableModel<K, L>, L extend
return {
filter: {
...filter,
- freeze: true,
fieldIdx: []
},
dataset
@@ -299,8 +274,7 @@ export function validateFilter<K extends KeplerTableModel<K, L>, L>(
}
/**
- * Validate saved filter config with new data,
- * calculate domain and fieldIdx based new fields and data
+ * Validate saved filter config with new data
*
* @param dataset
* @param filter - filter to be validate
@@ -335,8 +309,7 @@ function validateFilterYAxis(filter, dataset) {
filter = matchedAxis
? {
...filter,
- yAxis: matchedAxis,
- ...getFilterPlot({...filter, yAxis: matchedAxis}, dataset)
+ yAxis: matchedAxis
}
: filter;
}
@@ -400,7 +373,8 @@ export function getFilterProps(
view: FILTER_VIEW_TYPES.enlarged,
fixedDomain: true,
value: filterProps.domain,
- gpu: true
+ gpu: true,
+ plotType: {}
};
default:
@@ -639,6 +613,7 @@ export function diffFilters(
return {...{dynamicDomain: null, fixedDomain: null, cpu: null, gpu: null}, ...filterChanged};
}
+
/**
* Call by parsing filters from URL
* Check if value of filter within filter domain, if not adjust it to match
@@ -682,7 +657,6 @@ export function adjustValueToFilterDomain(value: Filter['value'], {domain, type}
return null;
}
}
-/* eslint-enable complexity */
/**
* Calculate numeric domain and suitable step
@@ -710,9 +684,7 @@ export function getNumericFieldDomain(
domain[1] = formatNumberByStep(domain[1], step, 'ceil');
}
- const {histogram, enlargedHistogram} = getHistogram(domain, mappedValue);
-
- return {domain, step, histogram, enlargedHistogram};
+ return {domain, step};
}
/**
@@ -753,8 +725,8 @@ export function getTimestampFieldDomain(
): TimeRangeFieldDomain {
// to avoid converting string format time to epoch
// every time we compare we store a value mapped to int in filter domain
-
const mappedValue = dataContainer.mapIndex(valueAccessor);
+
const domain = ScaleUtils.getLinearDomain(mappedValue);
const defaultTimeFormat = getTimeWidgetTitleFormatter(domain);
@@ -770,46 +742,14 @@ export function getTimestampFieldDomain(
step = entry.step;
}
- const {histogram, enlargedHistogram} = getHistogram(domain, mappedValue);
-
return {
domain,
step,
mappedValue,
- histogram,
- enlargedHistogram,
defaultTimeFormat
};
}
-export function histogramConstruct(
- domain: [number, number],
- mappedValue: (Millisecond | number)[],
- bins: number
-): HistogramBin[] {
- return d3Histogram()
- .thresholds(ticks(domain[0], domain[1], bins))
- .domain(domain)(mappedValue)
- .map(bin => ({
- count: bin.length,
- bin,
- x0: bin.x0,
- x1: bin.x1
- }));
-}
-/**
- * Calculate histogram from domain and array of values
- */
-export function getHistogram(
- domain: [number, number],
- mappedValue: (Millisecond | number)[]
-): {histogram: HistogramBin[]; enlargedHistogram: HistogramBin[]} {
- const histogram = histogramConstruct(domain, mappedValue, histogramBins);
- const enlargedHistogram = histogramConstruct(domain, mappedValue, enlargedHistogramBins);
-
- return {histogram, enlargedHistogram};
-}
-
/**
* round number based on step
*
@@ -902,7 +842,7 @@ export function getColumnFilterProps<K extends KeplerTableModel<K, L>, L>(
filter: Filter,
dataset: K
): {lineChart: LineChart; yAxs: Field} | Record<string, any> {
- if (filter.plotType === PLOT_TYPES.histogram || !filter.yAxis) {
+ if (filter.plotType?.type === PLOT_TYPES.histogram || !filter.yAxis) {
// histogram should be calculated when create filter
return {};
}
@@ -911,8 +851,8 @@ export function getColumnFilterProps<K extends KeplerTableModel<K, L>, L>(
const {yAxis} = filter;
const fieldIdx = dataset.getColumnFieldIdx(yAxis.name);
if (fieldIdx < 0) {
- Console.warn(`yAxis ${yAxis.name} does not exist in dataset`);
- return {};
+ // Console.warn(`yAxis ${yAxis.name} does not exist in dataset`);
+ return {lineChart: {}, yAxis};
}
// return lineChart
@@ -933,18 +873,21 @@ export function getColumnFilterProps<K extends KeplerTableModel<K, L>, L>(
return {lineChart: {series, yDomain, xDomain}, yAxis};
}
-export function getDefaultFilterPlotType(filter: Filter): string | null {
- const filterPlotTypes: (typeof SupportedPlotType)[keyof typeof SupportedPlotType] | null =
- filter.type && SupportedPlotType[filter.type];
- if (!filterPlotTypes) {
- return null;
+export function updateFilterPlot<K extends KeplerTableModel<K, any>>(
+ datasets: {[id: string]: K},
+ filter: Filter,
+ dataId: string | undefined = undefined
+) {
+ if (dataId) {
+ filter = removeFilterPlot(filter, dataId);
}
- if (!filter.yAxis) {
- return filterPlotTypes.default;
+ if (filter.type === FILTER_TYPES.timeRange) {
+ return updateTimeFilterPlotType(filter as TimeRangeFilter, filter.plotType, datasets);
+ } else if (filter.type === FILTER_TYPES.range) {
+ return updateRangeFilterPlotType(filter as RangeFilter, filter.plotType, datasets);
}
-
- return filterPlotTypes[filter.yAxis.type] || null;
+ return filter;
}
/**
@@ -977,7 +920,7 @@ export function applyFiltersToDatasets<
}
/**
- * Applies a new field name value to fielter and update both filter and dataset
+ * Applies a new field name value to filter and update both filter and dataset
* @param filter - to be applied the new field name on
* @param dataset - dataset the field belongs to
* @param fieldName - field.name
@@ -1011,16 +954,25 @@ export function applyFilterFieldName<K extends KeplerTableModel<K, L>, L>(
// TODO: validate field type
const filterProps = dataset.getColumnFilterProps(fieldName);
- const newFilter = {
+ let newFilter = {
...(mergeDomain ? mergeFilterDomainStep(filter, filterProps) : {...filter, ...filterProps}),
name: Object.assign([...toArray(filter.name)], {[filterDatasetIndex]: fieldName}),
fieldIdx: Object.assign([...toArray(filter.fieldIdx)], {
[filterDatasetIndex]: fieldIndex
}),
- // TODO, since we allow to add multiple fields to a filter we can no longer freeze the filter
- freeze: true
+ // Make sure plotType is not overwritten by the default empty plotType
+ ...(filter.plotType ? {plotType: filter.plotType} : {})
};
+ // TODO: if we don't set filter value in filterProps, we don't need to do this
+ if (filterDatasetIndex > 0) {
+ // don't reset the filter value if we are just adding a synced dataset
+ newFilter = {
+ ...newFilter,
+ value: filter.value
+ };
+ }
+
return {
filter: newFilter,
dataset
@@ -1047,14 +999,15 @@ export function mergeFilterDomainStep(
return filter;
}
- const combinedDomain = !filter.domain
+ const sortedDomain = !filter.domain
? filterProps.domain
: [...(filter.domain || []), ...(filterProps.domain || [])].sort((a, b) => a - b);
const newFilter = {
...filter,
...filterProps,
- domain: [combinedDomain[0], combinedDomain[combinedDomain.length - 1]]
+ // use min max as default domain
+ domain: [sortedDomain[0], sortedDomain[sortedDomain.length - 1]]
};
switch (filterProps.fieldType) {
@@ -1062,7 +1015,7 @@ export function mergeFilterDomainStep(
case ALL_FIELD_TYPES.date:
return {
...newFilter,
- domain: unique(combinedDomain).sort()
+ domain: unique(sortedDomain)
};
case ALL_FIELD_TYPES.timestamp: {
@@ -1171,19 +1124,15 @@ export function validateFiltersUpdateDatasets<
let updatedDatasets = datasets;
// merge filters
- filtersToValidate.forEach(filter => {
+ filtersToValidate.forEach(filterToValidate => {
// we can only look for datasets define in the filter dataId
- const datasetIds = toArray(filter.dataId);
+ const datasetIds = toArray(filterToValidate.dataId);
// we can merge a filter only if all datasets in filter.dataId are loaded
if (datasetIds.every(d => datasets[d] && !state.isMergingDatasets[d])) {
// all datasetIds in filter must be present the state datasets
- const {
- filter: validatedFilter,
- applyToDatasets,
- augmentedDatasets
- } = datasetIds.reduce<{
- filter: Filter | null;
+ const {validatedFilter, applyToDatasets, augmentedDatasets} = datasetIds.reduce<{
+ validatedFilter: Filter | null;
applyToDatasets: string[];
augmentedDatasets: {[datasetId: string]: any};
}>(
@@ -1192,21 +1141,14 @@ export function validateFiltersUpdateDatasets<
const layers = state.layers.filter(l => l.config.dataId === dataset.id);
const {filter: updatedFilter, dataset: updatedDataset} = validateFilterWithData(
acc.augmentedDatasets[datasetId] || dataset,
- filter,
+ acc.validatedFilter || filterToValidate,
layers
);
if (updatedFilter) {
+ // merge filter domain step
return {
- ...acc,
- // merge filter props
- filter: acc.filter
- ? {
- ...acc.filter,
- // TODO check: changed from acc to acc.filter to fix types
- ...mergeFilterDomainStep(acc.filter, updatedFilter)
- }
- : updatedFilter,
+ validatedFilter: updatedFilter,
applyToDatasets: [...acc.applyToDatasets, datasetId],
@@ -1220,75 +1162,51 @@ export function validateFiltersUpdateDatasets<
return acc;
},
{
- filter: null,
+ validatedFilter: null,
applyToDatasets: [],
augmentedDatasets: {}
}
);
if (validatedFilter && isEqual(datasetIds, applyToDatasets)) {
- validated.push(validatedFilter);
+ validated.push(updateFilterPlot(datasets, validatedFilter));
updatedDatasets = {
...updatedDatasets,
...augmentedDatasets
};
} else {
- failed.push(filter);
+ failed.push(filterToValidate);
}
} else {
- failed.push(filter);
+ failed.push(filterToValidate);
}
});
return {validated, failed, updatedDatasets};
}
-export function getFilterPlot<K extends KeplerTableModel<K, L>, L>(
- filter: Filter,
- dataset: K
-): {lineChart: LineChart; yAxs: Field} | Record<string, any> {
- if (filter.plotType === PLOT_TYPES.histogram || !filter.yAxis) {
- // histogram should be calculated when create filter
- return {};
- }
+export function removeFilterPlot(filter: Filter, dataId: string) {
+ let nextFilter = filter;
- const {mappedValue = []} = filter;
- const {yAxis} = filter;
- const fieldIdx = dataset.getColumnFieldIdx(yAxis.name);
- if (fieldIdx < 0) {
- Console.warn(`yAxis ${yAxis.name} does not exist in dataset`);
- return {lineChart: {}, yAxis};
+ const rangeFilter = filter as RangeFilter;
+ if (rangeFilter.bins && rangeFilter.bins[dataId]) {
+ const {[dataId]: _delete, ...nextBins} = rangeFilter.bins;
+ nextFilter = {
+ ...rangeFilter,
+ bins: nextBins
+ };
}
- // return lineChart
- const series = dataset.dataContainer
- .map(
- (row, rowIndex) => ({
- x: mappedValue[rowIndex],
- y: row.valueAt(fieldIdx)
- }),
- true
- )
- .filter(({x, y}) => Number.isFinite(x) && Number.isFinite(y))
- .sort((a, b) => ascending(a.x, b.x));
-
- const yDomain = extent(series, d => d.y);
- const xDomain = [series[0].x, series[series.length - 1].x];
-
- return {lineChart: {series, yDomain, xDomain}, yAxis};
-}
-
-/**
- * Retrieve interval bins for time filter
- */
-export function getIntervalBins(filter: TimeRangeFilter) {
- const {bins} = filter;
- const interval = filter.plotType?.interval;
- if (!interval || !bins || Object.keys(bins).length === 0) {
- return null;
+ const timeFilter = filter as TimeRangeFilter;
+ if (timeFilter.timeBins && timeFilter.timeBins[dataId]) {
+ const {[dataId]: __delete, ...nextTimeBins} = timeFilter.timeBins;
+ nextFilter = {
+ ...nextFilter,
+ timeBins: nextTimeBins
+ } as Filter;
}
- const values = Object.values(bins);
- return values[0] ? values[0][interval] : null;
+
+ return nextFilter;
}
export function isValidTimeDomain(domain) {
diff --git a/src/utils/src/format.ts b/src/utils/src/format.ts
index 6725283a7..e23dfc86d 100644
--- a/src/utils/src/format.ts
+++ b/src/utils/src/format.ts
@@ -1,7 +1,31 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {TOOLTIP_KEY} from '@kepler.gl/constants';
+import {TOOLTIP_KEY, TICK_INTERVALS} from '@kepler.gl/constants';
import {TimeLabelFormat} from '@kepler.gl/types';
-export const getFormatValue = (fmt: TimeLabelFormat): string | null => fmt[TOOLTIP_KEY];
+export function getDefaultTimeFormat(interval?: string): string {
+ const timeInterval = interval ? TICK_INTERVALS[interval] : {interval: 'none'};
+
+ switch ((timeInterval || {}).interval) {
+ case 'year':
+ // 2020
+ return 'YYYY';
+ case 'month':
+ case 'week':
+ case 'day':
+ return 'L';
+ case 'hour':
+ return 'L H A';
+ case 'minute':
+ return 'L LT';
+ case 'millisecond':
+ return 'L LTS.SSS';
+
+ case 'second':
+ default:
+ return 'L LTS';
+ }
+}
+
+export const getFormatValue = (fmt: TimeLabelFormat): string | null => fmt[TOOLTIP_KEY];
\ No newline at end of file
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index 2bc1bbc30..e2ec5e6b8 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -20,10 +20,12 @@ export {createNotification, exportImageError, successNotification} from './notif
export {setStyleSheetBaseHref} from './dom-utils';
export {default as domtoimage} from './dom-to-image';
-export {getFrequency, getMode, aggregate} from './aggregate-utils';
+export {getFrequency, getMode, aggregate} from './aggregation';
+export {getBinThresholds, histogramFromThreshold, histogramFromDomain} from './plot';
// eslint-disable-next-line prettier/prettier
export type {FieldFormatter} from './data-utils';
export * from './data-utils';
+export * from './strings';
export {
getTimelineFromAnimationConfig,
getTimelineFromFilter,
diff --git a/src/utils/src/plot.ts b/src/utils/src/plot.ts
index 9260cb3aa..023b611f7 100644
--- a/src/utils/src/plot.ts
+++ b/src/utils/src/plot.ts
@@ -1,7 +1,235 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {bisectLeft} from 'd3-array';
+import {bisectLeft, bisector, extent, histogram as d3Histogram, ticks} from 'd3-array';
+import {getFilterMappedValue, getInitialInterval, intervalToFunction} from './time';
+import moment from 'moment';
+import {
+ Bin,
+ TimeBins,
+ Millisecond,
+ TimeRangeFilter,
+ RangeFilter,
+ PlotType,
+ Filter,
+ LineChart,
+ Field,
+ ValueOf,
+ LineDatum
+} from '@kepler.gl/types';
+import {
+ ANIMATION_WINDOW,
+ BINS,
+ durationDay,
+ TIME_AGGREGATION,
+ AGGREGATION_TYPES,
+ PLOT_TYPES,
+ AggregationTypes
+} from '@kepler.gl/constants';
+import {VisState} from '@kepler.gl/schemas';
+
+import {notNullOrUndefined, roundValToStep} from './data-utils';
+import {aggregate, AGGREGATION_NAME} from './aggregation';
+import {capitalizeFirstLetter} from './strings';
+import {getDefaultTimeFormat} from './format';
+import {rgbToHex} from './color-utils';
+import {DataContainerInterface} from '.';
+
+// TODO kepler-table module isn't accessible from utils. Add compatible interface to types
+type Datasets = any;
+
+/**
+ *
+ * @param thresholds
+ * @param values
+ * @param indexes
+ */
+export function histogramFromThreshold(
+ thresholds: number[],
+ values: number[],
+ indexes: number[]
+): Bin[] {
+ const bins = d3Histogram()
+ .value(idx => values[idx])
+ .domain([thresholds[0], thresholds[thresholds.length - 1]])
+ .thresholds(thresholds)(indexes)
+ .map(bin => ({
+ count: bin.length,
+ indexes: bin,
+ x0: bin.x0,
+ x1: bin.x1
+ }));
+
+ // d3-histogram ignores threshold values outside the domain
+ // The first bin.x0 is always equal to the minimum domain value, and the last bin.x1 is always equal to the maximum domain value.
+
+ // bins[0].x0 = thresholds[0];
+ // bins[bins.length - 1].x1 = thresholds[thresholds.length - 1];
+
+ // @ts-ignore
+ // filter out bins with 0 counts
+ return bins.filter(b => b.count > 0);
+ // return bins;
+}
+
+/**
+ *
+ * @param domain
+ * @param values
+ * @param numBins
+ * @param valueAccessor
+ */
+export function histogramFromDomain(
+ domain: [number, number],
+ values: (Millisecond | null | number)[],
+ numBins: number,
+ valueAccessor?: (d: unknown) => number
+): Bin[] {
+ const getBins = d3Histogram()
+ .thresholds(ticks(domain[0], domain[1], numBins))
+ .domain(domain);
+ if (valueAccessor) {
+ getBins.value(valueAccessor);
+ }
+
+ // @ts-ignore d3-array types doesn't match
+ return getBins(values).map(bin => ({
+ count: bin.length,
+ indexes: bin,
+ x0: bin.x0,
+ x1: bin.x1
+ }));
+}
+
+/**
+ * @param filter
+ * @param datasets
+ * @param interval
+ */
+export function getTimeBins(
+ filter: TimeRangeFilter,
+ datasets: Datasets,
+ interval: PlotType['interval']
+): TimeBins {
+ let bins = filter.timeBins || {};
+
+ filter.dataId.forEach((dataId, dataIdIdx) => {
+ // reuse bins if filterData did not change
+ if (bins[dataId] && bins[dataId][interval]) {
+ return;
+ }
+ const dataset = datasets[dataId];
+
+ // do not apply current filter
+ const indexes = runGpuFilterForPlot(dataset, filter);
+
+ bins = {
+ ...bins,
+ [dataId]: {
+ ...bins[dataId],
+ [interval]: binByTime(indexes, dataset, interval, filter)
+ }
+ };
+ });
+
+ return bins;
+}
+
+export function binByTime(indexes, dataset, interval, filter) {
+ // gpuFilters need to be apply to filteredIndex
+ const mappedValue = getFilterMappedValue(dataset, filter);
+ const intervalBins = getBinThresholds(interval, filter.domain);
+
+ const bins = histogramFromThreshold(intervalBins, mappedValue, indexes);
+
+ return bins;
+}
+
+export function getBinThresholds(interval: string, domain: number[]): number[] {
+ const timeInterval = intervalToFunction(interval);
+ const [t0, t1] = domain;
+ const floor = timeInterval.floor(t0).getTime();
+ const ceiling = timeInterval.ceil(t1).getTime();
+
+ if (!timeInterval) {
+ // if time interval is not defined
+ // this should not happen
+ return [t0, t0 + durationDay];
+ }
+ const binThresholds = timeInterval.range(floor, ceiling + 1).map(t => moment.utc(t).valueOf());
+ const lastStep = binThresholds[binThresholds.length - 1];
+ if (lastStep === t1) {
+ // when last step equal to domain max, add one more step
+ binThresholds.push(moment.utc(timeInterval.offset(lastStep)).valueOf());
+ }
+
+ return binThresholds;
+}
+
+/**
+ * Run GPU filter on current filter result to generate indexes for ploting chart
+ * Skip ruuning for the same field
+ * @param {KeplerTable} dataset
+ * @param {Filter} filter
+ */
+export function runGpuFilterForPlot(dataset, filter) {
+ const skipIndexes = getSkipIndexes(dataset, filter);
+
+ const {
+ gpuFilter: {filterValueUpdateTriggers, filterRange, filterValueAccessor},
+ filteredIndex
+ } = dataset;
+ const getFilterValue = filterValueAccessor(dataset.dataContainer)();
+
+ const allChannels = Object.keys(filterValueUpdateTriggers)
+ .map((_, i) => i)
+ .filter(i => Object.values(filterValueUpdateTriggers)[i]);
+ const skipAll = !allChannels.filter(i => !skipIndexes.includes(i)).length;
+ if (skipAll) {
+ return filteredIndex;
+ }
+
+ const filterData = getFilterDataFunc(
+ filterRange,
+ getFilterValue,
+ dataset.dataContainer,
+ skipIndexes
+ );
+
+ return filteredIndex.filter(filterData);
+}
+
+function getSkipIndexes(dataset, filter) {
+ // array of gpu filter names
+ const gpuFilters = Object.values(dataset.gpuFilter.filterValueUpdateTriggers) as ({
+ name: string;
+ } | null)[];
+ const valueIndex = filter.dataId.findIndex(id => id === dataset.id);
+ const filterColumn = filter.name[valueIndex];
+
+ return gpuFilters.reduce((accu, item, idx) => {
+ if (item && filterColumn === item.name) {
+ accu.push(idx);
+ }
+ return accu;
+ }, [] as number[]);
+}
+
+export function getFilterDataFunc(
+ filterRange,
+ getFilterValue,
+ dataContainer: DataContainerInterface,
+ skips
+) {
+ return index =>
+ getFilterValue({index}).every(
+ (val, i) => skips.includes(i) || (val >= filterRange[i][0] && val <= filterRange[i][1])
+ );
+}
+
+export function validBin(b) {
+ return b.x0 !== undefined && b.x1 !== undefined;
+}
/**
* Use in slider, given a number and an array of numbers, return the nears number from the array
@@ -10,6 +238,10 @@ import {bisectLeft} from 'd3-array';
*/
export function snapToMarks(value: number, marks: number[]): number {
// always use bin x0
+ if (!marks.length) {
+ // @ts-expect-error looking at the usage null return value isn't expected and requires extra handling in a lot of places
+ return null;
+ }
const i = bisectLeft(marks, value);
if (i === 0) {
return marks[i];
@@ -19,3 +251,385 @@ export function snapToMarks(value: number, marks: number[]): number {
const idx = marks[i] - value < value - marks[i - 1] ? i : i - 1;
return marks[idx];
}
+
+export function normalizeValue(val, minValue, step, marks) {
+ if (marks && marks.length) {
+ return snapToMarks(val, marks);
+ }
+
+ return roundValToStep(minValue, step, val);
+}
+
+export function isPercentField(field) {
+ return field.metadata && field.metadata.numerator && field.metadata.denominator;
+}
+
+export function updateAggregationByField(field: Field, aggregation: ValueOf<AggregationTypes>) {
+ // shouldn't apply sum to percent fiele type
+ // default aggregation is average
+ return field && isPercentField(field)
+ ? AGGREGATION_TYPES.average
+ : aggregation || AGGREGATION_TYPES.average;
+}
+
+const getAgregationType = (field, aggregation) => {
+ if (isPercentField(field)) {
+ return 'mean_of_percent';
+ }
+ return aggregation;
+};
+
+const getAgregationAccessor = (field, dataContainer: DataContainerInterface, fields) => {
+ if (isPercentField(field)) {
+ const numeratorIdx = fields.findIndex(f => f.name === field.metadata.numerator);
+ const denominatorIdx = fields.findIndex(f => f.name === field.metadata.denominator);
+
+ return {
+ getNumerator: i => dataContainer.valueAt(i, numeratorIdx),
+ getDenominator: i => dataContainer.valueAt(i, denominatorIdx)
+ };
+ }
+
+ return i => field.valueAccessor({index: i});
+};
+
+export const getValueAggrFunc = (field, aggregation, dataset) => {
+ const {dataContainer, fields} = dataset;
+ return field && aggregation
+ ? bin =>
+ aggregate(
+ bin.indexes,
+ getAgregationType(field, aggregation),
+ // @ts-ignore
+ getAgregationAccessor(field, dataContainer, fields)
+ )
+ : bin => bin.count;
+};
+
+export const getAggregationOptiosnBasedOnField = field => {
+ if (isPercentField(field)) {
+ // don't show sum
+ return TIME_AGGREGATION.filter(({id}) => id !== AGGREGATION_TYPES.sum);
+ }
+ return TIME_AGGREGATION;
+};
+
+function getDelta(
+ bins: LineDatum[],
+ y: number,
+ interval: PlotType['interval']
+): Partial<LineDatum> {
+ // if (WOW[interval]) return getWow(bins, y, interval);
+ const lastBin = bins[bins.length - 1];
+
+ return {
+ delta: 'last',
+ pct: lastBin ? getPctChange(y, lastBin.y) : null
+ };
+}
+
+export function getPctChange(y, y0) {
+ if (Number.isFinite(y) && Number.isFinite(y0) && y0 !== 0) {
+ return (y - y0) / y0;
+ }
+ return null;
+}
+
+/**
+ *
+ * @param datasets
+ * @param filter
+ */
+export function getLineChart(datasets: Datasets, filter: Filter): LineChart {
+ const {dataId, yAxis, plotType} = filter;
+ const {aggregation, interval} = plotType;
+
+ if (
+ filter.lineChart &&
+ // @ts-expect-error add aggregation to LineChart?
+ filter.lineChart.aggregation === aggregation &&
+ // @ts-expect-error add aggregation to LineChart?
+ filter.lineChart.interval === interval
+ ) {
+ // don't update lineChart if plotType hasn't change
+ return filter.lineChart;
+ }
+
+ const seriesDataId = dataId[0];
+ const dataset = datasets[seriesDataId];
+ const getYValue = getValueAggrFunc(yAxis, aggregation, dataset);
+
+ // @ts-expect-error do we expect TimeRangeFilter here?
+ const bins = filter.timeBins[seriesDataId][interval];
+ const init = [];
+ const series = bins.reduce((accu, bin, i) => {
+ const y = getYValue(bin);
+ const delta = getDelta(accu, y, interval);
+ accu.push({
+ x: bin.x0,
+ y,
+ ...delta
+ });
+ return accu;
+ }, init);
+
+ const yDomain = extent<{y: any}>(series, d => d.y);
+ const xDomain = [bins[0].x0, bins[bins.length - 1].x1];
+
+ // treat missing data as another series
+ const split = splitSeries(series);
+ const aggrName = AGGREGATION_NAME[aggregation];
+
+ return {
+ // @ts-ignore
+ yDomain,
+ // @ts-ignore
+ xDomain,
+ interval,
+ aggregation,
+ // @ts-ignore
+ series: split,
+ title: `${aggrName}${' of '}${yAxis ? yAxis.name : 'Count'}`,
+ fieldType: yAxis ? yAxis.type : 'integer',
+ allTime: {
+ title: `All Time Average`,
+ value: aggregate(series, AGGREGATION_TYPES.average, d => d.y)
+ }
+ };
+}
+
+// split into multiple series when see missing data
+export function splitSeries(series) {
+ const lines: any[] = [];
+ let temp: any[] = [];
+ for (let i = 0; i < series.length; i++) {
+ const d = series[i];
+ if (!notNullOrUndefined(d.y) && temp.length) {
+ // ends temp
+ lines.push(temp);
+ temp = [];
+ } else if (notNullOrUndefined(d.y)) {
+ temp.push(d);
+ }
+
+ if (i === series.length - 1 && temp.length) {
+ lines.push(temp);
+ }
+ }
+
+ const markers = lines.length > 1 ? series.filter(d => notNullOrUndefined(d.y)) : [];
+
+ return {lines, markers};
+}
+
+export function filterSeriesByRange(series, range) {
+ if (!series) {
+ return [];
+ }
+ const [start, end] = range;
+ const inRange: any[] = [];
+
+ for (const serie of series) {
+ if (!serie.length) {
+ // eslint-disable-next-line no-console, no-undef
+ console.warn('Serie shouldnt be empty', series);
+ }
+
+ const i0 = bisector((s: {x: any}) => s.x).left(serie, start);
+ const i1 = bisector((s: {x: any}) => s.x).right(serie, end);
+ const sliced = serie.slice(i0, i1);
+ if (sliced.length) inRange.push(sliced);
+ }
+
+ return inRange;
+}
+
+export function adjustValueToAnimationWindow(state: VisState, filter: TimeRangeFilter) {
+ const {
+ plotType,
+ value: [value0, value1],
+ animationWindow
+ } = filter;
+
+ const interval = plotType.interval || getInitialInterval(filter, state.datasets);
+ const bins = getTimeBins(filter, state.datasets, interval);
+ const datasetBins = bins && Object.keys(bins).length && Object.values(bins)[0][interval];
+ const thresholds = (datasetBins || []).map(b => b.x0);
+
+ let val0 = value0;
+ let val1 = value1;
+ let idx;
+ if (animationWindow === ANIMATION_WINDOW.interval) {
+ val0 = snapToMarks(value1, thresholds);
+ idx = thresholds.indexOf(val0);
+ val1 = idx > -1 ? datasetBins[idx].x1 : NaN;
+ } else {
+ // fit current value to window
+ val0 = snapToMarks(value0, thresholds);
+ val1 = snapToMarks(value1, thresholds);
+
+ if (val0 === val1) {
+ idx = thresholds.indexOf(val0);
+ if (idx === thresholds.length - 1) {
+ val0 = thresholds[idx - 1];
+ } else {
+ val1 = thresholds[idx + 1];
+ }
+ }
+ }
+
+ const updatedFilter = {
+ ...filter,
+ plotType: {
+ ...filter.plotType,
+ interval
+ },
+ timeBins: bins,
+ value: [val0, val1]
+ };
+
+ return updatedFilter;
+}
+
+/**
+ * Create or update colors for a filter plot
+ * @param filter
+ * @param datasets
+ * @param oldColorsByDataId
+ */
+function getFilterPlotColorsByDataId(filter, datasets, oldColorsByDataId) {
+ let colorsByDataId = oldColorsByDataId || {};
+ for (const dataId of filter.dataId) {
+ if (!colorsByDataId[dataId] && datasets[dataId]) {
+ colorsByDataId = {
+ ...colorsByDataId,
+ [dataId]: rgbToHex(datasets[dataId].color)
+ };
+ }
+ }
+ return colorsByDataId;
+}
+
+/**
+ *
+ * @param filter
+ * @param plotType
+ * @param datasets
+ * @param dataId
+ */
+export function updateTimeFilterPlotType(
+ filter: TimeRangeFilter,
+ plotType: TimeRangeFilter['plotType'],
+ datasets: Datasets,
+ dataId?: string
+): TimeRangeFilter {
+ let nextFilter = filter;
+ let nextPlotType = plotType;
+ if (typeof nextPlotType !== 'object' || !nextPlotType.aggregation || !nextPlotType.interval) {
+ nextPlotType = getDefaultPlotType(filter, datasets);
+ }
+
+ if (filter.dataId.length > 1) {
+ nextPlotType = {
+ ...nextPlotType,
+ colorsByDataId: getFilterPlotColorsByDataId(filter, datasets, nextPlotType.colorsByDataId)
+ };
+ }
+ nextFilter = {
+ ...nextFilter,
+ plotType: nextPlotType
+ };
+
+ const bins = getTimeBins(nextFilter, datasets, nextPlotType.interval);
+
+ nextFilter = {
+ ...nextFilter,
+ timeBins: bins
+ };
+
+ if (plotType.type === PLOT_TYPES.histogram) {
+ // Histogram is calculated and memoized in the chart itself
+ } else if (plotType.type === PLOT_TYPES.lineChart) {
+ nextFilter = {
+ ...nextFilter,
+ lineChart: getLineChart(datasets, nextFilter)
+ };
+ }
+
+ return nextFilter;
+}
+
+export function getRangeFilterBins(filter, datasets, numBins) {
+ const {domain} = filter;
+ if (!filter.dataId) return null;
+
+ return filter.dataId.reduce((acc, dataId, datasetIdx) => {
+ if (filter.bins?.[dataId]) {
+ // don't recalculate bins
+ acc[dataId] = filter.bins[dataId];
+ return acc;
+ }
+ const fieldName = filter.name[datasetIdx];
+ if (dataId && fieldName) {
+ const dataset = datasets[dataId];
+ const field = dataset?.getColumnField(fieldName);
+ if (dataset && field) {
+ const indexes = runGpuFilterForPlot(dataset, filter);
+ const valueAccessor = index => field.valueAccessor({index});
+ acc[dataId] = histogramFromDomain(domain, indexes, numBins, valueAccessor);
+ }
+ }
+ return acc;
+ }, {});
+}
+
+export function updateRangeFilterPlotType(
+ filter: RangeFilter,
+ plotType: RangeFilter['plotType'],
+ datasets: Datasets,
+ dataId?: string
+): RangeFilter {
+ const nextFilter = {
+ ...filter,
+ plotType
+ };
+
+ // if (dataId) {
+ // // clear bins
+ // nextFilter = {
+ // ...nextFilter,
+ // bins: {
+ // ...nextFilter.bins,
+ // [dataId]: null
+ // }
+ // };
+ // }
+
+ return {
+ ...filter,
+ plotType,
+ bins: getRangeFilterBins(nextFilter, datasets, BINS)
+ };
+}
+
+export function getChartTitle(yAxis, plotType: {aggregation: string}) {
+ const yAxisName = yAxis?.displayName;
+ const {aggregation} = plotType;
+
+ if (yAxisName) {
+ return capitalizeFirstLetter(`${aggregation} ${yAxisName} over Time`);
+ }
+
+ return `Count of Rows over Time`;
+}
+
+export function getDefaultPlotType(filter, datasets) {
+ const interval = getInitialInterval(filter, datasets);
+ const defaultTimeFormat = getDefaultTimeFormat(interval);
+ return {
+ interval,
+ defaultTimeFormat,
+ type: PLOT_TYPES.histogram,
+ aggregation: AGGREGATION_TYPES.sum
+ };
+}
diff --git a/src/utils/src/strings.ts b/src/utils/src/strings.ts
new file mode 100644
index 000000000..2ea1710d3
--- /dev/null
+++ b/src/utils/src/strings.ts
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+/**
+ * Capitalize first letter of a string
+ */
+export function capitalizeFirstLetter(str: string): string {
+ return typeof str === 'string' ? str.charAt(0).toUpperCase() + str.slice(1) : str;
+}
diff --git a/src/utils/src/time.ts b/src/utils/src/time.ts
index f9ffe1f2f..eaa8ce3c3 100644
--- a/src/utils/src/time.ts
+++ b/src/utils/src/time.ts
@@ -4,6 +4,18 @@
import {AnimationConfig, Timeline, TimeRangeFilter} from '@kepler.gl/types';
import {toArray} from './utils';
+import {
+ TICK_INTERVALS,
+ BINS_LARGE,
+ DURATIONS,
+ TIME_INTERVALS,
+ durationYear,
+ TickInterval
+} from '@kepler.gl/constants';
+import moment from 'moment';
+import {getFrequency} from './aggregation';
+
+import {ascending, bisector, tickStep} from 'd3-array';
export const TIMELINE_MODES = {
inner: 'inner',
@@ -81,3 +93,212 @@ export const getTimelineFromFilter = (filter: TimeRangeFilter): Timeline => {
marks: null
};
};
+
+// check if the data inherent default time interval
+
+// https://github.com/d3/d3-scale/blob/732ed4b1cd5c643700571d1089c7deb8472242a6/src/time.js#L69
+// given number of ticks, calculate a reasonable interval
+export function getIntervalByTicks(ticks, start, stop) {
+ if (ticks === null) ticks = 10;
+ const tickIntervals = Object.values(TICK_INTERVALS);
+ let interval;
+ let step;
+ // If a desired tick count is specified, pick a reasonable tick interval
+ // based on the extent of the domain and a rough estimate of tick size.
+ // Otherwise, assume interval is already a time interval and use it.
+ if (typeof ticks === 'number') {
+ const target = Math.abs(stop - start) / ticks;
+ let i = bisector((d: TickInterval) => d.duration).right(tickIntervals, target);
+ if (i === tickIntervals.length) {
+ step = tickStep(start / durationYear, stop / durationYear, ticks);
+ interval = 'year';
+ } else if (i) {
+ const tickInterval =
+ tickIntervals[
+ target / tickIntervals[i - 1].duration < tickIntervals[i].duration / target ? i - 1 : i
+ ];
+ // @ts-ignore TODO/ib
+ step = tickInterval.step;
+ // @ts-ignore TODO/ib
+ interval = tickInterval.interval;
+ } else {
+ step = Math.max(tickStep(start, stop, ticks), 1);
+ interval = 'millisecond';
+ }
+ }
+
+ return `${step}-${interval}`;
+}
+
+// get a number of unique samples
+function getUniqueSamples(values, count) {
+ let i = -1;
+ const samples: any[] = [];
+ const sampleMap = {};
+ while (i++ < values.length && samples.length < count) {
+ const v = values[i];
+ if (v !== undefined && v !== null && !sampleMap[v]) {
+ sampleMap[v] = true;
+ samples.push(v);
+ }
+ }
+
+ return Object.values(samples);
+}
+
+/**
+ * Given an array of epoch timestamp. sort it, if number of element
+ * share the same time interval exceed thresholf, and total steps smaller than 100, return it, else return null
+ * @param values
+ */
+function detectInterval(values: number[] = [], domain, maxSteps = 10) {
+ const threshold = 0.7;
+
+ const sorted = values.sort(ascending);
+
+ // get first 100 unique sorted ts
+ const samples = getUniqueSamples(sorted, 100);
+ if (samples.length < 2) {
+ return null;
+ }
+
+ // get all intervals
+ const intervals = samples.reduce((accu, d, i) => {
+ if (i > 0) {
+ const duration = moment.duration(moment.utc(samples[i]).diff(moment.utc(samples[i - 1])));
+ const [dur, c] = getDurationUnit(duration);
+ accu.push(`${c}-${dur}`);
+ }
+ return accu;
+ }, []);
+
+ // find the most occured interval
+ const occur = getFrequency(intervals);
+ const maxOccr = Object.keys(occur).reduce(
+ (prev, key) => (occur[prev] >= occur[key] ? prev : key),
+ Object.keys(occur)[0]
+ );
+
+ // if occurance passed threshold
+ const mostOccur = occur[maxOccr] / intervals.length;
+ if (mostOccur >= threshold) {
+ const [step, dur] = maxOccr.split('-');
+ const durationSecond = DURATIONS[dur] * parseInt(step); // eslint-disable-line radix
+ const totalSteps = (domain[1] - domain[0]) / durationSecond;
+
+ if (totalSteps < maxSteps) {
+ // duration function is .days interval is day
+ return maxOccr.substring(0, maxOccr.length - 1);
+ }
+ }
+
+ return null;
+}
+
+/**
+ * mappedValue is saved to dataset.fields.filterProps
+ * @param dataset
+ * @param filter
+ */
+export function getFilterMappedValue(dataset, filter) {
+ const dataId = dataset.id;
+ const fieldName = filter.name[filter.dataId.indexOf(dataId)];
+ const field = dataset.getColumnField(fieldName);
+
+ if (!field) {
+ // eslint-disable-next-line no-console, no-undef
+ console.warn(`field ${fieldName} does not exist on dataset`);
+ return null;
+ }
+ const mappedValue = (field.filterProps || {}).mappedValue;
+ if (!mappedValue) {
+ // eslint-disable-next-line no-console, no-undef
+ console.warn(`mappedValue doesnt exist on filter field ${filter.name}`);
+ return null;
+ }
+ return mappedValue;
+}
+/**
+ * Find the round unit of given durmostOccurtion: x years | months | days
+ * @param duration
+ */
+function getDurationUnit(duration) {
+ const durFuncs = Object.keys(DURATIONS);
+ for (let i = 0; i < durFuncs.length; i++) {
+ const c = duration[durFuncs[i]]();
+ if (c > 0) {
+ return [durFuncs[i], c];
+ }
+ }
+ return ['milliseconds', 1];
+}
+
+export function intervalToFunction(id) {
+ const [stepStr, interval] = id.split('-');
+ const step = parseInt(stepStr); // eslint-disable-line radix
+ if (!step) {
+ // eslint-disable-next-line no-console, no-undef
+ console.warn('Step is not an integer');
+ return null;
+ }
+
+ if (!TIME_INTERVALS[interval]) {
+ // eslint-disable-next-line no-console, no-undef
+ console.warn(`Undefined time interval ${interval}`);
+ return null;
+ }
+
+ return TIME_INTERVALS[interval].every(step);
+}
+
+export function getInitialInterval(filter, datasets) {
+ const {domain} = filter;
+ const mergeMappedValue = filter.dataId.reduce((accu, dataId) => {
+ const mappedValue = getFilterMappedValue(datasets[dataId], filter);
+ if (!mappedValue) {
+ return accu;
+ }
+
+ for (let i = 0; i < mappedValue.length; i++) {
+ accu.push(mappedValue[i]);
+ }
+ return accu;
+ }, []);
+
+ // check if data has predefined interval
+ let interval = detectInterval(mergeMappedValue, domain);
+
+ if (!interval) {
+ const [t0, t1] = domain;
+ interval = getIntervalByTicks(BINS_LARGE, t0, t1);
+ }
+
+ return interval;
+}
+
+// Filter interval options by time filter domain
+// max number of interval is 1000
+/**
+ *
+ * @param options
+ * @param domain
+ */
+export function filterIntervalOptions(options, domain) {
+ const maxBins = 1000;
+ const minBins = 2;
+ const timeSpan = domain[1] - domain[0];
+
+ return options.filter(op => {
+ const {id} = op;
+ if (!TICK_INTERVALS[id]) {
+ return false;
+ }
+
+ const interval = TICK_INTERVALS[id];
+
+ // rough count on bins
+ const count = timeSpan / (interval.step * interval.duration);
+
+ return count >= minBins && count <= maxBins;
+ });
+}
diff --git a/src/utils/src/utils.ts b/src/utils/src/utils.ts
index 9223dc4a8..31a715e92 100644
--- a/src/utils/src/utils.ts
+++ b/src/utils/src/utils.ts
@@ -2,6 +2,7 @@
// Copyright contributors to the kepler.gl project
import window from 'global/window';
+import {capitalizeFirstLetter} from './strings';
/**
* Generate a hash string based on number of character
@@ -43,15 +44,6 @@ export function isChrome(): boolean {
return window.chrome && window.chrome.webstore;
}
-/**
- * Capitalize first letter of a string
- * @param {string} str
- * @returns {string}
- */
-export function capitalizeFirstLetter(str) {
- return typeof str === 'string' ? str.charAt(0).toUpperCase() + str.slice(1) : str;
-}
-
/**
* Convert camel style names to title
* strokeColor -> Stroke Color
diff --git a/test/browser-debug.js b/test/browser-debug.js
index 30509b48b..81fc77a5c 100644
--- a/test/browser-debug.js
+++ b/test/browser-debug.js
@@ -18,8 +18,8 @@ test.onFailure(args => {
test('Browser tests', t => {
// running all tests in browser for debugging
require('./node/index.js');
- require('./browser/index.js');
- require('./browser-headless/index.js');
+ // require('./browser/index.js');
+ // require('./browser-headless/index.js');
t.end();
});
diff --git a/test/browser/components/common/range-plot-test.js b/test/browser/components/common/range-plot-test.js
index cb2aa2701..60470901e 100644
--- a/test/browser/components/common/range-plot-test.js
+++ b/test/browser/components/common/range-plot-test.js
@@ -2,28 +2,63 @@
// Copyright contributors to the kepler.gl project
/* eslint-disable no-unused-vars */
+
import React from 'react';
import test from 'tape';
import {mountWithTheme} from 'test/helpers/component-utils';
-import {appInjector, RangePlotFactory} from '@kepler.gl/components';
+import {appInjector, RangePlotFactory, LoadingSpinner} from '@kepler.gl/components';
+import sinon from 'sinon';
const RangePlot = appInjector.get(RangePlotFactory);
test('Components -> RangePlot.render', t => {
+ const setFilterPlot = sinon.spy();
const props = {
- histogram: [],
isEnlarged: true,
isRanged: true,
onBrush: () => {},
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
range: [1421315219000, 1421348744000],
value: [1421315219000, 1421348744000],
- width: 137
+ width: 137,
+ setFilterPlot
};
+ let wrapper;
t.doesNotThrow(() => {
- const wrapper = mountWithTheme(<RangePlot {...props} />);
+ wrapper = mountWithTheme(<RangePlot {...props} />);
}, 'Show not fail without histogram');
+ // t.ok(setFilterPlot.calledOnce, 'should call setFilterPlot');
+ // t.deepEqual(
+ // setFilterPlot.getCall(0).args,
+ // [{plotType: {type: 'histogram'}}],
+ // 'should call setfilterPlot with plotType'
+ // );
+ // t.equal(wrapper.find(LoadingSpinner).length, 1, 'should render loading spinner');
+
+ const propsWLineChart = {
+ isEnlarged: true,
+ isRanged: true,
+ onBrush: () => {},
+ plotType: {type: 'lineChart'},
+ range: [1421315219000, 1421348744000],
+ value: [1421315219000, 1421348744000],
+ width: 137,
+ setFilterPlot
+ };
+
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(<RangePlot {...propsWLineChart} />);
+ }, 'Show not fail without lineChart');
+
+ t.ok(setFilterPlot.calledTwice, 'should call setFilterPlot');
+ t.deepEqual(
+ setFilterPlot.getCall(1).args,
+ [{plotType: {type: 'lineChart'}}],
+ 'should call setfilterPlot with plotType'
+ );
+ t.equal(wrapper.find(LoadingSpinner).length, 1, 'should render loading spinner');
+
// cant test D3 in jsDom for now
// props.histogram = [
// {count: 20, x0: 1421315219000, x1: 1421315500000},
@@ -34,9 +69,5 @@ test('Components -> RangePlot.render', t => {
// {count: 21, x0: 1421317500000, x1: 1421318000000}
// ];
- t.doesNotThrow(() => {
- const wrapper = mountWithTheme(<RangePlot {...props} />);
- }, 'Show not fail render histogram');
-
t.end();
});
diff --git a/test/browser/components/filters/time-widget-test.js b/test/browser/components/filters/time-widget-test.js
index 6bc740bce..7d83489ec 100644
--- a/test/browser/components/filters/time-widget-test.js
+++ b/test/browser/components/filters/time-widget-test.js
@@ -126,6 +126,12 @@ test('Components -> TimeWidget.mount -> test actions', t => {
);
}, 'mount TimeWidget should not fail');
+ // t.ok(setFilterPlot.calledOnce, 'should call setFilterPlot when 1st mount to set plotType');
+ // t.deepEqual(
+ // setFilterPlot.getCall(0).args,
+ // [0, {plotType: {type: 'histogram'}}, undefined],
+ // 'should set plotType to linechart'
+ // );
t.equal(wrapper.find(Icons.Close).length, 1, 'should render Close icon');
t.equal(wrapper.find(Icons.Reset).length, 1, 'should render Reset icon');
t.equal(wrapper.find(Icons.Play).length, 1, 'should render Play icon');
@@ -196,9 +202,10 @@ test('Components -> TimeWidget.mount -> test actions', t => {
t.equal(wrapper.find(Typeahead).length, 1, 'should render dropdown select');
wrapper.find(Typeahead).find('.field-selector_list-item').at(0).simulate('click');
- t.equal(setFilterPlot.args[0][0], 0, 'should pass filteridx to setFilterPlot');
+ t.ok(setFilterPlot.calledOnce, 'should call setFilterPlot again');
+ t.equal(setFilterPlot.getCall(0).args[0], 0, 'should pass filteridx to setFilterPlot');
t.equal(
- setFilterPlot.args[0][1].yAxis.name,
+ setFilterPlot.getCall(0).args[1].yAxis.name,
'gps_data.lat',
'should pass correct yAxis to setFilterPlot'
);
diff --git a/test/fixtures/geojson.js b/test/fixtures/geojson.js
index 5c9c9baa5..29a9ec3d5 100644
--- a/test/fixtures/geojson.js
+++ b/test/fixtures/geojson.js
@@ -2,6 +2,8 @@
// Copyright contributors to the kepler.gl project
import {extent} from 'd3-array';
+import {histogramFromDomain} from '@kepler.gl/utils';
+import {BINS} from '@kepler.gl/constants';
export const geoJsonDataId = 'ieukmgne';
@@ -272,131 +274,9 @@ export const rows = [
// add index to properties
export const datasetAllData = rows;
-export const geoJsonTripHistogram = [
- {count: 1, x0: 4, x1: 4.5},
- {count: 0, x0: 4.5, x1: 5},
- {count: 0, x0: 5, x1: 5.5},
- {count: 0, x0: 5.5, x1: 6},
- {count: 0, x0: 6, x1: 6.5},
- {count: 0, x0: 6.5, x1: 7},
- {count: 0, x0: 7, x1: 7.5},
- {count: 0, x0: 7.5, x1: 8},
- {count: 0, x0: 8, x1: 8.5},
- {count: 0, x0: 8.5, x1: 9},
- {count: 0, x0: 9, x1: 9.5},
- {count: 0, x0: 9.5, x1: 10},
- {count: 0, x0: 10, x1: 10.5},
- {count: 0, x0: 10.5, x1: 11},
- {count: 1, x0: 11, x1: 11.5},
- {count: 0, x0: 11.5, x1: 12},
- {count: 0, x0: 12, x1: 12.5},
- {count: 0, x0: 12.5, x1: 13},
- {count: 0, x0: 13, x1: 13.5},
- {count: 0, x0: 13.5, x1: 14},
- {count: 0, x0: 14, x1: 14.5},
- {count: 0, x0: 14.5, x1: 15},
- {count: 0, x0: 15, x1: 15.5},
- {count: 0, x0: 15.5, x1: 16},
- {count: 0, x0: 16, x1: 16.5},
- {count: 0, x0: 16.5, x1: 17},
- {count: 0, x0: 17, x1: 17.5},
- {count: 0, x0: 17.5, x1: 18},
- {count: 0, x0: 18, x1: 18.5},
- {count: 0, x0: 18.5, x1: 19},
- {count: 0, x0: 19, x1: 19.5},
- {count: 0, x0: 19.5, x1: 20},
- {count: 1, x0: 20, x1: 20}
-];
-
-export const geoJsonTripHistogramEnlarged = [
- {count: 1, x0: 4, x1: 4.2},
- {count: 0, x0: 4.2, x1: 4.4},
- {count: 0, x0: 4.4, x1: 4.6},
- {count: 0, x0: 4.6, x1: 4.8},
- {count: 0, x0: 4.8, x1: 5},
- {count: 0, x0: 5, x1: 5.2},
- {count: 0, x0: 5.2, x1: 5.4},
- {count: 0, x0: 5.4, x1: 5.6},
- {count: 0, x0: 5.6, x1: 5.8},
- {count: 0, x0: 5.8, x1: 6},
- {count: 0, x0: 6, x1: 6.2},
- {count: 0, x0: 6.2, x1: 6.4},
- {count: 0, x0: 6.4, x1: 6.6},
- {count: 0, x0: 6.6, x1: 6.8},
- {count: 0, x0: 6.8, x1: 7},
- {count: 0, x0: 7, x1: 7.2},
- {count: 0, x0: 7.2, x1: 7.4},
- {count: 0, x0: 7.4, x1: 7.6},
- {count: 0, x0: 7.6, x1: 7.8},
- {count: 0, x0: 7.8, x1: 8},
- {count: 0, x0: 8, x1: 8.2},
- {count: 0, x0: 8.2, x1: 8.4},
- {count: 0, x0: 8.4, x1: 8.6},
- {count: 0, x0: 8.6, x1: 8.8},
- {count: 0, x0: 8.8, x1: 9},
- {count: 0, x0: 9, x1: 9.2},
- {count: 0, x0: 9.2, x1: 9.4},
- {count: 0, x0: 9.4, x1: 9.6},
- {count: 0, x0: 9.6, x1: 9.8},
- {count: 0, x0: 9.8, x1: 10},
- {count: 0, x0: 10, x1: 10.2},
- {count: 0, x0: 10.2, x1: 10.4},
- {count: 0, x0: 10.4, x1: 10.6},
- {count: 0, x0: 10.6, x1: 10.8},
- {count: 0, x0: 10.8, x1: 11},
- {count: 1, x0: 11, x1: 11.2},
- {count: 0, x0: 11.2, x1: 11.4},
- {count: 0, x0: 11.4, x1: 11.6},
- {count: 0, x0: 11.6, x1: 11.8},
- {count: 0, x0: 11.8, x1: 12},
- {count: 0, x0: 12, x1: 12.2},
- {count: 0, x0: 12.2, x1: 12.4},
- {count: 0, x0: 12.4, x1: 12.6},
- {count: 0, x0: 12.6, x1: 12.8},
- {count: 0, x0: 12.8, x1: 13},
- {count: 0, x0: 13, x1: 13.2},
- {count: 0, x0: 13.2, x1: 13.4},
- {count: 0, x0: 13.4, x1: 13.6},
- {count: 0, x0: 13.6, x1: 13.8},
- {count: 0, x0: 13.8, x1: 14},
- {count: 0, x0: 14, x1: 14.2},
- {count: 0, x0: 14.2, x1: 14.4},
- {count: 0, x0: 14.4, x1: 14.6},
- {count: 0, x0: 14.6, x1: 14.8},
- {count: 0, x0: 14.8, x1: 15},
- {count: 0, x0: 15, x1: 15.2},
- {count: 0, x0: 15.2, x1: 15.4},
- {count: 0, x0: 15.4, x1: 15.6},
- {count: 0, x0: 15.6, x1: 15.8},
- {count: 0, x0: 15.8, x1: 16},
- {count: 0, x0: 16, x1: 16.2},
- {count: 0, x0: 16.2, x1: 16.4},
- {count: 0, x0: 16.4, x1: 16.6},
- {count: 0, x0: 16.6, x1: 16.8},
- {count: 0, x0: 16.8, x1: 17},
- {count: 0, x0: 17, x1: 17.2},
- {count: 0, x0: 17.2, x1: 17.4},
- {count: 0, x0: 17.4, x1: 17.6},
- {count: 0, x0: 17.6, x1: 17.8},
- {count: 0, x0: 17.8, x1: 18},
- {count: 0, x0: 18, x1: 18.2},
- {count: 0, x0: 18.2, x1: 18.4},
- {count: 0, x0: 18.4, x1: 18.6},
- {count: 0, x0: 18.6, x1: 18.8},
- {count: 0, x0: 18.8, x1: 19},
- {count: 0, x0: 19, x1: 19.2},
- {count: 0, x0: 19.2, x1: 19.4},
- {count: 0, x0: 19.4, x1: 19.6},
- {count: 0, x0: 19.6, x1: 19.8},
- {count: 0, x0: 19.8, x1: 20},
- {count: 1, x0: 20, x1: 20}
-];
-
export const geoJsonTripFilterProps = {
domain: [4, 20],
fieldType: 'integer',
- histogram: geoJsonTripHistogram,
- enlargedHistogram: geoJsonTripHistogramEnlarged,
step: 0.01,
type: 'range',
typeOptions: ['range'],
@@ -409,7 +289,6 @@ export const mergedTripFilter = {
...geoJsonTripFilterProps,
animationWindow: 'free',
dataId: [geoJsonDataId],
- freeze: true,
id: 'TRIPS-3',
enabled: true,
fixedDomain: false,
@@ -419,10 +298,16 @@ export const mergedTripFilter = {
name: ['TRIPS'],
fieldIdx: [4],
value: [4, 12],
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
- interval: null,
- gpuChannel: [0]
+ gpuChannel: [0],
+ bins: {
+ [geoJsonDataId]: histogramFromDomain(
+ [4, 20],
+ rows.map(r => r[4]),
+ BINS
+ )
+ }
};
export const geoJsonRateFilterProps = {
@@ -439,7 +324,6 @@ export const mergedRateFilter = {
animationWindow: 'free',
name: ['RATE'],
dataId: [geoJsonDataId],
- freeze: true,
id: 'RATE-1',
enabled: true,
fixedDomain: false,
@@ -448,9 +332,10 @@ export const mergedRateFilter = {
speed: 1,
fieldIdx: [5],
value: ['a'],
- plotType: 'histogram',
- yAxis: null,
- interval: null
+ plotType: {
+ type: 'histogram'
+ },
+ yAxis: null
};
export const geoBounds = [
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index c17b566d0..130971976 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -3,8 +3,9 @@
import {KeplerGlLayers} from '@kepler.gl/layers';
const {PointLayer, ArcLayer, HexagonLayer, GeojsonLayer} = KeplerGlLayers;
-import {DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI} from '@kepler.gl/constants';
+import {DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI, BINS} from '@kepler.gl/constants';
import {defaultInteractionConfig} from '@kepler.gl/reducers';
+import {getBinThresholds, histogramFromThreshold, histogramFromDomain} from '@kepler.gl/utils';
export const savedStateV0 = {
config: {
@@ -867,7 +868,6 @@ export const expectedFields1 = [
export const mergedFilters = [
{
dataId: ['9h10t7fyb'],
- freeze: true,
id: 'vxzfwyg2v',
enabled: true,
view: 'side',
@@ -879,16 +879,16 @@ export const mergedFilters = [
domain: ['2.103.2', '2.107.3', '2.116.2', '2.117.1', '3.68.4'],
value: ['3.68.4', '2.117.1', '2.103.2', '2.116.2'],
fieldType: 'string',
- plotType: 'histogram',
+ plotType: {
+ type: 'histogram'
+ },
yAxis: null,
- interval: null,
speed: 1,
fixedDomain: false,
gpu: false
},
{
dataId: ['9h10t7fyb'],
- freeze: true,
id: 'fo9tjm2unl',
enabled: true,
view: 'enlarged',
@@ -897,11 +897,13 @@ export const mergedFilters = [
name: ['timestamp_local'],
type: 'timeRange',
fieldIdx: [3],
- plotType: 'histogram',
+ plotType: {
+ interval: '5-second',
+ defaultTimeFormat: 'L LTS',
+ type: 'histogram',
+ aggregation: 'sum'
+ },
yAxis: null,
- interval: null,
- histogram: ['not tested'],
- enlargedHistogram: ['not tested'],
domain: [1453770124000, 1453770810000],
value: [1453770124000, 1453770415000],
step: 1000,
@@ -914,7 +916,26 @@ export const mergedFilters = [
fixedDomain: true,
gpu: true,
gpuChannel: [0],
- defaultTimeFormat: 'L LTS'
+ defaultTimeFormat: 'L LTS',
+ timeBins: {
+ '9h10t7fyb': {
+ '5-second': histogramFromThreshold(
+ getBinThresholds('5-second', [1453770124000, 1453770810000]),
+ [
+ 1453770810000,
+ 1453770279000,
+ 1453770358000,
+ 1453770124000,
+ 1453770131000,
+ 1453770395000,
+ 1453770173000,
+ 1453770394000,
+ 1453770540000
+ ],
+ [0, 1, 2, 3, 4, 5, 6, 7, 8]
+ )
+ }
+ }
},
{
dataId: ['9h10t7fyb'],
@@ -922,7 +943,6 @@ export const mergedFilters = [
enabled: true,
name: ['type_boolean'],
type: 'select',
- freeze: true,
value: false,
view: 'side',
isAnimating: false,
@@ -930,9 +950,10 @@ export const mergedFilters = [
fieldIdx: [10],
domain: [true, false],
fieldType: 'boolean',
- plotType: 'histogram',
+ plotType: {
+ type: 'histogram'
+ },
yAxis: null,
- interval: null,
speed: 1,
fixedDomain: false,
gpu: false
@@ -944,13 +965,11 @@ export const mergedFilters = [
name: ['int_range'],
type: 'range',
value: [78, 309],
- freeze: true,
view: 'side',
- plotType: 'histogram',
+ plotType: {
+ type: 'histogram'
+ },
yAxis: null,
- interval: null,
- histogram: ['not tested'],
- enlargedHistogram: ['not tested'],
isAnimating: false,
animationWindow: 'free',
fieldIdx: [9],
@@ -961,11 +980,17 @@ export const mergedFilters = [
typeOptions: ['range'],
fixedDomain: false,
gpu: true,
- gpuChannel: [1]
+ gpuChannel: [1],
+ bins: {
+ '9h10t7fyb': histogramFromDomain(
+ [78, 694],
+ [694, 335, 363, 78, 192, 242, 175, 223, 298],
+ BINS
+ )
+ }
},
{
dataId: ['v79816te8'],
- freeze: true,
id: '5nfmxjjzl',
enabled: true,
view: 'side',
@@ -974,11 +999,10 @@ export const mergedFilters = [
name: ['ZIP_CODE'],
type: 'range',
fieldIdx: [2],
- plotType: 'histogram',
+ plotType: {
+ type: 'histogram'
+ },
yAxis: null,
- interval: null,
- histogram: ['not tested'],
- enlargedHistogram: ['not tested'],
domain: [94107, 94132],
value: [94115.3, 94132],
step: 0.01,
@@ -987,7 +1011,10 @@ export const mergedFilters = [
typeOptions: ['range'],
fixedDomain: false,
gpu: true,
- gpuChannel: [0]
+ gpuChannel: [0],
+ bins: {
+ v79816te8: histogramFromDomain([94107, 94132], [94107, 94129, 94132, 94132], BINS)
+ }
}
];
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index e8002ab24..42f7a95b0 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -2,11 +2,13 @@
// Copyright contributors to the kepler.gl project
import {KeplerGlLayers} from '@kepler.gl/layers';
-import {DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI} from '@kepler.gl/constants';
+import {DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI, BINS} from '@kepler.gl/constants';
const {GeojsonLayer} = KeplerGlLayers;
import {defaultInteractionConfig} from '@kepler.gl/reducers';
+import {histogramFromDomain} from '@kepler.gl/utils';
+
export const savedStateV1 = {
datasets: [
{
@@ -820,7 +822,6 @@ export const v0ExpectedFields = [
export const mergedFilters = [
{
dataId: ['a5ybmwl2d'],
- freeze: true,
id: '9ca0l7p2a',
enabled: true,
view: 'side',
@@ -832,17 +833,21 @@ export const mergedFilters = [
domain: [0.03, 48.09],
value: [0.03, 21.8],
step: 0.01,
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
- interval: null,
- histogram: ['Not tested'],
- enlargedHistogram: ['Not tested'],
speed: 1,
fieldType: 'real',
typeOptions: ['range'],
fixedDomain: false,
gpu: true,
- gpuChannel: [0]
+ gpuChannel: [0],
+ bins: {
+ a5ybmwl2d: histogramFromDomain(
+ [0.03, 48.09],
+ savedStateV1.datasets[0].data.allData.map(d => d[3]),
+ BINS
+ )
+ }
}
];
diff --git a/test/fixtures/test-csv-data.js b/test/fixtures/test-csv-data.js
index 985c754f9..21dce54c1 100644
--- a/test/fixtures/test-csv-data.js
+++ b/test/fixtures/test-csv-data.js
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
+import {getBinThresholds, histogramFromThreshold} from '@kepler.gl/utils';
+
/* eslint-disable max-len */
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,date
2016-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-23
@@ -621,207 +623,51 @@ export const epochMappedValue = [
1472774400000, 1472774400000, 1472774400000, 1472774400000, 1472774400000, 1472774400000
];
-export const timeHistogram = [
- {count: 8, x0: 1474588800000, x1: 1474589000000},
- {count: 0, x0: 1474589000000, x1: 1474590000000},
- {count: 0, x0: 1474590000000, x1: 1474591000000},
- {count: 0, x0: 1474591000000, x1: 1474592000000},
- {count: 0, x0: 1474592000000, x1: 1474593000000},
- {count: 0, x0: 1474593000000, x1: 1474594000000},
- {count: 0, x0: 1474594000000, x1: 1474595000000},
- {count: 0, x0: 1474595000000, x1: 1474596000000},
- {count: 0, x0: 1474596000000, x1: 1474597000000},
- {count: 0, x0: 1474597000000, x1: 1474598000000},
- {count: 0, x0: 1474598000000, x1: 1474599000000},
- {count: 0, x0: 1474599000000, x1: 1474600000000},
- {count: 0, x0: 1474600000000, x1: 1474601000000},
- {count: 0, x0: 1474601000000, x1: 1474602000000},
- {count: 0, x0: 1474602000000, x1: 1474603000000},
- {count: 0, x0: 1474603000000, x1: 1474604000000},
- {count: 0, x0: 1474604000000, x1: 1474605000000},
- {count: 0, x0: 1474605000000, x1: 1474606000000},
- {count: 3, x0: 1474606000000, x1: 1474607000000},
- {count: 0, x0: 1474607000000, x1: 1474608000000},
- {count: 0, x0: 1474608000000, x1: 1474609000000},
- {count: 0, x0: 1474609000000, x1: 1474610000000},
- {count: 3, x0: 1474610000000, x1: 1474611000000},
- {count: 0, x0: 1474611000000, x1: 1474612000000},
- {count: 0, x0: 1474612000000, x1: 1474613000000},
- {count: 0, x0: 1474613000000, x1: 1474614000000},
- {count: 5, x0: 1474614000000, x1: 1474615000000},
- {count: 0, x0: 1474615000000, x1: 1474616000000},
- {count: 0, x0: 1474616000000, x1: 1474617000000},
- {count: 3, x0: 1474617000000, x1: 1474617600000}
-];
-
-export const enlargedTimeHistogram = [
- {count: 8, x0: 1474588800000, x1: 1474589000000},
- {count: 0, x0: 1474589000000, x1: 1474589200000},
- {count: 0, x0: 1474589200000, x1: 1474589400000},
- {count: 0, x0: 1474589400000, x1: 1474589600000},
- {count: 0, x0: 1474589600000, x1: 1474589800000},
- {count: 0, x0: 1474589800000, x1: 1474590000000},
- {count: 0, x0: 1474590000000, x1: 1474590200000},
- {count: 0, x0: 1474590200000, x1: 1474590400000},
- {count: 0, x0: 1474590400000, x1: 1474590600000},
- {count: 0, x0: 1474590600000, x1: 1474590800000},
- {count: 0, x0: 1474590800000, x1: 1474591000000},
- {count: 0, x0: 1474591000000, x1: 1474591200000},
- {count: 0, x0: 1474591200000, x1: 1474591400000},
- {count: 0, x0: 1474591400000, x1: 1474591600000},
- {count: 0, x0: 1474591600000, x1: 1474591800000},
- {count: 0, x0: 1474591800000, x1: 1474592000000},
- {count: 0, x0: 1474592000000, x1: 1474592200000},
- {count: 0, x0: 1474592200000, x1: 1474592400000},
- {count: 0, x0: 1474592400000, x1: 1474592600000},
- {count: 0, x0: 1474592600000, x1: 1474592800000},
- {count: 0, x0: 1474592800000, x1: 1474593000000},
- {count: 0, x0: 1474593000000, x1: 1474593200000},
- {count: 0, x0: 1474593200000, x1: 1474593400000},
- {count: 0, x0: 1474593400000, x1: 1474593600000},
- {count: 0, x0: 1474593600000, x1: 1474593800000},
- {count: 0, x0: 1474593800000, x1: 1474594000000},
- {count: 0, x0: 1474594000000, x1: 1474594200000},
- {count: 0, x0: 1474594200000, x1: 1474594400000},
- {count: 0, x0: 1474594400000, x1: 1474594600000},
- {count: 0, x0: 1474594600000, x1: 1474594800000},
- {count: 0, x0: 1474594800000, x1: 1474595000000},
- {count: 0, x0: 1474595000000, x1: 1474595200000},
- {count: 0, x0: 1474595200000, x1: 1474595400000},
- {count: 0, x0: 1474595400000, x1: 1474595600000},
- {count: 0, x0: 1474595600000, x1: 1474595800000},
- {count: 0, x0: 1474595800000, x1: 1474596000000},
- {count: 0, x0: 1474596000000, x1: 1474596200000},
- {count: 0, x0: 1474596200000, x1: 1474596400000},
- {count: 0, x0: 1474596400000, x1: 1474596600000},
- {count: 0, x0: 1474596600000, x1: 1474596800000},
- {count: 0, x0: 1474596800000, x1: 1474597000000},
- {count: 0, x0: 1474597000000, x1: 1474597200000},
- {count: 0, x0: 1474597200000, x1: 1474597400000},
- {count: 0, x0: 1474597400000, x1: 1474597600000},
- {count: 0, x0: 1474597600000, x1: 1474597800000},
- {count: 0, x0: 1474597800000, x1: 1474598000000},
- {count: 0, x0: 1474598000000, x1: 1474598200000},
- {count: 0, x0: 1474598200000, x1: 1474598400000},
- {count: 0, x0: 1474598400000, x1: 1474598600000},
- {count: 0, x0: 1474598600000, x1: 1474598800000},
- {count: 0, x0: 1474598800000, x1: 1474599000000},
- {count: 0, x0: 1474599000000, x1: 1474599200000},
- {count: 0, x0: 1474599200000, x1: 1474599400000},
- {count: 0, x0: 1474599400000, x1: 1474599600000},
- {count: 0, x0: 1474599600000, x1: 1474599800000},
- {count: 0, x0: 1474599800000, x1: 1474600000000},
- {count: 0, x0: 1474600000000, x1: 1474600200000},
- {count: 0, x0: 1474600200000, x1: 1474600400000},
- {count: 0, x0: 1474600400000, x1: 1474600600000},
- {count: 0, x0: 1474600600000, x1: 1474600800000},
- {count: 0, x0: 1474600800000, x1: 1474601000000},
- {count: 0, x0: 1474601000000, x1: 1474601200000},
- {count: 0, x0: 1474601200000, x1: 1474601400000},
- {count: 0, x0: 1474601400000, x1: 1474601600000},
- {count: 0, x0: 1474601600000, x1: 1474601800000},
- {count: 0, x0: 1474601800000, x1: 1474602000000},
- {count: 0, x0: 1474602000000, x1: 1474602200000},
- {count: 0, x0: 1474602200000, x1: 1474602400000},
- {count: 0, x0: 1474602400000, x1: 1474602600000},
- {count: 0, x0: 1474602600000, x1: 1474602800000},
- {count: 0, x0: 1474602800000, x1: 1474603000000},
- {count: 0, x0: 1474603000000, x1: 1474603200000},
- {count: 0, x0: 1474603200000, x1: 1474603400000},
- {count: 0, x0: 1474603400000, x1: 1474603600000},
- {count: 0, x0: 1474603600000, x1: 1474603800000},
- {count: 0, x0: 1474603800000, x1: 1474604000000},
- {count: 0, x0: 1474604000000, x1: 1474604200000},
- {count: 0, x0: 1474604200000, x1: 1474604400000},
- {count: 0, x0: 1474604400000, x1: 1474604600000},
- {count: 0, x0: 1474604600000, x1: 1474604800000},
- {count: 0, x0: 1474604800000, x1: 1474605000000},
- {count: 0, x0: 1474605000000, x1: 1474605200000},
- {count: 0, x0: 1474605200000, x1: 1474605400000},
- {count: 0, x0: 1474605400000, x1: 1474605600000},
- {count: 0, x0: 1474605600000, x1: 1474605800000},
- {count: 0, x0: 1474605800000, x1: 1474606000000},
- {count: 0, x0: 1474606000000, x1: 1474606200000},
- {count: 0, x0: 1474606200000, x1: 1474606400000},
- {count: 0, x0: 1474606400000, x1: 1474606600000},
- {count: 0, x0: 1474606600000, x1: 1474606800000},
- {count: 3, x0: 1474606800000, x1: 1474607000000},
- {count: 0, x0: 1474607000000, x1: 1474607200000},
- {count: 0, x0: 1474607200000, x1: 1474607400000},
- {count: 0, x0: 1474607400000, x1: 1474607600000},
- {count: 0, x0: 1474607600000, x1: 1474607800000},
- {count: 0, x0: 1474607800000, x1: 1474608000000},
- {count: 0, x0: 1474608000000, x1: 1474608200000},
- {count: 0, x0: 1474608200000, x1: 1474608400000},
- {count: 0, x0: 1474608400000, x1: 1474608600000},
- {count: 0, x0: 1474608600000, x1: 1474608800000},
- {count: 0, x0: 1474608800000, x1: 1474609000000},
- {count: 0, x0: 1474609000000, x1: 1474609200000},
- {count: 0, x0: 1474609200000, x1: 1474609400000},
- {count: 0, x0: 1474609400000, x1: 1474609600000},
- {count: 0, x0: 1474609600000, x1: 1474609800000},
- {count: 0, x0: 1474609800000, x1: 1474610000000},
- {count: 0, x0: 1474610000000, x1: 1474610200000},
- {count: 0, x0: 1474610200000, x1: 1474610400000},
- {count: 3, x0: 1474610400000, x1: 1474610600000},
- {count: 0, x0: 1474610600000, x1: 1474610800000},
- {count: 0, x0: 1474610800000, x1: 1474611000000},
- {count: 0, x0: 1474611000000, x1: 1474611200000},
- {count: 0, x0: 1474611200000, x1: 1474611400000},
- {count: 0, x0: 1474611400000, x1: 1474611600000},
- {count: 0, x0: 1474611600000, x1: 1474611800000},
- {count: 0, x0: 1474611800000, x1: 1474612000000},
- {count: 0, x0: 1474612000000, x1: 1474612200000},
- {count: 0, x0: 1474612200000, x1: 1474612400000},
- {count: 0, x0: 1474612400000, x1: 1474612600000},
- {count: 0, x0: 1474612600000, x1: 1474612800000},
- {count: 0, x0: 1474612800000, x1: 1474613000000},
- {count: 0, x0: 1474613000000, x1: 1474613200000},
- {count: 0, x0: 1474613200000, x1: 1474613400000},
- {count: 0, x0: 1474613400000, x1: 1474613600000},
- {count: 0, x0: 1474613600000, x1: 1474613800000},
- {count: 0, x0: 1474613800000, x1: 1474614000000},
- {count: 5, x0: 1474614000000, x1: 1474614200000},
- {count: 0, x0: 1474614200000, x1: 1474614400000},
- {count: 0, x0: 1474614400000, x1: 1474614600000},
- {count: 0, x0: 1474614600000, x1: 1474614800000},
- {count: 0, x0: 1474614800000, x1: 1474615000000},
- {count: 0, x0: 1474615000000, x1: 1474615200000},
- {count: 0, x0: 1474615200000, x1: 1474615400000},
- {count: 0, x0: 1474615400000, x1: 1474615600000},
- {count: 0, x0: 1474615600000, x1: 1474615800000},
- {count: 0, x0: 1474615800000, x1: 1474616000000},
- {count: 0, x0: 1474616000000, x1: 1474616200000},
- {count: 0, x0: 1474616200000, x1: 1474616400000},
- {count: 0, x0: 1474616400000, x1: 1474616600000},
- {count: 0, x0: 1474616600000, x1: 1474616800000},
- {count: 0, x0: 1474616800000, x1: 1474617000000},
- {count: 0, x0: 1474617000000, x1: 1474617200000},
- {count: 0, x0: 1474617200000, x1: 1474617400000},
- {count: 0, x0: 1474617400000, x1: 1474617600000},
- {count: 3, x0: 1474617600000, x1: 1474617600000}
+export const timeStampmappedValue = [
+ 1474070995000,
+ 1474071056000,
+ 1474071116000,
+ 1474071178000,
+ 1474071240000,
+ 1474071301000,
+ 1474071363000,
+ 1474071425000,
+ 1474071489000,
+ 1474071552000,
+ 1474071567000,
+ 1474071614000,
+ 1474071677000,
+ 1474071740000,
+ 1474071802000,
+ 1474071864000,
+ 1474071928000,
+ 1474071989000,
+ 1474072051000,
+ 1474072115000,
+ 1474072180000,
+ 1474072203000,
+ 1474072203000,
+ 1474072208000
];
export const timeFilterProps = {
domain: [1474588800000, 1474617600000],
step: 1000,
mappedValue: timeMappedValue,
- histogram: timeHistogram,
- enlargedHistogram: enlargedTimeHistogram,
fieldType: 'timestamp',
type: 'timeRange',
view: 'enlarged',
fixedDomain: true,
gpu: true,
value: [1474588800000, 1474617600000],
- defaultTimeFormat: 'L LTS'
+ defaultTimeFormat: 'L LTS',
+ plotType: {}
};
export const mergedTimeFilter = {
...timeFilterProps,
animationWindow: 'free',
dataId: [dataId],
- freeze: true,
id: 'time-0',
enabled: true,
fixedDomain: true,
@@ -831,26 +677,40 @@ export const mergedTimeFilter = {
name: ['time'],
type: 'timeRange',
fieldIdx: [7],
- plotType: 'histogram',
+ plotType: {
+ interval: '1-hour',
+ defaultTimeFormat: 'L H A',
+ type: 'histogram',
+ aggregation: 'sum'
+ },
yAxis: null,
- interval: null,
value: [1474606800000, 1474617600000],
- gpuChannel: [0]
+ gpuChannel: [0],
+ timeBins: {
+ [dataId]: {
+ '1-hour': [
+ {count: 8, indexes: [0, 1, 2, 3, 4, 7, 8, 15], x0: 1474588800000, x1: 1474592400000},
+ {count: 3, indexes: [5, 6, 10], x0: 1474606800000, x1: 1474610400000},
+ {count: 3, indexes: [9, 13, 14], x0: 1474610400000, x1: 1474614000000},
+ {count: 5, indexes: [16, 17, 18, 19, 20], x0: 1474614000000, x1: 1474617600000},
+ {count: 3, indexes: [21, 22, 23], x0: 1474617600000, x1: 1474621200000}
+ ]
+ }
+ }
};
export const epochFilterProps = {
domain: [1472688000000, 1472774400000],
step: 1000,
mappedValue: epochMappedValue,
- histogram: 'dont test me',
- enlargedHistogram: 'dont test me',
fieldType: 'timestamp',
type: 'timeRange',
view: 'enlarged',
fixedDomain: true,
gpu: true,
value: [1472688000000, 1472774400000],
- defaultTimeFormat: 'L LTS'
+ defaultTimeFormat: 'L LTS',
+ plotType: {}
};
// value set mockStateWithFilters 1472700000000, 1472760000000
@@ -858,7 +718,6 @@ export const mergedEpochFilter = {
...epochFilterProps,
animationWindow: 'free',
dataId: [dataId],
- freeze: true,
id: 'epoch-1',
enabled: true,
fixedDomain: true,
@@ -868,12 +727,97 @@ export const mergedEpochFilter = {
name: ['epoch'],
type: 'timeRange',
fieldIdx: [4],
- plotType: 'histogram',
+ plotType: {
+ interval: '15-minute',
+ defaultTimeFormat: 'L LT',
+ type: 'histogram',
+ aggregation: 'sum'
+ },
yAxis: null,
- interval: null,
value: [1472700000000, 1472760000000],
// time filter is in channel 0
- gpuChannel: [1]
+ gpuChannel: [1],
+ timeBins: {
+ [dataId]: {
+ '15-minute': histogramFromThreshold(
+ getBinThresholds('15-minute', [1472688000000, 1472774400000]),
+ epochMappedValue,
+ epochMappedValue.map((_, i) => i)
+ )
+ }
+ }
+};
+
+export const expectedSyncedTsFilter = {
+ id: 'filter-0',
+ enabled: true,
+ dataId: ['test-csv-data-1', 'test-csv-data-2'],
+ name: ['gps_data.utc_timestamp', 'gps_data.utc_timestamp'],
+ fieldIdx: [0, 0],
+ // domain
+ // 2016-09-17 00:09:55 // 1474070995000
+ // 2016-09-17 00:30:08 // 1474072208000
+ domain: [1474070995000, 1474072208000],
+ value: [1474071116000, 1474071677000],
+ animationWindow: 'free',
+ defaultTimeFormat: 'L LTS',
+ view: 'enlarged',
+ fieldType: 'timestamp',
+ fixedDomain: true,
+ gpu: true,
+ gpuChannel: [0, 0],
+ isAnimating: false,
+ plotType: {
+ interval: '15-second',
+ defaultTimeFormat: 'L LTS',
+ type: 'histogram',
+ aggregation: 'sum',
+ colorsByDataId: {
+ 'test-csv-data-1': '#FF0000',
+ 'test-csv-data-2': '#00FF00'
+ }
+ },
+ speed: 1,
+ step: 1000,
+ type: 'timeRange',
+ yAxis: null,
+ timeBins: {
+ 'test-csv-data-1': {
+ '15-second': histogramFromThreshold(
+ getBinThresholds('15-second', [1474070995000, 1474072208000]),
+ timeStampmappedValue.slice(0, 20),
+ epochMappedValue.map((_, i) => i)
+ )
+ },
+ 'test-csv-data-2': {
+ '15-second': histogramFromThreshold(
+ getBinThresholds('15-second', [1474070995000, 1474072208000]),
+ timeStampmappedValue.slice(5, timeStampmappedValue.length),
+ epochMappedValue.map((_, i) => i)
+ )
+ }
+ },
+ mappedValue: [
+ 1474071301000,
+ 1474071363000,
+ 1474071425000,
+ 1474071489000,
+ 1474071552000,
+ 1474071567000,
+ 1474071614000,
+ 1474071677000,
+ 1474071740000,
+ 1474071802000,
+ 1474071864000,
+ 1474071928000,
+ 1474071989000,
+ 1474072051000,
+ 1474072115000,
+ 1474072180000,
+ 1474072203000,
+ 1474072203000,
+ 1474072208000
+ ]
};
export const dateFilterProps = {
@@ -889,7 +833,6 @@ export const mergedDateFilter = {
...dateFilterProps,
animationWindow: 'free',
dataId: [dataId],
- freeze: true,
id: 'date-2',
enabled: true,
fixedDomain: false,
@@ -900,9 +843,10 @@ export const mergedDateFilter = {
type: 'multiSelect',
fieldIdx: [10],
value: ['2016-09-24', '2016-09-23'],
- plotType: 'histogram',
- yAxis: null,
- interval: null
+ plotType: {
+ type: 'histogram'
+ },
+ yAxis: null
};
export const wktCsvFields = [
@@ -1347,6 +1291,11 @@ export const testAllData = [
]
];
+export const testCsvDataSlice1 = testAllData.slice(0, 20);
+export const testCsvDataSlice1Id = 'test-csv-data-1';
+export const testCsvDataSlice2 = testAllData.slice(5, testAllData.length);
+export const testCsvDataSlice2Id = 'test-csv-data-2';
+
export default data;
// geojson layer from wktcsv
diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.js
index 60161ac72..17e4b8540 100644
--- a/test/fixtures/test-hex-id-data.js
+++ b/test/fixtures/test-hex-id-data.js
@@ -2,8 +2,8 @@
// Copyright contributors to the kepler.gl project
import {KeplerGlLayers} from '@kepler.gl/layers';
-import {createDataContainer} from '@kepler.gl/utils';
-import {DEFAULT_COLOR_UI} from '@kepler.gl/constants';
+import {createDataContainer, histogramFromDomain} from '@kepler.gl/utils';
+import {DEFAULT_COLOR_UI, BINS} from '@kepler.gl/constants';
const {H3Layer} = KeplerGlLayers;
export default `hex_id,value
@@ -150,23 +150,26 @@ export const mergedFilters = [
type: 'range',
value: [11.2, 28],
view: 'side',
- freeze: true,
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
isAnimating: false,
animationWindow: 'free',
fieldIdx: [1],
domain: [1, 76],
step: 0.01,
- interval: null,
- histogram: ['Not tested'],
- enlargedHistogram: ['Not tested'],
speed: 1,
fieldType: 'integer',
typeOptions: ['range'],
fixedDomain: false,
gpuChannel: [0],
- gpu: true
+ gpu: true,
+ bins: {
+ 'h3-hex-id': histogramFromDomain(
+ [1, 76],
+ [64, 73, 65, 74, 66, 76, 43, 40, 36, 27, 32, 26, 19, 18, 1, 3, 2, 4, 6, 1, 1, 1],
+ BINS
+ )
+ }
}
];
@@ -193,125 +196,6 @@ const mergedFields = [
filterProps: {
domain: [1, 76],
step: 0.01,
- histogram: [
- {count: 4, x0: 1, x1: 2},
- {count: 2, x0: 2, x1: 4},
- {count: 1, x0: 4, x1: 6},
- {count: 1, x0: 6, x1: 8},
- {count: 0, x0: 8, x1: 10},
- {count: 0, x0: 10, x1: 12},
- {count: 0, x0: 12, x1: 14},
- {count: 0, x0: 14, x1: 16},
- {count: 0, x0: 16, x1: 18},
- {count: 2, x0: 18, x1: 20},
- {count: 0, x0: 20, x1: 22},
- {count: 0, x0: 22, x1: 24},
- {count: 0, x0: 24, x1: 26},
- {count: 2, x0: 26, x1: 28},
- {count: 0, x0: 28, x1: 30},
- {count: 0, x0: 30, x1: 32},
- {count: 1, x0: 32, x1: 34},
- {count: 0, x0: 34, x1: 36},
- {count: 1, x0: 36, x1: 38},
- {count: 0, x0: 38, x1: 40},
- {count: 1, x0: 40, x1: 42},
- {count: 1, x0: 42, x1: 44},
- {count: 0, x0: 44, x1: 46},
- {count: 0, x0: 46, x1: 48},
- {count: 0, x0: 48, x1: 50},
- {count: 0, x0: 50, x1: 52},
- {count: 0, x0: 52, x1: 54},
- {count: 0, x0: 54, x1: 56},
- {count: 0, x0: 56, x1: 58},
- {count: 0, x0: 58, x1: 60},
- {count: 0, x0: 60, x1: 62},
- {count: 0, x0: 62, x1: 64},
- {count: 2, x0: 64, x1: 66},
- {count: 1, x0: 66, x1: 68},
- {count: 0, x0: 68, x1: 70},
- {count: 0, x0: 70, x1: 72},
- {count: 1, x0: 72, x1: 74},
- {count: 1, x0: 74, x1: 76},
- {count: 1, x0: 76, x1: 76}
- ],
- enlargedHistogram: [
- {count: 4, x0: 1, x1: 2},
- {count: 1, x0: 2, x1: 3},
- {count: 1, x0: 3, x1: 4},
- {count: 1, x0: 4, x1: 5},
- {count: 0, x0: 5, x1: 6},
- {count: 1, x0: 6, x1: 7},
- {count: 0, x0: 7, x1: 8},
- {count: 0, x0: 8, x1: 9},
- {count: 0, x0: 9, x1: 10},
- {count: 0, x0: 10, x1: 11},
- {count: 0, x0: 11, x1: 12},
- {count: 0, x0: 12, x1: 13},
- {count: 0, x0: 13, x1: 14},
- {count: 0, x0: 14, x1: 15},
- {count: 0, x0: 15, x1: 16},
- {count: 0, x0: 16, x1: 17},
- {count: 0, x0: 17, x1: 18},
- {count: 1, x0: 18, x1: 19},
- {count: 1, x0: 19, x1: 20},
- {count: 0, x0: 20, x1: 21},
- {count: 0, x0: 21, x1: 22},
- {count: 0, x0: 22, x1: 23},
- {count: 0, x0: 23, x1: 24},
- {count: 0, x0: 24, x1: 25},
- {count: 0, x0: 25, x1: 26},
- {count: 1, x0: 26, x1: 27},
- {count: 1, x0: 27, x1: 28},
- {count: 0, x0: 28, x1: 29},
- {count: 0, x0: 29, x1: 30},
- {count: 0, x0: 30, x1: 31},
- {count: 0, x0: 31, x1: 32},
- {count: 1, x0: 32, x1: 33},
- {count: 0, x0: 33, x1: 34},
- {count: 0, x0: 34, x1: 35},
- {count: 0, x0: 35, x1: 36},
- {count: 1, x0: 36, x1: 37},
- {count: 0, x0: 37, x1: 38},
- {count: 0, x0: 38, x1: 39},
- {count: 0, x0: 39, x1: 40},
- {count: 1, x0: 40, x1: 41},
- {count: 0, x0: 41, x1: 42},
- {count: 0, x0: 42, x1: 43},
- {count: 1, x0: 43, x1: 44},
- {count: 0, x0: 44, x1: 45},
- {count: 0, x0: 45, x1: 46},
- {count: 0, x0: 46, x1: 47},
- {count: 0, x0: 47, x1: 48},
- {count: 0, x0: 48, x1: 49},
- {count: 0, x0: 49, x1: 50},
- {count: 0, x0: 50, x1: 51},
- {count: 0, x0: 51, x1: 52},
- {count: 0, x0: 52, x1: 53},
- {count: 0, x0: 53, x1: 54},
- {count: 0, x0: 54, x1: 55},
- {count: 0, x0: 55, x1: 56},
- {count: 0, x0: 56, x1: 57},
- {count: 0, x0: 57, x1: 58},
- {count: 0, x0: 58, x1: 59},
- {count: 0, x0: 59, x1: 60},
- {count: 0, x0: 60, x1: 61},
- {count: 0, x0: 61, x1: 62},
- {count: 0, x0: 62, x1: 63},
- {count: 0, x0: 63, x1: 64},
- {count: 1, x0: 64, x1: 65},
- {count: 1, x0: 65, x1: 66},
- {count: 1, x0: 66, x1: 67},
- {count: 0, x0: 67, x1: 68},
- {count: 0, x0: 68, x1: 69},
- {count: 0, x0: 69, x1: 70},
- {count: 0, x0: 70, x1: 71},
- {count: 0, x0: 71, x1: 72},
- {count: 0, x0: 72, x1: 73},
- {count: 1, x0: 73, x1: 74},
- {count: 1, x0: 74, x1: 75},
- {count: 0, x0: 75, x1: 76},
- {count: 1, x0: 76, x1: 76}
- ],
fieldType: 'integer',
value: [1, 76],
type: 'range',
@@ -465,7 +349,7 @@ export const expectedMergedDataset = {
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: 'value',
+ gpuFilter_0: {name: 'value', domain0: 1},
gpuFilter_1: null,
gpuFilter_2: null,
gpuFilter_3: null
diff --git a/test/helpers/comparison-utils.js b/test/helpers/comparison-utils.js
index 6289d8163..c66d8b096 100644
--- a/test/helpers/comparison-utils.js
+++ b/test/helpers/comparison-utils.js
@@ -16,7 +16,14 @@ export function cmpObjectKeys(t, expectedObj, actualObj, name) {
`${name} should have same keys`
);
}
-
+export function cmpBins(t, expected, actual) {
+ t.equal(actual.length, expected.length, 'bins should have same length');
+ actual.forEach((b, i) => {
+ t.equal(b.count, expected[i].count, 'bins count should be same');
+ t.equal(b.x0, expected[i].x0, 'bins x0 should be same');
+ t.equal(b.x1, expected[i].x1, 'bins x1 should be same');
+ });
+}
export function cmpFilters(t, expectedFilter, actualFilter, opt = {}, idx = '', name = '') {
t.equal(typeof actualFilter, typeof expectedFilter, `${name}filters should be same type`);
if (Array.isArray(expectedFilter) && Array.isArray(actualFilter)) {
@@ -38,10 +45,36 @@ export function cmpFilters(t, expectedFilter, actualFilter, opt = {}, idx = '',
Object.keys(actualFilter).forEach(key => {
switch (key) {
- case 'histogram':
- case 'enlargedHistogram':
- if (actualFilter.type === FILTER_TYPES.range || FILTER_TYPES.timeRange) {
- t.ok(actualFilter[key].length, `${name}.filter.${key} should not be empty`);
+ case 'bins':
+ if (actualFilter.type === FILTER_TYPES.range) {
+ cmpObjectKeys(t, expectedFilter.bins, actualFilter.bins, 'filter.bins');
+ Object.keys(expectedFilter.bins).forEach(binDataId => {
+ // cmp bins
+ cmpBins(t, expectedFilter.bins[binDataId], actualFilter.bins[binDataId]);
+ });
+ // t.ok(actualFilter[key].length, `${name}.filter.${key} should not be empty`);
+ }
+ break;
+ case 'timeBins':
+ if (actualFilter.type === FILTER_TYPES.timeRange) {
+ cmpObjectKeys(t, expectedFilter.timeBins, actualFilter.timeBins, 'filter.timeBins');
+ Object.keys(expectedFilter.timeBins).forEach(binDataId => {
+ // cmp bins
+ cmpObjectKeys(
+ t,
+ expectedFilter.timeBins[binDataId],
+ actualFilter.timeBins[binDataId],
+ 'filter.timeBins[binDataId'
+ );
+ Object.keys(expectedFilter.timeBins[binDataId]).forEach(interval => {
+ cmpBins(
+ t,
+ expectedFilter.timeBins[binDataId][interval],
+ actualFilter.timeBins[binDataId][interval]
+ );
+ });
+ });
+ // t.ok(actualFilter[key].length, `${name}.filter.${key} should not be empty`);
}
break;
case 'yAxis':
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index ea44078d4..45eecf510 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -27,7 +27,15 @@ import {
} from '@kepler.gl/actions';
// fixtures
-import {dataId as csvDataId, testFields, testAllData} from '../fixtures/test-csv-data';
+import {
+ dataId as csvDataId,
+ testFields,
+ testAllData,
+ testCsvDataSlice1,
+ testCsvDataSlice1Id,
+ testCsvDataSlice2,
+ testCsvDataSlice2Id
+} from '../fixtures/test-csv-data';
import testLayerData from '../fixtures/test-layer-data';
import {fields, rows, geoJsonDataId} from '../fixtures/geojson';
@@ -125,6 +133,64 @@ export function mockStateWithFileUpload() {
return updatedState;
}
+function mockStateWithSyncedTimeFilter() {
+ const initialState = cloneDeep(InitialState);
+ // load 2 csv data
+ const updatedState = applyActions(keplerGlReducer, initialState, [
+ {
+ action: MapStyleActions.loadMapStyles,
+ payload: [{dark: MOCK_MAP_STYLE}]
+ },
+ {
+ action: VisStateActions.updateVisData,
+ payload: [
+ [
+ {
+ info: {
+ id: testCsvDataSlice1Id,
+ label: 'hello.csv',
+ color: [255, 0, 0]
+ },
+ data: {fields: testFields, rows: testCsvDataSlice1}
+ }
+ ]
+ ]
+ },
+ {
+ action: VisStateActions.updateVisData,
+ payload: [
+ [
+ {
+ info: {
+ id: testCsvDataSlice2Id,
+ label: 'world.csv',
+ color: [0, 255, 0]
+ },
+ data: {fields: testFields, rows: testCsvDataSlice2}
+ }
+ ]
+ ]
+ },
+ // add 1 filter
+ {action: VisStateActions.addFilter, payload: ['test-csv-data-1']},
+
+ // set filter name to 'time', and value
+ {
+ action: VisStateActions.setFilter,
+ // ['2016-09-17 00:11:56', '2016-09-17 00:21:17']
+ payload: [0, ['name', 'value'], ['gps_data.utc_timestamp', [1474071116000, 1474071677000]]]
+ },
+
+ // set filter name and dataId and index 1
+ {
+ action: VisStateActions.setFilter,
+ payload: [0, ['dataId', 'name'], ['test-csv-data-2', 'gps_data.utc_timestamp'], 1]
+ }
+ ]);
+
+ return updatedState;
+}
+
function mockStateWithTripGeojson() {
const initialState = cloneDeep(InitialState);
@@ -212,13 +278,10 @@ export function mockStateWithFilters(state) {
// add filter
{action: VisStateActions.addFilter, payload: [testCsvDataId]},
- // set filter to 'time'
- {action: VisStateActions.setFilter, payload: [0, 'name', 'time']},
-
- // set filter value
+ // set filter name to 'time', and value
{
action: VisStateActions.setFilter,
- payload: [0, 'value', [1474606800000, 1474617600000]]
+ payload: [0, ['name', 'value'], ['time', [1474606800000, 1474617600000]]]
},
// set filter animation speed
@@ -231,10 +294,7 @@ export function mockStateWithFilters(state) {
{action: VisStateActions.addFilter, payload: [testGeoJsonDataId]},
// set filter to 'RATE'
- {action: VisStateActions.setFilter, payload: [1, 'name', 'RATE']},
-
- // set filter value
- {action: VisStateActions.setFilter, payload: [1, 'value', ['a']]}
+ {action: VisStateActions.setFilter, payload: [1, ['name', 'value'], ['RATE', ['a']]]}
]);
// replace filter id with controlled value for easy testing
@@ -264,7 +324,7 @@ function mockStateWithMultiFilters() {
// add another filter
{action: VisStateActions.addFilter, payload: [testGeoJsonDataId]},
- // set filter to 'RATE'
+ // set filter to 'TRIPS'
{action: VisStateActions.setFilter, payload: [3, 'name', 'TRIPS']},
// set filter value
@@ -976,6 +1036,8 @@ export const StateWithGeocoderDataset = mockStateWithGeocoderDataset();
export const StateWLayerStyle = mockStateWithLayerStyling();
export const StateWTripTable = mockStateWithTripTable();
export const StateWArcNeighbors = mockStateWithArcNeighbors();
+export const StateWSyncedTimeFilter = mockStateWithSyncedTimeFilter();
+
export const expectedSavedTripLayer = {
id: 'trip-0',
type: 'trip',
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index b63f39e1b..44910bc50 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -1601,9 +1601,7 @@ test('VisStateMerger.v1 -> mergeFilters -> multiFilters', t => {
disableDataOperation: false,
fields: tFields0,
dataContainer: dc0,
- allIndexes: [
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
- ],
+ allIndexes: dc0.getPlainIndex(),
id: testCsvDataId,
label: 'hello.csv',
color: 'donot test me',
@@ -1624,8 +1622,8 @@ test('VisStateMerger.v1 -> mergeFilters -> multiFilters', t => {
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: 'time',
- gpuFilter_1: 'epoch',
+ gpuFilter_0: {name: 'time', domain0: 1474588800000},
+ gpuFilter_1: {name: 'epoch', domain0: 1472688000000},
gpuFilter_2: null,
gpuFilter_3: null
},
@@ -1669,7 +1667,7 @@ test('VisStateMerger.v1 -> mergeFilters -> multiFilters', t => {
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: 'TRIPS',
+ gpuFilter_0: {name: 'TRIPS', domain0: 4},
gpuFilter_1: null,
gpuFilter_2: null,
gpuFilter_3: null
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index f767260fd..e89a666ff 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -23,8 +23,8 @@ import {
import {processCsvData, processGeojson} from '@kepler.gl/processors';
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 {createNewDataEntry, maybeToDate} from '@kepler.gl/table';
+import {createDataContainer, getDefaultFilter, histogramFromDomain} from '@kepler.gl/utils';
import {
ALL_FIELD_TYPES,
EDITOR_MODES,
@@ -32,7 +32,8 @@ import {
DEFAULT_TEXT_LABEL,
DEFAULT_COLOR_UI,
FILTER_VIEW_TYPES,
- LIGHT_AND_SHADOW_EFFECT
+ LIGHT_AND_SHADOW_EFFECT,
+ BINS
} from '@kepler.gl/constants';
const {ArcLayer, PointLayer, GeojsonLayer, LineLayer, TripLayer} = KeplerGlLayers;
@@ -42,6 +43,7 @@ import testData, {
mergedTimeFilter,
testFields,
testAllData,
+ expectedSyncedTsFilter,
testCsvFieldPairs
} from 'test/fixtures/test-csv-data';
import {
@@ -74,6 +76,7 @@ import {
StateWFilters,
StateWFiles,
StateWFilesFiltersLayerColor,
+ StateWSyncedTimeFilter,
StateWH3Layer,
testCsvDataId,
testGeoJsonDataId,
@@ -81,6 +84,12 @@ import {
} from 'test/helpers/mock-state';
import {getNextColorMakerValue} from 'test/helpers/layer-utils';
import {expectedTripLayerConfig} from '../../fixtures/test-trip-csv-data';
+import {
+ testCsvDataSlice1,
+ testCsvDataSlice2,
+ testCsvDataSlice1Id,
+ testCsvDataSlice2Id
+} from '../../fixtures/test-csv-data';
const mockData = {
fields: [
@@ -1050,7 +1059,7 @@ test('#visStateReducer -> REMOVE_FILTER', t => {
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: 'time',
+ gpuFilter_0: {name: 'time', domain0: 1474588800000},
gpuFilter_1: null,
gpuFilter_2: null,
gpuFilter_3: null
@@ -1076,6 +1085,12 @@ test('#visStateReducer -> REMOVE_FILTER', t => {
...dataset1,
filteredIndex: dataset1.allIndexes,
filteredIndexForDomain: dataset1.allIndexes,
+ changedFilters: {
+ dynamicDomain: {'RATE-1': 'deleted'},
+ fixedDomain: null,
+ cpu: {'RATE-1': 'deleted'},
+ gpu: null
+ },
filterRecord: {
dynamicDomain: [],
fixedDomain: [],
@@ -1453,62 +1468,13 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {
});
test('#visStateReducer -> UPDATE_VIS_DATA.3 -> merge w/ existing state', t => {
- const mockLayer = new PointLayer({
- dataId: 'snowflake',
- columns: {
- lat: {
- value: 'start_point_lat',
- fieldIdx: 0
- },
- lng: {
- value: 'start_point_lng',
- fieldIdx: 1
- }
- }
- });
- const snowflake = new KeplerTable({
- data: {
- fields: [{name: 'a'}, {name: 'b'}],
- rows: [['something'], ['something_else']]
- },
- info: {
- id: 'snowflake'
- }
- });
-
const oldState = {
- ...INITIAL_VIS_STATE,
- layers: [mockLayer],
- layerData: [
- [1, 2],
- [3, 4],
- [5, 6],
- [7, 8]
- ],
- datasets: {
- snowflake
- },
- filters: [
- {name: 'hello', dataId: ['a']},
- {name: 'world', dataId: ['b']}
- ],
- interactionConfig: {
- tooltip: {
- id: 'tooltip',
- enabled: true,
- icon: 'messages',
- config: {
- fieldsToShow: {snowflake: ['a']}
- }
- }
- },
- layerOrder: [mockLayer.id],
- layerBlending: 'additive',
- splitMaps: []
+ ...StateWFiles.visState,
+ layerBlending: 'additive'
};
const expectedDatasets = {
- snowflake,
+ ...StateWFiles.visState.datasets,
smoothie: {
metadata: {
id: 'smoothie',
@@ -1548,8 +1514,9 @@ test('#visStateReducer -> UPDATE_VIS_DATA.3 -> merge w/ existing state', t => {
}
};
- const expectedInteractionTooltip = {
- fieldsToShow: {snowflake: ['a'], smoothie: []}
+ const expectedTooltip = {
+ ...oldState.interactionConfig.tooltip.config.fieldsToShow,
+ smoothie: []
};
const newState = reducer(
@@ -1565,26 +1532,28 @@ test('#visStateReducer -> UPDATE_VIS_DATA.3 -> merge w/ existing state', t => {
Object.keys(expectedDatasets).forEach(key =>
cmpDataset(t, expectedDatasets[key], newState.datasets[key])
);
- t.equal(newState.layers.length, 5, 'should find 1 arc aline and 2 point layers');
+ t.equal(newState.layers.length, 6, 'should find 1 arc 1 line and 2 point layers');
t.deepEqual(
newState.layerOrder,
[
- newState.layers[1].id,
newState.layers[2].id,
newState.layers[3].id,
newState.layers[4].id,
+ newState.layers[5].id,
+ newState.layers[1].id,
newState.layers[0].id
],
'should add new layer index to layer order, put them on top'
);
- t.equal(newState.layers[1].config.dataId, 'smoothie', 'should save dataId to layer');
t.equal(newState.layers[2].config.dataId, 'smoothie', 'should save dataId to layer');
t.equal(newState.layers[3].config.dataId, 'smoothie', 'should save dataId to layer');
- t.equal(newState.layerData.length, 5, 'should calculate layerData');
- t.equal(newState.filters.length, 2, 'should keep original filters');
+ t.equal(newState.layers[4].config.dataId, 'smoothie', 'should save dataId to layer');
+ t.equal(newState.layers[5].config.dataId, 'smoothie', 'should save dataId to layer');
+ t.equal(newState.layerData.length, 6, 'should calculate layerData');
+
t.deepEqual(
- newState.interactionConfig.tooltip.config,
- expectedInteractionTooltip,
+ newState.interactionConfig.tooltip.config.fieldsToShow,
+ expectedTooltip,
'should set interaction config back to default'
);
t.equal(newState.layerBlending, 'additive', 'should keep layerBlending');
@@ -1780,8 +1749,6 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {
const expectedFilterProps = {
domain: [12.249990000000002, 12.290000000000001],
step: 0.00001,
- histogram: [1], // test not empty
- enlargedHistogram: [2], // test not empty
fieldType: 'real',
view: FILTER_VIEW_TYPES.side,
type: mockFilter.type,
@@ -1796,14 +1763,12 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {
dataId: ['smoothie'],
fieldIdx: [0],
id: '38chejr',
- freeze: true,
fixedDomain: false,
view: FILTER_VIEW_TYPES.enlarged,
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
gpu: true,
gpuChannel: [0],
- interval: null,
name: [mockFilter.name],
speed: 1,
isAnimating: false,
@@ -1862,7 +1827,10 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: mockFilter.name,
+ gpuFilter_0: {
+ name: mockFilter.name,
+ domain0: 12.249990000000002
+ },
gpuFilter_1: null,
gpuFilter_2: null,
gpuFilter_3: null
@@ -2052,7 +2020,6 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
const expectedFilter = {
dataId: ['smoothie'],
- freeze: false,
id: 'donnot test me yet',
enabled: true,
name: [],
@@ -2063,10 +2030,9 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
view: FILTER_VIEW_TYPES.side,
isAnimating: false,
animationWindow: 'free',
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
speed: 1,
- interval: null,
gpu: false,
fieldIdx: []
};
@@ -2082,7 +2048,6 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
const expectedFilterWName = {
dataId: ['smoothie'],
- freeze: true,
id: filterId,
enabled: true,
name: ['date'],
@@ -2095,10 +2060,9 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
isAnimating: false,
animationWindow: 'free',
fieldType: 'date',
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
speed: 1,
- interval: null,
gpu: false
};
@@ -2330,7 +2294,6 @@ test('#visStateReducer -> SET_FILTER.name', t => {
const expectedFilter0 = oldFilter0;
const expectedFilter1 = {
dataId: [testGeoJsonDataId],
- freeze: true,
id: 'RATE-1',
enabled: true,
fixedDomain: false,
@@ -2343,16 +2306,20 @@ test('#visStateReducer -> SET_FILTER.name', t => {
fieldIdx: [2],
domain: [94105, 94111],
value: [94105, 94111],
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
- interval: null,
fieldType: 'integer',
step: 0.01,
- histogram: [],
- enlargedHistogram: 'dont test me',
typeOptions: ['range'],
gpu: true,
- gpuChannel: [0]
+ gpuChannel: [0],
+ bins: {
+ [testGeoJsonDataId]: histogramFromDomain(
+ [94105, 94111],
+ geojsonRows.map(d => d[2]),
+ BINS
+ )
+ }
};
cmpFilters(t, [expectedFilter0, expectedFilter1], updated.filters);
@@ -2362,25 +2329,20 @@ test('#visStateReducer -> SET_FILTER.name', t => {
test('#visStateReducer -> SET_FILTER.dataId', t => {
const oldState = CloneDeep(StateWFilters.visState);
+ const oldFilter = {...oldState.filters[1]};
let newState = reducer(oldState, VisStateActions.setFilter(1, 'dataId', testCsvDataId));
let newFilter = newState.filters[1];
- let expectedFilter = {
- ...getDefaultFilter({dataId: testCsvDataId}),
- id: newFilter.id
- };
+ let expectedFilter = getDefaultFilter({dataId: testCsvDataId, id: oldFilter.id});
t.deepEqual(newFilter, expectedFilter, 'Should create a new filter using the provided dataId');
// Using an array of dataId
- newState = reducer(newState, VisStateActions.setFilter(1, 'dataId', [testCsvDataId]));
+ newState = reducer(newState, VisStateActions.setFilter(1, 'dataId', testCsvDataId, 0));
newFilter = newState.filters[1];
- expectedFilter = {
- ...getDefaultFilter({dataId: testCsvDataId}),
- id: newFilter.id
- };
+ expectedFilter = getDefaultFilter({dataId: testCsvDataId, id: newFilter.id});
t.deepEqual(
newFilter,
@@ -2391,6 +2353,262 @@ test('#visStateReducer -> SET_FILTER.dataId', t => {
t.end();
});
+test('#visStateReducer -> SET_FILTER synced', t => {
+ const initialState = StateWSyncedTimeFilter.visState;
+ const oldFilter = {...initialState.filters[0]};
+ const filterId = oldFilter.id;
+
+ // test synced filter
+ expectedSyncedTsFilter.id = filterId;
+
+ const expectedFilteredDataset1 = {
+ ...initialState.datasets[testCsvDataSlice1Id],
+ changedFilters: {
+ dynamicDomain: null,
+ fixedDomain: {
+ [filterId]: 'dataId_changed'
+ },
+ cpu: null,
+ gpu: {
+ [filterId]: 'dataId_changed'
+ }
+ },
+ filterRecord: {
+ cpu: [],
+ dynamicDomain: [],
+ fixedDomain: [
+ // filterRecord cmparison util only check the name
+ {
+ name: ['gps_data.utc_timestamp', 'gps_data.utc_timestamp']
+ }
+ ],
+ gpu: [
+ // filterRecord cmparison util only check the name
+ {
+ name: ['gps_data.utc_timestamp', 'gps_data.utc_timestamp']
+ }
+ ]
+ },
+ gpuFilter: {
+ filterRange: [
+ [121000, 682000],
+ [0, 0],
+ [0, 0],
+ [0, 0]
+ ],
+ filterValueAccessor: {
+ inputs: [
+ {
+ data: testCsvDataSlice1[1],
+ index: 1
+ }
+ ],
+ result: [1474071056000 - 1474070995000, 0, 0, 0]
+ },
+ filterValueUpdateTriggers: {
+ gpuFilter_0: {
+ name: 'gps_data.utc_timestamp',
+ domain0: 1474070995000
+ },
+ gpuFilter_1: null,
+ gpuFilter_2: null,
+ gpuFilter_3: null
+ }
+ }
+ };
+
+ const expectedFilteredDataset2 = {
+ ...initialState.datasets[testCsvDataSlice2Id],
+ changedFilters: {
+ dynamicDomain: null,
+ fixedDomain: {
+ [filterId]: 'added'
+ },
+ cpu: null,
+ gpu: {
+ [filterId]: 'added'
+ }
+ },
+ filterRecord: {
+ cpu: [],
+ dynamicDomain: [],
+ fixedDomain: [
+ // filterRecord cmparison util only check the name
+ {
+ name: ['gps_data.utc_timestamp', 'gps_data.utc_timestamp']
+ }
+ ],
+ gpu: [
+ // filterRecord cmparison util only check the name
+ {
+ name: ['gps_data.utc_timestamp', 'gps_data.utc_timestamp']
+ }
+ ]
+ },
+ gpuFilter: {
+ filterRange: [
+ [121000, 682000],
+ [0, 0],
+ [0, 0],
+ [0, 0]
+ ],
+ filterValueAccessor: {
+ inputs: [
+ {
+ data: testCsvDataSlice2[1],
+ index: 1
+ }
+ ],
+ // 1474071056000
+ result: [1474071363000 - 1474070995000, 0, 0, 0]
+ },
+ filterValueUpdateTriggers: {
+ gpuFilter_0: {
+ name: 'gps_data.utc_timestamp',
+ domain0: 1474070995000
+ },
+ gpuFilter_1: null,
+ gpuFilter_2: null,
+ gpuFilter_3: null
+ }
+ }
+ };
+ cmpFilters(t, expectedSyncedTsFilter, initialState.filters[0]);
+ cmpDataset(t, expectedFilteredDataset1, initialState.datasets[testCsvDataSlice1Id]);
+ cmpDataset(t, expectedFilteredDataset2, initialState.datasets[testCsvDataSlice2Id]);
+
+ t.end();
+});
+
+test('#visStateReducer -> SET_FILTER synced -> remove 1', t => {
+ const initialState = StateWSyncedTimeFilter.visState;
+ const oldFilter = {...initialState.filters[0]};
+ const filterId = oldFilter.id;
+ // remove dataset at filter
+ const resultState = reducer(initialState, VisStateActions.setFilter(0, 'dataId', null, 0));
+ const expectedFilter = {
+ ...expectedSyncedTsFilter,
+ id: oldFilter.id,
+ dataId: ['test-csv-data-2'],
+ name: ['gps_data.utc_timestamp'],
+ fieldIdx: [0],
+ // reset domain
+ domain: [1474071301000, 1474072208000],
+ // adjust value
+ value: [1474071301000, 1474071677000],
+ gpuChannel: [0],
+ timeBins: {
+ 'test-csv-data-2': expectedSyncedTsFilter.timeBins['test-csv-data-2']
+ }
+ };
+
+ const expectedFilteredDataset1 = {
+ ...initialState.datasets[testCsvDataSlice1Id],
+ changedFilters: {
+ dynamicDomain: null,
+ fixedDomain: {
+ [filterId]: 'deleted'
+ },
+ cpu: null,
+ gpu: {
+ [filterId]: 'deleted'
+ }
+ },
+ filterRecord: {
+ cpu: [],
+ dynamicDomain: [],
+ fixedDomain: [],
+ gpu: []
+ },
+ gpuFilter: {
+ filterRange: [
+ [0, 0],
+ [0, 0],
+ [0, 0],
+ [0, 0]
+ ],
+ filterValueAccessor: {
+ inputs: [
+ {
+ data: testCsvDataSlice1[1],
+ index: 1
+ }
+ ],
+ result: [0, 0, 0, 0]
+ },
+ filterValueUpdateTriggers: {
+ gpuFilter_0: null,
+ gpuFilter_1: null,
+ gpuFilter_2: null,
+ gpuFilter_3: null
+ }
+ }
+ };
+
+ const expectedFilteredDataset2 = {
+ ...initialState.datasets[testCsvDataSlice2Id],
+ changedFilters: {
+ dynamicDomain: null,
+ fixedDomain: {
+ [filterId]: 'dataId_changed'
+ },
+ cpu: null,
+ gpu: {
+ [filterId]: 'dataId_changed'
+ }
+ },
+ filterRecord: {
+ cpu: [],
+ dynamicDomain: [],
+ fixedDomain: [
+ // filterRecord cmparison util only check the name
+ {
+ name: ['gps_data.utc_timestamp']
+ }
+ ],
+ gpu: [
+ // filterRecord cmparison util only check the name
+ {
+ name: ['gps_data.utc_timestamp']
+ }
+ ]
+ },
+ gpuFilter: {
+ filterRange: [
+ [0, 376000],
+ [0, 0],
+ [0, 0],
+ [0, 0]
+ ],
+ filterValueAccessor: {
+ inputs: [
+ {
+ data: testCsvDataSlice2[1],
+ index: 1
+ }
+ ],
+ // 1474071056000
+ result: [1474071363000 - 1474071301000, 0, 0, 0]
+ },
+ filterValueUpdateTriggers: {
+ gpuFilter_0: {
+ name: 'gps_data.utc_timestamp',
+ domain0: 1474071301000
+ },
+ gpuFilter_1: null,
+ gpuFilter_2: null,
+ gpuFilter_3: null
+ }
+ }
+ };
+
+ cmpFilters(t, expectedFilter, resultState.filters[0]);
+ cmpDataset(t, expectedFilteredDataset1, resultState.datasets[testCsvDataSlice1Id]);
+ cmpDataset(t, expectedFilteredDataset2, resultState.datasets[testCsvDataSlice2Id]);
+
+ t.end();
+});
+
function testSetFilterDynamicDomainGPU(t, setFilter) {
const {fields, rows} = processGeojson(CloneDeep(geojsonData));
const payload = [
@@ -2414,7 +2632,6 @@ function testSetFilterDynamicDomainGPU(t, setFilter) {
const expectedFilterWName = {
dataId: ['milkshake'],
- freeze: true,
enabled: true,
id: stateWithFilter.filters[0].id,
name: ['TRIPS'],
@@ -2425,20 +2642,53 @@ function testSetFilterDynamicDomainGPU(t, setFilter) {
value: [4, 20],
view: FILTER_VIEW_TYPES.side,
fixedDomain: false,
- histogram: [],
- enlargedHistogram: [],
isAnimating: false,
animationWindow: 'free',
fieldType: 'integer',
typeOptions: ['range'],
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
- interval: null,
speed: 1,
gpu: true,
- gpuChannel: [0]
+ gpuChannel: [0],
+ bins: {
+ milkshake: [
+ {count: 1, x0: 4, x1: 4.5},
+ {count: 0, x0: 4.5, x1: 5},
+ {count: 0, x0: 5, x1: 5.5},
+ {count: 0, x0: 5.5, x1: 6},
+ {count: 0, x0: 6, x1: 6.5},
+ {count: 0, x0: 6.5, x1: 7},
+ {count: 0, x0: 7, x1: 7.5},
+ {count: 0, x0: 7.5, x1: 8},
+ {count: 0, x0: 8, x1: 8.5},
+ {count: 0, x0: 8.5, x1: 9},
+ {count: 0, x0: 9, x1: 9.5},
+ {count: 0, x0: 9.5, x1: 10},
+ {count: 0, x0: 10, x1: 10.5},
+ {count: 0, x0: 10.5, x1: 11},
+ {count: 1, x0: 11, x1: 11.5},
+ {count: 0, x0: 11.5, x1: 12},
+ {count: 0, x0: 12, x1: 12.5},
+ {count: 0, x0: 12.5, x1: 13},
+ {count: 0, x0: 13, x1: 13.5},
+ {count: 0, x0: 13.5, x1: 14},
+ {count: 0, x0: 14, x1: 14.5},
+ {count: 0, x0: 14.5, x1: 15},
+ {count: 0, x0: 15, x1: 15.5},
+ {count: 0, x0: 15.5, x1: 16},
+ {count: 0, x0: 16, x1: 16.5},
+ {count: 0, x0: 16.5, x1: 17},
+ {count: 0, x0: 17, x1: 17.5},
+ {count: 0, x0: 17.5, x1: 18},
+ {count: 0, x0: 18, x1: 18.5},
+ {count: 0, x0: 18.5, x1: 19},
+ {count: 0, x0: 19, x1: 19.5},
+ {count: 0, x0: 19.5, x1: 20},
+ {count: 1, x0: 20, x1: 20}
+ ]
+ }
};
-
// test filter
cmpFilters(t, expectedFilterWName, stateWithFilterName.filters[0]);
@@ -2478,7 +2728,7 @@ function testSetFilterDynamicDomainGPU(t, setFilter) {
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: 'TRIPS',
+ gpuFilter_0: {name: 'TRIPS', domain0: 4},
gpuFilter_1: null,
gpuFilter_2: null,
gpuFilter_3: null
@@ -2595,7 +2845,6 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
const expectedFilterTs = {
dataId: ['smoothie'],
- freeze: true,
fixedDomain: true,
id: filterId,
name: ['gps_data.utc_timestamp'],
@@ -2604,9 +2853,13 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
domain: [1474070995000, 1474072208000],
value: [1474071425000, 1474071740000],
step: 1000,
- plotType: 'histogram',
+ plotType: {
+ type: 'histogram',
+ interval: '15-second',
+ aggregation: 'sum',
+ defaultTimeFormat: 'L LTS'
+ },
yAxis: null,
- interval: null,
speed: 1,
mappedValue: [
1474070995000, 1474071056000, 1474071116000, 1474071178000, 1474071240000, 1474071301000,
@@ -2614,15 +2867,129 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
1474071677000, 1474071740000, 1474071802000, 1474071864000, 1474071928000, 1474071989000,
1474072051000, 1474072115000, 1474072180000, 1474072203000, 1474072203000, 1474072208000
],
- histogram: [],
- enlargedHistogram: [],
view: FILTER_VIEW_TYPES.enlarged,
isAnimating: false,
animationWindow: 'free',
fieldType: 'timestamp',
gpu: true,
gpuChannel: [0],
- defaultTimeFormat: 'L LTS'
+ defaultTimeFormat: 'L LTS',
+ timeBins: {
+ smoothie: {
+ '15-second': [
+ {
+ count: 1,
+ x0: 1474070985000,
+ x1: 1474071000000
+ },
+ {
+ count: 1,
+ x0: 1474071045000,
+ x1: 1474071060000
+ },
+ {
+ count: 1,
+ x0: 1474071105000,
+ x1: 1474071120000
+ },
+ {
+ count: 1,
+ x0: 1474071165000,
+ x1: 1474071180000
+ },
+ {
+ count: 1,
+ x0: 1474071240000,
+ x1: 1474071255000
+ },
+ {
+ count: 1,
+ x0: 1474071300000,
+ x1: 1474071315000
+ },
+ {
+ count: 1,
+ x0: 1474071360000,
+ x1: 1474071375000
+ },
+ {
+ count: 1,
+ x0: 1474071420000,
+ x1: 1474071435000
+ },
+ {
+ count: 1,
+ x0: 1474071480000,
+ x1: 1474071495000
+ },
+ {
+ count: 1,
+ x0: 1474071540000,
+ x1: 1474071555000
+ },
+ {
+ count: 1,
+ x0: 1474071555000,
+ x1: 1474071570000
+ },
+ {
+ count: 1,
+ x0: 1474071600000,
+ x1: 1474071615000
+ },
+ {
+ count: 1,
+ x0: 1474071675000,
+ x1: 1474071690000
+ },
+ {
+ count: 1,
+ x0: 1474071735000,
+ x1: 1474071750000
+ },
+ {
+ count: 1,
+ x0: 1474071795000,
+ x1: 1474071810000
+ },
+ {
+ count: 1,
+ x0: 1474071855000,
+ x1: 1474071870000
+ },
+ {
+ count: 1,
+ x0: 1474071915000,
+ x1: 1474071930000
+ },
+ {
+ count: 1,
+ x0: 1474071975000,
+ x1: 1474071990000
+ },
+ {
+ count: 1,
+ x0: 1474072050000,
+ x1: 1474072065000
+ },
+ {
+ count: 1,
+ x0: 1474072110000,
+ x1: 1474072125000
+ },
+ {
+ count: 1,
+ x0: 1474072170000,
+ x1: 1474072185000
+ },
+ {
+ count: 3,
+ x0: 1474072200000,
+ x1: 1474072215000
+ }
+ ]
+ }
+ }
};
// cmpFilters(t, expectedFilterTs, stateWidthTsFilter.filters[0]);
@@ -2638,12 +3005,11 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
domain: [1474070995000, 1474072208000],
step: 1000,
mappedValue: expectedFilterTs.mappedValue,
- histogram: stateWidthTsFilter.filters[0].histogram,
- enlargedHistogram: stateWidthTsFilter.filters[0].enlargedHistogram,
fieldType: 'timestamp',
type: 'timeRange',
view: FILTER_VIEW_TYPES.enlarged,
fixedDomain: true,
+ plotType: {},
value: [1474070995000, 1474072208000],
gpu: true,
defaultTimeFormat: 'L LTS'
@@ -2665,7 +3031,7 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: 'gps_data.utc_timestamp',
+ gpuFilter_0: {name: 'gps_data.utc_timestamp', domain0: 1474070995000},
gpuFilter_1: null,
gpuFilter_2: null,
gpuFilter_3: null
@@ -2736,7 +3102,7 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
[0, 0]
],
filterValueUpdateTriggers: {
- gpuFilter_0: 'gps_data.utc_timestamp',
+ gpuFilter_0: {name: 'gps_data.utc_timestamp', domain0: 1474070995000},
gpuFilter_1: null,
gpuFilter_2: null,
gpuFilter_3: null
@@ -2770,7 +3136,7 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
t.end();
});
-test('#visStateReducer -> SET_FILTER_PLOT', t => {
+test('#visStateReducer -> SET_FILTER_PLOT.yAxis', t => {
// get test data
const {fields, rows} = processCsvData(testData);
const payload = [
@@ -2806,38 +3172,58 @@ test('#visStateReducer -> SET_FILTER_PLOT', t => {
);
const expectedFilterWName = {
- ...getDefaultFilter({dataId: 'smoothie'}),
- freeze: true,
+ ...getDefaultFilter({dataId: 'smoothie', id: filterId}),
fixedDomain: true,
- id: filterId,
name: ['gps_data.utc_timestamp'],
type: 'timeRange',
fieldIdx: [0],
domain: [1474070995000, 1474072208000],
value: [1474070995000, 1474072208000],
step: 1000,
- plotType: 'lineChart',
+ plotType: {
+ interval: '15-second',
+ defaultTimeFormat: 'L LTS',
+ type: 'lineChart',
+ aggregation: 'sum'
+ },
yAxis: yAxisField,
- interval: null,
lineChart: {
- series: [
- {x: 1474070995000, y: 1},
- {x: 1474071056000, y: 2},
- {x: 1474071116000, y: 3},
- {x: 1474071178000, y: 4},
- {x: 1474071240000, y: 5},
- {x: 1474071301000, y: 12124},
- {x: 1474071363000, y: 222},
- {x: 1474071425000, y: 345},
- {x: 1474071864000, y: 1},
- {x: 1474071989000, y: 43},
- {x: 1474072051000, y: 4},
- {x: 1474072115000, y: 5},
- {x: 1474072203000, y: 6},
- {x: 1474072203000, y: 7}
- ],
- yDomain: [1, 12124],
- xDomain: [1474070995000, 1474072203000]
+ yDomain: [0, 12124],
+ xDomain: [1474070985000, 1474072215000],
+ interval: '15-second',
+ aggregation: 'sum',
+ series: {
+ lines: [
+ [
+ {x: 1474070985000, y: 1, delta: 'last', pct: null},
+ {x: 1474071045000, y: 2, delta: 'last', pct: 1},
+ {x: 1474071105000, y: 3, delta: 'last', pct: 0.5},
+ {x: 1474071165000, y: 4, delta: 'last', pct: 0.3333333333333333},
+ {x: 1474071240000, y: 5, delta: 'last', pct: 0.25},
+ {x: 1474071300000, y: 12124, delta: 'last', pct: 2423.8},
+ {x: 1474071360000, y: 222, delta: 'last', pct: -0.9816892114813592},
+ {x: 1474071420000, y: 345, delta: 'last', pct: 0.5540540540540541},
+ {x: 1474071480000, y: 0, delta: 'last', pct: -1},
+ {x: 1474071540000, y: 0, delta: 'last', pct: null},
+ {x: 1474071555000, y: 0, delta: 'last', pct: null},
+ {x: 1474071600000, y: 0, delta: 'last', pct: null},
+ {x: 1474071675000, y: 0, delta: 'last', pct: null},
+ {x: 1474071735000, y: 0, delta: 'last', pct: null},
+ {x: 1474071795000, y: 0, delta: 'last', pct: null},
+ {x: 1474071855000, y: 1, delta: 'last', pct: null},
+ {x: 1474071915000, y: 0, delta: 'last', pct: -1},
+ {x: 1474071975000, y: 43, delta: 'last', pct: null},
+ {x: 1474072050000, y: 4, delta: 'last', pct: -0.9069767441860465},
+ {x: 1474072110000, y: 5, delta: 'last', pct: 0.25},
+ {x: 1474072170000, y: 0, delta: 'last', pct: -1},
+ {x: 1474072200000, y: 13, delta: 'last', pct: null}
+ ]
+ ],
+ markers: []
+ },
+ title: 'Total of uid',
+ fieldType: 'integer',
+ allTime: {title: 'All Time Average', value: 580.5454545454545}
},
speed: 1,
mappedValue: [
@@ -2846,19 +3232,144 @@ test('#visStateReducer -> SET_FILTER_PLOT', t => {
1474071677000, 1474071740000, 1474071802000, 1474071864000, 1474071928000, 1474071989000,
1474072051000, 1474072115000, 1474072180000, 1474072203000, 1474072203000, 1474072208000
],
- histogram: [],
- enlargedHistogram: [],
view: FILTER_VIEW_TYPES.enlarged,
isAnimating: false,
animationWindow: 'free',
fieldType: 'timestamp',
gpu: true,
gpuChannel: [0],
- defaultTimeFormat: 'L LTS'
+ defaultTimeFormat: 'L LTS',
+ timeBins: {
+ smoothie: {
+ '15-second': [
+ {
+ count: 1,
+ x0: 1474070985000,
+ x1: 1474071000000
+ },
+ {
+ count: 1,
+ x0: 1474071045000,
+ x1: 1474071060000
+ },
+ {
+ count: 1,
+ x0: 1474071105000,
+ x1: 1474071120000
+ },
+ {
+ count: 1,
+ x0: 1474071165000,
+ x1: 1474071180000
+ },
+ {
+ count: 1,
+ x0: 1474071240000,
+ x1: 1474071255000
+ },
+ {
+ count: 1,
+ x0: 1474071300000,
+ x1: 1474071315000
+ },
+ {
+ count: 1,
+ x0: 1474071360000,
+ x1: 1474071375000
+ },
+ {
+ count: 1,
+ x0: 1474071420000,
+ x1: 1474071435000
+ },
+ {
+ count: 1,
+ x0: 1474071480000,
+ x1: 1474071495000
+ },
+ {
+ count: 1,
+ x0: 1474071540000,
+ x1: 1474071555000
+ },
+ {
+ count: 1,
+ x0: 1474071555000,
+ x1: 1474071570000
+ },
+ {
+ count: 1,
+ x0: 1474071600000,
+ x1: 1474071615000
+ },
+ {
+ count: 1,
+ x0: 1474071675000,
+ x1: 1474071690000
+ },
+ {
+ count: 1,
+ x0: 1474071735000,
+ x1: 1474071750000
+ },
+ {
+ count: 1,
+ x0: 1474071795000,
+ x1: 1474071810000
+ },
+ {
+ count: 1,
+ x0: 1474071855000,
+ x1: 1474071870000
+ },
+ {
+ count: 1,
+ x0: 1474071915000,
+ x1: 1474071930000
+ },
+ {
+ count: 1,
+ x0: 1474071975000,
+ x1: 1474071990000
+ },
+ {
+ count: 1,
+ x0: 1474072050000,
+ x1: 1474072065000
+ },
+ {
+ count: 1,
+ x0: 1474072110000,
+ x1: 1474072125000
+ },
+ {
+ count: 1,
+ x0: 1474072170000,
+ x1: 1474072185000
+ },
+ {
+ count: 3,
+ x0: 1474072200000,
+ x1: 1474072215000
+ }
+ ]
+ }
+ }
};
-
// test filter
cmpFilters(t, expectedFilterWName, stateWithFilterPlot.filters[0]);
+
+ // set filterPlot type
+ const stateWithFilterPlotHistogram = reducer(
+ stateWithFilterPlot,
+ VisStateActions.setFilterPlot(0, {plotType: {type: 'histogram'}})
+ );
+ t.deepEqual(
+ stateWithFilterPlotHistogram.filters[0].plotType,
+ {interval: '15-second', defaultTimeFormat: 'L LTS', type: 'histogram', aggregation: 'sum'},
+ 'should set filter plotType to histogram'
+ );
+
t.end();
});
@@ -2999,6 +3510,33 @@ test('#visStateReducer -> REMOVE_DATASET w filter and layer', t => {
t.end();
});
+test('#visStateReducer -> REMOVE_DATASET w synced filter', t => {
+ const initialState = CloneDeep(StateWSyncedTimeFilter.visState);
+ const oldFilter = {...initialState.filters[0]};
+
+ const resultState = reducer(initialState, VisStateActions.removeDataset(testCsvDataSlice1Id));
+
+ t.equal(resultState.filters.length, 1, 'should still have 1 filter');
+ const expectedFilter = {
+ ...expectedSyncedTsFilter,
+ id: oldFilter.id,
+ dataId: ['test-csv-data-2'],
+ name: ['gps_data.utc_timestamp'],
+ fieldIdx: [0],
+ // reset domain
+ domain: [1474071301000, 1474072208000],
+ // adjust value
+ value: [1474071301000, 1474071677000],
+ gpuChannel: [0],
+ timeBins: {
+ 'test-csv-data-2': expectedSyncedTsFilter.timeBins['test-csv-data-2']
+ }
+ };
+ cmpFilters(t, expectedFilter, resultState.filters[0]);
+
+ t.end();
+});
+
test('#visStateReducer -> SPLIT_MAP: TOGGLE', t => {
const layer0 = new ArcLayer({id: 'a', dataId: 'puppy_0', isVisible: true});
const layer1 = new ArcLayer({id: 'b', dataId: 'puppy_0', isVisible: false});
@@ -4145,7 +4683,6 @@ test('#visStateReducer -> POLYGON: Create polygon filter', t => {
const expectedFilter = {
id: newFilter.id,
dataId: [firstDataset],
- freeze: false,
enabled: true,
fixedDomain: true,
view: FILTER_VIEW_TYPES.side,
@@ -4164,9 +4701,8 @@ test('#visStateReducer -> POLYGON: Create polygon filter', t => {
filterId: newFilter.id
}
},
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
- interval: null,
layerId: [newReducer.layers[0].id],
gpu: false
};
@@ -4354,7 +4890,6 @@ test('#visStateReducer -> POLYGON: Toggle filter feature', t => {
const expectedFilter = {
id: newFilter.id,
dataId: ['puppy'],
- freeze: false,
enabled: true,
fixedDomain: true,
view: FILTER_VIEW_TYPES.side,
@@ -4373,9 +4908,8 @@ test('#visStateReducer -> POLYGON: Toggle filter feature', t => {
filterId: newFilter.id
}
},
- plotType: 'histogram',
+ plotType: {type: 'histogram'},
yAxis: null,
- interval: null,
layerId: [newReducer.layers[0].id],
gpu: false
};
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index fa77c3582..f3434f716 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -99,7 +99,12 @@ test('#visStateSchema -> v1 -> save load filters', t => {
type: 'timeRange',
value: [1474606800000, 1474617600000],
view: 'enlarged',
- plotType: 'histogram',
+ plotType: {
+ interval: '1-hour',
+ defaultTimeFormat: 'L H A',
+ type: 'histogram',
+ aggregation: 'sum'
+ },
yAxis: null,
animationWindow: 'free',
speed: 4
@@ -112,7 +117,9 @@ test('#visStateSchema -> v1 -> save load filters', t => {
type: 'multiSelect',
value: ['a'],
view: 'side',
- plotType: 'histogram',
+ plotType: {
+ type: 'histogram'
+ },
yAxis: null,
animationWindow: 'free',
speed: 1
diff --git a/test/node/utils/aggregate-utils-test.js b/test/node/utils/aggregation-test.js
similarity index 87%
rename from test/node/utils/aggregate-utils-test.js
rename to test/node/utils/aggregation-test.js
index 62a1e1e9b..c9cb36df0 100644
--- a/test/node/utils/aggregate-utils-test.js
+++ b/test/node/utils/aggregation-test.js
@@ -5,7 +5,7 @@ import test from 'tape';
import {getFrequency, getMode, aggregate} from '@kepler.gl/utils';
import {AGGREGATION_TYPES} from '@kepler.gl/constants';
-test('AggregateUtils - GetFrequency', t => {
+test('Aggregate - GetFrequency', t => {
t.deepEqual(
getFrequency([2, 1, 2, 1]),
{
@@ -20,13 +20,13 @@ test('AggregateUtils - GetFrequency', t => {
t.end();
});
-test('AggregateUtils - GetMode', t => {
+test('Aggregate - GetMode', t => {
t.deepEqual(getMode([2, 1, 2, 1]), '1', 'should return 1 as Mode');
t.end();
});
-test('AggregateUtils - aggregate', t => {
+test('Aggregate - aggregate', t => {
const data = [1, 2, 3, 1, 2, 3, 4, 3];
const results = [8, 2.375, 4, 1, 2.5, 1.0606601717798212, 19, 1.125, '3', 4];
Object.keys(AGGREGATION_TYPES).map((technique, index) => {
diff --git a/test/node/utils/filter-utils-test.js b/test/node/utils/filter-utils-test.js
index 456712fa4..8ff4d4a14 100644
--- a/test/node/utils/filter-utils-test.js
+++ b/test/node/utils/filter-utils-test.js
@@ -15,7 +15,6 @@ import {
generatePolygonFilter,
isInPolygon,
diffFilters,
- getHistogram,
getTimestampFieldDomain,
createDataContainer
} from '@kepler.gl/utils';
@@ -301,8 +300,7 @@ test('filterUtils -> validatePolygonFilter', t => {
validatePolygonFilter(dataset, filter, layers).filter,
{
...filter,
- fieldIdx: [],
- freeze: true
+ fieldIdx: []
},
'Should positively validate filter'
);
@@ -463,8 +461,6 @@ test('filterUtils -> getTimestampFieldDomain', t => {
expect: {
domain: [1475315139000, 1475315140000],
mappedValue: [1475315139000, 1475315139000],
- histogram: [{count: 2, x0: 1475315139000, x1: 1475315139000}],
- enlargedHistogram: [{count: 2, x0: 1475315139000, x1: 1475315139000}],
step: 0.05,
defaultTimeFormat: 'L LTS'
}
@@ -474,10 +470,6 @@ test('filterUtils -> getTimestampFieldDomain', t => {
expect: {
domain: [1475315139001, 1475315139003],
mappedValue: [1475315139001, 1475315139002, 1475315139003],
- ...getHistogram(
- [1475315139001, 1475315139003],
- [1475315139001, 1475315139002, 1475315139003]
- ),
step: 0.1,
defaultTimeFormat: 'L LTS'
}
@@ -487,8 +479,6 @@ test('filterUtils -> getTimestampFieldDomain', t => {
expect: {
domain: [1475315139010, 1475315139030],
mappedValue: [1475315139010, 1475315139020, 1475315139030],
- histogram: [],
- enlargedHistogram: [],
step: 1,
defaultTimeFormat: 'L LTS'
}
@@ -498,8 +488,6 @@ test('filterUtils -> getTimestampFieldDomain', t => {
expect: {
domain: [1475315139100, 1475315139300],
mappedValue: [1475315139100, 1475315139200, 1475315139300],
- histogram: [],
- enlargedHistogram: [],
step: 5,
defaultTimeFormat: 'L LTS'
}
@@ -509,8 +497,6 @@ test('filterUtils -> getTimestampFieldDomain', t => {
expect: {
domain: [1475315139000, 1475315145000],
mappedValue: [1475315139000, 1475315145000],
- histogram: [],
- enlargedHistogram: [],
step: 1000,
defaultTimeFormat: 'L LTS'
}
@@ -530,15 +516,7 @@ test('filterUtils -> getTimestampFieldDomain', t => {
Object.keys(timeData[key].expect).forEach(k => {
// histogram is created by d3, only need to test they exist
- if (k === 'histogram' || k === 'enlargedHistogram') {
- t.ok(tsFieldDomain[k].length, `should create ${k}`);
- } else {
- t.deepEqual(
- tsFieldDomain[k],
- timeData[key].expect[k],
- `time domain ${k} should be the same`
- );
- }
+ t.deepEqual(tsFieldDomain[k], timeData[key].expect[k], `time domain ${k} should be the same`);
});
});
diff --git a/test/node/utils/index.js b/test/node/utils/index.js
index 1826501e6..2a857792a 100644
--- a/test/node/utils/index.js
+++ b/test/node/utils/index.js
@@ -13,7 +13,7 @@ import './interaction-utils-test';
import './mapbox-gl-style-editor-test';
import './mapbox-utils-test';
import './notifications-utils-test';
-import './aggregate-utils-test';
+import './aggregation-test';
import './color-util-test';
import './util-test';
import './export-utils-test';
diff --git a/test/node/utils/util-test.js b/test/node/utils/util-test.js
index bfa607f4c..8577a0742 100644
--- a/test/node/utils/util-test.js
+++ b/test/node/utils/util-test.js
@@ -2,15 +2,8 @@
// Copyright contributors to the kepler.gl project
import test from 'tape';
-import {
- set,
- toArray,
- getError,
- camelToTitle,
- camelize,
- capitalizeFirstLetter,
- arrayInsert
-} from '@kepler.gl/utils';
+import {set, toArray, getError, camelToTitle, camelize, arrayInsert} from '@kepler.gl/utils';
+import {capitalizeFirstLetter} from '@kepler.gl/utils';
test('Utils -> set', t => {
const obj1 = {map: {map1: 'world'}};
diff --git a/yarn.lock b/yarn.lock
index ef50d30ad..d63c32a49 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2859,7 +2859,7 @@ __metadata:
"@nebula.gl/edit-modes": "npm:1.0.2-alpha.1"
"@tippyjs/react": "npm:^4.2.0"
"@types/classnames": "npm:^2.3.1"
- "@types/d3-array": "npm:^2.0.0"
+ "@types/d3-array": "npm:^2.8.0"
"@types/d3-brush": "npm:^3.0.1"
"@types/d3-scale": "npm:^3.2.2"
"@types/d3-selection": "npm:^3.0.2"
@@ -2962,7 +2962,7 @@ __metadata:
"@luma.gl/core": "npm:^8.5.20"
"@mapbox/geo-viewport": "npm:^0.4.1"
"@mapbox/vector-tile": "npm:^1.3.1"
- "@types/d3-array": "npm:^2.0.0"
+ "@types/d3-array": "npm:^2.8.0"
"@types/geojson": "npm:^7946.0.8"
"@types/lodash.memoize": "npm:^4.1.7"
"@types/supercluster": "npm:^7.1.0"
@@ -3153,7 +3153,7 @@ __metadata:
"@kepler.gl/layers": "npm:3.0.0"
"@kepler.gl/types": "npm:3.0.0"
"@kepler.gl/utils": "npm:3.0.0"
- "@types/d3-array": "npm:^2.0.0"
+ "@types/d3-array": "npm:^2.8.0"
"@types/lodash.uniq": "npm:^4.5.7"
d3-array: "npm:^2.8.0"
global: "npm:^4.3.0"
@@ -3188,7 +3188,7 @@ __metadata:
"@mapbox/geo-viewport": "npm:^0.4.1"
"@turf/boolean-within": "npm:^6.0.1"
"@turf/helpers": "npm:^6.1.4"
- "@types/d3-array": "npm:^2.0.0"
+ "@types/d3-array": "npm:^2.8.0"
"@types/keymirror": "npm:^0.1.1"
"@types/lodash.clonedeep": "npm:^4.5.7"
"@types/lodash.get": "npm:^4.4.6"
@@ -5066,7 +5066,7 @@ __metadata:
languageName: node
linkType: hard
-"@types/d3-array@npm:^2.0.0":
+"@types/d3-array@npm:^2.8.0":
version: 2.12.7
resolution: "@types/d3-array@npm:2.12.7"
checksum: 10c0/31f9fc63e14de866630c526ac479b0854ad936b699fdd6a43df52628861ee50faddd6973e27cd3531193fc061c072810b0a07443921cb89e213988262c185312
@@ -15467,7 +15467,7 @@ __metadata:
"@testing-library/jest-dom": "npm:^5.16.5"
"@testing-library/react": "npm:^14.0.0"
"@testing-library/user-event": "npm:^14.4.3"
- "@types/d3-array": "npm:^2.0.0"
+ "@types/d3-array": "npm:^2.8.0"
"@types/d3-scale": "npm:^3.2.2"
"@types/geojson": "npm:^7946.0.8"
"@types/jsdom": "npm:^21.1.1"