Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

refactor to allow range dragging if one or both draggers are not in view of the timeline

Ed Platobc7d064d08bc
diff --git a/web/js/animation/range-select.js b/web/js/animation/range-select.js
index 82d22826e..628daafb2 100644
--- a/web/js/animation/range-select.js
+++ b/web/js/animation/range-select.js
@@ -13,6 +13,14 @@ export function animationRangeSelect(models, config, ui) {
var $header = $('#timeline-header');
var $timeline = $('#timeline');
+ // get timeline min/max date, zero out end date, and format to ISO
+ var timelineStartDateLimit = config.startDate;
+ var timelineEndDateLimit = models.layers.lastDate().toISOString();
+ // endDateLimit used in limiting updateRange
+ let endDateLimit = models.layers.lastDate();
+ endDateLimit.setHours(0, 0, 0, 0);
+ timelineEndDateLimit = endDateLimit.toISOString();
+
/*
* set listeners and initiates
* widget
@@ -84,6 +92,10 @@ export function animationRangeSelect(models, config, ui) {
options = {
startLocation: startLocation, // or zero
endLocation: endLocation,
+ startLocationDate: model.rangeState.startDate,
+ endLocationDate: model.rangeState.endDate,
+ timelineStartDateLimit: timelineStartDateLimit,
+ timelineEndDateLimit: timelineEndDateLimit,
max: self.getMaxWidth(),
startColor: '#40a9db',
endColor: '#295f92',
@@ -156,16 +168,31 @@ export function animationRangeSelect(models, config, ui) {
* @method getMaxWidth
* @static
*
- * @returns {number} max width
+ * @returns {object} maxWidth
*
*/
self.getMaxWidth = function() {
- var $elWidth = $footer.width();
- var $dataWidth = timeline.x(timeline.data.end());
- if ($elWidth > $dataWidth) {
- return $dataWidth;
+ // end of timeline
+ let $dataWidth = timeline.x(timeline.data.end());
+ // start of timeline
+ let $dataStart = timeline.x(timeline.data.start());
+ // default start/end false
+ let maxWidth = {
+ width: $footer.width(),
+ startOffset: $dataStart,
+ start: false,
+ end: false
+ };
+ // end of timeline in view
+ if (maxWidth.width > $dataWidth) {
+ maxWidth.width = $dataWidth;
+ maxWidth.end = true;
+ }
+ // start of timeline in view
+ if ($dataStart > 0) {
+ maxWidth.start = true;
}
- return $elWidth;
+ return maxWidth;
};
/*
@@ -182,6 +209,8 @@ export function animationRangeSelect(models, config, ui) {
var props = {};
props.startLocation = self.getLocationFromStringDate(state.startDate);
props.endLocation = self.getLocationFromStringDate(state.endDate);
+ props.startLocationDate = state.startDate;
+ props.endLocationDate = state.endDate;
props.max = self.getMaxWidth();
return props;
@@ -225,7 +254,15 @@ export function animationRangeSelect(models, config, ui) {
var endDate = util.roundTimeTenMinute(timeline.x.invert(EndLocation));
var state = model.rangeState;
state.startDate = util.toISOStringSeconds(startDate) || 0;
- state.endDate = util.toISOStringSeconds(endDate);
+ // prevent endDate overdrag from occuring in monthly/yearly by setting to max date limit
+ if (models.date.selectedZoom < 3) {
+ state.endDate = endDate <= endDateLimit
+ ? util.toISOStringSeconds(endDate)
+ : util.toISOStringSeconds(endDateLimit);
+ } else {
+ state.endDate = util.toISOStringSeconds(endDate);
+ }
+
model.rangeState.playing = false;
model.events.trigger('change');
model.events.trigger('datechange');
diff --git a/web/js/components/range-selection/dragger-range.js b/web/js/components/range-selection/dragger-range.js
index 819ae89c6..66bb09cc8 100644
--- a/web/js/components/range-selection/dragger-range.js
+++ b/web/js/components/range-selection/dragger-range.js
@@ -30,7 +30,7 @@ class TimelineDraggerRange extends React.Component {
checkWidth() {
var start = this.props.startLocation;
var end = this.props.endLocation;
- var max = this.props.max;
+ var max = this.props.max.width;
var width;
if (start < 0) {
@@ -64,30 +64,95 @@ class TimelineDraggerRange extends React.Component {
handleDrag(e, d) {
e.preventDefault();
e.stopPropagation();
- // +/- {number} - change in x - set to 0 to 'stop' dragger movement
- let deltaX = d.deltaX;
+ // +/- {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);
// +/- {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);
+ 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));
+ // match end date precise time units to dragging end date
+ let timelineEndDateLimitMatch = new Date(
+ timelineEndDate.getFullYear(),
+ timelineEndDate.getMonth(),
+ timelineEndDate.getDate(),
+ endLocationDate.getHours(),
+ endLocationDate.getMinutes()
+ );
+ // match buffer date precise time units to dragging end date - calculated endDateToLimitDifference used dynamically
+ // to change buffer dates of when to limit deltaX and therefore slow down dragger speed
+ let timelineMaxDateBufferMatch = new Date(
+ timelineEndDate.getFullYear(),
+ timelineEndDate.getMonth(),
+ timelineEndDate.getDate() - Math.abs(endDateToLimitDifference),
+ endLocationDate.getHours(),
+ endLocationDate.getMinutes()
+ );
+
+ // format dates to ISO for comparison
+ endLocationDate = endLocationDate.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) {
- // 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) {
+ // stop dragger if reached end date
+ if (endLocationDate >= timelineEndDateLimitMatch) {
deltaX = 0;
+ } else {
+ // if end of timeline date is within view - rely on max
+ if (this.props.max.end) {
+ // timeline dragger dragged to max future of current viewable timeline
+ if (this.props.endLocation >= this.props.max.width) {
+ deltaX = 0;
+ }
+ if (this.props.endLocation > this.props.max.width - deltaX) {
+ deltaX = 0;
+ }
+ // 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) {
+ deltaX = Math.min(deltaX, Math.abs(endDateToLimitDifference * 2));
+ }
+ }
}
// 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;
+ 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) {
+ deltaX = 0;
+ }
}
}
this.props.onDrag(deltaX, deltaStart, this.props.id);
}
+ /*
+ * 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());
+
+ return Math.floor((utc2 - utc1) / msPerDay);
+ }
+
/*
* Handle dragging timeline and syncing start position of dragger range
* used in rect to return x
@@ -176,8 +241,12 @@ TimelineDraggerRange.propTypes = {
opacity: PropTypes.number,
startLocation: PropTypes.number,
endLocation: PropTypes.number,
+ startLocationDate: PropTypes.string,
+ endLocationDate: PropTypes.string,
+ timelineStartDateLimit: PropTypes.string,
+ timelineEndDateLimit: PropTypes.string,
deltaStart: PropTypes.number,
- max: PropTypes.number,
+ max: PropTypes.object,
height: PropTypes.number,
width: PropTypes.number,
color: PropTypes.string,
diff --git a/web/js/components/range-selection/range-selection.js b/web/js/components/range-selection/range-selection.js
index d542e1e0f..d11ad1fa9 100644
--- a/web/js/components/range-selection/range-selection.js
+++ b/web/js/components/range-selection/range-selection.js
@@ -19,6 +19,8 @@ class TimelineRangeSelector extends React.Component {
this.state = {
startLocation: props.startLocation,
endLocation: props.endLocation,
+ startLocationDate: props.startLocationDate,
+ endLocationDate: props.endLocationDate,
max: props.max,
deltaStart: 0
};
@@ -27,6 +29,8 @@ class TimelineRangeSelector extends React.Component {
this.setState({
startLocation: props.startLocation,
endLocation: props.endLocation,
+ startLocationDate: props.startLocationDate,
+ endLocationDate: props.endLocationDate,
max: props.max
});
}
@@ -55,7 +59,7 @@ class TimelineRangeSelector extends React.Component {
return;
}
if (startX + this.props.pinWidth >= endX) {
- if (startX + this.props.pinWidth >= this.state.max) {
+ if (startX + this.props.pinWidth >= this.state.max.width) {
return;
} else {
endX = startX + this.props.pinWidth;
@@ -64,7 +68,7 @@ class TimelineRangeSelector extends React.Component {
} else if (id === 'end') {
startX = this.state.startLocation;
endX = deltaX + this.state.endLocation;
- if (endX > this.state.max || startX > endX) {
+ if (endX > this.state.max.width || startX > endX) {
return;
}
if (startX + 2 * this.props.pinWidth >= endX) {
@@ -73,7 +77,7 @@ class TimelineRangeSelector extends React.Component {
} else {
startX = deltaX + this.state.startLocation;
endX = deltaX + this.state.endLocation;
- if (endX >= this.state.max || startX < 0) {
+ if (endX >= this.state.max.width || startX < 0) {
return;
}
}
@@ -135,6 +139,10 @@ class TimelineRangeSelector extends React.Component {
opacity={this.props.rangeOpacity}
startLocation={this.state.startLocation}
endLocation={this.state.endLocation}
+ startLocationDate={this.state.startLocationDate}
+ endLocationDate={this.state.endLocationDate}
+ timelineStartDateLimit={this.props.timelineStartDateLimit}
+ timelineEndDateLimit={this.props.timelineEndDateLimit}
deltaStart={this.state.deltaStart}
max={this.state.max}
height={this.props.height}
@@ -152,13 +160,13 @@ class TimelineRangeSelector extends React.Component {
height={this.props.height}
onDrag={this.onItemDrag.bind(this)}
onStop={this.onDragStop.bind(this)}
- max={this.state.max}
+ max={this.state.max.width}
draggerID='range-selector-dragger-1'
backgroundColor={this.props.startTriangleColor}
first={true}
id='start' />
<Dragger
- max={this.state.max}
+ max={this.state.max.width}
position={this.state.endLocation}
color={this.props.endColor}
width={this.props.pinWidth}
@@ -177,7 +185,11 @@ class TimelineRangeSelector extends React.Component {
TimelineRangeSelector.propTypes = {
startLocation: PropTypes.number,
endLocation: PropTypes.number,
- max: PropTypes.number,
+ startLocationDate: PropTypes.string,
+ endLocationDate: PropTypes.string,
+ timelineStartDateLimit: PropTypes.string,
+ timelineEndDateLimit: PropTypes.string,
+ max: PropTypes.object,
pinWidth: PropTypes.number,
height: PropTypes.number,
onDrag: PropTypes.func,