From c0f59c441bebd1b62d6e597a7855d88e3abb1e2f Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 24 Sep 2024 12:14:51 +0800 Subject: [PATCH] feature: allow user to select the chart fill color --- src/Models/Statistics.cs | 8 +++++- src/Resources/Icons.axaml | 1 + src/ViewModels/Preference.cs | 8 ++++++ src/ViewModels/Statistics.cs | 16 ++++-------- src/Views/Statistics.axaml | 20 ++++++++++++++- src/Views/Statistics.axaml.cs | 48 +++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 13 deletions(-) diff --git a/src/Models/Statistics.cs b/src/Models/Statistics.cs index 39daa4c2..8bb80921 100644 --- a/src/Models/Statistics.cs +++ b/src/Models/Statistics.cs @@ -103,7 +103,7 @@ namespace SourceGit.Models { Values = samples, Stroke = null, - Fill = new SolidColorPaint(SKColors.Green), + Fill = null, Padding = 1, } ); @@ -117,6 +117,12 @@ namespace SourceGit.Models _mapSamples.Clear(); } + public void ChangeColor(uint color) + { + if (Series is [ColumnSeries series]) + series.Fill = new SolidColorPaint(new SKColor(color)); + } + private StaticsticsMode _mode = StaticsticsMode.All; private Dictionary _mapUsers = new Dictionary(); private Dictionary _mapSamples = new Dictionary(); diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index ef3e13aa..e8b0cc85 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -14,6 +14,7 @@ M797 829a49 49 0 1049 49 49 49 0 00-49-49zm147-114A49 49 0 10992 764a49 49 0 00-49-49zM928 861a49 49 0 1049 49A49 49 0 00928 861zm-5-586L992 205 851 64l-71 71a67 67 0 00-94 0l235 235a67 67 0 000-94zm-853 128a32 32 0 00-32 50 1291 1291 0 0075 112L288 552c20 0 25 21 8 37l-93 86a1282 1282 0 00120 114l100-32c19-6 28 15 14 34l-40 55c26 19 53 36 82 53a89 89 0 00115-20 1391 1391 0 00256-485l-188-188s-306 224-595 198z M1280 704c0 141-115 256-256 256H288C129 960 0 831 0 672c0-126 80-232 192-272A327 327 0 01192 384c0-177 143-320 320-320 119 0 222 64 277 160C820 204 857 192 896 192c106 0 192 86 192 192 0 24-5 48-13 69C1192 477 1280 580 1280 704zm-493-128H656V352c0-18-14-32-32-32h-96c-18 0-32 14-32 32v224h-131c-29 0-43 34-23 55l211 211c12 12 33 12 45 0l211-211c20-20 6-55-23-55z M853 102H171C133 102 102 133 102 171v683C102 891 133 922 171 922h683C891 922 922 891 922 853V171C922 133 891 102 853 102zM390 600l-48 48L205 512l137-137 48 48L301 512l88 88zM465 819l-66-18L559 205l66 18L465 819zm218-171L634 600 723 512l-88-88 48-48L819 512 683 649z + M731 331c-28-28-43-27-64-130s-95-136-176-136C244 65 64 265 64 512a447 447 0 00448 447c247 0 450-165 448-412-2-224-186-173-229-215zM246 467a57 57 0 1157 57 57 57 0 01-57-57zm125 215a45 45 0 1145-45 45 45 0 01-45 45zm34-310a71 71 0 1171-71 71 71 0 01-71 71z M796 471A292 292 0 00512 256a293 293 0 00-284 215H0v144h228A293 293 0 00512 832a291 291 0 00284-217H1024V471h-228M512 688A146 146 0 01366 544A145 145 0 01512 400c80 0 146 63 146 144A146 146 0 01512 688 M645 448l64 64 220-221L704 64l-64 64 115 115H128v90h628zM375 576l-64-64-220 224L314 960l64-64-116-115H896v-90H262z M608 0q48 0 88 23t63 63 23 87v70h55q35 0 67 14t57 38 38 57 14 67V831q0 34-14 66t-38 57-57 38-67 13H426q-34 0-66-13t-57-38-38-57-14-66v-70h-56q-34 0-66-14t-57-38-38-57-13-67V174q0-47 23-87T109 23 196 0h412m175 244H426q-46 0-86 22T278 328t-26 85v348H608q47 0 86-22t63-62 25-85l1-348m-269 318q18 0 31 13t13 31-13 31-31 13-31-13-13-31 13-31 31-13m0-212q13 0 22 9t11 22v125q0 14-9 23t-22 10-23-7-11-22l-1-126q0-13 10-23t23-10z diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index ef63d61e..be1137ac 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -337,6 +337,12 @@ namespace SourceGit.ViewModels } } + public uint StatisticsSampleColor + { + get => _statisticsSampleColor; + set => SetProperty(ref _statisticsSampleColor, value); + } + public List RepositoryNodes { get; @@ -621,5 +627,7 @@ namespace SourceGit.ViewModels private int _shellOrTerminal = -1; private int _externalMergeToolType = 0; private string _externalMergeToolPath = string.Empty; + + private uint _statisticsSampleColor = 0xFF00FF00; } } diff --git a/src/ViewModels/Statistics.cs b/src/ViewModels/Statistics.cs index ce28cfea..7d943fa8 100644 --- a/src/ViewModels/Statistics.cs +++ b/src/ViewModels/Statistics.cs @@ -47,18 +47,12 @@ namespace SourceGit.ViewModels if (_data == null) return; - switch (_selectedIndex) + SelectedReport = _selectedIndex switch { - case 0: - SelectedReport = _data.All; - break; - case 1: - SelectedReport = _data.Month; - break; - default: - SelectedReport = _data.Week; - break; - } + 0 => _data.All, + 1 => _data.Month, + _ => _data.Week, + }; } private bool _isLoading = true; diff --git a/src/Views/Statistics.axaml b/src/Views/Statistics.axaml index a3364830..05ef6a5b 100644 --- a/src/Views/Statistics.axaml +++ b/src/Views/Statistics.axaml @@ -185,7 +185,25 @@ - + + + + + diff --git a/src/Views/Statistics.axaml.cs b/src/Views/Statistics.axaml.cs index 3c5e70b6..5fbf1492 100644 --- a/src/Views/Statistics.axaml.cs +++ b/src/Views/Statistics.axaml.cs @@ -1,17 +1,65 @@ +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); + } + } } }