动画连续性优化
This commit is contained in:
parent
2da27f3dcd
commit
6883c8046d
@ -15,13 +15,18 @@
|
|||||||
<RowDefinition Height="Auto"></RowDefinition>
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
<RowDefinition Height="*"></RowDefinition>
|
<RowDefinition Height="*"></RowDefinition>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<lvc:CartesianChart Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="flowChart" Series="{Binding Series}" LegendLocation="None" >
|
<lvc:CartesianChart Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="flowChart" Series="{Binding Series}" LegendLocation="None" AnimationsSpeed="0:0:1" >
|
||||||
<lvc:CartesianChart.AxisY>
|
|
||||||
<lvc:Axis Foreground="#222" MinValue="0" LabelFormatter="{Binding YFormatter}"></lvc:Axis>
|
<lvc:CartesianChart.AxisX >
|
||||||
</lvc:CartesianChart.AxisY>
|
<lvc:Axis Unit="1000" LabelsRotation="0" Foreground="#222" LabelFormatter="{Binding XFormatter}">
|
||||||
<lvc:CartesianChart.AxisX>
|
</lvc:Axis>
|
||||||
<lvc:Axis Foreground="#222" Labels="{Binding Labels}"></lvc:Axis>
|
|
||||||
</lvc:CartesianChart.AxisX>
|
</lvc:CartesianChart.AxisX>
|
||||||
|
|
||||||
|
<lvc:CartesianChart.AxisY>
|
||||||
|
<lvc:Axis Foreground="#222" MinValue="0" LabelFormatter="{Binding YFormatter}">
|
||||||
|
</lvc:Axis>
|
||||||
|
</lvc:CartesianChart.AxisY>
|
||||||
|
|
||||||
</lvc:CartesianChart>
|
</lvc:CartesianChart>
|
||||||
<StackPanel Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" VerticalAlignment="Top">
|
<StackPanel Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" VerticalAlignment="Top">
|
||||||
<TextBlock FontSize="12" FontWeight="Light" Foreground="DodgerBlue" HorizontalAlignment="Center" Margin="0 5">上行流量</TextBlock>
|
<TextBlock FontSize="12" FontWeight="Light" Foreground="DodgerBlue" HorizontalAlignment="Center" Margin="0 5">上行流量</TextBlock>
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
using LiveCharts;
|
using LiveCharts;
|
||||||
|
using LiveCharts.Configurations;
|
||||||
using LiveCharts.Wpf;
|
using LiveCharts.Wpf;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@ -18,19 +18,24 @@ namespace FastGithub.UI
|
|||||||
{
|
{
|
||||||
Title = "上行速率",
|
Title = "上行速率",
|
||||||
PointGeometry = null,
|
PointGeometry = null,
|
||||||
Values = new ChartValues<double>()
|
Values = new ChartValues<RateItem>()
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly LineSeries writeSeries = new LineSeries()
|
private readonly LineSeries writeSeries = new LineSeries()
|
||||||
{
|
{
|
||||||
Title = "下行速率",
|
Title = "下行速率",
|
||||||
PointGeometry = null,
|
PointGeometry = null,
|
||||||
Values = new ChartValues<double>()
|
Values = new ChartValues<RateItem>()
|
||||||
};
|
};
|
||||||
|
|
||||||
public SeriesCollection Series { get; } = new SeriesCollection();
|
private static DateTime GetDateTime(double timestamp) => new DateTime(1970, 1, 1).Add(TimeSpan.FromMilliseconds(timestamp)).ToLocalTime();
|
||||||
|
|
||||||
public List<string> Labels { get; } = new List<string>();
|
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 Func<double, string> XFormatter { get; } = timestamp => GetDateTime(timestamp).ToString("HH:mm:ss");
|
||||||
|
|
||||||
public Func<double, string> YFormatter { get; } = value => $"{FlowStatistics.ToNetworkSizeString((long)value)}/s";
|
public Func<double, string> YFormatter { get; } = value => $"{FlowStatistics.ToNetworkSizeString((long)value)}/s";
|
||||||
|
|
||||||
@ -77,16 +82,29 @@ namespace FastGithub.UI
|
|||||||
this.textBlockRead.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalRead);
|
this.textBlockRead.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalRead);
|
||||||
this.textBlockWrite.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalWrite);
|
this.textBlockWrite.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalWrite);
|
||||||
|
|
||||||
this.readSeries.Values.Add(flowStatistics.ReadRate);
|
var timestamp = GetTimestamp(DateTime.Now);
|
||||||
this.writeSeries.Values.Add(flowStatistics.WriteRate);
|
this.readSeries.Values.Add(new RateItem(flowStatistics.ReadRate, timestamp));
|
||||||
this.Labels.Add(DateTime.Now.ToString("HH:mm:ss"));
|
this.writeSeries.Values.Add(new RateItem(flowStatistics.WriteRate, timestamp));
|
||||||
|
|
||||||
if (this.Labels.Count > 60)
|
if (this.readSeries.Values.Count > 60)
|
||||||
{
|
{
|
||||||
this.readSeries.Values.RemoveAt(0);
|
this.readSeries.Values.RemoveAt(0);
|
||||||
this.writeSeries.Values.RemoveAt(0);
|
this.writeSeries.Values.RemoveAt(0);
|
||||||
this.Labels.RemoveAt(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class RateItem
|
||||||
|
{
|
||||||
|
public double Rate { get; }
|
||||||
|
|
||||||
|
public double Timestamp { get; }
|
||||||
|
|
||||||
|
public RateItem(double rate, double timestamp)
|
||||||
|
{
|
||||||
|
this.Rate = rate;
|
||||||
|
this.Timestamp = timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user