mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-11 23:57:21 -08:00
ux: new layout for Staticstics
window
This commit is contained in:
parent
6151f4dc5f
commit
b9597dc92a
3 changed files with 49 additions and 70 deletions
|
@ -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;
|
||||
|
|
|
@ -123,11 +123,26 @@
|
|||
</ListBoxItem>
|
||||
</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 -->
|
||||
<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>
|
||||
<DataTemplate DataType="m:StatisticsReport">
|
||||
<Grid ColumnDefinitions="256,*" Margin="8,8,8,16">
|
||||
<Grid ColumnDefinitions="256,*">
|
||||
<Grid Grid.Column="0" RowDefinitions="*,16">
|
||||
<!-- Table By Committer -->
|
||||
<ListBox Grid.Column="0"
|
||||
|
@ -185,25 +200,12 @@
|
|||
</Grid>
|
||||
|
||||
<!-- Graph -->
|
||||
<Grid Grid.Column="1" RowDefinitions="28,*" Margin="16,0">
|
||||
<Button Grid.Row="0" Background="Transparent" BorderThickness="0" HorizontalAlignment="Center">
|
||||
<Button.Flyout>
|
||||
<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"
|
||||
<lvc:CartesianChart Grid.Column="1"
|
||||
Margin="0"
|
||||
Padding="0"
|
||||
Series="{Binding Series}"
|
||||
XAxes="{Binding XAxes}" YAxes="{Binding YAxes}"
|
||||
ZoomMode="X"
|
||||
DataContextChanged="OnReportChanged"/>
|
||||
</Grid>
|
||||
ZoomMode="X"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
|
|
|
@ -1,65 +1,17 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue