upsetjs export interface BandScaleLike { ( v ) : number | undefined ; bandwidth ( ) : number ; } export interface BandScaleFactory { ( domain , size , padding ) : BandScaleLike ; } export const bandScale = ( domain , size , padding ) => { const blocks = domain . length + padding ; const step = size / Math . max ( 1 , blocks ) ; const start = size - step * domain . length ; const lookup = new Map ( domain . map ( ( d , i ) => [ d , i ] ) ) ; const bandwidth = step / ( 1 + padding ) ; const scale = ( v ) => { const index = lookup . get ( v ) ; if ( index == null ) { return undefined ; } return start + step * index ; } ; scale . bandwidth = ( ) => bandwidth ; return scale ; } ;