Use LabelAlignment for labels
MODIFY
WalletWasabi.Fluent/Controls/LineChart.Properties.cs
WalletWasabi.Fluent/Controls/LineChart.Properties.cs
@@ -126,8 +126,8 @@ namespace WalletWasabi.Fluent.Controls
public static readonly StyledProperty<Point> XAxisLabelOffsetProperty =
AvaloniaProperty.Register<LineChart, Point>(nameof(XAxisLabelOffset), new Point(0, 5));
- public static readonly StyledProperty<TextAlignment> XAxisLabelAlignmentProperty =
- AvaloniaProperty.Register<LineChart, TextAlignment>(nameof(XAxisLabelAlignment), TextAlignment.Center);
+ public static readonly StyledProperty<LabelAlignment> XAxisLabelAlignmentProperty =
+ AvaloniaProperty.Register<LineChart, LabelAlignment>(nameof(XAxisLabelAlignment), LabelAlignment.Center);
public static readonly StyledProperty<double> XAxisLabelAngleProperty =
AvaloniaProperty.Register<LineChart, double>(nameof(XAxisLabelAngle));
@@ -231,8 +231,8 @@ namespace WalletWasabi.Fluent.Controls
public static readonly StyledProperty<Point> YAxisLabelOffsetProperty =
AvaloniaProperty.Register<LineChart, Point>(nameof(YAxisLabelOffset), new Point(-5, 0));
- public static readonly StyledProperty<TextAlignment> YAxisLabelAlignmentProperty =
- AvaloniaProperty.Register<LineChart, TextAlignment>(nameof(YAxisLabelAlignment), TextAlignment.Right);
+ public static readonly StyledProperty<LabelAlignment> YAxisLabelAlignmentProperty =
+ AvaloniaProperty.Register<LineChart, LabelAlignment>(nameof(YAxisLabelAlignment), LabelAlignment.Right);
public static readonly StyledProperty<double> YAxisLabelAngleProperty =
AvaloniaProperty.Register<LineChart, double>(nameof(YAxisLabelAngle));
@@ -591,7 +591,7 @@ namespace WalletWasabi.Fluent.Controls
set => SetValue(XAxisLabelOffsetProperty, value);
}
- public TextAlignment XAxisLabelAlignment
+ public LabelAlignment XAxisLabelAlignment
{
get => GetValue(XAxisLabelAlignmentProperty);
set => SetValue(XAxisLabelAlignmentProperty, value);
@@ -795,7 +795,7 @@ namespace WalletWasabi.Fluent.Controls
set => SetValue(YAxisLabelOffsetProperty, value);
}
- public TextAlignment YAxisLabelAlignment
+ public LabelAlignment YAxisLabelAlignment
{
get => GetValue(YAxisLabelAlignmentProperty);
set => SetValue(YAxisLabelAlignmentProperty, value);

MODIFY
WalletWasabi.Fluent/Controls/LineChart.cs
WalletWasabi.Fluent/Controls/LineChart.cs
@@ -540,10 +540,20 @@ namespace WalletWasabi.Fluent.Controls
var formattedTextLabels = new List<FormattedText>();
var constrainWidthMax = 0.0;
var constrainHeightMax = 0.0;
+ var labels = state.XAxisLabels;
- foreach (var label in state.XAxisLabels)
+ for (var i = 0; i < labels.Count; i++)
{
- var formattedText = CreateFormattedText(label, typeface, alignment, fontSize, Size.Empty);
+ var label = labels[i];
+ var textAlignment = alignment switch
+ {
+ LabelAlignment.Auto => i == 0 ? TextAlignment.Left : i == labels.Count - 1 ? TextAlignment.Right : TextAlignment.Center,
+ LabelAlignment.Left => TextAlignment.Left,
+ LabelAlignment.Center => TextAlignment.Center,
+ LabelAlignment.Right => TextAlignment.Right,
+ _ => TextAlignment.Center
+ };
+ var formattedText = CreateFormattedText(label, typeface, textAlignment, fontSize, Size.Empty);
formattedTextLabels.Add(formattedText);
constrainWidthMax = Math.Max(constrainWidthMax, formattedText.Bounds.Width);
constrainHeightMax = Math.Max(constrainHeightMax, formattedText.Bounds.Height);
@@ -640,11 +650,20 @@ namespace WalletWasabi.Fluent.Controls
var formattedTextLabels = new List<FormattedText>();
var constrainWidthMax = 0.0;
var constrainHeightMax = 0.0;
+ var labels = state.YAxisLabels;
- for (var index = state.YAxisLabels.Count - 1; index >= 0; index--)
+ for (var i = labels.Count - 1; i >= 0; i--)
{
- var label = state.YAxisLabels[index];
- var formattedText = CreateFormattedText(label, typeface, alignment, fontSize, Size.Empty);
+ var label = labels[i];
+ var textAlignment = alignment switch
+ {
+ LabelAlignment.Auto => i == 0 ? TextAlignment.Left : i == labels.Count - 1 ? TextAlignment.Right : TextAlignment.Center,
+ LabelAlignment.Left => TextAlignment.Left,
+ LabelAlignment.Center => TextAlignment.Center,
+ LabelAlignment.Right => TextAlignment.Right,
+ _ => TextAlignment.Center
+ };
+ var formattedText = CreateFormattedText(label, typeface, textAlignment, fontSize, Size.Empty);
formattedTextLabels.Add(formattedText);
constrainWidthMax = Math.Max(constrainWidthMax, formattedText.Bounds.Width);
constrainHeightMax = Math.Max(constrainHeightMax, formattedText.Bounds.Height);

Use LabelAlignment for labels