-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chart.cs
112 lines (102 loc) · 4.31 KB
/
Chart.cs
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
using Microsoft.VisualBasic.Devices;
using StockLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace CandleStock
{
/// <summary>
/// The chart.
/// </summary>
public partial class Chart : Form
{
/// <summary>
/// Initializes a new instance of the <see cref="Chart"/> class.
/// </summary>
public Chart()
{
InitializeComponent();
CustomInitalizeComponent();
}
/// <summary>
/// if the chart mouse moves.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The E.</param>
private void firstChart_MouseMove(object sender, MouseEventArgs e)
{
selectedPoint = firstChart.HitTest(e.X, e.Y, false, ChartElementType.DataPoint).First().Object as DataPoint;
if (selectedPoint != null)
{
int stickIndex = stock.Date.ToList().FindIndex(x => x == DateTime.FromOADate(selectedPoint.XValue));
if (stickIndex >= 0 && RecognizerUtils.TypeToString(stock.dojiType[stickIndex]).Length > 4)
{
Doji_Type.Show(RecognizerUtils.TypeToString(stock.dojiType[stickIndex]), this, e.X, e.Y);
}
}
else
{
Doji_Type.Hide(this);
}
firstChart.Invalidate();
}
/// <summary>
/// if the chart paints.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The E.</param>
private void firstChart_Paint(object sender, PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
if(selectedPoint == null)
{
return;
}
Axis xAxis = firstChart.ChartAreas.First().AxisX;
Axis yAxis = firstChart.ChartAreas.First().AxisY;
int stickIndex = stock.Date.ToList().FindIndex(x => x == DateTime.FromOADate(selectedPoint.XValue));
int candleWidth = (int)Math.Abs(xAxis.ValueToPixelPosition(selectedPoint.XValue - currentDateWidth.DateTypeToWidth()) - xAxis.ValueToPixelPosition(selectedPoint.XValue));
Point rectSelected = new Point((int)xAxis.ValueToPixelPosition(selectedPoint.XValue) - (candleWidth >> 1),
(int)yAxis.ValueToPixelPosition(selectedPoint.YValues.Max()) - 5);
Rectangle selectionRect = new Rectangle(rectSelected, new Size(candleWidth, (int)Math.Abs(yAxis.ValueToPixelPosition(selectedPoint.YValues.Max()) - yAxis.ValueToPixelPosition(selectedPoint.YValues.Min())) + 10));
g.DrawRectangle(new Pen((RecognizerUtils.TypeHas(stock.dojiType[stickIndex], RecognizerUtils.Type.bullish) && RecognizerUtils.TypeHas(stock.dojiType[stickIndex], RecognizerUtils.Type.engulfing)) ? Color.LawnGreen :
(RecognizerUtils.TypeHas(stock.dojiType[stickIndex], RecognizerUtils.Type.bearish) && RecognizerUtils.TypeHas(stock.dojiType[stickIndex], RecognizerUtils.Type.engulfing)) ? Color.IndianRed :
Color.GhostWhite),
selectionRect);
}
/// <summary>
/// if the chart form is closing.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The E.</param>
private void Chart_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
Hide();
ShowInTaskbar = false;
}
}
/// <summary>
/// if the chart resizes.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The E.</param>
private void Chart_Resize(object sender, EventArgs e)
{
this.ShowInTaskbar = (this.WindowState == FormWindowState.Minimized);
}
private void Doji_Type_Popup(object sender, PopupEventArgs e)
{
}
}
}