Interactive interface for browsing global, full-resolution satellite imagery
add draggable functionality to gif animation timeline dragger range
Ed Platod3d8fc2b65dc
diff --git a/web/js/components/range-selection/dragger-range.js b/web/js/components/range-selection/dragger-range.jsindex e5693d040..819ae89c6 100644--- a/web/js/components/range-selection/dragger-range.js+++ b/web/js/components/range-selection/dragger-range.js@@ -1,5 +1,6 @@import React from 'react';import PropTypes from 'prop-types';+import Draggable from 'react-draggable';/** A react component, is a draggable svg* rect element@@ -12,10 +13,20 @@ class TimelineDraggerRange extends React.Component {*/constructor(props) {super(props);- this.opacity = {- fillOpacity: this.props.opacity+ this.state = {+ width: 0,+ startLocation: this.props.startLocation,+ endLocation: this.props.endLocation,+ previousStartLocation: this.props.startLocation};}+ /*+ * Resize timeline dragger width+ *+ * @method checkWidth+ *+ * @return {void}+ */checkWidth() {var start = this.props.startLocation;var end = this.props.endLocation;@@ -32,10 +43,10 @@ class TimelineDraggerRange extends React.Component {if (width < 0) {width = 0;}- this.state = {+ this.setState({width: width,startLocation: start- };+ });}/** When the component is dragged,@@ -45,28 +56,118 @@ class TimelineDraggerRange extends React.Component {** @method handleDrag*+ * @param {object} e - event object+ * @param {object} d - Draggable object+ ** @return {void}*/handleDrag(e, d) {+ e.preventDefault();e.stopPropagation();- this.props.onDrag(d.deltaX);+ // +/- {number} - change in x - set to 0 to 'stop' dragger movement+ let deltaX = d.deltaX;+ // +/- {number} - start position+ let deltaStart = d.x;++ // timeline dragger dragged into the future (to the right)+ if (deltaX > 0) {+ // timeline dragger dragged to max future of current viewable timeline+ if (this.props.endLocation >= this.props.max) {+ deltaX = 0;+ }+ if (this.props.endLocation > this.props.max - deltaX) {+ deltaX = 0;+ }+ // timeline dragger dragged into the past (to the left)+ } else {+ // timeline dragger dragged to min past of current viewable timeline+ if (this.props.startLocation + deltaX <= 0) {+ deltaX = 0;+ }+ }+ this.props.onDrag(deltaX, deltaStart, this.props.id);}+ /*+ * 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) {+ return -this.props.deltaStart;+ } else {+ return this.props.startLocation - this.props.deltaStart;+ }+ }++ /*+ * 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)) {+ this.props.onClick(e);+ } else {+ this.setState({ previousStartLocation: this.state.startLocation });+ }+ }++ componentDidMount () {+ this.checkWidth();+ }++ // update state - used in componentDidUpdate+ updateExtent(nextProps) {+ this.setState({+ startLocation: nextProps.startLocation,+ endLocation: nextProps.endLocation+ });+ }++ componentDidUpdate (prevProps) {+ // update state and checkWidth only on startLocation and/or endLocation changes+ if (prevProps.startLocation !== this.props.startLocation || prevProps.endLocation !== this.props.endLocation) {+ this.updateExtent(this.props);+ this.checkWidth();+ }+ }/** @method render*/render() {- this.checkWidth();return (- <rect- x={this.state.startLocation}- fill={this.props.color}- width={this.state.width}- style={this.opacity}- height={this.props.height}- className='dragger-range'- onClick={this.props.onClick}- />+ <Draggable+ handle=".dragger-range"+ axis="x"+ position={null}+ defaultPosition={{ x: 0, y: 0 }}+ onStop={this.props.onStop}+ onDrag={this.handleDrag.bind(this)}+ >+ <rect+ x={this.handleStartPositionRestriction()}+ fill={this.props.color}+ width={this.state.width}+ style={{+ fillOpacity: this.props.opacity,+ cursor: 'pointer'+ }}+ height={this.props.height}+ className='dragger-range'+ id={this.props.draggerID}+ onClick={this.handleDraggerClick.bind(this)}+ />+ </Draggable>);}}@@ -75,11 +176,16 @@ TimelineDraggerRange.propTypes = {opacity: PropTypes.number,startLocation: PropTypes.number,endLocation: PropTypes.number,+ deltaStart: PropTypes.number,max: PropTypes.number,height: PropTypes.number,- onDrag: PropTypes.func,+ width: PropTypes.number,+ color: PropTypes.string,+ draggerID: PropTypes.string,onClick: PropTypes.func,- color: PropTypes.string+ onDrag: PropTypes.func,+ onStop: PropTypes.func,+ id: PropTypes.string};export default TimelineDraggerRange;diff --git a/web/js/components/range-selection/range-selection.js b/web/js/components/range-selection/range-selection.jsindex 9b969903d..d542e1e0f 100644--- a/web/js/components/range-selection/range-selection.js+++ b/web/js/components/range-selection/range-selection.js@@ -19,7 +19,8 @@ class TimelineRangeSelector extends React.Component {this.state = {startLocation: props.startLocation,endLocation: props.endLocation,- max: props.max+ max: props.max,+ deltaStart: 0};}componentWillReceiveProps(props) {@@ -83,7 +84,6 @@ class TimelineRangeSelector extends React.Component {endLocation: endX});}-/** Send callback with new locations on* Drag Stop@@ -95,29 +95,56 @@ class TimelineRangeSelector extends React.Component {onDragStop() {this.props.onDrag(this.state.startLocation, this.state.endLocation);}- onRangeClick(d) {- this.props.onRangeClick(d.nativeEvent);+ /*+ * Send callback with click event+ *+ * @method onRangeClick+ *+ * @param {object} d - proxy click event object+ *+ * @return {void}+ */+ onRangeClick(e) {+ this.props.onRangeClick(e.nativeEvent);+ }+ /*+ * Update state based on distance range was dragged+ *+ * @method onRangeDrag+ *+ * @param {number} d - change in x+ * @param {number} deltaStart - delta start to track changes+ *+ * @return {void}+ */+ onRangeDrag(d, deltaStart) {+ this.setState({+ startLocation: this.state.startLocation + d,+ endLocation: this.state.endLocation + d,+ deltaStart: deltaStart+ });+ this.props.onDrag(this.state.startLocation, this.state.endLocation);}/** @method render*/render() {return (- <svg- id="wv-timeline-range-selector"- className="wv-timeline-range-selector"- >+ <svg id="wv-timeline-range-selector" className="wv-timeline-range-selector"><DraggerRange- width={this.props.pinWidth}- endLocation={this.state.endLocation}opacity={this.props.rangeOpacity}- color={this.props.rangeColor}+ startLocation={this.state.startLocation}+ endLocation={this.state.endLocation}+ deltaStart={this.state.deltaStart}+ max={this.state.max}height={this.props.height}- startLocation={this.state.startLocation + this.props.pinWidth}+ width={this.props.pinWidth}+ color={this.props.rangeColor}+ draggerID='range-selector-range'onClick={this.onRangeClick.bind(this)}- max={this.state.max}- id="range"- />+ onDrag={this.onRangeDrag.bind(this)}+ onStop={this.onDragStop.bind(this)}+ id='range'/><Draggerposition={this.state.startLocation}color={this.props.startColor}@@ -126,11 +153,10 @@ class TimelineRangeSelector extends React.Component {onDrag={this.onItemDrag.bind(this)}onStop={this.onDragStop.bind(this)}max={this.state.max}- draggerID="range-selector-dragger-1"+ draggerID='range-selector-dragger-1'backgroundColor={this.props.startTriangleColor}first={true}- id="start"- />+ id='start' /><Draggermax={this.state.max}position={this.state.endLocation}@@ -138,12 +164,11 @@ 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>);}