Commit c4205399 authored by 潘栩锋's avatar 潘栩锋 🚴

优化 整理定点图, 可以显示1ms

parent 49008677
......@@ -54,7 +54,7 @@ namespace FLY.Thick.Base.UI.UiModule
void graphparam_clone_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Interval")
if (e.PropertyName == nameof(graphparam_clone.Interval))
{
updateDataLenOpt();
......@@ -63,7 +63,7 @@ namespace FLY.Thick.Base.UI.UiModule
graphparam_clone.Len = 10;
graphparam_clone.Len = len;
}
else if(e.PropertyName == "IsADMode")
else if(e.PropertyName == nameof(graphparam_clone.IsADMode))
{
graphparam_clone.IsAutoTarget = true;
graphparam_clone.IsAutoY = false;
......@@ -77,8 +77,8 @@ namespace FLY.Thick.Base.UI.UiModule
void updateIntervalOpt()
{
IntervalOpt.Clear();
IntervalOpt.Add(new FixInterval() { Interval = 1, Title = "1.28ms" });
IntervalOpt.Add(new FixInterval() { Interval = 4, Title = "5.12ms" });
IntervalOpt.Add(new FixInterval() { Interval = 1, Title = "1ms" });
IntervalOpt.Add(new FixInterval() { Interval = 5, Title = "5ms" });
IntervalOpt.Add(new FixInterval() { Interval = 10, Title = "10ms" });
IntervalOpt.Add(new FixInterval() { Interval = 50, Title = "50ms" });
IntervalOpt.Add(new FixInterval() { Interval = 100, Title = "0.1s" });
......@@ -97,45 +97,55 @@ namespace FLY.Thick.Base.UI.UiModule
if (graphparam_clone.Interval == 1)
{
DataLenOpt.Add(500);
DataLenOpt.Add(1000);
DataLenOpt.Add(2000);
DataLenOpt.Add(4000);
DataLenOpt.Add(10000);
DataLenOpt.Add(20000);
DataLenOpt.Add(50000);
DataLenOpt.Add(100000);
DataLenOpt.Add(5000);//5s
DataLenOpt.Add(10000);//10s
DataLenOpt.Add(20000);//20s
DataLenOpt.Add(50000);//50s
DataLenOpt.Add(100000);//100s
}
else if (graphparam_clone.Interval <= 5)
{
DataLenOpt.Add(1000);//5s
DataLenOpt.Add(2000);//10s
DataLenOpt.Add(5000);//25s
DataLenOpt.Add(10000);//50s
DataLenOpt.Add(20000);//100s
DataLenOpt.Add(50000);//250s
}
else if (graphparam_clone.Interval <= 10)
{
DataLenOpt.Add(500);
DataLenOpt.Add(1000);
DataLenOpt.Add(2000);
DataLenOpt.Add(4000);
DataLenOpt.Add(10000);
DataLenOpt.Add(20000);
DataLenOpt.Add(500);//5s
DataLenOpt.Add(1000);//10s
DataLenOpt.Add(2000);//20s
DataLenOpt.Add(5000);//50s
DataLenOpt.Add(10000);//100s
DataLenOpt.Add(20000);//200s
DataLenOpt.Add(50000);//500s
}
else if (graphparam_clone.Interval <= 50)
{
DataLenOpt.Add(500);
DataLenOpt.Add(1000);
DataLenOpt.Add(2000);
DataLenOpt.Add(4000);
DataLenOpt.Add(10000);
DataLenOpt.Add(20000);
DataLenOpt.Add(500);//25s
DataLenOpt.Add(1000);//50s
DataLenOpt.Add(2000);//100s
DataLenOpt.Add(5000);//250s
DataLenOpt.Add(10000);//500s
DataLenOpt.Add(20000);//16.6min
}
else if (graphparam_clone.Interval <= 100)
{
DataLenOpt.Add(500);
DataLenOpt.Add(1000);
DataLenOpt.Add(2000);
DataLenOpt.Add(4000);
DataLenOpt.Add(500);//50s
DataLenOpt.Add(1000);//100s
DataLenOpt.Add(2000);//200s
DataLenOpt.Add(5000);//500s
DataLenOpt.Add(10000);//16.6min
}
else
{
DataLenOpt.Add(500);
DataLenOpt.Add(1000);
DataLenOpt.Add(2000);
DataLenOpt.Add(50);//50s
DataLenOpt.Add(100);//100s
DataLenOpt.Add(200);//200s
DataLenOpt.Add(500);//500s
DataLenOpt.Add(1000);//16.6min
}
......@@ -234,9 +244,6 @@ namespace FLY.Thick.Base.UI.UiModule
double total_ms;
if (ms < 10)
total_ms = (1.28 * ms) * len;
else
total_ms = ms *len;
TimeSpan ts = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * total_ms));
return ts.TotalSeconds.ToString("F1") + "s";
......
......@@ -34,7 +34,7 @@ namespace FLY.Thick.Base.UI.UiModule
private int interval = 1000;
/// <summary>
/// 间隔,只能选 1, 10, 100, 1000, 这些单位;
/// 特别的,1 = 1.28ms,10=10ms,100=100ms
/// 1 = 1ms,10=10ms,100=100ms
/// </summary>
public int Interval
{
......
......@@ -115,7 +115,6 @@ namespace FLY.Thick.Base.UI.UiModule
IFixService fixService;
FixGraphItemParam graphparam;
DateTime updateTime;
public FixGraphVm()
{
#region 与数据无关界面参数
......@@ -123,7 +122,7 @@ namespace FLY.Thick.Base.UI.UiModule
{
int index = (int)x;
double s = Interval.TotalSeconds * index * values_scale;
return $"{s:F1}s";
return $"{s:F0}s";
};
YFormatter = (y) => y.ToString("F1");
......@@ -146,20 +145,16 @@ namespace FLY.Thick.Base.UI.UiModule
private void FixService_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(fixService.UpdateTime))
{
//检测是哪个变化了
if (fixService.UpdateTime != updateTime)
{
//变化了
//向服务获取数据
fixService.GetFixDatas(fixService_GetFixDatas, this);
}
}
}
private void FixGraphViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "AutoTarget")
if (e.PropertyName == nameof(AutoTarget))
{
updateAutoTarget();
}
......@@ -189,26 +184,26 @@ namespace FLY.Thick.Base.UI.UiModule
}
private void Graphparam_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Interval")
if (e.PropertyName == nameof(graphparam.Interval))
{
UpdateInterval();
}
else if (e.PropertyName == "Mix")
else if (e.PropertyName == nameof(graphparam.Mix))
{
UpdateMix();
}
else if (e.PropertyName == "Len")
else if (e.PropertyName == nameof(graphparam.Len))
{
UpdateX();
}
else if ((e.PropertyName == "IsAutoY") ||
(e.PropertyName == "IsAutoTarget") ||
(e.PropertyName == "YRange") ||
(e.PropertyName == "YTarget"))
else if ((e.PropertyName == nameof(graphparam.IsAutoY)) ||
(e.PropertyName == nameof(graphparam.IsAutoTarget)) ||
(e.PropertyName == nameof(graphparam.YRange)) ||
(e.PropertyName == nameof(graphparam.YTarget)))
{
UpdateY();
}
else if (e.PropertyName == "IsADMode")
else if (e.PropertyName == nameof(graphparam.IsADMode))
{
UpdateIsADMode();
}
......@@ -257,9 +252,6 @@ namespace FLY.Thick.Base.UI.UiModule
void UpdateInterval()
{
TimeSpan interval;
if (graphparam.Interval < 10)
interval = TimeSpan.FromTicks((long)(graphparam.Interval * TimeSpan.TicksPerMillisecond * 1.28));
else
interval = TimeSpan.FromTicks((long)(graphparam.Interval * TimeSpan.TicksPerMillisecond));
Interval = interval;
Intervalms = ((double)(Interval.Ticks)) / TimeSpan.TicksPerMillisecond;
......@@ -389,9 +381,12 @@ namespace FLY.Thick.Base.UI.UiModule
{
double avg = data_interval.Average();
data_interval.Clear();
do
{
data_interval_totaltime -= Interval;
data_mix.Add(avg);
} while (data_interval_totaltime >= Interval);//当 reponse.ts = 1.28, Interval=1时,需要添加更多的数据
int len = data_mix.Count - graphparam.Mix;
if (len > 0)
data_mix.RemoveRange(0, len);
......@@ -489,16 +484,14 @@ namespace FLY.Thick.Base.UI.UiModule
{
using (StreamWriter sw = new StreamWriter(path, false, Encoding.GetEncoding("GB2312")))
{
double ms = graphparam.Interval;
if (ms < 10)
ms *= 1.28;
int ms = graphparam.Interval;
if (IsADMode)
{
sw.WriteLine("时间(ms),AD");
for (int i = 0; i < mDatas.Count(); i++)
{
double d = mDatas[i];
sw.WriteLine($"{(i * ms):F2},{d:F0}");
sw.WriteLine($"{(i * ms)},{d:F0}");
}
}
else
......@@ -507,7 +500,7 @@ namespace FLY.Thick.Base.UI.UiModule
for (int i = 0; i < mDatas.Count(); i++)
{
double d = mDatas[i];
sw.WriteLine($"{(i * ms):F2},{d:F2}");
sw.WriteLine($"{(i * ms)},{d:F2}");
}
}
sw.Flush();
......
......@@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FLY.Thick.Base.UI.UiModule"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Background="White"
......@@ -26,12 +26,10 @@
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<lvc:CartesianChart Grid.Column="1" Hoverable="False" DisableAnimations="True" DataTooltip="{x:Null}" Margin="10" MouseDown="UIElement_OnMouseDown">
<lvc:CartesianChart Hoverable="False" DisableAnimations="True" DataTooltip="{x:Null}" Margin="10" MouseDown="UIElement_OnMouseDown">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Values="{Binding Values}"
......@@ -69,45 +67,27 @@
</lvc:Axis>
</lvc:CartesianChart.AxisY >
</lvc:CartesianChart>
<Grid Grid.Column="1" Grid.Row="1" Margin="10,0,10,10">
<Controls:RangeSlider Grid.Row="1"
Margin="5"
Controls:SliderHelper.ChangeValueBy="LargeChange"
Controls:SliderHelper.EnableMouseWheel="MouseHover"
AutoToolTipPlacement="TopLeft"
LargeChange="10"
Maximum="{Binding XRangeSliderMax}"
Minimum="{Binding XRangeSliderMin}"
Orientation="Horizontal"
SmallChange="1"
LowerValue="{Binding LowerValue}"
UpperValue="{Binding UpperValue}" />
<Grid Grid.Row="2" Margin="{StaticResource ControlMargin}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldHeaderEditable}" Text="X轴最小" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource ResourceKey=TextBoxStyle_FieldContent}" Text="{Binding HzMin}" />
<TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" Text="Hz"/>
<Button Style="{StaticResource ButtonStyle_empty}" Click="ButtonResetXMinClick" VerticalAlignment="Top">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldHeaderEditable}" Text="复位" Background="{StaticResource Color_theme_activity}" Foreground="White" Padding="3"/>
</Grid>
</Button>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldHeaderEditable}" Text="X轴最大" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource ResourceKey=TextBoxStyle_FieldContent}" Text="{Binding HzMax}" />
<TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" Text="Hz"/>
<Button Style="{StaticResource Styles.Button.Square2}" Grid.Column="1" Click="ButtonTestClick" Content="测试"/>
<Button Style="{StaticResource ButtonStyle_empty}" Click="ButtonResetXMaxClick" VerticalAlignment="Top">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldHeaderEditable}" Text="复位" Background="{StaticResource Color_theme_activity}" Foreground="White" Padding="3"/>
</Grid>
</Button>
</StackPanel>
</StackPanel>
</StackPanel>
<Button Style="{StaticResource ButtonStyle_empty}" Click="ButtonTestClick" Grid.Column="1">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldHeaderEditable}" Text="测试" VerticalAlignment="Bottom" Background="{StaticResource Color_theme_noact}" Foreground="White" Padding="10"/>
</Grid>
</Button>
</Grid>
</Grid>
......
......@@ -12,7 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Helpers;
......@@ -56,14 +56,6 @@ namespace FLY.Thick.Base.UI.UiModule
vm.XPointer = p.X;
}
private void ButtonResetXMinClick(object sender, RoutedEventArgs e)
{
viewModel.HzMin = double.NaN;
}
private void ButtonResetXMaxClick(object sender, RoutedEventArgs e)
{
viewModel.HzMax = double.NaN;
}
private void ButtonTestClick(object sender, RoutedEventArgs e)
{
......@@ -89,75 +81,42 @@ namespace FLY.Thick.Base.UI.UiModule
}
}
public class PgFixAnalyzeVm : INotifyPropertyChanged
{
public double XMax
{
get {
if (double.IsNaN(HzMax))
return HzMax;
else
{
return HzMax / MinFs;
}
}
}
public double XMin
{
get
{
if (double.IsNaN(HzMin))
return HzMin;
else
{
return HzMin / MinFs;
}
}
}
/// <summary>
/// X轴拖拉条 最大值
/// </summary>
public double XRangeSliderMax { get; set; } = 10000;
public double YMax { get; set; } = double.NaN;
public double YMin { get; set; } = double.NaN;
/// <summary>
/// X轴拖拉条 最小值
/// </summary>
public double XRangeSliderMin { get; set; } = 0;
private double hzMax = double.NaN;
public double HzMax
{
get {
return hzMax;
}
set {
if(double.IsNaN(HzMin) && double.IsNaN(value) && (value <= HzMin))
return;
/// <summary>
/// X轴 最大值
/// </summary>
public double XMax { get; set; } = 1000;
if (hzMax != value)
{
hzMax = value;
}
}
}
private double hzMin = double.NaN;
public double HzMin
{
get
{
return hzMin;
}
set
{
if (double.IsNaN(HzMax) && double.IsNaN(value) && (value <= HzMax))
return;
/// <summary>
/// X轴 最小值
/// </summary>
public double XMin { get; set; }
if (hzMin != value)
{
hzMin = value;
}
}
}
public double LowerValue { get; set; }
public double UpperValue { get; set; }
public double YMax { get; set; } = double.NaN;
public double YMin { get; set; } = double.NaN;
public double YPointer { get; set; } = 3;
public double XPointer { get; set; } = 3;
public ChartValues<double> Values { get; private set; } = new ChartValues<double>();
public Func<double, string> XFormatter { get; private set; }
DispatcherTimer timer;
public void Test()
{
List<double> datas = new List<double>();
......@@ -177,7 +136,6 @@ namespace FLY.Thick.Base.UI.UiModule
}
Init(intervalms, datas);
//XMax = 1000;
}
double getd(double hz, double ms, int i)
{
......@@ -187,8 +145,33 @@ namespace FLY.Thick.Base.UI.UiModule
public PgFixAnalyzeVm()
{
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
this.PropertyChanged += PgFixAnalyzeVm_PropertyChanged;
}
private void PgFixAnalyzeVm_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(UpperValue)
|| e.PropertyName == nameof(LowerValue)) {
if (!timer.IsEnabled)
timer.Start();
}
}
private void Timer_Tick(object sender, EventArgs e)
{
timer.Stop();
if (LowerValue < UpperValue) {
XMax = UpperValue;
XMin = LowerValue;
}
}
List<double> Magnitudes = new List<double>();
public double MinFs { get; private set; } = 0.1;
public void Init(double intervalms, List<double> datas)
{
......@@ -208,12 +191,18 @@ namespace FLY.Thick.Base.UI.UiModule
MathNet.Numerics.IntegralTransforms.Fourier.Forward(complexs);
complexs[0] = new System.Numerics.Complex(0, 0);
Magnitudes.Clear();
Magnitudes.AddRange(complexs.Take(complexs.Count() / 2).Select(c=>c.Magnitude));
for (int i = 0; i < datas.Count() / 2; i++)
{
Values.Add(complexs[i].Magnitude);
}
Values.AddRange(Magnitudes);
XRangeSliderMax = Values.Count();
XRangeSliderMin = 0;
UpperValue = XRangeSliderMax;
LowerValue = 0;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void ToPropertyChanged(string propertyName) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment