tangxu
2024-06-11 e08f18c84c96ca794407f4fcb737b26fa76c0a1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using DevExpress.Charts.Native;
using DevExpress.ClipboardSource.SpreadsheetML;
using DevExpress.Utils;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class TimeValueEasyChartView : DevExpress.XtraEditors.XtraUserControl
    {
        public TimeValueEasyChartView()
        {
            InitializeComponent();
 
            _boxSelHelper = new ChartBoxSelHelper(this.chartControl1);
            _boxSelHelper.BoxSelCompletedEvent += _boxSelHelper_BoxSelCompletedEvent;
            _diagram = this.chartControl1.Diagram as SwiftPlotDiagram;
            _defaultSeries = this.chartControl1.Series[0];
        }
 
 
        #region  BoxSelHelper
 
        private string _boxSelTag;//框选标签
 
        //开始框选
        public void StartBoxSel(string tag)
        {
            _boxSelTag = tag;
            _diagram.EnableAxisXScrolling = false;
            _diagram.EnableAxisXZooming = false;
            _boxSelHelper.StartBoxSel();
        }
 
 
        //结束框选
        public void CloseBoxSel()
        {
            _boxSelHelper.CloseBoxSel();
        }
 
        private List<SeriesPoint> _boxSelSeriesPointList = null;//框选点
 
        //框选辅助类
        private void _boxSelHelper_BoxSelCompletedEvent(MouseEventArgs obj)
        {
            _diagram.EnableAxisXScrolling = true;
            _diagram.EnableAxisXZooming = true;
            if (_boxSelHelper == null)
                return;
            _boxSelSeriesPointList = _boxSelHelper.CalcuDataTimeSelSeriesPoints(new List<Series>() { _defaultSeries });
            if (_boxSelSeriesPointList == null || _boxSelSeriesPointList.Count < 1)
            {
                _boxSelHelper.CloseBoxSel();
                return;
            }
 
            this.popMenu.ShowPopup(MousePosition);
        }
 
 
        //确认
        private void barBtnOk_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.BoxSelCompleteEvent != null)
            {
                var list = _boxSelSeriesPointList.Select(x => x.Tag as TimeValue).ToList();
                this.BoxSelCompleteEvent.Invoke(_boxSelTag, list);
            }
            _boxSelSeriesPointList = null;
            _boxSelHelper.CloseBoxSel();
        }
 
        #endregion
 
 
        private SwiftPlotDiagram _diagram;//图表   
        private Series _defaultSeries;
 
        private ChartBoxSelHelper _boxSelHelper = null;//框选辅助类  
        public event Action<string, List<TimeValue>> BoxSelCompleteEvent = null;//框选完成事件
 
 
        /// <summary>
        /// 初始化默认系列
        /// </summary>
        /// <param name="timeValues">数据源</param>
        public void InitialDefaultSeries(IEnumerable<TimeValue> timeValues)
        {
            var lays = this.chartControl1.ShowOverlay();
            if (timeValues == null || timeValues.Count() < 1)
            {
                _defaultSeries.BindToData(timeValues, null);
            }
            else
            {
                _defaultSeries.BindToData(timeValues, "Time", "Value");
            }
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForFullGCComplete();
            lays.Close();
        }
 
        public void SetAxisXTitle(string title)
        {
            _diagram.AxisX.Title.Text = title;
        }
 
        public void SetAxisYTitle(string title)
        {
            _diagram.AxisY.Title.Text = title;
        }
 
    }
}