mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix(chart): prevent x-axis date labels from disappearing when rotated (#37755)
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user