import { ScaleContinuousNumeric , ScaleTime } from "d3-scale" ; import { first , last } from "." ; param props param moreProps return { number } export const plotDataLengthBarWidth = < T > ( props , moreProps ) : number => { const { widthRatio } = props ; const { xAccessor , xScale , plotData } = moreProps ; const [ l , r ] = xScale . range ( ) ; if ( xScale . invert != null ) { const [ dl , dr ] = xScale . domain ( ) ; if ( typeof dl === "number" && typeof dr === "number" ) { const totalWidth = Math . abs ( r - l ) ; const width = totalWidth / Math . abs ( dl - dr ) ; return width * widthRatio ; } const width = xScale ( xAccessor ( last ( plotData ) ) ) - xScale ( xAccessor ( first ( plotData ) ) ) ; return ( width / plotData . length ) * widthRatio * 0.7 ; } const totalWidth = Math . abs ( r - l ) ; const width = totalWidth / xScale . domain ( ) . length ; return width * widthRatio ; } ;