Skip to content

Commit 0be9b3c

Browse files
Fixed the issue of Horizontal Axis label despite there is an available space.
1 parent 9f0a0a7 commit 0be9b3c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

maui/src/Charts/Axis/ChartAxis.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ public double PointToValue(double x, double y)
239239
protected internal double GetActualDesiredIntervalsCount(Size availableSize)
240240
{
241241
double size = !IsVertical ? availableSize.Width : availableSize.Height;
242-
double adjustedDesiredIntervalsCount = size * (!IsVertical ? 0.54 : 1.0) * MaximumLabels;
243-
var actualDesiredIntervalsCount = Math.Max(adjustedDesiredIntervalsCount / 100, 1.0);
244-
return actualDesiredIntervalsCount;
242+
double spacingFactor = GetLabelSpacingFactor();
243+
double adjustedDesiredIntervalsCount = size * spacingFactor * MaximumLabels;
244+
return Math.Max(adjustedDesiredIntervalsCount / 100, 1.0);
245245
}
246246

247247
/// <summary>
@@ -776,6 +776,25 @@ void RaiseActualRangeChangedEvent(DoubleRange visibleRange, Size plotSize)
776776
}
777777
}
778778

779+
double GetLabelSpacingFactor()
780+
{
781+
if (IsVertical)
782+
return 1.0;
783+
784+
// Base factor for horizontal labels - more conservative than 0.54
785+
double factor = 0.6;
786+
// Adjust based on label rotation
787+
double rotationRadians = Math.Abs(LabelRotation) * Math.PI / 180;
788+
789+
if (rotationRadians > 0)
790+
{
791+
// Rotated labels can be packed more densely
792+
factor *= 1.0 + 0.3 * Math.Sin(rotationRadians);
793+
}
794+
795+
return factor;
796+
}
797+
779798
#endregion
780799

781800
#endregion

0 commit comments

Comments
 (0)