diff --git a/src/ViewModels/Statistics.cs b/src/ViewModels/Statistics.cs
index 7d943fa8..7852a367 100644
--- a/src/ViewModels/Statistics.cs
+++ b/src/ViewModels/Statistics.cs
@@ -1,5 +1,8 @@
using System.Threading.Tasks;
+
+using Avalonia.Media;
using Avalonia.Threading;
+
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
@@ -28,6 +31,25 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _selectedReport, value);
}
+ public uint SampleColor
+ {
+ get => Preference.Instance.StatisticsSampleColor;
+ set
+ {
+ if (value != Preference.Instance.StatisticsSampleColor)
+ {
+ Preference.Instance.StatisticsSampleColor = value;
+ OnPropertyChanged(nameof(SampleBrush));
+ _selectedReport?.ChangeColor(value);
+ }
+ }
+ }
+
+ public IBrush SampleBrush
+ {
+ get => new SolidColorBrush(SampleColor);
+ }
+
public Statistics(string repo)
{
Task.Run(() =>
@@ -47,12 +69,15 @@ namespace SourceGit.ViewModels
if (_data == null)
return;
- SelectedReport = _selectedIndex switch
+ var report = _selectedIndex switch
{
0 => _data.All,
1 => _data.Month,
_ => _data.Week,
};
+
+ report.ChangeColor(SampleColor);
+ SelectedReport = report;
}
private bool _isLoading = true;
diff --git a/src/Views/Statistics.axaml b/src/Views/Statistics.axaml
index 05ef6a5b..468faac0 100644
--- a/src/Views/Statistics.axaml
+++ b/src/Views/Statistics.axaml
@@ -123,11 +123,26 @@
+
+
+
+
+
-
+
-
+
-
-
-
-
-
+
diff --git a/src/Views/Statistics.axaml.cs b/src/Views/Statistics.axaml.cs
index 5fbf1492..3c5e70b6 100644
--- a/src/Views/Statistics.axaml.cs
+++ b/src/Views/Statistics.axaml.cs
@@ -1,65 +1,17 @@
-using Avalonia;
using Avalonia.Input;
-using Avalonia.Media;
namespace SourceGit.Views
{
public partial class Statistics : ChromelessWindow
{
- public static readonly StyledProperty SampleFillColorProperty =
- AvaloniaProperty.Register(nameof(SampleFillColor));
-
- public uint SampleFillColor
- {
- get => GetValue(SampleFillColorProperty);
- set => SetValue(SampleFillColorProperty, value);
- }
-
- public static readonly StyledProperty SampleFillBrushProperty =
- AvaloniaProperty.Register(nameof(SampleFillBrush), Brushes.Transparent);
-
- public IBrush SampleFillBrush
- {
- get => GetValue(SampleFillBrushProperty);
- set => SetValue(SampleFillBrushProperty, value);
- }
-
public Statistics()
{
- SampleFillColor = ViewModels.Preference.Instance.StatisticsSampleColor;
- SampleFillBrush = new SolidColorBrush(SampleFillColor);
InitializeComponent();
}
- protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
- {
- base.OnPropertyChanged(change);
-
- if (change.Property == SampleFillColorProperty)
- ChangeColor(SampleFillColor);
- }
-
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
{
BeginMoveDrag(e);
}
-
- private void OnReportChanged(object sender, System.EventArgs e)
- {
- if (DataContext is ViewModels.Statistics { SelectedReport: Models.StatisticsReport report })
- report.ChangeColor(SampleFillColor);
- }
-
- private void ChangeColor(uint color)
- {
- if (color != ViewModels.Preference.Instance.StatisticsSampleColor)
- {
- ViewModels.Preference.Instance.StatisticsSampleColor = color;
- SetCurrentValue(SampleFillBrushProperty, new SolidColorBrush(color));
-
- if (DataContext is ViewModels.Statistics { SelectedReport: Models.StatisticsReport report })
- report.ChangeColor(color);
- }
- }
}
}