-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGraphControl.cs
More file actions
291 lines (237 loc) · 8.8 KB
/
GraphControl.cs
File metadata and controls
291 lines (237 loc) · 8.8 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Steema.TeeChart.Styles;
using System.IO;
namespace HdbPoet
{
public partial class GraphControl : UserControl
{
GraphData graphDef;
public GraphControl()
{
InitializeComponent();
//graphDef = new GraphData(0);
//graphDef.GraphRow.AddGraphRow(graphDef.Graph.NewGraphRow());
}
/// <summary>
/// clear out all Series
/// </summary>
internal void Cleanup()
{
chart.Series.Clear();
}
internal void Print()
{
this.chart.Printer.Preview();
}
internal void ChangeSeriesValue(TimeSeriesChangeEventArgs e)
{
Series s = chart.Series[e.SeriesIndex];
if (e.Value.HasValue)
{
s[e.RowIndex].Y = e.Value.Value;
s[e.RowIndex].Color = s.Color;
}
else
{
s[e.RowIndex].Color = Color.Transparent;
}
}
internal void DrawGraph(GraphData graphDef)
{
this.graphDef = graphDef;
this.toolStripButtonDragPoints.Enabled = !graphDef.ReadOnly;
UndoZoom();
chart.Axes.Left.Automatic = true;
chart.Axes.Right.Automatic = true;
bool haveTemplate = !graphDef.GraphRow.IsChartSettingsNull();
if (haveTemplate)
{
MemoryStream m = new MemoryStream(graphDef.GraphRow.ChartSettings);
chart.Import.Template.Load(m);
m.Close();
}
HdbPoet.Graphs.StandardTChart(graphDef, chart,haveTemplate);
SetupTChartTools();
}
private bool m_dragPoints = false;
public bool DragPoints
{
get { return m_dragPoints; }
set
{
m_dragPoints = value;
SetupTChartTools();
}
}
void SetupTChartTools()
{
chart.Tools.Clear();
Steema.TeeChart.Tools.MarksTip marksTip1 = new Steema.TeeChart.Tools.MarksTip();
marksTip1.Style = Steema.TeeChart.Styles.MarksStyles.XY;
marksTip1.GetText += new Steema.TeeChart.Tools.MarksTipGetTextEventHandler(this.marksTip1_GetText);
chart.Tools.Add(marksTip1);
if (graphDef == null)
return;
if (m_dragPoints && !graphDef.ReadOnly)
{
for (int i = 0; i < graphDef.SeriesRows.Count(); i++)
{
Steema.TeeChart.Tools.DragPoint dragPoint1 = new Steema.TeeChart.Tools.DragPoint();
dragPoint1.Series = chart[i];
dragPoint1.Active = true;
dragPoint1.Style = Steema.TeeChart.Tools.DragPointStyles.Y;
dragPoint1.Drag += new Steema.TeeChart.Tools.DragPointEventHandler(this.dragPoint1_Drag);
dragPoint1.Cursor = System.Windows.Forms.Cursors.Hand;
chart.Tools.Add(dragPoint1);
}
}
}
bool m_SetActiveCellNeeded = false;
DateTime dragDateTime = DateTime.MinValue;
int dragSeriesIndex = -1;
private void dragPoint1_Drag(Steema.TeeChart.Tools.DragPoint sender,
int Index)
{
int seriesIndex = chart.Series.IndexOf(sender.Series);
if (seriesIndex >= 0)
{
double val = chart[seriesIndex].YValues[Index];
val = Math.Round(val, 2);
chart[seriesIndex].YValues[Index] = val;
DateTime t = Steema.TeeChart.Utils.DateTime(chart[seriesIndex].XValues[Index]);
graphDef.UpdateIntervalTable(seriesIndex, t, val);
dragDateTime = t;
dragSeriesIndex = seriesIndex;
m_SetActiveCellNeeded = true;
}
}
public event EventHandler<PointChangeEventArgs> PointChanged;
private void chart_MouseUp(object sender, MouseEventArgs e)
{
if (m_SetActiveCellNeeded)
{
PointChangedRaised(dragDateTime,dragSeriesIndex);
//timeSeriesTableView1.SelectCell(dragDateTime, dragSeriesIndex);
m_SetActiveCellNeeded = false;
}
}
private void PointChangedRaised(DateTime dragDateTime, int dragSeriesIndex)
{
EventHandler<PointChangeEventArgs> handler= PointChanged;
if (handler != null)
{
handler(this, new PointChangeEventArgs(dragSeriesIndex, dragDateTime));
}
}
void UndoZoom()
{
chart.Zoom.Undo();
chart.Refresh();
}
private void menuItemChartProperties_Click(object sender, EventArgs e)
{
chart.ShowEditor();
}
private void toolStripButtonDragPoints_Click(object sender, EventArgs e)
{
DragPoints = !DragPoints;
toolStripButtonDragPoints.Checked = DragPoints;
}
private void marksTip1_GetText(Steema.TeeChart.Tools.MarksTip sender, Steema.TeeChart.Tools.MarksTipGetTextEventArgs e)
{
e.Text = m_markTipText;
}
string m_markTipText = "";
private void chart_MouseMove(object sender, MouseEventArgs e)
{
m_markTipText = "";
int index = -1;
for (int i = 0; i < chart.Series.Count; i++)
{
Series s = chart[i];
index = s.Clicked(e.X, e.Y);
if (index != -1 && i < graphDef.SeriesRows.Count())
{
DateTime t = Steema.TeeChart.Utils.DateTime(s[index].X);
double val = s[index].Y;
switch (graphDef.SeriesRows.Skip(i).First().Interval)
{
case "day": m_markTipText = t.ToString("MM/dd/yyyy") + ", " + val.ToString();
break;
case "hour": m_markTipText = t.ToString("MM/dd/yyyy HH:mm") + ", " + val.ToString();
break;
case "instant": m_markTipText = t.ToString("MM/dd/yyyy HH:mm") + ", " + val.ToString();
break;
default: m_markTipText = t.ToString("MM/dd/yyyy") + ", " + val.ToString();
break;
}
break;
}
}
}
//private void GraphForm_FormClosing(object sender, FormClosingEventArgs e)
//{
// if (e.CloseReason == CloseReason.UserClosing)
// {
// e.Cancel = true;
// this.Visible = false;
// }
//}
private void toolStripButtonUndoZoom_Click(object sender, EventArgs e)
{
UndoZoom();
}
private void toolStripButtonProperties_Click(object sender, EventArgs e)
{
//chart.ShowEditor();
chart.Export.Template.IncludeData = false;
// to do.. write to stream of bytes.. then save in ChartSettings
Steema.TeeChart.Editor.Show(chart);
MemoryStream mem = new MemoryStream();
chart.Export.Template.Save(mem);
graphDef.GraphRow.ChartSettings = mem.ToArray();
mem.Close();
}
private void undoZoomToolStripMenuItem_Click(object sender, EventArgs e)
{
UndoZoom();
}
private void propertieschartToolStripMenuItem_Click(object sender, EventArgs e)
{
Steema.TeeChart.Editor.Show(chart);
}
public event EventHandler<EventArgs> EditSeriesClick;
private void editSeriesToolStripMenuItem_Click(object sender, EventArgs e)
{
EventHandler<EventArgs> handler = EditSeriesClick;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
public event EventHandler<EventArgs> DatesClick;
private void toolStripButtonDates_Click(object sender, EventArgs e)
{
EventHandler<EventArgs> handler = DatesClick;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
private void toolStripMenuItemDates_Click(object sender, EventArgs e)
{
toolStripButtonDates_Click(sender, e);
}
private void toolStripButtonPrint_Click(object sender, EventArgs e)
{
Print();
}
}
}