import { AxisProps } from '.' ; import { Position } from '../../../../../utils/common' ; import { AxisTick , getTickLabelPosition } from '../../../utils/axis_utils' ; import { renderText } from '../primitives/text' ; import { renderDebugRectCenterRotated } from '../utils/debug' ; const TICK_TO_LABEL_GAP = 2 ; internal export function renderTickLabel ( ctx , tick , showTicks , { axisSpec : { position , timeAxisLayerCount } , dimension , size , debug , axisStyle } , layerGirth ) { const labelStyle = axisStyle . tickLabel ; const tickLabelProps = getTickLabelPosition ( axisStyle , tick . domainClampedPosition , position , labelStyle . rotation , size , dimension , showTicks , labelStyle . offset , labelStyle . alignment ) ; const center = { x : tickLabelProps . x + tickLabelProps . offsetX , y : tickLabelProps . y + tickLabelProps . offsetY } ; if ( debug ) { const { maxLabelBboxWidth , maxLabelBboxHeight , maxLabelTextWidth : width , maxLabelTextHeight : height } = dimension ; renderDebugRectCenterRotated ( ctx , center , { ... center , width , height } , undefined , undefined , labelStyle . rotation ) ; if ( labelStyle . rotation % 90 !== 0 ) { renderDebugRectCenterRotated ( ctx , center , { ... center , width : maxLabelBboxWidth , height : maxLabelBboxHeight } ) ; } } const tickOnTheSide = timeAxisLayerCount > 0 && Number . isFinite ( tick . layer ) ; renderText ( ctx , center , tick . label , { fontFamily : labelStyle . fontFamily , fontStyle : labelStyle . fontStyle ?? 'normal' , fontVariant : 'normal' , fontWeight : 'normal' , textColor : labelStyle . fill , fontSize : labelStyle . fontSize , align : tickLabelProps . horizontalAlign , baseline : tickLabelProps . verticalAlign , } , labelStyle . rotation , tickLabelProps . textOffsetX + ( tickOnTheSide ? TICK_TO_LABEL_GAP : 0 ) , tickLabelProps . textOffsetY + ( tick . layer || 0 ) * layerGirth * ( position === Position . Top ? - 1 : 1 ) , 1 , tick . direction ) ; }