Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix bugs with A|B dragger label #1118

Benjamin King2e16ae2476bd
diff --git a/web/js/components/range-selection/dragger.js b/web/js/components/range-selection/dragger.js
index 6a8bba136..cef995339 100644
--- a/web/js/components/range-selection/dragger.js
+++ b/web/js/components/range-selection/dragger.js
@@ -167,7 +167,9 @@ class TimelineDragger extends React.Component {
<Draggable
onDrag={this.handleDrag.bind(this)}
position={{ x: this.state.position, y: this.props.yOffset }}
- onStop={this.props.onStop}
+ onStop={() => {
+ this.props.onStop(this.props.id, this.state.position);
+ }}
axis="x"
>
<g>
diff --git a/web/js/date/compare-picks.js b/web/js/date/compare-picks.js
index b44cc2d77..6ca643b8d 100644
--- a/web/js/date/compare-picks.js
+++ b/web/js/date/compare-picks.js
@@ -3,16 +3,15 @@ import ReactDOM from 'react-dom';
import TimelineDragger from '../components/range-selection/dragger';
import { getMaxTimelineWidth } from './util';
import $ from 'jquery';
-import lodashThrottle from 'lodash/throttle';
+import lodashDebounce from 'lodash/debounce';
import util from '../util/util';
-const THROTTLE_TIME = 100;
+const DEBOUNCE_TIME = 100;
const PICK_PATH =
'M 7.3151,0.7426 C 3.5507,0.7426 0.5,3.7926 0.5,7.5553 l 0,21.2724 14.6038,15.7112 14.6039,15.7111 14.6038,-15.7111 14.6037,-15.7112 0,-21.2724 c 0,-3.7627 -3.051,-6.8127 -6.8151,-6.8127 l -44.785,0 z';
export function timelineCompare(models, config, ui) {
var self = {};
var xmlns = 'http://www.w3.org/2000/svg';
-
var timeline = ui.timeline;
var $footer = $('#timeline-footer');
var $header = $('#timeline-header');
@@ -20,6 +19,8 @@ export function timelineCompare(models, config, ui) {
var mountObjectA;
var mountObjectB;
var parentSvg;
+ var max;
+ self.events = util.events();
if (models.compare.active) {
$timeline.addClass('ab-active');
}
@@ -51,9 +52,14 @@ export function timelineCompare(models, config, ui) {
models.date.events
.on('timeline-change', updateState)
.on('select', updateState);
+ self.events
+ .on('drag', showPickHoverDate)
+ .on('drag', debounceDateSelect)
+ .on('drag-end', dateSelect)
+ .on('drag-end', removeTicks);
};
var setMax = function() {
- var max = getMaxTimelineWidth(ui);
+ max = getMaxTimelineWidth(ui);
self.comparePickA.setState({
max: max
});
@@ -77,17 +83,22 @@ export function timelineCompare(models, config, ui) {
models.compare.toggleState();
};
var getInitialProps = function(compareLetter, label) {
+ max = getMaxTimelineWidth(ui);
return {
id: 'selected' + compareLetter,
- onDrag: lodashThrottle(onDrag, THROTTLE_TIME),
- onStop: onDragEnd,
+ onDrag: (e, id, position) => {
+ self.events.trigger('drag', e, id, position);
+ },
+ onStop: (id, position) => {
+ self.events.trigger('drag-end', null, id, position);
+ },
yOffset: 15,
path: PICK_PATH,
height: 59.51,
width: 58.42,
textColor: null,
color: null,
- max: getMaxTimelineWidth(ui),
+ max: max,
draggerID: 'compare-dragger-' + compareLetter,
position: getLocationFromStringDate(
models.date['selected' + compareLetter]
@@ -122,6 +133,19 @@ export function timelineCompare(models, config, ui) {
var getLocationFromStringDate = function(date) {
return timeline.x(util.roundTimeTenMinute(date));
};
+ var dateSelect = function(e, id, offsetX) {
+ var position = offsetX;
+ if (position > max) {
+ position = max - 10;
+ } else if (position <= 0) {
+ position = 5;
+ }
+ var date = timeline.x.invert(position);
+ if (models.date[id] !== date) {
+ models.date.select(date, id);
+ }
+ };
+ var debounceDateSelect = lodashDebounce(dateSelect, DEBOUNCE_TIME);
/*
* Handles click on widget:
* switches current date to
@@ -135,12 +159,13 @@ export function timelineCompare(models, config, ui) {
* @returns {object} props
*
*/
- var onDrag = function(e, id, offsetX) {
- var date = timeline.x.invert(offsetX);
- ui.timeline.pick.hoverDate(date, true);
- models.date.select(date, id);
+ var showPickHoverDate = function(e, id, offsetX) {
+ if (offsetX < max && offsetX > 0) {
+ let date = timeline.x.invert(offsetX);
+ ui.timeline.pick.hoverDate(date, true);
+ }
};
- var onDragEnd = function() {
+ var removeTicks = function() {
ui.timeline.ticks.label.remove();
};
init();
diff --git a/web/js/date/timeline-pick.js b/web/js/date/timeline-pick.js
index 351e61745..fcb192567 100644
--- a/web/js/date/timeline-pick.js
+++ b/web/js/date/timeline-pick.js
@@ -133,6 +133,7 @@ export function timelinePick(models, config, ui) {
// Pan the timeline if the pick is dragged off the side
// or if the date input goes outside of the shown range
self.shiftView = function() {
+ if (models.compare && models.compare.active) return;
var zt = tl.pan.xPosition;
var activeDate = model[model.activeDate];
if (tl.x(activeDate) >= tl.width - 15) {
diff --git a/web/js/date/timeline-ticks.js b/web/js/date/timeline-ticks.js
index ae547bf48..5d4846888 100644
--- a/web/js/date/timeline-ticks.js
+++ b/web/js/date/timeline-ticks.js
@@ -383,14 +383,14 @@ export function timelineTicks(models, config, ui) {
};
self.label = { // TODO: Update, this is just copied over
- show: function (d) {
+ show: function (d, isAlternativeDragger) {
var $boundaryTick;
var tick;
if (this) tick = this.parentNode;
var boundaryTick, boundaryTickWidth;
// Using jquery to precise select as it's easier than d3
- if (d3.select(tick)
+ if (tick && d3.select(tick)
.classed('tick-labeled')) {
$boundaryTick = $(tick);
} else {