| | |
| | | using ScottPlot; |
| | | using Plugin.TestResult_WPF.Model; |
| | | using ScottPlot; |
| | | using ScottPlot.Plottables; |
| | | using ScottPlot.TickGenerators; |
| | | using System; |
| | |
| | | |
| | | namespace Plugin.TestResult_WPF |
| | | { |
| | | /// <summary> |
| | | /// Chart.xaml 的交互逻辑 |
| | | /// </summary> |
| | | /// <summary> |
| | | /// Chart.xaml 的交互逻辑 |
| | | /// </summary> |
| | |
| | | |
| | | private double maxYValue = -1; |
| | | private double minYValue = double.MaxValue; |
| | | private float fontSize = -1; |
| | | |
| | | private Timer timer; |
| | | |
| | |
| | | timer.Elapsed += Timer_Elapsed; |
| | | } |
| | | |
| | | public Chart(string title, bool multi, float titleSize) |
| | | { |
| | | BaseConfig config = new BaseConfig(); |
| | | this.title = title; |
| | | this.multi = multi; |
| | | this.maxSize = config.MaxSize; |
| | | this.refreshInterval = config.RefreshInterval; |
| | | fontSize = titleSize; |
| | | |
| | | InitializeComponent(); |
| | | if (this.multi) |
| | | { |
| | | xValues = new Dictionary<string, Queue<long>>(); |
| | | yValues = new Dictionary<string, Queue<double>>(); |
| | | //chart.Plot.ShowLegend(Alignment.UpperLeft, Orientation.Vertical); |
| | | var legend = chart.Plot.ShowLegend(Edge.Top); |
| | | legend.Alignment = Alignment.UpperLeft; |
| | | legend.Padding = new PixelPadding(0); |
| | | |
| | | |
| | | chart.Plot.Axes.Left.TickLabelStyle.FontSize = titleSize - 3; |
| | | chart.Plot.Axes.Bottom.TickLabelStyle.FontSize = titleSize - 3; |
| | | chart.Plot.Axes.Left.Label.FontSize = titleSize; |
| | | } |
| | | else |
| | | { |
| | | singleLogger = InitLogger(); |
| | | singleLogger.Color = Colors.Red; |
| | | xData = new Queue<long>(maxSize); |
| | | yData = new Queue<double>(maxSize); |
| | | chart.Plot.Axes.Left.TickLabelStyle.FontSize = titleSize - 3; |
| | | chart.Plot.Axes.Bottom.TickLabelStyle.FontSize = titleSize - 3; |
| | | chart.Plot.Axes.Left.Label.FontSize = titleSize; |
| | | } |
| | | |
| | | /// 禁用鼠标 |
| | | chart.UserInputProcessor.Disable(); |
| | | |
| | | string CustomFormatter(double position) |
| | | { |
| | | if (position > 0) |
| | | return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(position).ToString("HH:mm:ss"); |
| | | return ""; |
| | | } |
| | | EvenlySpacedMinorTickGenerator minorTickGen = new EvenlySpacedMinorTickGenerator(10); |
| | | NumericAutomatic myTickGenerator = new NumericAutomatic() |
| | | { |
| | | LabelFormatter = CustomFormatter, |
| | | MinorTickGenerator = minorTickGen |
| | | }; |
| | | chart.Plot.Axes.Bottom.TickGenerator = myTickGenerator; |
| | | if (!string.IsNullOrEmpty(this.title)) |
| | | { |
| | | chart.Plot.Axes.Left.Label.Text = this.title; |
| | | chart.Plot.Axes.Left.Label.Bold = false; |
| | | chart.Plot.Font.Automatic(); |
| | | //RefreshData(); |
| | | } |
| | | |
| | | timer = new Timer(); |
| | | timer.Interval = this.refreshInterval; |
| | | timer.Elapsed += Timer_Elapsed; |
| | | } |
| | | |
| | | private void Timer_Elapsed(object sender, ElapsedEventArgs e) |
| | | { |
| | | if (maxYValue > 0) |
| | |
| | | |
| | | public void RefreshData() |
| | | { |
| | | bool flag = timer.Enabled; |
| | | try |
| | | { |
| | | timer.Enabled = false; |
| | | /// 限制y轴 |
| | | if (maxYValue > -1) |
| | | { |
| | |
| | | chart.Plot.Axes.SetLimitsY(0, 100); |
| | | } |
| | | chart.Refresh(); |
| | | } |
| | | finally |
| | | { |
| | | timer.Enabled = flag; |
| | | } |
| | | } |
| | | |
| | | public void Clear() |
| | |
| | | .ToList() |
| | | .ForEach(m => chart.Plot.Remove(m)); |
| | | //RefreshData(); |
| | | } |
| | | |
| | | public List<double> GetSingleData() |
| | | { |
| | | bool flag = timer.Enabled; |
| | | try |
| | | { |
| | | timer.Enabled = false; |
| | | return yData?.ToList(); |
| | | } |
| | | finally |
| | | { |
| | | timer.Enabled = flag; |
| | | } |
| | | } |
| | | |
| | | private void InsertData(Queue<long> xAxis, Queue<double> yAxis, long x, double y) |
| | |
| | | private void UserControl_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e) |
| | | { |
| | | if (this.multi) return; |
| | | if (fontSize < 0) |
| | | { |
| | | chart.Plot.Axes.Left.Label.FontSize = (float)FontSizeConverter.CountFontSize(15, ActualHeight, 92); |
| | | chart.Plot.Axes.Left.TickLabelStyle.FontSize = (float)FontSizeConverter.CountFontSize(10, ActualHeight, 92); |
| | | chart.Plot.Axes.Bottom.TickLabelStyle.FontSize = (float)FontSizeConverter.CountFontSize(10, ActualHeight, 92); |
| | | } |
| | | else |
| | | { |
| | | chart.Plot.Axes.Left.Label.FontSize = fontSize - 3; |
| | | chart.Plot.Axes.Left.TickLabelStyle.FontSize = fontSize - 3; |
| | | chart.Plot.Axes.Bottom.TickLabelStyle.FontSize = fontSize; |
| | | } |
| | | } |
| | | } |
| | | } |