Skip to content

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

feat: improvements for timeline chart settings (#3444)

Igor Dykhta4c6398325fe4
diff --git a/src/components/src/common/histogram-plot.tsx b/src/components/src/common/histogram-plot.tsx
index c7ca39873..7410fb4de 100644
--- a/src/components/src/common/histogram-plot.tsx
+++ b/src/components/src/common/histogram-plot.tsx
@@ -37,6 +37,11 @@ const HistogramBreakLine = styled.g`
transform: translate(0, 0);
`;
+const YAxisTick = styled.text`
+ font-size: 9px;
+ fill: ${props => props.theme.textColor};
+`;
+
type BarType = {
$inRange: boolean;
$isOverlay: boolean;
@@ -90,6 +95,7 @@ interface HistogramPlotProps {
height: number;
margin: {top: number; bottom: number; left: number; right: number};
isRanged?: boolean;
+ isEnlarged?: boolean;
value: number[];
isMasked?: number;
brushComponent?: ReactElement;
@@ -107,6 +113,7 @@ function HistogramPlotFactory() {
histogramsByGroup,
colorsByGroup,
isMasked = HISTOGRAM_MASK_MODE.NoMask,
+ isEnlarged,
countProp = 'count',
margin,
isRanged,
@@ -164,6 +171,17 @@ function HistogramPlotFactory() {
[histogramsByGroup, groupKeys, height, countProp]
);
+ const yAxisTicks = useMemo(() => {
+ if (!isEnlarged) return null;
+ const yMax = Math.max(
+ Number(max(groupKeys, key => max(histogramsByGroup[key], d => d[countProp]))),
+ 1
+ );
+ const tickCount = 3;
+ const ticks = scaleLinear().domain([0, yMax]).ticks(tickCount);
+ return ticks;
+ }, [isEnlarged, groupKeys, histogramsByGroup, countProp]);
+
if (groupKeys.length === 0) {
return null;
}
@@ -301,6 +319,21 @@ function HistogramPlotFactory() {
</g>
))}
</g>
+ {yAxisTicks ? (
+ <g className="histogram-y-axis">
+ {yAxisTicks.map(tick => (
+ <YAxisTick
+ key={tick}
+ x={-4}
+ y={height - y(tick)}
+ textAnchor="end"
+ dominantBaseline="middle"
+ >
+ {tick}
+ </YAxisTick>
+ ))}
+ </g>
+ ) : null}
<g transform={`translate(${isRanged ? 0 : fallbackBarWidth / 2}, 0)`}>{brushComponent}</g>
</HistogramWrapper>
);
diff --git a/src/components/src/filters/index.ts b/src/components/src/filters/index.ts
index 51f051515..c07bf1948 100644
--- a/src/components/src/filters/index.ts
+++ b/src/components/src/filters/index.ts
@@ -8,3 +8,4 @@ export {default as RangeFilter} from './range-filter';
export {default as PolygonFilter} from './polygon-filter';
export {default as TimeWidget} from './time-widget';
export {default as TimeWidgetTop} from './time-widget-top';
+export {default as TimeWidgetSettings} from './time-widget-settings';
diff --git a/src/components/src/filters/time-widget-settings.tsx b/src/components/src/filters/time-widget-settings.tsx
new file mode 100644
index 000000000..382edd7ce
--- /dev/null
+++ b/src/components/src/filters/time-widget-settings.tsx
@@ -0,0 +1,442 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import React, {useCallback, useEffect, useMemo, useState} from 'react';
+import styled from 'styled-components';
+import ItemSelector from '../common/item-selector/item-selector';
+import FieldSelectorFactory from '../common/field-selector';
+import Switch from '../common/switch';
+import {ArrowRight} from '../common/icons';
+import {
+ TIME_AGGREGATION,
+ AGGREGATION_TYPES,
+ durationMillisecond,
+ durationSecond,
+ durationMinute,
+ durationHour,
+ durationDay,
+ durationWeek,
+ durationMonth,
+ durationYear
+} from '@kepler.gl/constants';
+import {TimeRangeFilter, Field} from '@kepler.gl/types';
+import {Datasets} from '@kepler.gl/table';
+import {getDefaultTimeFormat} from '@kepler.gl/utils';
+
+const MAX_BINS = 2048;
+
+const INTERVAL_UNITS = [
+ {id: 'millisecond', label: 'Millisecond', duration: durationMillisecond},
+ {id: 'second', label: 'Second', duration: durationSecond},
+ {id: 'minute', label: 'Minute', duration: durationMinute},
+ {id: 'hour', label: 'Hour', duration: durationHour},
+ {id: 'day', label: 'Day', duration: durationDay},
+ {id: 'week', label: 'Week', duration: durationWeek},
+ {id: 'month', label: 'Month', duration: durationMonth},
+ {id: 'year', label: 'Year', duration: durationYear}
+];
+
+const SettingsPanel = styled.div`
+ display: flex;
+ flex-direction: column;
+ padding: 4px 0 8px 0;
+ gap: 12px;
+`;
+
+const AxisSection = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+`;
+
+const AxisHeader = styled.div`
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ color: ${props => props.theme.textColor};
+ font-size: 11px;
+ font-weight: 600;
+ white-space: nowrap;
+`;
+
+const AxisRow = styled.div`
+ display: flex;
+ align-items: flex-end;
+ gap: 25px;
+`;
+
+const FieldBlock = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: 3px;
+`;
+
+const FieldLabel = styled.span`
+ color: ${props => props.theme.labelColor};
+ font-size: 10px;
+ font-weight: 400;
+ white-space: nowrap;
+`;
+
+const FieldValue = styled.span`
+ color: ${props => props.theme.textColor};
+ font-size: 11px;
+ font-weight: 500;
+ width: 160px;
+ height: 28px;
+ display: flex;
+ align-items: center;
+`;
+
+const SelectorWrapper = styled.div`
+ width: 120px;
+
+ .item-selector__dropdown {
+ background: ${props => props.theme.secondaryInputBgd};
+ border-color: ${props => props.theme.secondaryInputBorderColor};
+ height: 28px;
+ padding: 2px 8px;
+ font-size: 11px;
+ }
+`;
+
+const FieldSelectorWrapper = styled.div`
+ width: 160px;
+
+ .item-selector__dropdown {
+ background: ${props => props.theme.secondaryInputBgd};
+ border-color: ${props => props.theme.secondaryInputBorderColor};
+ height: 28px;
+ padding: 2px 8px;
+ font-size: 11px;
+ }
+`;
+
+type StepInputProps = {
+ $hasError?: boolean;
+};
+
+const StepInput = styled.input<StepInputProps>`
+ width: 48px;
+ height: 28px;
+ padding: 2px 8px;
+ font-size: 11px;
+ border-radius: 4px;
+ border: 1px solid
+ ${props => (props.$hasError ? props.theme.errorColor : props.theme.secondaryInputBorderColor)};
+ background: ${props => props.theme.secondaryInputBgd};
+ color: ${props => props.theme.textColor};
+ outline: none;
+
+ &::-webkit-outer-spin-button,
+ &::-webkit-inner-spin-button {
+ -webkit-appearance: none;
+ margin: 0;
+ }
+ -moz-appearance: textfield;
+
+ &:focus {
+ border-color: ${props =>
+ props.$hasError ? props.theme.errorColor : props.theme.primaryBtnBgd};
+ }
+`;
+
+type UnitSelectorWrapperProps = {
+ $hasError?: boolean;
+};
+
+const UnitSelectorWrapper = styled.div<UnitSelectorWrapperProps>`
+ width: 110px;
+
+ .item-selector__dropdown {
+ background: ${props => props.theme.secondaryInputBgd};
+ border-color: ${props =>
+ props.$hasError ? props.theme.errorColor : props.theme.secondaryInputBorderColor};
+ height: 28px;
+ padding: 2px 8px;
+ font-size: 11px;
+ }
+`;
+
+const IntervalGroup = styled.div`
+ display: flex;
+ align-items: center;
+ gap: 3px;
+`;
+
+const ErrorMessage = styled.span`
+ color: ${props => props.theme.errorColor};
+ font-size: 10px;
+ white-space: nowrap;
+`;
+
+const SwitchBlock = styled.div`
+ display: flex;
+ align-items: center;
+ height: 28px;
+`;
+
+type DisabledOverlayProps = {
+ $disabled?: boolean;
+};
+
+const DisabledBlock = styled.div<DisabledOverlayProps>`
+ opacity: ${props => (props.$disabled ? 0.4 : 1)};
+ pointer-events: ${props => (props.$disabled ? 'none' : 'auto')};
+`;
+
+export type TimeWidgetSettingsProps = {
+ filter: TimeRangeFilter;
+ datasets: Datasets;
+ setFilterPlot: (newProp: any, valueIndex?: number) => void;
+};
+
+function parseInterval(intervalId: string | undefined): {step: number; unit: string} {
+ if (!intervalId) return {step: 1, unit: 'day'};
+ const parts = intervalId.split('-');
+ if (parts.length === 2) {
+ return {step: parseInt(parts[0], 10) || 1, unit: parts[1]};
+ }
+ return {step: 1, unit: 'day'};
+}
+
+TimeWidgetSettingsFactory.deps = [FieldSelectorFactory];
+
+function TimeWidgetSettingsFactory(FieldSelector: ReturnType<typeof FieldSelectorFactory>) {
+ const TimeWidgetSettings: React.FC<TimeWidgetSettingsProps> = ({
+ filter,
+ datasets,
+ setFilterPlot
+ }) => {
+ const {plotType} = filter;
+ const currentInterval = plotType?.interval;
+ const currentAggregation = plotType?.aggregation || AGGREGATION_TYPES.average;
+
+ const {step: parsedStep, unit: parsedUnit} = useMemo(
+ () => parseInterval(currentInterval),
+ [currentInterval]
+ );
+
+ const [stepValue, setStepValue] = useState<string>(String(parsedStep));
+ const [unitValue, setUnitValue] = useState<string>(parsedUnit);
+
+ useEffect(() => {
+ setStepValue(String(parsedStep));
+ }, [parsedStep]);
+
+ useEffect(() => {
+ setUnitValue(parsedUnit);
+ }, [parsedUnit]);
+
+ const effectiveStep = useMemo(() => {
+ const num = parseInt(stepValue, 10);
+ return num > 0 ? num : parsedStep;
+ }, [stepValue, parsedStep]);
+
+ const isIntervalTooSmall = useCallback(
+ (step: number, unit: string) => {
+ const timeSpan = filter.domain ? filter.domain[1] - filter.domain[0] : 0;
+ const unitDuration = INTERVAL_UNITS.find(u => u.id === unit)?.duration || durationDay;
+ const count = timeSpan / (step * unitDuration);
+ return count > MAX_BINS;
+ },
+ [filter.domain]
+ );
+
+ const intervalTooSmall = useMemo(() => {
+ return isIntervalTooSmall(effectiveStep, unitValue);
+ }, [isIntervalTooSmall, effectiveStep, unitValue]);
+
+ const aggregationOptions = useMemo(() => TIME_AGGREGATION, []);
+
+ const yAxisFields = useMemo(
+ () =>
+ ((datasets[filter.dataId[0]] || {}).fields || []).filter(
+ (f: Field) => f.type === 'integer' || f.type === 'real'
+ ),
+ [datasets, filter.dataId]
+ );
+
+ const applyInterval = useCallback(
+ (step: number, unit: string) => {
+ if (isIntervalTooSmall(step, unit)) {
+ return;
+ }
+ const intervalId = `${step}-${unit}`;
+ const defaultTimeFormat = getDefaultTimeFormat(intervalId);
+ setFilterPlot({plotType: {interval: intervalId, defaultTimeFormat}});
+ },
+ [setFilterPlot, isIntervalTooSmall]
+ );
+
+ const onStepChange = useCallback(
+ (e: React.ChangeEvent<HTMLInputElement>) => {
+ const val = e.target.value;
+ setStepValue(val);
+ },
+ []
+ );
+
+ const onStepBlur = useCallback(() => {
+ const num = parseInt(stepValue, 10);
+ if (num > 0) {
+ applyInterval(num, unitValue);
+ } else {
+ setStepValue(String(parsedStep));
+ }
+ }, [stepValue, unitValue, parsedStep, applyInterval]);
+
+ const onStepKeyDown = useCallback(
+ (e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === 'Enter') {
+ (e.target as HTMLInputElement).blur();
+ }
+ },
+ []
+ );
+
+ const onUnitChange = useCallback(
+ (value: any) => {
+ if (value) {
+ const unitId = typeof value === 'string' ? value : value.id;
+ setUnitValue(unitId);
+ applyInterval(effectiveStep, unitId);
+ }
+ },
+ [effectiveStep, applyInterval]
+ );
+
+ const onAggregationChange = useCallback(
+ (value: any) => {
+ if (value) {
+ setFilterPlot({plotType: {aggregation: value}});
+ }
+ },
+ [setFilterPlot]
+ );
+
+ const _setFilterPlotYAxis = useCallback(
+ value => setFilterPlot({yAxis: value}),
+ [setFilterPlot]
+ );
+
+ const _toggleYAxisAutoRange = useCallback(
+ () => setFilterPlot({plotType: {yAxisAutoRange: !filter.plotType?.yAxisAutoRange}}),
+ [setFilterPlot, filter.plotType?.yAxisAutoRange]
+ );
+
+ const displayUnitOption = useCallback((opt: any) => {
+ if (typeof opt === 'string') {
+ return INTERVAL_UNITS.find(u => u.id === opt)?.label || opt;
+ }
+ return opt?.label || '';
+ }, []);
+
+ const displayAggregationOption = useCallback(
+ (opt: any) => {
+ if (typeof opt === 'string') {
+ return aggregationOptions.find(o => o.id === opt)?.label || opt;
+ }
+ return opt?.label || '';
+ },
+ [aggregationOptions]
+ );
+
+ return (
+ <SettingsPanel className="time-widget--settings">
+ <AxisSection>
+ <AxisHeader><ArrowRight height="10px" />X Axis</AxisHeader>
+ <AxisRow>
+ <FieldBlock>
+ <FieldLabel>Select Field</FieldLabel>
+ <FieldValue>{filter.name}</FieldValue>
+ </FieldBlock>
+ <FieldBlock>
+ <FieldLabel>Interval</FieldLabel>
+ <IntervalGroup>
+ <StepInput
+ type="number"
+ min={1}
+ value={stepValue}
+ onChange={onStepChange}
+ onBlur={onStepBlur}
+ onKeyDown={onStepKeyDown}
+ $hasError={intervalTooSmall}
+ />
+ <UnitSelectorWrapper $hasError={intervalTooSmall}>
+ <ItemSelector
+ selectedItems={unitValue}
+ options={INTERVAL_UNITS}
+ multiSelect={false}
+ onChange={onUnitChange}
+ getOptionValue={o => o.id}
+ displayOption={displayUnitOption}
+ placement="top"
+ searchable={false}
+ />
+ </UnitSelectorWrapper>
+ </IntervalGroup>
+ </FieldBlock>
+ </AxisRow>
+ {intervalTooSmall ? (
+ <ErrorMessage>Interval is too small</ErrorMessage>
+ ) : null}
+ </AxisSection>
+ <AxisSection>
+ <AxisHeader><ArrowRight height="10px" />Y Axis</AxisHeader>
+ <AxisRow>
+ <FieldBlock>
+ <FieldLabel>Select Field</FieldLabel>
+ <FieldSelectorWrapper>
+ <FieldSelector
+ fields={yAxisFields}
+ placement="top"
+ id="selected-time-widget-field"
+ value={filter.yAxis ? filter.yAxis.name : null}
+ onSelect={_setFilterPlotYAxis}
+ placeholder="placeholder.yAxis"
+ erasable
+ showToken={false}
+ />
+ </FieldSelectorWrapper>
+ </FieldBlock>
+ <DisabledBlock $disabled={!filter.yAxis}>
+ <FieldBlock>
+ <FieldLabel>Aggregation</FieldLabel>
+ <SelectorWrapper>
+ <ItemSelector
+ selectedItems={currentAggregation}
+ options={aggregationOptions}
+ multiSelect={false}
+ onChange={onAggregationChange}
+ getOptionValue={o => o.id}
+ displayOption={displayAggregationOption}
+ placement="top"
+ searchable={false}
+ />
+ </SelectorWrapper>
+ </FieldBlock>
+ </DisabledBlock>
+ <DisabledBlock $disabled={!filter.yAxis}>
+ <FieldBlock>
+ <FieldLabel>Fit Y</FieldLabel>
+ <SwitchBlock>
+ <Switch
+ checked={Boolean(filter.plotType?.yAxisAutoRange)}
+ id={`${filter.id}-y-axis-auto-range`}
+ onChange={_toggleYAxisAutoRange}
+ secondary
+ />
+ </SwitchBlock>
+ </FieldBlock>
+ </DisabledBlock>
+ </AxisRow>
+ </AxisSection>
+ </SettingsPanel>
+ );
+ };
+
+ return TimeWidgetSettings;
+}
+
+export default TimeWidgetSettingsFactory;
diff --git a/src/components/src/filters/time-widget-top.tsx b/src/components/src/filters/time-widget-top.tsx
index aa0c5ff95..e4850645c 100644
--- a/src/components/src/filters/time-widget-top.tsx
+++ b/src/components/src/filters/time-widget-top.tsx
@@ -1,14 +1,12 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import React, {useCallback, useMemo} from 'react';
+import React, {useMemo} from 'react';
import styled, {IStyledComponent} from 'styled-components';
-import {Clock, Close, LineChart, ArrowDown, ArrowUp} from '../common/icons';
-import FieldSelectorFactory from '../common/field-selector';
-import Switch from '../common/switch';
+import {Clock, Close, ArrowDown, ArrowUp, Gear} from '../common/icons';
import {SelectTextBold, IconRoundSmall, CenterFlexbox} from '../common/styled-components';
import {TimeWidgetTopProps, TopSectionWrapperProps} from './types';
-import {Field} from '@kepler.gl/types';
+import {TIME_AGGREGATION, AGGREGATION_TYPES} from '@kepler.gl/constants';
const TOP_SECTION_HEIGHT = '36px';
@@ -21,40 +19,6 @@ const TopSectionWrapper: IStyledComponent<'web', TopSectionWrapperProps> = style
color: ${props => props.theme.labelColor};
height: ${TOP_SECTION_HEIGHT};
- .bottom-widget__y-axis {
- flex-grow: 1;
- margin-left: 20px;
- }
-
- .bottom-widget__field-select {
- width: 160px;
- display: inline-block;
-
- .item-selector__dropdown {
- background: transparent;
- padding: 4px 10px 4px 4px;
- border-color: transparent;
-
- &:active,
- &:focus,
- &.focus,
- &.active {
- background: transparent;
- border-color: transparent;
- }
- }
-
- .item-selector__dropdown:hover {
- background: transparent;
- border-color: transparent;
-
- .item-selector__dropdown__value {
- color: ${props =>
- props.hoverColor ? props.theme[props.hoverColor] : props.theme.textColorHl};
- }
- }
- }
-
.animation-control__speed-control {
margin-right: -12px;
@@ -83,32 +47,33 @@ const StyledCenterBox = styled(CenterFlexbox)`
}
`;
-TimeWidgetTopFactory.deps = [FieldSelectorFactory];
-function TimeWidgetTopFactory(FieldSelector: ReturnType<typeof FieldSelectorFactory>) {
+TimeWidgetTopFactory.deps = [];
+function TimeWidgetTopFactory() {
const TimeWidgetTop: React.FC<TimeWidgetTopProps> = ({
filter,
readOnly,
- datasets,
- setFilterPlot,
onClose,
isMinified,
- onToggleMinify
+ onToggleMinify,
+ onToggleSettings
}) => {
- const yAxisFields = useMemo(
- () =>
- ((datasets[filter.dataId[0]] || {}).fields || []).filter(
- (f: Field) => f.type === 'integer' || f.type === 'real'
- ),
- [datasets, filter.dataId]
- );
- const _setFilterPlotYAxis = useCallback(
- value => setFilterPlot({yAxis: value}),
- [setFilterPlot]
- );
- const _toggleYAxisAutoRange = useCallback(
- () => setFilterPlot({plotType: {yAxisAutoRange: !filter.plotType?.yAxisAutoRange}}),
- [setFilterPlot, filter.plotType?.yAxisAutoRange]
- );
+ const chartTitle = useMemo(() => {
+ const interval = filter.plotType?.interval;
+ let intervalLabel = 'Time';
+ if (interval) {
+ const parts = interval.split('-');
+ if (parts.length === 2) {
+ intervalLabel = `${parts[0]} ${parts[1]}`;
+ }
+ }
+ if (!filter.yAxis) {
+ return `Count of Rows per ${intervalLabel}`;
+ }
+ const aggregation = filter.plotType?.aggregation || AGGREGATION_TYPES.average;
+ const aggLabel =
+ TIME_AGGREGATION.find(a => a.id === aggregation)?.label || aggregation;
+ return `${aggLabel} ${filter.yAxis.name} per ${intervalLabel}`;
+ }, [filter.yAxis, filter.plotType?.aggregation, filter.plotType?.interval]);
return (
<TopSectionWrapper>
@@ -116,37 +81,14 @@ function TimeWidgetTopFactory(FieldSelector: ReturnType<typeof FieldSelectorFact
<CenterFlexbox className="bottom-widget__icon">
<Clock height="15px" />
</CenterFlexbox>
- <SelectTextBold>{filter.name}</SelectTextBold>
+ <SelectTextBold>{chartTitle}</SelectTextBold>
</StyledTitle>
- {!isMinified ? (
- <StyledTitle className="bottom-widget__y-axis">
- <CenterFlexbox className="bottom-widget__icon">
- <LineChart height="15px" />
- </CenterFlexbox>
- <div className="bottom-widget__field-select">
- <FieldSelector
- fields={yAxisFields}
- placement="top"
- id="selected-time-widget-field"
- value={filter.yAxis ? filter.yAxis.name : null}
- onSelect={_setFilterPlotYAxis}
- placeholder="placeholder.yAxis"
- erasable
- showToken={false}
- />
- </div>
- {filter.yAxis ? (
- <Switch
- checked={Boolean(filter.plotType?.yAxisAutoRange)}
- id={`${filter.id}-y-axis-auto-range`}
- onChange={_toggleYAxisAutoRange}
- secondary
- label="Fit Y"
- />
- ) : null}
- </StyledTitle>
- ) : null}
<StyledCenterBox>
+ {!isMinified ? (
+ <IconRoundSmall>
+ <Gear height="12px" onClick={onToggleSettings} />
+ </IconRoundSmall>
+ ) : null}
<IconRoundSmall>
{isMinified ? (
<ArrowUp height="12px" onClick={onToggleMinify} />
diff --git a/src/components/src/filters/time-widget.tsx b/src/components/src/filters/time-widget.tsx
index f14bcd187..83aa53059 100644
--- a/src/components/src/filters/time-widget.tsx
+++ b/src/components/src/filters/time-widget.tsx
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import React, {useCallback, useMemo} from 'react';
+import React, {useCallback, useMemo, useState} from 'react';
import styled from 'styled-components';
import {FILTER_VIEW_TYPES} from '@kepler.gl/constants';
import {BottomWidgetInner} from '../common/styled-components';
@@ -10,17 +10,24 @@ import FloatingTimeDisplayFactory from '../common/animation-control/floating-tim
import {timeRangeSliderFieldsSelector} from './time-range-filter';
import {TimeWidgetProps} from './types';
import TimeWidgetTopFactory from './time-widget-top';
+import TimeWidgetSettingsFactory from './time-widget-settings';
const TimeBottomWidgetInner = styled(BottomWidgetInner)`
padding: 6px 32px 24px 32px;
`;
-TimeWidgetFactory.deps = [TimeRangeSliderFactory, FloatingTimeDisplayFactory, TimeWidgetTopFactory];
+TimeWidgetFactory.deps = [
+ TimeRangeSliderFactory,
+ FloatingTimeDisplayFactory,
+ TimeWidgetTopFactory,
+ TimeWidgetSettingsFactory
+];
function TimeWidgetFactory(
TimeRangeSlider: ReturnType<typeof TimeRangeSliderFactory>,
FloatingTimeDisplay: ReturnType<typeof FloatingTimeDisplayFactory>,
- TimeWidgetTop: ReturnType<typeof TimeWidgetTopFactory>
+ TimeWidgetTop: ReturnType<typeof TimeWidgetTopFactory>,
+ TimeWidgetSettings: ReturnType<typeof TimeWidgetSettingsFactory>
) {
const TimeWidget: React.FC<TimeWidgetProps> = ({
datasets,
@@ -42,6 +49,8 @@ function TimeWidgetFactory(
animationConfig,
timeline
}: TimeWidgetProps) => {
+ const [showSettings, setShowSettings] = useState(false);
+
const _updateAnimationSpeed = useCallback(
speed => updateAnimationSpeed(index, speed),
[updateAnimationSpeed, index]
@@ -67,6 +76,10 @@ function TimeWidgetFactory(
[index, setFilterPlot]
);
+ const _onToggleSettings = useCallback(() => {
+ setShowSettings(prev => !prev);
+ }, []);
+
const timeRangeSlideProps = useMemo(
() => timeRangeSliderFieldsSelector(filter, datasets, layers),
[filter, datasets, layers]
@@ -77,13 +90,14 @@ function TimeWidgetFactory(
<TimeWidgetTop
filter={filter}
readOnly={readOnly}
- datasets={datasets}
- setFilterPlot={_setFilterPlot}
- index={index}
onClose={onClose}
onToggleMinify={onToggleMinify}
+ onToggleSettings={_onToggleSettings}
isMinified={isMinified}
/>
+ {showSettings && !isMinified ? (
+ <TimeWidgetSettings filter={filter} datasets={datasets} setFilterPlot={_setFilterPlot} />
+ ) : null}
{/* Once AnimationControl is able to display large timeline*/}
{/* we can replace TimeRangeSlider with AnimationControl*/}
<TimeRangeSlider
diff --git a/src/components/src/filters/types.ts b/src/components/src/filters/types.ts
index 402065710..e83a4f899 100644
--- a/src/components/src/filters/types.ts
+++ b/src/components/src/filters/types.ts
@@ -69,11 +69,9 @@ export type MultiSelectFilterProps = {
export type TimeWidgetTopProps = {
filter: Filter;
readOnly: boolean;
- datasets: Datasets;
- setFilterPlot: (newProp, valueIndex?: number) => void;
- index: number;
onClose: () => void;
onToggleMinify: () => void;
+ onToggleSettings?: () => void;
isMinified: boolean;
};
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index cf7c52d43..1817d9a41 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -54,7 +54,8 @@ export {
LayerToFilterTimeInterval,
TileTimeInterval,
getTimelineFromAnimationConfig,
- getTimelineFromFilter
+ getTimelineFromFilter,
+ filterIntervalOptions
} from './time';
export {maybeHexToGeo, getPositionFromHexValue} from './position-utils';
diff --git a/src/utils/src/plot.ts b/src/utils/src/plot.ts
index 9b2383bab..e313a11d2 100644
--- a/src/utils/src/plot.ts
+++ b/src/utils/src/plot.ts
@@ -698,6 +698,6 @@ export function getDefaultPlotType(filter, datasets) {
interval,
defaultTimeFormat,
type: PLOT_TYPES.histogram,
- aggregation: AGGREGATION_TYPES.sum
+ aggregation: AGGREGATION_TYPES.average
};
}
diff --git a/test/browser/components/filters/time-widget-test.js b/test/browser/components/filters/time-widget-test.js
index ce773160f..9c8c91e93 100644
--- a/test/browser/components/filters/time-widget-test.js
+++ b/test/browser/components/filters/time-widget-test.js
@@ -83,9 +83,15 @@ test('Components -> TimeWidget.mount -> with time filter', t => {
t.equal(wrapper.find(TimeWidget).length, 1, 'should render TimeWidget');
t.equal(wrapper.find(FloatingTimeDisplay).length, 1, 'should render FloatingTimeDisplay');
t.equal(wrapper.find(TimeRangeSlider).length, 1, 'should render TimeRangeSlider');
- t.equal(wrapper.find(FieldSelector).length, 1, 'should render FieldSelector');
t.equal(wrapper.find(PlaybackControls).length, 1, 'should render PlaybackControls');
+ // FieldSelector is now inside the collapsible settings panel
+ // open settings by clicking the Gear icon
+ wrapper.find(Icons.Gear).at(0).simulate('click');
+ wrapper.update();
+
+ t.equal(wrapper.find(FieldSelector).length, 1, 'should render FieldSelector');
+
// check yAxisFields
const yAxisFields = wrapper.find(FieldSelector).at(0).props().fields;
t.deepEqual(
@@ -198,8 +204,11 @@ test('Components -> TimeWidget.mount -> test actions', t => {
'should call setFilterAnimationWindow'
);
- // click yaxis select
- wrapper.find('.item-selector__dropdown').at(0).simulate('click');
+ // click yaxis select (open settings first since FieldSelector moved there)
+ wrapper.find(Icons.Gear).at(0).simulate('click');
+ wrapper.update();
+
+ wrapper.find(FieldSelector).find('.item-selector__dropdown').at(0).simulate('click');
t.equal(wrapper.find(Typeahead).length, 1, 'should render dropdown select');
wrapper.find(Typeahead).find('.field-selector_list-item').at(0).simulate('click');
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index aa91c975a..ab9579edb 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -902,7 +902,7 @@ export const mergedFilters = [
interval: '5-second',
defaultTimeFormat: 'L LTS',
type: 'histogram',
- aggregation: 'sum'
+ aggregation: 'average'
},
yAxis: null,
domain: [1453770124000, 1453770810000],
diff --git a/test/fixtures/test-csv-data.js b/test/fixtures/test-csv-data.js
index c0da79520..cfd07e9fa 100644
--- a/test/fixtures/test-csv-data.js
+++ b/test/fixtures/test-csv-data.js
@@ -662,7 +662,7 @@ export const mergedTimeFilter = {
interval: '1-hour',
defaultTimeFormat: 'L H A',
type: 'histogram',
- aggregation: 'sum'
+ aggregation: 'average'
},
yAxis: null,
value: [1474606800000, 1474617600000],
@@ -712,7 +712,7 @@ export const mergedEpochFilter = {
interval: '15-minute',
defaultTimeFormat: 'L LT',
type: 'histogram',
- aggregation: 'sum'
+ aggregation: 'average'
},
yAxis: null,
value: [1472700000000, 1472760000000],
@@ -751,7 +751,7 @@ export const expectedSyncedTsFilter = {
interval: '15-second',
defaultTimeFormat: 'L LTS',
type: 'histogram',
- aggregation: 'sum',
+ aggregation: 'average',
colorsByDataId: {
'test-csv-data-1': '#FF0000',
'test-csv-data-2': '#00FF00'
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 08769a4d1..994659e9a 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -3038,7 +3038,7 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', as
plotType: {
type: 'histogram',
interval: '15-second',
- aggregation: 'sum',
+ aggregation: 'average',
defaultTimeFormat: 'L LTS'
},
yAxis: null,
@@ -3353,11 +3353,17 @@ test('#visStateReducer -> SET_FILTER_PLOT.yAxis', t => {
const yAxisField = stateWithFilterName.datasets.smoothie.fields.find(f => f.name === 'uid');
// set filterPlot yAxis
- const stateWithFilterPlot = reducer(
+ const stateWithFilterPlotYAxis = reducer(
stateWithFilterName,
VisStateActions.setFilterPlot(0, {yAxis: yAxisField})
);
+ // set aggregation to sum
+ const stateWithFilterPlot = reducer(
+ stateWithFilterPlotYAxis,
+ VisStateActions.setFilterPlot(0, {plotType: {aggregation: 'sum'}})
+ );
+
const bins = [
{
count: 1,
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index 1464b5aab..6ec67fdb1 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -108,7 +108,7 @@ test('#visStateSchema -> v1 -> save load filters', t => {
interval: '1-hour',
defaultTimeFormat: 'L H A',
type: 'histogram',
- aggregation: 'sum'
+ aggregation: 'average'
},
yAxis: null,
animationWindow: 'free',
diff --git a/test/node/utils/filter-utils-test.js b/test/node/utils/filter-utils-test.js
index aa62406da..301788fde 100644
--- a/test/node/utils/filter-utils-test.js
+++ b/test/node/utils/filter-utils-test.js
@@ -568,7 +568,7 @@ test('filterUtils -> mergeFilterWithTimeline', t => {
interval: '1-minute',
defaultTimeFormat: 'L LT',
type: 'histogram',
- aggregation: 'sum'
+ aggregation: 'average'
},
yAxis: null,
gpu: true,
diff --git a/test/node/utils/timeline-test.js b/test/node/utils/timeline-test.js
index 5417c8687..19a27b759 100644
--- a/test/node/utils/timeline-test.js
+++ b/test/node/utils/timeline-test.js
@@ -22,7 +22,7 @@ test('#timeline -> getTimelineFromFilter', t => {
interval: '5-minute',
defaultTimeFormat: 'L LT',
type: 'histogram',
- aggregation: 'sum'
+ aggregation: 'average'
},
yAxis: null,
gpu: true,