<UserControl x:Class="WSDDBBrowser.Chart.HistogramGraph"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WSDDBBrowser.Chart"
             xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Background="WhiteSmoke">
    <UserControl.Resources>
        <local:HistogramGraphViewModel_UnitTest x:Key="viewmodel"/>

    </UserControl.Resources>
    <Grid d:DataContext="{StaticResource viewmodel}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <lvc:CartesianChart Grid.Row="1"  Series="{Binding Series}" Margin="2"
                            Hoverable="False" DisableAnimations="True" DataTooltip="{x:Null}" >
            <lvc:CartesianChart.AxisX>
                <lvc:Axis IsMerged="True" LabelFormatter="{Binding XFormatter}" FontSize="16" MinValue="{Binding XMin}" MaxValue="{Binding XMax}">
                    <lvc:Axis.Sections>
                        <lvc:AxisSection 
                            Value="{Binding Target}" 
                            DataLabel="True"
                            StrokeThickness="2" 
                            Stroke="{StaticResource AreaColors2}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding CtrllineMax}"  
                            DataLabel="True"
                            StrokeThickness="2" 
                            Stroke="{StaticResource AreaColors1}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding CtrllineMin}"  
                            DataLabel="True"
                            StrokeThickness="2" 
                            Stroke="{StaticResource AreaColors3}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding ToleranceMax}"  
                            DataLabel="True"
                            StrokeThickness="2" 
                            Stroke="{StaticResource AreaColors0}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding ToleranceMin}"  
                            DataLabel="True"
                            StrokeThickness="2" 
                            Stroke="{StaticResource AreaColors4}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                    </lvc:Axis.Sections>
                    <lvc:Axis.Separator>
                        <lvc:Separator StrokeThickness="1" StrokeDashArray="2">
                            <lvc:Separator.Stroke>
                                <SolidColorBrush Color="#404F56" />
                            </lvc:Separator.Stroke>
                        </lvc:Separator>
                    </lvc:Axis.Separator>
                </lvc:Axis>
            </lvc:CartesianChart.AxisX>
            <lvc:CartesianChart.AxisY>
                <lvc:Axis IsMerged="True" IsEnabled="False" ShowLabels="False" MinValue="{Binding YMin}" MaxValue="{Binding YMax}"/>

            </lvc:CartesianChart.AxisY>
        </lvc:CartesianChart>
        <StackPanel Margin="10" Orientation="Horizontal" Height="60">
            <StackPanel Orientation="Vertical" Margin="20, 0,20,-60">
                <StackPanel.Resources>
                    <Style x:Key="TitleStyle" TargetType="TextBlock">
                        <Setter Property="Width" Value="80"/>
                        <Setter Property="Foreground" Value="{DynamicResource GrayBrush1}"/>
                        <Setter Property="FontSize" Value="16"/>
                        <Setter Property="TextAlignment" Value="Right"/>
                    </Style>
                    <Style x:Key="ValueStyle" TargetType="TextBlock">
                        <Setter Property="Foreground" Value="{DynamicResource TextBrush}"/>
                        <Setter Property="FontSize" Value="20"/>
                        <Setter Property="Padding" Value="5,0"/>
                    </Style>
                    <Style x:Key="UnitStyle" TargetType="TextBlock">
                        <Setter Property="Foreground" Value="{DynamicResource GrayBrush2}"/>
                        <Setter Property="FontSize" Value="15"/>
                        <Setter Property="VerticalAlignment" Value="Bottom"/>
                    </Style>
                </StackPanel.Resources>
                <TextBlock FontSize="24" Foreground="{DynamicResource TextBrush}" Text="直方图"/>
                <StackPanel Orientation="Horizontal" Margin="5,0">
                    <TextBlock Style="{StaticResource TitleStyle}" Text="总量:" />
                    <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding TotalCount}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="5,0">
                    <TextBlock Style="{StaticResource TitleStyle}" Text="间隔:" />
                    <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Step}"/>
                </StackPanel>
            </StackPanel>
            <ItemsControl ItemsSource="{Binding SeriesInfos}" VerticalAlignment="Top" Margin="0,0,0,-160">
                <ItemsControl.Resources>
                    <Style TargetType="Button" BasedOn="{StaticResource ButtonStyle_empty}">
                        <Setter Property="Margin" Value="2"/>
                        <Setter Property="Height" Value="35"/>
                        <Setter Property="Width" Value="40"/>
                        <Setter Property="HorizontalAlignment" Value="Left"/>
                    </Style>
                </ItemsControl.Resources>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Vertical" Height="160"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>

                        <Button Click="button_select_Click" Tag="{Binding}" >
                            <Border x:Name="mainBorder"  Background="{Binding Fill}" BorderThickness="2" BorderBrush="{DynamicResource ControlBackgroundBrush}">
                                <Viewbox>
                                    <TextBlock x:Name="tb" Text="{Binding Title}" FontSize="40" Foreground="{DynamicResource WhiteBrush}" FontWeight="Bold"  VerticalAlignment="Center" HorizontalAlignment="Center"  />
                                </Viewbox>
                            </Border>
                        </Button>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsVisible}" Value="False">
                                <Setter TargetName="tb" Property="Foreground" Value="{Binding Fill}"/>
                                <Setter TargetName="mainBorder" Property="Background" Value="{DynamicResource ControlBackgroundBrush}"/>
                                <Setter TargetName="mainBorder" Property="BorderBrush" Value="{DynamicResource AccentColorBrush}"/>
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <StackPanel Orientation="Horizontal" Margin="20,0">
                <Button  Style="{StaticResource ButtonStyle_empty}" Margin="5" VerticalAlignment="Bottom" Click="ButtonXlsxClick" >
                    <StackPanel VerticalAlignment="Center">
                        <iconPacks:PackIconModern Kind="OfficeExcel" Foreground="{DynamicResource AccentColorBrush}" Height="35" Width="35" HorizontalAlignment="Center"/>
                        <TextBlock Text="输出xlsx" Foreground="{DynamicResource GrayBrush2}" HorizontalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button  Style="{StaticResource ButtonStyle_empty}" Margin="5" VerticalAlignment="Bottom" Click="ButtonJpgClick" >
                    <StackPanel VerticalAlignment="Center">
                        <iconPacks:PackIconFontAwesome Kind="CameraRetroSolid" Foreground="{DynamicResource AccentColorBrush}" Height="35" Width="35" HorizontalAlignment="Center"/>
                        <TextBlock Text="输出jpg" Foreground="{DynamicResource GrayBrush2}"/>
                    </StackPanel>
                </Button>
            </StackPanel>
        </StackPanel>
        <Grid Grid.RowSpan="2" VerticalAlignment="Top" HorizontalAlignment="Right" Background="{DynamicResource SemiTransparentGreyBrush}" Margin="10,0" Panel.ZIndex="1">
            <Grid.Resources>
                <Style x:Key="TitleStyle" TargetType="TextBlock">
                    <Setter Property="Foreground" Value="{DynamicResource GrayBrush1}"/>
                    <Setter Property="FontSize" Value="16"/>
                    <Setter Property="Width" Value="50"/>
                    <Setter Property="TextAlignment" Value="Right"/>
                </Style>
                <Style x:Key="ValueStyle" TargetType="TextBlock">
                    <Setter Property="Foreground" Value="{DynamicResource TextBrush}"/>
                    <Setter Property="FontSize" Value="30"/>
                </Style>
                <Style x:Key="UnitStyle" TargetType="TextBlock">
                    <Setter Property="Foreground" Value="{DynamicResource GrayBrush2}"/>
                    <Setter Property="FontSize" Value="15"/>
                    <Setter Property="VerticalAlignment" Value="Bottom"/>
                </Style>
            </Grid.Resources>
            <StackPanel Margin="10">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource TitleStyle}" Text="CPK:"/>
                    <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding CPK,StringFormat={}{0:F1}}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource TitleStyle}" Text="平均:"/>
                    <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Average,StringFormat={}{0:F1}}"/>
                    <TextBlock Style="{StaticResource UnitStyle}" Text="g/m²"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource TitleStyle}" Text="3σ:"/>
                    <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Sigma3,StringFormat={}{0:F1}}"/>
                    <TextBlock Style="{StaticResource UnitStyle}" Text="g/m²"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource TitleStyle}" Text="规格线内:" FontSize="12"/>
                    <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding TolerancePercent,StringFormat={}{0:P1}}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource TitleStyle}" Text="控制线内:" FontSize="12"/>
                    <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding CtrllinePercent,StringFormat={}{0:P1}}"/>

                </StackPanel>
            </StackPanel>
        </Grid>



    </Grid>
</UserControl>
