From c4a3f8db90530a727ffab77c3bb5bb7d782792bf Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 25 八月 2025 15:50:27 +0800
Subject: [PATCH] 上传代码;

---
 Plugin.TestResult/Chart.xaml.cs |  121 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 111 insertions(+), 10 deletions(-)

diff --git a/Plugin.TestResult/Chart.xaml.cs b/Plugin.TestResult/Chart.xaml.cs
index 16257d5..988f2a2 100644
--- a/Plugin.TestResult/Chart.xaml.cs
+++ b/Plugin.TestResult/Chart.xaml.cs
@@ -1,4 +1,5 @@
-锘縰sing ScottPlot;
+锘縰sing Plugin.TestResult_WPF.Model;
+using ScottPlot;
 using ScottPlot.Plottables;
 using ScottPlot.TickGenerators;
 using System;
@@ -9,6 +10,9 @@
 
 namespace Plugin.TestResult_WPF
 {
+    /// <summary>
+    /// Chart.xaml 鐨勪氦浜掗�昏緫
+    /// </summary>
     /// <summary>
     /// Chart.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
@@ -30,6 +34,7 @@
 
         private double maxYValue = -1;
         private double minYValue = double.MaxValue;
+        private float fontSize = -1;
 
         private Timer timer;
 
@@ -167,6 +172,70 @@
             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)
@@ -177,16 +246,25 @@
 
         public void RefreshData()
         {
-            /// 闄愬埗y杞�
-            if (maxYValue > -1)
+            bool flag = timer.Enabled;
+            try
             {
-                chart.Plot.Axes.SetLimitsY(minYValue > 5 ? minYValue - 5 : 0, maxYValue + 5);
+                timer.Enabled = false;
+                /// 闄愬埗y杞�
+                if (maxYValue > -1)
+                {
+                    chart.Plot.Axes.SetLimitsY(minYValue > 5 ? minYValue - 5 : 0, maxYValue + 5);
+                }
+                else
+                {
+                    chart.Plot.Axes.SetLimitsY(0, 100);
+                }
+                chart.Refresh();
             }
-            else
+            finally
             {
-                chart.Plot.Axes.SetLimitsY(0, 100);
+                timer.Enabled = flag;
             }
-            chart.Refresh();
         }
 
         public void Clear()
@@ -234,6 +312,20 @@
                 .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)
@@ -306,9 +398,18 @@
         private void UserControl_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
         {
             if (this.multi) return;
-            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);
+            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;
+            }
         }
     }
 }

--
Gitblit v1.9.1