<UserControl x:Class="WSDDBBrowser.Chart.TrendGraph"
             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:lvc_feng="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Feng.Wpf"
            xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
            xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Background="WhiteSmoke">
    <UserControl.Resources>
        <local:TrendGraphViewModel_UnitTest x:Key="viewmodel"/>
    </UserControl.Resources>
    <Grid d:DataContext="{StaticResource viewmodel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <lvc:CartesianChart x:Name="chart" 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" >
                    <lvc:Axis.Separator>
                        <lvc:Separator Stroke="LightGray"/>
                    </lvc:Axis.Separator>
                </lvc:Axis>
            </lvc:CartesianChart.AxisX>
            <lvc:CartesianChart.AxisY>
                <lvc:Axis IsMerged="True" LabelFormatter="{Binding YFormatter}" MaxValue="{Binding YMax}" MinValue="{Binding YMin}">
                    <lvc:Axis.Sections>
                        <lvc:AxisSection 
                            Value="{Binding Target}" 
                            DataLabel="True"
                            StrokeThickness="1" 
                            Stroke="{StaticResource AreaColors2}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding CtrllineYMax}"  
                            DataLabel="True"
                            StrokeThickness="1" 
                            Stroke="{StaticResource AreaColors1}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding CtrllineYMin}"  
                            DataLabel="True"
                            StrokeThickness="1" 
                            Stroke="{StaticResource AreaColors3}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding ToleranceYMax}"  
                            DataLabel="True"
                            StrokeThickness="1" 
                            Stroke="{StaticResource AreaColors0}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                        <lvc:AxisSection 
                            Value="{Binding ToleranceYMin}"  
                            DataLabel="True"
                            StrokeThickness="1" 
                            Stroke="{StaticResource AreaColors4}"
                            DisableAnimations="True"
                            DataLabelForeground="White"
                            Opacity="0.5"
                            Panel.ZIndex="1"
                            />
                    </lvc:Axis.Sections>
                    <lvc:Axis.Separator>
                        <lvc:Separator Stroke="LightGray"/>
                    </lvc:Axis.Separator>
                </lvc:Axis>

            </lvc:CartesianChart.AxisY>
        </lvc:CartesianChart>

        <StackPanel Orientation="Horizontal" Margin="10" Height="60">
            <StackPanel Margin="20,0" Orientation="Vertical">
                <StackPanel Orientation="Horizontal">
                    <TextBlock FontSize="24" Foreground="{DynamicResource TextBrush}" Text="趋势图"/>
                </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 Orientation="Horizontal">
                <StackPanel Margin="10">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource TitleStyle}" Text="最大:"/>
                        <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Max,StringFormat={}{0:F1}}"/>
                        <TextBlock Style="{StaticResource UnitStyle}" Text="g/m²"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource TitleStyle}" Text="最小:"/>
                        <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Min,StringFormat={}{0:F1}}"/>
                        <TextBlock Style="{StaticResource UnitStyle}" VerticalAlignment="Bottom" Text="g/m²"/>
                    </StackPanel>
                </StackPanel>
                <StackPanel Margin="10">


                    <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}" VerticalAlignment="Bottom" Text="g/m²"/>
                    </StackPanel>
                </StackPanel>
            </StackPanel>


        </Grid>


    </Grid>
</UserControl>

