Skip to content

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

[feat] Hubble gl integration (#1899)

Igor Dykhta6c51a2aed9b1
diff --git a/.gitignore b/.gitignore
index ea1e126db..b7b84a133 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@ package-lock.json
/index.html
npm-debug.log
+.history/
.pnp.*
.yarn/*
diff --git a/examples/demo-app/package.json b/examples/demo-app/package.json
index 15abf2a14..edc22b6a5 100644
--- a/examples/demo-app/package.json
+++ b/examples/demo-app/package.json
@@ -7,6 +7,7 @@
"start-local-deck": "webpack-dev-server --mode development --env.es6 --env.deck --progress --hot --open",
"start-local-deck-src": "webpack-dev-server --mode development --env.es6 --env.deck_src --progress --hot --open",
"start-local-loaders-src": "webpack-dev-server --mode development --env.es6 --env.loaders_src --progress --hot --open",
+ "start-local-hubble-src": "webpack-dev-server --mode development --env.es6 --env.hubble_src --progress --hot --open",
"start-local-https": "webpack-dev-server --mode development --https --env.es6 --progress --hot --open"
},
"dependencies": {
diff --git a/examples/webpack.config.local.js b/examples/webpack.config.local.js
index 2a51b535c..4a8a17169 100644
--- a/examples/webpack.config.local.js
+++ b/examples/webpack.config.local.js
@@ -45,6 +45,9 @@ const EXTERNAL_DECK_SRC = resolve(__dirname, '../../deck.gl');
// For debugging loaders.gl, load loaders.gl from external loaders.gl directory
const EXTERNAL_LOADERS_SRC = resolve(__dirname, '../../loaders.gl');
+// For debugging hubble.gl, load hubble.gl from external hubble.gl directory
+const EXTERNAL_HUBBLE_SRC = resolve(__dirname, '../../hubble.gl');
+
// Support for hot reloading changes to the deck.gl library:
function makeLocalDevConfig(env, EXAMPLE_DIR = LIB_DIR, externals = {}) {
const resolveAlias = {
@@ -57,18 +60,22 @@ function makeLocalDevConfig(env, EXAMPLE_DIR = LIB_DIR, externals = {}) {
'react-intl': `${NODE_MODULES_DIR}/react-intl`
};
+ // Combine flags
+ const useLocalDeck = env.deck || env.hubble_src;
+ const useRepoDeck = env.deck_src;
+
// resolve deck.gl from local dir
- if (env.deck || env.deck_src) {
+ if (useLocalDeck || useRepoDeck) {
// Load deck.gl from root node_modules
// if env.deck_src Load deck.gl from deck.gl/modules/main/src folder parallel to kepler.gl
- resolveAlias['deck.gl'] = env.deck
+ resolveAlias['deck.gl'] = useLocalDeck
? `${NODE_MODULES_DIR}/deck.gl/src`
: `${EXTERNAL_DECK_SRC}/modules/main/src`;
// if env.deck Load @deck.gl modules from root node_modules/@deck.gl
// if env.deck_src Load @deck.gl modules from deck.gl/modules folder parallel to kepler.gl
externals['deck.gl'].forEach(mdl => {
- resolveAlias[`@deck.gl/${mdl}`] = env.deck
+ resolveAlias[`@deck.gl/${mdl}`] = useLocalDeck
? `${NODE_MODULES_DIR}/@deck.gl/${mdl}/src`
: `${EXTERNAL_DECK_SRC}/modules/${mdl}/src`;
});
@@ -76,7 +83,7 @@ function makeLocalDevConfig(env, EXAMPLE_DIR = LIB_DIR, externals = {}) {
['luma.gl', 'probe.gl', 'loaders.gl'].forEach(name => {
// if env.deck Load ${name} from root node_modules
// if env.deck_src Load ${name} from deck.gl/node_modules folder parallel to kepler.gl
- resolveAlias[name] = env.deck
+ resolveAlias[name] = useLocalDeck
? `${NODE_MODULES_DIR}/${name}/src`
: name === 'probe.gl'
? `${EXTERNAL_DECK_SRC}/node_modules/${name}/src`
@@ -85,7 +92,7 @@ function makeLocalDevConfig(env, EXAMPLE_DIR = LIB_DIR, externals = {}) {
// if env.deck Load @${name} modules from root node_modules/@${name}
// if env.deck_src Load @${name} modules from deck.gl/node_modules/@${name} folder parallel to kepler.gl`
externals[name].forEach(mdl => {
- resolveAlias[`@${name}/${mdl}`] = env.deck
+ resolveAlias[`@${name}/${mdl}`] = useLocalDeck
? `${NODE_MODULES_DIR}/@${name}/${mdl}/src`
: `${EXTERNAL_DECK_SRC}/node_modules/@${name}/${mdl}/src`;
});
@@ -98,6 +105,12 @@ function makeLocalDevConfig(env, EXAMPLE_DIR = LIB_DIR, externals = {}) {
});
}
+ if (env.hubble_src) {
+ externals['hubble.gl'].forEach(mdl => {
+ resolveAlias[`@hubble.gl/${mdl}`] = `${EXTERNAL_HUBBLE_SRC}/modules/${mdl}/src`;
+ });
+ }
+
logStep(`resolve.alias:\n ${JSON.stringify(resolveAlias, null, 2)}`);
// load deck.gl from
@@ -157,6 +170,7 @@ function makeBabelRule(env, exampleDir) {
join(EXTERNAL_DECK_SRC, 'node_modules/@loaders.gl')
]
: []),
+ ...(env.hubble_src ? [join(EXTERNAL_HUBBLE_SRC, 'modules')] : []),
join(exampleDir, 'src'),
SRC_DIR
],
@@ -172,6 +186,7 @@ function makeBabelRule(env, exampleDir) {
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-export-namespace-from',
+ '@babel/plugin-transform-runtime',
[
'search-and-replace',
{
@@ -232,8 +247,8 @@ function addBabelSettings(env, config, exampleDir) {
}
module.exports = (exampleConfig, exampleDir) => env => {
- // find all @deck.gl @luma.gl @loaders.gl modules
- const modules = ['@deck.gl', '@loaders.gl', '@luma.gl', '@probe.gl'];
+ // find all @deck.gl @luma.gl @loaders.gl @hubble.gl modules
+ const modules = ['@deck.gl', '@loaders.gl', '@luma.gl', '@probe.gl', '@hubble.gl'];
const loadAllDirs = modules.map(
dir =>
new Promise(function readDir(success, reject) {
@@ -252,7 +267,8 @@ module.exports = (exampleConfig, exampleDir) => env => {
'deck.gl': results[0],
'loaders.gl': results[1],
'luma.gl': results[2],
- 'probe.gl': results[3]
+ 'probe.gl': results[3],
+ 'hubble.gl': results[4]
}))
.then(externals => {
const config = addLocalDevSettings(env, exampleConfig, exampleDir, externals);
diff --git a/src/actions/action-types.ts b/src/actions/action-types.ts
index 7edef9050..13c7eb415 100644
--- a/src/actions/action-types.ts
+++ b/src/actions/action-types.ts
@@ -152,6 +152,9 @@ const ActionTypes = {
SET_EXPORT_IMAGE_ERROR: `${ACTION_PREFIX}SET_EXPORT_IMAGE_ERROR`,
CLEANUP_EXPORT_IMAGE: `${ACTION_PREFIX}CLEANUP_EXPORT_IMAGE`,
+ // uiState > export video (state only, via hubble.gl)
+ SET_EXPORT_VIDEO_SETTING: `${ACTION_PREFIX}SET_EXPORT_VIDEO_SETTING`,
+
// uiState > export data
SET_EXPORT_SELECTED_DATASET: `${ACTION_PREFIX}SET_EXPORT_SELECTED_DATASET`,
SET_EXPORT_DATA_TYPE: `${ACTION_PREFIX}SET_EXPORT_DATA_TYPE`,
diff --git a/src/components/common/animation-control/animation-window-control.tsx b/src/components/common/animation-control/animation-window-control.tsx
new file mode 100644
index 000000000..0f8fbdd0c
--- /dev/null
+++ b/src/components/common/animation-control/animation-window-control.tsx
@@ -0,0 +1,68 @@
+import React, {useCallback} from 'react';
+import {FormattedMessage} from 'localization';
+import {ReactComponentLike} from 'prop-types';
+import IconButton from '../icon-button';
+import {Tooltip} from 'components/common/styled-components';
+
+export interface AnimationItem {
+ id: string;
+ icon: ReactComponentLike;
+ tooltip: string;
+}
+interface AnimationWindowControlProps {
+ animationWindow?: string;
+ setFilterAnimationWindow: (id: string) => void;
+ toggleAnimationWindowControl: () => void;
+ height?: string;
+ animationItems: {[key: string]: AnimationItem};
+ btnStyle;
+ showAnimationWindowControl: boolean;
+}
+
+function AnimationWindowControlFactory(): React.FC<AnimationWindowControlProps> {
+ const AnimationWindowControl = ({
+ animationWindow,
+ setFilterAnimationWindow,
+ toggleAnimationWindowControl,
+ height,
+ animationItems,
+ btnStyle = {},
+ showAnimationWindowControl
+ }: AnimationWindowControlProps) => {
+ const onSelectAnimationControl = useCallback(
+ item => {
+ setFilterAnimationWindow(item.id);
+ toggleAnimationWindowControl();
+ },
+ [setFilterAnimationWindow, toggleAnimationWindowControl]
+ );
+
+ return showAnimationWindowControl ? (
+ <div className="animation-window-control">
+ {Object.values(animationItems)
+ .filter(item => item.id !== animationWindow)
+ .map(item => (
+ <IconButton
+ key={item.id}
+ data-tip
+ data-for={`${item.id}-tooltip`}
+ className="playback-control-button"
+ onClick={() => onSelectAnimationControl(item)}
+ {...btnStyle}
+ >
+ <item.icon height={height} />
+ {item.tooltip ? (
+ <Tooltip id={`${item.id}-tooltip`} effect="solid" place="top">
+ <FormattedMessage id={item.tooltip} />
+ </Tooltip>
+ ) : null}
+ </IconButton>
+ ))}
+ </div>
+ ) : null;
+ };
+
+ return AnimationWindowControl;
+}
+
+export default AnimationWindowControlFactory;
diff --git a/src/components/common/animation-control/play-control.tsx b/src/components/common/animation-control/play-control.tsx
new file mode 100644
index 000000000..0772a273d
--- /dev/null
+++ b/src/components/common/animation-control/play-control.tsx
@@ -0,0 +1,44 @@
+import React from 'react';
+import classnames from 'classnames';
+import {FormattedMessage} from 'localization';
+import {Tooltip} from 'components/common/styled-components';
+import IconButton from '../icon-button';
+
+const DELAY_SHOW = 500;
+
+function PlayControlFactory() {
+ const PlayControl = ({
+ showAnimationWindowControl,
+ isAnimating,
+ pauseAnimation,
+ startAnimation,
+ isSpeedControlVisible,
+ btnStyle,
+ playbackIcons,
+ buttonHeight
+ }) => {
+ return showAnimationWindowControl ? null : (
+ <IconButton
+ data-tip
+ data-for="animate-play-pause"
+ className={classnames('playback-control-button', {active: isAnimating})}
+ onClick={isAnimating ? pauseAnimation : startAnimation}
+ hide={isSpeedControlVisible}
+ {...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>
+ );
+ };
+
+ return PlayControl;
+}
+
+export default PlayControlFactory;
diff --git a/src/components/common/animation-control/playback-controls.tsx b/src/components/common/animation-control/playback-controls.tsx
index 50d4289f6..15bb68342 100644
--- a/src/components/common/animation-control/playback-controls.tsx
+++ b/src/components/common/animation-control/playback-controls.tsx
@@ -21,15 +21,15 @@
import React, {useState, useCallback} from 'react';
import styled from 'styled-components';
import classnames from 'classnames';
-import {FormattedMessage} from '@kepler.gl/localization';
-import {Button, Tooltip, ButtonProps} from 'components/common/styled-components';
-import AnimationSpeedSliderFactory from './animation-speed-slider';
-import {Reset, Play, Pause, Rocket, AnchorWindow, FreeWindow} from 'components/common/icons';
+import {Reset, Play, Pause, Save, Rocket, AnchorWindow, FreeWindow} from 'components/common/icons';
import {ANIMATION_WINDOW} from '@kepler.gl/constants';
-import {preciseRound} from 'utils/data-utils';
-import {ReactComponentLike} from 'prop-types';
+import AnimationSpeedSliderFactory from './animation-speed-slider';
+import WindowActionControlFactory from './window-action-control';
+import AnimationWindowControlFactory, {AnimationItem} from './animation-window-control';
+import ResetControlFactory from './reset-control';
+import PlayControlFactory from './play-control';
+import SpeedControlFactory from './speed-control';
-const DELAY_SHOW = 500;
const DEFAULT_BUTTON_HEIGHT = '20px';
const StyledAnimationControls = styled.div`
@@ -42,52 +42,20 @@ const StyledAnimationControls = styled.div`
}
`;
-const StyledSpeedControl = styled.div`
- display: flex;
- align-items: center;
-
- .animation-control__speed-slider {
- left: 0;
- }
-`;
-
-interface IconButtonProps extends ButtonProps {
- collapsed?: boolean;
-}
-
-export const IconButton = styled(Button)<IconButtonProps>`
- 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;
- }
- &.active {
- background-color: ${props => props.theme.playbackButtonActBgColor};
- }
-`;
-
-function nop() {}
const DEFAULT_ICONS = {
/* eslint-disable react/display-name */
reset: _ => <Reset height="18px" />,
play: _ => <Play height="18px" />,
pause: _ => <Pause height="18px" />,
+ export: _ => <Save height="18px" />,
/* eslint-enable react/display-name */
speed: Rocket,
animationFree: FreeWindow,
animationIncremental: AnchorWindow
};
+function nop() {}
+
const DEFAULT_ANIMATE_ITEMS = {
[ANIMATION_WINDOW.free]: {
id: ANIMATION_WINDOW.free,
@@ -100,56 +68,6 @@ const DEFAULT_ANIMATE_ITEMS = {
tooltip: 'tooltip.animationByIncremental'
}
};
-
-interface AnimationItem {
- id: string;
- icon: ReactComponentLike;
- tooltip: string;
-}
-
-interface AnimationWindowControlProps {
- onClick?: (id: string) => void;
- selected?: string;
- onHide: () => void;
- height?: string;
- animationItems: {[key: string]: AnimationItem};
- btnStyle;
-}
-
-export const AnimationWindowControl: React.FC<AnimationWindowControlProps> = ({
- 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>
-);
-
interface PlaybackControlsProps {
isAnimatable?: boolean;
isAnimating?: boolean;
@@ -165,28 +83,51 @@ interface PlaybackControlsProps {
animationItems?: {[key: string]: AnimationItem};
buttonStyle?: string;
buttonHeight?: string;
+ playbackActionItems?: any[];
}
-PlaybackControlsFactory.deps = [AnimationSpeedSliderFactory];
+PlaybackControlsFactory.deps = [
+ // keeping this for backwards compatibility but we can decide to drop it later
+ AnimationSpeedSliderFactory,
+ WindowActionControlFactory,
+ AnimationWindowControlFactory,
+ ResetControlFactory,
+ PlayControlFactory
+];
+
function PlaybackControlsFactory(
- AnimationSpeedSlider: ReturnType<typeof AnimationSpeedSliderFactory>
+ AnimationSpeedSlider: ReturnType<typeof AnimationSpeedSliderFactory>,
+ WindowActionControl,
+ AnimationWindowControl,
+ ResetControl,
+ PlayControl
) {
+ const PLAYBACK_CONTROLS_DEFAULT_ACTION_COMPONENTS = [
+ WindowActionControl,
+ AnimationWindowControl,
+ // backwards compatible
+ SpeedControlFactory(AnimationSpeedSlider),
+ ResetControl,
+ PlayControl
+ ];
+
// eslint-disable-next-line complexity
const PlaybackControls: React.FC<PlaybackControlsProps> = ({
- isAnimatable = true,
+ isAnimatable,
isAnimating,
width,
speed,
- animationWindow = ANIMATION_WINDOW.free,
+ animationWindow,
setFilterAnimationWindow,
updateAnimationSpeed,
- pauseAnimation = nop,
- resetAnimation = nop,
- startAnimation = nop,
- playbackIcons = DEFAULT_ICONS,
- animationItems = DEFAULT_ANIMATE_ITEMS,
- buttonStyle = 'secondary',
- buttonHeight = DEFAULT_BUTTON_HEIGHT
+ pauseAnimation,
+ resetAnimation,
+ startAnimation,
+ playbackIcons,
+ animationItems,
+ buttonStyle,
+ buttonHeight,
+ playbackActionItems = []
}) => {
const [isSpeedControlVisible, toggleSpeedControl] = useState(false);
const [showAnimationWindowControl, setShowAnimationWindowControl] = useState(false);
@@ -205,6 +146,7 @@ function PlaybackControlsFactory(
window.setTimeout(() => toggleSpeedControl(false), 200);
}
}, [isSpeedControlVisible, toggleSpeedControl]);
+
return (
<StyledAnimationControls
className={classnames('playback-controls', {
@@ -213,103 +155,44 @@ function PlaybackControlsFactory(
style={{width: `${width}px`}}
>
{/** Window */}
- {setFilterAnimationWindow ? (
- <IconButton
- data-tip
- data-for="animate-window"
- className={classnames('playback-control-button', {active: showAnimationWindowControl})}
- onClick={toggleAnimationWindowControl}
- {...btnStyle}
- >
- {(() => {
- if (animationItems[animationWindow]) {
- const WindowIcon = animationItems[animationWindow].icon;
- return <WindowIcon 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}
+ {playbackActionItems.map((ActionComponent, index) => (
+ <ActionComponent
+ key={index}
+ toggleAnimationWindowControl={toggleAnimationWindowControl}
+ showAnimationWindowControl={showAnimationWindowControl}
btnStyle={btnStyle}
+ hideAndShowSpeedControl={hideAndShowSpeedControl}
animationItems={animationItems}
+ animationWindow={animationWindow}
+ buttonHeight={buttonHeight}
+ setFilterAnimationWindow={setFilterAnimationWindow}
+ updateAnimationSpeed={updateAnimationSpeed}
+ isAnimating={isAnimating}
+ pauseAnimation={pauseAnimation}
+ resetAnimation={resetAnimation}
+ startAnimation={startAnimation}
+ playbackIcons={playbackIcons}
+ isSpeedControlVisible={isSpeedControlVisible}
+ speed={speed}
/>
- ) : null}
-
- {/** Speed */}
- {showAnimationWindowControl || !updateAnimationSpeed ? null : (
- <StyledSpeedControl>
- <IconButton
- data-tip
- data-for="animate-speed"
- className="playback-control-button"
- {...btnStyle}
- onClick={hideAndShowSpeedControl}
- >
- <playbackIcons.speed height={buttonHeight} />
- <Tooltip id="animate-speed" place="top" delayShow={DELAY_SHOW} effect="solid">
- <span>{preciseRound(speed, 1)}x</span>
- </Tooltip>
- </IconButton>
- {isSpeedControlVisible ? (
- <AnimationSpeedSlider
- onHide={hideAndShowSpeedControl}
- updateAnimationSpeed={updateAnimationSpeed}
- speed={speed}
- />
- ) : null}
- </StyledSpeedControl>
- )}
-
- {/** Reset */}
- {showAnimationWindowControl ? null : (
- <IconButton
- data-tip
- data-for="animate-reset"
- className="playback-control-button"
- onClick={resetAnimation}
- {...btnStyle}
- >
- <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
- data-tip
- data-for="animate-play-pause"
- className={classnames('playback-control-button', {active: isAnimating})}
- onClick={isAnimating ? pauseAnimation : startAnimation}
- {...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>
- )}
+ ))}
</StyledAnimationControls>
);
};
+
+ PlaybackControls.defaultProps = {
+ playbackIcons: DEFAULT_ICONS,
+ animationItems: DEFAULT_ANIMATE_ITEMS,
+ buttonStyle: 'secondary',
+ buttonHeight: DEFAULT_BUTTON_HEIGHT,
+ playbackActionItems: PLAYBACK_CONTROLS_DEFAULT_ACTION_COMPONENTS,
+ animationWindow: ANIMATION_WINDOW.free,
+ isAnimatable: true,
+ pauseAnimation: nop,
+ resetAnimation: nop,
+ startAnimation: nop
+ };
+
return PlaybackControls;
}
diff --git a/src/components/common/animation-control/reset-control.tsx b/src/components/common/animation-control/reset-control.tsx
new file mode 100644
index 000000000..a19254e62
--- /dev/null
+++ b/src/components/common/animation-control/reset-control.tsx
@@ -0,0 +1,35 @@
+import React from 'react';
+import {FormattedMessage} from 'localization';
+import {Tooltip} from 'components/common/styled-components';
+import IconButton from '../icon-button';
+
+const DELAY_SHOW = 500;
+
+function ResetControlFactory() {
+ const ResetControl = ({
+ showAnimationWindowControl,
+ resetAnimation,
+ btnStyle,
+ playbackIcons,
+ buttonHeight
+ }) => {
+ return showAnimationWindowControl ? null : (
+ <IconButton
+ data-tip
+ data-for="animate-reset"
+ className="playback-control-button"
+ onClick={resetAnimation}
+ {...btnStyle}
+ >
+ <playbackIcons.reset height={buttonHeight} />
+ <Tooltip id="animate-reset" place="top" delayShow={DELAY_SHOW} effect="solid">
+ <FormattedMessage id="tooltip.reset" />
+ </Tooltip>
+ </IconButton>
+ );
+ };
+
+ return ResetControl;
+}
+
+export default ResetControlFactory;
diff --git a/src/components/common/animation-control/speed-control.tsx b/src/components/common/animation-control/speed-control.tsx
index 66ff7d920..5c32ffe98 100644
--- a/src/components/common/animation-control/speed-control.tsx
+++ b/src/components/common/animation-control/speed-control.tsx
@@ -20,52 +20,63 @@
import React from 'react';
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 {Tooltip} from 'components/common/styled-components';
+import IconButton from '../icon-button';
+import {media} from '@kepler.gl/styles';
import {preciseRound} from 'utils/data-utils';
-const StyledSpeedToggle = styled.div`
+const StyledSpeedControl = styled.div`
display: flex;
- flex-grow: 0;
- color: ${props => props.theme.textColor};
- position: relative;
-`;
+ align-items: center;
-const StyledSpeedText = styled.div`
- display: inline-block;
- width: 24px;
- text-align: left;
+ .animation-control__speed-slider {
+ left: 0;
+ ${media.palm`
+ left: 60px;
+ `}
+ }
`;
-SpeedControlFactory.deps = [AnimationSpeedSliderFactory];
+const DELAY_SHOW = 500;
+const PRECISE_SPEED_ROUND = 1;
-function SpeedControlFactory(AnimationSpeedSlider: ReturnType<typeof AnimationSpeedSliderFactory>) {
+function SpeedControlFactory(AnimationSpeedSlider) {
const SpeedControl = ({
- onClick,
+ showAnimationWindowControl,
updateAnimationSpeed,
+ btnStyle,
+ hideAndShowSpeedControl,
+ buttonHeight,
+ playbackIcons,
speed,
- showSpeedControl,
- buttonHeight = '18px'
- }) => (
- <StyledSpeedToggle className="animation-control__speed-control">
- <Button link width="80px" onClick={onClick}>
- <CenterFlexbox className="bottom-widget__icon speed">
- <Rocket height={buttonHeight} />
- </CenterFlexbox>
- <StyledSpeedText style={{visibility: !showSpeedControl ? 'visible' : 'hidden'}}>
- {preciseRound(speed, 1)}x
- </StyledSpeedText>
- </Button>
- {showSpeedControl ? (
- <AnimationSpeedSlider
- onHide={onClick}
- updateAnimationSpeed={updateAnimationSpeed}
- speed={speed}
- />
- ) : null}
- </StyledSpeedToggle>
- );
+ isSpeedControlVisible
+ }) => {
+ return showAnimationWindowControl || !updateAnimationSpeed ? null : (
+ <StyledSpeedControl>
+ <IconButton
+ data-tip
+ data-for="animate-speed"
+ className="playback-control-button"
+ {...btnStyle}
+ onClick={hideAndShowSpeedControl}
+ >
+ <playbackIcons.speed height={buttonHeight} />
+ <Tooltip id="animate-speed" place="top" delayShow={DELAY_SHOW} effect="solid">
+ <span>{preciseRound(speed, PRECISE_SPEED_ROUND)}x</span>
+ </Tooltip>
+ </IconButton>
+ {isSpeedControlVisible ? (
+ <AnimationSpeedSlider
+ onHide={hideAndShowSpeedControl}
+ updateAnimationSpeed={updateAnimationSpeed}
+ speed={speed}
+ />
+ ) : null}
+ </StyledSpeedControl>
+ );
+ };
+
return SpeedControl;
}
+
export default SpeedControlFactory;
diff --git a/src/components/common/animation-control/window-action-control.tsx b/src/components/common/animation-control/window-action-control.tsx
new file mode 100644
index 000000000..eb934996e
--- /dev/null
+++ b/src/components/common/animation-control/window-action-control.tsx
@@ -0,0 +1,47 @@
+import React, {useMemo} from 'react';
+import classnames from 'classnames';
+import {FormattedMessage} from 'localization';
+import {Tooltip} from 'components/common/styled-components';
+import IconButton from '../icon-button';
+
+const DELAY_SHOW = 500;
+function WindowActionControlFactory() {
+ const WindowActionComponent = ({
+ toggleAnimationWindowControl,
+ showAnimationWindowControl,
+ btnStyle,
+ animationItems,
+ animationWindow,
+ buttonHeight,
+ setFilterAnimationWindow
+ }) => {
+ const icon = useMemo(() => {
+ if (animationItems[animationWindow]) {
+ const WindowIcon = animationItems[animationWindow].icon;
+ return <WindowIcon height={buttonHeight} />;
+ }
+ return null;
+ }, [animationItems, animationWindow, buttonHeight]);
+
+ return setFilterAnimationWindow ? (
+ <IconButton
+ data-tip
+ data-for="animate-window"
+ className={classnames('playback-control-button', {active: showAnimationWindowControl})}
+ onClick={toggleAnimationWindowControl}
+ {...btnStyle}
+ >
+ {icon}
+ {animationItems[animationWindow] && animationItems[animationWindow].tooltip ? (
+ <Tooltip id="animate-window" place="top" delayShow={DELAY_SHOW} effect="solid">
+ <FormattedMessage id={animationItems[animationWindow].tooltip} />
+ </Tooltip>
+ ) : null}
+ </IconButton>
+ ) : null;
+ };
+
+ return WindowActionComponent;
+}
+
+export default WindowActionControlFactory;
diff --git a/src/components/common/icon-button.tsx b/src/components/common/icon-button.tsx
new file mode 100644
index 000000000..2c2d325e4
--- /dev/null
+++ b/src/components/common/icon-button.tsx
@@ -0,0 +1,28 @@
+import styled from 'styled-components';
+import {Button, ButtonProps} from './styled-components';
+interface IconButtonProps extends ButtonProps {
+ collapsed?: boolean;
+}
+
+export const IconButton = styled(Button)<IconButtonProps>`
+ 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;
+ }
+ &.active {
+ background-color: ${props => props.theme.playbackButtonActBgColor};
+ }
+`;
+
+export default IconButton;
diff --git a/src/components/common/time-range-slider.tsx b/src/components/common/time-range-slider.tsx
index c283372e9..3ebf9e628 100644
--- a/src/components/common/time-range-slider.tsx
+++ b/src/components/common/time-range-slider.tsx
@@ -108,6 +108,7 @@ export default function TimeRangeSliderFactory(
onChange
} = props;
const throttledOnchange = useMemo(() => throttle(onChange, 20), [onChange]);
+
return (
<div className="time-range-slider">
{!hideTimeTitle ? (
diff --git a/src/components/index.ts b/src/components/index.ts
index 2cb54d238..258608f50 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -132,8 +132,12 @@ export {default as NotificationItemFactory} from './notification-panel/notificat
// // common factory
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 PlaybackControlsFactory} from './common/animation-control/playback-controls';
+export {default as WindowActionControlFactory} from './common/animation-control/window-action-control';
+export {default as PlayControlFactory} from './common/animation-control/play-control';
+export {default as ResetControlFactory} from './common/animation-control/reset-control';
+export {default as SpeedControlFactory} from './common/animation-control/speed-control';
+export {default as AnimationWindowControlFactory} from './common/animation-control/animation-window-control';
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';
@@ -142,7 +146,7 @@ export {default as LineChartFactory} from './common/line-chart';
export {default as RangeBrushFactory} from './common/range-brush';
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 SingleSelectFilterFactory} from './filters/single-select-filter';
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index 50122227d..7a3446186 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -215,7 +215,8 @@ export default {
speed: 'speed',
play: 'play',
pause: 'pause',
- reset: 'reset'
+ reset: 'reset',
+ export: 'export'
},
toolbar: {
exportImage: 'Export Image',
diff --git a/test/browser/components/common/animation-control-test.js b/test/browser/components/common/animation-control-test.js
index 5c06b4c4b..0d9ea756d 100644
--- a/test/browser/components/common/animation-control-test.js
+++ b/test/browser/components/common/animation-control-test.js
@@ -32,10 +32,8 @@ import {
} from 'components';
import {appInjector} from 'components/container';
import {StateWTripGeojson} from 'test/helpers/mock-state';
-import {
- AnimationWindowControl,
- IconButton
-} from 'components/common/animation-control/playback-controls';
+import IconButton from 'components/common/icon-button';
+
import reducer from 'reducers/vis-state';
const AnimationControl = appInjector.get(AnimationControlFactory);
@@ -67,7 +65,7 @@ test('Components -> AnimationControl -> render with props', t => {
}, 'Show not fail with trip layer props');
t.equal(
- wrapper.find(AnimationWindowControl).length,
+ wrapper.find('.animation-window-control').length,
0,
'should not render AnimationWindowControl'
);
diff --git a/test/browser/components/filters/time-widget-test.js b/test/browser/components/filters/time-widget-test.js
index c8fbc25b5..49f8790b1 100644
--- a/test/browser/components/filters/time-widget-test.js
+++ b/test/browser/components/filters/time-widget-test.js
@@ -40,10 +40,7 @@ import {
TimeSliderMarkerFactory,
TimeRangeSliderTimeTitleFactory
} from 'components';
-import {
- AnimationWindowControl,
- IconButton
-} from 'components/common/animation-control/playback-controls';
+import IconButton from 'components/common/icon-button';
import SliderHandle from 'components/common/slider/slider-handle';
import Typeahead from 'components/common/item-selector/typeahead';
@@ -159,9 +156,9 @@ test('Components -> TimeWidget.mount -> test actions', t => {
'should not render AnimationSpeedSlider iniitally'
);
t.equal(
- wrapper.find(AnimationWindowControl).length,
+ wrapper.find('.animation-window-control').length,
0,
- 'should not render AnimationWindowControl iniitally'
+ 'should not render AnimationWindowControl initially'
);
// hit play
@@ -207,26 +204,27 @@ test('Components -> TimeWidget.mount -> test actions', t => {
.at(0)
.simulate('click');
t.equal(
- wrapper.find(AnimationWindowControl).length,
+ wrapper.find('.animation-window-control').length,
1,
- 'should render AnimationWindowControl iniitally'
+ 'should render AnimationWindowControl initially'
);
t.equal(
wrapper
- .find(AnimationWindowControl)
+ .find('.animation-window-control')
.at(0)
.find(IconButton).length,
1,
'should render 1 animate window options'
);
- // select an animtion option
+ // select an animation option
wrapper
- .find(AnimationWindowControl)
+ .find('.animation-window-control')
.at(0)
.find(IconButton)
.at(0)
.simulate('click');
+
t.deepEqual(
setFilterAnimationWindow.args[0],
[{id: StateWFilters.visState.filters[0].id, animationWindow: 'incremental'}],
diff --git a/yarn.lock b/yarn.lock
index 252c568dc..fc98cdfeb 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2245,7 +2245,12 @@
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-5.1.5.tgz#153405227ab933d004a5bb9641a9ed999fcbe0cf"
integrity sha512-/lF+JR+qNDHZ8bF9d+Cp58nxtZWJ3sqFe6n3u3Vpj+/0cqkjk4nXKYBSY0azm+GIYB5mWKxUXvuP/m0ZnKj1bw==
-"@turf/helpers@^6.1.4", "@turf/helpers@^6.3.0":
+"@turf/helpers@^6.1.4":
+ version "6.1.4"
+ resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-6.1.4.tgz#d6fd7ebe6782dd9c87dca5559bda5c48ae4c3836"
+ integrity sha512-vJvrdOZy1ngC7r3MDA7zIGSoIgyrkWcGnNIEaqn/APmw+bVLF2gAW7HIsdTxd12s5wQMqEpqIQrmrbRRZ0xC7g==
+
+"@turf/helpers@^6.3.0":
version "6.3.0"
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-6.3.0.tgz#87f90f806c3f8ad6385ef8d2041d3662bf3c9fb1"
integrity sha512-kr6KuD4Z0GZ30tblTEvi90rvvVNlKieXuMC8CTzE/rVQb0/f/Cb29zCXxTD7giQTEQY/P2nRW23wEqqyNHulCg==
@@ -10518,7 +10523,7 @@ [email protected]:
is-plain-obj "^1.1.0"
kind-of "^6.0.3"
[email protected], minimist@^0.1.0, minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@~1.2.0, minimist@~1.2.5:
[email protected], [email protected], minimist@^0.1.0, minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@~1.2.0, minimist@~1.2.5:
version "1.2.3"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.3.tgz#3db5c0765545ab8637be71f333a104a965a9ca3f"
integrity sha512-+bMdgqjMN/Z77a6NlY/I3U5LlRDbnmaAk6lDveAPKwSpcPM4tKAuYsvYF8xjhOPXhOYGe/73vVLVez5PW+jqhw==
@@ -10583,7 +10588,14 @@ mkdirp-classic@^0.5.2, mkdirp-classic@^0.5.3:
resolved "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113"
integrity sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==
-mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.4, mkdirp@^0.5.5:
+mkdirp@^0.5.0, mkdirp@^0.5.1:
+ version "0.5.1"
+ resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
+ integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
+ dependencies:
+ minimist "0.0.8"
+
+mkdirp@^0.5.3, mkdirp@^0.5.4, mkdirp@^0.5.5:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==
@@ -12564,9 +12576,9 @@ react-motion@^0.5.2:
raf "^3.1.0"
react-onclickoutside@^6.7.1:
- version "6.10.0"
- resolved "https://registry.yarnpkg.com/react-onclickoutside/-/react-onclickoutside-6.10.0.tgz#05abb592575b08b4d129003494056b9dff46eeeb"
- integrity sha512-7i2L3ef+0ILXpL6P+Hg304eCQswh4jl3ynwR71BSlMU49PE2uk31k8B2GkP6yE9s2D4jTGKnzuSpzWxu4YxfQQ==
+ version "6.9.0"
+ resolved "https://registry.yarnpkg.com/react-onclickoutside/-/react-onclickoutside-6.9.0.tgz#a54bc317ae8cf6131a5d78acea55a11067f37a1f"
+ integrity sha512-8ltIY3bC7oGhj2nPAvWOGi+xGFybPNhJM0V1H8hY/whNcXgmDeaeoCMPPd8VatrpTsUWjb/vGzrmu6SrXVty3A==
react-onclickoutside@^6.9.0:
version "6.12.2"