UI动画优化

This commit is contained in:
陈国伟 2021-11-11 12:39:50 +08:00
parent 6883c8046d
commit 5f97c381ab
4 changed files with 27 additions and 17 deletions

View File

@ -18,12 +18,12 @@
<lvc:CartesianChart Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="flowChart" Series="{Binding Series}" LegendLocation="None" AnimationsSpeed="0:0:1" >
<lvc:CartesianChart.AxisX >
<lvc:Axis Unit="1000" LabelsRotation="0" Foreground="#222" LabelFormatter="{Binding XFormatter}">
<lvc:Axis Foreground="#222" Unit="1000" LabelFormatter="{Binding XFormatter}">
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Foreground="#222" MinValue="0" LabelFormatter="{Binding YFormatter}">
<lvc:Axis Foreground="#222" MinValue="0" LabelFormatter="{Binding YFormatter}">
</lvc:Axis>
</lvc:CartesianChart.AxisY>

View File

@ -18,14 +18,16 @@ namespace FastGithub.UI
{
Title = "上行速率",
PointGeometry = null,
Values = new ChartValues<RateItem>()
LineSmoothness = 1D,
Values = new ChartValues<RateTick>()
};
private readonly LineSeries writeSeries = new LineSeries()
{
Title = "下行速率",
PointGeometry = null,
Values = new ChartValues<RateItem>()
LineSmoothness = 1D,
Values = new ChartValues<RateTick>()
};
private static DateTime GetDateTime(double timestamp) => new DateTime(1970, 1, 1).Add(TimeSpan.FromMilliseconds(timestamp)).ToLocalTime();
@ -33,7 +35,7 @@ namespace FastGithub.UI
private static double GetTimestamp(DateTime dateTime) => dateTime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
public SeriesCollection Series { get; } = new SeriesCollection(Mappers.Xy<RateItem>().X(item => item.Timestamp).Y(item => item.Rate));
public SeriesCollection Series { get; } = new SeriesCollection(Mappers.Xy<RateTick>().X(item => item.Timestamp).Y(item => item.Rate));
public Func<double, string> XFormatter { get; } = timestamp => GetDateTime(timestamp).ToString("HH:mm:ss");
@ -47,10 +49,10 @@ namespace FastGithub.UI
this.Series.Add(this.writeSeries);
this.DataContext = this;
this.InitFlowChart();
this.InitFlowChartAsync();
}
private async void InitFlowChart()
private async void InitFlowChartAsync()
{
using var httpClient = new HttpClient();
while (this.Dispatcher.HasShutdownStarted == false)
@ -83,8 +85,8 @@ namespace FastGithub.UI
this.textBlockWrite.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalWrite);
var timestamp = GetTimestamp(DateTime.Now);
this.readSeries.Values.Add(new RateItem(flowStatistics.ReadRate, timestamp));
this.writeSeries.Values.Add(new RateItem(flowStatistics.WriteRate, timestamp));
this.readSeries.Values.Add(new RateTick(flowStatistics.ReadRate, timestamp));
this.writeSeries.Values.Add(new RateTick(flowStatistics.WriteRate, timestamp));
if (this.readSeries.Values.Count > 60)
{
@ -93,13 +95,13 @@ namespace FastGithub.UI
}
}
private class RateItem
private class RateTick
{
public double Rate { get; }
public double Timestamp { get; }
public RateItem(double rate, double timestamp)
public RateTick(double rate, double timestamp)
{
this.Rate = rate;
this.Timestamp = timestamp;

View File

@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using System.Windows.Controls;
namespace FastGithub.UI
@ -19,16 +20,22 @@ namespace FastGithub.UI
}
private async void InitUdpLoggerAsync()
{
{
while (this.Dispatcher.HasShutdownStarted == false)
{
var log = await UdpLogger.GetUdpLogAsync();
if (log != null)
try
{
var log = await UdpLogger.GetUdpLogAsync();
if (log != null)
{
this.LogList.Add(log);
}
}
catch (Exception)
{
this.LogList.Add(log);
}
}
}
}
private void MenuItem_Copy_Click(object sender, System.Windows.RoutedEventArgs e)
{

View File

@ -149,6 +149,7 @@ namespace FastGithub
}
finally
{
this.logger.LogInformation($"正在主动关闭,因为父进程已退出");
await this.host.StopAsync(cancellationToken);
}
}