// Copyright (c) 2022 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. import React, {useMemo} from 'react'; import throttle from 'lodash/throttle'; import styled from 'styled-components'; import RangeSliderFactory from 'components/common/range-slider'; import TimeSliderMarkerFactory from 'components/common/time-slider-marker'; import PlaybackControlsFactory from 'components/common/animation-control/playback-controls'; import TimeRangeSliderTimeTitleFactory from 'components/common/time-range-slider-time-title'; import {HistogramBin, LineChart} from 'reducers'; const animationControlWidth = 176; interface StyledSliderContainerProps { isEnlarged?: boolean; } type TimeRangeSliderProps = { domain?: [number, number]; value: [number, number]; isEnlarged?: boolean; hideTimeTitle?: boolean; isAnimating: boolean; timeFormat: string; timezone?: string | null; histogram?: HistogramBin[]; plotType?: string; lineChart?: LineChart; step: number; isAnimatable?: boolean; speed: number; animationWindow: string; resetAnimation?: () => void; toggleAnimation: () => void; updateAnimationSpeed?: (val: number) => void; setFilterAnimationWindow?: (id: string) => void; onChange: (v: number[]) => void; }; const StyledSliderContainer = styled.div` align-items: flex-end; display: flex; flex-direction: row; justify-content: space-between; padding-left: ${props => (props.isEnlarged ? 24 : 0)}px; .timeline-container .kg-slider { display: none; } .playback-controls { margin-left: 22px; } `; TimeRangeSliderFactory.deps = [ PlaybackControlsFactory, RangeSliderFactory, TimeSliderMarkerFactory, TimeRangeSliderTimeTitleFactory ]; export default function TimeRangeSliderFactory( PlaybackControls: ReturnType, RangeSlider: ReturnType, TimeSliderMarker: ReturnType, TimeRangeSliderTimeTitle: ReturnType ) { const TimeRangeSlider: React.FC = props => { const { domain, value, isEnlarged, hideTimeTitle, isAnimating, resetAnimation, timeFormat, timezone, histogram, plotType, lineChart, step, isAnimatable, speed, animationWindow, updateAnimationSpeed, setFilterAnimationWindow, toggleAnimation, onChange } = props; const throttledOnchange = useMemo(() => throttle(onChange, 20), [onChange]); return (
{!hideTimeTitle ? (
) : null}
{isEnlarged ? ( ) : null}
); }; return React.memo(TimeRangeSlider); }