ux: new layout for Staticstics window

This commit is contained in:
leo 2024-09-24 17:06:16 +08:00
parent 6151f4dc5f
commit b9597dc92a
No known key found for this signature in database
3 changed files with 49 additions and 70 deletions

View file

@ -1,5 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Media;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels namespace SourceGit.ViewModels
@ -28,6 +31,25 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _selectedReport, value); 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) public Statistics(string repo)
{ {
Task.Run(() => Task.Run(() =>
@ -47,12 +69,15 @@ namespace SourceGit.ViewModels
if (_data == null) if (_data == null)
return; return;
SelectedReport = _selectedIndex switch var report = _selectedIndex switch
{ {
0 => _data.All, 0 => _data.All,
1 => _data.Month, 1 => _data.Month,
_ => _data.Week, _ => _data.Week,
}; };
report.ChangeColor(SampleColor);
SelectedReport = report;
} }
private bool _isLoading = true; private bool _isLoading = true;

View file

@ -123,11 +123,26 @@
</ListBoxItem> </ListBoxItem>
</ListBox> </ListBox>
<!-- Color Picker -->
<Border Grid.Row="1" HorizontalAlignment="Right">
<Button Background="Transparent" BorderThickness="0" Width="28" Height="28" Margin="0,0,24,0" VerticalAlignment="Center">
<Button.Flyout>
<Flyout>
<Border Padding="8">
<v:ColorPicker Value="{Binding SampleColor, Mode=TwoWay}"/>
</Border>
</Flyout>
</Button.Flyout>
<Path Width="14" Height="14" Data="{StaticResource Icons.ColorPicker}" Fill="{Binding SampleBrush}"/>
</Button>
</Border>
<!-- Contents --> <!-- Contents -->
<ContentControl Grid.Row="2" Content="{Binding SelectedReport, Mode=OneWay}"> <ContentControl Grid.Row="2" Content="{Binding SelectedReport, Mode=OneWay}" Margin="8,8,8,16">
<ContentControl.DataTemplates> <ContentControl.DataTemplates>
<DataTemplate DataType="m:StatisticsReport"> <DataTemplate DataType="m:StatisticsReport">
<Grid ColumnDefinitions="256,*" Margin="8,8,8,16"> <Grid ColumnDefinitions="256,*">
<Grid Grid.Column="0" RowDefinitions="*,16"> <Grid Grid.Column="0" RowDefinitions="*,16">
<!-- Table By Committer --> <!-- Table By Committer -->
<ListBox Grid.Column="0" <ListBox Grid.Column="0"
@ -185,25 +200,12 @@
</Grid> </Grid>
<!-- Graph --> <!-- Graph -->
<Grid Grid.Column="1" RowDefinitions="28,*" Margin="16,0"> <lvc:CartesianChart Grid.Column="1"
<Button Grid.Row="0" Background="Transparent" BorderThickness="0" HorizontalAlignment="Center"> Margin="0"
<Button.Flyout> Padding="0"
<Flyout>
<Border Padding="8">
<v:ColorPicker Value="{Binding #ThisControl.SampleFillColor, Mode=TwoWay}"/>
</Border>
</Flyout>
</Button.Flyout>
<Path Width="20" Height="20" Data="{StaticResource Icons.ColorPicker}" Fill="{Binding #ThisControl.SampleFillBrush}"/>
</Button>
<lvc:CartesianChart Grid.Row="1"
Series="{Binding Series}" Series="{Binding Series}"
XAxes="{Binding XAxes}" YAxes="{Binding YAxes}" XAxes="{Binding XAxes}" YAxes="{Binding YAxes}"
ZoomMode="X" ZoomMode="X"/>
DataContextChanged="OnReportChanged"/>
</Grid>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>

View file

@ -1,65 +1,17 @@
using Avalonia;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Media;
namespace SourceGit.Views namespace SourceGit.Views
{ {
public partial class Statistics : ChromelessWindow public partial class Statistics : ChromelessWindow
{ {
public static readonly StyledProperty<uint> SampleFillColorProperty =
AvaloniaProperty.Register<Statistics, uint>(nameof(SampleFillColor));
public uint SampleFillColor
{
get => GetValue(SampleFillColorProperty);
set => SetValue(SampleFillColorProperty, value);
}
public static readonly StyledProperty<IBrush> SampleFillBrushProperty =
AvaloniaProperty.Register<Statistics, IBrush>(nameof(SampleFillBrush), Brushes.Transparent);
public IBrush SampleFillBrush
{
get => GetValue(SampleFillBrushProperty);
set => SetValue(SampleFillBrushProperty, value);
}
public Statistics() public Statistics()
{ {
SampleFillColor = ViewModels.Preference.Instance.StatisticsSampleColor;
SampleFillBrush = new SolidColorBrush(SampleFillColor);
InitializeComponent(); InitializeComponent();
} }
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == SampleFillColorProperty)
ChangeColor(SampleFillColor);
}
private void BeginMoveWindow(object _, PointerPressedEventArgs e) private void BeginMoveWindow(object _, PointerPressedEventArgs e)
{ {
BeginMoveDrag(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);
}
}
} }
} }