fix(chart): prevent x-axis date labels from disappearing when rotated (#37755)

This commit is contained in:
Enzo Martellucci
2026-02-26 18:10:44 +01:00
committed by GitHub
parent c1c012fb52
commit 5a134170a0
2 changed files with 127 additions and 5 deletions

View File

@@ -607,14 +607,24 @@ export default function transformProps(
nameGap: convertInteger(xAxisTitleMargin),
nameLocation: 'middle',
axisLabel: {
hideOverlap: true,
// When rotation is applied on time axes, hideOverlap can
// aggressively hide the last label. Rotated labels already
// have less overlap, so disabling hideOverlap is safe.
// At 0° rotation, keep hideOverlap to prevent long labels
// from overlapping each other, with showMaxLabel to ensure
// the last data point label stays visible (#37181).
hideOverlap: !(xAxisType === AxisType.Time && xAxisLabelRotation !== 0),
formatter: xAxisFormatter,
rotate: xAxisLabelRotation,
interval: xAxisLabelInterval,
...(xAxisType === AxisType.Time && {
showMaxLabel: true,
alignMaxLabel: 'right',
}),
// Force last label on non-rotated time axes to prevent
// hideOverlap from hiding it. Skipped when rotated to
// avoid phantom labels at the axis boundary.
...(xAxisType === AxisType.Time &&
xAxisLabelRotation === 0 && {
showMaxLabel: true,
alignMaxLabel: 'right',
}),
},
minorTick: { show: minorTicks },
minInterval:
@@ -660,6 +670,22 @@ export default function transformProps(
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
};
// Increase right padding for rotated time axis labels to prevent
// the last label from being clipped at the chart boundary.
if (
xAxisType === AxisType.Time &&
xAxisLabelRotation !== 0 &&
!isHorizontal
) {
padding.right = Math.max(
padding.right || 0,
TIMESERIES_CONSTANTS.gridOffsetRight +
Math.ceil(
Math.abs(Math.sin((xAxisLabelRotation * Math.PI) / 180)) * 80,
),
);
}
if (isHorizontal) {
[xAxis, yAxis] = [yAxis, xAxis];
[padding.bottom, padding.left] = [padding.left, padding.bottom];