tangxu
2025-02-10 e40718947b5aa9205c87a7478aa86c37a82e0510
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotLineGraph
 
    public class ParrotLineGraph : Control
    {
        public ParrotLineGraph()
        {
            DoubleBuffered = true;
            base.SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
            base.Size = new Size(200, 100);
            items.Add(50);
            items.Add(20);
            items.Add(100);
            items.Add(60);
            items.Add(1);
            items.Add(20);
            items.Add(80);
            items.Add(12);
            items.Add(72);
            items.Add(58);
            items.Add(19);
            items.Add(600);
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public List<int> Items
        {
            get => items;
            set
            {
                items = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public bool ShowVerticalLines
        {
            get => showVerticalLines;
            set
            {
                showVerticalLines = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public Color BackGroundColor
        {
            get => backgroundColor;
            set
            {
                backgroundColor = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public Color BackColor
        {
            get => backColor;
            set
            {
                backColor = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public Color BelowLineColor
        {
            get => belowLineColor;
            set
            {
                belowLineColor = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public Color LineColor
        {
            get => lineColor;
            set
            {
                lineColor = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public Color BorderColor
        {
            get => borderColor;
            set
            {
                borderColor = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text when the tab is selected")]
        public Color VerticalLineColor
        {
            get => verticalLineColor;
            set
            {
                verticalLineColor = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the graph title")]
        public Color GraphTitleColor
        {
            get => graphTitleColor;
            set
            {
                graphTitleColor = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The of the graph")]
        public string GraphTitle
        {
            get => graphTitle;
            set
            {
                graphTitle = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Draw the title on the control")]
        public bool ShowTitle
        {
            get => showTitle;
            set
            {
                showTitle = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Draw the border on the control")]
        public bool ShowBorder
        {
            get => showBorder;
            set
            {
                showBorder = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Draw the points on each value")]
        public bool ShowPoints
        {
            get => showPoints;
            set
            {
                showPoints = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The point size")]
        public int PointSize
        {
            get => pointSize;
            set
            {
                pointSize = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The title alignment")]
        public StringAlignment TitleAlignment
        {
            get => titleAlignment;
            set
            {
                titleAlignment = value;
                Refresh();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The style of the graph")]
        public Style GraphStyle
        {
            get => graphStyle;
            set
            {
                graphStyle = value;
                Refresh();
            }
        }
 
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public PixelOffsetMode PixelOffsetType
        {
            get => _PixelOffsetType;
            set
            {
                _PixelOffsetType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        [Category("Parrot")]
        [Browsable(true)]
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingType;
 
            Pen pen = new(lineColor, 1f);
            Pen pen2 = new(verticalLineColor, 1f);
 
            if (graphStyle == Style.Material)
            {
                e.Graphics.FillRectangle(new SolidBrush(backColor), new Rectangle(0, 0, base.Width, base.Height));
            }
            else
            {
                e.Graphics.FillRectangle(new SolidBrush(backgroundColor), new Rectangle(0, 0, base.Width, base.Height));
            }
 
            int total = items.ToArray().Max();
            int num = base.Width / items.Count;
            int num2 = 0;
            int num3 = base.Height;
            int num4 = num;
            int num5 = 0;
 
            List<PointF> list = new()
            {
                new Point(1, base.Height)
            };
 
            foreach (int num6 in items)
            {
                if (num6 > 0)
                {
                    int num7 = Percentage.IntToPercent(num6, total);
 
                    if (num7 > 97)
                    {
                        num5 = base.Height - Percentage.PercentToInt(97, base.Height);
                    }
                    else if (num7 < 3)
                    {
                        num5 = base.Height - Percentage.PercentToInt(3, base.Height);
                    }
                    else
                    {
                        num5 = base.Height - (num7 * base.Height / 100);
                    }
 
                    list.Add(new Point(num4 - 1, num5 - 1));
 
                    num2 = num4;
                    num3 = num5;
                    num4 += num;
                }
            }
 
            list.Add(new Point(base.Width, num5 - 1));
 
            if (graphStyle != Style.Curved)
            {
                list.Add(new Point(base.Width, base.Height));
 
                if (graphStyle == Style.Flat)
                {
                    SolidBrush brush = new(belowLineColor);
                    e.Graphics.FillPolygon(brush, list.ToArray());
                }
                else
                {
                    LinearGradientBrush brush2 = new(new Rectangle(0, 0, base.Width, base.Height), Color.FromArgb(249, 55, 98), Color.FromArgb(0, 162, 250), 1f);
                    e.Graphics.FillPolygon(brush2, list.ToArray());
                }
 
                num2 = 1;
                num3 = base.Height;
                num4 = num;
                num5 = 0;
 
                int num8 = 0;
 
                foreach (int number in items)
                {
                    int num9 = Percentage.IntToPercent(number, total);
 
                    if (num9 > 97)
                    {
                        num5 = base.Height - Percentage.PercentToInt(97, base.Height);
                    }
                    else if (num9 < 3)
                    {
                        num5 = base.Height - Percentage.PercentToInt(3, base.Height);
                    }
                    else
                    {
                        num5 = base.Height - (num9 * base.Height / 100);
                    }
 
                    if (graphStyle == Style.Flat && showVerticalLines)
                    {
                        num8++;
 
                        if (num8 != items.ToArray().Length && num4 != 0 && num4 != base.Width)
                        {
                            e.Graphics.DrawLine(pen2, num4, base.Height, num4, 0);
                        }
                    }
 
                    e.Graphics.DrawLine(pen, num2 - 1, num3 - 1, num4 - 1, num5 - 1);
 
                    if (showPoints)
                    {
                        if (num5 - (pointSize / 2) - 1 < 0)
                        {
                            e.Graphics.FillEllipse(new SolidBrush(lineColor), new RectangleF(num4 - (pointSize / 2) - 1, -1f, pointSize, pointSize));
                        }
                        else if (num5 - (pointSize / 2) - 1 + pointSize > base.Height)
                        {
                            e.Graphics.FillEllipse(new SolidBrush(lineColor), new RectangleF(num4 - (pointSize / 2) - 1, base.Height - pointSize + 1, pointSize, pointSize));
                        }
                        else
                        {
                            e.Graphics.FillEllipse(new SolidBrush(lineColor), new RectangleF(num4 - (pointSize / 2) - 1, num5 - (pointSize / 2) - 1, pointSize, pointSize));
                        }
                    }
 
                    num2 = num4;
                    num3 = num5;
                    num4 += num;
                }
 
                e.Graphics.DrawLine(pen, num2, num3, base.Width, num3);
            }
            else
            {
                if (showPoints)
                {
                    foreach (PointF pointF in list)
                    {
                        if (pointF.Y - (pointSize / 2) - 1f < 0f)
                        {
                            e.Graphics.FillEllipse(new SolidBrush(lineColor), new RectangleF(pointF.X - (pointSize / 2) - 1f, -1f, pointSize, pointSize));
                        }
                        else if (pointF.Y - (pointSize / 2) - 1f + pointSize > Height)
                        {
                            e.Graphics.FillEllipse(new SolidBrush(lineColor), new RectangleF(pointF.X - (pointSize / 2) - 1f, base.Height - pointSize + 1, pointSize, pointSize));
                        }
                        else
                        {
                            e.Graphics.FillEllipse(new SolidBrush(lineColor), new RectangleF(pointF.X - (pointSize / 2) - 1f, pointF.Y - (pointSize / 2) - 1f, pointSize, pointSize));
                        }
                    }
                }
 
                e.Graphics.DrawCurve(pen, list.ToArray());
            }
 
            if (graphStyle != Style.Material && showBorder)
            {
                e.Graphics.DrawRectangle(new Pen(borderColor, 2f), new Rectangle(0, 0, base.Width - 1, base.Height - 1));
            }
 
            if (showTitle)
            {
                StringFormat stringFormat = new()
                {
                    LineAlignment = StringAlignment.Near,
                    Alignment = titleAlignment
                };
 
                Font font = new("Arial", 14f);
                SolidBrush brush3 = new(graphTitleColor);
                RectangleF layoutRectangle = new(0f, 0f, Width, Height);
 
                e.Graphics.PixelOffsetMode = PixelOffsetType;
                e.Graphics.TextRenderingHint = TextRenderingType;
 
                e.Graphics.DrawString(graphTitle, font, brush3, layoutRectangle, stringFormat);
            }
            base.OnPaint(e);
        }
 
        private List<int> items = new();
 
        private bool showVerticalLines;
 
        private bool showBorder;
 
        private bool showTitle;
 
        private bool showPoints = true;
 
        private StringAlignment titleAlignment;
 
        private int pointSize = 7;
 
        private Color backgroundColor = Color.FromArgb(102, 217, 174);
 
        private Color backColor = Color.FromArgb(40, 40, 40);
 
        private Color belowLineColor = Color.FromArgb(24, 202, 142);
 
        private Color borderColor = Color.White;
 
        private Color lineColor = Color.White;
 
        private Color verticalLineColor = Color.DimGray;
 
        private Color graphTitleColor = Color.Gray;
 
        private string graphTitle = "Parrot Line Graph";
 
        private Style graphStyle = Style.Material;
 
        public enum Style
        {
            Flat,
            Material,
            Curved
        }
    }
 
    #endregion
}