import { Axis , Scale } from '@chart-parts/interfaces' ; import { AxisContext , PositionedTickValue } from '../../interfaces' ; ignore param context export function getTickValues ( context ) { const { axis , scale } = context ; if ( axis . values != null ) { return axis . values . map ( av => ( { ... av , position : scale ( av . value ) } ) ) ; } return scale . ticks ? getTicksFromScaleTicks ( context ) : scale . domain ? getTicksFromScaleDomain ( context , scale ) : [ ] ; } function getDomainScaleValue ( t , scale , axis ) { const tickRound = axis . tickRound ; const bandPosition = axis . bandPosition as number ; const result = scale . bandwidth ? scale ( t ) + scale . bandwidth ( ) * bandPosition : t ; return tickRound ? Math . round ( result ) : result ; } function getTicksFromScaleTicks ( context ) { const { axis , scale } = context ; const tickWidth = axis . tickWidth as number ; if ( ! scale . ticks ) { throw new Error ( 'cannot extract scale domain' ) ; } const ticks = axis . tickCount != null ? scale . ticks ( axis . tickCount ) : scale . ticks ( ) ; return ticks . map ( ( t ) => { const position = scale ( t ) ; const label = context . labelFormatter ( t ) ; return { value : t , position : axis . tickRound ? Math . round ( position ) : position - tickWidth / 2 , label , } ; } ) ; } function getTicksFromScaleDomain ( context , scale ) { const { axis } = context ; if ( ! scale . domain ) { throw new Error ( 'cannot extract scale domain' ) ; } const domain = scale . domain ( ) ; return domain . map ( ( t ) => { const label = context . labelFormatter ( t ) ; return { value : t , position : getDomainScaleValue ( t , scale , axis ) , label , } ; } ) ; }