import { zoomIdentity , ZoomTransform } from 'd3-zoom' ; import { Scale } from '../../common/types' ; export const getTransformFromDates = ( { prevXScale , prevDates , currDates , } ) => { const prevTimeSpan = prevDates . end . getTime ( ) - prevDates . start . getTime ( ) ; const currTimeSpan = currDates . end . getTime ( ) - currDates . start . getTime ( ) ; const k = prevTimeSpan / currTimeSpan ; const xCurrStartDate = prevXScale ( currDates . start ) ; const t = - 1 * xCurrStartDate * k ; return zoomIdentity . translate ( t , 0 ) . scale ( k ) ; } ; /**
 * Get Transformed Date Range
 * Apply a given transformation to the given date range
 *
 * NOTE: The reason to pass in an `xScale` as opposed to the start and end date directly
 * is that a transform is in terms of the pixel space,
 * rather than the input space (the domain in which the data is in, which is time plus some number value).
 */ export const getTransformedDateRange = ( { xScale , transform , } ) : { startDate : Date ; endDate : Date ; } => { const transformedScale = transform . rescaleX ( xScale ) ; const [ startTime , endTime ] = transformedScale . domain ( ) ; return { startDate : new Date ( startTime ) , endDate : new Date ( endTime ) , } ; } ;