Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

redux animation widget #1623

Benjamin King920b1fb02d18
diff --git a/web/css/anim.widget.css b/web/css/anim.widget.css
index 370c408ae..b348fbe73 100644
--- a/web/css/anim.widget.css
+++ b/web/css/anim.widget.css
@@ -8,7 +8,6 @@
-webkit-transform: translate(-50%);
top: -160px;
left: 50%;
- display: none;
color: #fff;
}
diff --git a/web/js/app.js b/web/js/app.js
index e1a1ee155..c50d9861d 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -22,6 +22,7 @@ import { updateLegacyInitComplete } from './modules/migration/actions';
// import { screenResize } from './modules/browser/actions';
import { calculateResponsiveState } from 'redux-responsive';
import Tour from './containers/tour';
+import AnimationWidget from './containers/animation-widget';
// Dependency CSS
import '../../node_modules/bootstrap/dist/css/bootstrap.css';
@@ -82,6 +83,7 @@ class App extends React.Component {
this.onload();
}
render() {
+ const { config } = this.props;
return (
<div className="wv-content" id="wv-content" data-role="content">
<Toolbar />
@@ -179,7 +181,9 @@ class App extends React.Component {
</div>
</div>
<div id="timeline-footer">
- <div id="wv-animation-widet-case"> </div>
+ <div id="wv-animation-widet-case">
+ {config.features.animation ? <AnimationWidget /> : ''}
+ </div>
</div>
<div id="timeline-hide">
<svg className="hamburger" width="10" height="9">
diff --git a/web/js/combine-models.js b/web/js/combine-models.js
index f30e137dd..36800a2cc 100644
--- a/web/js/combine-models.js
+++ b/web/js/combine-models.js
@@ -43,7 +43,7 @@ export function combineModels(config) {
models.tour = tourModel(config);
}
if (config.features.animation) {
- models.anim = animationModel(models, config);
+ // models.anim = animationModel(models, config);
}
if (config.features.dataDownload) {
models.data = dataModel(models, config);
diff --git a/web/js/combine-ui.js b/web/js/combine-ui.js
index 33a072fc3..a8a254a84 100644
--- a/web/js/combine-ui.js
+++ b/web/js/combine-ui.js
@@ -20,10 +20,10 @@ import { timelineCompare } from './date/compare-picks';
import { layersActive } from './layers/active';
import { mapui } from './map/ui';
import { mapAnimate } from './map/animate';
-import { animationUi } from './animation/ui';
-import { animationWidget } from './animation/widget';
-import { animationRangeSelect } from './animation/range-select';
-import { animationGif } from './animation/gif';
+// import { animationUi } from './animation/ui';
+// import { animationWidget } from './animation/widget';
+// import { animationRangeSelect } from './animation/range-select';
+// import { animationGif } from './animation/gif';
import { debugLayers } from './debug';
import { dataUi } from './map/data/ui';
import naturalEventsUI from './map/natural-events/ui';
@@ -68,11 +68,11 @@ export function combineUi(models, config, MapMouseEvents, store) {
ui.timeline.input = timelineInput(models, config, ui, store);
ui.timeline.config = timelineConfig(models, config, ui);
if (config.features.animation) {
- ui.anim = {};
- ui.anim.rangeselect = animationRangeSelect(models, config, ui); // SETS STATE: NEEDS TO LOAD BEFORE ANIMATION WIDGET
- ui.anim.widget = animationWidget(models, config, ui);
- ui.anim.gif = animationGif(models, config, ui);
- ui.anim.ui = animationUi(models, ui);
+ // ui.anim = {};
+ // ui.anim.rangeselect = animationRangeSelect(models, config, ui); // SETS STATE: NEEDS TO LOAD BEFORE ANIMATION WIDGET
+ // ui.anim.widget = animationWidget(models, config, ui);
+ // ui.anim.gif = animationGif(models, config, ui);
+ // ui.anim.ui = animationUi(models, ui);
}
if (config.features.compare) {
ui.timeline.compare = timelineCompare(models, config, ui);
diff --git a/web/js/components/animation-widget/animation-widget.js b/web/js/components/animation-widget/animation-widget.js
deleted file mode 100644
index d06c755f9..000000000
--- a/web/js/components/animation-widget/animation-widget.js
+++ /dev/null
@@ -1,235 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-import Slider, { Handle } from 'rc-slider';
-import TimeSelector from '../date-selector/date-selector';
-import LoopButton from './loop-button';
-import PlayButton from './play-button';
-import AnimWidgetHeader from './header';
-import googleTagManager from 'googleTagManager';
-
-const RangeHandle = props => {
- const { value, offset, dragging, ...restProps } = props;
-
- const positionStyle = {
- position: 'absolute',
- left: `${(offset - 5).toFixed(2)}%`
- };
-
- return (
- <React.Fragment>
- <span className="anim-frame-rate-label" style={positionStyle}>
- {value < 10 ? value.toFixed(1) : value}
- </span>
- <Handle
- dragging={dragging.toString()}
- value={value}
- offset={offset}
- {...restProps}
- />
- </React.Fragment>
- );
-};
-/*
- * A react component, Builds a rather specific
- * interactive widget
- *
- * @class AnimationWidget
- * @extends React.Component
- */
-class AnimationWidget extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- value: props.sliderSpeed,
- looping: props.looping,
- startDate: props.startDate,
- endDate: props.endDate,
- maxZoom: props.maxZoom,
- header: props.header,
- incrementArray: props.incrementArray,
- increment: props.increment
- };
- }
-
- /*
- * Sets a new state value when a
- * when the slider is adjusted
- *
- * @method onSlide
- *
- * @param {number} value - Value of the slider
- * selection
- *
- * @return {void}
- */
- onSlide(value) {
- this.props.onSlide(value);
- this.setState({
- value: value
- });
- }
-
- /*
- * calls the callback, passing the
- * current state elements as parameters
- *
- * @method play
- *
- * @return {void}
- */
- play() {
- this.props.onPushPlay();
- this.setState({
- playing: true
- });
- }
- pause() {
- this.props.onPushPause();
- this.setState({
- playing: false
- });
- }
- /*
- * Sets a new state to say whether or not
- * the animation should loop
- *
- * @method onLoop
- *
- * @param {Object} component - slider react
- * component
- * @param {number} value - Value of the slider
- * selection
- *
- * @return {void}
- */
- onLoop() {
- var loop = true;
- if (this.state.looping) {
- loop = false;
- }
- this.setState({
- looping: loop
- });
- this.props.onPushLoop(loop);
- }
- onDateChange(date, id) {
- const { endDate, startDate } = this.state;
- googleTagManager.pushEvent({
- event: 'GIF_animation_date_case'
- });
- if (id === 'start') {
- this.setState({
- startDate: date
- });
- this.props.onDateChange(date, endDate);
- } else {
- this.setState({
- endDate: date
- });
- this.props.onDateChange(startDate, date);
- }
- }
- render() {
- return (
- <div
- id="wv-animation-widget"
- className={
- 'wv-animation-widget' + (this.state.maxZoom >= 4 ? ' subdaily' : '')
- }
- >
- <AnimWidgetHeader
- text={this.state.increment}
- toolTipTextArray={this.state.incrementArray}
- onClick={this.props.onZoomSelect}
- />
-
- <PlayButton
- playing={this.state.playing}
- play={this.play.bind(this)}
- pause={this.pause.bind(this)}
- />
- <LoopButton
- looping={this.state.looping}
- onLoop={this.onLoop.bind(this)}
- />
- <div className="wv-slider-case">
- <Slider
- className="input-range"
- step={0.5}
- max={10}
- min={0.5}
- value={this.state.value}
- onChange={this.onSlide.bind(this)}
- handle={RangeHandle}
- />
- <span className="wv-slider-label">{this.props.sliderLabel}</span>
- </div>
-
- <a
- href="javascript:void(null)"
- title="Create Animated GIF"
- className="wv-icon-case"
- onClick={this.props.onPushGIF}
- >
- <i
- id="wv-animation-widget-file-video-icon"
- className="fas fa-file-video wv-animation-widget-icon"
- />
- </a>
- <div className="wv-anim-dates-case">
- <TimeSelector
- width="120"
- height="30"
- date={this.state.startDate}
- id="start"
- idSuffix="animation-widget-start"
- onDateChange={this.onDateChange.bind(this)}
- maxDate={this.state.endDate}
- minDate={this.props.minDate}
- maxZoom={this.state.maxZoom}
- />
- <div className="thru-label">To</div>
- <TimeSelector
- width="120"
- height="30"
- date={this.state.endDate}
- id="end"
- idSuffix="animation-widget-end"
- onDateChange={this.onDateChange.bind(this)}
- maxDate={this.props.maxDate}
- minDate={this.state.startDate}
- maxZoom={this.state.maxZoom}
- />
- </div>
- <i className="fa fa-times wv-close" onClick={this.props.onClose} />
- </div>
- );
- }
-}
-RangeHandle.propTypes = {
- value: PropTypes.number,
- offset: PropTypes.number
-};
-AnimationWidget.propTypes = {
- sliderSpeed: PropTypes.number,
- looping: PropTypes.bool,
- startDate: PropTypes.object,
- endDate: PropTypes.object,
- header: PropTypes.element,
- incrementArray: PropTypes.array,
- increment: PropTypes.string,
- onSlide: PropTypes.func,
- onPushPlay: PropTypes.func,
- onPushPause: PropTypes.func,
- onPushLoop: PropTypes.func,
- onDateChange: PropTypes.func,
- onZoomSelect: PropTypes.func,
- sliderLabel: PropTypes.string,
- onPushGIF: PropTypes.func,
- minDate: PropTypes.object,
- maxDate: PropTypes.object,
- maxZoom: PropTypes.number,
- onClose: PropTypes.func
-};
-
-export default AnimationWidget;
diff --git a/web/js/components/date-selector/date-selector.js b/web/js/components/date-selector/date-selector.js
index 9b320d626..0d8cb227a 100644
--- a/web/js/components/date-selector/date-selector.js
+++ b/web/js/components/date-selector/date-selector.js
@@ -17,21 +17,24 @@ class DateSelector extends React.Component {
constructor(props) {
super(props);
this.state = {
- date: props.date,
- maxDate: props.maxDate,
- minDate: props.minDate,
- tab: null,
- maxZoom: props.maxZoom
+ // date: props.draggerSelected === 'selectedB' ? props.dateB : props.date,
+ // maxDate: props.maxDate,
+ // minDate: props.minDate,
+ tab: null
+ // maxZoom: props.maxZoom,
+ // hasSubdailyLayers: props.hasSubdailyLayers
};
}
- componentWillReceiveProps(props) {
- this.setState({
- date: props.date,
- maxDate: props.maxDate,
- minDate: props.minDate,
- maxZoom: props.maxZoom
- });
- }
+ // componentWillReceiveProps(props) {
+ // this.setState({
+ // // date: props.draggerSelectedB ? props.dateB : props.date,
+ // // date: props.draggerSelected === 'selectedB' ? props.dateB : props.date,
+ // maxDate: props.maxDate,
+ // minDate: props.minDate,
+ // // maxZoom: props.maxZoom,
+ // hasSubdailyLayers: props.hasSubdailyLayers
+ // });
+ // }
blur() {
this.setState({ tab: null });
}
@@ -41,7 +44,7 @@ class DateSelector extends React.Component {
changeTab(index) {
var nextTab = index;
var maxTab;
- if (this.state.maxZoom >= 4) {
+ if (this.state.hasSubdailyLayers) {
maxTab = 5;
} else {
maxTab = 3;
@@ -61,27 +64,26 @@ class DateSelector extends React.Component {
tab: nextTab
});
}
- updateDate(date) {
- this.setState({
- date: date
- });
+ updateDate(date, type, amt) {
+ // this.props.onDateChange(date, this.props.id, type, amt);
+ // # allows dragger change via main date selector, and id change via anim date selectors
this.props.onDateChange(date, this.props.id);
}
renderSubdaily() {
- if (this.state.maxZoom >= 4) {
+ if (this.props.hasSubdailyLayers) {
return (
<React.Fragment>
<DateInputColumn
step={1}
startDate={new Date(2000)}
today={new Date()}
- date={this.state.date}
+ date={this.props.date}
type="hour"
inputId={this.props.idSuffix ? 'hour-' + this.props.idSuffix : ''}
height={this.props.height}
width={this.props.width}
updateDate={this.updateDate.bind(this)}
- value={util.pad(this.state.date.getUTCHours(), 2, '0')}
+ value={util.pad(this.props.date.getUTCHours(), 2, '0')}
tabIndex={4}
focused={this.state.tab === 4}
setFocusedTab={this.setFocusedTab.bind(this)}
@@ -96,12 +98,12 @@ class DateSelector extends React.Component {
step={10}
startDate={new Date(2000)}
today={new Date()}
- date={this.state.date}
+ date={this.props.date}
type="minute"
height={this.props.height}
width={this.props.width}
updateDate={this.updateDate.bind(this)}
- value={util.pad(this.state.date.getUTCMinutes(), 2, '0')}
+ value={util.pad(this.props.date.getUTCMinutes(), 2, '0')}
inputId={this.props.idSuffix ? 'minute-' + this.props.idSuffix : ''}
tabIndex={5}
focused={this.state.tab === 5}
@@ -118,67 +120,77 @@ class DateSelector extends React.Component {
}
}
render() {
+ const {
+ date,
+ width,
+ height,
+ maxDate,
+ minDate,
+ fontSize,
+ idSuffix
+ } = this.props;
+ const tab = this.state;
return (
<div className="wv-date-selector-widget">
<DateInputColumn
step={1}
startDate={new Date(2000)}
today={new Date()}
- date={this.state.date}
- value={this.state.date.getUTCFullYear()}
+ date={date}
+ value={date.getUTCFullYear()}
type="year"
- height={this.props.height}
- width={this.props.width}
+ height={height}
+ width={width}
updateDate={this.updateDate.bind(this)}
- inputId={this.props.idSuffix ? 'year-' + this.props.idSuffix : ''}
+ inputId={idSuffix ? 'year-' + idSuffix : ''}
tabIndex={1}
- focused={this.state.tab === 1}
+ focused={tab === 1}
setFocusedTab={this.setFocusedTab.bind(this)}
changeTab={this.changeTab.bind(this)}
- maxDate={this.props.maxDate}
- minDate={this.props.minDate}
+ maxDate={maxDate}
+ minDate={minDate}
blur={this.blur.bind(this)}
- fontSize={this.props.fontSize}
+ fontSize={fontSize}
/>
<DateInputColumn
step={1}
startDate={new Date(2000)}
today={new Date()}
- date={this.state.date}
- value={util.monthStringArray[this.state.date.getUTCMonth()]}
+ date={date}
+ value={util.monthStringArray[date.getUTCMonth()]}
type="month"
- inputId={this.props.idSuffix ? 'month-' + this.props.idSuffix : ''}
- height={this.props.height}
- width={this.props.width}
+ inputId={idSuffix ? 'month-' + idSuffix : ''}
+ height={height}
+ width={width}
updateDate={this.updateDate.bind(this)}
tabIndex={2}
- focused={this.state.tab === 2}
+ focused={tab === 2}
setFocusedTab={this.setFocusedTab.bind(this)}
changeTab={this.changeTab.bind(this)}
- maxDate={this.props.maxDate}
- minDate={this.props.minDate}
+ maxDate={maxDate}
+ minDate={minDate}
blur={this.blur.bind(this)}
- fontSize={this.props.fontSize}
+ fontSize={fontSize}
/>
<DateInputColumn
step={1}
startDate={new Date(2000)}
today={new Date()}
- date={this.state.date}
+ date={date}
type="day"
- height={this.props.height}
- width={this.props.width}
+ height={height}
+ width={width}
updateDate={this.updateDate.bind(this)}
- value={util.pad(this.state.date.getUTCDate(), 2, '0')}
+ value={util.pad(date.getUTCDate(), 2, '0')}
tabIndex={3}
- inputId={this.props.idSuffix ? 'day-' + this.props.idSuffix : ''}
- focused={this.state.tab === 3}
+ inputId={idSuffix ? 'day-' + idSuffix : ''}
+ focused={tab === 3}
setFocusedTab={this.setFocusedTab.bind(this)}
changeTab={this.changeTab.bind(this)}
- maxDate={this.props.maxDate}
- minDate={this.props.minDate}
+ maxDate={maxDate}
+ minDate={minDate}
blur={this.blur.bind(this)}
- fontSize={this.props.fontSize}
+ fontSize={fontSize}
/>
{this.renderSubdaily()}
</div>
@@ -198,7 +210,8 @@ DateSelector.propTypes = {
height: PropTypes.string,
width: PropTypes.string,
idSuffix: PropTypes.string,
- fontSize: PropTypes.number
+ fontSize: PropTypes.number,
+ hasSubdailyLayers: PropTypes.bool
};
export default DateSelector;
diff --git a/web/js/components/range-selection/dragger-range.js b/web/js/components/range-selection/dragger-range.js
index 747030119..1386afc58 100644
--- a/web/js/components/range-selection/dragger-range.js
+++ b/web/js/components/range-selection/dragger-range.js
@@ -21,12 +21,12 @@ class TimelineDraggerRange extends React.Component {
};
}
/*
- * Resize timeline dragger width
- *
- * @method checkWidth
- *
- * @return {void}
- */
+ * Resize timeline dragger width
+ *
+ * @method checkWidth
+ *
+ * @return {void}
+ */
checkWidth() {
var start = this.props.startLocation;
var end = this.props.endLocation;
@@ -65,19 +65,25 @@ class TimelineDraggerRange extends React.Component {
e.preventDefault();
e.stopPropagation();
// +/- {number} - change in x - set to 0 to 'stop' dragger movement - min/max of -55/55 to prevent overdrag
- let deltaX = d.deltaX < -55 ? -55 : (d.deltaX > 55 ? 55 : d.deltaX);
+ let deltaX = d.deltaX < -55 ? -55 : d.deltaX > 55 ? 55 : d.deltaX;
// +/- {number} - start position
let deltaStart = d.x;
let startLocationDate = new Date(this.props.startLocationDate);
let endLocationDate = new Date(this.props.endLocationDate);
let timelineEndDate = new Date(this.props.timelineEndDateLimit);
// used to determine and buffer large monthly/yearly ranges
- let startDateToEndDifference = this.dateDifferenceInDays(startLocationDate, endLocationDate);
+ let startDateToEndDifference = this.dateDifferenceInDays(
+ startLocationDate,
+ endLocationDate
+ );
if (startDateToEndDifference > 100) {
startDateToEndDifference = 300;
}
// difference between last date on timeline (current day/now) and end date dragger
- let endDateToLimitDifference = Math.min(startDateToEndDifference, this.dateDifferenceInDays(endLocationDate, timelineEndDate));
+ let endDateToLimitDifference = Math.min(
+ startDateToEndDifference,
+ this.dateDifferenceInDays(endLocationDate, timelineEndDate)
+ );
// match end date precise time units to dragging end date
let timelineEndDateLimitMatch = new Date(
timelineEndDate.getFullYear(),
@@ -98,8 +104,10 @@ class TimelineDraggerRange extends React.Component {
// format dates to ISO for comparison
endLocationDate = endLocationDate.toISOString().split('.')[0] + 'Z';
- timelineEndDateLimitMatch = timelineEndDateLimitMatch.toISOString().split('.')[0] + 'Z';
- timelineMaxDateBufferMatch = timelineMaxDateBufferMatch.toISOString().split('.')[0] + 'Z';
+ timelineEndDateLimitMatch =
+ timelineEndDateLimitMatch.toISOString().split('.')[0] + 'Z';
+ timelineMaxDateBufferMatch =
+ timelineMaxDateBufferMatch.toISOString().split('.')[0] + 'Z';
// timeline dragger dragged into the future (to the right)
if (deltaX > 0) {
@@ -116,7 +124,7 @@ class TimelineDraggerRange extends React.Component {
if (this.props.endLocation > this.props.max.width - deltaX) {
deltaX = 0;
}
- // end of timeline date is not within view - rely on dates
+ // end of timeline date is not within view - rely on dates
} else {
// use buffer to start slowing down allowed deltaX to prevent overdrag
if (endLocationDate >= timelineMaxDateBufferMatch) {
@@ -124,11 +132,14 @@ class TimelineDraggerRange extends React.Component {
}
}
}
- // timeline dragger dragged into the past (to the left)
+ // timeline dragger dragged into the past (to the left)
} else {
if (this.props.max.start) {
// timeline dragger dragged to min past of current viewable timeline
- if (this.props.startLocation + deltaX - this.props.max.startOffset <= 0) {
+ if (
+ this.props.startLocation + deltaX - this.props.max.startOffset <=
+ 0
+ ) {
deltaX = 0;
}
}
@@ -137,30 +148,40 @@ class TimelineDraggerRange extends React.Component {
}
/*
- * Utility function to caculate difference between two dates
- * put cutoff date as dateA for min (dateA hours & minutes used for both), and dateB for max
- *
- * @method dateDifferenceInDays
- *
- * @return {number}
- */
+ * Utility function to caculate difference between two dates
+ * put cutoff date as dateA for min (dateA hours & minutes used for both), and dateB for max
+ *
+ * @method dateDifferenceInDays
+ *
+ * @return {number}
+ */
dateDifferenceInDays(dateA, dateB) {
const msPerDay = 1000 * 60 * 60 * 24;
// Discard the time and time-zone information.
- const utc1 = Date.UTC(dateA.getFullYear(), dateA.getMonth(), dateA.getDate());
- const utc2 = Date.UTC(dateB.getFullYear(), dateB.getMonth(), dateB.getDate(), dateA.getHours(), dateA.getMinutes());
+ const utc1 = Date.UTC(
+ dateA.getFullYear(),
+ dateA.getMonth(),
+ dateA.getDate()
+ );
+ const utc2 = Date.UTC(
+ dateB.getFullYear(),
+ dateB.getMonth(),
+ dateB.getDate(),
+ dateA.getHours(),
+ dateA.getMinutes()
+ );
return Math.floor((utc2 - utc1) / msPerDay);
}
/*
- * Handle dragging timeline and syncing start position of dragger range
- * used in rect to return x
- *
- * @method handleStartPositionRestriction
- *
- * @return {number}
- */
+ * Handle dragging timeline and syncing start position of dragger range
+ * used in rect to return x
+ *
+ * @method handleStartPositionRestriction
+ *
+ * @return {number}
+ */
handleStartPositionRestriction() {
// if startLocation is in the past prior to min past of current viewable timeline
if (this.props.startLocation <= 0) {
@@ -171,23 +192,26 @@ class TimelineDraggerRange extends React.Component {
}
/*
- * Handle click within dragger range for drag vs guitarpick click behavior
- * used in rect as onClick
- *
- * @method handleDraggerClick
- *
- * @return {void}
- */
+ * Handle click within dragger range for drag vs guitarpick click behavior
+ * used in rect as onClick
+ *
+ * @method handleDraggerClick
+ *
+ * @return {void}
+ */
handleDraggerClick(e) {
// compare start locations to check if range has been dragged vs. clicked
- if (this.state.startLocation.toFixed(3) === this.state.previousStartLocation.toFixed(3)) {
+ if (
+ this.state.startLocation.toFixed(3) ===
+ this.state.previousStartLocation.toFixed(3)
+ ) {
this.props.onClick(e);
} else {
this.setState({ previousStartLocation: this.state.startLocation });
}
}
- componentDidMount () {
+ componentDidMount() {
this.checkWidth();
}
@@ -199,9 +223,12 @@ class TimelineDraggerRange extends React.Component {
});
}
- componentDidUpdate (prevProps) {
+ componentDidUpdate(prevProps) {
// update state and checkWidth only on startLocation and/or endLocation changes
- if (prevProps.startLocation !== this.props.startLocation || prevProps.endLocation !== this.props.endLocation) {
+ if (
+ prevProps.startLocation !== this.props.startLocation ||
+ prevProps.endLocation !== this.props.endLocation
+ ) {
this.updateExtent(this.props);
this.checkWidth();
}
@@ -215,7 +242,7 @@ class TimelineDraggerRange extends React.Component {
handle=".dragger-range"
axis="x"
position={null}
- defaultPosition={{ x: 0, y: -16 }}
+ defaultPosition={{ x: 0, y: 0 }}
onStop={this.props.onStop}
onDrag={this.handleDrag.bind(this)}
>
@@ -227,8 +254,9 @@ class TimelineDraggerRange extends React.Component {
fillOpacity: this.props.opacity,
cursor: 'pointer'
}}
- height={this.props.height}
- className='dragger-range'
+ // height={this.props.height}
+ height={63}
+ className="dragger-range"
id={this.props.draggerID}
onClick={this.handleDraggerClick.bind(this)}
/>
diff --git a/web/js/components/range-selection/dragger.js b/web/js/components/range-selection/dragger.js
index cae0c45ab..4ecc9ffc1 100644
--- a/web/js/components/range-selection/dragger.js
+++ b/web/js/components/range-selection/dragger.js
@@ -41,17 +41,18 @@ class TimelineDragger extends React.Component {
<React.Fragment>
<rect
width={this.props.width}
- height={this.props.height}
+ // height={this.props.height}
+ height={40}
style={{
fill: this.props.color,
visibility: visibility
}}
/>
{/*
- * this polygon element builds a triangle
- * based on the width and height of the
- * rectangle element
- */}
+ * this polygon element builds a triangle
+ * based on the width and height of the
+ * rectangle element
+ */}
<polygon
points={
'0,0,' +
@@ -190,7 +191,7 @@ TimelineDragger.defaultProps = {
color: '#fff',
position: 0,
visibility: 'visible',
- yOffset: -16,
+ yOffset: 23,
path: null,
textColor: '#000'
};
diff --git a/web/js/components/range-selection/range-selection.js b/web/js/components/range-selection/range-selection.js
index 3ad186823..324ec966b 100644
--- a/web/js/components/range-selection/range-selection.js
+++ b/web/js/components/range-selection/range-selection.js
@@ -98,20 +98,20 @@ class TimelineRangeSelector extends React.Component {
* @return {void}
*/
onDragStop() {
- this.props.onDrag(this.state.startLocation, this.state.endLocation);
+ this.props.onDrag(this.state.startLocation, this.state.endLocation, true);
googleTagManager.pushEvent({
- 'event': 'GIF_animation_dragger'
+ event: 'GIF_animation_dragger'
});
}
/*
- * Send callback with click event
- *
- * @method onRangeClick
- *
- * @param {object} d - proxy click event object
- *
- * @return {void}
- */
+ * Send callback with click event
+ *
+ * @method onRangeClick
+ *
+ * @param {object} d - proxy click event object
+ *
+ * @return {void}
+ */
onRangeClick(e) {
this.props.onRangeClick(e.nativeEvent);
}
@@ -138,7 +138,11 @@ class TimelineRangeSelector extends React.Component {
*/
render() {
return (
- <svg id="wv-timeline-range-selector" className="wv-timeline-range-selector">
+ <svg
+ id="wv-timeline-range-selector"
+ className="wv-timeline-range-selector"
+ onMouseEnter={this.props.onHover}
+ >
<DraggerRange
opacity={this.props.rangeOpacity}
startLocation={this.state.startLocation}
@@ -152,11 +156,12 @@ class TimelineRangeSelector extends React.Component {
height={this.props.height}
width={this.props.pinWidth}
color={this.props.rangeColor}
- draggerID='range-selector-range'
+ draggerID="range-selector-range"
onClick={this.onRangeClick.bind(this)}
onDrag={this.onRangeDrag.bind(this)}
onStop={this.onDragStop.bind(this)}
- id='range'/>
+ id="range"
+ />
<Dragger
position={this.state.startLocation}
color={this.props.startColor}
@@ -165,10 +170,11 @@ class TimelineRangeSelector extends React.Component {
onDrag={this.onItemDrag.bind(this)}
onStop={this.onDragStop.bind(this)}
max={this.state.max.width}
- draggerID='range-selector-dragger-1'
+ draggerID="range-selector-dragger-1"
backgroundColor={this.props.startTriangleColor}
first={true}
- id='start' />
+ id="start"
+ />
<Dragger
max={this.state.max.width}
position={this.state.endLocation}
@@ -176,11 +182,12 @@ class TimelineRangeSelector extends React.Component {
width={this.props.pinWidth}
height={this.props.height}
first={false}
- draggerID='range-selector-dragger-2'
+ draggerID="range-selector-dragger-2"
onDrag={this.onItemDrag.bind(this)}
onStop={this.onDragStop.bind(this)}
backgroundColor={this.props.endTriangleColor}
- id='end'/>
+ id="end"
+ />
</svg>
);
}
@@ -197,6 +204,7 @@ TimelineRangeSelector.propTypes = {
pinWidth: PropTypes.number,
height: PropTypes.number,
onDrag: PropTypes.func,
+ onHover: PropTypes.func,
onRangeClick: PropTypes.func,
rangeOpacity: PropTypes.number,
rangeColor: PropTypes.string,
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.js
new file mode 100644
index 000000000..6c5ce454c
--- /dev/null
+++ b/web/js/containers/animation-widget.js
@@ -0,0 +1,300 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { without as lodashWithout } from 'lodash';
+import PropTypes from 'prop-types';
+import Slider, { Handle } from 'rc-slider';
+import TimeSelector from '../components/date-selector/date-selector';
+import LoopButton from '../components/animation-widget/loop-button';
+import PlayButton from '../components/animation-widget/play-button';
+import AnimWidgetHeader from '../components/animation-widget/header';
+import googleTagManager from 'googleTagManager';
+import { hasSubDaily as hasSubDailySelector } from '../modules/layers/selectors';
+import {
+ play,
+ onClose,
+ stop,
+ toggleLooping,
+ changeFrameRate,
+ changeStartDate,
+ changeEndDate
+} from '../modules/animation/actions';
+
+const timeScaleFromNumberKey = {
+ '0': 'custom',
+ '1': 'year',
+ '2': 'month',
+ '3': 'day',
+ '4': 'hour',
+ '5': 'minute'
+};
+
+const RangeHandle = props => {
+ const { value, offset, dragging, ...restProps } = props;
+
+ const positionStyle = {
+ position: 'absolute',
+ left: `${(offset - 5).toFixed(2)}%`
+ };
+
+ return (
+ <React.Fragment>
+ <span className="anim-frame-rate-label" style={positionStyle}>
+ {value < 10 ? value.toFixed(1) : value}
+ </span>
+ <Handle
+ dragging={dragging.toString()}
+ value={value}
+ offset={offset}
+ {...restProps}
+ />
+ </React.Fragment>
+ );
+};
+/*
+ * A react component, Builds a rather specific
+ * interactive widget
+ *
+ * @class AnimationWidget
+ * @extends React.Component
+ */
+class AnimationWidget extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ speed: props.speed,
+ isSliding: false
+ };
+ }
+ static getDerivedStateFromProps(props, state) {
+ if (props.speed !== state.speed && !state.isSliding) {
+ return { speed: props.speed };
+ } else return null;
+ }
+ /*
+ * Sets a new state to say whether or not
+ * the animation should loop
+ *
+ * @method onLoop
+ *
+ * @param {Object} component - slider react
+ * component
+ * @param {number} value - Value of the slider
+ * selection
+ *
+ * @return {void}
+ */
+ onLoop() {
+ var loop = true;
+ if (this.state.looping) {
+ loop = false;
+ }
+ this.props.onPushLoop(loop);
+ }
+ onDateChange(date, id) {
+ const { onUpdateStartDate, onUpdateEndDate } = this.props;
+ googleTagManager.pushEvent({
+ event: 'GIF_animation_date_case'
+ });
+ if (id === 'start') {
+ onUpdateStartDate(date);
+ } else {
+ onUpdateEndDate(date);
+ }
+ }
+ render() {
+ const {
+ hasSubdailyLayers,
+ increment,
+ onZoomSelect,
+ incrementArray,
+ looping,
+ isPlaying,
+ maxDate,
+ minDate,
+ sliderLabel,
+ startDate,
+ endDate,
+ onPushPlay,
+ onPushPause
+ } = this.props;
+ return (
+ <div
+ id="wv-animation-widget"
+ className={
+ 'wv-animation-widget' + (hasSubdailyLayers ? ' subdaily' : '')
+ }
+ >
+ <AnimWidgetHeader
+ text={increment}
+ toolTipTextArray={incrementArray}
+ onClick={onZoomSelect}
+ />
+
+ <PlayButton playing={isPlaying} play={onPushPlay} pause={onPushPause} />
+ <LoopButton looping={looping} onLoop={this.onLoop.bind(this)} />
+ <div className="wv-slider-case">
+ <Slider
+ className="input-range"
+ step={0.5}
+ max={10}
+ min={0.5}
+ value={this.state.speed}
+ onChange={num => this.setState({ speed: num })}
+ handle={RangeHandle}
+ onBeforeChange={() => this.setState({ isSliding: true })}
+ onAfterChange={() => {
+ this.setState({ isSliding: false });
+ this.props.onSlide(this.state.speed);
+ }}
+ />
+ <span className="wv-slider-label">{sliderLabel}</span>
+ </div>
+
+ <a
+ href="javascript:void(null)"
+ title="Create Animated GIF"
+ className="wv-icon-case"
+ onClick={this.props.onPushGIF}
+ >
+ <i
+ id="wv-animation-widget-file-video-icon"
+ className="fas fa-file-video wv-animation-widget-icon"
+ />
+ </a>
+ <div className="wv-anim-dates-case">
+ <TimeSelector
+ width="120"
+ height="30"
+ date={startDate}
+ id="start"
+ idSuffix="animation-widget-start"
+ onDateChange={this.onDateChange.bind(this)}
+ maxDate={endDate}
+ minDate={minDate}
+ hasSubdailyLayers={hasSubdailyLayers}
+ />
+ <div className="thru-label">To</div>
+ <TimeSelector
+ width="120"
+ height="30"
+ date={endDate}
+ id="end"
+ idSuffix="animation-widget-end"
+ onDateChange={this.onDateChange.bind(this)}
+ maxDate={maxDate}
+ minDate={startDate}
+ hasSubdailyLayers={hasSubdailyLayers}
+ />
+ </div>
+ <i className="fa fa-times wv-close" onClick={this.props.onClose} />
+ </div>
+ );
+ }
+}
+function mapStateToProps(state) {
+ const { legacy, layers, compare, animation, models } = state;
+ const { startDate, endDate, speed, loop, isPlaying } = animation;
+ const activeStr = compare.activeString;
+ const hasSubdailyLayers = hasSubDailySelector(layers[activeStr]);
+ const zoomObj = getZoomObject(legacy.date, hasSubdailyLayers);
+ const minDate = models.date.minDate();
+ const maxDate = models.date.maxDate();
+
+ return {
+ startDate,
+ endDate,
+ minDate,
+ maxDate,
+ hasSubdailyLayers,
+ incrementArray: zoomObj.array,
+ increment: zoomObj.increment,
+ sliderLabel: 'Frames Per Second',
+ speed,
+ isPlaying,
+ looping: loop
+ };
+}
+const mapDispatchToProps = dispatch => ({
+ onClose: () => {
+ dispatch(onClose());
+ },
+ onPushPlay: () => {
+ dispatch(play());
+ },
+ onPushPause: () => {
+ dispatch(stop());
+ },
+ onPushLoop: () => {
+ dispatch(toggleLooping());
+ },
+ onPushGIF: () => {
+ // dispatch(onPushGIF());
+ },
+ onSlide: num => {
+ dispatch(changeFrameRate(num));
+ },
+ onZoomSelect: num => {
+ // dispatch(onZoomSelect(num));
+ },
+ onUpdateStartDate(date) {
+ dispatch(changeStartDate(date));
+ },
+ onUpdateEndDate(date) {
+ dispatch(changeEndDate(date));
+ }
+});
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(AnimationWidget);
+
+AnimationWidget.propTypes = {
+ speed: PropTypes.number,
+ looping: PropTypes.bool,
+ startDate: PropTypes.object,
+ endDate: PropTypes.object,
+ incrementArray: PropTypes.array,
+ increment: PropTypes.string,
+ onSlide: PropTypes.func,
+ onPushPlay: PropTypes.func,
+ onPushPause: PropTypes.func,
+ onPushLoop: PropTypes.func,
+ onDateChange: PropTypes.func,
+ onZoomSelect: PropTypes.func,
+ sliderLabel: PropTypes.string,
+ onPushGIF: PropTypes.func,
+ minDate: PropTypes.object,
+ maxDate: PropTypes.object,
+ hasSubdailyLayers: PropTypes.bool,
+ onClose: PropTypes.func,
+ isPlaying: PropTypes.bool
+};
+
+const getZoomObject = function(dateModel, hasSubDaily) {
+ let zooms = [];
+ let headerText = '';
+ const customText =
+ dateModel.customDelta && dateModel.customInterval
+ ? `${dateModel.customDelta} ${
+ timeScaleFromNumberKey[dateModel.customInterval]
+ }`
+ : 'custom';
+ if (hasSubDaily) {
+ zooms = [customText, 'yearly', 'monthly', 'daily', 'hourly', 'minutely'];
+ } else {
+ zooms = [customText, 'yearly', 'monthly', 'daily'];
+ }
+ if (dateModel.customSelected) {
+ headerText = zooms[0];
+ } else {
+ let interval = dateModel.interval
+ ? dateModel.interval
+ : dateModel.selectedZoom - 1;
+ headerText = zooms[interval];
+ }
+ return {
+ increment: headerText,
+ array: lodashWithout(zooms, headerText)
+ };
+};
diff --git a/web/js/location.js b/web/js/location.js
index e8a8961bf..f910eee94 100644
--- a/web/js/location.js
+++ b/web/js/location.js
@@ -225,13 +225,13 @@ export function getParamObject(
errors
);
if (config.features.animation) {
- animationParamObject = getAnimationParameterSetup(
- parameters,
- config,
- models,
- legacyState,
- errors
- );
+ // animationParamObject = getAnimationParameterSetup(
+ // parameters,
+ // config,
+ // models,
+ // legacyState,
+ // errors
+ // );
}
const dateParamObject = getDateParameterSetup(
parameters,
@@ -243,7 +243,7 @@ export function getParamObject(
const obj = lodashAssign(
{},
dateParamObject,
- animationParamObject,
+ // animationParamObject,
mapParamObject,
getParameters(config, parameters)
);
diff --git a/web/js/modules/animation/actions.js b/web/js/modules/animation/actions.js
new file mode 100644
index 000000000..0a3ce27a3
--- /dev/null
+++ b/web/js/modules/animation/actions.js
@@ -0,0 +1,48 @@
+import {
+ EXIT_ANIMATION,
+ PLAY_ANIMATION,
+ STOP_ANIMATION,
+ UPDATE_FRAME_RATE,
+ TOGGLE_LOOPING,
+ UPDATE_START_DATE,
+ UPDATE_END_DATE
+} from './constants';
+
+export function onClose() {
+ return {
+ type: EXIT_ANIMATION
+ };
+}
+export function play() {
+ return {
+ type: PLAY_ANIMATION
+ };
+}
+export function stop() {
+ return {
+ type: STOP_ANIMATION
+ };
+}
+export function toggleLooping() {
+ return {
+ type: TOGGLE_LOOPING
+ };
+}
+export function changeFrameRate(num) {
+ return {
+ type: UPDATE_FRAME_RATE,
+ value: num
+ };
+}
+export function changeStartDate(date) {
+ return {
+ type: UPDATE_START_DATE,
+ value: date
+ };
+}
+export function changeEndDate(date) {
+ return {
+ type: UPDATE_END_DATE,
+ value: date
+ };
+}
diff --git a/web/js/modules/animation/constants.js b/web/js/modules/animation/constants.js
new file mode 100644
index 000000000..4204513dc
--- /dev/null
+++ b/web/js/modules/animation/constants.js
@@ -0,0 +1,7 @@
+export const EXIT_ANIMATION = 'ANIMATION/EXIT_ANIMATION';
+export const PLAY_ANIMATION = 'ANIMATION/PLAY_ANIMATION';
+export const STOP_ANIMATION = 'ANIMATION/STOP_ANIMATION';
+export const UPDATE_FRAME_RATE = 'ANIMATION/UPDATE_FRAME_RATE';
+export const TOGGLE_LOOPING = 'ANIMATION/TOGGLE_LOOPING';
+export const UPDATE_START_DATE = 'ANIMATION/UPDATE_START_DATE';
+export const UPDATE_END_DATE = 'ANIMATION/UPDATE_END_DATE';
diff --git a/web/js/modules/animation/reducers.js b/web/js/modules/animation/reducers.js
new file mode 100644
index 000000000..a994aed5f
--- /dev/null
+++ b/web/js/modules/animation/reducers.js
@@ -0,0 +1,59 @@
+import { assign as lodashAssign } from 'lodash';
+import util from '../../util/util';
+import {
+ EXIT_ANIMATION,
+ PLAY_ANIMATION,
+ STOP_ANIMATION,
+ UPDATE_FRAME_RATE,
+ TOGGLE_LOOPING,
+ UPDATE_START_DATE,
+ UPDATE_END_DATE
+} from './constants';
+
+const defaultState = {
+ isActive: false,
+ isPlaying: false,
+ loop: false,
+ speed: 3
+};
+export function getInitialState(config) {
+ return lodashAssign({}, defaultState, {
+ startDate: util.dateAdd(new Date(), 'day', -7),
+ endDate: new Date()
+ });
+}
+
+export function animationReducer(state = defaultState, action) {
+ switch (action.type) {
+ case EXIT_ANIMATION:
+ return lodashAssign({}, state, {
+ isActive: false
+ });
+ case PLAY_ANIMATION:
+ return lodashAssign({}, state, {
+ isPlaying: true
+ });
+ case STOP_ANIMATION:
+ return lodashAssign({}, state, {
+ isPlaying: false
+ });
+ case UPDATE_FRAME_RATE:
+ return lodashAssign({}, state, {
+ speed: action.value
+ });
+ case UPDATE_START_DATE:
+ return lodashAssign({}, state, {
+ startDate: action.value
+ });
+ case UPDATE_END_DATE:
+ return lodashAssign({}, state, {
+ endDate: action.value
+ });
+ case TOGGLE_LOOPING:
+ return lodashAssign({}, state, {
+ loop: !state.loop
+ });
+ default:
+ return state;
+ }
+}
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index c70e608c9..9cc68a1e0 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -25,6 +25,10 @@ import {
layerReducer,
getInitialState as getLayersInitialState
} from './layers/reducers';
+import {
+ animationReducer,
+ getInitialState as getAnimationInitialState
+} from './animation/reducers';
import { paletteReducer, getInitialPaletteState } from './palettes/reducers';
import dataDownloadReducer from './data/reducers';
import { get as lodashGet } from 'lodash';
@@ -57,6 +61,7 @@ export function getInitialState(models, config, parameters) {
config,
models,
legacy: models,
+ animation: getAnimationInitialState(config),
proj: getProjInitialState(config),
layers: getLayersInitialState(config),
requestedEvents: eventRequestResponse(eventsIgnoreArray),
@@ -84,6 +89,7 @@ const reducers = {
palettes: paletteReducer,
tour: tourReducer,
map: mapReducer,
+ animation: animationReducer,
requestedEvents,
requestedEventSources,
requestedEventCategories,