Skip to content

Fixed the issue of Horizontal axis labels skipped despite available space. #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions maui/src/Charts/Axis/ChartAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ public double PointToValue(double x, double y)
protected internal double GetActualDesiredIntervalsCount(Size availableSize)
{
double size = !IsVertical ? availableSize.Width : availableSize.Height;
double adjustedDesiredIntervalsCount = size * (!IsVertical ? 0.54 : 1.0) * MaximumLabels;
var actualDesiredIntervalsCount = Math.Max(adjustedDesiredIntervalsCount / 100, 1.0);
return actualDesiredIntervalsCount;
double spacingFactor = GetLabelSpacingFactor();
double adjustedDesiredIntervalsCount = size * spacingFactor * MaximumLabels;
return Math.Max(adjustedDesiredIntervalsCount / 100, 1.0);
}

/// <summary>
Expand Down Expand Up @@ -776,6 +776,25 @@ void RaiseActualRangeChangedEvent(DoubleRange visibleRange, Size plotSize)
}
}

double GetLabelSpacingFactor()
{
if (IsVertical)
return 1.0;

// Base factor for horizontal labels - more conservative than 0.54
double factor = 0.6;
// Adjust based on label rotation
double rotationRadians = Math.Abs(LabelRotation) * Math.PI / 180;

if (rotationRadians > 0)
{
// Rotated labels can be packed more densely
factor *= 1.0 + 0.3 * Math.Sin(rotationRadians);
}

return factor;
}

#endregion

#endregion
Expand Down