Interactive interface for browsing global, full-resolution satellite imagery
add helper date format function to handle subdaily and remove seconds from date tool tip text
Ed Plato25ef3ce8380b
diff --git a/web/js/components/timeline/timeline-axis/date-tooltip/date-tooltip.js b/web/js/components/timeline/timeline-axis/date-tooltip/date-tooltip.jsindex 89e32befd..5076dc15b 100644--- a/web/js/components/timeline/timeline-axis/date-tooltip/date-tooltip.js+++ b/web/js/components/timeline/timeline-axis/date-tooltip/date-tooltip.js@@ -2,6 +2,29 @@ import React, { PureComponent } from 'react';import PropTypes from 'prop-types';import { getDaysInYear } from '../../date-util';+/**+* @desc helper function to format date string for tooltip display+* @param {String} time+* @param {Boolean} hasSubdailyLayers+* @returns {String} formatted yearMonthDay -OR- yearMonthDayHourMin (subdaily)+*/+const getToolTipTime = (time, hasSubdailyLayers) => {+ const timeSplit = time.split('T');+ const yearMonthDay = timeSplit[0];++ // if no subdaily, return YEAR-MON-DAY / 2020-02-15+ if (!hasSubdailyLayers) {+ return yearMonthDay;+ }++ const hourMinSecZ = timeSplit[1].split(':');+ const hourMinZ = [hourMinSecZ[0], hourMinSecZ[1]].join(':') + 'Z';+ const yearMonthDayHourMin = yearMonthDay + ' ' + hourMinZ;++ // if subdaily, return YEAR-MON-DAY HOUR-MIN-Z / 2020-02-15 18:00Z+ return yearMonthDayHourMin;+};+/** Date tooltip for hover and draggers*@@ -32,10 +55,11 @@ class DateToolTip extends PureComponent {let toolTipDayOfYear;let toolTipDisplay;- if (showDraggerToolTip) { // handle dragger tooltip- // determine A or B dragger and set variables+ if (showDraggerToolTip) {+ // handle dragger tooltiplet draggerTime;let position;+ // determine A or B dragger and set variablesif (draggerSelected === 'selected') {draggerTime = draggerTimeState;position = draggerPosition;@@ -43,31 +67,30 @@ class DateToolTip extends PureComponent {draggerTime = draggerTimeStateB;position = draggerPositionB;}- toolTipLeftOffest = position - (hasSubdailyLayers ? 87 : 35);- toolTipDate = hasSubdailyLayers ? draggerTime.split('T').join(' ') : draggerTime.split('T')[0];+ toolTipLeftOffest = position - (hasSubdailyLayers ? 68 : 35);+ toolTipDate = getToolTipTime(draggerTime, hasSubdailyLayers);toolTipDayOfYear = getDaysInYear(draggerTime);toolTipDisplay = position > -49 && position < axisWidth - 49 ? 'block' : 'none';- } else if (showHoverToolTip) { // handle hover tooltip- toolTipLeftOffest = hasSubdailyLayers ? leftOffset - 136 : leftOffset - 84;- toolTipDate = hasSubdailyLayers ? hoverTime.split('T').join(' ') : hoverTime.split('T')[0];+ } else if (showHoverToolTip) {+ // handle hover tooltip+ toolTipLeftOffest = hasSubdailyLayers ? leftOffset - 117 : leftOffset - 84;+ toolTipDate = getToolTipTime(hoverTime, hasSubdailyLayers);toolTipDayOfYear = getDaysInYear(hoverTime);toolTipDisplay = 'block';}return (<React.Fragment>- {- (showDraggerToolTip) || (showHoverToolTip)- ? <div- className="date-tooltip"- style={{- transform: `translate(${toolTipLeftOffest}px, -100px)`,- display: toolTipDisplay,- width: hasSubdailyLayers ? '270px' : '165px'- }}- >- { toolTipDate } <span className="date-tooltip-day">({ toolTipDayOfYear })</span>- </div>- : null+ { (showDraggerToolTip || showHoverToolTip) &&+ <div+ className="date-tooltip"+ style={{+ transform: `translate(${toolTipLeftOffest}px, -100px)`,+ display: toolTipDisplay,+ width: hasSubdailyLayers ? '232px' : '165px'+ }}+ >+ { toolTipDate } <span className="date-tooltip-day">({ toolTipDayOfYear })</span>+ </div>}</React.Fragment>);