@@ -10,6 +10,7 @@ import {
1010 Rotation ,
1111 TickFormatter ,
1212 UpperBoundedDomain ,
13+ AxisStyle ,
1314} from '../series/specs' ;
1415import { AxisConfig , Theme } from '../themes/theme' ;
1516import { Dimensions , Margins } from '../utils/dimensions' ;
@@ -44,7 +45,7 @@ export interface TickLabelProps {
4445/**
4546 * Compute the ticks values and identify max width and height of the labels
4647 * so we can compute the max space occupied by the axis component.
47- * @param axisSpec tbe spec of the axis
48+ * @param axisSpec the spec of the axis
4849 * @param xDomain the x domain associated
4950 * @param yDomain the y domain array
5051 * @param totalBarsInCluster the total number of grouped series
@@ -69,11 +70,15 @@ export function computeAxisTicksDimensions(
6970 if ( ! scale ) {
7071 throw new Error ( `Cannot compute scale for axis spec ${ axisSpec . id } ` ) ;
7172 }
73+
74+ const tickLabelPadding = getAxisTickLabelPadding ( axisConfig . tickLabelStyle . padding , axisSpec . style ) ;
75+
7276 const dimensions = computeTickDimensions (
7377 scale ,
7478 axisSpec . tickFormat ,
7579 bboxCalculator ,
7680 axisConfig ,
81+ tickLabelPadding ,
7782 axisSpec . tickLabelRotation ,
7883 ) ;
7984
@@ -82,6 +87,13 @@ export function computeAxisTicksDimensions(
8287 } ;
8388}
8489
90+ export function getAxisTickLabelPadding ( axisConfigTickLabelPadding : number , axisSpecStyle ?: AxisStyle ) : number {
91+ if ( axisSpecStyle && axisSpecStyle . tickLabelPadding !== undefined ) {
92+ return axisSpecStyle . tickLabelPadding ;
93+ }
94+ return axisConfigTickLabelPadding ;
95+ }
96+
8597export function isYDomain ( position : Position , chartRotation : Rotation ) : boolean {
8698 const isStraightRotation = chartRotation === 0 || chartRotation === 180 ;
8799 if ( isVertical ( position ) ) {
@@ -133,6 +145,7 @@ export const getMaxBboxDimensions = (
133145 fontSize : number ,
134146 fontFamily : string ,
135147 tickLabelRotation : number ,
148+ tickLabelPadding : number ,
136149) => (
137150 acc : { [ key : string ] : number } ,
138151 tickLabel : string ,
@@ -142,7 +155,7 @@ export const getMaxBboxDimensions = (
142155 maxLabelTextWidth : number ;
143156 maxLabelTextHeight : number ;
144157} => {
145- const bbox = bboxCalculator . compute ( tickLabel , fontSize , fontFamily ) . getOrElse ( {
158+ const bbox = bboxCalculator . compute ( tickLabel , tickLabelPadding , fontSize , fontFamily ) . getOrElse ( {
146159 width : 0 ,
147160 height : 0 ,
148161 } ) ;
@@ -158,7 +171,6 @@ export const getMaxBboxDimensions = (
158171 const prevHeight = acc . maxLabelBboxHeight ;
159172 const prevLabelWidth = acc . maxLabelTextWidth ;
160173 const prevLabelHeight = acc . maxLabelTextHeight ;
161-
162174 return {
163175 maxLabelBboxWidth : prevWidth > width ? prevWidth : width ,
164176 maxLabelBboxHeight : prevHeight > height ? prevHeight : height ,
@@ -172,6 +184,7 @@ function computeTickDimensions(
172184 tickFormat : TickFormatter ,
173185 bboxCalculator : BBoxCalculator ,
174186 axisConfig : AxisConfig ,
187+ tickLabelPadding : number ,
175188 tickLabelRotation : number = 0 ,
176189) {
177190 const tickValues = scale . ticks ( ) ;
@@ -182,7 +195,7 @@ function computeTickDimensions(
182195 } = axisConfig ;
183196
184197 const { maxLabelBboxWidth, maxLabelBboxHeight, maxLabelTextWidth, maxLabelTextHeight } = tickLabels . reduce (
185- getMaxBboxDimensions ( bboxCalculator , fontSize , fontFamily , tickLabelRotation ) ,
198+ getMaxBboxDimensions ( bboxCalculator , fontSize , fontFamily , tickLabelRotation , tickLabelPadding ) ,
186199 { maxLabelBboxWidth : 0 , maxLabelBboxHeight : 0 , maxLabelTextWidth : 0 , maxLabelTextHeight : 0 } ,
187200 ) ;
188201
0 commit comments