@@ -34,7 +34,7 @@ import { isLegendWrapViewport, isMobileFontViewport } from '@cdc/core/helpers/vi
3434import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
3535import { calcInitialHeight , handleAutoPaddingRight } from '../helpers/sizeHelpers'
3636import { filterAndShiftLinearDateTicks } from '../helpers/filterAndShiftLinearDateTicks'
37- import { calculateHorizontalBarYAxisWidth } from '../helpers/calculateHorizontalBarYAxisWidth '
37+ import { calculateHorizontalBarCategoryLabelWidth } from '../helpers/calculateHorizontalBarCategoryLabelWidth '
3838
3939// Hooks
4040import useReduceData from '../hooks/useReduceData'
@@ -248,9 +248,9 @@ const LinearChart = forwardRef<SVGAElement, LinearChartProps>(({ parentHeight, p
248248 currentViewport
249249 } )
250250
251- // Calculate dynamic Y-axis width for horizontal bar charts
252- const calculatedYAxisWidth = useMemo ( ( ) => {
253- return calculateHorizontalBarYAxisWidth ( {
251+ // Calculate category label space for horizontal bar charts
252+ const categoryLabelSpace = useMemo ( ( ) => {
253+ return calculateHorizontalBarCategoryLabelWidth ( {
254254 yScale,
255255 parentWidth,
256256 formatDate,
@@ -261,8 +261,9 @@ const LinearChart = forwardRef<SVGAElement, LinearChartProps>(({ parentHeight, p
261261 } )
262262 } , [ isHorizontal , config . visualizationType , config . yAxis . labelPlacement , yScale , parentWidth ] )
263263
264+ const horizontalYAxisLabelSpace = runtime . yAxis . label && ! config . hideYAxisLabel ? 30 : 0
264265 if ( isHorizontal && config . visualizationType === 'Bar' && ! config . isLollipopChart ) {
265- runtime . yAxis . size = calculatedYAxisWidth
266+ runtime . yAxis . size = categoryLabelSpace + horizontalYAxisLabelSpace
266267 }
267268
268269 const [ yTickCount , xTickCount ] = [ 'yAxis' , 'xAxis' ] . map ( axis =>
@@ -1184,12 +1185,12 @@ const LinearChart = forwardRef<SVGAElement, LinearChartProps>(({ parentHeight, p
11841185
11851186 return (
11861187 < Text
1187- x = { tick . to . x - Number ( runtime . yAxis . size ) + 8 }
1188+ x = { tick . from . x - Number ( runtime . yAxis . size ) + horizontalYAxisLabelSpace }
11881189 y = { labelCenterY }
11891190 verticalAnchor = { 'middle' }
11901191 textAnchor = { 'start' }
11911192 fontSize = { tickLabelFontSize }
1192- width = { Number ( runtime . yAxis . size ) }
1193+ width = { categoryLabelSpace }
11931194 lineHeight = { '1.2em' }
11941195 >
11951196 { tick . formattedValue }
0 commit comments