sourcegit/src/Views/Statistics.axaml
leo e19d025572
code_review: PR #431
* move resources and styles for macOS caption button to `CaptionButtonsMacOS` because it is never used by others and should not been changed
* add `IsCloseButtonOnly` property to `CaptionButtons` and `CaptionButtonsMacOS` and replace the controls in windows
2024-09-01 16:54:20 +08:00

202 lines
8.8 KiB
XML

<v:ChromelessWindow xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.Statistics"
x:DataType="vm:Statistics"
x:Name="ThisControl"
Title="{DynamicResource Text.Statistics}"
Width="860" Height="500"
WindowStartupLocation="CenterOwner"
CanResize="False">
<Grid RowDefinitions="Auto,Auto,*">
<!-- Title bar -->
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<Border Grid.Column="0" Grid.ColumnSpan="3"
Background="{DynamicResource Brush.TitleBar}"
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
PointerPressed="BeginMoveWindow"/>
<Path Grid.Column="0"
Width="14" Height="14"
Margin="10,0,0,0"
Data="{StaticResource Icons.Statistics}"
IsVisible="{OnPlatform True, macOS=False}"/>
<v:CaptionButtonsMacOS Grid.Column="0"
Margin="0,2,0,0"
IsCloseButtonOnly="True"
IsVisible="{OnPlatform False, macOS=True}"/>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold"
Text="{DynamicResource Text.Statistics}"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/>
<v:CaptionButtons Grid.Column="2"
IsCloseButtonOnly="True"
IsVisible="{OnPlatform True, macOS=False}"/>
</Grid>
<!-- View mode switcher -->
<ListBox Grid.Row="1"
Margin="0,8"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="1"
BorderBrush="{DynamicResource Brush.Border2}"
CornerRadius="14"
Padding="3,0">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Height" Value="28"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="ListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="ListBoxItem:selected /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="ListBoxItem Border.switcher_bg">
<Setter Property="Height" Value="22"/>
<Setter Property="CornerRadius" Value="11"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Padding" Value="16,0"/>
</Style>
<Style Selector="ListBoxItem:selected Border.switcher_bg">
<Setter Property="Background" Value="{DynamicResource Brush.Accent}"/>
</Style>
<Style Selector="TextBlock.view_mode_switcher">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="{DynamicResource Brush.FG2}"/>
</Style>
<Style Selector="ListBoxItem:pointerover TextBlock.view_mode_switcher">
<Setter Property="Foreground" Value="{DynamicResource Brush.FG1}"/>
</Style>
<Style Selector="ListBoxItem:selected TextBlock.view_mode_switcher">
<Setter Property="Foreground" Value="White"/>
</Style>
</ListBox.Styles>
<ListBoxItem>
<Border Classes="switcher_bg">
<TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.MostRecentYear}"/>
</Border>
</ListBoxItem>
<ListBoxItem>
<Border Classes="switcher_bg">
<TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.ThisMonth}"/>
</Border>
</ListBoxItem>
<ListBoxItem>
<Border Classes="switcher_bg">
<TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.ThisWeek}"/>
</Border>
</ListBoxItem>
</ListBox>
<!-- Contents -->
<ContentControl Grid.Row="2" Content="{Binding SelectedReport, Mode=OneWay}">
<ContentControl.DataTemplates>
<DataTemplate DataType="m:StatisticsReport">
<Grid ColumnDefinitions="256,*" Margin="8,8,8,16">
<Grid Grid.Column="0" RowDefinitions="*,16">
<!-- Table By Committer -->
<ListBox Grid.Column="0"
ItemsSource="{Binding ByAuthor}"
SelectionMode="Single"
BorderThickness="1"
BorderBrush="{DynamicResource Brush.Border2}"
Background="{DynamicResource Brush.Contents}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Height" Value="26"/>
</Style>
</ListBox.Styles>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate DataType="m:StatisticsSample">
<Border BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
<Grid ColumnDefinitions="*,100">
<Border Grid.Column="0" Padding="8,0" ClipToBounds="True">
<TextBlock Text="{Binding Name}" HorizontalAlignment="Left"/>
</Border>
<Border Grid.Column="1" Padding="8,0" ClipToBounds="True">
<TextBlock Text="{Binding Count}" HorizontalAlignment="Right"/>
</Border>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!-- Summary -->
<Grid Grid.Row="1" ColumnDefinitions="*,*">
<!-- Total Committers -->
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Bottom">
<TextBlock Classes="primary" Text="{DynamicResource Text.Statistics.TotalAuthors}" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
<TextBlock Classes="primary" Text="{Binding ByAuthor.Count}" FontSize="11" Margin="4,0,0,0"/>
</StackPanel>
<!-- Total Commits -->
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">
<TextBlock Classes="primary" Text="{DynamicResource Text.Statistics.TotalCommits}" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
<TextBlock Classes="primary" Text="{Binding Total}" FontSize="11" Margin="4,0,0,0"/>
</StackPanel>
</Grid>
</Grid>
<!-- Graph -->
<v:Chart Grid.Column="1"
Margin="16"
LabelBrush="{DynamicResource Brush.FG1}"
LineBrush="{DynamicResource Brush.Border2}"
ShapeBrush="{DynamicResource Brush.Accent}"
Samples="{Binding Samples}"/>
</Grid>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
<!-- Loading Mask -->
<v:LoadingIcon Grid.Row="2"
Width="48" Height="48"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsLoading}"/>
</Grid>
</v:ChromelessWindow>