Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-4034: Modernize timeline (#6655)

vicgonzalez25f085308e369d
diff --git a/web/js/components/timeline/timeline-controls/date-change-arrows.js b/web/js/components/timeline/timeline-controls/date-change-arrows.js
index ca86080f8..3e35b431f 100644
--- a/web/js/components/timeline/timeline-controls/date-change-arrows.js
+++ b/web/js/components/timeline/timeline-controls/date-change-arrows.js
@@ -1,4 +1,4 @@
-import { PureComponent } from 'react';
+import { useEffect, useRef, useCallback } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { ArrowChevronLeft, ArrowChevronRight } from '@edsc/earthdata-react-icons/horizon-design-system/hds/ui';
@@ -12,153 +12,153 @@ import {
const ANIMATION_DELAY = 600; // interval for timestep
const CLICK_HOLD_DELAY = 200; // wait before click is considered a hold
-let arrowDownCheckTimer = null;
-// left/right arrow intervals
-const intervals = {
- left: 0,
- right: 0,
-};
-
-class DateChangeArrows extends PureComponent {
- constructor(props) {
- super(props);
- this.arrowDownMap = {
- left: props.leftArrowDown,
- right: props.rightArrowDown,
- };
- }
-
- componentDidUpdate (prevProps) {
- const { tilesPreloaded, arrowDown } = this.props;
- const notAnimating = !intervals.left && !intervals.right;
+function DateChangeArrows(props) {
+ const {
+ handleSelectNowButton,
+ isMobile,
+ leftArrowDisabled,
+ leftArrowDown: leftArrowDownProp,
+ nowButtonDisabled,
+ rightArrowDisabled,
+ rightArrowDown: rightArrowDownProp,
+ arrowDown,
+ tilesPreloaded,
+ isKioskModeActive,
+ isEmbedModeActive,
+ setArrowDown,
+ setArrowUp,
+ } = props;
+
+ const intervalsRef = useRef({ left: 0, right: 0 });
+ const arrowDownCheckTimerRef = useRef(null);
+
+ // Refs to always access the latest callbacks
+ const leftArrowDownRef = useRef(leftArrowDownProp);
+ leftArrowDownRef.current = leftArrowDownProp;
+ const rightArrowDownRef = useRef(rightArrowDownProp);
+ rightArrowDownRef.current = rightArrowDownProp;
+
+ const arrowDownMap = useCallback((direction) => {
+ if (direction === 'left') {
+ leftArrowDownRef.current();
+ } else {
+ rightArrowDownRef.current();
+ }
+ }, []);
+ // Start click-and-hold interval when tiles are preloaded and arrow is held
+ useEffect(() => {
+ const notAnimating = !intervalsRef.current.left && !intervalsRef.current.right;
if (tilesPreloaded && arrowDown && notAnimating) {
- // set interval for holding arrow down
- intervals[arrowDown] = setInterval(this.arrowDownMap[arrowDown], ANIMATION_DELAY);
+ intervalsRef.current[arrowDown] = setInterval(
+ () => arrowDownMap(arrowDown),
+ ANIMATION_DELAY,
+ );
}
- }
-
- componentWillUnmount() {
- clearInterval(intervals.left);
- clearInterval(intervals.right);
- }
-
- clickAndHold = (direction) => {
- const { setArrowDown } = this.props;
- setArrowDown(direction);
- arrowDownCheckTimer = null;
- };
-
- onArrowDown = (direction) => {
- this.arrowDownMap[direction]();
- arrowDownCheckTimer = setTimeout(() => {
- this.clickAndHold(direction);
+ }, [tilesPreloaded, arrowDown]);
+
+ // Cleanup intervals on unmount
+ useEffect(() => () => {
+ clearInterval(intervalsRef.current.left);
+ clearInterval(intervalsRef.current.right);
+ }, []);
+
+ const onArrowDown = (direction) => {
+ arrowDownMap(direction);
+ arrowDownCheckTimerRef.current = setTimeout(() => {
+ setArrowDown(direction);
+ arrowDownCheckTimerRef.current = null;
}, CLICK_HOLD_DELAY);
};
- onArrowUp = (direction) => {
- const { setArrowUp, arrowDown } = this.props;
- if (arrowDownCheckTimer) {
- clearTimeout(arrowDownCheckTimer);
+ const onArrowUp = (direction) => {
+ if (arrowDownCheckTimerRef.current) {
+ clearTimeout(arrowDownCheckTimerRef.current);
}
- clearInterval(intervals[direction]);
- intervals[direction] = 0;
+ clearInterval(intervalsRef.current[direction]);
+ intervalsRef.current[direction] = 0;
if (arrowDown) setArrowUp();
};
- render() {
- const {
- handleSelectNowButton,
- isMobile,
- leftArrowDisabled,
- nowButtonDisabled,
- rightArrowDisabled,
- arrowDown,
- tilesPreloaded,
- isKioskModeActive,
- isEmbedModeActive,
- } = this.props;
-
- const leftArrowDown = () => this.onArrowDown('left');
- const rightArrowDown = () => this.onArrowDown('right');
- const leftArrowUp = () => this.onArrowUp('left');
- const rightArrowUp = () => this.onArrowUp('right');
-
- return (
- <div className="arrow-group">
- {arrowDown && !tilesPreloaded && (
- <LoadingIndicator
- title="Loading ..."
- bodyMsg="Keep holding to animate the map!"
- />
- )}
-
- {/* LEFT ARROW */}
- <button
- type="button"
- className={`button-action-group${leftArrowDisabled ? ' button-disabled' : ''} ${isKioskModeActive && !isEmbedModeActive ? 'd-none' : ''}`}
- id="left-arrow-group"
- onMouseDown={leftArrowDown}
- onMouseUp={leftArrowUp}
- onMouseLeave={leftArrowUp}
- aria-disabled={leftArrowDisabled}
- aria-label="Decrement date"
- >
- <HoverTooltip
- isMobile={isMobile}
- labelText="Decrement date"
- placement="top"
- target="left-arrow-group"
- />
- <ArrowChevronLeft className="arrow" size="30px" />
- </button>
-
- {/* RIGHT ARROW */}
- <button
- type="button"
- className={`button-action-group${rightArrowDisabled ? ' button-disabled' : ''} ${isKioskModeActive && !isEmbedModeActive ? 'd-none' : ''}`}
- id="right-arrow-group"
- onMouseDown={rightArrowDown}
- onMouseUp={rightArrowUp}
- onMouseLeave={rightArrowUp}
- aria-disabled={rightArrowDisabled}
- aria-label="Increment date"
- >
- <HoverTooltip
- isMobile={isMobile}
- labelText="Increment date"
- placement="top"
- target="right-arrow-group"
- />
- <ArrowChevronRight className="arrow" size="30px" />
- </button>
-
- {/* NOW BUTTON */}
- <button
- type="button"
- className={`button-action-group now-button-group${nowButtonDisabled ? ' button-disabled' : ''} ${isKioskModeActive ? 'd-none' : ''}`}
- id="now-button-group"
- onClick={handleSelectNowButton}
- aria-disabled={nowButtonDisabled}
- aria-label="Latest available date"
-
- >
- <HoverTooltip
- isMobile={isMobile}
- labelText="Latest available date"
- placement="top"
- target="now-button-group"
+ const leftArrowMouseDown = () => onArrowDown('left');
+ const rightArrowMouseDown = () => onArrowDown('right');
+ const leftArrowMouseUp = () => onArrowUp('left');
+ const rightArrowMouseUp = () => onArrowUp('right');
+
+ return (
+ <div className="arrow-group">
+ {arrowDown && !tilesPreloaded && (
+ <LoadingIndicator
+ title="Loading ..."
+ bodyMsg="Keep holding to animate the map!"
+ />
+ )}
+
+ {/* LEFT ARROW */}
+ <button
+ type="button"
+ className={`button-action-group${leftArrowDisabled ? ' button-disabled' : ''} ${isKioskModeActive && !isEmbedModeActive ? 'd-none' : ''}`}
+ id="left-arrow-group"
+ onMouseDown={leftArrowMouseDown}
+ onMouseUp={leftArrowMouseUp}
+ onMouseLeave={leftArrowMouseUp}
+ aria-disabled={leftArrowDisabled}
+ aria-label="Decrement date"
+ >
+ <HoverTooltip
+ isMobile={isMobile}
+ labelText="Decrement date"
+ placement="top"
+ target="left-arrow-group"
+ />
+ <ArrowChevronLeft className="arrow" size="30px" />
+ </button>
+
+ {/* RIGHT ARROW */}
+ <button
+ type="button"
+ className={`button-action-group${rightArrowDisabled ? ' button-disabled' : ''} ${isKioskModeActive && !isEmbedModeActive ? 'd-none' : ''}`}
+ id="right-arrow-group"
+ onMouseDown={rightArrowMouseDown}
+ onMouseUp={rightArrowMouseUp}
+ onMouseLeave={rightArrowMouseUp}
+ aria-disabled={rightArrowDisabled}
+ aria-label="Increment date"
+ >
+ <HoverTooltip
+ isMobile={isMobile}
+ labelText="Increment date"
+ placement="top"
+ target="right-arrow-group"
+ />
+ <ArrowChevronRight className="arrow" size="30px" />
+ </button>
+
+ {/* NOW BUTTON */}
+ <button
+ type="button"
+ className={`button-action-group now-button-group${nowButtonDisabled ? ' button-disabled' : ''} ${isKioskModeActive ? 'd-none' : ''}`}
+ id="now-button-group"
+ onClick={handleSelectNowButton}
+ aria-disabled={nowButtonDisabled}
+ aria-label="Latest available date"
+
+ >
+ <HoverTooltip
+ isMobile={isMobile}
+ labelText="Latest available date"
+ placement="top"
+ target="now-button-group"
+ />
+ <svg height="30" width="30" viewBox="0 0 40 28">
+ <path
+ d="M 10.240764,0 24,15 10.240764,30 0,30 13.759236,15 0,0 10.240764,0 z M 26,30 26,0 34,0 34,30 z"
+ className="arrow"
/>
- <svg height="30" width="30" viewBox="0 0 40 28">
- <path
- d="M 10.240764,0 24,15 10.240764,30 0,30 13.759236,15 0,0 10.240764,0 z M 26,30 26,0 34,0 34,30 z"
- className="arrow"
- />
- </svg>
- </button>
- </div>
- );
- }
+ </svg>
+ </button>
+ </div>
+ );
}
const mapStateToProps = (state) => {
diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.js
index c75a0f9e7..0397bfc18 100644
--- a/web/js/containers/timeline/timeline.js
+++ b/web/js/containers/timeline/timeline.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import moment from 'moment';
@@ -73,6 +73,7 @@ import {
customModalType,
} from '../../modules/date/constants';
import util from '../../util/util';
+import usePrevious from '../../util/customHooks';
import MobileComparisonToggle from '../../components/compare/mobile-toggle';
@@ -177,459 +178,239 @@ const getTimelineEndDateLimit = (state) => {
return timelineEndDateLimit;
};
-class Timeline extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- position: 0,
- transformX: 0,
- leftOffset: 0,
- frontDate: '',
- backDate: '',
- animationStartLocationDate: '',
- animationEndLocationDate: '',
- animationStartLocation: 0,
- animationEndLocation: 0,
- draggerTimeState: '',
- draggerTimeStateB: '',
- draggerPosition: 0,
- draggerPositionB: 0,
- draggerVisible: true,
- draggerVisibleB: false,
- hoverTime: '',
- hoverLinePosition: 0,
- showHoverLine: false,
- showDraggerTime: false,
- isAnimationDraggerDragging: false,
- isDraggerDragging: false,
- isTimelineDragging: false,
- initialLoadComplete: false,
- timelineHidden: false,
- rangeSelectorMax: {
- end: false, start: false, startOffset: -50, width: 50000,
- },
- matchingTimelineCoverage: [],
- isTimelineLayerCoveragePanelOpen: false,
- shouldIncludeHiddenLayers: false,
- };
-
- const {
- selectDate,
- onUpdateStartDate,
- onUpdateEndDate,
- onUpdateStartAndEndDate,
- } = this.props;
-
- // left/right arrows
- const throttleSettings = { leading: true, trailing: false };
- this.debounceDateUpdate = lodashDebounce(selectDate, 8);
-
- // animation dragger updates
- this.debounceOnUpdateStartDate = lodashDebounce(onUpdateStartDate, 30);
- this.debounceOnUpdateEndDate = lodashDebounce(onUpdateEndDate, 30);
- this.debounceOnUpdateStartAndEndDate = lodashDebounce(onUpdateStartAndEndDate, 30);
-
- // change timescale
- this.debounceWheelTime = 60;
- this.debounceChangeTimeScaleWheel = lodashDebounce(
- this.throttleChangeTimeScaleWheel,
- this.debounceWheelTime,
- throttleSettings,
- );
- this.throttleChangeTimeScaleWheelFire = lodashThrottle(
- this.changeTimeScaleScroll,
- 200,
- throttleSettings,
- );
-
- // application relative now time
- this.appNowUpdateInterval = 0;
- }
+function Timeline(props) {
+ const {
+ activeLayers,
+ addGranuleDateRanges,
+ animationDisabled,
+ animEndLocationDate,
+ animStartLocationDate,
+ appNow,
+ autoSelected,
+ axisWidth,
+ breakpoints,
+ changeAutoInterval,
+ changeCustomInterval,
+ changeTimeScale: changeTimeScaleProp,
+ closeAnimation,
+ customInterval,
+ customSelected,
+ dateA,
+ dateB,
+ activeString,
+ deltaChangeAmt,
+ displayStaticMap,
+ draggerSelected,
+ hasFutureLayers,
+ hasSubdailyLayers,
+ hasTempoProduct,
+ hideTimeline,
+ interval,
+ isAnimatingToEvent,
+ isAnimationPlaying,
+ isAnimationWidgetOpen,
+ isChartingActive,
+ isCompareModeActive,
+ isDataDownload,
+ isDistractionFreeModeActive,
+ isEmbedModeActive,
+ isGifActive,
+ isKioskModeActive,
+ isLandscape,
+ isMobile,
+ isMobilePhone,
+ isMobileTablet,
+ isPortrait,
+ isTourActive,
+ leftArrowDisabled,
+ newCustomDelta,
+ nowButtonDisabled,
+ nowOverride,
+ onPauseAnimation,
+ onToggleAnimationCollapse,
+ onUpdateEndDate,
+ onUpdateStartAndEndDate,
+ onUpdateStartDate,
+ openAnimation,
+ parentOffset,
+ rightArrowDisabled,
+ screenWidth,
+ selectDate,
+ selectedDate,
+ subDailyLayersList,
+ timelineCustomModalOpen,
+ timelineEndDateLimit,
+ timelineStartDateLimit,
+ timeScale,
+ timeScaleChangeUnit,
+ toggleActiveCompareState,
+ triggerTodayButton,
+ updateAppNow,
+ proj,
+ describeDomainsUrl,
+ cmrBaseUrl,
+ } = props;
+
+ // State
+ const [position, setPosition] = useState(0);
+ const [transformX, setTransformX] = useState(0);
+ const [leftOffset, setLeftOffset] = useState(0);
+ const [frontDate, setFrontDate] = useState('');
+ const [backDate, setBackDate] = useState('');
+ const [animationStartLocationDate, setAnimationStartLocationDate] = useState('');
+ const [animationEndLocationDate, setAnimationEndLocationDate] = useState('');
+ const [animationStartLocation, setAnimationStartLocation] = useState(0);
+ const [animationEndLocation, setAnimationEndLocation] = useState(0);
+ const [draggerTimeState, setDraggerTimeState] = useState('');
+ const [draggerTimeStateB, setDraggerTimeStateB] = useState('');
+ const [draggerPosition, setDraggerPosition] = useState(0);
+ const [draggerPositionB, setDraggerPositionB] = useState(0);
+ const [draggerVisible, setDraggerVisible] = useState(true);
+ const [draggerVisibleB, setDraggerVisibleB] = useState(false);
+ const [hoverTime, setHoverTime] = useState('');
+ const [hoverLinePosition, setHoverLinePosition] = useState(0);
+ const [showHoverLine, setShowHoverLine] = useState(false);
+ const [showDraggerTime, setShowDraggerTime] = useState(false);
+ const [isAnimationDraggerDragging, setIsAnimationDraggerDragging] = useState(false);
+ const [isDraggerDragging, setIsDraggerDragging] = useState(false);
+ const [isTimelineDragging, setIsTimelineDragging] = useState(false);
+ const [initialLoadComplete, setInitialLoadComplete] = useState(false);
+ const [timelineHidden, setTimelineHidden] = useState(false);
+ const [rangeSelectorMax] = useState({
+ end: false, start: false, startOffset: -50, width: 50000,
+ });
+ const [matchingTimelineCoverage, setMatchingTimelineCoverage] = useState([]);
+ const [isTimelineLayerCoveragePanelOpen, setIsTimelineLayerCoveragePanelOpen] = useState(false);
+ const [shouldIncludeHiddenLayers, setShouldIncludeHiddenLayers] = useState(false);
+
+ // Debounced functions — dispatch props are stable (memoized by connect)
+ const debounceDateUpdateRef = useRef(lodashDebounce(selectDate, 8));
+ const debounceOnUpdateStartDateRef = useRef(lodashDebounce(onUpdateStartDate, 30));
+ const debounceOnUpdateEndDateRef = useRef(lodashDebounce(onUpdateEndDate, 30));
+ const debounceOnUpdateStartAndEndDateRef = useRef(
+ lodashDebounce(onUpdateStartAndEndDate, 30),
+ );
+ const appNowUpdateIntervalRef = useRef(0);
- static getDerivedStateFromProps(props, currentState) {
- // Update animation Date states when animation is initiated
- if (!currentState.animationEndLocationDate &&
- !currentState.animationStartLocationDate &&
- props.animStartLocationDate &&
- props.animEndLocationDate) {
- const { position, transformX } = currentState;
- const { timeScale } = props;
- const startDate = props.animStartLocationDate;
- const endDate = props.animEndLocationDate;
- const options = timeScaleOptions[timeScale].timeAxis;
- const { gridWidth } = options;
+ // Refs for state values needed in interval/event callbacks
+ const stateRef = useRef({});
+ stateRef.current = {
+ position,
+ transformX,
+ frontDate,
+ hoverTime,
+ draggerPosition,
+ draggerPositionB,
+ draggerVisible,
+ draggerVisibleB,
+ draggerTimeState,
+ draggerTimeStateB,
+ isTimelineDragging,
+ isDraggerDragging,
+ isAnimationDraggerDragging,
+ showHoverLine,
+ showDraggerTime,
+ animationStartLocation,
+ animationEndLocation,
+ };
- const frontDate = moment.utc(currentState.frontDate);
- const startLocation = frontDate.diff(startDate, timeScale, true) * gridWidth;
- const endLocation = frontDate.diff(endDate, timeScale, true) * gridWidth;
- return {
- animationStartLocationDate: props.animStartLocationDate,
- animationEndLocationDate: props.animEndLocationDate,
- animationStartLocation: position - startLocation + transformX,
- animationEndLocation: position - endLocation + transformX,
- };
+ // Previous values for componentDidUpdate logic
+ const prevIsAnimationPlaying = usePrevious(isAnimationPlaying);
+ const prevIsGifActive = usePrevious(isGifActive);
+ const prevAnimStartLocationDate = usePrevious(animStartLocationDate);
+ const prevAnimEndLocationDate = usePrevious(animEndLocationDate);
+ const prevHasSubdailyLayers = usePrevious(hasSubdailyLayers);
+ const prevHasTempoProduct = usePrevious(hasTempoProduct);
+ const prevSubDailyLayersList = usePrevious(subDailyLayersList);
+ const prevFrontDate = usePrevious(frontDate);
+ const prevDateA = usePrevious(dateA);
+ const prevDateB = usePrevious(dateB);
+
+ // METHODS
+
+ function onDateChange(date, draggerSelectedArg = draggerSelected) {
+ const dateISOFormatted = getISODateFormatted(date);
+ if (draggerSelectedArg === 'selected') {
+ setDraggerTimeState(dateISOFormatted);
+ } else {
+ setDraggerTimeStateB(dateISOFormatted);
}
- return null;
+ debounceDateUpdateRef.current(new Date(date), draggerSelectedArg);
}
- componentDidMount() {
- const {
- nowOverride,
- } = this.props;
- document.addEventListener('keydown', this.handleKeyDown);
- document.addEventListener('keyup', this.handleKeyUp);
- // prevent default react synthetic event passive event listener
- // that allows browser resize/zoom on certain wheel events
- document.querySelector('.timeline-container').addEventListener('wheel', preventDefaultFunc, { passive: false });
-
- // appNow will not update if set in query string using 'now' parameter
- if (!nowOverride) {
- this.checkAndUpdateAppNow = this.checkAndUpdateAppNow.bind(this);
- this.appNowUpdateInterval = setInterval(this.checkAndUpdateAppNow, 60000 * 10);
- }
-
- this.setInitialState();
+ function changeTimeScaleLocal(timeScaleNum) {
+ setShowHoverLine(false);
+ setShowDraggerTime(false);
+ changeTimeScaleProp(timeScaleNum);
}
- componentDidUpdate(prevProps, prevState) {
- const prevStartLocationDate = prevProps.animStartLocationDate;
- const prevEndLocationDate = prevProps.animEndLocationDate;
- const {
- animStartLocationDate,
- animEndLocationDate,
- changeCustomInterval,
- changeAutoInterval,
- customInterval,
- dateA,
- dateB,
- interval,
- isAnimationPlaying,
- isAnimationWidgetOpen,
- isGifActive,
- hasSubdailyLayers,
- hasTempoProduct,
- subDailyLayersList,
- newCustomDelta,
- } = this.props;
- const { frontDate, draggerTimeState, draggerTimeStateB } = this.state;
-
- // handle update animation positioning and local state from play button/gif creation
- const didAnimationTurnOn = !prevProps.isAnimationPlaying && isAnimationPlaying;
- const didGifTurnOn = !prevProps.isGifActive && isGifActive;
- if (didAnimationTurnOn || didGifTurnOn) {
- this.animationDraggerDateUpdateLocal(animStartLocationDate, animEndLocationDate);
- }
+ const changeTimeScaleScrollRef = useRef(null);
+ changeTimeScaleScrollRef.current = (e) => {
+ const timeScaleNumber = Number(TIME_SCALE_TO_NUMBER[timeScale]);
+ const maxTimeScaleNumber = hasSubdailyLayers ? 5 : 3;
- // handle location update triggered from animation start/end date change from animation widget
- if (isAnimationWidgetOpen) {
- if (
- prevStartLocationDate &&
- prevEndLocationDate &&
- animStartLocationDate &&
- animEndLocationDate
- ) {
- const animStartDateChanged = prevStartLocationDate.getTime() !==
- animStartLocationDate.getTime();
- const animEndDateChanged = prevEndLocationDate.getTime() !== animEndLocationDate.getTime();
- const frontDateChanged = prevState.frontDate !== frontDate;
- if (animStartDateChanged || animEndDateChanged || frontDateChanged) {
- this.animationDraggerDateUpdate(animStartLocationDate, animEndLocationDate);
- }
+ if (e.deltaY > 0) {
+ if (timeScaleNumber > 1) {
+ changeTimeScaleLocal(timeScaleNumber - 1);
}
+ } else if (timeScaleNumber < maxTimeScaleNumber) {
+ changeTimeScaleLocal(timeScaleNumber + 1);
}
+ };
- const subdailyRemoved = !hasSubdailyLayers && prevProps.hasSubdailyLayers;
- const tempoRemoved = !hasTempoProduct && prevProps.hasTempoProduct;
- const subDailyCountChanged = subDailyLayersList.length !== prevProps.subDailyLayersList.length;
- const subdailyInterval = customInterval > 3 || interval > 3;
-
- if (tempoRemoved) {
- changeAutoInterval();
- selectInterval(1, TIME_SCALE_TO_NUMBER.day, false, false);
- }
- if (subdailyRemoved && subdailyInterval) {
- changeCustomInterval();
- selectInterval(1, TIME_SCALE_TO_NUMBER.day, false, false);
- }
-
- const isSubDaily = newCustomDelta < 1440; // 1440 == 1 day in minutes
- if (subDailyCountChanged) {
- if (hasTempoProduct) {
- changeAutoInterval(true);
- } else if (isSubDaily) {
- changeCustomInterval(newCustomDelta, TIME_SCALE_TO_NUMBER.minute);
- }
- }
+ // Throttled/debounced wheel timescale change refs
+ const throttleSettings = { leading: true, trailing: false };
+ const throttleChangeTimeScaleWheelFireRef = useRef(
+ lodashThrottle((e) => changeTimeScaleScrollRef.current(e), 200, throttleSettings),
+ );
+ const debounceChangeTimeScaleWheelRef = useRef(
+ lodashDebounce(
+ (e) => { throttleChangeTimeScaleWheelFireRef.current(e); },
+ 60,
+ throttleSettings,
+ ),
+ );
- // if user adds a subdaily layer (and none were active) change the time scale to hourly
- if (hasSubdailyLayers && !prevProps.hasSubdailyLayers) {
- this.changeTimeScale(4);
- }
+ function animationDraggerDateUpdateLocal(startDate, endDate) {
+ const { position: pos, transformX: tx, frontDate: fd } = stateRef.current;
+ const options = timeScaleOptions[timeScale].timeAxis;
+ const { gridWidth } = options;
- if (dateA !== prevProps.dateA && dateA !== draggerTimeState) {
- this.updateDraggerTimeState(dateA, false);
- }
- if (dateB !== prevProps.dateB && dateB !== draggerTimeStateB) {
- this.updateDraggerTimeState(dateB, true);
- }
- }
+ const frontDateObj = moment.utc(fd);
+ const startLocation = frontDateObj.diff(startDate, timeScale, true) * gridWidth;
+ const endLocation = frontDateObj.diff(endDate, timeScale, true) * gridWidth;
- componentWillUnmount() {
- if (this.appNowUpdateInterval) clearInterval(this.appNowUpdateInterval);
- document.removeEventListener('keydown', this.handleKeyDown);
- document.removeEventListener('keyup', this.handleKeyUp);
- document.querySelector('.timeline-container').removeEventListener('wheel', preventDefaultFunc);
+ setAnimationStartLocation(pos - startLocation + tx);
+ setAnimationEndLocation(pos - endLocation + tx);
+ setAnimationStartLocationDate(startDate);
+ setAnimationEndLocationDate(endDate);
}
- // chain throttled timescale wheel change call after debounce for smoother UX
- throttleChangeTimeScaleWheel = (e) => {
- this.throttleChangeTimeScaleWheelFire(e);
- };
-
- // HOVER TIME
- /**
- * @desc display date based on hover grid tile
- * @param {String} date
- * @param {Number} leftOffset
- * @returns {void}
- */
- displayDate = (date, leftOffset) => {
- const { parentOffset } = this.props;
- requestAnimationFrame(() => {
- this.setState({
- hoverTime: date,
- // relative location from parent bounding box of mouse hover position (i.e. BLUE LINE)
- leftOffset: leftOffset - parentOffset,
- });
- });
- };
-
- /**
- * @desc show hover line
- * @param {Event} mouse event
- * @returns {void}
- */
- showHoverOn = () => {
- const { showHoverLine, showDraggerTime } = this.state;
- if (!showHoverLine && !showDraggerTime) {
- this.setState({
- showHoverLine: true,
- });
- }
- };
+ function animationDraggerDateUpdate(startDate, endDate) {
+ animationDraggerDateUpdateLocal(startDate, endDate);
- /**
- * @desc hide hover line
- * @returns {void}
- */
- showHoverOff = () => {
- const { showHoverLine } = this.state;
- if (showHoverLine === true) {
- this.setState({
- showHoverLine: false,
- });
+ const didStartDateChange = startDate.getTime() !== animStartLocationDate.getTime();
+ const didEndDateChange = endDate.getTime() !== animEndLocationDate.getTime();
+ if (didStartDateChange || didEndDateChange) {
+ debounceOnUpdateStartAndEndDateRef.current(startDate, endDate);
}
- };
-
- /**
- * @desc toggle dragger time on/off
- * @param {Boolean} toggleBoolean
- * @returns {void}
- */
- toggleShowDraggerTime = (toggleBoolean) => {
- this.setState({
- showDraggerTime: toggleBoolean,
- showHoverLine: false,
- isDraggerDragging: toggleBoolean,
- });
- };
-
- /**
- * @desc handle svg blue line axis hover
- * @param {Event} mouse event
- * @param {String} itemDate
- * @param {String} nextDate
- * @param {Number} index
- * @returns {void}
- */
- showHover = (e, itemDate, nextDate, index) => {
- e.preventDefault();
- e.stopPropagation();
- e.persist();
- requestAnimationFrame(() => {
- const {
- position,
- transformX,
- } = this.state;
- const {
- timeScale,
- timelineStartDateLimit,
- timelineEndDateLimit,
- } = this.props;
-
- const options = timeScaleOptions[timeScale].timeAxis;
- const { gridWidth } = options;
-
- const { target } = e;
- const { clientX } = e;
- const boundingClientRect = target.getBoundingClientRect();
- const xHoverPositionInCurrentGrid = Math.floor(clientX) - Math.floor(boundingClientRect.left);
-
- const currentDateValue = new Date(itemDate).getTime();
- const nextDateValue = new Date(nextDate).getTime();
- const diff = nextDateValue - currentDateValue;
- const diffFactor = diff / gridWidth;
- const displayDateValue = currentDateValue + xHoverPositionInCurrentGrid * diffFactor;
+ }
- const isBetweenValidTimeline = getIsBetween(
- displayDateValue,
- timelineStartDateLimit,
- timelineEndDateLimit,
- );
- if (isBetweenValidTimeline) {
- const displayDateFormat = getISODateFormatted(displayDateValue);
- this.displayDate(displayDateFormat, clientX);
- this.setState({
- hoverLinePosition: index * gridWidth + xHoverPositionInCurrentGrid +
- transformX + position,
- });
+ function determineAnimationDraggerUpdate(startDate, endDate) {
+ const startChanged = animStartLocationDate !== startDate;
+ const endChanged = animEndLocationDate !== endDate;
+ if (startChanged) {
+ if (endChanged) {
+ debounceOnUpdateStartAndEndDateRef.current(startDate, endDate);
+ } else {
+ debounceOnUpdateStartDateRef.current(startDate);
}
- });
- };
-
- /**
- * @desc handles dynamic position changes from axis that affect dragger and range select
- * @param {Object} args
- * @param {Boolean} isTimelineDragging
- * @param {Number} position
- * @param {Number} transformX
- * @param {String} frontDate
- * @param {String} backDate
- * @param {Number} draggerPosition
- * @param {Number} draggerPositionB
- * @param {Boolean} draggerVisible
- * @param {Boolean} draggerVisibleB
- * @param {Number} animationStartLocation
- * @param {Number} animationEndLocation
- * @param {String} hoverTime - defaults to state
- * @returns {void}
- */
- updatePositioning = ({
- isTimelineDragging,
- position,
- transformX,
- frontDate,
- backDate,
- draggerPosition,
- draggerPositionB,
- draggerVisible,
- draggerVisibleB,
- animationStartLocation,
- animationEndLocation,
-
- }, hoverTime = this.state.hoverTime) => {
- this.setState({
- isTimelineDragging,
- showHoverLine: false,
- position,
- transformX,
- frontDate,
- backDate,
- draggerPosition,
- draggerPositionB,
- draggerVisible,
- draggerVisibleB,
- animationStartLocation,
- animationEndLocation,
- hoverTime,
- });
- };
-
- /**
- * @desc handles dynamic positioning update based on simple drag
- * @param {Object} args
- * @param {Number} position
- * @param {Number} draggerPosition
- * @param {Number} draggerPositionB
- * @param {Number} animationStartLocation
- * @param {Number} animationEndLocation
- * @returns {void}
- */
- updatePositioningOnSimpleDrag = ({
- position,
- draggerPosition,
- draggerPositionB,
- animationStartLocation,
- animationEndLocation,
- }) => {
- this.setState({
- isTimelineDragging: true,
- showHoverLine: false,
- position,
- draggerPosition,
- draggerPositionB,
- animationStartLocation,
- animationEndLocation,
- });
- };
-
- /**
- * @desc handles dynamic positioning update based on axis drag stop event
- * @param {Object} args
- * @param {Boolean} isTimelineDragging
- * @param {Number} position
- * @param {Number} transformX
- * @param {String} hoverTime - defaults to state
- * @returns {void}
- */
- updatePositioningOnAxisStopDrag = ({
- isTimelineDragging,
- position,
- transformX,
-
- }, hoverTime = this.state.hoverTime) => {
- this.setState({
- isTimelineDragging,
- showHoverLine: false,
- position,
- transformX,
- hoverTime,
- });
- };
-
- /**
- * @desc update is timeline moved (drag timeline vs. click) and if timeline is dragging
- * @param {Boolean} isTimelineDragging
- * @returns {void}
- */
- updateTimelineMoveAndDrag = (isTimelineDragging) => {
- this.setState({
- isTimelineDragging,
- });
- };
-
- /**
- * @desc handle left/right arrow decrement/increment date
- * @param {Number} signConstant - used to determine if decrement (-1) or increment (1)
- * @returns {void}
- */
- handleArrowDateChange(signConstant) {
- const {
- customSelected,
- autoSelected,
- deltaChangeAmt,
- timeScaleChangeUnit,
- selectedDate,
- rightArrowDisabled,
- leftArrowDisabled,
- timelineEndDateLimit,
- timelineStartDateLimit,
- subDailyLayersList,
- activeString,
- dateA,
- dateB,
- } = this.props;
+ } else if (endChanged) {
+ debounceOnUpdateEndDateRef.current(endDate);
+ }
+ }
+ function handleArrowDateChange(signConstant) {
let delta = customSelected && deltaChangeAmt ? deltaChangeAmt : 1;
let timescale = timeScaleChangeUnit;
if (autoSelected && subDailyLayersList && subDailyLayersList.length) {
@@ -640,15 +421,13 @@ class Timeline extends React.Component {
);
timescale = 'minute';
}
- if (!timeScaleChangeUnit) { // undefined custom will not allow arrow change
- return;
- }
- delta = Number(delta * signConstant); // determine if negative or positive change
+ if (!timeScaleChangeUnit) return;
+ delta = Number(delta * signConstant);
const disabled = signConstant > 0 ? rightArrowDisabled : leftArrowDisabled;
if (!disabled) {
const minDate = new Date(timelineStartDateLimit);
const maxDate = new Date(timelineEndDateLimit);
- this.onDateChange(getNextTimeSelection(
+ onDateChange(getNextTimeSelection(
delta,
timescale,
selectedDate,
@@ -658,96 +437,156 @@ class Timeline extends React.Component {
}
}
- /**
- * @desc handles left/right arrow down to decrement/increment date
- * @param {Event} mouse event
- * @returns {void}
- */
- handleKeyDown = (e) => {
- const { isTimelineDragging } = this.state;
- const { hasSubdailyLayers, timeScale } = this.props;
- // prevent left/right arrows changing date within inputs
- if (e.target.tagName !== 'INPUT' && e.target.className !== 'form-range' && !e.ctrlKey && !e.metaKey && !isTimelineDragging) {
+ const handleKeyDownRef = useRef(null);
+ handleKeyDownRef.current = (e) => {
+ const { isTimelineDragging: dragging } = stateRef.current;
+ if (e.target.tagName !== 'INPUT' && e.target.className !== 'form-range' && !e.ctrlKey && !e.metaKey && !dragging) {
const timeScaleNumber = Number(TIME_SCALE_TO_NUMBER[timeScale]);
const maxTimeScaleNumber = hasSubdailyLayers ? 5 : 3;
if (e.key === 'ArrowUp') {
e.preventDefault();
if (timeScaleNumber > 1) {
- this.changeTimeScale(timeScaleNumber - 1);
+ changeTimeScaleLocal(timeScaleNumber - 1);
}
- // down arrow
} else if (e.key === 'ArrowDown') {
e.preventDefault();
if (timeScaleNumber < maxTimeScaleNumber) {
- this.changeTimeScale(timeScaleNumber + 1);
+ changeTimeScaleLocal(timeScaleNumber + 1);
}
} else if (e.key === 'ArrowLeft') {
e.preventDefault();
- this.handleArrowDateChange(-1);
+ handleArrowDateChange(-1);
} else if (e.key === 'ArrowRight') {
e.preventDefault();
- this.handleArrowDateChange(1);
+ handleArrowDateChange(1);
}
}
};
- /**
- * @desc Change the timescale parent state
- * @param {Number} timeScaleNumber
- * @returns {void}
- */
- changeTimeScale = (timeScale) => {
- const { changeTimeScale } = this.props;
- this.setState({
- showHoverLine: false,
- showDraggerTime: false,
+ const handleKeyUpRef = useRef(() => {});
+
+ function displayDateFn(date, leftOffsetArg) {
+ requestAnimationFrame(() => {
+ setHoverTime(date);
+ setLeftOffset(leftOffsetArg - parentOffset);
});
- changeTimeScale(timeScale);
- };
+ }
- /**
- * @desc changes timeScale with wheel scroll - throttled invocations
- * y axis change - change timescale scroll (e.g. from 'day' to 'month')
- * @param {Event} wheel scroll event
- * @returns {void}
- */
- changeTimeScaleScroll = (e) => {
- const {
- timeScale,
- hasSubdailyLayers,
- } = this.props;
- const timeScaleNumber = Number(TIME_SCALE_TO_NUMBER[timeScale]);
- const maxTimeScaleNumber = hasSubdailyLayers ? 5 : 3;
+ function showHoverOn() {
+ const { showHoverLine: hovLine, showDraggerTime: dragTime } = stateRef.current;
+ if (!hovLine && !dragTime) {
+ setShowHoverLine(true);
+ }
+ }
- // handle time scale change on y axis wheel event
- // wheel zoom out
- if (e.deltaY > 0) {
- if (timeScaleNumber > 1) {
- this.changeTimeScale(timeScaleNumber - 1);
- }
- // wheel zoom in
- } else if (timeScaleNumber < maxTimeScaleNumber) {
- this.changeTimeScale(timeScaleNumber + 1);
+ function showHoverOff() {
+ const { showHoverLine: hovLine } = stateRef.current;
+ if (hovLine === true) {
+ setShowHoverLine(false);
}
- };
+ }
- /**
- * @desc open animation widget
- * @returns {void}
- */
- clickAnimationButton = () => {
- const {
- closeAnimation,
- isAnimationWidgetOpen,
- openAnimation,
- isMobile,
- onPauseAnimation,
- onToggleAnimationCollapse,
- isCompareModeActive,
- isChartingActive,
- isDataDownload,
- } = this.props;
+ function toggleShowDraggerTimeFn(toggleBoolean) {
+ setShowDraggerTime(toggleBoolean);
+ setShowHoverLine(false);
+ setIsDraggerDragging(toggleBoolean);
+ }
+
+ function showHoverFn(e, itemDate, nextDate, index) {
+ e.preventDefault();
+ e.stopPropagation();
+ e.persist();
+ requestAnimationFrame(() => {
+ const { position: pos, transformX: tx } = stateRef.current;
+ const options = timeScaleOptions[timeScale].timeAxis;
+ const { gridWidth } = options;
+ const { target } = e;
+ const { clientX } = e;
+ const boundingClientRect = target.getBoundingClientRect();
+ const xHoverPositionInCurrentGrid = Math.floor(clientX) - Math.floor(boundingClientRect.left);
+
+ const currentDateValue = new Date(itemDate).getTime();
+ const nextDateValue = new Date(nextDate).getTime();
+ const diff = nextDateValue - currentDateValue;
+ const diffFactor = diff / gridWidth;
+ const displayDateValue = currentDateValue + xHoverPositionInCurrentGrid * diffFactor;
+
+ const isBetweenValidTimeline = getIsBetween(
+ displayDateValue,
+ timelineStartDateLimit,
+ timelineEndDateLimit,
+ );
+ if (isBetweenValidTimeline) {
+ const displayDateFormat = getISODateFormatted(displayDateValue);
+ displayDateFn(displayDateFormat, clientX);
+ setHoverLinePosition(index * gridWidth + xHoverPositionInCurrentGrid +
+ tx + pos);
+ }
+ });
+ }
+
+ function updatePositioning({
+ isTimelineDragging: dragging,
+ position: pos,
+ transformX: tx,
+ frontDate: fd,
+ backDate: bd,
+ draggerPosition: dp,
+ draggerPositionB: dpB,
+ draggerVisible: dv,
+ draggerVisibleB: dvB,
+ animationStartLocation: asl,
+ animationEndLocation: ael,
+ }, ht = stateRef.current.hoverTime) {
+ setIsTimelineDragging(dragging);
+ setShowHoverLine(false);
+ setPosition(pos);
+ setTransformX(tx);
+ setFrontDate(fd);
+ setBackDate(bd);
+ setDraggerPosition(dp);
+ setDraggerPositionB(dpB);
+ setDraggerVisible(dv);
+ setDraggerVisibleB(dvB);
+ setAnimationStartLocation(asl);
+ setAnimationEndLocation(ael);
+ setHoverTime(ht);
+ }
+
+ function updatePositioningOnSimpleDrag({
+ position: pos,
+ draggerPosition: dp,
+ draggerPositionB: dpB,
+ animationStartLocation: asl,
+ animationEndLocation: ael,
+ }) {
+ setIsTimelineDragging(true);
+ setShowHoverLine(false);
+ setPosition(pos);
+ setDraggerPosition(dp);
+ setDraggerPositionB(dpB);
+ setAnimationStartLocation(asl);
+ setAnimationEndLocation(ael);
+ }
+
+ function updatePositioningOnAxisStopDrag({
+ isTimelineDragging: dragging,
+ position: pos,
+ transformX: tx,
+ }, ht = stateRef.current.hoverTime) {
+ setIsTimelineDragging(dragging);
+ setShowHoverLine(false);
+ setPosition(pos);
+ setTransformX(tx);
+ setHoverTime(ht);
+ }
+
+ function updateTimelineMoveAndDrag(dragging) {
+ setIsTimelineDragging(dragging);
+ }
+
+ function clickAnimationButton() {
if (isCompareModeActive || isChartingActive || isDataDownload) {
return;
}
@@ -764,243 +603,100 @@ class Timeline extends React.Component {
});
openAnimation();
}
- };
-
- /**
- * @desc toggle hide timeline
- * @returns {void}
- */
- toggleHideTimeline = () => {
- const { timelineHidden } = this.state;
- this.setState({
- timelineHidden: !timelineHidden,
- });
- };
-
- /**
- * @desc handle animation date dragger updates
- * @param {String} startDate
- * @param {String} endDate
- * @param {Number} startLocation
- * @param {Number} endLocation
- * @param {Boolean} isDragging
- * @returns {void}
- */
- updateAnimationDateAndLocation = (startDate, endDate, startLocation, endLocation, isDragging) => {
- const { animationStartLocation, animationEndLocation } = this.state;
- this.setState({
- animationStartLocation: startLocation || animationStartLocation,
- animationEndLocation: endLocation || animationEndLocation,
- animationStartLocationDate: startDate,
- animationEndLocationDate: endDate,
- isAnimationDraggerDragging: isDragging,
- });
- this.determineAnimationDraggerUpdate(startDate, endDate);
- };
-
- /**
- * @desc handle animation date dragger updates of startDate, endDate, or both
- * @param {String} startDate
- * @param {String} endDate
- * @returns {void}
- */
- determineAnimationDraggerUpdate = (startDate, endDate) => {
- const {
- animStartLocationDate,
- animEndLocationDate,
- } = this.props;
- const startChanged = animStartLocationDate !== startDate;
- const endChanged = animEndLocationDate !== endDate;
- if (startChanged) {
- if (endChanged) {
- this.debounceOnUpdateStartAndEndDate(startDate, endDate);
- } else {
- this.debounceOnUpdateStartDate(startDate);
- }
- } else if (endChanged) {
- this.debounceOnUpdateEndDate(endDate);
- }
- };
-
- /**
- * @desc handle animation dragger location and date state update
- * @param {String} startDate
- * @param {String} endDate
- * @returns {void}
- */
- animationDraggerDateUpdateLocal = (startDate, endDate) => {
- const {
- frontDate,
- position,
- transformX,
- } = this.state;
- const { timeScale } = this.props;
-
- const options = timeScaleOptions[timeScale].timeAxis;
- const { gridWidth } = options;
-
- const frontDateObj = moment.utc(frontDate);
- const startLocation = frontDateObj.diff(startDate, timeScale, true) * gridWidth;
- const endLocation = frontDateObj.diff(endDate, timeScale, true) * gridWidth;
-
- this.setState({
- animationStartLocation: position - startLocation + transformX,
- animationEndLocation: position - endLocation + transformX,
- animationStartLocationDate: startDate,
- animationEndLocationDate: endDate,
- });
- };
+ }
- /**
- * @desc handle animation dragger location and date state update and global date update
- * @param {String} startDate
- * @param {String} endDate
- * @returns {void}
- */
- animationDraggerDateUpdate = (startDate, endDate) => {
- const {
- animStartLocationDate,
- animEndLocationDate,
- } = this.props;
- // update local state location and date
- this.animationDraggerDateUpdateLocal(startDate, endDate);
+ function toggleHideTimelineFn() {
+ setTimelineHidden((prev) => !prev);
+ }
- // update global state date if changed
- const didStartDateChange = startDate.getTime() !== animStartLocationDate.getTime();
- const didEndDateChange = endDate.getTime() !== animEndLocationDate.getTime();
- if (didStartDateChange || didEndDateChange) {
- this.debounceOnUpdateStartAndEndDate(startDate, endDate);
- }
- };
+ function updateAnimationDateAndLocationFn(
+ startDate, endDate, startLocation, endLocation, isDragging,
+ ) {
+ const { animationStartLocation: asl, animationEndLocation: ael } = stateRef.current;
+ setAnimationStartLocation(startLocation || asl);
+ setAnimationEndLocation(endLocation || ael);
+ setAnimationStartLocationDate(startDate);
+ setAnimationEndLocationDate(endDate);
+ setIsAnimationDraggerDragging(isDragging);
+ determineAnimationDraggerUpdate(startDate, endDate);
+ }
- // DRAGGER
- /**
- * @desc update state dragger position and if new date, change store date
- * @param {String} newDate - new dragger date
- * @param {String} draggerSelected
- * @param {Number} draggerPositionArg
- * @param {Boolean} draggerVisibleArg
- * @param {Boolean} otherDraggerVisibleArg
- * @returns {void}
- */
- updateDraggerDatePosition = (
+ function updateDraggerDatePositionFn(
newDate,
- draggerSelected,
+ draggerSelectedArg,
draggerPositionArg,
draggerVisibleArg,
otherDraggerVisibleArg,
- ) => {
+ ) {
const {
- draggerPosition,
- draggerPositionB,
- draggerVisible,
- draggerVisibleB,
- draggerTimeState,
- draggerTimeStateB,
- } = this.state;
- if (draggerSelected === 'selected') {
- this.setState({
- draggerPosition: draggerPositionArg || draggerPosition,
- draggerVisible: draggerVisibleArg || draggerVisible,
- draggerVisibleB: otherDraggerVisibleArg || draggerVisibleB,
- draggerTimeState: newDate || draggerTimeState,
- });
+ draggerPosition: dp,
+ draggerPositionB: dpB,
+ draggerVisible: dv,
+ draggerVisibleB: dvB,
+ draggerTimeState: dts,
+ draggerTimeStateB: dtsB,
+ } = stateRef.current;
+ if (draggerSelectedArg === 'selected') {
+ setDraggerPosition(draggerPositionArg || dp);
+ setDraggerVisible(draggerVisibleArg || dv);
+ setDraggerVisibleB(otherDraggerVisibleArg || dvB);
+ setDraggerTimeState(newDate || dts);
if (newDate) {
- this.onDateChange(newDate, 'selected');
+ onDateChange(newDate, 'selected');
}
} else {
- this.setState({
- draggerPositionB: draggerPositionArg || draggerPositionB,
- draggerVisible: otherDraggerVisibleArg || draggerVisible,
- draggerVisibleB: draggerVisibleArg || draggerVisibleB,
- draggerTimeStateB: newDate || draggerTimeStateB,
- });
+ setDraggerPositionB(draggerPositionArg || dpB);
+ setDraggerVisible(otherDraggerVisibleArg || dv);
+ setDraggerVisibleB(draggerVisibleArg || dvB);
+ setDraggerTimeStateB(newDate || dtsB);
if (newDate) {
- this.onDateChange(newDate, 'selectedB');
+ onDateChange(newDate, 'selectedB');
}
}
- };
+ }
- /**
- * @desc set dragger visibility
- * @param {Boolean} draggerVisible
- * @param {Boolean} draggerVisibleB
- * @returns {void}
- */
- setDraggerVisibility = (draggerVisible, draggerVisibleB) => {
- this.setState({
- draggerVisible,
- draggerVisibleB,
- });
- };
+ function setDraggerVisibilityFn(dv, dvB) {
+ setDraggerVisible(dv);
+ setDraggerVisibleB(dvB);
+ }
- /**
- * @desc set matching layer coverage range for selected layers timeline
- * @param {Object} dateRange
- * @returns {void}
- */
- setMatchingTimelineCoverage = (dateRange, shouldIncludeHiddenLayers) => {
- this.setState({
- matchingTimelineCoverage: dateRange,
- shouldIncludeHiddenLayers,
- });
- };
+ function setMatchingTimelineCoverageFn(dateRange, includeHidden) {
+ setMatchingTimelineCoverage(dateRange);
+ setShouldIncludeHiddenLayers(includeHidden);
+ }
- /**
- * @desc toggle layer coverage panel open/closed
- * @param {Boolean} isOpen
- * @returns {void}
- */
- toggleLayerCoveragePanel = (isOpen) => {
+ function toggleLayerCoveragePanel(isOpen) {
if (isOpen) {
googleTagManager.pushEvent({
event: 'open_layer_coverage_panel',
});
}
- this.setState({
- isTimelineLayerCoveragePanelOpen: isOpen,
- });
- };
+ setIsTimelineLayerCoveragePanelOpen(isOpen);
+ }
- /**
- * @desc update dragger time state
- * @param {String} date
- * @param {Boolean} is dragger B selected to update
- * @returns {void}
- */
- updateDraggerTimeState = (date, isDraggerB) => {
+ function updateDraggerTimeStateFn(date, isDraggerB) {
if (isDraggerB) {
- this.setState({
- draggerTimeStateB: date,
- });
+ setDraggerTimeStateB(date);
} else {
- this.setState({
- draggerTimeState: date,
- });
+ setDraggerTimeState(date);
}
- };
+ }
- /**
- * Make sure user is not currently interacting with the timeline/dragger/scale/etc,
- * then update appNow to current time.
- */
- checkAndUpdateAppNow() {
- const {
- updateAppNow,
- } = this.props;
- const self = this;
+ const propsRef = useRef({});
+ propsRef.current = { isAnimationPlaying, updateAppNow };
+
+ function checkAndUpdateAppNow() {
const ensureCanUpdate = function() {
- return new Promise((resolve, reject) => {
+ return new Promise((resolve) => {
(function waitForSafeUpdate() {
const {
- isTimelineDragging,
- isDraggerDragging,
- isAnimationDraggerDragging,
- } = self.state;
- const { isAnimationPlaying, arrowDown } = self.props;
- const userIsInteracting = arrowDown || isTimelineDragging ||
- isDraggerDragging || isAnimationDraggerDragging;
- if (!userIsInteracting && !isAnimationPlaying) {
+ isTimelineDragging: dragging,
+ isDraggerDragging: draggerDrag,
+ isAnimationDraggerDragging: animDrag,
+ } = stateRef.current;
+ const { isAnimationPlaying: playing } = propsRef.current;
+ const userIsInteracting = dragging || draggerDrag || animDrag;
+ if (!userIsInteracting && !playing) {
return resolve();
}
return setTimeout(waitForSafeUpdate, 1000);
@@ -1009,73 +705,21 @@ class Timeline extends React.Component {
};
ensureCanUpdate().then(() => {
- updateAppNow(util.now());
+ propsRef.current.updateAppNow(util.now());
});
}
- setInitialState = () => {
- const {
- dateA,
- dateB,
- } = this.props;
- this.setState({
- draggerTimeState: dateA,
- draggerTimeStateB: dateB,
- hoverTime: dateA,
- initialLoadComplete: true,
- });
- };
-
- /**
- * @desc change store date
- * @param {String} date
- * @param {String} draggerSelected - default to props draggerSelected
- * @returns {void}
- */
-
- onDateChange = (date, draggerSelected = this.props.draggerSelected) => {
- const dateObj = new Date(date);
- const dateISOFormatted = getISODateFormatted(date);
- if (draggerSelected === 'selected') { // dragger A
- this.setState({
- draggerTimeState: dateISOFormatted,
- });
- } else { // dragger B
- this.setState({
- draggerTimeStateB: dateISOFormatted,
- });
- }
- this.debounceDateUpdate(dateObj, draggerSelected);
- };
-
- handleSelectNowButton = () => {
- const { triggerTodayButton } = this.props;
+ function handleSelectNowButton() {
triggerTodayButton();
- };
-
- /**
- * @desc getMobileDateButtonStyle date change button style for smaller displays
- * @returns {Object} style { left, bottom }
- */
- getMobileDateButtonStyle = () => {
- const {
- hasSubdailyLayers,
- isCompareModeActive,
- isEmbedModeActive,
- screenWidth,
- } = this.props;
+ }
- // default positioning
+ function getMobileDateButtonStyle() {
let mobileLeft = 190;
let mobileBottom = 20;
if (isEmbedModeActive) {
mobileLeft = 145;
mobileBottom = 20;
}
- // positioning will change depending on a combination of:
- // 1) subdaily (mobile date picker width);
- // 2) screen width; and
- // 3) compare mode
if (hasSubdailyLayers && screenWidth >= 484) {
mobileLeft = 287;
if (isEmbedModeActive) {
@@ -1094,46 +738,23 @@ class Timeline extends React.Component {
left: `${mobileLeft}px`,
bottom: `${mobileBottom}px`,
};
- };
+ }
- renderDateChangeArrows = () => {
- const {
- isMobile, leftArrowDisabled, rightArrowDisabled, nowButtonDisabled,
- } = this.props;
+ function renderDateChangeArrows() {
return (
<DateChangeArrows
- leftArrowDown={() => this.handleArrowDateChange(-1)}
+ leftArrowDown={() => handleArrowDateChange(-1)}
leftArrowDisabled={leftArrowDisabled}
isMobile={isMobile}
- rightArrowDown={() => this.handleArrowDateChange(1)}
+ rightArrowDown={() => handleArrowDateChange(1)}
rightArrowDisabled={rightArrowDisabled}
nowButtonDisabled={nowButtonDisabled}
- handleSelectNowButton={this.handleSelectNowButton}
+ handleSelectNowButton={handleSelectNowButton}
/>
);
- };
-
- renderMobile() {
- const {
- animationDisabled,
- hasSubdailyLayers,
- isCompareModeActive,
- isChartingActive,
- isDataDownload,
- isEmbedModeActive,
- isKioskModeActive,
- isMobile,
- isMobilePhone,
- isMobileTablet,
- isLandscape,
- isPortrait,
- breakpoints,
- screenWidth,
- selectedDate,
- timelineEndDateLimit,
- timelineStartDateLimit,
- } = this.props;
+ }
+ function renderMobile() {
const dataDownloadLabel = isDataDownload
? 'Animation feature is deactivated when Data Download feature is active'
: '';
@@ -1146,7 +767,7 @@ class Timeline extends React.Component {
date={selectedDate}
startDateLimit={timelineStartDateLimit}
endDateLimit={timelineEndDateLimit}
- onDateChange={this.onDateChange}
+ onDateChange={onDateChange}
hasSubdailyLayers={hasSubdailyLayers}
isMobile={isMobile}
isEmbedModeActive={isEmbedModeActive}
@@ -1154,10 +775,10 @@ class Timeline extends React.Component {
<MobileComparisonToggle />
<div
className="mobile-date-change-arrows-btn"
- style={this.getMobileDateButtonStyle()}
+ style={getMobileDateButtonStyle()}
>
<div id="zoom-buttons-group">
- {this.renderDateChangeArrows()}
+ {renderDateChangeArrows()}
</div>
</div>
<div>
@@ -1170,7 +791,7 @@ class Timeline extends React.Component {
isMobileTablet={isMobileTablet}
isLandscape={isLandscape}
isPortrait={isPortrait}
- clickAnimationButton={this.clickAnimationButton}
+ clickAnimationButton={clickAnimationButton}
hasSubdailyLayers={hasSubdailyLayers}
isKioskModeActive={isKioskModeActive}
isEmbedModeActive={isEmbedModeActive}
@@ -1185,169 +806,324 @@ class Timeline extends React.Component {
);
}
- render() {
- const {
- activeLayers,
- addGranuleDateRanges,
- animationDisabled,
- animEndLocationDate,
- animStartLocationDate,
- appNow,
- axisWidth,
- breakpoints,
- dateA,
- dateB,
- displayStaticMap,
- draggerSelected,
- hasFutureLayers,
- hasSubdailyLayers,
- hasTempoProduct,
- hideTimeline,
- isAnimationPlaying,
- isAnimatingToEvent,
- isAnimationWidgetOpen,
- isCompareModeActive,
- isChartingActive,
- isDataDownload,
- isDistractionFreeModeActive,
- isEmbedModeActive,
- isKioskModeActive,
- isMobile,
- isTourActive,
- parentOffset,
- screenWidth,
- selectedDate,
- timelineCustomModalOpen,
- timelineEndDateLimit,
- timelineStartDateLimit,
- timeScale,
- timeScaleChangeUnit,
- toggleActiveCompareState,
- proj,
- describeDomainsUrl,
- cmrBaseUrl,
- } = this.props;
- const {
- animationEndLocation,
- animationEndLocationDate,
- animationStartLocation,
- animationStartLocationDate,
- backDate,
- draggerPosition,
- draggerPositionB,
- draggerTimeState,
- draggerTimeStateB,
- draggerVisible,
- draggerVisibleB,
- frontDate,
- hoverLinePosition,
- hoverTime,
- initialLoadComplete,
- isAnimationDraggerDragging,
- isDraggerDragging,
- isTimelineDragging,
- isTimelineLayerCoveragePanelOpen,
- leftOffset,
- matchingTimelineCoverage,
- position,
- rangeSelectorMax,
- shouldIncludeHiddenLayers,
- showDraggerTime,
- showHoverLine,
- timelineHidden,
- transformX,
- } = this.state;
- const selectedDraggerPosition = draggerSelected === 'selected'
- ? draggerPosition
- : draggerPositionB;
- // timeline open/closed styling
- const isTimelineHidden = timelineHidden || hideTimeline;
- const chevronDirection = isTimelineHidden ? 'left' : 'right';
- const isAnimationWidgetReady = isAnimationWidgetOpen &&
- !animationDisabled &&
- animationStartLocation &&
- animationStartLocationDate &&
- animationEndLocation &&
- animationEndLocationDate;
-
- const containerDisplayStyle = {
- display: isDistractionFreeModeActive ? 'block' : 'block',
+ // EFFECTS
+
+ // Stable handler wrappers that delegate to refs (avoid stale closures)
+ const keyDownHandler = (e) => handleKeyDownRef.current(e);
+ const keyUpHandler = (e) => handleKeyUpRef.current(e);
+
+ // componentDidMount + componentWillUnmount
+ useEffect(() => {
+ document.addEventListener('keydown', keyDownHandler);
+ document.addEventListener('keyup', keyUpHandler);
+ document.querySelector('.timeline-container')
+ .addEventListener('wheel', preventDefaultFunc, { passive: false });
+
+ if (!nowOverride) {
+ appNowUpdateIntervalRef.current = setInterval(
+ () => checkAndUpdateAppNow(), 60000 * 10,
+ );
+ }
+
+ // setInitialState
+ setDraggerTimeState(dateA);
+ setDraggerTimeStateB(dateB);
+ setHoverTime(dateA);
+ setInitialLoadComplete(true);
+
+ return () => {
+ if (appNowUpdateIntervalRef.current) {
+ clearInterval(appNowUpdateIntervalRef.current);
+ }
+ document.removeEventListener('keydown', keyDownHandler);
+ document.removeEventListener('keyup', keyUpHandler);
+ document.querySelector('.timeline-container')
+ .removeEventListener('wheel', preventDefaultFunc);
};
+ }, []);
+
+ // getDerivedStateFromProps replacement - update animation dates when animation is initiated
+ useEffect(() => {
+ if (!animationStartLocationDate &&
+ !animationEndLocationDate &&
+ animStartLocationDate &&
+ animEndLocationDate) {
+ const startDate = animStartLocationDate;
+ const endDate = animEndLocationDate;
+ const options = timeScaleOptions[timeScale].timeAxis;
+ const { gridWidth } = options;
- const dataDownloadLabel = isDataDownload
- ? 'Animation feature is deactivated when Data Download feature is active'
- : '';
- const chartingActiveLabel = isChartingActive
- ? 'Animation feature is deactivated when Charting feature is active'
- : dataDownloadLabel;
+ const frontDateObj = moment.utc(frontDate);
+ const startLocation = frontDateObj.diff(startDate, timeScale, true) * gridWidth;
+ const endLocation = frontDateObj.diff(endDate, timeScale, true) * gridWidth;
- return (
- <div
- className="timeline-container"
- style={containerDisplayStyle}
- >
- {initialLoadComplete && !isDistractionFreeModeActive &&
- (
- <ErrorBoundary>
- {isMobile || isEmbedModeActive
- /* Mobile Timeline Size */
- ? this.renderMobile()
- /* Normal Timeline Size */
- : !isDistractionFreeModeActive && (
- <section id="timeline" className="timeline-inner clearfix">
- <div
- id="timeline-header"
- className={`timeline-header-desktop ${hasSubdailyLayers ? 'subdaily' : ''}`}
- style={{ marginRight: isTimelineHidden ? '20px' : '0' }}
- >
- {/* Date Selector, Interval, Arrow Controls */}
- <div id="date-selector-main" className={isKioskModeActive ? 'date-selector-kiosk' : ''}>
- <DateSelector
- id={draggerSelected}
- idSuffix="timeline"
- date={new Date(selectedDate)}
- onDateChange={this.onDateChange}
- maxDate={new Date(timelineEndDateLimit)}
- minDate={new Date(timelineStartDateLimit)}
- subDailyMode={hasSubdailyLayers}
- isKioskModeActive={isKioskModeActive}
- fontSize={24}
- />
- </div>
- <div id="zoom-buttons-group" className={isKioskModeActive ? 'd-none' : ''}>
+ setAnimationStartLocationDate(animStartLocationDate);
+ setAnimationEndLocationDate(animEndLocationDate);
+ setAnimationStartLocation(position - startLocation + transformX);
+ setAnimationEndLocation(position - endLocation + transformX);
+ }
+ }, [animStartLocationDate, animEndLocationDate]);
- <TimeScaleIntervalChange
- timeScaleChangeUnit={timeScaleChangeUnit}
- hasSubdailyLayers={hasSubdailyLayers}
- hasTempoProduct={hasTempoProduct}
- modalType={customModalType.TIMELINE}
- />
+ // componentDidUpdate logic — skip on first render (componentDidUpdate doesn't run on mount)
+ const hasMountedRef = useRef(false);
+ useEffect(() => {
+ if (!hasMountedRef.current) {
+ hasMountedRef.current = true;
+ return;
+ }
+
+ // handle update animation positioning from play button/gif creation
+ const didAnimationTurnOn = !prevIsAnimationPlaying && isAnimationPlaying;
+ const didGifTurnOn = !prevIsGifActive && isGifActive;
+ if (didAnimationTurnOn || didGifTurnOn) {
+ animationDraggerDateUpdateLocal(animStartLocationDate, animEndLocationDate);
+ }
+
+ // handle location update from animation widget date changes
+ if (isAnimationWidgetOpen) {
+ if (
+ prevAnimStartLocationDate &&
+ prevAnimEndLocationDate &&
+ animStartLocationDate &&
+ animEndLocationDate
+ ) {
+ const animStartDateChanged = prevAnimStartLocationDate.getTime() !==
+ animStartLocationDate.getTime();
+ const animEndDateChanged = prevAnimEndLocationDate.getTime() !==
+ animEndLocationDate.getTime();
+ const frontDateChanged = prevFrontDate !== frontDate;
+ if (animStartDateChanged || animEndDateChanged || frontDateChanged) {
+ animationDraggerDateUpdate(animStartLocationDate, animEndLocationDate);
+ }
+ }
+ }
+
+ const subdailyRemoved = !hasSubdailyLayers && prevHasSubdailyLayers;
+ const tempoRemoved = !hasTempoProduct && prevHasTempoProduct;
+ const subDailyCountChanged = prevSubDailyLayersList &&
+ subDailyLayersList.length !== prevSubDailyLayersList.length;
+ const subdailyInterval = customInterval > 3 || interval > 3;
+
+ if (tempoRemoved) {
+ changeAutoInterval();
+ selectInterval(1, TIME_SCALE_TO_NUMBER.day, false, false);
+ }
+ if (subdailyRemoved && subdailyInterval) {
+ changeCustomInterval();
+ selectInterval(1, TIME_SCALE_TO_NUMBER.day, false, false);
+ }
+
+ const isSubDaily = newCustomDelta < 1440;
+ if (subDailyCountChanged) {
+ if (hasTempoProduct) {
+ changeAutoInterval(true);
+ } else if (isSubDaily) {
+ changeCustomInterval(newCustomDelta, TIME_SCALE_TO_NUMBER.minute);
+ }
+ }
+
+ if (hasSubdailyLayers && !prevHasSubdailyLayers) {
+ changeTimeScaleLocal(4);
+ }
+
+ if (dateA !== prevDateA && dateA !== draggerTimeState) {
+ updateDraggerTimeStateFn(dateA, false);
+ }
+ if (dateB !== prevDateB && dateB !== draggerTimeStateB) {
+ updateDraggerTimeStateFn(dateB, true);
+ }
+ });
+
+ // RENDER
+
+ const selectedDraggerPosition = draggerSelected === 'selected'
+ ? draggerPosition
+ : draggerPositionB;
+ const isTimelineHidden = timelineHidden || hideTimeline;
+ const chevronDirection = isTimelineHidden ? 'left' : 'right';
+ const isAnimationWidgetReady = isAnimationWidgetOpen &&
+ !animationDisabled &&
+ animationStartLocation &&
+ animationStartLocationDate &&
+ animationEndLocation &&
+ animationEndLocationDate;
+
+ const containerDisplayStyle = {
+ display: isDistractionFreeModeActive ? 'block' : 'block',
+ };
- {this.renderDateChangeArrows()}
- </div>
- <AnimationButton
- clickAnimationButton={this.clickAnimationButton}
- disabled={animationDisabled}
+ const dataDownloadLabel = isDataDownload
+ ? 'Animation feature is deactivated when Data Download feature is active'
+ : '';
+ const chartingActiveLabel = isChartingActive
+ ? 'Animation feature is deactivated when Charting feature is active'
+ : dataDownloadLabel;
+
+ return (
+ <div
+ className="timeline-container"
+ style={containerDisplayStyle}
+ >
+ {initialLoadComplete && !isDistractionFreeModeActive &&
+ (
+ <ErrorBoundary>
+ {isMobile || isEmbedModeActive
+ /* Mobile Timeline Size */
+ ? renderMobile()
+ /* Normal Timeline Size */
+ : !isDistractionFreeModeActive && (
+ <section id="timeline" className="timeline-inner clearfix">
+ <div
+ id="timeline-header"
+ className={`timeline-header-desktop ${hasSubdailyLayers ? 'subdaily' : ''}`}
+ style={{ marginRight: isTimelineHidden ? '20px' : '0' }}
+ >
+ {/* Date Selector, Interval, Arrow Controls */}
+ <div id="date-selector-main" className={isKioskModeActive ? 'date-selector-kiosk' : ''}>
+ <DateSelector
+ id={draggerSelected}
+ idSuffix="timeline"
+ date={new Date(selectedDate)}
+ onDateChange={onDateChange}
+ maxDate={new Date(timelineEndDateLimit)}
+ minDate={new Date(timelineStartDateLimit)}
+ subDailyMode={hasSubdailyLayers}
isKioskModeActive={isKioskModeActive}
- screenWidth={screenWidth}
- breakpoints={breakpoints}
- label={isCompareModeActive
- ? 'Animation feature is deactivated when Compare feature is active'
- : chartingActiveLabel}
+ fontSize={24}
/>
</div>
+ <div id="zoom-buttons-group" className={isKioskModeActive ? 'd-none' : ''}>
- {!isTimelineHidden &&
- (
- <div id="timeline-footer" className="notranslate">
- {/* Axis */}
- <TimelineAxis
- activeLayers={activeLayers}
- addGranuleDateRanges={addGranuleDateRanges}
- appNow={appNow}
+ <TimeScaleIntervalChange
+ timeScaleChangeUnit={timeScaleChangeUnit}
+ hasSubdailyLayers={hasSubdailyLayers}
+ hasTempoProduct={hasTempoProduct}
+ modalType={customModalType.TIMELINE}
+ />
+
+ {renderDateChangeArrows()}
+ </div>
+ <AnimationButton
+ clickAnimationButton={clickAnimationButton}
+ disabled={animationDisabled}
+ isKioskModeActive={isKioskModeActive}
+ screenWidth={screenWidth}
+ breakpoints={breakpoints}
+ label={isCompareModeActive
+ ? 'Animation feature is deactivated when Compare feature is active'
+ : chartingActiveLabel}
+ />
+ </div>
+
+ {!isTimelineHidden &&
+ (
+ <div id="timeline-footer" className="notranslate">
+ {/* Axis */}
+ <TimelineAxis
+ activeLayers={activeLayers}
+ addGranuleDateRanges={addGranuleDateRanges}
+ appNow={appNow}
+ axisWidth={axisWidth}
+ parentOffset={parentOffset}
+ leftOffset={leftOffset}
+ position={position}
+ transformX={transformX}
+ timeScale={timeScale}
+ timelineStartDateLimit={timelineStartDateLimit}
+ timelineEndDateLimit={timelineEndDateLimit}
+ frontDate={frontDate}
+ backDate={backDate}
+ dateA={dateA}
+ dateB={dateB}
+ hoverTime={hoverTime}
+ draggerSelected={draggerSelected}
+ draggerTimeState={draggerTimeState}
+ draggerTimeStateB={draggerTimeStateB}
+ draggerPosition={draggerPosition}
+ draggerPositionB={draggerPositionB}
+ draggerVisible={draggerVisible}
+ draggerVisibleB={draggerVisibleB}
+ animationStartLocation={animationStartLocation}
+ animationEndLocation={animationEndLocation}
+ animStartLocationDate={animStartLocationDate}
+ animEndLocationDate={animEndLocationDate}
+ debounceChangeTimeScaleWheel={debounceChangeTimeScaleWheelRef.current}
+ onDateChange={onDateChange}
+ updatePositioning={updatePositioning}
+ updateTimelineMoveAndDrag={updateTimelineMoveAndDrag}
+ updatePositioningOnSimpleDrag={updatePositioningOnSimpleDrag}
+ updatePositioningOnAxisStopDrag={updatePositioningOnAxisStopDrag}
+ updateDraggerDatePosition={updateDraggerDatePositionFn}
+ showHoverOn={showHoverOn}
+ showHoverOff={showHoverOff}
+ showHover={showHoverFn}
+ hasFutureLayers={hasFutureLayers}
+ hasSubdailyLayers={hasSubdailyLayers}
+ isCompareModeActive={isCompareModeActive}
+ isAnimationPlaying={isAnimationPlaying}
+ isAnimatingToEvent={isAnimatingToEvent}
+ isTourActive={isTourActive}
+ isAnimationDraggerDragging={isAnimationDraggerDragging}
+ isDraggerDragging={isDraggerDragging}
+ isTimelineDragging={isTimelineDragging}
+ matchingTimelineCoverage={matchingTimelineCoverage}
+ proj={proj}
+ describeDomainsUrl={describeDomainsUrl}
+ cmrBaseUrl={cmrBaseUrl}
+ />
+
+ <AxisHoverLine
+ activeLayers={activeLayers}
+ shouldIncludeHiddenLayers={shouldIncludeHiddenLayers}
+ axisWidth={axisWidth}
+ hoverLinePosition={hoverLinePosition}
+ showHoverLine={showHoverLine}
+ isTimelineDragging={isTimelineDragging}
+ isAnimationDraggerDragging={isAnimationDraggerDragging}
+ isDraggerDragging={isDraggerDragging}
+ selectedDraggerPosition={selectedDraggerPosition}
+ isTimelineLayerCoveragePanelOpen={isTimelineLayerCoveragePanelOpen}
+ />
+
+ {/* Timeline Layer Coverage Panel */}
+ <TimelineLayerCoveragePanel
+ appNow={appNow}
+ axisWidth={axisWidth}
+ backDate={backDate}
+ frontDate={frontDate}
+ isTimelineLayerCoveragePanelOpen={isTimelineLayerCoveragePanelOpen}
+ matchingTimelineCoverage={matchingTimelineCoverage}
+ parentOffset={parentOffset}
+ positionTransformX={position + transformX}
+ setMatchingTimelineCoverage={setMatchingTimelineCoverageFn}
+ timelineStartDateLimit={timelineStartDateLimit}
+ timeScale={timeScale}
+ toggleLayerCoveragePanel={toggleLayerCoveragePanel}
+ />
+
+ {isAnimationWidgetReady &&
+ (
+ <TimelineRangeSelector
+ axisWidth={axisWidth}
+ position={position}
+ transformX={transformX}
+ timeScale={timeScale}
+ timelineStartDateLimit={timelineStartDateLimit}
+ timelineEndDateLimit={timelineEndDateLimit}
+ frontDate={frontDate}
+ startLocation={animationStartLocation}
+ endLocation={animationEndLocation}
+ startLocationDate={animationStartLocationDate}
+ endLocationDate={animationEndLocationDate}
+ updateAnimationDateAndLocation={updateAnimationDateAndLocationFn}
+ max={rangeSelectorMax}
+ />
+ )}
+
+ {frontDate &&
+ (
+ <DraggerContainer
axisWidth={axisWidth}
- parentOffset={parentOffset}
- leftOffset={leftOffset}
position={position}
transformX={transformX}
timeScale={timeScale}
@@ -1355,9 +1131,6 @@ class Timeline extends React.Component {
timelineEndDateLimit={timelineEndDateLimit}
frontDate={frontDate}
backDate={backDate}
- dateA={dateA}
- dateB={dateB}
- hoverTime={hoverTime}
draggerSelected={draggerSelected}
draggerTimeState={draggerTimeState}
draggerTimeStateB={draggerTimeStateB}
@@ -1365,189 +1138,93 @@ class Timeline extends React.Component {
draggerPositionB={draggerPositionB}
draggerVisible={draggerVisible}
draggerVisibleB={draggerVisibleB}
- animationStartLocation={animationStartLocation}
- animationEndLocation={animationEndLocation}
- animStartLocationDate={animStartLocationDate}
- animEndLocationDate={animEndLocationDate}
- debounceChangeTimeScaleWheel={this.debounceChangeTimeScaleWheel}
- onDateChange={this.onDateChange}
- updatePositioning={this.updatePositioning}
- updateTimelineMoveAndDrag={this.updateTimelineMoveAndDrag}
- updatePositioningOnSimpleDrag={this.updatePositioningOnSimpleDrag}
- updatePositioningOnAxisStopDrag={this.updatePositioningOnAxisStopDrag}
- updateDraggerDatePosition={this.updateDraggerDatePosition}
- showHoverOn={this.showHoverOn}
- showHoverOff={this.showHoverOff}
- showHover={this.showHover}
- hasFutureLayers={hasFutureLayers}
- hasSubdailyLayers={hasSubdailyLayers}
+ setDraggerVisibility={setDraggerVisibilityFn}
+ toggleShowDraggerTime={toggleShowDraggerTimeFn}
+ onChangeSelectedDragger={toggleActiveCompareState}
+ updateDraggerDatePosition={updateDraggerDatePositionFn}
isCompareModeActive={isCompareModeActive}
- isAnimationPlaying={isAnimationPlaying}
- isAnimatingToEvent={isAnimatingToEvent}
- isTourActive={isTourActive}
- isAnimationDraggerDragging={isAnimationDraggerDragging}
isDraggerDragging={isDraggerDragging}
- isTimelineDragging={isTimelineDragging}
- matchingTimelineCoverage={matchingTimelineCoverage}
- proj={proj}
- describeDomainsUrl={describeDomainsUrl}
- cmrBaseUrl={cmrBaseUrl}
+ isAnimationPlaying={isAnimationPlaying}
/>
+ )}
- <AxisHoverLine
+ {!isTimelineDragging &&
+ (
+ <DateTooltip
activeLayers={activeLayers}
shouldIncludeHiddenLayers={shouldIncludeHiddenLayers}
axisWidth={axisWidth}
- hoverLinePosition={hoverLinePosition}
- showHoverLine={showHoverLine}
- isTimelineDragging={isTimelineDragging}
- isAnimationDraggerDragging={isAnimationDraggerDragging}
- isDraggerDragging={isDraggerDragging}
+ leftOffset={leftOffset}
+ hoverTime={hoverTime}
+ selectedDate={selectedDate}
selectedDraggerPosition={selectedDraggerPosition}
+ hasSubdailyLayers={hasSubdailyLayers}
+ showDraggerTime={showDraggerTime}
+ showHoverLine={showHoverLine}
isTimelineLayerCoveragePanelOpen={isTimelineLayerCoveragePanelOpen}
/>
-
- {/* Timeline Layer Coverage Panel */}
- <TimelineLayerCoveragePanel
- appNow={appNow}
- axisWidth={axisWidth}
- backDate={backDate}
- frontDate={frontDate}
- isTimelineLayerCoveragePanelOpen={isTimelineLayerCoveragePanelOpen}
- matchingTimelineCoverage={matchingTimelineCoverage}
- parentOffset={parentOffset}
- positionTransformX={position + transformX}
- setMatchingTimelineCoverage={this.setMatchingTimelineCoverage}
- timelineStartDateLimit={timelineStartDateLimit}
- timeScale={timeScale}
- toggleLayerCoveragePanel={this.toggleLayerCoveragePanel}
- />
-
- {isAnimationWidgetReady &&
- (
- <TimelineRangeSelector
- axisWidth={axisWidth}
- position={position}
- transformX={transformX}
- timeScale={timeScale}
- timelineStartDateLimit={timelineStartDateLimit}
- timelineEndDateLimit={timelineEndDateLimit}
- frontDate={frontDate}
- startLocation={animationStartLocation}
- endLocation={animationEndLocation}
- startLocationDate={animationStartLocationDate}
- endLocationDate={animationEndLocationDate}
- updateAnimationDateAndLocation={this.updateAnimationDateAndLocation}
- max={rangeSelectorMax}
- />
- )}
-
- {frontDate &&
- (
- <DraggerContainer
- axisWidth={axisWidth}
- position={position}
- transformX={transformX}
- timeScale={timeScale}
- timelineStartDateLimit={timelineStartDateLimit}
- timelineEndDateLimit={timelineEndDateLimit}
- frontDate={frontDate}
- backDate={backDate}
- draggerSelected={draggerSelected}
- draggerTimeState={draggerTimeState}
- draggerTimeStateB={draggerTimeStateB}
- draggerPosition={draggerPosition}
- draggerPositionB={draggerPositionB}
- draggerVisible={draggerVisible}
- draggerVisibleB={draggerVisibleB}
- setDraggerVisibility={this.setDraggerVisibility}
- toggleShowDraggerTime={this.toggleShowDraggerTime}
- onChangeSelectedDragger={toggleActiveCompareState}
- updateDraggerDatePosition={this.updateDraggerDatePosition}
- isCompareModeActive={isCompareModeActive}
- isDraggerDragging={isDraggerDragging}
- isAnimationPlaying={isAnimationPlaying}
- />
- )}
-
- {!isTimelineDragging &&
- (
- <DateTooltip
- activeLayers={activeLayers}
- shouldIncludeHiddenLayers={shouldIncludeHiddenLayers}
- axisWidth={axisWidth}
- leftOffset={leftOffset}
- hoverTime={hoverTime}
- selectedDate={selectedDate}
- selectedDraggerPosition={selectedDraggerPosition}
- hasSubdailyLayers={hasSubdailyLayers}
- showDraggerTime={showDraggerTime}
- showHoverLine={showHoverLine}
- isTimelineLayerCoveragePanelOpen={isTimelineLayerCoveragePanelOpen}
- />
- )}
- </div>
- )}
-
- {/* Custom Interval Selector Widget */}
- <CustomIntervalSelector
- modalOpen={timelineCustomModalOpen}
- hasSubdailyLayers={hasSubdailyLayers}
- />
-
- {/* Zoom Level Change Controls */}
- <AxisTimeScaleChange
- timeScale={timeScale}
- changeTimeScale={this.changeTimeScale}
- isDraggerDragging={isDraggerDragging}
- hasSubdailyLayers={hasSubdailyLayers}
- timelineHidden={isTimelineHidden}
+ )}
+ </div>
+ )}
+
+ {/* Custom Interval Selector Widget */}
+ <CustomIntervalSelector
+ modalOpen={timelineCustomModalOpen}
+ hasSubdailyLayers={hasSubdailyLayers}
+ />
+
+ {/* Zoom Level Change Controls */}
+ <AxisTimeScaleChange
+ timeScale={timeScale}
+ changeTimeScale={changeTimeScaleLocal}
+ isDraggerDragging={isDraggerDragging}
+ hasSubdailyLayers={hasSubdailyLayers}
+ timelineHidden={isTimelineHidden}
+ />
+
+ {/* Open/Close Chevron */}
+ <button
+ type="button"
+ id="timeline-hide"
+ aria-label={isTimelineHidden ? 'Show timeline' : 'Hide timeline'}
+ onClick={toggleHideTimelineFn}
+ >
+ <UncontrolledTooltip id="center-align-tooltip" target="timeline-hide" placement="top">
+ {isTimelineHidden ? 'Show timeline' : 'Hide timeline'}
+ </UncontrolledTooltip>
+ <div
+ className={`wv-timeline-hide wv-timeline-hide-double-chevron-${chevronDirection}`}
/>
-
- {/* Open/Close Chevron */}
- <button
- type="button"
- id="timeline-hide"
- aria-label={isTimelineHidden ? 'Show timeline' : 'Hide timeline'}
- onClick={this.toggleHideTimeline}
- >
- <UncontrolledTooltip id="center-align-tooltip" target="timeline-hide" placement="top">
- {isTimelineHidden ? 'Show timeline' : 'Hide timeline'}
- </UncontrolledTooltip>
- <div
- className={`wv-timeline-hide wv-timeline-hide-double-chevron-${chevronDirection}`}
- />
- </button>
- </section>
- )}
- </ErrorBoundary>
- )}
- {initialLoadComplete && isDistractionFreeModeActive &&
- (
- <ErrorBoundary>
- <section id="distraction-free-timeline" className="clearfix">
- <div
- id="distraction-free-timeline-header"
- className={`distraction-free-timeline-header ${hasSubdailyLayers ? 'subdaily' : ''} ${isMobile ? 'mobile' : ''}`}
- style={
- {
- marginRight: isTimelineHidden ? '20px' : '0',
- display: displayStaticMap ? 'none' : 'flex',
- }
- }
- >
- <KioskTimeStamp
- date={selectedDate}
- subdaily={hasSubdailyLayers}
- isKioskModeActive={isKioskModeActive}
- />
- </div>
- </section>
+ </button>
+ </section>
+ )}
</ErrorBoundary>
)}
- </div>
- );
- }
+ {initialLoadComplete && isDistractionFreeModeActive &&
+ (
+ <ErrorBoundary>
+ <section id="distraction-free-timeline" className="clearfix">
+ <div
+ id="distraction-free-timeline-header"
+ className={`distraction-free-timeline-header ${hasSubdailyLayers ? 'subdaily' : ''} ${isMobile ? 'mobile' : ''}`}
+ style={
+ {
+ marginRight: isTimelineHidden ? '20px' : '0',
+ display: displayStaticMap ? 'none' : 'flex',
+ }
+ }
+ >
+ <KioskTimeStamp
+ date={selectedDate}
+ subdaily={hasSubdailyLayers}
+ isKioskModeActive={isKioskModeActive}
+ />
+ </div>
+ </section>
+ </ErrorBoundary>
+ )}
+ </div>
+ );
}
function mapStateToProps(state) {