Skip to content

Fix CategoryAxis labels not visible on Android XXHDPI devices #219

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

Closed
wants to merge 4 commits into from
Closed
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
31 changes: 31 additions & 0 deletions maui/src/Charts/Axis/CategoryAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,43 @@ protected override double CalculateActualInterval(DoubleRange range, Size availa
{
if (double.IsNaN(AxisInterval) || AxisInterval <= 0)
{
#if ANDROID
// Fix for CategoryAxis labels not visible on Android XXHDPI devices
// Normalize size by display density to ensure consistent interval calculation across different screen densities
var density = Android.Content.Res.Resources.System?.DisplayMetrics?.Density ?? 1.0f;
var normalizedAvailableSize = new Size(availableSize.Width / density, availableSize.Height / density);
return Math.Max(1d, Math.Floor(range.Delta / GetActualDesiredIntervalsCount(normalizedAvailableSize)));
#else
return Math.Max(1d, Math.Floor(range.Delta / GetActualDesiredIntervalsCount(availableSize)));
#endif
}

return AxisInterval;
}

/// <inheritdoc/>
protected override double CalculateVisibleInterval(DoubleRange visibleRange, Size availableSize)
{
if (ZoomFactor < 1 || ZoomPosition > 0)
{
#if ANDROID
// Fix for CategoryAxis labels not visible on Android XXHDPI devices
// Normalize size by display density to ensure consistent interval calculation across different screen densities
var density = Android.Content.Res.Resources.System?.DisplayMetrics?.Density ?? 1.0f;
var normalizedAvailableSize = new Size(availableSize.Width / density, availableSize.Height / density);
return EnableAutoIntervalOnZooming
? CalculateNiceInterval(visibleRange, normalizedAvailableSize)
: ActualInterval;
#else
return EnableAutoIntervalOnZooming
? CalculateNiceInterval(visibleRange, availableSize)
: ActualInterval;
#endif
}

return ActualInterval;
}

/// <inheritdoc/>
protected override DoubleRange ApplyRangePadding(DoubleRange range, double interval)
{
Expand Down