Skip to content

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

[Feat] add incremental timeline animation (#1315)

Shan He7f5282b4fcd0
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.js
index 1c297c398..a24a05e2c 100644
--- a/examples/demo-app/src/app.js
+++ b/examples/demo-app/src/app.js
@@ -180,7 +180,7 @@ class App extends Component {
_loadSampleData() {
this._loadPointData();
// this._loadGeojsonData();
- // this._loadTripGeoJson();
+ this._loadTripGeoJson();
// this._loadIconData();
// this._loadH3HexagonData();
// this._loadS2Data();
diff --git a/src/actions/vis-state-actions.d.ts b/src/actions/vis-state-actions.d.ts
index 9b4c10081..3f41289a5 100644
--- a/src/actions/vis-state-actions.d.ts
+++ b/src/actions/vis-state-actions.d.ts
@@ -125,18 +125,27 @@ export function setFilter(
): Merge<SetFilterUpdaterAction, {type: ActionTypes.SET_FILTER}>;
-export type SetTimeAnimationUpdaterAction = {
+export type SetFilterAnimationTimeUpdaterAction = {
idx: number;
prop: string;
value: any;
valueIndex?: number;
};
-export function setTimeAnmation(
+export function setFilterAnimationTime(
idx: number,
prop: string,
value: any,
valueIndex?: number
-): Merge<SetTimeAnimationUpdaterAction, {type: ActionTypes.SET_TIME_ANIMATION}>;
+): Merge<SetFilterAnimationTimeUpdaterAction, {type: ActionTypes.SET_FILTER_ANIMATION_TIME}>;
+
+export type SetFilterAnimationWindowUpdaterAction = {
+ id: string;
+ animationWindow: string;
+};
+export function setFilterAnimationWindow({
+ id: string,
+ animationWindow: string,
+}): Merge<SetFilterAnimationWindowUpdaterAction, {type: ActionTypes.SET_FILTER_ANIMATION_WINDOW}>;
export type AddFilterUpdaterAction = {
@@ -253,12 +262,12 @@ export function updateFilterAnimationSpeed(
{type: ActionTypes.UPDATE_FILTER_ANIMATION_SPEED}
>;
-export type UpdateAnimationTimeUpdaterAction = {
+export type SetLayerAnimationTimeUpdaterAction = {
value: number;
};
-export function updateAnimationTime(
+export function setLayerAnimationTime(
value: number
-): Merge<UpdateAnimationTimeUpdaterAction, {type: ActionTypes.UPDATE_ANIMATION_TIME}>;
+): Merge<SetLayerAnimationTimeUpdaterAction, {type: ActionTypes.SET_LAYER_ANIMATION_TIME}>;
export type UpdateLayerAnimationSpeedUpdaterAction = {
speed: number;
@@ -267,6 +276,13 @@ export function updateLayerAnimationSpeed(
speed: number
): Merge<UpdateLayerAnimationSpeedUpdaterAction, {type: ActionTypes.UPDATE_LAYER_ANIMATION_SPEED}>;
+export type ToggleLayerAnimationUpdaterAction = {
+ idx;
+};
+export function toggleLayerAnimation(
+ idx: number
+): Merge<ToggleLayerAnimationUpdaterAction, {type: ActionTypes.TOGGLE_LAYER_ANIMATION}>;
+
export type EnlargeFilterUpdaterAction = {
idx: number;
};
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.js
index bb128fc90..069e01134 100644
--- a/src/actions/vis-state-actions.js
+++ b/src/actions/vis-state-actions.js
@@ -187,12 +187,12 @@ export function setFilter(idx, prop, value, valueIndex) {
* @param value - new value
* @param valueIndex - dataId index
* @returns action
- * @type {typeof import('./vis-state-actions').setTimeAnmation}
+ * @type {typeof import('./vis-state-actions').setFilterAnimationTime}
* @public
*/
-export function setTimeAnmation(idx, prop, value, valueIndex) {
+export function setFilterAnimationTime(idx, prop, value, valueIndex) {
return {
- type: ActionTypes.SET_TIME_ANIMATION,
+ type: ActionTypes.SET_FILTER_ANIMATION_TIME,
idx,
prop,
value,
@@ -200,6 +200,19 @@ export function setTimeAnmation(idx, prop, value, valueIndex) {
};
}
+/**
+ * Same as Update filter
+ * @memberof visStateActions
+ * @type {typeof import('./vis-state-actions').setFilterAnimationWindow}
+ * @public
+ */
+export function setFilterAnimationWindow({id, animationWindow}) {
+ return {
+ type: ActionTypes.SET_FILTER_ANIMATION_WINDOW,
+ id,
+ animationWindow
+ };
+}
/**
* Add a new filter
* @memberof visStateActions
@@ -428,13 +441,13 @@ export function updateFilterAnimationSpeed(idx, speed) {
* Reset animation
* @memberof visStateActions
* @param value - Current value of the slider
- * @type {typeof import('./vis-state-actions').updateAnimationTime}
+ * @type {typeof import('./vis-state-actions').setLayerAnimationTime}
* @returns action
* @public
*/
-export function updateAnimationTime(value) {
+export function setLayerAnimationTime(value) {
return {
- type: ActionTypes.UPDATE_ANIMATION_TIME,
+ type: ActionTypes.SET_LAYER_ANIMATION_TIME,
value
};
}
@@ -454,6 +467,12 @@ export function updateLayerAnimationSpeed(speed) {
};
}
+export function toggleLayerAnimation() {
+ return {
+ type: ActionTypes.TOGGLE_LAYER_ANIMATION
+ };
+}
+
/**
* Show larger time filter at bottom for time playback (apply to time filter only)
* @memberof visStateActions
diff --git a/src/components/bottom-widget.js b/src/components/bottom-widget.js
index 528f63a36..dcb48b900 100644
--- a/src/components/bottom-widget.js
+++ b/src/components/bottom-widget.js
@@ -18,12 +18,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React from 'react';
+import React, {useCallback, useMemo} from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import TimeWidgetFactory from './filters/time-widget';
import AnimationControlFactory from './common/animation-control/animation-control';
-import {FILTER_TYPES} from 'constants/default-settings';
+import AnimationControllerFactory from './common/animation-control/animation-controller';
+import {ANIMATION_WINDOW, FILTER_TYPES} from 'constants';
const propTypes = {
filters: PropTypes.arrayOf(PropTypes.object),
@@ -38,23 +39,104 @@ const propTypes = {
const maxWidth = 1080;
-BottomWidgetFactory.deps = [TimeWidgetFactory, AnimationControlFactory];
-
const BottomWidgetContainer = styled.div`
position: absolute;
display: flex;
flex-direction: column;
- padding-top: ${props => props.theme.bottomWidgetPaddingTop}px;
- padding-right: ${props => props.theme.bottomWidgetPaddingRight}px;
- padding-bottom: ${props => props.theme.bottomWidgetPaddingBottom}px;
- padding-left: ${props => props.theme.bottomWidgetPaddingLeft}px;
+ padding-top: ${props => (props.hasPadding ? props.theme.bottomWidgetPaddingTop : 0)}px;
+ padding-right: ${props => (props.hasPadding ? props.theme.bottomWidgetPaddingRight : 0)}px;
+ padding-bottom: ${props => (props.hasPadding ? props.theme.bottomWidgetPaddingBottom : 0)}px;
+ padding-left: ${props => (props.hasPadding ? props.theme.bottomWidgetPaddingLeft : 0)}px;
width: ${props => props.width}px;
bottom: 0;
right: 0;
z-index: 1;
`;
-export default function BottomWidgetFactory(TimeWidget, AnimationControl) {
+FilterAnimationControllerFactory.deps = [AnimationControllerFactory];
+export function FilterAnimationControllerFactory(AnimationController) {
+ const FilterAnimationController = ({
+ filter = {},
+ filterIdx,
+ setFilterAnimationTime,
+ children
+ }) => {
+ const intervalBins = useMemo(() => {
+ const bins = filter && filter.bins;
+ const interval = filter.plotType && filter.plotType.interval;
+ return bins && Object.keys(bins).length && Object.values(bins)[0][interval];
+ }, [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;
+}
+
+LayerAnimationControllerFactory.deps = [AnimationControllerFactory];
+export function LayerAnimationControllerFactory(AnimationController) {
+ const LayerAnimationController = ({animationConfig, setLayerAnimationTime, children}) => (
+ <AnimationController
+ key="layer-control"
+ value={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;
+}
+
+BottomWidgetFactory.deps = [
+ TimeWidgetFactory,
+ AnimationControlFactory,
+ FilterAnimationControllerFactory,
+ LayerAnimationControllerFactory
+];
+export default function BottomWidgetFactory(
+ TimeWidget,
+ AnimationControl,
+ FilterAnimationController,
+ LayerAnimationController
+) {
const BottomWidget = props => {
const {
datasets,
@@ -70,54 +152,80 @@ export default function BottomWidgetFactory(TimeWidget, AnimationControl) {
const {activeSidePanel, readOnly} = uiState;
const isOpen = Boolean(activeSidePanel);
- const enlargedFilterIdx = filters.findIndex(
- f => f.enlarged && f.type === FILTER_TYPES.timeRange
+ const enlargedFilterIdx = useMemo(
+ () => filters.findIndex(f => f.enlarged && f.type === FILTER_TYPES.timeRange),
+ [filters]
);
- const isAnyFilterAnimating = filters.some(f => f.isAnimating);
+ const animatedFilter = useMemo(() => filters.find(f => f.isAnimating), [filters]);
const enlargedFilterWidth = isOpen ? containerW - sidePanelWidth : containerW;
// show playback control if layers contain trip layer & at least one trip layer is visible
- const animatedLayer = layers.filter(
- l => l.config.animation && l.config.animation.enabled && l.config.isVisible
+ const animatableLayer = useMemo(
+ () =>
+ layers.filter(l => l.config.animation && l.config.animation.enabled && l.config.isVisible),
+ [layers]
);
- const readToAnimation = Array.isArray(animationConfig.domain) && animationConfig.currentTime;
+ const readyToAnimation =
+ Array.isArray(animationConfig.domain) && Number.isFinite(animationConfig.currentTime);
// if animation control is showing, hide time display in time slider
- const showFloatingTimeDisplay = !animatedLayer.length;
- const showAnimationControl = animatedLayer.length && readToAnimation;
+ const showFloatingTimeDisplay = !animatableLayer.length;
+ const showAnimationControl = animatableLayer.length && readyToAnimation;
const showTimeWidget = enlargedFilterIdx > -1 && Object.keys(datasets).length > 0;
- // The bottom widget can hide clickable elements so do not render it if not needed
- if (!showAnimationControl && !showTimeWidget) {
- return null;
- }
+
return (
<BottomWidgetContainer
width={Math.min(maxWidth, enlargedFilterWidth)}
className="bottom-widget--container"
+ hasPadding={showAnimationControl || showTimeWidget}
>
- {showAnimationControl ? (
- <AnimationControl
- animationConfig={animationConfig}
- updateAnimationTime={visStateActions.updateAnimationTime}
- updateAnimationSpeed={visStateActions.updateLayerAnimationSpeed}
- />
- ) : null}
- {showTimeWidget ? (
- <TimeWidget
- filter={filters[enlargedFilterIdx]}
- index={enlargedFilterIdx}
- isAnyFilterAnimating={isAnyFilterAnimating}
- datasets={datasets}
- readOnly={readOnly}
- showTimeDisplay={showFloatingTimeDisplay}
- setFilterPlot={visStateActions.setFilterPlot}
- setFilter={visStateActions.setFilter}
- setTimeAnmation={visStateActions.setTimeAnmation}
- toggleAnimation={visStateActions.toggleFilterAnimation}
- updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
- enlargeFilter={visStateActions.enlargeFilter}
- />
- ) : null}
+ <LayerAnimationController
+ animationConfig={animationConfig}
+ setLayerAnimationTime={visStateActions.setLayerAnimationTime}
+ >
+ {animationControlProps =>
+ showAnimationControl ? (
+ <AnimationControl
+ animationConfig={animationConfig}
+ setLayerAnimationTime={visStateActions.setLayerAnimationTime}
+ updateAnimationSpeed={visStateActions.updateLayerAnimationSpeed}
+ toggleAnimation={visStateActions.toggleLayerAnimation}
+ isAnimatable={!animatedFilter}
+ animationControlProps={animationControlProps}
+ />
+ ) : null
+ }
+ </LayerAnimationController>
+ <FilterAnimationController
+ /* pass if filter is not animating, pass in
+ enlarged filter here because animation controller needs to call reset on it
+ we can */
+ filter={animatedFilter || filters[enlargedFilterIdx]}
+ filterIdx={enlargedFilterIdx}
+ setFilterAnimationTime={visStateActions.setFilterAnimationTime}
+ >
+ {animationControlProps =>
+ showTimeWidget ? (
+ <TimeWidget
+ filter={filters[enlargedFilterIdx]}
+ index={enlargedFilterIdx}
+ isAnyFilterAnimating={Boolean(animatedFilter)}
+ datasets={datasets}
+ readOnly={readOnly}
+ showTimeDisplay={showFloatingTimeDisplay}
+ setFilterPlot={visStateActions.setFilterPlot}
+ setFilter={visStateActions.setFilter}
+ setFilterAnimationTime={visStateActions.setFilterAnimationTime}
+ setFilterAnimationWindow={visStateActions.setFilterAnimationWindow}
+ toggleAnimation={visStateActions.toggleFilterAnimation}
+ updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
+ enlargeFilter={visStateActions.enlargeFilter}
+ animationControlProps={animationControlProps}
+ isAnimatable={!animationConfig || !animationConfig.isAnimating}
+ />
+ ) : null
+ }
+ </FilterAnimationController>
</BottomWidgetContainer>
);
};
diff --git a/src/components/common/animation-control/animation-control.js b/src/components/common/animation-control/animation-control.js
index 3ed4b50d2..5031def86 100644
--- a/src/components/common/animation-control/animation-control.js
+++ b/src/components/common/animation-control/animation-control.js
@@ -18,18 +18,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React from 'react';
+import React, {useCallback} from 'react';
import styled from 'styled-components';
import moment from 'moment';
import Slider from 'components/common/slider/slider';
import {BottomWidgetInner} from 'components/common/styled-components';
-import SpeedControlFactory from './speed-control';
-import AnimationPlaybacksFactory from './playback-controls';
+import PlaybackControlsFactory from './playback-controls';
import FloatingTimeDisplayFactory from './floating-time-display';
-import AnimationControllerFactory from './animation-controller';
import {snapToMarks} from 'utils/data-utils';
-import {DEFAULT_TIME_FORMAT, ANIMATION_TYPE} from 'constants/default-settings';
+import {DEFAULT_TIME_FORMAT} from 'constants';
const SliderWrapper = styled.div`
display: flex;
@@ -45,12 +43,9 @@ const AnimationWidgetInner = styled.div`
align-items: center;
height: 32px;
- .animation-control__speed-control {
- margin-right: -10px;
-
- .animation-control__speed-slider {
- right: calc(0% - 10px);
- }
+ .playback-controls {
+ margin-left: -8px;
+ margin-right: 16px;
}
`;
@@ -60,116 +55,73 @@ const StyledDomain = styled.div`
font-size: 10px;
`;
-const BUTTON_HEIGHT = '18px';
-
-AnimationControlFactory.deps = [
- SpeedControlFactory,
- AnimationPlaybacksFactory,
- FloatingTimeDisplayFactory,
- AnimationControllerFactory
-];
-
-function AnimationControlFactory(
- SpeedControl,
- AnimationPlaybacks,
- FloatingTimeDisplay,
- AnimationController
-) {
- class AnimationControl extends React.PureComponent {
- state = {
- showSpeedControl: false
- };
- onSlider1Change = val => {
- const {domain} = this.props.animationConfig;
- if (Array.isArray(this.props.timeSteps)) {
- this.props.updateAnimationTime(snapToMarks(val, this.props.timeSteps));
- // TODO: merge slider in to avoid this step
- } else if (val >= domain[0] && val <= domain[1]) {
- this.props.updateAnimationTime(val);
- }
- };
-
- toggleSpeedControl = () => {
- this.setState({showSpeedControl: !this.state.showSpeedControl});
- };
-
- onChange = () => {
- this.toggleSpeedControl();
- };
-
- _updateAnimation = value => {
- this.props.updateAnimationTime(Array.isArray(value) ? value[0] : value);
- };
-
- render() {
- const {currentTime, domain, speed, step, timeSteps} = this.props.animationConfig;
- const {showSpeedControl} = this.state;
- const animationType = Array.isArray(timeSteps)
- ? ANIMATION_TYPE.interval
- : ANIMATION_TYPE.continuous;
-
- return (
- <BottomWidgetInner className="bottom-widget--inner">
- <AnimationWidgetInner className="animation-widget--inner">
- <div style={{marginLeft: '-10px'}}>
- <AnimationController
- value={currentTime}
- domain={domain}
- speed={speed}
- updateAnimation={this._updateAnimation}
- steps={timeSteps}
- animationType={animationType}
- >
- {(isAnimating, start, pause, reset) => (
- <AnimationPlaybacks
- className="animation-control-playpause"
- startAnimation={start}
- isAnimating={isAnimating}
- pauseAnimation={pause}
- resetAnimation={reset}
- buttonHeight={BUTTON_HEIGHT}
- buttonStyle="link"
- />
- )}
- </AnimationController>
- </div>
- <StyledDomain className="animation-control__time-domain">
- <span>{moment.utc(domain[0]).format(DEFAULT_TIME_FORMAT)}</span>
- </StyledDomain>
- <SliderWrapper className="animation-control__slider">
- <Slider
- showValues={false}
- isRanged={false}
- step={step}
- minValue={domain ? domain[0] : 0}
- maxValue={domain ? domain[1] : 1}
- value1={currentTime}
- onSlider1Change={this.onSlider1Change}
- enableBarDrag={true}
- />
- </SliderWrapper>
- <StyledDomain className="animation-control__time-domain">
- <span>{moment.utc(domain[1]).format(DEFAULT_TIME_FORMAT)}</span>
- </StyledDomain>
- <div className="animation-control__speed-control">
- <SpeedControl
- onClick={this.toggleSpeedControl}
- showSpeedControl={showSpeedControl}
- updateAnimationSpeed={this.props.updateAnimationSpeed}
- speed={speed}
- buttonHeight={BUTTON_HEIGHT}
- />
- </div>
- </AnimationWidgetInner>
- <FloatingTimeDisplay currentTime={currentTime} />
- </BottomWidgetInner>
- );
- }
- }
+AnimationControlFactory.deps = [PlaybackControlsFactory, FloatingTimeDisplayFactory];
+
+function AnimationControlFactory(PlaybackControls, FloatingTimeDisplay) {
+ const AnimationControl = ({
+ isAnimatable,
+ animationControlProps,
+ toggleAnimation,
+ setLayerAnimationTime,
+ updateAnimationSpeed,
+ animationConfig
+ }) => {
+ const {currentTime, domain, speed, step, timeSteps} = animationConfig;
+ const onSlider1Change = useCallback(
+ val => {
+ if (Array.isArray(timeSteps)) {
+ setLayerAnimationTime(snapToMarks(val, timeSteps));
+
+ // TODO: merge slider in to avoid this step
+ } else if (val >= domain[0] && val <= domain[1]) {
+ setLayerAnimationTime(val);
+ }
+ },
+ [domain, timeSteps, setLayerAnimationTime]
+ );
+
+ return (
+ <BottomWidgetInner className="bottom-widget--inner">
+ <AnimationWidgetInner className="animation-widget--inner">
+ <PlaybackControls
+ className="animation-control-playpause"
+ startAnimation={toggleAnimation}
+ isAnimating={animationControlProps.isAnimating}
+ pauseAnimation={toggleAnimation}
+ resetAnimation={animationControlProps.reset}
+ speed={speed}
+ isAnimatable={isAnimatable}
+ updateAnimationSpeed={updateAnimationSpeed}
+ />
+ <StyledDomain className="animation-control__time-domain">
+ <span>{domain ? moment.utc(domain[0]).format(DEFAULT_TIME_FORMAT) : ''}</span>
+ </StyledDomain>
+ <SliderWrapper className="animation-control__slider">
+ <Slider
+ showValues={false}
+ isRanged={false}
+ step={step}
+ minValue={domain ? domain[0] : 0}
+ maxValue={domain ? domain[1] : 1}
+ value1={currentTime}
+ onSlider1Change={onSlider1Change}
+ enableBarDrag={true}
+ />
+ </SliderWrapper>
+ <StyledDomain className="animation-control__time-domain">
+ <span>{domain ? moment.utc(domain[1]).format(DEFAULT_TIME_FORMAT) : ''}</span>
+ </StyledDomain>
+ </AnimationWidgetInner>
+ <FloatingTimeDisplay currentTime={currentTime} />
+ </BottomWidgetInner>
+ );
+ };
AnimationControl.defaultProps = {
- sliderHandleWidth: 12,
- onChange: () => {}
+ toggleAnimation: () => {},
+ updateAnimationSpeed: () => {},
+ animationControlProps: {},
+ animationConfig: {}
};
return AnimationControl;
diff --git a/src/components/common/animation-control/animation-controller.js b/src/components/common/animation-control/animation-controller.js
index 9537c1069..75e0c8702 100644
--- a/src/components/common/animation-control/animation-controller.js
+++ b/src/components/common/animation-control/animation-controller.js
@@ -21,43 +21,69 @@
import {Component} from 'react';
import {bisectLeft} from 'd3-array';
import {requestAnimationFrame, cancelAnimationFrame} from 'global/window';
-import {BASE_SPEED, FPS, ANIMATION_TYPE} from 'constants/default-settings';
+import {BASE_SPEED, FPS, ANIMATION_WINDOW} from 'constants';
import Console from 'global/console';
function AnimationControllerFactory() {
+ /**
+ * 4 Animation Window Types
+ * 1. free
+ * |-> |->
+ * Current time is a fixed range, animate a moving window that calls next animation frames continuously
+ * The increment id based on domain / BASE_SPEED * SPEED
+ *
+ * 2. incremental
+ * | |->
+ * Same as free, current time is a growing range, only the max value of range increment during animation.
+ * The increment is also based on domain / BASE_SPEED * SPEED
+ *
+ * 3. point
+ * o -> o
+ * Current time is a point, animate a moving point calls next animation frame continuously
+ * The increment is based on domain / BASE_SPEED * SPEED
+ *
+ * 4. interval
+ * o ~> o
+ * Current time is a point. An array of sorted time steps are provided,
+ * animate a moving point jumps to the next step
+ */
class AnimationController extends Component {
+ // TODO: convert the entire component to use hooks in the next PR
static defaultProps = {
baseSpeed: BASE_SPEED,
speed: 1,
- animationType: ANIMATION_TYPE.continuous
+ steps: null,
+ animationWindow: ANIMATION_WINDOW.free
};
state = {
isAnimating: false
};
+ componentDidMount() {
+ this._startOrPauseAnimation();
+ }
+
componentDidUpdate() {
- if (!this._timer && this.state.isAnimating) {
- if (this.props.animationType === ANIMATION_TYPE.continuous) {
- this._timer = requestAnimationFrame(this._nextFrame);
- } else {
- // animate by interval
- // 30*600
- const {steps, speed} = this.props;
- if (!Array.isArray(steps) || !steps.length) {
- Console.warn('animation steps should be an array');
- return;
- }
- // when speed = 1, animation should loop through 600 frames at 60 FPS
- // calculate delay based on # steps
- const delay = (BASE_SPEED * (1000 / FPS)) / steps.length / (speed || 1);
- this._animate(delay);
- }
+ this._startOrPauseAnimation();
+ }
+
+ componentWillUnmount() {
+ if (this._timer) {
+ cancelAnimationFrame(this._timer);
}
}
_timer = null;
+ _startOrPauseAnimation() {
+ if (!this._timer && this.props.isAnimating) {
+ this._startAnimation();
+ } else if (this._timer && !this.props.isAnimating) {
+ this._pauseAnimation();
+ }
+ }
+
_animate = delay => {
this._startTime = new Date().getTime();
@@ -77,44 +103,56 @@ function AnimationControllerFactory() {
this._timer = requestAnimationFrame(loop);
};
- _resetAnimationWindow = () => {
- const {domain, value} = this.props;
+ _resetAnimationByDomain = () => {
+ const {domain, value, animationWindow} = this.props;
if (Array.isArray(value)) {
- const value0 = domain[0];
- const value1 = value0 + value[1] - value[0];
- this.props.updateAnimation([value0, value1]);
+ if (animationWindow === ANIMATION_WINDOW.incremental) {
+ this.props.updateAnimation([value[0], value[0] + 1]);
+ } else {
+ this.props.updateAnimation([domain[0], domain[0] + value[1] - value[0]]);
+ }
} else {
this.props.updateAnimation(domain[0]);
}
};
- _resetAnimtionStep = () => {
+ _resetAnimtionByTimeStep = () => {
// go to the first steps
this.props.updateAnimation([this.props.steps[0], 0]);
};
_resetAnimation = () => {
- if (this.props.animationType === ANIMATION_TYPE.continuous) {
- this._resetAnimationWindow();
+ if (this.props.animationWindow === ANIMATION_WINDOW.interval) {
+ this._resetAnimtionByTimeStep();
} else {
- this._resetAnimtionStep();
+ this._resetAnimationByDomain();
}
};
_startAnimation = () => {
this._pauseAnimation();
- if (typeof this.props.startAnimation === 'function') {
- this.props.startAnimation();
+ if (this.props.animationWindow === ANIMATION_WINDOW.interval) {
+ // animate by interval
+ // 30*600
+ const {steps, speed} = this.props;
+ if (!Array.isArray(steps) || !steps.length) {
+ Console.warn('animation steps should be an array');
+ return;
+ }
+ // when speed = 1, animation should loop through 600 frames at 60 FPS
+ // calculate delay based on # steps
+ const delay = (BASE_SPEED * (1000 / FPS)) / steps.length / (speed || 1);
+ this._animate(delay);
+ } else {
+ this._timer = requestAnimationFrame(this._nextFrame);
}
+
this.setState({isAnimating: true});
};
_pauseAnimation = () => {
if (this._timer) {
cancelAnimationFrame(this._timer);
- if (typeof this.props.pauseAnimation === 'function') {
- this.props.pauseAnimation();
- }
this._timer = null;
}
this.setState({isAnimating: false});
@@ -123,27 +161,38 @@ function AnimationControllerFactory() {
_nextFrame = () => {
this._timer = null;
const nextValue =
- this.props.animationType === ANIMATION_TYPE.continuous
- ? this._nextFrameByWindow()
- : this._nextFrameByStep();
+ this.props.animationWindow === ANIMATION_WINDOW.interval
+ ? this._nextFrameByTimeStep()
+ : this._nextFrameByDomain();
this.props.updateAnimation(nextValue);
};
- _nextFrameByWindow() {
- const {domain, value, speed, baseSpeed} = this.props;
+ _nextFrameByDomain() {
+ const {domain, value, speed, baseSpeed, animationWindow} = this.props;
const delta = ((domain[1] - domain[0]) / baseSpeed) * speed;
// loop when reaches the end
+ // current time is a range
if (Array.isArray(value)) {
- const value0 = value[1] + delta > domain[1] ? domain[0] : value[0] + delta;
- const value1 = value0 + value[1] - value[0];
+ let value0;
+ let value1;
+ const readEnd = value[1] + delta > domain[1];
+ if (animationWindow === ANIMATION_WINDOW.incremental) {
+ value0 = value[0];
+ value1 = readEnd ? value[0] + 1 : value[1] + delta;
+ } else {
+ value0 = readEnd ? domain[0] : value[0] + delta;
+ value1 = value0 + value[1] - value[0];
+ }
return [value0, value1];
}
+
+ // current time is a point
return value + delta > domain[1] ? domain[0] : value + delta;
}
- _nextFrameByStep() {
+ _nextFrameByTimeStep() {
const {steps, value} = this.props;
const val = Array.isArray(value) ? value[0] : value;
const index = bisectLeft(steps, val);
@@ -157,7 +206,12 @@ function AnimationControllerFactory() {
const {children} = this.props;
return typeof children === 'function'
- ? children(isAnimating, this._startAnimation, this._pauseAnimation, this._resetAnimation)
+ ? children({
+ isAnimating,
+ start: this._startAnimation,
+ pause: this._pauseAnimation,
+ reset: this._resetAnimation
+ })
: null;
}
}
diff --git a/src/components/common/animation-control/animation-speed-slider.js b/src/components/common/animation-control/animation-speed-slider.js
index 8f98fcbc1..3ed1cef74 100644
--- a/src/components/common/animation-control/animation-speed-slider.js
+++ b/src/components/common/animation-control/animation-speed-slider.js
@@ -34,10 +34,12 @@ const SpeedSliderContainer = styled.div`
right: calc(0% - 32px);
width: 180px;
padding: 2px 8px 2px 12px;
- background-color: ${props => props.theme.panelBackground};
+ background-color: ${props => props.theme.bottomWidgetBgd};
box-shadow: -2px -2px 0 0 rgba(0, 0, 0, 0.1);
+
.kg-range-slider__input {
- width: 36px;
+ width: 48px;
+ padding: 6px;
}
`;
diff --git a/src/components/common/animation-control/playback-controls.js b/src/components/common/animation-control/playback-controls.js
index 2a01764e4..bc98821b9 100644
--- a/src/components/common/animation-control/playback-controls.js
+++ b/src/components/common/animation-control/playback-controls.js
@@ -18,16 +18,22 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React from 'react';
+import React, {useState, useCallback} from 'react';
import styled from 'styled-components';
import classnames from 'classnames';
+import {FormattedMessage} from 'localization';
+import {Button, Tooltip} from 'components/common/styled-components';
+import AnimationSpeedSliderFactory from './animation-speed-slider';
+import {Reset, Play, Pause, Rocket, AnchorWindow, FreeWindow} from 'components/common/icons';
+import {ANIMATION_WINDOW} from 'constants';
+import {preciseRound} from 'utils/data-utils';
-import {ButtonGroup, Button} from 'components/common/styled-components';
-import {Play, Reset, Pause} from 'components/common/icons';
+const DELAY_SHOW = 500;
+const DEFAULT_BUTTON_HEIGHT = '20px';
const StyledAnimationControls = styled.div`
display: flex;
- margin-right: 12px;
+ position: relative;
&.disabled {
opacity: 0.4;
@@ -35,65 +41,235 @@ const StyledAnimationControls = styled.div`
}
`;
-const IconButton = styled(Button)`
- padding: 6px 4px;
+const StyledSpeedControl = styled.div`
+ display: flex;
+ align-items: center;
+
+ .animation-control__speed-slider {
+ left: 0;
+ }
+`;
+
+export const IconButton = styled(Button)`
+ width: ${props => (props.collapsed ? 0 : 32)}px;
+ height: 32px;
+ color: ${props => props.theme.playbackButtonColor};
+ background-color: ${props => props.theme.playbackButtonBgColor};
+ border-radius: 4px;
+ margin-left: 7px;
+ border: 0;
+ padding: 0;
+
+ .__react_component_tooltip {
+ font-family: ${props => props.theme.fontFamily};
+ }
svg {
- margin: 0 6px;
+ margin: 0;
+ }
+ &.active {
+ background-color: ${props => props.theme.playbackButtonActBgColor};
}
`;
function nop() {}
-const DEFAULT_BUTTON_HEIGHT = '18px';
const DEFAULT_ICONS = {
- reset: Reset,
- play: Play,
- pause: Pause
+ /* eslint-disable react/display-name */
+ reset: () => <Reset height="18px" />,
+ play: () => <Play height="18px" />,
+ pause: () => <Pause height="18px" />,
+ /* eslint-enable react/display-name */
+ speed: Rocket,
+ animationFree: FreeWindow,
+ animationIncremental: AnchorWindow
+};
+
+const DEFAULT_ANIMATE_ITEMS = {
+ [ANIMATION_WINDOW.free]: {
+ id: ANIMATION_WINDOW.free,
+ icon: DEFAULT_ICONS.animationFree,
+ tooltip: 'tooltip.animationByWindow'
+ },
+ [ANIMATION_WINDOW.incremental]: {
+ id: ANIMATION_WINDOW.incremental,
+ icon: DEFAULT_ICONS.animationIncremental,
+ tooltip: 'tooltip.animationByIncremental'
+ }
};
-function AnimationPlaybacksFactory() {
- const AnimationPlaybacks = ({
- isAnimatable,
+export const AnimationWindowControl = ({
+ onClick,
+ selected,
+ onHide,
+ height,
+ animationItems,
+ btnStyle = {}
+}) => (
+ <div>
+ {Object.values(animationItems)
+ .filter(item => item.id !== selected)
+ .map(item => (
+ <IconButton
+ key={item.id}
+ data-tip
+ data-for={`${item.id}-tooltip`}
+ className="playback-control-button"
+ onClick={() => {
+ onClick(item.id);
+ onHide();
+ }}
+ {...btnStyle}
+ >
+ <item.icon height={height} />
+ {item.tooltip ? (
+ <Tooltip id={`${item.id}-tooltip`} effect="solid" place="top">
+ <FormattedMessage id={item.tooltip} />
+ </Tooltip>
+ ) : null}
+ </IconButton>
+ ))}
+ </div>
+);
+
+PlaybackControlsFactory.deps = [AnimationSpeedSliderFactory];
+function PlaybackControlsFactory(AnimationSpeedSlider) {
+ // eslint-disable-next-line complexity
+ const PlaybackControls = ({
+ isAnimatable = true,
isAnimating,
- buttonStyle,
width,
+ speed,
+ animationWindow = ANIMATION_WINDOW.free,
+ setFilterAnimationWindow,
+ updateAnimationSpeed,
pauseAnimation = nop,
- updateAnimationTime = nop,
+ resetAnimation = nop,
startAnimation = nop,
- buttonHeight = DEFAULT_BUTTON_HEIGHT,
- playbackIcons = DEFAULT_ICONS
+ playbackIcons = DEFAULT_ICONS,
+ animationItems = DEFAULT_ANIMATE_ITEMS,
+ buttonStyle = 'secondary',
+ buttonHeight = DEFAULT_BUTTON_HEIGHT
}) => {
+ const [showSpeedControl, toggleSpeedControl] = useState(false);
+ const [showAnimationWindowControl, setShowAnimationWindowControl] = useState(false);
+ const toggleAnimationWindowControl = useCallback(() => {
+ setShowAnimationWindowControl(!showAnimationWindowControl);
+ }, [showAnimationWindowControl, setShowAnimationWindowControl]);
const btnStyle = buttonStyle ? {[buttonStyle]: true} : {};
+
return (
<StyledAnimationControls
- className={classnames('time-range-slider__control', {
+ className={classnames('playback-controls', {
disabled: !isAnimatable
})}
style={{width: `${width}px`}}
>
- <ButtonGroup>
+ {/** Window */}
+ {setFilterAnimationWindow ? (
+ <IconButton
+ data-tip
+ data-for="animate-window"
+ className={classnames('playback-control-button', {active: showAnimationWindowControl})}
+ onClick={toggleAnimationWindowControl}
+ {...btnStyle}
+ >
+ {(() => {
+ if (animationItems[animationWindow]) {
+ return React.createElement(animationItems[animationWindow].icon, {
+ height: buttonHeight
+ });
+ }
+ return null;
+ })()}
+ {animationItems[animationWindow] && animationItems[animationWindow].tooltip ? (
+ <Tooltip id="animate-window" place="top" delayShow={500} effect="solid">
+ <FormattedMessage id={animationItems[animationWindow].tooltip} />
+ </Tooltip>
+ ) : null}
+ </IconButton>
+ ) : null}
+
+ {showAnimationWindowControl ? (
+ <AnimationWindowControl
+ onClick={setFilterAnimationWindow}
+ selected={animationWindow}
+ onHide={toggleAnimationWindowControl}
+ height={buttonHeight}
+ btnStyle={btnStyle}
+ animationItems={animationItems}
+ />
+ ) : null}
+
+ {/** Speed */}
+ {showAnimationWindowControl || !updateAnimationSpeed ? null : (
+ <StyledSpeedControl
+ onClick={() => {
+ toggleSpeedControl(!showSpeedControl);
+ }}
+ >
+ <IconButton
+ data-tip
+ data-for="animate-speed"
+ className="playback-control-button"
+ onClick={nop}
+ {...btnStyle}
+ >
+ <playbackIcons.speed height={buttonHeight} />
+ <Tooltip id="animate-speed" place="top" delayShow={DELAY_SHOW} effect="solid">
+ <span>{preciseRound(speed, 1)}x</span>
+ </Tooltip>
+ </IconButton>
+ {showSpeedControl ? (
+ <AnimationSpeedSlider
+ onHide={() => {
+ toggleSpeedControl(false);
+ }}
+ updateAnimationSpeed={updateAnimationSpeed}
+ speed={speed}
+ />
+ ) : null}
+ </StyledSpeedControl>
+ )}
+
+ {/** Reset */}
+ {showAnimationWindowControl ? null : (
<IconButton
+ data-tip
+ data-for="animate-reset"
className="playback-control-button"
+ onClick={resetAnimation}
{...btnStyle}
- onClick={updateAnimationTime}
>
<playbackIcons.reset height={buttonHeight} />
+ <Tooltip id="animate-reset" place="top" delayShow={DELAY_SHOW} effect="solid">
+ <FormattedMessage id="tooltip.reset" />
+ </Tooltip>
</IconButton>
+ )}
+
+ {/** Play and pause */}
+ {showAnimationWindowControl ? null : (
<IconButton
- {...btnStyle}
+ data-tip
+ data-for="animate-play-pause"
className={classnames('playback-control-button', {active: isAnimating})}
onClick={isAnimating ? pauseAnimation : startAnimation}
+ hide={showSpeedControl}
+ {...btnStyle}
>
{isAnimating ? (
<playbackIcons.pause height={buttonHeight} />
) : (
<playbackIcons.play height={buttonHeight} />
)}
+ <Tooltip id="animate-play-pause" place="top" delayShow={DELAY_SHOW} effect="solid">
+ <FormattedMessage id={isAnimating ? 'tooltip.pause' : 'tooltip.play'} />
+ </Tooltip>
</IconButton>
- </ButtonGroup>
+ )}
</StyledAnimationControls>
);
};
- return AnimationPlaybacks;
+ return PlaybackControls;
}
-export default AnimationPlaybacksFactory;
+export default PlaybackControlsFactory;
diff --git a/src/components/common/animation-control/speed-control.js b/src/components/common/animation-control/speed-control.js
index c0373a975..03e855737 100644
--- a/src/components/common/animation-control/speed-control.js
+++ b/src/components/common/animation-control/speed-control.js
@@ -23,6 +23,7 @@ import styled from 'styled-components';
import AnimationSpeedSliderFactory from './animation-speed-slider';
import {Button, CenterFlexbox} from 'components/common/styled-components';
import {Rocket} from 'components/common/icons';
+import {preciseRound} from 'utils/data-utils';
const StyledSpeedToggle = styled.div`
display: flex;
@@ -53,7 +54,7 @@ function SpeedControlFactory(AnimationSpeedSlider) {
<Rocket height={buttonHeight} />
</CenterFlexbox>
<StyledSpeedText style={{visibility: !showSpeedControl ? 'visible' : 'hidden'}}>
- {speed}x
+ {preciseRound(speed, 1)}x
</StyledSpeedText>
</Button>
{showSpeedControl ? (
diff --git a/src/components/common/icons/anchor_window.js b/src/components/common/icons/anchor_window.js
new file mode 100644
index 000000000..0f75451ee
--- /dev/null
+++ b/src/components/common/icons/anchor_window.js
@@ -0,0 +1,53 @@
+// Copyright (c) 2020 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 React from 'react';
+import Base from './base';
+import PropTypes from 'prop-types';
+
+const AnchorWindow = props => (
+ <Base {...props}>
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M2.73645 4.67861C2.73645 4.40246 2.96031 4.17861 3.23645 4.17861H11.5177C11.7938 4.17861 12.0177 4.40246 12.0177 4.67861V11.3214C12.0177 11.5975 11.7938 11.8214 11.5177 11.8214H3.23645C2.96031 11.8214 2.73645 11.5975 2.73645 11.3214V4.67861ZM3.73645 5.17861V10.8214H11.0177V5.17861H3.73645Z"
+ />
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M0.5 3.66954C0.776142 3.66954 1 3.8934 1 4.16954L1 11.8304C1 12.1066 0.776143 12.3304 0.5 12.3304C0.223858 12.3304 3.68794e-07 12.1066 3.56723e-07 11.8304L2.18557e-08 4.16954C9.78513e-09 3.8934 0.223858 3.66954 0.5 3.66954Z"
+ />
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M13.7039 5.74894C13.9227 5.58041 14.2366 5.62113 14.4051 5.83988L15.8342 7.69486C15.9727 7.8747 15.9727 8.1253 15.8342 8.30514L14.4051 10.1601C14.2366 10.3789 13.9227 10.4196 13.7039 10.2511C13.4852 10.0825 13.4444 9.76858 13.613 9.54983L14.8069 8L13.613 6.45017C13.4444 6.23142 13.4852 5.91746 13.7039 5.74894Z"
+ />
+ </Base>
+);
+AnchorWindow.propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string
+};
+AnchorWindow.defaultProps = {
+ height: '16px',
+ viewBox: '0 0 16 16',
+ predefinedClassName: 'data-ex-icons-anchorwindow'
+};
+export default AnchorWindow;
diff --git a/src/components/common/icons/free-window.js b/src/components/common/icons/free-window.js
new file mode 100644
index 000000000..87b3960ce
--- /dev/null
+++ b/src/components/common/icons/free-window.js
@@ -0,0 +1,53 @@
+// Copyright (c) 2020 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 React from 'react';
+import Base from './base';
+import PropTypes from 'prop-types';
+
+const FreeWindow = props => (
+ <Base {...props}>
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M3.75665 4.67861C3.75665 4.40246 3.98051 4.17861 4.25665 4.17861H11.7433C12.0195 4.17861 12.2433 4.40246 12.2433 4.67861V11.3214C12.2433 11.5975 12.0195 11.8214 11.7433 11.8214H4.25665C3.98051 11.8214 3.75665 11.5975 3.75665 11.3214V4.67861ZM4.75665 5.17861V10.8214H11.2433V5.17861H4.75665Z"
+ />
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M2.25611 10.2511C2.03735 10.4196 1.7234 10.3789 1.55487 10.1601L0.125822 8.30514C-0.0127244 8.1253 -0.0127244 7.8747 0.125822 7.69486L1.55487 5.83988C1.7234 5.62113 2.03735 5.58041 2.25611 5.74894C2.47486 5.91746 2.51558 6.23142 2.34705 6.45017L1.15308 8L2.34705 9.54983C2.51558 9.76858 2.47486 10.0825 2.25611 10.2511Z"
+ />
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M13.7439 5.76226C13.9626 5.59374 14.2766 5.63446 14.4451 5.85321L15.8742 7.70818C16.0127 7.88802 16.0127 8.13863 15.8742 8.31847L14.4451 10.1734C14.2766 10.3922 13.9626 10.4329 13.7439 10.2644C13.5251 10.0959 13.4844 9.78191 13.6529 9.56316L14.8469 8.01333L13.6529 6.4635C13.4844 6.24474 13.5251 5.93079 13.7439 5.76226Z"
+ />
+ </Base>
+);
+FreeWindow.propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string
+};
+FreeWindow.defaultProps = {
+ height: '16px',
+ viewBox: '0 0 16 16',
+ predefinedClassName: 'data-ex-icons-freewindow'
+};
+export default FreeWindow;
diff --git a/src/components/common/icons/index.js b/src/components/common/icons/index.js
index 016408a4d..5e0104e79 100644
--- a/src/components/common/icons/index.js
+++ b/src/components/common/icons/index.js
@@ -19,6 +19,7 @@
// THE SOFTWARE.
export {default as Add} from './add';
+export {default as AnchorWindow} from './anchor_window';
export {default as ArrowDown} from './arrow-down';
export {default as ArrowDownAlt} from './arrow-down-alt';
export {default as ArrowDownSolid} from './arrow-down-alt';
@@ -50,6 +51,7 @@ export {default as File} from './file';
export {default as Files} from './files';
export {default as FileType} from './file-type';
export {default as FilterFunnel} from './filter-funnel';
+export {default as FreeWindow} from './free-window';
export {default as Gear} from './gear';
export {default as Hash} from './hash';
export {default as Histogram} from './histogram';
diff --git a/src/components/common/time-range-slider.js b/src/components/common/time-range-slider.js
index 5f168067a..6a5923437 100644
--- a/src/components/common/time-range-slider.js
+++ b/src/components/common/time-range-slider.js
@@ -29,41 +29,34 @@ import {Minus} from 'components/common/icons';
import RangeSliderFactory from 'components/common/range-slider';
import TimeSliderMarkerFactory from 'components/common/time-slider-marker';
import PlaybackControlsFactory from 'components/common/animation-control/playback-controls';
-import AnimationControllerFactory from 'components/common/animation-control/animation-controller';
import {DEFAULT_TIME_FORMAT} from 'constants/default-settings';
-const animationControlWidth = 140;
+const animationControlWidth = 176;
const StyledSliderContainer = styled.div`
align-items: flex-end;
display: flex;
flex-direction: row;
justify-content: space-between;
+ padding-left: ${props => (props.isEnlarged ? 24 : 0)}px;
- .time-range-slider__control {
- margin-bottom: 12px;
- margin-right: 30px;
+ .timeline-container .kg-slider {
+ display: none;
}
- .playback-control-button {
- padding: 9px 12px;
+ .playback-controls {
+ margin-left: 22px;
}
`;
TimeRangeSliderFactory.deps = [
PlaybackControlsFactory,
RangeSliderFactory,
- TimeSliderMarkerFactory,
- AnimationControllerFactory
+ TimeSliderMarkerFactory
];
-export default function TimeRangeSliderFactory(
- PlaybackControls,
- RangeSlider,
- TimeSliderMarker,
- AnimationController
-) {
+export default function TimeRangeSliderFactory(PlaybackControls, RangeSlider, TimeSliderMarker) {
class TimeRangeSlider extends Component {
static propTypes = {
onChange: PropTypes.func.isRequired,
@@ -116,7 +109,7 @@ export default function TimeRangeSliderFactory(
};
render() {
- const {domain, value, isEnlarged, hideTimeTitle} = this.props;
+ const {domain, value, isEnlarged, hideTimeTitle, animationControlProps} = this.props;
return (
<div className="time-range-slider">
@@ -124,29 +117,6 @@ export default function TimeRangeSliderFactory(
<TimeTitle timeFormat={this.props.timeFormat} value={value} isEnlarged={isEnlarged} />
) : null}
<StyledSliderContainer className="time-range-slider__container" isEnlarged={isEnlarged}>
- {isEnlarged ? (
- <AnimationController
- value={this.props.value}
- domain={this.props.domain}
- speed={this.props.speed}
- startAnimation={this.props.toggleAnimation}
- pauseAnimation={this.props.toggleAnimation}
- updateAnimation={this.props.onChange}
- >
- {(isAnimating, start, pause, reset) => (
- <PlaybackControls
- isAnimatable={this.props.isAnimatable}
- isAnimating={isAnimating}
- width={animationControlWidth}
- pauseAnimation={pause}
- resetAnimation={reset}
- startAnimation={start}
- buttonHeight="12px"
- buttonStyle="secondary"
- />
- )}
- </AnimationController>
- ) : null}
<div
style={{
width: isEnlarged ? `calc(100% - ${animationControlWidth}px)` : '100%'
@@ -166,6 +136,21 @@ export default function TimeRangeSliderFactory(
xAxis={TimeSliderMarker}
/>
</div>
+
+ {isEnlarged ? (
+ <PlaybackControls
+ isAnimatable={this.props.isAnimatable}
+ width={animationControlWidth}
+ speed={this.props.speed}
+ animationWindow={this.props.animationWindow}
+ updateAnimationSpeed={this.props.updateAnimationSpeed}
+ setFilterAnimationWindow={this.props.setFilterAnimationWindow}
+ pauseAnimation={this.props.toggleAnimation}
+ resetAnimation={animationControlProps.reset}
+ isAnimating={animationControlProps.isAnimating}
+ startAnimation={this.props.toggleAnimation}
+ />
+ ) : null}
</StyledSliderContainer>
</div>
);
diff --git a/src/components/filters/time-range-filter.js b/src/components/filters/time-range-filter.js
index 9af35513b..8c66db6ca 100644
--- a/src/components/filters/time-range-filter.js
+++ b/src/components/filters/time-range-filter.js
@@ -37,6 +37,7 @@ function TimeRangeFilterFactory(TimeRangeSlider) {
lineChart={filter.lineChart}
step={filter.step}
speed={filter.speed}
+ isAnimating={filter.isAnimating}
histogram={filter.enlarged ? filter.enlargedHistogram : filter.histogram}
onChange={setFilter}
toggleAnimation={toggleAnimation}
diff --git a/src/components/filters/time-widget.js b/src/components/filters/time-widget.js
index 6377871ea..be456e1a0 100644
--- a/src/components/filters/time-widget.js
+++ b/src/components/filters/time-widget.js
@@ -30,7 +30,8 @@ import {
} from 'components/common/styled-components';
import {Close, Clock, LineChart} from 'components/common/icons';
import SpeedControlFactory from 'components/common/animation-control/speed-control';
-import TimeRangeFilterFactory from 'components/filters/time-range-filter';
+import TimeRangeSliderFactory from 'components/common/time-range-slider';
+
import FloatingTimeDisplayFactory from 'components/common/animation-control/floating-time-display';
import FieldSelectorFactory from '../common/field-selector';
@@ -104,16 +105,12 @@ const StyledTitle = styled(CenterFlexbox)`
TimeWidgetFactory.deps = [
SpeedControlFactory,
- TimeRangeFilterFactory,
+ TimeRangeSliderFactory,
FloatingTimeDisplayFactory,
FieldSelectorFactory
];
-function TimeWidgetFactory(SpeedControl, TimeRangeFilter, FloatingTimeDisplay, FieldSelector) {
+function TimeWidgetFactory(SpeedControl, TimeRangeSlider, FloatingTimeDisplay, FieldSelector) {
class TimeWidget extends Component {
- state = {
- showSpeedControl: false
- };
-
fieldSelector = props => props.fields;
yAxisFieldsSelector = createSelector(this.fieldSelector, fields =>
fields.filter(f => f.type === 'integer' || f.type === 'real')
@@ -121,20 +118,28 @@ function TimeWidgetFactory(SpeedControl, TimeRangeFilter, FloatingTimeDisplay, F
_updateAnimationSpeed = speed => this.props.updateAnimationSpeed(this.props.index, speed);
- _toggleSpeedControl = () => this.setState({showSpeedControl: !this.state.showSpeedControl});
-
- _setFilterPlotYAxis = value => this.props.setFilterPlot(this.props.index, {yAxis: value});
-
- _updateAnimationSpeed = speed => this.props.updateAnimationSpeed(this.props.index, speed);
-
_toggleAnimation = () => this.props.toggleAnimation(this.props.index);
_onClose = () => this.props.enlargeFilter(this.props.index);
+ _setFilterPlotYAxis = value => this.props.setFilterPlot(this.props.index, {yAxis: value});
+
+ _setFilterAnimationWindow = animationWindow => {
+ this.props.setFilterAnimationWindow({id: this.props.filter.id, animationWindow});
+ };
+
render() {
- const {datasets, filter, index, readOnly, setFilter, showTimeDisplay} = this.props;
+ const {
+ datasets,
+ filter,
+ index,
+ readOnly,
+ showTimeDisplay,
+ setFilterAnimationTime,
+ animationControlProps,
+ isAnimatable
+ } = this.props;
- const {showSpeedControl} = this.state;
return (
<TimeBottomWidgetInner className="bottom-widget--inner">
<TopSectionWrapper>
@@ -161,14 +166,6 @@ function TimeWidgetFactory(SpeedControl, TimeRangeFilter, FloatingTimeDisplay, F
/>
</div>
</StyledTitle>
- <StyledTitle className="bottom-widget__speed">
- <SpeedControl
- onClick={this._toggleSpeedControl}
- showSpeedControl={showSpeedControl}
- updateAnimationSpeed={this._updateAnimationSpeed}
- speed={filter.speed}
- />
- </StyledTitle>
{!readOnly ? (
<CenterFlexbox>
<IconRoundSmall>
@@ -177,13 +174,28 @@ function TimeWidgetFactory(SpeedControl, TimeRangeFilter, FloatingTimeDisplay, F
</CenterFlexbox>
) : null}
</TopSectionWrapper>
- <TimeRangeFilter
- filter={filter}
- setFilter={value => setFilter(index, 'value', value)}
+ <TimeRangeSlider
+ id={filter.id}
+ domain={filter.domain}
+ bins={filter.bins}
+ value={filter.value}
+ plotType={filter.plotType}
+ lineChart={filter.lineChart}
+ step={filter.step}
+ speed={filter.speed}
+ histogram={filter.enlargedHistogram}
+ onChange={value => setFilterAnimationTime(index, 'value', value)}
toggleAnimation={this._toggleAnimation}
+ updateAnimationSpeed={this._updateAnimationSpeed}
+ setFilterAnimationWindow={this._setFilterAnimationWindow}
+ isEnlarged={filter.enlarged}
+ animationWindow={filter.animationWindow}
+ isAnimating={filter.isAnimating}
hideTimeTitle={showTimeDisplay}
- isAnimatable
+ animationControlProps={animationControlProps}
+ isAnimatable={isAnimatable}
/>
+
{showTimeDisplay ? <FloatingTimeDisplay currentTime={filter.value} /> : null}
</TimeBottomWidgetInner>
);
diff --git a/src/components/index.js b/src/components/index.js
index 87b8aa170..141024142 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -36,7 +36,11 @@ export {default as KeplerGl, default, injectComponents} from './container';
export {default as KeplerGlFactory} from './kepler-gl';
export {default as SidePanelFactory, PanelTitleFactory} from './side-panel';
export {default as MapContainerFactory} from './map-container';
-export {default as BottomWidgetFactory} from './bottom-widget';
+export {
+ default as BottomWidgetFactory,
+ LayerAnimationControllerFactory,
+ FilterAnimationControllerFactory
+} from './bottom-widget';
export {default as ModalContainerFactory} from './modal-container';
export {default as PlotContainerFactory} from './plot-container';
export {default as GeocoderPanelFactory} from './geocoder-panel';
@@ -106,7 +110,7 @@ export {default as ExportHtmlMapFactory} from './modals/export-map-modal/export-
export {default as AnimationControlFactory} from './common/animation-control/animation-control';
export {default as AnimationControllerFactory} from './common/animation-control/animation-controller';
export {default as SpeedControlFactory} from './common/animation-control/speed-control';
-export {default as AnimationPlaybacksFactory} from './common/animation-control/playback-controls';
+export {default as PlaybackControlsFactory} from './common/animation-control/playback-controls';
export {default as FloatingTimeDisplayFactory} from './common/animation-control/floating-time-display';
export {default as AnimationSpeedSliderFactory} from './common/animation-control/animation-speed-slider';
export {default as RangePlotFactory} from './common/range-plot';
diff --git a/src/components/side-panel/layer-panel/layer-panel.js b/src/components/side-panel/layer-panel/layer-panel.js
index c2b55b693..291335382 100644
--- a/src/components/side-panel/layer-panel/layer-panel.js
+++ b/src/components/side-panel/layer-panel/layer-panel.js
@@ -53,7 +53,7 @@ function LayerPanelFactory(LayerConfigurator, LayerPanelHeader) {
layerVisConfigChange: PropTypes.func.isRequired,
layerVisualChannelConfigChange: PropTypes.func.isRequired,
layerColorUIChange: PropTypes.func.isRequired,
- updateAnimationTime: PropTypes.func,
+ setLayerAnimationTime: PropTypes.func,
updateLayerAnimationSpeed: PropTypes.func
};
diff --git a/src/constants/action-types.d.ts b/src/constants/action-types.d.ts
index 05a5ea6ec..4a91d33b4 100644
--- a/src/constants/action-types.d.ts
+++ b/src/constants/action-types.d.ts
@@ -23,17 +23,19 @@ export type ActionType = {
REMOVE_DATASET: string;
REORDER_LAYER: string;
SET_FILTER: string;
- SET_TIME_ANIMATION: string;
+ SET_FILTER_ANIMATION_TIME: string;
+ SET_FILTER_ANIMATION_WINDOW: string;
SHOW_DATASET_TABLE: string;
UPDATE_LAYER_BLENDING: string;
UPDATE_VIS_DATA: string;
TOGGLE_FILTER_ANIMATION: string;
UPDATE_FILTER_ANIMATION_SPEED: string;
PLAY_ANIMATION: string;
- UPDATE_ANIMATION_TIME: string;
+ SET_LAYER_ANIMATION_TIME: string;
UPDATE_ANIMATION_SPEED: string;
UPDATE_LAYER_ANIMATION_SPEED: string;
TOGGLE_LAYER_CONFIG_ACTIVE: string;
+ TOGGLE_LAYER_ANIMATION: string;
ENLARGE_FILTER: string;
TOGGLE_FILTER_FEATURE: string;
SET_VISIBLE_LAYERS_FOR_MAP: string;
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index 2c2e70c88..012ef893d 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -75,16 +75,18 @@ const ActionTypes = {
REMOVE_DATASET: `${ACTION_PREFIX}REMOVE_DATASET`,
REORDER_LAYER: `${ACTION_PREFIX}REORDER_LAYER`,
SET_FILTER: `${ACTION_PREFIX}SET_FILTER`,
- SET_TIME_ANIMATION: `${ACTION_PREFIX}SET_TIME_ANIMATION`,
+ SET_FILTER_ANIMATION_TIME: `${ACTION_PREFIX}SET_FILTER_ANIMATION_TIME`,
+ SET_FILTER_ANIMATION_WINDOW: `${ACTION_PREFIX}SET_FILTER_ANIMATION_WINDOW`,
SHOW_DATASET_TABLE: `${ACTION_PREFIX}SHOW_DATASET_TABLE`,
UPDATE_LAYER_BLENDING: `${ACTION_PREFIX}UPDATE_LAYER_BLENDING`,
UPDATE_VIS_DATA: `${ACTION_PREFIX}UPDATE_VIS_DATA`,
TOGGLE_FILTER_ANIMATION: `${ACTION_PREFIX}TOGGLE_FILTER_ANIMATION`,
UPDATE_FILTER_ANIMATION_SPEED: `${ACTION_PREFIX}UPDATE_FILTER_ANIMATION_SPEED`,
PLAY_ANIMATION: `${ACTION_PREFIX}PLAY_ANIMATION`,
- UPDATE_ANIMATION_TIME: `${ACTION_PREFIX}UPDATE_ANIMATION_TIME`,
+ SET_LAYER_ANIMATION_TIME: `${ACTION_PREFIX}SET_LAYER_ANIMATION_TIME`,
UPDATE_ANIMATION_SPEED: `${ACTION_PREFIX}UPDATE_ANIMATION_SPEED`,
UPDATE_LAYER_ANIMATION_SPEED: `${ACTION_PREFIX}UPDATE_LAYER_ANIMATION_SPEED`,
+ TOGGLE_LAYER_ANIMATION: `${ACTION_PREFIX}TOGGLE_LAYER_ANIMATION`,
TOGGLE_LAYER_CONFIG_ACTIVE: `${ACTION_PREFIX}TOGGLE_LAYER_CONFIG_ACTIVE`,
ENLARGE_FILTER: `${ACTION_PREFIX}ENLARGE_FILTER`,
TOGGLE_FILTER_FEATURE: `${ACTION_PREFIX}TOGGLE_FILTER_FEATURE`,
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index 0d86b6bc4..12ae1e9b4 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -792,9 +792,34 @@ export const DEFAULT_NOTIFICATION_TOPICS = keyMirror({
// Animation
export const BASE_SPEED = 600;
export const FPS = 60;
-export const ANIMATION_TYPE = keyMirror({
- interval: null,
- continuous: null
+
+/**
+ * 4 Animation Window Types
+ * 1. free
+ * |-> |->
+ * Current time is a fixed range, animation controller calls next animation frames continuously to animation a moving window
+ * The increment id based on domain / BASE_SPEED * SPEED
+ *
+ * 2. incremental
+ * | |->
+ * Same as free, current time is a growing range, only the max value of range increment during animation.
+ * The increment is also based on domain / BASE_SPEED * SPEED
+ *
+ * 3. point
+ * o -> o
+ * Current time is a point, animation controller calls next animation frame continuously to animation a moving point
+ * The increment is based on domain / BASE_SPEED * SPEED
+ *
+ * 4. interval
+ * o ~> o
+ * Current time is a point. An array of sorted time steps need to be provided.
+ * animation controller calls next animation at a interval when the point jumps to the next step
+ */
+export const ANIMATION_WINDOW = keyMirror({
+ free: null,
+ incremental: null,
+ point: null,
+ interval: null
});
export const DEFAULT_TIME_FORMAT = 'MM/DD/YY HH:mm:ssa';
export const SPEED_CONTROL_RANGE = [0, 10];
diff --git a/src/constants/index.js b/src/constants/index.js
index fafdd6303..6d2dc9a8f 100644
--- a/src/constants/index.js
+++ b/src/constants/index.js
@@ -59,7 +59,7 @@ export {
TRIP_POINT_FIELDS,
BASE_SPEED,
FPS,
- ANIMATION_TYPE,
+ ANIMATION_WINDOW,
DEFAULT_TIME_FORMAT,
SPEED_CONTROL_RANGE,
RESOLUTIONS
diff --git a/src/localization/en.js b/src/localization/en.js
index 1a4a5cda8..772babded 100644
--- a/src/localization/en.js
+++ b/src/localization/en.js
@@ -204,7 +204,13 @@ export default {
delete: 'Delete',
timePlayback: 'Time Playback',
cloudStorage: 'Cloud Storage',
- '3DMap': '3D Map'
+ '3DMap': '3D Map',
+ animationByWindow: 'Moving Time Window',
+ animationByIncremental: 'Incremental Time Window',
+ speed: 'speed',
+ play: 'play',
+ pause: 'pause',
+ reset: 'reset'
},
toolbar: {
exportImage: 'Export Image',
diff --git a/src/reducers/vis-state-updaters.d.ts b/src/reducers/vis-state-updaters.d.ts
index 0c490d497..e6a81a00c 100644
--- a/src/reducers/vis-state-updaters.d.ts
+++ b/src/reducers/vis-state-updaters.d.ts
@@ -225,6 +225,7 @@ export type AnimationConfig = {
domain: number[] | null;
currentTime: number | null;
speed: number;
+ isAnimating?: boolean;
};
export type BaseInteraction = {
@@ -365,6 +366,10 @@ export function updateLayerBlendingUpdater(
state: VisState,
action: VisStateActions.UpdateLayerBlendingUpdaterAction
): VisState;
+export function toggleLayerAnimationUpdater(
+ state: VisState,
+ action: VisStateActions.ToggleLayerAnimationUpdaterAction
+): VisState;
export function interactionConfigChangeUpdater(
state: VisState,
action: VisStateActions.InteractionConfigChangeUpdaterAction
@@ -373,9 +378,13 @@ export function setFilterUpdater(
state: VisState,
action: VisStateActions.SetFilterUpdaterAction
): VisState;
-export function setTimeAnmationUpdater(
+export function setFilterAnimationTimeUpdater(
+ state: VisState,
+ action: VisStateActions.setFilterAnimationTimeUpdaterAction
+): VisState;
+export function setFilterAnimationWindowUpdater(
state: VisState,
- action: VisStateActions.SetTimeAnmationUpdaterAction
+ action: VisStateActions.setFilterAnimationWindowUpdaterAction
): VisState;
export function addFilterUpdater(
state: VisState,
@@ -429,9 +438,9 @@ export function updateFilterAnimationSpeedUpdater(
state: VisState,
action: VisStateActions.UpdateFilterAnimationSpeedUpdaterAction
): VisState;
-export function updateAnimationTimeUpdater(
+export function setLayerAnimationTimeUpdater(
state: VisState,
- action: VisStateActions.UpdateAnimationTimeUpdaterAction
+ action: VisStateActions.setLayerAnimationTimeUpdaterAction
): VisState;
export function updateLayerAnimationSpeedUpdater(
state: VisState,
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 1e1217476..377cdeebf 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -133,7 +133,8 @@ const visStateUpdaters = null;
export const DEFAULT_ANIMATION_CONFIG = {
domain: null,
currentTime: null,
- speed: 1
+ speed: 1,
+ isAnimating: false
};
/** @type {Editor} */
@@ -521,13 +522,32 @@ export function layerVisConfigChangeUpdater(state, action) {
/**
* Update filter property
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').setTimeAnmationUpdater}
+ * @type {typeof import('./vis-state-updaters').setFilterAnimationTimeUpdater}
* @public
*/
-export function setTimeAnmationUpdater(state, action) {
+export function setFilterAnimationTimeUpdater(state, action) {
return setFilterUpdater(state, action);
}
+/**
+ * Update filter animation window
+ * @memberof visStateUpdaters
+ * @type {typeof import('./vis-state-updaters').setFilterAnimationWindowUpdater}
+ * @public
+ */
+export function setFilterAnimationWindowUpdater(state, {id, animationWindow}) {
+ return {
+ ...state,
+ filters: state.filters.map(f =>
+ f.id === id
+ ? {
+ ...f,
+ animationWindow
+ }
+ : f
+ )
+ };
+}
/**
* Update filter property
* @memberof visStateUpdaters
@@ -729,6 +749,18 @@ export const toggleFilterAnimationUpdater = (state, action) => ({
filters: state.filters.map((f, i) => (i === action.idx ? {...f, isAnimating: !f.isAnimating} : f))
});
+/**
+ * @memberof visStateUpdaters
+ * @type {typeof import('./vis-state-updaters').toggleLayerAnimationUpdater}
+ * @public
+ */
+export const toggleLayerAnimationUpdater = state => ({
+ ...state,
+ animationConfig: {
+ ...state.animationConfig,
+ isAnimating: !state.animationConfig.isAnimating
+ }
+});
/**
* Change filter animation speed
* @memberof visStateUpdaters
@@ -743,11 +775,11 @@ export const updateFilterAnimationSpeedUpdater = (state, action) => ({
/**
* Reset animation config current time to a specified value
* @memberof visStateUpdaters
- * @type {typeof import('./vis-state-updaters').updateAnimationTimeUpdater}
+ * @type {typeof import('./vis-state-updaters').setLayerAnimationTimeUpdater}
* @public
*
*/
-export const updateAnimationTimeUpdater = (state, {value}) => ({
+export const setLayerAnimationTimeUpdater = (state, {value}) => ({
...state,
animationConfig: {
...state.animationConfig,
@@ -779,14 +811,16 @@ export const updateLayerAnimationSpeedUpdater = (state, {speed}) => {
* @public
*/
export const enlargeFilterUpdater = (state, action) => {
- const isEnlarged = state.filters[action.idx].enlarged;
-
return {
...state,
- filters: state.filters.map((f, i) => {
- f.enlarged = !isEnlarged && i === action.idx;
- return f;
- })
+ filters: state.filters.map((f, i) =>
+ i === action.idx
+ ? {
+ ...f,
+ enlarged: !f.enlarged
+ }
+ : f
+ )
};
};
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.js
index 967b36c7c..5574ff82b 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.js
@@ -51,6 +51,8 @@ const actionHandler = {
[ActionTypes.LAYER_COLOR_UI_CHANGE]: visStateUpdaters.layerColorUIChangeUpdater,
+ [ActionTypes.TOGGLE_LAYER_ANIMATION]: visStateUpdaters.toggleLayerAnimationUpdater,
+
[ActionTypes.LOAD_FILES]: visStateUpdaters.loadFilesUpdater,
[ActionTypes.LOAD_FILES_ERR]: visStateUpdaters.loadFilesErrUpdater,
@@ -77,7 +79,9 @@ const actionHandler = {
[ActionTypes.SET_FILTER]: visStateUpdaters.setFilterUpdater,
- [ActionTypes.SET_TIME_ANIMATION]: visStateUpdaters.setTimeAnmationUpdater,
+ [ActionTypes.SET_FILTER_ANIMATION_TIME]: visStateUpdaters.setFilterAnimationTimeUpdater,
+
+ [ActionTypes.SET_FILTER_ANIMATION_WINDOW]: visStateUpdaters.setFilterAnimationWindowUpdater,
[ActionTypes.SET_FILTER_PLOT]: visStateUpdaters.setFilterPlotUpdater,
@@ -89,7 +93,7 @@ const actionHandler = {
[ActionTypes.UPDATE_FILTER_ANIMATION_SPEED]: visStateUpdaters.updateFilterAnimationSpeedUpdater,
- [ActionTypes.UPDATE_ANIMATION_TIME]: visStateUpdaters.updateAnimationTimeUpdater,
+ [ActionTypes.SET_LAYER_ANIMATION_TIME]: visStateUpdaters.setLayerAnimationTimeUpdater,
[ActionTypes.UPDATE_LAYER_ANIMATION_SPEED]: visStateUpdaters.updateLayerAnimationSpeedUpdater,
diff --git a/src/schemas/vis-state-schema.js b/src/schemas/vis-state-schema.js
index ede3c8855..1c1b28070 100644
--- a/src/schemas/vis-state-schema.js
+++ b/src/schemas/vis-state-schema.js
@@ -661,6 +661,7 @@ export class SplitMapsSchema extends Schema {
export const filterPropsV1 = {
...filterPropsV0,
plotType: null,
+ animationWindow: null,
yAxis: new DimensionFieldSchema({
version: VERSIONS.v1,
key: 'yAxis',
diff --git a/src/utils/filter-utils.js b/src/utils/filter-utils.js
index d34665c52..c7f800521 100644
--- a/src/utils/filter-utils.js
+++ b/src/utils/filter-utils.js
@@ -24,7 +24,7 @@ import get from 'lodash.get';
import booleanWithin from '@turf/boolean-within';
import {point as turfPoint} from '@turf/helpers';
import {Decimal} from 'decimal.js';
-import {ALL_FIELD_TYPES, FILTER_TYPES} from 'constants/default-settings';
+import {ALL_FIELD_TYPES, FILTER_TYPES, ANIMATION_WINDOW} from 'constants/default-settings';
import {maybeToDate, notNullorUndefined, unique, timeToUnixMilli} from './data-utils';
import * as ScaleUtils from './data-scale-utils';
import {LAYER_TYPES} from 'layers/types';
@@ -104,6 +104,7 @@ export const DEFAULT_FILTER_STRUCTURE = {
fixedDomain: false,
enlarged: false,
isAnimating: false,
+ animationWindow: ANIMATION_WINDOW.free,
speed: 1,
// field specific
diff --git a/test/browser/components/bottom-widget-test.js b/test/browser/components/bottom-widget-test.js
index b2ce78c8f..444aa21bb 100644
--- a/test/browser/components/bottom-widget-test.js
+++ b/test/browser/components/bottom-widget-test.js
@@ -21,12 +21,13 @@
import React from 'react';
import test from 'tape';
import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
-import BottomWidgetFactory from 'components/bottom-widget';
+import {BottomWidgetFactory, TimeWidgetFactory, AnimationControlFactory} from 'components';
import {appInjector} from 'components/container';
+import * as VisStateActions from 'actions/vis-state-actions';
const BottomWidget = appInjector.get(BottomWidgetFactory);
-
-import * as VisStateActions from 'actions/vis-state-actions';
+const TimeWidget = appInjector.get(TimeWidgetFactory);
+const AnimationControl = appInjector.get(AnimationControlFactory);
// mock state
import {InitialState} from 'test/helpers/mock-state';
@@ -45,7 +46,6 @@ const defaultProps = {
test('Components -> BottomWidget.mount -> initial state', t => {
let wrapper;
-
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
@@ -53,10 +53,9 @@ test('Components -> BottomWidget.mount -> initial state', t => {
</IntlWrapper>
);
}, 'BottomWidget should not fail without props');
- t.equal(
- wrapper.find('div').length,
- 0,
- 'should not render anything when layers and filters are empty'
- );
+
+ t.equal(wrapper.find(TimeWidget).length, 0, 'should not render');
+ t.equal(wrapper.find(AnimationControl).length, 0, 'should not render');
+
t.end();
});
diff --git a/test/browser/components/common/animation-control-test.js b/test/browser/components/common/animation-control-test.js
new file mode 100644
index 000000000..82640f5e7
--- /dev/null
+++ b/test/browser/components/common/animation-control-test.js
@@ -0,0 +1,72 @@
+// Copyright (c) 2020 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 React from 'react';
+import test from 'tape';
+import sinon from 'sinon';
+import {mountWithTheme} from 'test/helpers/component-utils';
+import {AnimationControlFactory, PlaybackControlsFactory} from 'components';
+import {appInjector} from 'components/container';
+import {StateWTripGeojson} from 'test/helpers/mock-state';
+import {
+ AnimationWindowControl,
+ IconButton
+} from 'components/common/animation-control/playback-controls';
+
+const AnimationControl = appInjector.get(AnimationControlFactory);
+const PlaybackControls = appInjector.get(PlaybackControlsFactory);
+
+test('Components -> AnimationControl.render', t => {
+ t.doesNotThrow(() => {
+ mountWithTheme(<AnimationControl />);
+ }, 'Show not fail without props');
+
+ t.end();
+});
+
+test('Components -> AnimationControl.render with props', t => {
+ let wrapper;
+ const toggleAnimation = sinon.spy();
+ const setLayerAnimationTime = sinon.spy();
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <AnimationControl
+ isAnimatable
+ setLayerAnimationTime={setLayerAnimationTime}
+ toggleAnimation={toggleAnimation}
+ animationConfig={StateWTripGeojson.visState.animationConfig}
+ />
+ );
+ }, 'Show not fail without props');
+
+ t.equal(
+ wrapper.find(AnimationWindowControl).length,
+ 0,
+ 'should not render AnimationWindowControl'
+ );
+ t.ok(wrapper.find(PlaybackControls), 'should render PlaybackControls');
+
+ wrapper
+ .find(IconButton)
+ .at(2)
+ .simulate('click');
+ t.ok(toggleAnimation.calledOnce, 'should call toggleAnimation');
+ t.end();
+});
diff --git a/test/browser/components/common/index.js b/test/browser/components/common/index.js
index 9ebd17d76..e625b4e2b 100644
--- a/test/browser/components/common/index.js
+++ b/test/browser/components/common/index.js
@@ -23,3 +23,4 @@ import './color-legend-test';
import './range-slider-test';
import './item-selector-test';
import './range-plot-test';
+import './animation-control-test';
diff --git a/test/fixtures/geojson.js b/test/fixtures/geojson.js
index 3bc02b9bd..d2263c07b 100644
--- a/test/fixtures/geojson.js
+++ b/test/fixtures/geojson.js
@@ -419,6 +419,7 @@ export const geoJsonTripFilterProps = {
export const mergedTripFilter = {
...geoJsonTripFilterProps,
+ animationWindow: 'free',
dataId: [geoJsonDataId],
freeze: true,
id: 'TRIPS-3',
@@ -445,6 +446,7 @@ export const geoJsonRateFilterProps = {
export const mergedRateFilter = {
...geoJsonRateFilterProps,
+ animationWindow: 'free',
name: ['RATE'],
dataId: [geoJsonDataId],
freeze: true,
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index 2181b2c09..4710a6db8 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -888,6 +888,7 @@ export const mergedFilters = [
id: 'vxzfwyg2v',
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
name: ['song_name'],
type: 'multiSelect',
fieldIdx: [0],
@@ -907,6 +908,7 @@ export const mergedFilters = [
id: 'fo9tjm2unl',
enlarged: true,
isAnimating: false,
+ animationWindow: 'free',
name: ['timestamp_local'],
type: 'timeRange',
fieldIdx: [3],
@@ -944,6 +946,7 @@ export const mergedFilters = [
value: false,
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
fieldIdx: [10],
domain: [true, false],
fieldType: 'boolean',
@@ -968,6 +971,7 @@ export const mergedFilters = [
histogram: ['not tested'],
enlargedHistogram: ['not tested'],
isAnimating: false,
+ animationWindow: 'free',
fieldIdx: [9],
domain: [78, 694],
step: 1,
@@ -984,6 +988,7 @@ export const mergedFilters = [
id: '5nfmxjjzl',
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
name: ['ZIP_CODE'],
type: 'range',
fieldIdx: [2],
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index a742a5437..0bd505b23 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -839,6 +839,7 @@ export const mergedFilters = [
id: '9ca0l7p2a',
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
name: ['zip_area'],
type: 'range',
fieldIdx: [3],
diff --git a/test/fixtures/test-csv-data.js b/test/fixtures/test-csv-data.js
index 091b610bf..1f7a67696 100644
--- a/test/fixtures/test-csv-data.js
+++ b/test/fixtures/test-csv-data.js
@@ -790,6 +790,7 @@ export const timeFilterProps = {
export const mergedTimeFilter = {
...timeFilterProps,
+ animationWindow: 'free',
dataId: [dataId],
freeze: true,
id: 'time-0',
@@ -824,6 +825,7 @@ export const epochFilterProps = {
// value set mockStateWithFilters 1472700000000, 1472760000000
export const mergedEpochFilter = {
...epochFilterProps,
+ animationWindow: 'free',
dataId: [dataId],
freeze: true,
id: 'epoch-1',
@@ -852,6 +854,7 @@ export const dateFilterProps = {
export const mergedDateFilter = {
...dateFilterProps,
+ animationWindow: 'free',
dataId: [dataId],
freeze: true,
id: 'date-2',
diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.js
index 5c8eb83c8..1aa9b51ea 100644
--- a/test/fixtures/test-hex-id-data.js
+++ b/test/fixtures/test-hex-id-data.js
@@ -164,6 +164,7 @@ export const mergedFilters = [
plotType: 'histogram',
yAxis: null,
isAnimating: false,
+ animationWindow: 'free',
fieldIdx: [1],
domain: [1, 76],
step: 0.01,
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 3f252aef9..d4f848f59 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -1514,6 +1514,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA -> mergeFilters', t => {
const expectedFilter = {
...expectedFilterProps,
+ animationWindow: 'free',
dataId: ['smoothie'],
fieldIdx: [0],
id: '38chejr',
@@ -1794,6 +1795,7 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
value: null,
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
plotType: 'histogram',
yAxis: null,
speed: 1,
@@ -1823,6 +1825,7 @@ test('#visStateReducer -> setFilter.dynamicDomain & cpu', t => {
value: [],
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
fieldType: 'date',
plotType: 'histogram',
yAxis: null,
@@ -1974,6 +1977,7 @@ test('#visStateReducer -> SET_FILTER.name', t => {
fixedDomain: false,
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
speed: 1,
name: ['ZIP_CODE'],
type: 'range',
@@ -2064,6 +2068,7 @@ function testSetFilterDynamicDomainGPU(t, setFilter) {
histogram: [],
enlargedHistogram: [],
isAnimating: false,
+ animationWindow: 'free',
fieldType: 'integer',
typeOptions: ['range'],
plotType: 'histogram',
@@ -2149,8 +2154,23 @@ test('#visStateReducer -> setFilter.dynamicDomain & gpu', t => {
t.end();
});
-test('#visStateReducer -> setTimeAnmation', t => {
- testSetFilterDynamicDomainGPU(t, VisStateActions.setTimeAnmation);
+test('#visStateReducer -> SET_FILTER_ANIMATION_TIME', t => {
+ testSetFilterDynamicDomainGPU(t, VisStateActions.setFilterAnimationTime);
+ t.end();
+});
+
+test('#visStateReducer -> SET_FILTER_ANIMATION_WINDOW', t => {
+ const initialState = StateWFilters.visState;
+ const nextState = reducer(
+ initialState,
+ VisStateActions.setFilterAnimationWindow({
+ id: initialState.filters[0].id,
+ animationWindow: 'incremental'
+ })
+ );
+
+ t.equal(nextState.filters[0].animationWindow, 'incremental', 'should update ANIMATIONWINDOW');
+
t.end();
});
@@ -2251,6 +2271,7 @@ test('#visStateReducer -> setFilter.fixedDomain & DynamicDomain & gpu & cpu', t
enlargedHistogram: [],
enlarged: true,
isAnimating: false,
+ animationWindow: 'free',
fieldType: 'timestamp',
gpu: true,
gpuChannel: [0]
@@ -2486,6 +2507,7 @@ test('#visStateReducer -> SET_FILTER_PLOT', t => {
enlargedHistogram: [],
enlarged: true,
isAnimating: false,
+ animationWindow: 'free',
fieldType: 'timestamp',
gpu: true,
gpuChannel: [0]
@@ -2997,16 +3019,16 @@ test('#visStateReducer -> SPLIT_MAP: HIDE LAYER', t => {
t.end();
});
-test('#visStateReducer -> UPDATE_ANIMATION_TIME', t => {
- const initialState = StateWTripGeojson;
- const newState = reducer(initialState, VisStateActions.updateAnimationTime(1000));
+test('#visStateReducer -> SET_LAYER_ANIMATION_TIME', t => {
+ const initialState = StateWTripGeojson.visState;
+ const newState = reducer(initialState, VisStateActions.setLayerAnimationTime(1000));
t.equal(newState.animationConfig.currentTime, 1000, 'should update animation time');
t.end();
});
test('#visStateReducer -> UPDATE_LAYER_ANIMATION_SPEED', t => {
- const initialState = StateWTripGeojson;
+ const initialState = StateWTripGeojson.visState;
const newState = reducer(initialState, VisStateActions.updateLayerAnimationSpeed(1.23));
t.equal(newState.animationConfig.speed, 1.23, 'should update animation speed');
@@ -3014,6 +3036,13 @@ test('#visStateReducer -> UPDATE_LAYER_ANIMATION_SPEED', t => {
t.end();
});
+test('#visStateReducer -> TOGGLE_LAYER_ANIMATION', t => {
+ const initialState = StateWTripGeojson.visState;
+ const newState = reducer(initialState, VisStateActions.toggleLayerAnimation());
+ t.equal(newState.animationConfig.isAnimating, true, 'should update animationConfig');
+ t.end();
+});
+
test('#visStateReducer -> INTERACTION_CONFIG_CHANGE', t => {
const defaultInteractionConfig = getDefaultInteraction();
@@ -3755,6 +3784,7 @@ test('#visStateReducer -> POLYGON: Create polygon filter', t => {
fixedDomain: true,
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
speed: 1,
name: [],
type: 'polygon',
@@ -3883,6 +3913,7 @@ test('#visStateReducer -> POLYGON: Toggle filter feature', t => {
fixedDomain: true,
enlarged: false,
isAnimating: false,
+ animationWindow: 'free',
speed: 1,
name: [],
type: 'polygon',
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index 949e31dd4..503125b1a 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -100,7 +100,8 @@ test('#visStateSchema -> v1 -> save load filters', t => {
value: [1474606800000, 1474617600000],
enlarged: true,
plotType: 'histogram',
- yAxis: null
+ yAxis: null,
+ animationWindow: 'free'
},
{
dataId: [testGeoJsonDataId],
@@ -110,7 +111,8 @@ test('#visStateSchema -> v1 -> save load filters', t => {
value: ['a'],
enlarged: false,
plotType: 'histogram',
- yAxis: null
+ yAxis: null,
+ animationWindow: 'free'
}
];