import { zoomIdentity , ZoomTransform } from 'd3-zoom' ; import { MovementConfig , Scale } from '../../common/types' ; export const createBrushTransform = ( { xScale , xSelectedPixelMax , xSelectedPixelMin , xScaleOriginal , movement , } ) : ZoomTransform => { const timeSpan = ( xScale . invert ( xSelectedPixelMax ) as Date ) . getTime ( ) - ( xScale . invert ( xSelectedPixelMin ) as Date ) . getTime ( ) ; const prevTimeSpan = ( xScaleOriginal . domain ( ) [ 1 ] as Date ) . getTime ( ) - ( xScaleOriginal . domain ( ) [ 0 ] as Date ) . getTime ( ) ; const k = Math . max ( Math . min ( prevTimeSpan / timeSpan , movement . zoomMax ) , movement . zoomMin ) ; const xMin = xScaleOriginal ( xScale . invert ( xSelectedPixelMin ) ) ; const t = - 1 * k * xMin ; return zoomIdentity . translate ( t , 0 ) . scale ( k ) ; } ;