Skip to content

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

[Feat] refactored AnimationControl to handle both layer and minified filter playback (#2079)

Igor Dykhta608fa0f36760
diff --git a/src/components/src/bottom-widget.tsx b/src/components/src/bottom-widget.tsx
index 0871ec112..a5a35e7b9 100644
--- a/src/components/src/bottom-widget.tsx
+++ b/src/components/src/bottom-widget.tsx
@@ -18,16 +18,19 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {useCallback, forwardRef, useMemo} from 'react';
+import React, {forwardRef, useMemo, useCallback} from 'react';
import styled from 'styled-components';
-import TimeWidgetFactory from './filters/time-widget';
-import AnimationControlFactory from './common/animation-control/animation-control';
-import AnimationControllerFactory from './common/animation-control/animation-controller';
-import {ANIMATION_WINDOW, DIMENSIONS, FILTER_VIEW_TYPES} from '@kepler.gl/constants';
-import {getIntervalBins, hasPortableWidth, isSideFilter} from '@kepler.gl/utils';
+
+import {DIMENSIONS, FILTER_VIEW_TYPES} from '@kepler.gl/constants';
+import {hasPortableWidth, isSideFilter} from '@kepler.gl/utils';
import {media, breakPointValues} from '@kepler.gl/styles';
-import {AnimationConfig, TimeRangeFilter} from '@kepler.gl/types';
+import {TimeRangeFilter} from '@kepler.gl/types';
+
+import TimeWidgetFactory from './filters/time-widget';
import {bottomWidgetSelector} from './kepler-gl';
+import FilterAnimationControllerFactory from './filter-animation-controller';
+import LayerAnimationControllerFactory from './layer-animation-controller';
+import AnimationControlFactory from './common/animation-control/animation-control';
const maxWidth = 1080;
@@ -53,94 +56,6 @@ const BottomWidgetContainer = styled.div<BottomWidgetContainerProps>`
${media.portable`padding: 0;`}
`;
-interface FilterAnimationControllerProps {
- filter: TimeRangeFilter & {animationWindow?: string};
- filterIdx: number;
- setFilterAnimationTime: (idx: number, value: string, a: any[]) => void;
-}
-
-FilterAnimationControllerFactory.deps = [AnimationControllerFactory];
-export function FilterAnimationControllerFactory(
- AnimationController: ReturnType<typeof AnimationControllerFactory>
-) {
- const FilterAnimationController: React.FC<FilterAnimationControllerProps> = ({
- filter,
- filterIdx,
- setFilterAnimationTime,
- children
- }) => {
- const intervalBins = useMemo(() => getIntervalBins(filter), [filter]);
-
- const steps = useMemo(() => (intervalBins ? intervalBins.map(x => x.x0) : null), [
- intervalBins
- ]);
-
- 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
- ]);
- break;
- default:
- setFilterAnimationTime(filterIdx, 'value', value);
- break;
- }
- },
- [filterIdx, intervalBins, filter.animationWindow, setFilterAnimationTime]
- );
-
- return (
- <AnimationController
- key="filter-control"
- value={filter.value}
- domain={filter.domain}
- speed={filter.speed}
- isAnimating={filter.isAnimating}
- animationWindow={filter.animationWindow}
- steps={steps}
- updateAnimation={updateAnimation}
- children={children}
- />
- );
- };
- return FilterAnimationController;
-}
-
-interface LayerAnimationControllerProps {
- animationConfig: AnimationConfig & {timeSteps?: number[] | null};
- setLayerAnimationTime: (x: number) => void;
-}
-
-LayerAnimationControllerFactory.deps = [AnimationControllerFactory];
-export function LayerAnimationControllerFactory(
- AnimationController: ReturnType<typeof AnimationControllerFactory>
-) {
- const LayerAnimationController: React.FC<LayerAnimationControllerProps> = ({
- animationConfig,
- setLayerAnimationTime,
- children
- }) => (
- <AnimationController<number>
- key="layer-control"
- value={Number(animationConfig.currentTime)}
- domain={animationConfig.domain}
- speed={animationConfig.speed}
- isAnimating={animationConfig.isAnimating}
- updateAnimation={setLayerAnimationTime}
- steps={animationConfig.timeSteps}
- animationWindow={
- animationConfig.timeSteps ? ANIMATION_WINDOW.interval : ANIMATION_WINDOW.point
- }
- children={children}
- />
- );
- return LayerAnimationController;
-}
-
type BottomWidgetProps = {
rootRef: React.ForwardedRef<HTMLDivElement>;
containerW: number;
@@ -159,8 +74,12 @@ export default function BottomWidgetFactory(
AnimationControl: ReturnType<typeof AnimationControlFactory>,
FilterAnimationController: ReturnType<typeof FilterAnimationControllerFactory>,
LayerAnimationController: ReturnType<typeof LayerAnimationControllerFactory>
-) {
- const BottomWidget = (props: BottomWidgetProps) => {
+): React.FC<BottomWidgetProps> {
+ const LayerAnimationControl = styled(AnimationControl)`
+ background-color: ${props => props.theme.sidePanelBg};
+ `;
+
+ const BottomWidget: React.FC<BottomWidgetProps> = (props: BottomWidgetProps) => {
const {
datasets,
filters,
@@ -228,27 +147,27 @@ export default function BottomWidgetFactory(
animationConfig={animationConfig}
setLayerAnimationTime={visStateActions.setLayerAnimationTime}
>
- {(isAnimating, start, pause, reset) =>
+ {(isAnimating, start, pause, resetAnimation, timeline, setTimelineValue) =>
showAnimationControl ? (
- <AnimationControl
- animationConfig={animationConfig}
- setLayerAnimationTime={visStateActions.setLayerAnimationTime}
+ <LayerAnimationControl
updateAnimationSpeed={visStateActions.updateLayerAnimationSpeed}
toggleAnimation={visStateActions.toggleLayerAnimation}
isAnimatable={!animatedFilter}
isAnimating={isAnimating}
- resetAnimation={reset}
+ resetAnimation={resetAnimation}
+ setTimelineValue={setTimelineValue}
+ timeline={timeline}
/>
) : null
}
</LayerAnimationController>
- {filter && (
+ {filter ? (
<FilterAnimationController
filter={filter}
filterIdx={animatedFilterIdx > -1 ? animatedFilterIdx : enlargedFilterIdx}
setFilterAnimationTime={visStateActions.setFilterAnimationTime}
>
- {(isAnimating, start, pause, resetAnimation) =>
+ {(isAnimating, start, pause, resetAnimation, timeline, setTimelineValue) =>
showTimeWidget ? (
<TimeWidget
// TimeWidget uses React.memo, here we pass width
@@ -259,18 +178,19 @@ export default function BottomWidgetFactory(
readOnly={readOnly}
showTimeDisplay={showFloatingTimeDisplay}
setFilterPlot={visStateActions.setFilterPlot}
- setFilterAnimationTime={visStateActions.setFilterAnimationTime}
+ setFilterAnimationTime={setTimelineValue}
setFilterAnimationWindow={visStateActions.setFilterAnimationWindow}
toggleAnimation={visStateActions.toggleFilterAnimation}
updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
resetAnimation={resetAnimation}
isAnimatable={!animationConfig || !animationConfig.isAnimating}
onClose={onClose}
+ timeline={timeline}
/>
) : null
}
</FilterAnimationController>
- )}
+ ) : null}
</BottomWidgetContainer>
);
};
diff --git a/src/components/src/common/animation-control/animation-control.tsx b/src/components/src/common/animation-control/animation-control.tsx
index c4bf3ff6a..3a3b7c64c 100644
--- a/src/components/src/common/animation-control/animation-control.tsx
+++ b/src/components/src/common/animation-control/animation-control.tsx
@@ -18,28 +18,29 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {useCallback, useMemo} from 'react';
+import React from 'react';
import styled from 'styled-components';
import classnames from 'classnames';
-import Slider from '../slider/slider';
-import {BottomWidgetInner} from '../styled-components';
+import {media} from '@kepler.gl/styles';
+import {Timeline} from '@kepler.gl/types';
+
+import TimelineSliderFactory from '../timeline-slider';
import PlaybackControlsFactory from './playback-controls';
import FloatingTimeDisplayFactory from './floating-time-display';
-import {datetimeFormatter, snapToMarks, toArray} from '@kepler.gl/utils';
-import {DEFAULT_TIME_FORMAT} from '@kepler.gl/constants';
-import {media} from '@kepler.gl/styles';
const SLIDER_MARGIN_PALM = 6;
-const SliderWrapper = styled.div`
- display: flex;
+const AnimationControlContainer = styled.div`
+ padding: ${props => `${props.theme.bottomInnerPdVert}px ${props.theme.bottomInnerPdSide}px`};
position: relative;
- flex-grow: 1;
- margin: 0 24px;
+ margin-top: ${props => props.theme.bottomPanelGap}px;
- ${media.palm`
- margin: 0 ${SLIDER_MARGIN_PALM}px;
+ ${media.portable`
+ border-top: 1px solid ${props => props.theme.panelBorderColor};
+ border-left: 1px solid ${props => props.theme.panelBorderColor};
+ padding: 12px 12px;
+ margin-top: 0;
`}
`;
@@ -81,110 +82,99 @@ const AnimationWidgetInner = styled.div`
`};
`;
-const StyledDomain = styled.div.attrs(props => ({
- className: classnames('animation-control__time-domain', props.className)
-}))`
- color: ${props => props.theme.titleTextColor};
- font-weight: 400;
- font-size: 10px;
-`;
-
-AnimationControlFactory.deps = [PlaybackControlsFactory, FloatingTimeDisplayFactory];
+const TIMELINE_PLAYBACK_STYLE = {flex: 1};
+
+type AnimationControlProps = {
+ timeline: Timeline;
+ isAnimatable?: boolean;
+ isAnimating?: boolean;
+ updateAnimationSpeed?: (val: number) => void;
+ setAnimationWindow?: (id: string) => void;
+ toggleAnimation: () => void;
+ resetAnimation?: () => void;
+ setTimelineValue: (value: number[]) => void;
+ showTimeDisplay?: boolean;
+ showTimeline?: boolean;
+ showControls?: boolean;
+ className?: string;
+ style?: object;
+};
+
+AnimationControlFactory.deps = [
+ PlaybackControlsFactory,
+ FloatingTimeDisplayFactory,
+ TimelineSliderFactory
+];
function AnimationControlFactory(
PlaybackControls: ReturnType<typeof PlaybackControlsFactory>,
- FloatingTimeDisplay: ReturnType<typeof FloatingTimeDisplayFactory>
+ FloatingTimeDisplay: ReturnType<typeof FloatingTimeDisplayFactory>,
+ TimelineSlider: ReturnType<typeof TimelineSliderFactory>
) {
- const AnimationControl = ({
+ const AnimationControl: React.FC<AnimationControlProps> = ({
+ className,
+ style,
isAnimatable,
isAnimating,
resetAnimation,
toggleAnimation,
- setLayerAnimationTime,
updateAnimationSpeed,
- animationConfig
+ setTimelineValue,
+ setAnimationWindow,
+ timeline,
+ showTimeline = true,
+ showControls = true,
+ showTimeDisplay = true
}) => {
- const {
- currentTime,
- domain,
- speed,
- step,
- timeSteps,
- timeFormat,
- timezone,
- defaultTimeFormat
- } = animationConfig;
- const onSlider1Change = useCallback(
- val => {
- // TODO: can we move this logic into setLayerAnimationTimeUpdater
- if (Array.isArray(timeSteps)) {
- setLayerAnimationTime(snapToMarks(toArray(val)[0], timeSteps));
-
- // TODO: merge slider in to avoid this step
- } else if (val >= domain[0] && val <= domain[1]) {
- setLayerAnimationTime(val);
- }
- },
- [domain, timeSteps, setLayerAnimationTime]
- );
-
- const dateFunc = useMemo(() => {
- const hasUserFormat = typeof timeFormat === 'string';
- const currentFormat = (hasUserFormat ? timeFormat : defaultTimeFormat) || DEFAULT_TIME_FORMAT;
- return datetimeFormatter(timezone)(currentFormat);
- }, [timeFormat, defaultTimeFormat, timezone]);
+ if (!timeline) {
+ return null;
+ }
- const timeStart = useMemo(() => (domain ? dateFunc(domain[0]) : ''), [domain, dateFunc]);
- const timeEnd = useMemo(() => (domain ? dateFunc(domain[1]) : ''), [domain, dateFunc]);
+ const {animationWindow, value, speed, defaultTimeFormat, timeFormat, timezone} = timeline;
return (
- <BottomWidgetInner className="bottom-widget--inner">
+ <AnimationControlContainer
+ style={style}
+ className={classnames('animation-control-container', className)}
+ >
<AnimationWidgetInner className="animation-widget--inner">
- <div className="animation-control__time-slider">
- <StyledDomain className="domain-start">
- <span>{timeStart}</span>
- </StyledDomain>
- <SliderWrapper className="animation-control__slider">
- <Slider
- isRanged={false}
- step={step}
- minValue={domain ? domain[0] : 0}
- maxValue={domain ? domain[1] : 1}
- value1={currentTime}
- onSlider1Change={onSlider1Change}
- enableBarDrag={true}
- />
- </SliderWrapper>
- <StyledDomain className="domain-end">
- <span>{timeEnd}</span>
- </StyledDomain>
- </div>
- <PlaybackControls
- className="animation-control-playpause"
- startAnimation={toggleAnimation}
- isAnimating={isAnimating}
- pauseAnimation={toggleAnimation}
- resetAnimation={resetAnimation}
- speed={speed}
- isAnimatable={isAnimatable}
- updateAnimationSpeed={updateAnimationSpeed}
- />
+ {showTimeline ? (
+ <TimelineSlider
+ style={TIMELINE_PLAYBACK_STYLE}
+ timeline={timeline}
+ setTimelineValue={setTimelineValue}
+ />
+ ) : null}
+ {showControls ? (
+ <PlaybackControls
+ className="animation-control-playpause"
+ isAnimatable={isAnimatable}
+ startAnimation={toggleAnimation}
+ isAnimating={isAnimating}
+ pauseAnimation={toggleAnimation}
+ resetAnimation={resetAnimation}
+ speed={speed}
+ updateAnimationSpeed={updateAnimationSpeed}
+ setFilterAnimationWindow={setAnimationWindow}
+ animationWindow={animationWindow}
+ />
+ ) : null}
</AnimationWidgetInner>
- <FloatingTimeDisplay
- currentTime={currentTime}
- defaultTimeFormat={defaultTimeFormat}
- timeFormat={timeFormat}
- timezone={timezone}
- />
- </BottomWidgetInner>
+ {showTimeDisplay ? (
+ <FloatingTimeDisplay
+ currentTime={value}
+ defaultTimeFormat={defaultTimeFormat}
+ timeFormat={timeFormat}
+ timezone={timezone}
+ />
+ ) : null}
+ </AnimationControlContainer>
);
};
AnimationControl.defaultProps = {
toggleAnimation: () => {},
- updateAnimationSpeed: () => {},
- animationControlProps: {},
- animationConfig: {}
+ updateAnimationSpeed: () => {}
};
return AnimationControl;
diff --git a/src/components/src/common/animation-control/animation-controller.ts b/src/components/src/common/animation-control/animation-controller.ts
index 3b1f0a66d..70783ecb4 100644
--- a/src/components/src/common/animation-control/animation-controller.ts
+++ b/src/components/src/common/animation-control/animation-controller.ts
@@ -23,11 +23,14 @@ import {bisectLeft} from 'd3-array';
import {requestAnimationFrame, cancelAnimationFrame} from 'global/window';
import Console from 'global/console';
import {BASE_SPEED, FPS, ANIMATION_WINDOW} from '@kepler.gl/constants';
+import {Timeline} from '@kepler.gl/types';
interface AnimationControllerProps<T extends number | number[]> {
isAnimating?: boolean;
speed?: number;
- updateAnimation: (x: T) => void;
+ updateAnimation?: (x: T) => void;
+ setTimelineValue: (x: T) => void;
+ timeline?: Timeline;
animationWindow?: string;
steps?: number[] | null;
domain: number[] | null;
@@ -121,31 +124,37 @@ function AnimationControllerFactory(): typeof AnimationControllerType {
};
_resetAnimationByDomain = () => {
- const {domain, value, animationWindow} = this.props;
+ const {domain, value, animationWindow, updateAnimation} = this.props;
if (!domain) {
return;
}
+ // interim solution while we fully migrate filter and layer controllers
+ const setTimelineValue = updateAnimation || this.props.setTimelineValue;
+
if (Array.isArray(value)) {
if (animationWindow === ANIMATION_WINDOW.incremental) {
- this.props.updateAnimation([value[0], value[0] + 1] as T);
+ setTimelineValue([value[0], value[0] + 1] as T);
} else {
- this.props.updateAnimation([domain[0], domain[0] + value[1] - value[0]] as T);
+ setTimelineValue([domain[0], domain[0] + value[1] - value[0]] as T);
}
} else {
- this.props.updateAnimation(domain[0] as T);
+ setTimelineValue(domain[0] as T);
}
};
- _resetAnimtionByTimeStep = () => {
- const {steps = null} = this.props;
+ _resetAnimationByTimeStep = () => {
+ const {steps = null, updateAnimation} = this.props;
if (!steps) return;
+ // interim solution while we fully migrate filter and layer controllers
+ const setTimelineValue = updateAnimation || this.props.setTimelineValue;
+
// go to the first steps
- this.props.updateAnimation([steps[0], 0] as T);
+ setTimelineValue([steps[0], 0] as T);
};
_resetAnimation = () => {
if (this.props.animationWindow === ANIMATION_WINDOW.interval) {
- this._resetAnimtionByTimeStep();
+ this._resetAnimationByTimeStep();
} else {
this._resetAnimationByDomain();
}
@@ -193,7 +202,9 @@ function AnimationControllerFactory(): typeof AnimationControllerType {
? this._nextFrameByTimeStep()
: this._nextFrameByDomain();
- this.props.updateAnimation(nextValue as T);
+ // interim solution while we fully migrate filter and layer controllers
+ const setTimelineValue = this.props.updateAnimation || this.props.setTimelineValue;
+ setTimelineValue(nextValue as T);
};
_nextFrameByDomain() {
@@ -240,7 +251,14 @@ function AnimationControllerFactory(): typeof AnimationControllerType {
const {children} = this.props;
return typeof children === 'function'
- ? children(isAnimating, this._startAnimation, this._pauseAnimation, this._resetAnimation)
+ ? children(
+ isAnimating,
+ this._startAnimation,
+ this._pauseAnimation,
+ this._resetAnimation,
+ this.props.timeline,
+ this.props.setTimelineValue
+ )
: null;
}
}
diff --git a/src/components/src/common/slider/slider.tsx b/src/components/src/common/slider/slider.tsx
index 2d4090fcc..de41dbdc7 100644
--- a/src/components/src/common/slider/slider.tsx
+++ b/src/components/src/common/slider/slider.tsx
@@ -58,8 +58,8 @@ type SliderProps = {
minValue: number;
maxValue: number;
sliderHandleWidth: number;
- onSlider0Change: (val: number) => void;
- onSlider1Change: (val: number) => void;
+ onSlider0Change: (val: number) => any;
+ onSlider1Change: (val: number) => any;
onSliderBarChange: (val0: number, val1: number) => void;
step: number;
enableBarDrag: boolean;
@@ -68,9 +68,11 @@ type SliderProps = {
marks?: number[];
classSet?: {[key: string]: boolean};
disabled: boolean;
+ className?: string;
+ style?: object;
};
-export default class Slider extends Component {
+export default class Slider extends Component<SliderProps> {
static defaultProps = {
title: '',
isRanged: true,
@@ -175,6 +177,7 @@ export default class Slider extends Component {
render() {
const {
+ className,
classSet,
disabled,
isRanged,
@@ -183,7 +186,8 @@ export default class Slider extends Component {
value1,
vertical,
sliderHandleWidth,
- showTooltip
+ showTooltip,
+ style
} = this.props;
const value0 = !isRanged && minValue > 0 ? minValue : this.props.value0;
const currValDelta = value1 - value0;
@@ -194,10 +198,11 @@ export default class Slider extends Component {
return (
<SliderWrapper
- className={classnames('kg-slider', {...classSet, disabled})}
+ className={classnames('kg-slider', {...classSet, disabled}, className)}
ref={this.ref}
isRanged={isRanged}
vertical={vertical}
+ style={style}
>
<StyledRangeSlider className="kg-range-slider" vertical={vertical} ref={this.track}>
<SliderHandle
diff --git a/src/components/src/common/time-range-slider.tsx b/src/components/src/common/time-range-slider.tsx
index 1c207ee7a..8ab159c01 100644
--- a/src/components/src/common/time-range-slider.tsx
+++ b/src/components/src/common/time-range-slider.tsx
@@ -26,7 +26,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} from '@kepler.gl/types';
+import {HistogramBin, LineChart, Timeline} from '@kepler.gl/types';
+import AnimationControlFactory from './animation-control/animation-control';
const animationControlWidth = 176;
@@ -38,6 +39,7 @@ type TimeRangeSliderProps = {
domain?: [number, number];
value: [number, number];
isEnlarged?: boolean;
+ isMinified?: boolean;
hideTimeTitle?: boolean;
isAnimating: boolean;
timeFormat: string;
@@ -54,6 +56,7 @@ type TimeRangeSliderProps = {
updateAnimationSpeed?: (val: number) => void;
setFilterAnimationWindow?: (id: string) => void;
onChange: (v: number[]) => void;
+ timeline: Timeline;
};
const StyledSliderContainer = styled.div<StyledSliderContainerProps>`
@@ -72,24 +75,29 @@ const StyledSliderContainer = styled.div<StyledSliderContainerProps>`
}
`;
+const ANIMATION_CONTROL_STYLE = {flex: 1};
+
TimeRangeSliderFactory.deps = [
PlaybackControlsFactory,
RangeSliderFactory,
TimeSliderMarkerFactory,
- TimeRangeSliderTimeTitleFactory
+ TimeRangeSliderTimeTitleFactory,
+ AnimationControlFactory
];
export default function TimeRangeSliderFactory(
PlaybackControls: ReturnType<typeof PlaybackControlsFactory>,
RangeSlider: ReturnType<typeof RangeSliderFactory>,
TimeSliderMarker: ReturnType<typeof TimeSliderMarkerFactory>,
- TimeRangeSliderTimeTitle: ReturnType<typeof TimeRangeSliderTimeTitleFactory>
+ TimeRangeSliderTimeTitle: ReturnType<typeof TimeRangeSliderTimeTitleFactory>,
+ AnimationControl: ReturnType<typeof AnimationControlFactory>
) {
const TimeRangeSlider: React.FC<TimeRangeSliderProps> = props => {
const {
domain,
value,
isEnlarged,
+ isMinified,
hideTimeTitle,
isAnimating,
resetAnimation,
@@ -105,8 +113,10 @@ export default function TimeRangeSliderFactory(
updateAnimationSpeed,
setFilterAnimationWindow,
toggleAnimation,
- onChange
+ onChange,
+ timeline
} = props;
+
const throttledOnchange = useMemo(() => throttle(onChange, 20), [onChange]);
const style = useMemo(
@@ -129,24 +139,39 @@ export default function TimeRangeSliderFactory(
</div>
) : null}
<StyledSliderContainer className="time-range-slider__container" isEnlarged={isEnlarged}>
- <div className="timeline-container" style={style}>
- <RangeSlider
- range={domain}
- value0={value[0]}
- value1={value[1]}
- histogram={histogram}
- lineChart={lineChart}
- plotType={plotType}
- isEnlarged={isEnlarged}
- showInput={false}
- step={step}
- onChange={throttledOnchange}
- xAxis={TimeSliderMarker}
- timezone={timezone}
- timeFormat={timeFormat}
+ {!isMinified ? (
+ <div className="timeline-container" style={style}>
+ <RangeSlider
+ range={domain}
+ value0={value[0]}
+ value1={value[1]}
+ histogram={histogram}
+ lineChart={lineChart}
+ plotType={plotType}
+ isEnlarged={isEnlarged}
+ showInput={false}
+ step={step}
+ onChange={throttledOnchange}
+ xAxis={TimeSliderMarker}
+ timezone={timezone}
+ timeFormat={timeFormat}
+ />
+ </div>
+ ) : (
+ <AnimationControl
+ style={ANIMATION_CONTROL_STYLE}
+ isAnimatable={isAnimatable}
+ isAnimating={isAnimating}
+ resetAnimation={resetAnimation}
+ toggleAnimation={toggleAnimation}
+ updateAnimationSpeed={updateAnimationSpeed}
+ setTimelineValue={throttledOnchange}
+ setAnimationWindow={setFilterAnimationWindow}
+ showTimeDisplay={false}
+ timeline={timeline}
/>
- </div>
- {isEnlarged ? (
+ )}
+ {isEnlarged && !isMinified ? (
<PlaybackControls
isAnimatable={isAnimatable}
width={animationControlWidth}
diff --git a/src/components/src/common/timeline-slider.tsx b/src/components/src/common/timeline-slider.tsx
new file mode 100644
index 000000000..491d67bf0
--- /dev/null
+++ b/src/components/src/common/timeline-slider.tsx
@@ -0,0 +1,160 @@
+import React, {useMemo} from 'react';
+import styled from 'styled-components';
+import throttle from 'lodash.throttle';
+import classnames from 'classnames';
+import {clamp, datetimeFormatter} from '@kepler.gl/utils';
+import {media} from '@kepler.gl/styles';
+import {DEFAULT_TIME_FORMAT, ANIMATION_WINDOW} from '@kepler.gl/constants';
+import {Timeline} from '@kepler.gl/types';
+import Slider from './slider/slider';
+
+function noop() {}
+
+const SLIDER_MARGIN_PALM = 6;
+
+const AnimationControlSlider = styled.div`
+ display: flex;
+ align-items: center;
+`;
+
+const SliderWrapper = styled.div`
+ display: flex;
+ position: relative;
+ flex-grow: 1;
+ margin: 0 24px;
+
+ ${media.palm`
+ margin: 0 ${SLIDER_MARGIN_PALM}px;
+ `}
+`;
+
+const StyledSlider = styled(Slider)`
+ .kg-range-slider__bar {
+ // change colors
+ }
+`;
+
+const StyledDomain = styled.div.attrs(props => ({
+ className: classnames('animation-control__time-domain', props.className)
+}))`
+ color: ${props => props.theme.titleTextColor};
+ font-weight: 400;
+ font-size: 10px;
+`;
+
+const PROGRESS_BAR_HEIGHT = 8;
+
+interface TimelineSliderProps {
+ timeline: Timeline;
+ setTimelineValue: (value: [number] | [number, number]) => void;
+ enableBarDrag?: boolean;
+ showDomainTimes?: boolean;
+ height?: number;
+ className?: string | null;
+ style?: object;
+}
+
+function TimelineSliderFactory() {
+ const TimelineSlider: React.FC<TimelineSliderProps> = ({
+ timeline, // timeline can be a union of filter and animationConfig
+ // we can pass timeline to a hook and get back values and controllers
+ setTimelineValue,
+ enableBarDrag = true,
+ showDomainTimes = true,
+ height = PROGRESS_BAR_HEIGHT,
+ className = null,
+ style
+ }) => {
+ const onThrottleUpdate = useMemo(() => throttle(setTimelineValue, 20), [setTimelineValue]);
+
+ const {
+ step,
+ domain,
+ value,
+ timeFormat,
+ defaultTimeFormat,
+ timezone,
+ animationWindow
+ } = timeline;
+
+ const isRanged = useMemo(
+ () =>
+ Array.isArray(value) && value.length === 2 && animationWindow !== ANIMATION_WINDOW.interval,
+ [animationWindow, value]
+ );
+
+ const [value0, value1]: [number, number] = useMemo(
+ () => [isRanged ? value[0] : null, isRanged ? value[1] : value[0]],
+ [isRanged, value]
+ );
+
+ const [onSlider0Change, onSlider1Change] = useMemo(() => {
+ if (!domain) return [noop, noop];
+ return [
+ isRanged ? (newValue: number) => onThrottleUpdate([clamp(domain, newValue), value1]) : noop,
+ isRanged
+ ? (newValue: number) => onThrottleUpdate([value0, clamp(domain, newValue)])
+ : (newValue: number) =>
+ onThrottleUpdate(
+ animationWindow === ANIMATION_WINDOW.interval
+ ? // filter requires an array with 2 values
+ [clamp(domain, newValue), clamp(domain, newValue)]
+ : // animationConfig only requires one value
+ [clamp(domain, newValue)]
+ )
+ ];
+ }, [animationWindow, domain, isRanged, value0, value1, onThrottleUpdate]);
+
+ const timelineSliderStyle = useMemo(() => ({height: `${height}px`}), [height]);
+
+ const [timeStart, timeEnd] = useMemo(() => {
+ if (!showDomainTimes) {
+ return [null, null];
+ }
+
+ const hasUserFormat = typeof timeFormat === 'string';
+ const currentFormat = (hasUserFormat ? timeFormat : defaultTimeFormat) || DEFAULT_TIME_FORMAT;
+ const dateFunc = datetimeFormatter(timezone)(currentFormat);
+
+ return [domain ? dateFunc(domain[0]) : '', domain ? dateFunc(domain[1]) : ''];
+ }, [domain, timezone, timeFormat, defaultTimeFormat, showDomainTimes]);
+
+ const requiresRangeSlider = isRanged && animationWindow !== ANIMATION_WINDOW.interval;
+
+ return (
+ <AnimationControlSlider
+ style={style}
+ className={classnames('animation-control__time-slider', className)}
+ >
+ {timeStart ? (
+ <StyledDomain className="domain-start">
+ <span>{timeStart}</span>
+ </StyledDomain>
+ ) : null}
+ <SliderWrapper className="animation-control__slider">
+ <StyledSlider
+ isRanged={requiresRangeSlider}
+ step={step || undefined}
+ minValue={domain ? domain[0] : 0}
+ maxValue={domain ? domain[1] : 1}
+ enableBarDrag={enableBarDrag}
+ style={timelineSliderStyle}
+ onSlider0Change={onSlider0Change}
+ onSlider1Change={onSlider1Change}
+ value0={value0}
+ value1={value1}
+ />
+ </SliderWrapper>
+ {timeEnd ? (
+ <StyledDomain className="domain-end">
+ <span>{timeEnd}</span>
+ </StyledDomain>
+ ) : null}
+ </AnimationControlSlider>
+ );
+ };
+
+ return TimelineSlider;
+}
+
+export default TimelineSliderFactory;
diff --git a/src/components/src/filter-animation-controller.tsx b/src/components/src/filter-animation-controller.tsx
new file mode 100644
index 000000000..c7e1afefc
--- /dev/null
+++ b/src/components/src/filter-animation-controller.tsx
@@ -0,0 +1,70 @@
+import React, {useCallback, useMemo} from 'react';
+import {getIntervalBins, 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';
+
+interface FilterAnimationControllerProps {
+ filter: TimeRangeFilter & {animationWindow?: string};
+ filterIdx: number;
+ setFilterAnimationTime: (idx: number, value: string, a: any[]) => void;
+}
+
+FilterAnimationControllerFactory.deps = [AnimationControllerFactory];
+function FilterAnimationControllerFactory(
+ AnimationController: ReturnType<typeof AnimationControllerFactory>
+) {
+ const FilterAnimationController: React.FC<FilterAnimationControllerProps> = ({
+ filter,
+ filterIdx,
+ setFilterAnimationTime,
+ children
+ }) => {
+ const intervalBins = useMemo(() => getIntervalBins(filter), [filter]);
+
+ const steps = useMemo(() => (intervalBins ? intervalBins.map(x => x.x0) : null), [
+ intervalBins
+ ]);
+
+ 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
+ ]);
+ break;
+ default:
+ setFilterAnimationTime(filterIdx, 'value', value);
+ break;
+ }
+ },
+ [filterIdx, intervalBins, filter.animationWindow, setFilterAnimationTime]
+ );
+
+ // if filter is synced merge the filter and animation config
+ const timeline = getTimelineFromFilter(filter);
+
+ return (
+ <AnimationController
+ key="filter-control"
+ value={filter.value}
+ domain={filter.domain}
+ speed={filter.speed}
+ isAnimating={filter.isAnimating}
+ animationWindow={filter.animationWindow}
+ steps={steps}
+ updateAnimation={updateAnimation}
+ // @ts-expect-error different function type, goes to TimeWidget setFilterAnimationTime()
+ setTimelineValue={setFilterAnimationTime}
+ timeline={timeline}
+ children={children}
+ />
+ );
+ };
+ return FilterAnimationController;
+}
+
+export default FilterAnimationControllerFactory;
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 1b44faaec..65b3fd8b5 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
@@ -23,7 +23,7 @@ import TimeRangeFilterFactory from '../time-range-filter';
import {Clock} from '../../common/icons';
import FieldPanelWithFieldSelectFactory from './filter-panel-with-field-select';
import {TimeRangeFilterPanelComponent} from './types';
-import {isSideFilter} from '@kepler.gl/utils';
+import {isSideFilter, getTimelineFromFilter} from '@kepler.gl/utils';
TimeRangeFilterPanelFactory.deps = [FieldPanelWithFieldSelectFactory, TimeRangeFilterFactory];
@@ -59,6 +59,8 @@ function TimeRangeFilterPanelFactory(
[filter.id, isEnlarged, enlargeFilter]
);
+ const timeline = getTimelineFromFilter(filter);
+
return (
<>
<FieldPanelWithFieldSelect
@@ -78,6 +80,7 @@ function TimeRangeFilterPanelFactory(
setFilter={onSetFilter}
isAnimatable
hideTimeTitle
+ timeline={timeline}
/>
</div>
)}
diff --git a/src/components/src/filters/index.ts b/src/components/src/filters/index.ts
index 168146c6e..7aabdf54b 100644
--- a/src/components/src/filters/index.ts
+++ b/src/components/src/filters/index.ts
@@ -23,3 +23,5 @@ export {default as MultiSelectFilter} from './multi-select-filter';
export {default as TimeRangeFilter} from './time-range-filter';
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';
diff --git a/src/components/src/filters/time-range-filter.tsx b/src/components/src/filters/time-range-filter.tsx
index bda736fb1..240ab69bc 100644
--- a/src/components/src/filters/time-range-filter.tsx
+++ b/src/components/src/filters/time-range-filter.tsx
@@ -60,7 +60,8 @@ function TimeRangeFilterFactory(TimeRangeSlider: ReturnType<typeof TimeRangeSlid
setFilter,
isAnimatable,
toggleAnimation,
- hideTimeTitle
+ hideTimeTitle,
+ timeline
}) => (
<TimeRangeSlider
{...timeRangeSliderFieldsSelector(filter)}
@@ -68,6 +69,7 @@ function TimeRangeFilterFactory(TimeRangeSlider: ReturnType<typeof TimeRangeSlid
toggleAnimation={toggleAnimation}
isAnimatable={isAnimatable}
hideTimeTitle={hideTimeTitle}
+ timeline={timeline}
/>
);
diff --git a/src/components/src/filters/time-widget-top.tsx b/src/components/src/filters/time-widget-top.tsx
new file mode 100644
index 000000000..247435e3d
--- /dev/null
+++ b/src/components/src/filters/time-widget-top.tsx
@@ -0,0 +1,152 @@
+import React, {useCallback, useMemo} from 'react';
+import styled from 'styled-components';
+import {Clock, Close, LineChart, ArrowDown, ArrowUp} from '../common/icons';
+import FieldSelectorFactory from '../common/field-selector';
+import {SelectTextBold, IconRoundSmall, CenterFlexbox} from '../common/styled-components';
+import {TimeWidgetTopProps, TopSectionWrapperProps} from './types';
+import {Field} from '@kepler.gl/types';
+
+const TOP_SECTION_HEIGHT = '36px';
+
+const TopSectionWrapper = styled.div.attrs({
+ className: 'time-widget--top'
+})<TopSectionWrapperProps>`
+ display: flex;
+ justify-content: space-between;
+ width: 100%;
+ 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;
+
+ .animation-control__speed-slider {
+ right: calc(0% - 48px);
+ }
+ }
+`;
+
+const StyledTitle = styled(CenterFlexbox)`
+ flex-grow: 0;
+ color: ${props => props.theme.textColor};
+ margin-right: 10px;
+
+ .bottom-widget__icon {
+ margin-right: 6px;
+ }
+ .bottom-widget__icon.speed {
+ margin-right: 0;
+ }
+`;
+
+const StyledCenterBox = styled(CenterFlexbox)`
+ > div {
+ margin-left: 4px;
+ }
+`;
+
+TimeWidgetTopFactory.deps = [FieldSelectorFactory];
+function TimeWidgetTopFactory(FieldSelector: ReturnType<typeof FieldSelectorFactory>) {
+ const TimeWidgetTop: React.FC<TimeWidgetTopProps> = ({
+ filter,
+ readOnly,
+ datasets,
+ setFilterPlot,
+ index,
+ onClose,
+ isMinified,
+ onToggleMinify
+ }) => {
+ 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(index, {yAxis: value}), [
+ setFilterPlot,
+ index
+ ]);
+
+ return (
+ <TopSectionWrapper>
+ <StyledTitle className="bottom-widget__field">
+ <CenterFlexbox className="bottom-widget__icon">
+ <Clock height="15px" />
+ </CenterFlexbox>
+ <SelectTextBold>{filter.name}</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"
+ value={filter.yAxis ? filter.yAxis.name : null}
+ onSelect={_setFilterPlotYAxis}
+ placeholder="placeholder.yAxis"
+ erasable
+ showToken={false}
+ />
+ </div>
+ </StyledTitle>
+ ) : null}
+ <StyledCenterBox>
+ <IconRoundSmall>
+ {isMinified ? (
+ <ArrowUp height="12px" onClick={onToggleMinify} />
+ ) : (
+ <ArrowDown height="12px" onClick={onToggleMinify} />
+ )}
+ </IconRoundSmall>
+ {!readOnly ? (
+ <IconRoundSmall>
+ <Close height="12px" onClick={onClose} />
+ </IconRoundSmall>
+ ) : null}
+ </StyledCenterBox>
+ </TopSectionWrapper>
+ );
+ };
+ return TimeWidgetTop;
+}
+
+export default TimeWidgetTopFactory;
diff --git a/src/components/src/filters/time-widget.tsx b/src/components/src/filters/time-widget.tsx
index e04d829a8..bfb30d9f4 100644
--- a/src/components/src/filters/time-widget.tsx
+++ b/src/components/src/filters/time-widget.tsx
@@ -18,151 +18,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {useCallback, useMemo} from 'react';
+import React, {useCallback, useState} from 'react';
import styled from 'styled-components';
-import {
- CenterFlexbox,
- SelectTextBold,
- IconRoundSmall,
- BottomWidgetInner
-} from '../common/styled-components';
-import {Close, Clock, LineChart} from '../common/icons';
+import {BottomWidgetInner} from '../common/styled-components';
import TimeRangeSliderFactory from '../common/time-range-slider';
-import FieldSelectorFactory from '../common/field-selector';
import FloatingTimeDisplayFactory from '../common/animation-control/floating-time-display';
-import {Field} from '@kepler.gl/types';
import {timeRangeSliderFieldsSelector} from './time-range-filter';
-import {TimeWidgetProps, TimeWidgetTopProps, TopSectionWrapperProps} from './types';
-
-const TOP_SECTION_HEIGHT = '36px';
+import {TimeWidgetProps} from './types';
+import TimeWidgetTopFactory from './time-widget-top';
const TimeBottomWidgetInner = styled(BottomWidgetInner)`
padding: 6px 32px 24px 32px;
`;
-const TopSectionWrapper = styled.div.attrs({
- className: 'time-widget--top'
-})<TopSectionWrapperProps>`
- display: flex;
- justify-content: space-between;
- width: 100%;
- 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;
-
- .animation-control__speed-slider {
- right: calc(0% - 48px);
- }
- }
-`;
-
-const StyledTitle = styled(CenterFlexbox)`
- flex-grow: 0;
- color: ${props => props.theme.textColor};
- margin-right: 10px;
-
- .bottom-widget__icon {
- margin-right: 6px;
- }
- .bottom-widget__icon.speed {
- margin-right: 0;
- }
-`;
-
-TimeWidgetTopFactory.deps = [FieldSelectorFactory];
-export function TimeWidgetTopFactory(FieldSelector: ReturnType<typeof FieldSelectorFactory>) {
- const TimeWidgetTop: React.FC<TimeWidgetTopProps> = ({
- filter,
- readOnly,
- datasets,
- setFilterPlot,
- index,
- onClose
- }) => {
- 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(index, {yAxis: value}), [
- setFilterPlot,
- index
- ]);
- return (
- <TopSectionWrapper>
- <StyledTitle className="bottom-widget__field">
- <CenterFlexbox className="bottom-widget__icon">
- <Clock height="15px" />
- </CenterFlexbox>
- <SelectTextBold>{filter.name}</SelectTextBold>
- </StyledTitle>
- <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"
- value={filter.yAxis ? filter.yAxis.name : null}
- onSelect={_setFilterPlotYAxis}
- placeholder="placeholder.yAxis"
- erasable
- showToken={false}
- />
- </div>
- </StyledTitle>
- {!readOnly ? (
- <CenterFlexbox>
- <IconRoundSmall>
- <Close height="12px" onClick={onClose} />
- </IconRoundSmall>
- </CenterFlexbox>
- ) : null}
- </TopSectionWrapper>
- );
- };
- return TimeWidgetTop;
-}
TimeWidgetFactory.deps = [TimeRangeSliderFactory, FloatingTimeDisplayFactory, TimeWidgetTopFactory];
+
function TimeWidgetFactory(
TimeRangeSlider: ReturnType<typeof TimeRangeSliderFactory>,
FloatingTimeDisplay: ReturnType<typeof FloatingTimeDisplayFactory>,
@@ -181,8 +51,11 @@ function TimeWidgetFactory(
updateAnimationSpeed,
toggleAnimation,
setFilterPlot,
- setFilterAnimationWindow
+ setFilterAnimationWindow,
+ timeline
}: TimeWidgetProps) => {
+ const [isMinified, setMinified] = useState(false);
+
const _updateAnimationSpeed = useCallback(speed => updateAnimationSpeed(index, speed), [
updateAnimationSpeed,
index
@@ -190,6 +63,8 @@ function TimeWidgetFactory(
const _toggleAnimation = useCallback(() => toggleAnimation(index), [toggleAnimation, index]);
+ const _onToggleMinify = useCallback(() => setMinified(!isMinified), [setMinified, isMinified]);
+
const _setFilterAnimationWindow = useCallback(
animationWindow => setFilterAnimationWindow({id: filter.id, animationWindow}),
[setFilterAnimationWindow, filter.id]
@@ -209,7 +84,11 @@ function TimeWidgetFactory(
setFilterPlot={setFilterPlot}
index={index}
onClose={onClose}
+ onToggleMinify={_onToggleMinify}
+ isMinified={isMinified}
/>
+ {/* Once AnimationControl is able to display large timeline*/}
+ {/* we can replace TimeRangeSlider with AnimationControl*/}
<TimeRangeSlider
{...timeRangeSliderFieldsSelector(filter)}
onChange={timeSliderOnChange}
@@ -219,6 +98,8 @@ function TimeWidgetFactory(
hideTimeTitle={showTimeDisplay}
resetAnimation={resetAnimation}
isAnimatable={isAnimatable}
+ isMinified={isMinified}
+ timeline={timeline}
/>
{showTimeDisplay ? (
<FloatingTimeDisplay
diff --git a/src/components/src/filters/types.ts b/src/components/src/filters/types.ts
index 9aeabb48d..2fa29caff 100644
--- a/src/components/src/filters/types.ts
+++ b/src/components/src/filters/types.ts
@@ -3,7 +3,8 @@ import {
MultiSelectFilter,
RangeFilter,
SelectFilter,
- TimeRangeFilter
+ TimeRangeFilter,
+ Timeline
} from '@kepler.gl/types';
import {Layer} from '@kepler.gl/layers';
import {
@@ -37,6 +38,7 @@ export type TimeRangeFilterProps = {
hideTimeTitle: boolean;
setFilter: (v: number[]) => void;
toggleAnimation: () => void;
+ timeline: Timeline;
};
export type SingleSelectFilterProps = {
@@ -58,6 +60,8 @@ export type TimeWidgetTopProps = {
setFilterPlot: ActionHandler<typeof setFilterPlot>;
index: number;
onClose: () => void;
+ onToggleMinify: () => void;
+ isMinified: boolean;
};
export type TimeWidgetProps = {
@@ -74,4 +78,5 @@ export type TimeWidgetProps = {
toggleAnimation: ActionHandler<typeof toggleFilterAnimation>;
setFilterPlot: ActionHandler<typeof setFilterPlot>;
setFilterAnimationWindow: ActionHandler<typeof setFilterAnimationWindow>;
+ timeline: Timeline;
};
diff --git a/src/components/src/index.ts b/src/components/src/index.ts
index d8d5e2962..d9aecc4ba 100644
--- a/src/components/src/index.ts
+++ b/src/components/src/index.ts
@@ -43,11 +43,9 @@ export {default as SidePanelFactory} from './side-panel';
export {default as PanelTitleFactory} from './side-panel/panel-title';
export {default as MapContainerFactory} from './map-container';
export {default as MapsLayoutFactory} from './maps-layout';
-export {
- default as BottomWidgetFactory,
- LayerAnimationControllerFactory,
- FilterAnimationControllerFactory
-} from './bottom-widget';
+export {default as BottomWidgetFactory} from './bottom-widget';
+export {default as LayerAnimationControllerFactory} from './layer-animation-controller';
+export {default as FilterAnimationControllerFactory} from './filter-animation-controller';
export {default as ModalContainerFactory} from './modal-container';
export {default as PlotContainerFactory} from './plot-container';
export {default as GeocoderPanelFactory, getUpdateVisDataPayload} from './geocoder-panel';
@@ -176,7 +174,8 @@ export {default as TimeSliderMarkerFactory} from './common/time-slider-marker';
export {default as TimeRangeSliderTimeTitleFactory} from './common/time-range-slider-time-title';
export {default as IconButton} from './common/icon-button';
// // Filters factory
-export {default as TimeWidgetFactory, TimeWidgetTopFactory} from './filters/time-widget';
+export {default as TimeWidgetFactory} from './filters/time-widget';
+export {default as TimeWidgetTopFactory} from './filters/time-widget-top';
export {default as SingleSelectFilterFactory} from './filters/single-select-filter';
export {default as MultiSelectFilterFactory} from './filters/multi-select-filter';
export {default as NewFilterPanelFactory} from './filters/filter-panels/new-filter-panel';
diff --git a/src/components/src/layer-animation-controller.tsx b/src/components/src/layer-animation-controller.tsx
new file mode 100644
index 000000000..2597161a2
--- /dev/null
+++ b/src/components/src/layer-animation-controller.tsx
@@ -0,0 +1,59 @@
+import React, {useCallback} from 'react';
+import {ANIMATION_WINDOW} from '@kepler.gl/constants';
+import {AnimationConfig} from '@kepler.gl/types';
+import {snapToMarks, getTimelineFromAnimationConfig, toArray} from '@kepler.gl/utils';
+import AnimationControllerFactory from './common/animation-control/animation-controller';
+
+interface LayerAnimationControllerProps {
+ animationConfig: AnimationConfig;
+ setLayerAnimationTime: (x: number) => void;
+}
+
+LayerAnimationControllerFactory.deps = [AnimationControllerFactory];
+
+function LayerAnimationControllerFactory(
+ AnimationController: ReturnType<typeof AnimationControllerFactory>
+) {
+ const LayerAnimationController: React.FC<LayerAnimationControllerProps> = ({
+ animationConfig,
+ setLayerAnimationTime,
+ children
+ }) => {
+ const {timeSteps, domain} = animationConfig;
+
+ const setTimelineValue = useCallback(
+ (value: number) => {
+ if (Array.isArray(timeSteps)) {
+ setLayerAnimationTime(snapToMarks(toArray(value)[0], timeSteps));
+
+ // TODO: merge slider in to avoid this step
+ } else if (domain && value >= domain[0] && value <= domain[1]) {
+ setLayerAnimationTime(value);
+ }
+ },
+ [domain, setLayerAnimationTime, timeSteps]
+ );
+
+ const timeline = getTimelineFromAnimationConfig(animationConfig);
+
+ return (
+ <AnimationController
+ key="layer-control"
+ value={Number(animationConfig.currentTime)}
+ domain={animationConfig.domain}
+ speed={animationConfig.speed}
+ isAnimating={animationConfig.isAnimating}
+ steps={animationConfig.timeSteps}
+ animationWindow={
+ animationConfig.timeSteps ? ANIMATION_WINDOW.interval : ANIMATION_WINDOW.point
+ }
+ setTimelineValue={setTimelineValue}
+ timeline={timeline}
+ children={children}
+ />
+ );
+ };
+ return LayerAnimationController;
+}
+
+export default LayerAnimationControllerFactory;
diff --git a/src/types/reducers.d.ts b/src/types/reducers.d.ts
index 9522777aa..f3137c1b5 100644
--- a/src/types/reducers.d.ts
+++ b/src/types/reducers.d.ts
@@ -188,6 +188,7 @@ export type AnimationConfig = {
currentTime: number | null;
speed: number;
isAnimating?: boolean;
+ timeSteps?: null | number[];
// auto generated based on time domain
defaultTimeFormat?: string | null;
// custom ui input
@@ -198,6 +199,20 @@ export type AnimationConfig = {
hideControl?: boolean;
};
+export type Timeline = {
+ domain: [number, number] | null;
+ value: number | [number, number];
+ speed: number;
+ isAnimating: boolean;
+ step?: null | number;
+ timeSteps?: null | number[];
+ defaultTimeFormat?: null | string;
+ timeFormat?: null | string;
+ timezone?: null | string;
+ animationWindow?: null | Filter['animationWindow'];
+ marks?: null | number[];
+} & Record<string, any>;
+
export type BaseInteraction = {
label: string;
enabled: boolean;
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index 325538578..e999e3114 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -65,6 +65,8 @@ export {
datetimeFormatter,
formatNumber
} from './data-utils';
+export {getTimelineFromAnimationConfig, getTimelineFromFilter} from './time';
+
export {
datasetColorMaker,
findDefaultColorField,
diff --git a/src/utils/src/time.ts b/src/utils/src/time.ts
new file mode 100644
index 000000000..9f89117ce
--- /dev/null
+++ b/src/utils/src/time.ts
@@ -0,0 +1,100 @@
+// Copyright (c) 2023 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import {AnimationConfig, Timeline, TimeRangeFilter} from '@kepler.gl/types';
+
+import {toArray} from './utils';
+
+export const TIMELINE_MODES = {
+ inner: 'inner',
+ outer: 'outer'
+};
+
+export const SAMPLE_TIMELINE = {
+ // value: [15], // represent 15% of the all width
+ value: [5, 15], // represent start at 5% and ends at 15%
+ domain: [1, 100], // represent the total domain
+ speed: 1,
+ enableInteraction: false, // can use interact with this timeline
+ isAnimating: false,
+ step: null,
+ // @todo: giuseppe coverType: 'inner' | 'outer'
+ mode: TIMELINE_MODES.inner
+ // ....
+};
+
+export const getTimelineFromAnimationConfig = (animationConfig: AnimationConfig): Timeline => {
+ const {
+ currentTime,
+ domain,
+ speed,
+ isAnimating,
+ timeSteps,
+ defaultTimeFormat,
+ timeFormat,
+ timezone
+ } = animationConfig;
+
+ return {
+ // @ts-expect-error
+ value: toArray(currentTime),
+ enableInteraction: true,
+ // @ts-expect-error
+ domain,
+ speed,
+ isAnimating: isAnimating || false,
+ timeSteps,
+ defaultTimeFormat,
+ timeFormat,
+ timezone,
+ marks: null
+ };
+};
+
+export const getTimelineFromFilter = (filter: TimeRangeFilter): Timeline => {
+ const {
+ value,
+ domain,
+ speed,
+ isAnimating,
+ step,
+ // @ts-expect-error
+ timeSteps,
+ defaultTimeFormat,
+ timeFormat,
+ timezone,
+ animationWindow
+ } = filter;
+
+ return {
+ value,
+ enableInteraction: true,
+ domain,
+ speed,
+ isAnimating,
+ step,
+ timeSteps,
+ defaultTimeFormat,
+ timeFormat,
+ timezone,
+ animationWindow,
+ marks: null
+ };
+};
diff --git a/test/browser/components/common/animation-control-test.js b/test/browser/components/common/animation-control-test.js
index 8a33fd6a6..46a4bf5dd 100644
--- a/test/browser/components/common/animation-control-test.js
+++ b/test/browser/components/common/animation-control-test.js
@@ -23,6 +23,7 @@ import test from 'tape';
import sinon from 'sinon';
import moment from 'moment';
import {setLayerAnimationTimeConfig} from '@kepler.gl/actions';
+import {getTimelineFromAnimationConfig} from '@kepler.gl/utils';
import {mountWithTheme} from 'test/helpers/component-utils';
import {
@@ -43,7 +44,7 @@ const FloatingTimeDisplay = appInjector.get(FloatingTimeDisplayFactory);
test('Components -> AnimationControl.render', t => {
t.doesNotThrow(() => {
mountWithTheme(<AnimationControl />);
- }, 'Show not fail without props');
+ }, 'Should not fail without props');
t.end();
});
@@ -53,16 +54,18 @@ test('Components -> AnimationControl -> render with props', t => {
const toggleAnimation = sinon.spy();
const setLayerAnimationTime = sinon.spy();
+ const timeline = getTimelineFromAnimationConfig(StateWTripGeojson.visState.animationConfig);
+
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<AnimationControl
isAnimatable
- setLayerAnimationTime={setLayerAnimationTime}
+ setTimelineValue={setLayerAnimationTime}
toggleAnimation={toggleAnimation}
- animationConfig={StateWTripGeojson.visState.animationConfig}
+ timeline={timeline}
/>
);
- }, 'Show not fail with trip layer props');
+ }, 'Should not fail with trip layer props');
t.equal(
wrapper.find('.animation-window-control').length,
@@ -83,6 +86,7 @@ test('Components -> AnimationControl -> render with props', t => {
test('Components -> AnimationControl -> time display', t => {
let wrapper;
+ const timeline = getTimelineFromAnimationConfig(StateWTripGeojson.visState.animationConfig);
// because we are using locale based formats, we set a locale here to make sure
// result are always the same
moment.locale('en');
@@ -92,12 +96,12 @@ test('Components -> AnimationControl -> time display', t => {
wrapper = mountWithTheme(
<AnimationControl
isAnimatable
- setLayerAnimationTime={setLayerAnimationTime}
+ setTimelineValue={setLayerAnimationTime}
toggleAnimation={toggleAnimation}
- animationConfig={StateWTripGeojson.visState.animationConfig}
+ timeline={timeline}
/>
);
- }, 'Show not fail with props');
+ }, 'Should not fail with props');
const timeDisplay = wrapper.find(FloatingTimeDisplay);
const timeDomainStart = wrapper.find('.animation-control__time-domain.domain-start');
@@ -167,18 +171,20 @@ test('Components -> AnimationControl -> time display -> custom timezone and time
})
);
+ const timeline = getTimelineFromAnimationConfig(nextState.animationConfig);
+
const toggleAnimation = () => {};
const setLayerAnimationTime = () => {};
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<AnimationControl
isAnimatable
- setLayerAnimationTime={setLayerAnimationTime}
+ setTimelineValue={setLayerAnimationTime}
toggleAnimation={toggleAnimation}
- animationConfig={nextState.animationConfig}
+ timeline={timeline}
/>
);
- }, 'Show not fail with props');
+ }, 'Should not fail with props');
const timeDisplay = wrapper.find(FloatingTimeDisplay);
const timeDomainStart = wrapper.find('.animation-control__time-domain.domain-start');
const timeDomainEnd = wrapper.find('.animation-control__time-domain.domain-end');
diff --git a/test/browser/components/filters/time-widget-test.js b/test/browser/components/filters/time-widget-test.js
index f7c38959e..7a851bc6c 100644
--- a/test/browser/components/filters/time-widget-test.js
+++ b/test/browser/components/filters/time-widget-test.js
@@ -71,7 +71,8 @@ const defaultProps = {
resetAnimation: nop,
updateAnimationSpeed: nop,
toggleAnimation: nop,
- enlargeFilter: nop,
+ onClose: nop,
+ onToggleMinify: nop,
setFilterPlot: nop,
setFilterAnimationWindow: nop
};
diff --git a/test/node/utils/index.js b/test/node/utils/index.js
index c5ce4ac17..21aacaec0 100644
--- a/test/node/utils/index.js
+++ b/test/node/utils/index.js
@@ -36,4 +36,5 @@ import './util-test';
import './export-utils-test';
import './s2-utils-test';
import './editor-utils-test';
-import './kepler-gl-utils-test';
\ No newline at end of file
+import './kepler-gl-utils-test';
+import './timeline-test';
diff --git a/test/node/utils/timeline-test.js b/test/node/utils/timeline-test.js
new file mode 100644
index 000000000..6481e5f0a
--- /dev/null
+++ b/test/node/utils/timeline-test.js
@@ -0,0 +1,128 @@
+// Copyright (c) 2023 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import test from 'tape';
+import {getTimelineFromFilter, getTimelineFromAnimationConfig} from '@kepler.gl/utils';
+
+test('#timeline -> getTimelineFromFilter', t => {
+ const filter = {
+ dataId: ['test_trip_data'],
+ id: 'lojgttzht',
+ fixedDomain: true,
+ enlarged: true,
+ isAnimating: false,
+ animationWindow: 'free',
+ speed: 1,
+ name: ['tpep_pickup_datetime'],
+ type: 'timeRange',
+ fieldIdx: [0],
+ domain: [1421315219000, 1421348744000],
+ value: [1421315219000, 1421348744000],
+ plotType: {
+ interval: '5-minute',
+ defaultTimeFormat: 'L LT',
+ type: 'histogram',
+ aggregation: 'sum'
+ },
+ yAxis: null,
+ gpu: true,
+ step: 1000,
+ mappedValue: [
+ null,
+ null,
+ 1421348740000,
+ null,
+ 1421348741000,
+ 1421348741000,
+ 1421348741000,
+ 1421348741000,
+ 1421348741000,
+ 1421348741000,
+ 1421348741000,
+ 1421348741000,
+ 1421320174000
+ ],
+ defaultTimeFormat: 'L LTS',
+ fieldType: 'timestamp',
+ gpuChannel: [0]
+ };
+
+ const timeline = getTimelineFromFilter(filter);
+ t.deepEqual(
+ Object.keys(timeline),
+ [
+ 'value',
+ 'enableInteraction',
+ 'domain',
+ 'speed',
+ 'isAnimating',
+ 'step',
+ 'timeSteps',
+ 'defaultTimeFormat',
+ 'timeFormat',
+ 'timezone',
+ 'animationWindow',
+ 'marks'
+ ],
+ 'Should generate the correct keys for filter timeline'
+ );
+ t.end();
+});
+
+test('#timeline -> getTimelineFromAnimationConfig', t => {
+ const animationConfig = {
+ domain: [1565577697000, 1565578881000],
+ currentTime: 1565577697000,
+ speed: 1,
+ isAnimating: false,
+ timeSteps: null,
+ timeFormat: null,
+ timezone: null,
+ defaultTimeFormat: 'L LTS',
+ duration: null
+ };
+
+ const timeline = getTimelineFromAnimationConfig(animationConfig);
+
+ t.deepEqual(
+ Object.keys(timeline),
+ [
+ 'value',
+ 'enableInteraction',
+ 'domain',
+ 'speed',
+ 'isAnimating',
+ 'timeSteps',
+ 'defaultTimeFormat',
+ 'timeFormat',
+ 'timezone',
+ 'marks'
+ ],
+ 'Should generate the correct keys for animationConfig timeline'
+ );
+
+ t.deepEqual(
+ getTimelineFromAnimationConfig(animationConfig).value,
+ [animationConfig.currentTime],
+ 'Should have converted animationConfig currentTime to value and array shaped'
+ );
+
+ t.end();
+});