From cecd5e98941ff09c2e00b50d1c3e5733d2d9309c Mon Sep 17 00:00:00 2001
From: Shuxia Ning <NingShuxia0927@outlook.com>
Date: 星期二, 10 十二月 2024 10:42:45 +0800
Subject: [PATCH] workingChart

---
 WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-run-view/PumpRunViewChart.cs |  139 ++++++++++++++++++++++++++-------------------
 1 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-run-view/PumpRunViewChart.cs b/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-run-view/PumpRunViewChart.cs
index c36c8f9..f1992ab 100644
--- a/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-run-view/PumpRunViewChart.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-run-view/PumpRunViewChart.cs
@@ -1,7 +1,6 @@
-锘縰sing DevExpress.Office.Utils;
-using DevExpress.PivotGrid.OLAP.AdoWrappers;
-using DevExpress.Utils;
+锘縰sing DevExpress.Utils;
 using DevExpress.Utils.Drawing;
+using DevExpress.Utils.Html.Internal;
 using DevExpress.XtraCharts;
 
 namespace Yw.WinFrmUI.Phart
@@ -16,6 +15,8 @@
             InitializeComponent();
             InitialChart();
             this.chartControl1.RuntimeHitTesting = true;
+            this.chartControl1.SelectionMode = ElementSelectionMode.Extended;
+            this.chartControl1.SeriesSelectionMode = SeriesSelectionMode.Point;
         }
 
         #region Private Variable 
@@ -34,11 +35,55 @@
         private bool _qe_visible = true;
         private bool _qp_visible = true;
 
-        private bool _run_visible = true; 
+        private bool _run_point_visible = true;
 
         private bool _initial_data = false;
 
         private PumpRunViewViewModel _vm = null;
+
+        #endregion
+
+
+        #region Public Variable 
+
+        /// <summary>
+        /// 鏁堢巼鏄剧ず
+        /// </summary>
+        public bool QEVisible
+        {
+            get => _qe_visible;
+            set
+            {
+                _qe_visible = value;
+                SetQEVisible(_qe_visible);
+            }
+        }
+
+        /// <summary>
+        /// 鍔熺巼鏄剧ず
+        /// </summary>
+        public bool QPVisble
+        {
+            get => _qp_visible;
+            set
+            {
+                _qp_visible = value;
+                SetQPVisible(_qp_visible);
+            }
+        }
+
+        /// <summary>
+        /// 杩愯鐐规樉绀�
+        /// </summary>
+        public bool RunPointVisible
+        {
+            get => _run_point_visible;
+            set
+            {
+                _run_point_visible = value;
+            }
+        }
+
 
         #endregion
 
@@ -53,7 +98,9 @@
         /// <summary>
         /// 杩愯鐐归�夋嫨浜嬩欢
         /// </summary>
-        public event Action<PumpCoordinate> RunPointSelectedEvent = null;
+        public event Action<PumpRunViewItemViewModel> RunPointSelectedEvent = null;
+
+
         #endregion
 
         #region Initial
@@ -91,46 +138,32 @@
             _axis_y_power.Visibility = DefaultBoolean.False;
             _axis_y_power.GridLines.Visible = false;
 
-
-            this.chartControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseUp);
-            this.chartControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseMove);
-            this.chartControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseDown);
+             
+            this.chartControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseDown); 
             this.chartControl1.CustomPaint += ChartControl1_CustomPaint;
         }
 
+        private List<Tuple<Rectangle, Color, PumpRunViewItemViewModel>> _rect_list = new();
+        private Point? _rect_point = null;
         private void chartControl1_MouseDown(object sender, MouseEventArgs e)
         {
             if (!_initial_data)
-                return; 
+                return;
+            if (!_run_point_visible)
+                return;
             if (_rect_list == null || !_rect_list.Any())
                 return;
             foreach (var rect in _rect_list)
             {
                 if (rect.Item1.Contains(e.Location))
                 {
-                    _rect_sel = new Rectangle(rect.Item1.X, rect.Item1.Y, 12, 12);
-                    _rect_color_sel = rect.Item2;
+                    _rect_point = new Point(rect.Item1.X + 5, rect.Item1.Y + 5);
+                    this.RunPointSelectedEvent?.Invoke(rect.Item3);
                     break;
                 }
             }
         }
-
-        private void chartControl1_MouseMove(object sender, MouseEventArgs e)
-        {
-            if (!_initial_data)
-                return;
-            if (_rect_list == null || !_rect_list.Any())
-                return;
-        }
-
-        private void chartControl1_MouseUp(object sender, MouseEventArgs e)
-        {
-            if (!_initial_data)
-                return;
-            if (_rect_list == null || !_rect_list.Any())
-                return;
-        }
-
+         
         private void ChartControl1_CustomPaint(object sender, CustomPaintEventArgs e)
         {
             if (e is not DXCustomPaintEventArgs dxArgs)
@@ -138,8 +171,8 @@
             if (_vm == null)
                 return;
             _rect_list.Clear();
-            if (_vm.Items != null && _vm.Items.Any() && _run_visible)
-            { 
+            if (_vm.Items != null && _vm.Items.Any() && _run_point_visible)
+            {
                 foreach (var vm in _vm.Items)
                 {
                     var color = vm.Color;
@@ -153,7 +186,7 @@
                         var dg_y = dg_pt.Point.Y - 5;
 
                         dxArgs.Cache.FillEllipse(dg_x, dg_y, 10, 10, color);
-                        _rect_list.Add(new Tuple<Rectangle, Color>(new Rectangle(dg_x, dg_y, 10, 10),color));
+                        _rect_list.Add(new(new Rectangle(dg_x, dg_y, 10, 10), color, vm));
                     }
                     if (eff.HasValue && _qe_visible)
                     {
@@ -161,6 +194,7 @@
                         var dg_x = dg_pt.Point.X - 5;
                         var dg_y = dg_pt.Point.Y - 5;
                         dxArgs.Cache.FillEllipse(dg_x, dg_y, 10, 10, color);
+                        _rect_list.Add(new(new Rectangle(dg_x, dg_y, 10, 10), color, vm));
                     }
 
                     if (power.HasValue && _qp_visible)
@@ -169,32 +203,21 @@
                         var dg_x = dg_pt.Point.X - 5;
                         var dg_y = dg_pt.Point.Y - 5;
                         dxArgs.Cache.FillEllipse(dg_x, dg_y, 10, 10, color);
-                    } 
+                        _rect_list.Add(new(new Rectangle(dg_x, dg_y, 10, 10), color, vm));
+                    }
                 }
-                if (_rect_sel.HasValue)
+                if (_rect_point.HasValue)
                 {
-                    using Brush brush = new SolidBrush(_rect_color_sel.Value);
-                    dxArgs.Cache.FillEllipse(brush, _rect_sel.Value);
+                    var x = _rect_point.Value.X;
+                    var y = _rect_point.Value.Y;
+                    var length = 20;
+                    using Pen pen = new Pen(Color.Magenta, 2);
+                    dxArgs.Cache.DrawLine(pen, new Point(x - length, y), new Point(x + length, y));
+                    dxArgs.Cache.DrawLine(pen, new Point(x, y - length), new Point(x, y + length));
+                    dxArgs.Cache.DrawEllipse(pen, new Rectangle(x - 10, y - 10, length, length));
                 }
             }
-          
         }
-
-        private List<Tuple<Rectangle,Color>> _rect_list = new List<Tuple<Rectangle, Color>>();
-        private Rectangle? _rect_sel = null;
-        private Color? _rect_color_sel = null;
-      
-        private Rectangle DrawWorkPoint(GraphicsCache cache, Color color, AxisYBase axis_y, double x, double y)
-        {
-            var dg_pt = _diagram.DiagramToPoint(x, y, _axis_x_flow, axis_y);
-            var dg_x = dg_pt.Point.X - 5;
-            var dg_y = dg_pt.Point.Y - 5;
-
-            cache.FillEllipse(dg_x, dg_y, 10, 10, color);
-            return new Rectangle(dg_x, dg_y, 10, 10);
-        }
-
-
          
         /// <summary>
         /// 鍒濆鍖栧浘琛ㄦ暟鎹�
@@ -202,8 +225,7 @@
         public void InitialChartData()
         {
             _initial_data = false;
-            _coordinate = null;
-
+            _coordinate = null; 
             UpdateChart(false);
         }
 
@@ -237,9 +259,8 @@
         /// </summary>
         public void UpdateChart(bool calc_coordinate = false)
         {
-            _rect_sel = null;
-            _rect_color_sel = null;
-            _rect_list = new List<Tuple<Rectangle, Color>>();
+            _rect_point = null; 
+            _rect_list = new ();
             if (calc_coordinate || _coordinate == null)
             {
                 //涓嶅己杩绠�,灏辩敤涓婃鏇存柊鐨勫潗鏍囩郴
@@ -809,7 +830,7 @@
         /// </summary> 
         public void SetEQVisible(bool visible)
         {
-            _run_visible = visible;
+            _run_point_visible = visible;
         }
 
 

--
Gitblit v1.9.3