Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Make A|B use same guitar-pick #1328 #1327

Benjamin Kingbf515e14d561
diff --git a/web/css/timeline.css b/web/css/timeline.css
index 61fd3940e..54ff6b2b1 100644
--- a/web/css/timeline.css
+++ b/web/css/timeline.css
@@ -604,5 +604,5 @@ g.plot rect.data-bar-invisible {
display: block;
}
.ab-active #guitarpick {
- display: none;
+ opacity: 0;
}
diff --git a/web/js/components/compare/pick.js b/web/js/components/compare/pick.js
new file mode 100644
index 000000000..8ccd46eae
--- /dev/null
+++ b/web/js/components/compare/pick.js
@@ -0,0 +1,81 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import lodashRound from 'lodash/round';
+
+class Pick extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ position: props.position,
+ visibility: props.visibility,
+ color: props.color,
+ max: props.max
+ };
+ }
+ /**
+ * Return visibility style string
+ */
+ getVisibility() {
+ var visibility = 'visible';
+ if (this.state.position < 0 || this.state.position > this.state.max) {
+ visibility = 'hidden';
+ }
+ return visibility;
+ }
+ /**
+ * Return text el to show over dragger
+ * @param {number} x | x offset
+ * @param {number} y | y offset
+ */
+ getText(x, y, visibility) {
+ if (this.props.text) {
+ return (
+ <text
+ x={x}
+ y={y}
+ alignmentBaseline="middle"
+ textAnchor="middle"
+ style={{
+ fill: this.state.textColor ? this.state.textColor : null,
+ visibility: visibility || null
+ }}
+ >
+ {this.props.text}
+ </text>
+ );
+ }
+ }
+ render() {
+ var visibility = this.getVisibility();
+ const { yOffset, path, width, height } = this.props;
+ const { position } = this.state;
+ var translate = 'translate(' + position + ',' + yOffset + ')';
+ return (
+ <g transform={translate}>
+ <path
+ style={{
+ fill: this.props.color ? this.props.color : null,
+ visibility: visibility
+ }}
+ d={path}
+ transform={'translate(' + -width / 2 + ', ' + -height / 4 + ')'}
+ />
+ {this.getText(-5, lodashRound(height / 6, 4), visibility)}
+ </g>
+ );
+ }
+}
+
+Pick.propTypes = {
+ position: PropTypes.number,
+ height: PropTypes.number,
+ width: PropTypes.number,
+ path: PropTypes.string,
+ visibility: PropTypes.string,
+ color: PropTypes.string,
+ text: PropTypes.string,
+ yOffset: PropTypes.number,
+ max: PropTypes.number
+};
+
+export default Pick;
diff --git a/web/js/date/compare-picks.js b/web/js/date/compare-picks.js
index b64dfb095..90108db05 100644
--- a/web/js/date/compare-picks.js
+++ b/web/js/date/compare-picks.js
@@ -1,12 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
-import TimelineDragger from '../components/range-selection/dragger';
+import TimelineDragger from '../components/compare/pick';
import { getMaxTimelineWidth } from './util';
import $ from 'jquery';
-import lodashDebounce from 'lodash/debounce';
import util from '../util/util';
-const DEBOUNCE_TIME = 50;
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) {
@@ -26,13 +24,15 @@ export function timelineCompare(models, config, ui) {
}
var init = function() {
const START_EVENT = util.browser.touchDevice ? 'touchstart' : 'mousedown';
+ var guitarPick = document.getElementById('guitarpick');
mountObjectA = document.createElementNS(xmlns, 'g');
mountObjectB = document.createElementNS(xmlns, 'g');
mountObjectA.addEventListener(START_EVENT, toggleCheck);
mountObjectB.addEventListener(START_EVENT, toggleCheck);
parentSvg = document.getElementById('timeline-footer-svg');
- parentSvg.appendChild(mountObjectA);
- parentSvg.appendChild(mountObjectB);
+
+ parentSvg.insertBefore(mountObjectA, guitarPick);
+ parentSvg.insertBefore(mountObjectB, guitarPick);
applyActiveClasses();
self.comparePickA = ReactDOM.render(
React.createElement(TimelineDragger, getInitialProps('', 'A')),
@@ -53,11 +53,6 @@ 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() {
max = getMaxTimelineWidth(ui);
@@ -92,21 +87,10 @@ export function timelineCompare(models, config, ui) {
var getInitialProps = function(compareLetter, label) {
max = getMaxTimelineWidth(ui);
return {
- id: 'selected' + compareLetter,
- onDrag: (e, id, position) => {
- self.events.trigger('drag', e, id, position);
- },
-
- onStop: (id, position) => {
- self.dragging = false;
- self.events.trigger('drag-end', null, id, position);
- },
yOffset: 15,
path: PICK_PATH,
height: 59.51,
width: 58.42,
- textColor: null,
- color: null,
max: max,
draggerID: 'compare-dragger-' + compareLetter,
position: getLocationFromStringDate(
@@ -142,45 +126,6 @@ export function timelineCompare(models, config, ui) {
var getLocationFromStringDate = function(date) {
return timeline.x(util.roundTimeTenMinute(date));
};
- var dateSelect = function(e, id, offsetX) {
- const padding = 10;
- var position = offsetX;
- if (position > max - padding) {
- position = max - padding;
- } else if (position <= padding) {
- position = padding;
- }
- var date = timeline.x.invert(position);
- if (models.date[id] !== date && util.isValidDate(date)) {
- models.date.select(date, id);
- } else {
- models.date.select(models.date[id], id);
- }
- };
- var debounceDateSelect = lodashDebounce(dateSelect, DEBOUNCE_TIME);
- /*
- * Handles click on widget:
- * switches current date to
- * date clicked
- *
- * @method onRangeClick
- * @static
- *
- * @param e {object} native event object
- *
- * @returns {object} props
- *
- */
- var showPickHoverDate = function(e, id, offsetX) {
- if (offsetX < max - 5 && offsetX > 5) {
- let date = timeline.x.invert(offsetX);
- ui.timeline.pick.hoverDate(date, true);
- }
- };
- var removeTicks = function() {
- ui.timeline.ticks.label.remove();
- updateState();
- };
init();
return self;
}
diff --git a/web/js/date/timeline-pick.js b/web/js/date/timeline-pick.js
index 61eae6c6b..633b70a05 100644
--- a/web/js/date/timeline-pick.js
+++ b/web/js/date/timeline-pick.js
@@ -133,7 +133,6 @@ 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) {
@@ -154,6 +153,7 @@ export function timelinePick(models, config, ui) {
tl.pan.xPosition = tl.axisZoom.translate()[0];
tl.pan.axis();
}
+
$('#guitarpick').removeClass('hidden');
};